SetProtocol / set-protocol-v2

Set Protocol V2
118 stars 94 forks source link

CurveAmmAdapter #259

Open andris-balodis opened 2 years ago

andris-balodis commented 2 years ago

There are a few things to consider about the CurveAmmAdapter.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

FlattestWhite commented 2 years ago

I've only looked closely at the contract so far, leaving a more detailed look to the tests later