feat: allow executor to do native swaps, add diff pool type tests
Took 4 seconds
This commit is contained in:
committed by
Diana Carvalho
parent
7cde5130d6
commit
93bdc86dc6
@@ -9,26 +9,41 @@ contract CurveExecutor is IExecutor {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
ICurveRouter public immutable curveRouter;
|
||||
address public immutable ethAddress;
|
||||
|
||||
constructor(address _curveRouter) {
|
||||
constructor(address _curveRouter, address _ethAddress) {
|
||||
curveRouter = ICurveRouter(_curveRouter);
|
||||
ethAddress = _ethAddress;
|
||||
}
|
||||
|
||||
// slither-disable-next-line locked-ether
|
||||
function swap(uint256 amountIn, bytes calldata data)
|
||||
external
|
||||
payable
|
||||
returns (uint256)
|
||||
{
|
||||
CurveRouterParams memory params = _decodeData(data);
|
||||
IERC20(params.route[0]).approve(address(curveRouter), amountIn);
|
||||
return curveRouter.exchange(
|
||||
if (params.route[0] != ethAddress) {
|
||||
IERC20(params.route[0]).approve(address(curveRouter), amountIn);
|
||||
|
||||
return curveRouter.exchange(
|
||||
params.route,
|
||||
params.swapParams,
|
||||
amountIn,
|
||||
params.minAmountOut,
|
||||
params.pools,
|
||||
params.receiver
|
||||
);
|
||||
);
|
||||
} else {
|
||||
return curveRouter.exchange{value: amountIn}(
|
||||
params.route,
|
||||
params.swapParams,
|
||||
amountIn,
|
||||
params.minAmountOut,
|
||||
params.pools,
|
||||
params.receiver
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function _decodeData(bytes calldata data)
|
||||
@@ -38,4 +53,6 @@ contract CurveExecutor is IExecutor {
|
||||
{
|
||||
return abi.decode(data, (CurveRouterParams));
|
||||
}
|
||||
|
||||
receive() external payable {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user