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

Curve amm adapter #9

Closed
wants to merge 9 commits into from
Closed

Conversation

edkim
Copy link

@edkim edkim commented Feb 1, 2023

This PR was originally targeting the SetV2 repo. Discussion can be found here: SetProtocol#259

TODO: Upgrade to Solidity 0.8
TODO: Replace any Set Protocol deployed addresses with their Index Protocol equivalent.

Text from original PR by DeePhil:

There are a few things to consider about the CurveAmmAdapter.

All curve pools have 2 ~ 4 component coins.
CVXETH - 0x3A283D9c08E8b55966afb64C515f5143cf907611 (two tokens - WETH/CVX)
TRICRYPTO - 0xc4AD29ba4B3c580e6D59105FFf484999997675Ff (three tokens - USDT/WBTC/WETH)

There is no generalized query function to get component coin count of the pool.
To support different number of component coins, the CurveAmmAdapter will accept coinCount in constructor.

Each curve pool has token contract (which has IERC20 standard interface) and minter contract (which has addLiquidity / removeLiquidity functionality).
Example curve pool with different token/minter contract address
CVXETH token contract - 0x3A283D9c08E8b55966afb64C515f5143cf907611
CVXETH minter contract - 0xb576491f1e6e5e62f1d8f26062ee822b40b0e0d4

Example curve pool with same token/minter contract address
MIM token contract - 0x5a6A4D54456819380173272A5E8E9B9904BdF41B
MIM minter contract - 0x5a6A4D54456819380173272A5E8E9B9904BdF41B

Since some has the same token/minter contract and some has different token/minter contract, the CurveAmmAdapter will accept poolToken and poolMinter contract addresses in constructor.

The curve pools support removeLiquidityOneCoin functionality, but some pools use int128 for the coin index, some pools use uint256 for the coin index.
MIM token contract - 0x5a6A4D54456819380173272A5E8E9B9904BdF41B (use int128 for the coin index)
TRICRYPTO - 0xc4AD29ba4B3c580e6D59105FFf484999997675Ff (use uint256 for the coin index)

To solve this problem, the CurveAmmAdapter will accept a flag that tells if the pool uses int128 or uint256 for coin index.

The curve pools has addLiquidity and removeLiquidity functionality but it doesn't accept any recipient address. So we can't specify setToken address in the calldata.
This is fixed by introducing addLiquidity, removeLiquidity and removeLiquidityOneCoin wrapper functions in CurveAmmAdapter contract.
E.g. addLiquidity wrapper function will accept the recipient address. It will get component tokens from msg.sender, add liquidity & mint pool tokens, transfer pool tokens back to recipient address.

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.

3 participants