Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0x trading testing script #361

Merged
merged 71 commits into from
Feb 4, 2021
Merged

0x trading testing script #361

merged 71 commits into from
Feb 4, 2021

Conversation

haythemsellami
Copy link
Member

@haythemsellami haythemsellami commented Jan 27, 2021

Task: 0x trading testing script

High Level Description

This PR add a script to test Gamma actions batched with 0x trading on Kovan testnet.
The script use two address:

  • Maker: account[1] from the imported wallet that will sign a 0x order to sell 1 USDC for 1 Call option
  • Taker: account[0] from the imported wallet that will mint a Call option and sell it using the Trade0x Callee

The Taker account need to have at least 1USDC and few ETH to approve USDC transfer.
The Maker account need to have at least 1ETH to collateralize the minted option + few ETH for 0x and transaction fees.

Also this PR add a bunch of scripts that help interacting with the protocol:

  • Deploy new Permit Callee
  • Deploy new 0x Callee
  • Set call restriction in Controller
  • Whitelist callee address

Usage:
truffle exec scripts/trade0x-kovan.js --network kovan --makerPrivateKey 0x0000...
where makerPrivateKey is the account private key used to sign 0x order.

Output:

πŸ”₯πŸ”₯πŸ”₯ STARTING 0x TRADING SCRIPT πŸ”₯πŸ”₯πŸ”₯
0x order signer address: πŸ–‹οΈ  0x543361Be968e2f59087316514eaee9e9E9A30aF7
Taker address:  0x8c8b4C5caEAf1A6FB8308a6336932B3e3419704C
WETHUSDC 30-January-2021 640Call WETH Collateral 0x10980E19f0b40Abde86Df23aFE7Fb90DF74C7D0d
Signed 0x order with signature: πŸ–‹οΈ  0x1c46f91a51cc20e17a91b00fb32a3ae7b0d690b74b0d287a11a787f327db33761e0a486220fbf0eb91d3138f4c37ae680d05c18b2d5278f566b1e825651af2814d02
ETH needed: πŸ’°  1003500000000000000
MarginPool WETH balance before: πŸ“Š  25408108658113122978
Maker USDC balance before: πŸ“Š  98000000
Maker Otoken balance before: πŸ“Š  200000000
Taker USDC balance before: πŸ“Š  941437399
Taker Otoken balance before: πŸ“Š  500000000
Otoken total supply before: πŸ“Š  700000000
Approving 0x Callee and calling Operate πŸš€
MarginPool WETH balance after: πŸ“ˆ  26408108658113122978
Maker USDC balance after: πŸ“‰  97000000
Maker Otoken balance after: πŸ“ˆ  500000000
Taker USDC balance after: πŸ“ˆ  942437399
Taker Otoken balance after: πŸ“‰ 500000000
Otoken total supply after: πŸ“ˆ  800000000

Code

  • Unit test 100% coverage
  • Does your code follow the naming and code documentation guidelines?

Documentation

  • Is your code up to date with the spec?
  • Have you added your tests to the testing doc?

@haythemsellami haythemsellami self-assigned this Jan 27, 2021
@haythemsellami haythemsellami changed the title [WIP] 0x trading script [WIP] 0x trading testing script Jan 29, 2021
@haythemsellami haythemsellami changed the title [WIP] 0x trading testing script 0x trading testing script Jan 29, 2021
@antoncoding
Copy link
Contributor

@haythem96 can you rebase your branch to the current master? It's been containing commit message from last Dec πŸ˜‚


console.log("Approving 0x Callee and calling Operate πŸš€")

await callOption1.approve(trade0xCallee.address, optionsToMint, {from: taker})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to use the permit callee for this approval?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Otoken in Kovan currently have no permit(), so I just used the approve()

expiryDate.setUTCSeconds(0)
expiry = new BigNumber(Math.floor(expiryDate.getTime() / 1000))

let callOption1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also test put options? :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is the same as the Trade0x is agnostic to what the option type is, it is the same asset/contract.

@haythemsellami haythemsellami merged commit f09c40c into master Feb 4, 2021
@haythemsellami haythemsellami deleted the task/0x-script branch February 4, 2021 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants