feat: add swap encode
This commit is contained in:
@@ -7,23 +7,17 @@ import {Constants} from "../Constants.sol";
|
||||
|
||||
contract MaverickV2ExecutorExposed is MaverickV2Executor {
|
||||
constructor(address _factory) MaverickV2Executor(_factory) {}
|
||||
|
||||
function decodeParams(bytes calldata data)
|
||||
external
|
||||
pure
|
||||
returns (
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver
|
||||
)
|
||||
returns (IERC20 tokenIn, address target, address receiver)
|
||||
{
|
||||
return _decodeData(data);
|
||||
}
|
||||
}
|
||||
|
||||
contract MaverickV2ExecutorTest is
|
||||
Test,
|
||||
Constants
|
||||
{
|
||||
contract MaverickV2ExecutorTest is Test, Constants {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
MaverickV2ExecutorExposed maverickV2Exposed;
|
||||
@@ -37,15 +31,11 @@ contract MaverickV2ExecutorTest is
|
||||
}
|
||||
|
||||
function testDecodeParams() public view {
|
||||
bytes memory params = abi.encodePacked(
|
||||
GHO_ADDR, GHO_USDC_POOL, address(2)
|
||||
);
|
||||
bytes memory params =
|
||||
abi.encodePacked(GHO_ADDR, GHO_USDC_POOL, address(2));
|
||||
|
||||
(
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver
|
||||
) = maverickV2Exposed.decodeParams(params);
|
||||
(IERC20 tokenIn, address target, address receiver) =
|
||||
maverickV2Exposed.decodeParams(params);
|
||||
|
||||
assertEq(address(tokenIn), GHO_ADDR);
|
||||
assertEq(target, GHO_USDC_POOL);
|
||||
@@ -74,4 +64,33 @@ contract MaverickV2ExecutorTest is
|
||||
assertGt(balanceAfter, balanceBefore);
|
||||
assertEq(balanceAfter - balanceBefore, amountOut);
|
||||
}
|
||||
|
||||
function testDecodeIntegration() public view {
|
||||
// Generated by the SwapEncoder - test_encode_maverick_v2
|
||||
bytes memory protocolData =
|
||||
hex"40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f14cf6d2fe3e1b326114b07d22a6f6bb59e346c671d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e";
|
||||
|
||||
(IERC20 tokenIn, address pool, address receiver) =
|
||||
maverickV2Exposed.decodeParams(protocolData);
|
||||
|
||||
assertEq(address(tokenIn), GHO_ADDR);
|
||||
assertEq(pool, GHO_USDC_POOL);
|
||||
assertEq(receiver, BOB);
|
||||
}
|
||||
|
||||
function testSwapIntegration() public {
|
||||
// Generated by the SwapEncoder - test_encode_maverick_v2
|
||||
bytes memory protocolData =
|
||||
hex"40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f14cf6d2fe3e1b326114b07d22a6f6bb59e346c671d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e";
|
||||
|
||||
uint256 amountIn = 10 ** 18;
|
||||
deal(GHO_ADDR, address(maverickV2Exposed), amountIn);
|
||||
uint256 balanceBefore = GHO.balanceOf(BOB);
|
||||
|
||||
uint256 amountOut = maverickV2Exposed.swap(amountIn, protocolData);
|
||||
|
||||
uint256 balanceAfter = USDC.balanceOf(BOB);
|
||||
assertGt(balanceAfter, balanceBefore);
|
||||
assertEq(balanceAfter - balanceBefore, amountOut);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user