-
Notifications
You must be signed in to change notification settings - Fork 48
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
HyETH Flashmint contract #173
Conversation
_depositIntoAcross(_amount); | ||
return; | ||
} | ||
revert("Component not supported for deposit"); |
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.
This assumes that the product will not have any other component other than insta, pendle and across.
TODO: verify that this is okay
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.
Let's make this contract slightly more general by adding support for multiple spot ERC-20 positions - similar to its ability to support multiple Pendle positions
_withdrawFromPendle(IPendlePrincipalToken(_component), _amount, market); | ||
return; | ||
} | ||
if (IERC20(_component) == acrossToken) { |
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.
Assumes that accross component address will not change
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.
Fine to hardcode for Across / Pendle tokens
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.
Note that only across and instadapp tokens are hardcoed. Pendle tokens are not hard coded. Afaik their addresses will change with maturity roll-over
uint256 ptAmount = uint256(-_ptToAccount); | ||
marketData.pt.transfer(msg.sender, ptAmount); | ||
} else if (_syToAccount < 0) { | ||
uint256 syAmount = uint256(-_syToAccount); |
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.
We only find out in this callback how much sy tokens we are paying for the requested pt tokens, when issuing.
I did not find any preview method, which is why I didn't find a good way to estimate the eth amount required before issuing and had to resort to swapping all of the input token into eth when issuing via issueExactTokenFromERC20
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.
Fine to me to have some ETH specific logic in this FlashMint contract
) external payable nonReentrant returns (uint256) { | ||
_inputToken.safeTransferFrom(msg.sender, address(this), _maxInputTokenAmount); | ||
|
||
uint256 ethAmount = _swapFromTokenToEth(_inputToken, _maxInputTokenAmount, _swapDataInputTokenToEth); |
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.
Here we are swapping all of the maxInputTokenAmount
into eth, with the left over being swapped back.
This is not efficient / optimal, but doing it differently would require determening the amount of eth beforehand. I didn't find a good way to do this mainly because I couldn't find a way to precalculate the amount of SY tokens we are going to pay for obtaining a given pt position on pendle.
See: https://github.com/IndexCoop/index-coop-smart-contracts/pull/173/files#r1593326522
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.
Fine with step 1 of issueExactSetFromERC20
being a swap to ETH in this contract
uint256 ethAmount = _swapFromTokenToEth(_inputToken, _maxInputTokenAmount, _swapDataInputTokenToEth); | ||
ethAmount = ethAmount.sub(_issueExactSetFromEth(_setToken, _amountSetToken)); | ||
|
||
uint256 inputTokenLeft = _swapFromEthToToken(_inputToken, ethAmount, _swapDataEthToInputToken); |
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.
Here we could think about giving the user a way of opting out of swapping back. (in case the associated gas costs will be higher than any returned input tokens). (and optionally send back eth as gas rebate)
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.
Yes i do think its worth adding a boolean input on the contract to offer ETH gas rebate or swap back to initial ERC-20
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.
Let's update this contract name from FlashMintHyETH
to a slightly more general FlashMintETH
This ETH specific FlashMint contract should flash issuance and redemption for a SetToken with any of the following positions present
- Multiple Spot positions
- Multiple Pendle ETH positions
- The initial Instadapp ETH position
- The initial Across ETH position
The addition of multiple Spot position support will be useful during auction rebalancing, after Pendle expirations, and potentially for new LST positions. Its implementation will look similar to the Pendle integration and previous FlashMint contracts.
It will have some ETH specific logic like
- Swapping to ETH at the beginning of
issueExactSetFromERC20
- Gives the option to receive ETH rebate or ERC20 in
issueExactSetFromERC20
]; | ||
|
||
const componentSwapDataIssue = [ | ||
NO_OP_SWAP_DATA, |
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.
Note that for every non-spot component. (i.e. one of the standard hyETH components that can be deposited / withdrawn from you will have to pass a non-op SwapData entry with DEX = 0 here).
@janndriessen
* shift .only to latest contract
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 🔥
🎉 This PR is included in version 0.24.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
No description provided.