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

HyETH Flashmint contract #173

Merged
merged 26 commits into from
Jun 1, 2024
Merged

HyETH Flashmint contract #173

merged 26 commits into from
Jun 1, 2024

Conversation

ckoopmann
Copy link
Collaborator

No description provided.

@ckoopmann ckoopmann marked this pull request as draft April 28, 2024 11:31
@ckoopmann ckoopmann marked this pull request as ready for review May 8, 2024 02:58
@ckoopmann ckoopmann requested a review from pblivin0x May 8, 2024 03:01
_depositIntoAcross(_amount);
return;
}
revert("Component not supported for deposit");
Copy link
Collaborator Author

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

Copy link
Contributor

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) {
Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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

Copy link
Contributor

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);
Copy link
Collaborator Author

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

Copy link
Contributor

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);
Copy link
Collaborator Author

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)

Copy link
Contributor

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

Copy link
Contributor

@pblivin0x pblivin0x left a 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

@pblivin0x pblivin0x requested a review from janndriessen May 13, 2024 12:16
@ckoopmann ckoopmann requested a review from pblivin0x May 30, 2024 12:01
];

const componentSwapDataIssue = [
NO_OP_SWAP_DATA,
Copy link
Collaborator Author

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
Copy link
Contributor

@pblivin0x pblivin0x left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

@ckoopmann ckoopmann merged commit e0cf003 into master Jun 1, 2024
5 checks passed
@ckoopmann ckoopmann deleted the hyeth-flashmint branch June 1, 2024 06:56
Copy link

github-actions bot commented Jun 1, 2024

🎉 This PR is included in version 0.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants