Last active
March 8, 2022 22:12
-
-
Save 0xtuytuy/5ed58c8da9052e4a9fe628168793ee18 to your computer and use it in GitHub Desktop.
Alluo - Extract 3CRV Adatptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function executeSwap( | |
address pool, | |
address fromToken, | |
address toToken, | |
uint256 amount | |
) external payable returns (uint256) { | |
ICurve3Crv pool3crv = ICurve3Crv(pool); | |
if (toToken == address(token3crv)) { | |
// enter 3crv pool to get 3crv token | |
int128 i = indexByCoin(fromToken); | |
require(i != 0, "Curve3CrvSwapAdapter: can't swap"); | |
uint256[3] memory amounts; | |
amounts[uint256(int256(i - 1))] = amount; | |
pool3crv.add_liquidity(amounts, 0); | |
return token3crv.balanceOf(address(this)); | |
} else if (fromToken == address(token3crv)) { | |
// exit 3crv pool to get stable | |
int128 i = indexByCoin(toToken); | |
require(i != 0, "Curve3CrvSwapAdapter: can't swap"); | |
pool3crv.remove_liquidity_one_coin(amount, i - 1, 0); | |
return IERC20(toToken).balanceOf(address(this)); | |
} else { | |
revert("Curve3CrvSwapAdapter: can't swap"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment