feat(curve): Add integration test
Bonus fix of a shameful typo :| --- don't change below this line --- ENG-4306 Took 21 minutes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
"uniswap_v4": "0x042C0ebBEAb9d9987c2f64Ee05f2B3aeB86eAf70",
|
||||
"vm:balancer_v2": "0x00BE8EfAE40219Ff76287b0F9b9e497942f5BC91",
|
||||
"ekubo_v2": "0x4f88f6630a33dB05BEa1FeF7Dc7ff7508D1c531D",
|
||||
"vm:curve": "0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"
|
||||
"vm:curve": "0x1d1499e622D69689cdf9004d05Ec547d650Ff211"
|
||||
},
|
||||
"tenderly_ethereum": {
|
||||
"uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E",
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
"uniswap_v4": "0xF62849F9A0B5Bf2913b396098F7c7019b51A820a",
|
||||
"vm:balancer_v2": "0xc7183455a4C133Ae270771860664b6B7ec320bB1",
|
||||
"ekubo_v2": "0x2a07706473244BC757E10F2a9E86fB532828afe3",
|
||||
"vm:curve": "0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"
|
||||
"vm:curve": "0x1d1499e622D69689cdf9004d05Ec547d650Ff211"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -843,7 +843,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
// Tests swapping WETH -> DAI on a USV2 pool
|
||||
deal(WETH_ADDR, ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -855,10 +855,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
|
||||
assertEq(balanceAfter - balanceBefore, 2659881924818443699787);
|
||||
}
|
||||
|
||||
function testSingleSwapWithoutPermit2Integration() public {
|
||||
@@ -869,16 +869,16 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
deal(WETH_ADDR, ALICE, 1 ether);
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), 1 ether);
|
||||
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
// Encoded solution generated using `test_split_swap_strategy_encoder_simple_route_no_permit2`
|
||||
(bool success,) = tychoRouterAddr.call(
|
||||
hex"0a83cb080000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000008f1d5c1cae37400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000058005600010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d01395000000000000000000"
|
||||
);
|
||||
|
||||
vm.stopPrank();
|
||||
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
|
||||
assertEq(balanceAfter - balanceBefore, 2659881924818443699787);
|
||||
}
|
||||
|
||||
function testUSV4Integration() public {
|
||||
@@ -890,7 +890,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// USDC ──(USV4)──> ETH ───(USV4)──> PEPE
|
||||
//
|
||||
deal(USDC_ADDR, ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -902,10 +902,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 97191013220606467325121599);
|
||||
assertEq(balanceAfter - balanceBefore, 97191013220606467325121599);
|
||||
}
|
||||
|
||||
function testUSV4IntegrationInputETH() public {
|
||||
@@ -916,7 +916,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// ETH ───(USV4)──> PEPE
|
||||
//
|
||||
deal(ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Encoded solution generated using `test_split_encoding_strategy_usv4_eth_in`
|
||||
(bool success,) = tychoRouterAddr.call{value: 1 ether}(
|
||||
@@ -925,10 +925,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(PEPE_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 242373460199848577067005852);
|
||||
assertEq(balanceAfter - balanceBefore, 242373460199848577067005852);
|
||||
}
|
||||
|
||||
function testUSV4IntegrationOutputETH() public {
|
||||
@@ -939,7 +939,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// USDC ───(USV4)──> ETH
|
||||
//
|
||||
deal(USDC_ADDR, ALICE, 3000_000000);
|
||||
uint256 balancerBefore = ALICE.balance;
|
||||
uint256 balanceBefore = ALICE.balance;
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -952,11 +952,11 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = ALICE.balance;
|
||||
uint256 balanceAfter = ALICE.balance;
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
console.logUint(balancerAfter - balancerBefore);
|
||||
assertEq(balancerAfter - balancerBefore, 1117254495486192350);
|
||||
console.logUint(balanceAfter - balanceBefore);
|
||||
assertEq(balanceAfter - balanceBefore, 1117254495486192350);
|
||||
}
|
||||
|
||||
function testSingleSwapWithWrapIntegration() public {
|
||||
@@ -966,7 +966,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// Tests swapping WETH -> DAI on a USV2 pool, but ETH is received from the user
|
||||
// and wrapped before the swap
|
||||
deal(ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -977,10 +977,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
|
||||
assertEq(balanceAfter - balanceBefore, 2659881924818443699787);
|
||||
}
|
||||
|
||||
function testSingleSwapWithUnwrapIntegration() public {
|
||||
@@ -990,7 +990,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// Tests swapping DAI -> WETH on a USV2 pool, and WETH is unwrapped to ETH
|
||||
// before sending back to the user
|
||||
deal(DAI_ADDR, ALICE, 3000 ether);
|
||||
uint256 balancerBefore = ALICE.balance;
|
||||
uint256 balanceBefore = ALICE.balance;
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -1002,10 +1002,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = ALICE.balance;
|
||||
uint256 balanceAfter = ALICE.balance;
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertEq(balancerAfter - balancerBefore, 1120007305574805922);
|
||||
assertEq(balanceAfter - balanceBefore, 1120007305574805922);
|
||||
}
|
||||
|
||||
function testEkuboIntegration() public {
|
||||
@@ -1026,7 +1026,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
);
|
||||
|
||||
deal(ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -1035,10 +1035,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
hex"0a83cb080000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000077007500010000002a07706473244bc757e10f2a9e86fb532828afe31d1499e622d69689cdf9004d05ec547d650ff2110000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4851d02a5948496a67827242eabc5725531342527c000000000000000000000000000000000000000000"
|
||||
);
|
||||
|
||||
uint256 balancerAfter = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertGe(balancerAfter - balancerBefore, 26173932);
|
||||
assertGe(balanceAfter - balanceBefore, 26173932);
|
||||
|
||||
// All input tokens are transferred to the router at first. Make sure we used
|
||||
// all of it (and thus our splits are correct).
|
||||
@@ -1055,7 +1055,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
// WETH ─┤
|
||||
// └──(USV2)──> DAI ───(USV2)──> USDC
|
||||
deal(WETH_ADDR, ALICE, 1 ether);
|
||||
uint256 balancerBefore = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceBefore = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
|
||||
// Approve permit2
|
||||
vm.startPrank(ALICE);
|
||||
@@ -1067,10 +1067,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 balancerAfter = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
uint256 balanceAfter = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
|
||||
assertTrue(success, "Call Failed");
|
||||
assertGe(balancerAfter - balancerBefore, 26173932);
|
||||
assertGe(balanceAfter - balanceBefore, 26173932);
|
||||
|
||||
// All input tokens are transferred to the router at first. Make sure we used
|
||||
// all of it (and thus our splits are correct).
|
||||
@@ -1448,4 +1448,19 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
tychoRouter.exposedSwap(amountIn, 2, pleEncode(swaps));
|
||||
assertGt(IERC20(BASE_MAG7).balanceOf(tychoRouterAddr), 1379830606);
|
||||
}
|
||||
|
||||
function testCurveIntegration() public {
|
||||
deal(UWU_ADDR, ALICE, 1 ether);
|
||||
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(UWU_ADDR).approve(tychoRouterAddr, type(uint256).max);
|
||||
// Encoded solution generated using `test_split_encoding_strategy_curve`
|
||||
(bool success,) = tychoRouterAddr.call(
|
||||
hex"0a83cb080000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000055c08ca52497e2f1534b59e2917bf524d4765257000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc20000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000005b005900010000001d1499e622d69689cdf9004d05ec547d650ff21155c08ca52497e2f1534b59e2917bf524d4765257c02aaa39b223fe8d0a0e5c4f27ead9083c756cc277146b0a1d08b6844376df6d9da99ba7f1b19e71020100010000000000"
|
||||
);
|
||||
|
||||
assertEq(IERC20(WETH_ADDR).balanceOf(ALICE), 4691958787921);
|
||||
|
||||
vm.stopPrank();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "../src/executors/BalancerV2Executor.sol";
|
||||
import "../src/executors/CurveExecutor.sol";
|
||||
import "../src/executors/EkuboExecutor.sol";
|
||||
import "../src/executors/UniswapV2Executor.sol";
|
||||
import "../src/executors/UniswapV3Executor.sol";
|
||||
@@ -42,6 +43,7 @@ contract TychoRouterTestSetup is Test, Constants {
|
||||
UniswapV4Executor public usv4Executor;
|
||||
BalancerV2Executor public balancerv2Executor;
|
||||
EkuboExecutor public ekuboExecutor;
|
||||
CurveExecutor public curveExecutor;
|
||||
MockERC20[] tokens;
|
||||
|
||||
function setUp() public {
|
||||
@@ -96,14 +98,16 @@ contract TychoRouterTestSetup is Test, Constants {
|
||||
new UniswapV3Executor(factoryPancakeV3, initCodePancakeV3);
|
||||
balancerv2Executor = new BalancerV2Executor();
|
||||
ekuboExecutor = new EkuboExecutor(ekuboCore);
|
||||
curveExecutor = new CurveExecutor(ETH_ADDR);
|
||||
|
||||
address[] memory executors = new address[](6);
|
||||
address[] memory executors = new address[](7);
|
||||
executors[0] = address(usv2Executor);
|
||||
executors[1] = address(usv3Executor);
|
||||
executors[2] = address(pancakev3Executor);
|
||||
executors[3] = address(usv4Executor);
|
||||
executors[4] = address(balancerv2Executor);
|
||||
executors[5] = address(ekuboExecutor);
|
||||
executors[6] = address(curveExecutor);
|
||||
return executors;
|
||||
}
|
||||
|
||||
|
||||
@@ -1773,4 +1773,62 @@ mod tests {
|
||||
assert_eq!(hex_calldata[1288..], expected_swaps);
|
||||
println!("{}", hex_calldata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_encoding_strategy_curve() {
|
||||
// UWU ──(curve 2 crypto pool)──> WETH
|
||||
|
||||
let token_in = Bytes::from("0x55C08ca52497e2f1534B59E2917BF524D4765257"); // UWU
|
||||
let token_out = Bytes::from("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"); // USDC
|
||||
|
||||
let static_attributes = HashMap::from([(
|
||||
"factory".to_string(),
|
||||
Bytes::from("0x98ee851a00abee0d95d08cf4ca2bdce32aeaaf7f"),
|
||||
)]);
|
||||
|
||||
let component = ProtocolComponent {
|
||||
id: String::from("0x77146B0a1d08B6844376dF6d9da99bA7F1b19e71"),
|
||||
protocol_system: String::from("vm:curve"),
|
||||
static_attributes,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let swap = Swap {
|
||||
component,
|
||||
token_in: token_in.clone(),
|
||||
token_out: token_out.clone(),
|
||||
split: 0f64,
|
||||
};
|
||||
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SplitSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
swap_encoder_registry,
|
||||
None,
|
||||
Some(Bytes::from_str("0x3Ede3eCa2a72B3aeCC820E955B36f38437D01395").unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let solution = Solution {
|
||||
exact_out: false,
|
||||
given_token: token_in,
|
||||
given_amount: BigUint::from_str("1_000000000000000000").unwrap(),
|
||||
checked_token: token_out,
|
||||
expected_amount: None,
|
||||
checked_amount: Some(BigUint::from_str("1").unwrap()),
|
||||
slippage: None,
|
||||
// Alice
|
||||
sender: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
receiver: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
swaps: vec![swap],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (calldata, _) = encoder
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("{}", hex_calldata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ impl CurveSwapEncoder {
|
||||
// Tricrypto factory
|
||||
"0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963" => Ok(U8::from(3)),
|
||||
// Twocrypto factory
|
||||
"0x98ee851a00abee0d95d08cf4ca2bdce32aeaaf7f" => Ok(U8::from(2)),
|
||||
"0x98EE851a00abeE0d95D08cF4CA2BdCE32aeaAF7F" => Ok(U8::from(2)),
|
||||
// StableSwap factory
|
||||
"0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d" => Ok(U8::from(1)),
|
||||
_ => Err(EncodingError::FatalError(format!(
|
||||
@@ -1131,10 +1131,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_curve_encode_factory() {
|
||||
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
||||
static_attributes.insert(
|
||||
"factory".into(),
|
||||
Bytes::from_str("0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf").unwrap(),
|
||||
);
|
||||
static_attributes
|
||||
.insert("factory".into(), Bytes::from("0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf"));
|
||||
let curve_pool = ProtocolComponent {
|
||||
id: String::from("0x02950460E2b9529D0E00284A5fA2d7bDF3fA4d72"),
|
||||
protocol_system: String::from("vm:curve"),
|
||||
|
||||
Reference in New Issue
Block a user