fix: Improve curve executor tests and docstrings
--- don't change below this line --- ENG-4305 Took 34 minutes Took 8 seconds
This commit is contained in:
@@ -13,10 +13,42 @@ contract CurveExecutor is IExecutor {
|
||||
ICurveRouter public immutable curveRouter;
|
||||
address public immutable nativeToken;
|
||||
|
||||
struct SwapParams {
|
||||
/**
|
||||
* @dev Struct representing the parameters for a Curve swap.
|
||||
*
|
||||
* `route` is an array of [initial token, pool or zap, token, pool or zap, token, ...]
|
||||
* The array is iterated until a pool address of 0x00, then the last given token is transferred to `receiver`.
|
||||
*
|
||||
* `swapParams` is a multidimensional array of [i, j, swap_type, pool_type, n_coins] where:
|
||||
* - i is the index of input token
|
||||
* - j is the index of output token
|
||||
*
|
||||
* The swap_type should be:
|
||||
* 1. for `exchange`
|
||||
* 2. for `exchange_underlying`
|
||||
* 3. for underlying exchange via zap: factory stable metapools with lending base pool `exchange_underlying`
|
||||
* and factory crypto-meta pools underlying exchange (`exchange` method in zap)
|
||||
* 4. for coin -> LP token "exchange" (actually `add_liquidity`)
|
||||
* 5. for lending pool underlying coin -> LP token "exchange" (actually `add_liquidity`)
|
||||
* 6. for LP token -> coin "exchange" (actually `remove_liquidity_one_coin`)
|
||||
* 7. for LP token -> lending or fake pool underlying coin "exchange" (actually `remove_liquidity_one_coin`)
|
||||
* 8. for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, frxETH <-> sfrxETH, ETH -> wBETH, USDe -> sUSDe
|
||||
*
|
||||
* pool_type: 1 - stable, 2 - twocrypto, 3 - tricrypto, 4 - llamma
|
||||
* 10 - stable-ng, 20 - twocrypto-ng, 30 - tricrypto-ng
|
||||
*
|
||||
* n_coins is the number of coins in the pool.
|
||||
*
|
||||
* `receiver` is the address of the receiver of the final token.
|
||||
*
|
||||
* `needsApproval` is a flag indicating whether the initial token needs approval before the swap.
|
||||
*
|
||||
* For more see https://github.com/curvefi/curve-router-ng/blob/9ab006ca848fc7f1995b6fbbecfecc1e0eb29e2a/contracts/Router.vy
|
||||
*
|
||||
*/
|
||||
struct CurveSwapParams {
|
||||
address[11] route;
|
||||
uint256[5][5] swapParams;
|
||||
uint256 minAmountOut;
|
||||
address receiver;
|
||||
bool needsApproval;
|
||||
}
|
||||
@@ -35,7 +67,7 @@ contract CurveExecutor is IExecutor {
|
||||
payable
|
||||
returns (uint256)
|
||||
{
|
||||
SwapParams memory params = _decodeData(data);
|
||||
CurveSwapParams memory params = _decodeData(data);
|
||||
|
||||
if (params.needsApproval) {
|
||||
// slither-disable-next-line unused-return
|
||||
@@ -47,21 +79,18 @@ contract CurveExecutor is IExecutor {
|
||||
address[5] memory pools;
|
||||
return curveRouter.exchange{
|
||||
value: params.route[0] == nativeToken ? amountIn : 0
|
||||
}(
|
||||
params.route,
|
||||
params.swapParams,
|
||||
amountIn,
|
||||
params.minAmountOut,
|
||||
pools,
|
||||
params.receiver
|
||||
);
|
||||
}(params.route, params.swapParams, amountIn, 0, pools, params.receiver);
|
||||
}
|
||||
|
||||
function _decodeData(bytes calldata data)
|
||||
internal
|
||||
pure
|
||||
returns (SwapParams memory params)
|
||||
returns (CurveSwapParams memory params)
|
||||
{
|
||||
return abi.decode(data, (SwapParams));
|
||||
return abi.decode(data, (CurveSwapParams));
|
||||
}
|
||||
|
||||
receive() external payable {
|
||||
require(msg.sender.code.length != 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user