feat: Add SingleSwap integration test and fix bug in method signatures
--- don't change below this line --- ENG-4306 Took 27 minutes Took 15 seconds
This commit is contained in:
@@ -304,4 +304,42 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
|||||||
|
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSingleSwapIntegration() public {
|
||||||
|
// Tests swapping WETH -> DAI on a USV2 pool with regular approvals
|
||||||
|
deal(WETH_ADDR, ALICE, 1 ether);
|
||||||
|
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||||
|
|
||||||
|
vm.startPrank(ALICE);
|
||||||
|
IERC20(WETH_ADDR).approve(tychoRouterAddr, type(uint256).max);
|
||||||
|
// Encoded solution generated using `test_single_swap_strategy_encoder_no_permit2`
|
||||||
|
(bool success,) = tychoRouterAddr.call(
|
||||||
|
hex"20144a070000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000008f1d5c1cae3740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000515615deb798bb3e4dfa0139dfa1b3d433cc23b72fc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d0139500000000000000000000000000000000"
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.stopPrank();
|
||||||
|
|
||||||
|
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||||
|
assertTrue(success, "Call Failed");
|
||||||
|
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSingleSwapIntegrationPermit2() public {
|
||||||
|
// Tests swapping WETH -> DAI on a USV2 pool with permit2
|
||||||
|
deal(WETH_ADDR, ALICE, 1 ether);
|
||||||
|
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||||
|
|
||||||
|
vm.startPrank(ALICE);
|
||||||
|
IERC20(WETH_ADDR).approve(PERMIT2_ADDRESS, type(uint256).max);
|
||||||
|
// Encoded solution generated using `test_single_swap_strategy_encoder`
|
||||||
|
(bool success,) = tychoRouterAddr.call(
|
||||||
|
hex"30ace1b10000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000903146e5f6c59c064b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000006817833200000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067effd3a00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000000417efea09004d5d40d8d072e1ce0a425507717ea485c765eb90c170859197d362b502fb039b4f5cdce57318ecfe3ab276d1ac87771eb5d017b253a8f4107e6a20b1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000515615deb798bb3e4dfa0139dfa1b3d433cc23b72fc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d0139500000000000000000000000000000000"
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.stopPrank();
|
||||||
|
|
||||||
|
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||||
|
assertTrue(success, "Call Failed");
|
||||||
|
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,11 @@ impl SingleSwapStrategyEncoder {
|
|||||||
) -> Result<Self, EncodingError> {
|
) -> Result<Self, EncodingError> {
|
||||||
let chain = Chain::from(blockchain);
|
let chain = Chain::from(blockchain);
|
||||||
let (permit2, selector) = if let Some(swapper_pk) = swapper_pk {
|
let (permit2, selector) = if let Some(swapper_pk) = swapper_pk {
|
||||||
(Some(Permit2::new(swapper_pk, chain.clone())?), "singleSwapPermit2(uint256,address,address,uint256,bool,bool,uint256,address,((address,uint160,uint48,uint48),address,uint256),bytes,bytes)".to_string())
|
(Some(Permit2::new(swapper_pk, chain.clone())?), "singleSwapPermit2(uint256,address,address,uint256,bool,bool,address,((address,uint160,uint48,uint48),address,uint256),bytes,bytes)".to_string())
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
"singleSwap(uint256,address,address,uint256,bool,bool,uint256,address,bytes)"
|
"singleSwap(uint256,address,address,uint256,bool,bool,address,bytes)".to_string(),
|
||||||
.to_string(),
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
Ok(Self { permit2, selector, swap_encoder_registry, router_address })
|
Ok(Self { permit2, selector, swap_encoder_registry, router_address })
|
||||||
@@ -914,7 +913,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_min_amount_encoded = hex::encode(U256::abi_encode(&expected_min_amount));
|
let expected_min_amount_encoded = hex::encode(U256::abi_encode(&expected_min_amount));
|
||||||
let expected_input = [
|
let expected_input = [
|
||||||
"c378044e", // Function selector
|
"30ace1b1", // Function selector
|
||||||
"0000000000000000000000000000000000000000000000000de0b6b3a7640000", // amount out
|
"0000000000000000000000000000000000000000000000000de0b6b3a7640000", // amount out
|
||||||
"000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
|
"000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
|
||||||
"0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", // token out
|
"0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", // token out
|
||||||
@@ -1450,8 +1449,8 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_min_amount_encoded = hex::encode(U256::abi_encode(&expected_min_amount));
|
let expected_min_amount_encoded = hex::encode(U256::abi_encode(&expected_min_amount));
|
||||||
let expected_input = [
|
let expected_input = [
|
||||||
"0f6cbbe8", // Function selector
|
"20144a07", // Function selector
|
||||||
"0000000000000000000000000000000000000000000000000de0b6b3a7640000", // amount out
|
"0000000000000000000000000000000000000000000000000de0b6b3a7640000", // amount in
|
||||||
"000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
|
"000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
|
||||||
"0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", // token out
|
"0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", // token out
|
||||||
&expected_min_amount_encoded, // min amount out
|
&expected_min_amount_encoded, // min amount out
|
||||||
|
|||||||
Reference in New Issue
Block a user