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

feat: add flashmint hyeth #64

Merged
merged 48 commits into from
Jun 8, 2024
Merged

feat: add flashmint hyeth #64

merged 48 commits into from
Jun 8, 2024

Conversation

janndriessen
Copy link
Collaborator

@janndriessen janndriessen commented Jun 3, 2024

  • Adds FlashMintHyEth
  • Updates github workflow by running hardhat first

TODOs

Most of these only work once the token is rebalanced/migrated.

  • add swap data
  • add builder class for FlashMintHyEth
  • add returning quotes for minting/redeeming
  • add integration tests
  • add tests to github workflow

exchange: Exchange.None,
}
}
if (inputOutputToken.symbol === USDC.symbol) {
Copy link
Collaborator Author

@janndriessen janndriessen Jun 4, 2024

Choose a reason for hiding this comment

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

Now that I see this function again. If I make another check for ETH to return null, I can in this case probably just always return with path [WETH.address!, inputOutputToken.address] no matter the ERC-20 input/output token, correct? @ckoopmann So I'd delete the specific check for USDC.

This would make it more future proof.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a UniV3 pool between the two tokens for the given fee level then yes you can just return that path.

// https://etherscan.io/address/0xa0d3707c569ff8c87fa923d3823ec5d81c98be78#readProxyContract
const tokenContract = new Contract(component, VAULT_ABI, provider)
// TODO: confirm previewWithdraw (and not previewRedeem)
const stEthAmount: BigNumber = await tokenContract.previewWithdraw(position)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pblivin0x please confirm previewWithdraw is the correct function to call (and not previewRedeem)

Copy link

@pblivin0x pblivin0x Jun 7, 2024

Choose a reason for hiding this comment

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

this is actually a redeem() call in FlashMintHyETH https://github.com/IndexCoop/index-coop-smart-contracts/blob/72243db162ad34124db681aad363746bed075944/contracts/exchangeIssuance/FlashMintHyETH.sol#L521
, so i would expect

Suggested change
const stEthAmount: BigNumber = await tokenContract.previewWithdraw(position)
const stEthAmount: BigNumber = await tokenContract.previewRedeem(position)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to previewRedeem. Thank you!

isMinting ? inputToken.decimals : outputToken.decimals,
slippage,
isMinting
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pblivin0x we used this slippage adjusting function for ZeroEx as well. it seems to makes sense here as otherwise mint quotes can revert.

Choose a reason for hiding this comment

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

it makes sense to use some slippage adjustments, but they may be better placed in the integrations

with these itemized adjustments made, it may not be necessary to do a overall slippage adjustment here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Individual changes have been made but we still might wanna watch slippage for a bit.

@janndriessen janndriessen marked this pull request as ready for review June 7, 2024 21:23
Comment on lines +38 to +40
const ethAmount =
(exchangeRate.toBigInt() * acrossLpAmount) / BigInt(1e18) +
this.roundingError

Choose a reason for hiding this comment

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

Comment on lines 61 to 63
const ethAmount =
(exchangeRate.toBigInt() * acrossLpAmount) / BigInt(1e18) +
this.roundingError

Choose a reason for hiding this comment

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

note that this conversion with roundingError isn't the same as FlashMintHyETH https://github.com/IndexCoop/index-coop-smart-contracts/blob/72243db162ad34124db681aad363746bed075944/contracts/exchangeIssuance/FlashMintHyETH.sol#L573

adding the rounding error here increase the amount of expected output (as opposed to increasing the amount of input for deposits)

should be able to omit this.roundingError or subtract is instead

// console.log(sy, 'SY', component)
const routerContract = this.getRouterStatic(this.routerStaticMainnet)
const assetRate: BigNumber = await routerContract.getPtToAssetRate(market)
const ethAmount = (position * assetRate.toBigInt()) / BigInt(1e18)

Choose a reason for hiding this comment

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

noting that if the deposit is large enough to move the exchangeRate(), then this calculation will under quote the amount of ETH required.

on FlashMintHyETH we check the previewDeposit() method to confirm if our ethAmount needs to be inflated or not

https://github.com/IndexCoop/index-coop-smart-contracts/blob/72243db162ad34124db681aad363746bed075944/contracts/exchangeIssuance/FlashMintHyETH.sol#L352-L358

Comment on lines +82 to +83
const assetRate: BigNumber = await routerContract.getPtToAssetRate(market)
const ethAmount = (position * assetRate.toBigInt()) / BigInt(1e18)

Choose a reason for hiding this comment

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

there isn't any logic for values large enough to move the assetRate() on FlashMintHyETH because it isn't necessary for the computation, but some may be necessary here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's watch this. It does seem like slippage has to be higher for redemptions but I think Allan also mentioned that this would be the case for FlashMint (thus the request to also allow direct redemption).

isMinting: true,
inputToken: eth,
outputToken: indexToken,
indexTokenAmount: wei('1'),

Choose a reason for hiding this comment

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

can we test with much larger amounts? like 1000 ether ? that will let us know if any of the integrations quotes break with large values

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Highest I could do for now is 300 but that's 1+m. Should be enough?

@janndriessen janndriessen merged commit f55bc02 into main Jun 8, 2024
1 check passed
@janndriessen janndriessen deleted the feat/add-flashmint-hyeth branch June 8, 2024 10:40
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.

4 participants