Skip to content

Instantly share code, notes, and snippets.

@0xtuytuy
Last active March 8, 2022 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xtuytuy/5ed58c8da9052e4a9fe628168793ee18 to your computer and use it in GitHub Desktop.
Save 0xtuytuy/5ed58c8da9052e4a9fe628168793ee18 to your computer and use it in GitHub Desktop.
Alluo - Extract 3CRV Adatptor
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