ExchangeIssuanceZeroEx
ExchangeIssuanceZeroEx
can be used to issue and redeem any SetToken using native chain currency (ex: ETH, MATIC) or an ERC20 as the paying/receiving token.
When issuing, the contract converts the input token into the components required to mint a SetToken.
When redeeming, it converts redeemed components into the desired output token.
All swaps are done using 0x Exchange.
Users of ExchangeIssuanceZeroEx must fetch quotes for the Set's underlying components from 0x via off-chain API calls and submit returned quote data with their issuance or redemption request. The API response also includes expected outcome quantities for the trade which can be used to estimate the cost of issuance.
Before issuing or redeeming for the first time, approveSetToken
should be called to authorize ExchangeIssuanceZeroEx
to trade the Set's components with 0x.
To obtain the inputs required execute an issuance call, you can follow the recipe in the code block below:
NOTES:
set.js exposes a UtilsAPI class which is useful for batching quote requests, managing request cadences (0x's services are rate-limited) and handling the authentication required to use 0x's gated endpoints. (By default it uses their public endpoints).
when issuing, it's sometimes necessary to add a small buffer to your "paying currency" amount in addition to the total suggested by 0x. This helps prevent reverts caused by tiny rounding errors. Any unused paying currency will be returned to you at the end of the transaction.
IMPORTANT: You should sanity check the cumulative cost of the component quotes you receive and make sure it's within slippage tolerances that are acceptable to you. For example, when issuing, add up the quote
sellAmount
quantities and determine if the total is a fair price for the amount of SetToken you wish to buy.
Select Methods
approveSetToken
Runs all the necessary approval functions for a SetToken's components that are required before issuing or redeeming a SetToken. This function only needs to be called once before the first time this smart contract is used on any particular SetToken.
Parameter Guide
issueExactSetForToken()
Issues an exact amount of SetTokens for given amount of input ERC20 tokens. Any excess input tokens are returned to the user.
Parameter Guide
issueExactSetForETH()
Issues an exact amount of SetTokens for given amount of native chain currency (e.g ETH, MATIC). Any excess native currency is returns to the user.
IMPORTANT: When fetching 0x quotes for this method, you must specify the WETH token address (or its equivalent for non-ETH chains) as the "paying currency" or sellToken
. When executing the method, send ETH with it using the transaction's `value` attribute. ExchangeIssuanceZeroEx
will wrap it into WETH and execute the 0x trades with it as an ERC20.
Parameter Guide
redeemExactSetForToken()
Redeems an exact amount of SetTokens for an ERC20 token. The SetToken must be approved by the sender to this contract.
Parameter Guide
redeemExactSetForETH()
Redeems an exact amount of SetTokens for a native chain currency (e.g ETH, MATIC). The SetToken must be approved by the sender to this contract.
IMPORTANT: When fetching 0x quotes for this method, you must specify the WETH token address (or its equivalent for non-ETH chains) as the "receive currency" or buyToken
. When executing the method, ExchangeIssuanceZeroEx
will receive WETH from 0x, unwrap it and forward the native currency to you.
Parameter Guide
Select View Methods
getRequiredIssuanceComponents
Returns component positions required for issuance. This method can be called to fetch the necessary inputs to fetch 0x API issuance quotes.
Parameter Guide
getRequiredRedemptionComponents
Returns component positions required for redemption. This method can be called to fetch the necessary inputs to fetch 0x API redemption quotes
Parameter Guide
Last updated