-
Notifications
You must be signed in to change notification settings - Fork 53
Flash Mint contract for Set tokens with wrapped components #116
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
Flash Mint contract for Set tokens with wrapped components #116
Conversation
@FlattestWhite could you give this a first look? Is it in line with the thoughts you had for the implementation of this? I yet have to implement the tests |
…wlist; implement getter functions
… extend required utils etc.
@FlattestWhite I changed the description of the PR. Please have a look at the caveat and let me know what you think... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using user provided calldata seems dangerous to me, especially when the calltarget is an erc20 token.
In general there seem to be a few places where we might need additional checks to make sure that attackers can't steal leftover transactions from previous issuance / redemption transactions.
Otherwise great work though 👍
…fix _getAndValidateAdapter params
@FlattestWhite @ckoopmann FYI #issueExactSetFromETH: paying with ETH #issueExactSetFromERC20: paying with USDC #issueExactSetFromERC20: paying with DAI #redeemExactSetForETH: receiving ETH #redeemExactSetForERC20: receiving USDC #redeemExactSetForERC20: receiving DAI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Also thanks for the detailed gas analysis 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had one question but other than that lgtm
@FlattestWhite fixed everything you pointed out and added test cases for
|
Implements flash mint functionality for Set tokens with wrapped components.
Wrapping info is passed in as calldata. Only allowlisted wrap-callTargets are enabled (and when wrap callTarget == set token component, e.g. for CompoundV2).Uses wrap adapters directly, only the integrationName is passed in which is used to fetch the wrap adapter directly from the IntegrationRegistry.
This Flash mint contract is generalized and can be used for any protocol, given that WrapAdapters behave the same way.
This contract also supports flash minting for Set tokens that contain both unwrapped and wrapped components (technically speaking it would even support token sets with no wrapped components at all).
Does not support debt positions on Set token.
Wrapping / Unwrapping is skipped for a component if ComponentSwapData[component_index].underlyingERC20 address == set component address.
If the set contains both the wrapped and unwrapped version of a token (e.g. DAI and cDAI) -> two separate component data points have to be supplied in _swapData and _wrapData
e.g. for issue
Set components at index 0 = DAI; then -> ComponentSwapData[0].underlyingERC20 = DAI; (no wrapping will happen)
Set components at index 1 = cDAI; then -> ComponentSwapData[1].underlyingERC20 = DAI; (wrapping will happen)
Compatible with:
IssuanceModules: DebtIssuanceModule, DebtIssuanceModuleV2, IWrapV2Adapter
Caveat
There might be cases where some wrapped components dust may stay in the flashMintContract because the exchange rate or swap rate might change a tiny bit. Setting a tiny tolerance is the task of the caller...
There is still the check of maxAmountInputSpent / minAmountOutput
This is because the exchange rate from wrapped to unwrapped is used for computation of the actual amounts moments before the actual transaction with the input data is triggered.
This could only be solved by passing in a selector method that returns the exchange rate for each wrapped token (to directly compute everything just-in-time on-chain). It gets complicated... and costs more gas...
The contract is withdrawable, so that dust can be collected