feat: add swap encoder test in balancer v2 executor
This commit is contained in:
@@ -82,4 +82,40 @@ contract BalancerV2ExecutorTest is
|
|||||||
assertGt(balanceAfter, balanceBefore);
|
assertGt(balanceAfter, balanceBefore);
|
||||||
assertEq(balanceAfter - balanceBefore, amountOut);
|
assertEq(balanceAfter - balanceBefore, amountOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSwapExecutorEncoderData() public {
|
||||||
|
// Generated by the SwapEncoder - test_encode_balancer_v2
|
||||||
|
bytes memory protocolData =
|
||||||
|
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01";
|
||||||
|
|
||||||
|
(
|
||||||
|
IERC20 tokenIn,
|
||||||
|
IERC20 tokenOut,
|
||||||
|
bytes32 poolId,
|
||||||
|
address receiver,
|
||||||
|
bool needsApproval
|
||||||
|
) = balancerV2Exposed.decodeParams(protocolData);
|
||||||
|
|
||||||
|
assertEq(address(tokenIn), WETH_ADDR);
|
||||||
|
assertEq(address(tokenOut), BAL_ADDR);
|
||||||
|
assertEq(poolId, WETH_BAL_POOL_ID);
|
||||||
|
assertEq(receiver, BOB);
|
||||||
|
assertEq(needsApproval, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSwapExecutorSwap() public {
|
||||||
|
// Generated by the SwapEncoder - test_encode_balancer_v2
|
||||||
|
bytes memory protocolData =
|
||||||
|
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01";
|
||||||
|
|
||||||
|
uint256 amountIn = 10 ** 18;
|
||||||
|
deal(WETH_ADDR, address(balancerV2Exposed), amountIn);
|
||||||
|
uint256 balanceBefore = BAL.balanceOf(BOB);
|
||||||
|
|
||||||
|
uint256 amountOut = balancerV2Exposed.swap(amountIn, protocolData);
|
||||||
|
|
||||||
|
uint256 balanceAfter = BAL.balanceOf(BOB);
|
||||||
|
assertGt(balanceAfter, balanceBefore);
|
||||||
|
assertEq(balanceAfter - balanceBefore, amountOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ impl SwapEncoder for BalancerV2SwapEncoder {
|
|||||||
bytes_to_address(&swap.token_out)?,
|
bytes_to_address(&swap.token_out)?,
|
||||||
component_id,
|
component_id,
|
||||||
bytes_to_address(&encoding_context.receiver)?,
|
bytes_to_address(&encoding_context.receiver)?,
|
||||||
encoding_context.exact_out,
|
|
||||||
approval_needed,
|
approval_needed,
|
||||||
);
|
);
|
||||||
Ok(args.abi_encode_packed())
|
Ok(args.abi_encode_packed())
|
||||||
@@ -285,11 +284,12 @@ mod tests {
|
|||||||
let swap = Swap {
|
let swap = Swap {
|
||||||
component: balancer_pool,
|
component: balancer_pool,
|
||||||
token_in: Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), // WETH
|
token_in: Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), // WETH
|
||||||
token_out: Bytes::from("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"), // BAL
|
token_out: Bytes::from("0xba100000625a3754423978a60c9317c58a424e3D"), // BAL
|
||||||
split: 0f64,
|
split: 0f64,
|
||||||
};
|
};
|
||||||
let encoding_context = EncodingContext {
|
let encoding_context = EncodingContext {
|
||||||
receiver: Bytes::from("0x0000000000000000000000000000000000000001"),
|
// The receiver was generated with `makeAddr("bob") using forge`
|
||||||
|
receiver: Bytes::from("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e"),
|
||||||
exact_out: false,
|
exact_out: false,
|
||||||
router_address: Bytes::zero(20),
|
router_address: Bytes::zero(20),
|
||||||
};
|
};
|
||||||
@@ -299,6 +299,7 @@ mod tests {
|
|||||||
.encode_swap(swap, encoding_context)
|
.encode_swap(swap, encoding_context)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let hex_swap = encode(&encoded_swap);
|
let hex_swap = encode(&encoded_swap);
|
||||||
|
println!("{}", hex_swap);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
hex_swap,
|
hex_swap,
|
||||||
@@ -306,13 +307,11 @@ mod tests {
|
|||||||
// token in
|
// token in
|
||||||
"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||||
// token out
|
// token out
|
||||||
"2791bca1f2de4661ed88a30c99a7a9449aa84174",
|
"ba100000625a3754423978a60c9317c58a424e3d",
|
||||||
// pool id
|
// pool id
|
||||||
"5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014",
|
"5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014",
|
||||||
// receiver
|
// receiver
|
||||||
"0000000000000000000000000000000000000001",
|
"1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e",
|
||||||
// exact out
|
|
||||||
"00",
|
|
||||||
// approval needed
|
// approval needed
|
||||||
"01"
|
"01"
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user