feat: Add check to don't support cyclical swaps with native actions
Remove unnecessary tests and improve comments --- don't change below this line --- ENG-4331 Took 30 minutes
This commit is contained in:
@@ -1661,139 +1661,4 @@ mod tests {
|
||||
assert_eq!(hex_calldata[..520], expected_input);
|
||||
assert_eq!(hex_calldata[1288..], expected_swaps);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cylic_swap_unwrap_output() {
|
||||
// This test has start and end tokens that are the same
|
||||
// The flow is:
|
||||
// ETH -> WBTC -> WETH(unwrap operation) -> ETH
|
||||
|
||||
// Set up a mock private key for signing (Alice's pk in our router tests)
|
||||
let private_key =
|
||||
"0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234".to_string();
|
||||
|
||||
let weth = Bytes::from_str("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").unwrap();
|
||||
let wbtc = Bytes::from_str("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599").unwrap();
|
||||
|
||||
// ETH -> WBTC (Uniswap V4)
|
||||
let swap_eth_wbtc = Swap {
|
||||
component: ProtocolComponent {
|
||||
id: "0x54c72c46df32f2cc455e84e41e191b26ed73a29452cdd3d82f511097af9f427e"
|
||||
.to_string(),
|
||||
protocol_system: "uniswap_v4".to_string(),
|
||||
static_attributes: {
|
||||
let mut attrs = HashMap::new();
|
||||
attrs.insert(
|
||||
"key_lp_fee".to_string(),
|
||||
Bytes::from(BigInt::from(3000).to_signed_bytes_be()),
|
||||
);
|
||||
attrs.insert(
|
||||
"tick_spacing".to_string(),
|
||||
Bytes::from(BigInt::from(60).to_signed_bytes_be()),
|
||||
);
|
||||
attrs
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: eth(),
|
||||
token_out: wbtc.clone(),
|
||||
split: 0f64,
|
||||
};
|
||||
|
||||
// WBTC -> WETH (Uniswap V3)
|
||||
let swap_wbtc_weth = Swap {
|
||||
component: ProtocolComponent {
|
||||
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
|
||||
protocol_system: "uniswap_v3".to_string(),
|
||||
static_attributes: {
|
||||
let mut attrs = HashMap::new();
|
||||
attrs.insert(
|
||||
"fee".to_string(),
|
||||
Bytes::from(BigInt::from(3000).to_signed_bytes_be()),
|
||||
);
|
||||
attrs
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: wbtc.clone(),
|
||||
token_out: weth.clone(),
|
||||
split: 0f64,
|
||||
};
|
||||
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder =
|
||||
SplitSwapStrategyEncoder::new(eth_chain(), swap_encoder_registry, Some(private_key))
|
||||
.unwrap();
|
||||
|
||||
let solution = Solution {
|
||||
exact_out: false,
|
||||
given_token: eth(),
|
||||
given_amount: BigUint::from_str("1000000000000000000").unwrap(), // 1 WETH
|
||||
checked_token: eth(),
|
||||
expected_amount: None,
|
||||
checked_amount: Some(BigUint::from_str("993164318934741987").unwrap()), /* Expected output
|
||||
* from
|
||||
* test */
|
||||
slippage: None,
|
||||
swaps: vec![swap_eth_wbtc, swap_wbtc_weth],
|
||||
router_address: Bytes::from_str("0x3Ede3eCa2a72B3aeCC820E955B36f38437D01395").unwrap(),
|
||||
sender: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
receiver: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
native_action: Some(NativeAction::Unwrap),
|
||||
};
|
||||
|
||||
let (calldata, _) = encoder
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = hex::encode(&calldata);
|
||||
|
||||
let expected_input = [
|
||||
"d499aa88", // selector
|
||||
"0000000000000000000000000000000000000000000000000de0b6b3a7640000", // given amount
|
||||
"0000000000000000000000000000000000000000000000000000000000000000", // given token
|
||||
"0000000000000000000000000000000000000000000000000000000000000000", // checked token
|
||||
"0000000000000000000000000000000000000000000000000dc86dafa1b2b3e3", // min amount out
|
||||
"0000000000000000000000000000000000000000000000000000000000000000", // wrap action
|
||||
"0000000000000000000000000000000000000000000000000000000000000001", // unwrap action
|
||||
"0000000000000000000000000000000000000000000000000000000000000003", // tokens length
|
||||
"000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2", // receiver
|
||||
]
|
||||
.join("");
|
||||
|
||||
let expected_swaps = [
|
||||
"00000000000000000000000000000000000000000000000000000000000000e1", // length of ple encoded swaps without padding
|
||||
"0070", // ple encoded swaps
|
||||
"00", // token in index
|
||||
"01", // token out index
|
||||
"000000", // split
|
||||
"042c0ebbeab9d9987c2f64ee05f2b3aeb86eaf70", // executor address
|
||||
"0000000000000000000000000000000000000000", // token in
|
||||
"2260fac5e5542a773aa44fbcfedf7c193bc2c599", // intermediary token
|
||||
"01", // zero2one
|
||||
"042c0ebbeab9d9987c2f64ee05f2b3aeb86eaf70", // executor address
|
||||
// Pool params
|
||||
"2260fac5e5542a773aa44fbcfedf7c193bc2c599", // intermediary token
|
||||
"000bb8", // pool fee
|
||||
"00003c", // tick spacing
|
||||
// Next swap
|
||||
"006d", // ple encoded swaps
|
||||
"01", // token in index
|
||||
"02", // token out index
|
||||
"000000", // split
|
||||
"dd8559c917393fc8dd2b4dd289c52ff445fde1b0", // executor address
|
||||
"2260fac5e5542a773aa44fbcfedf7c193bc2c599", // token in
|
||||
"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token out
|
||||
"000bb8", // pool fee
|
||||
"3ede3eca2a72b3aecc820e955b36f38437d01395", // router address
|
||||
"cbcdf9626bc03e24f779434178a73a0b4bad62ed", // component id
|
||||
"01", // zero2one
|
||||
"00000000000000000000000000000000000000000000000000000000000000" // padding
|
||||
]
|
||||
.join("");
|
||||
|
||||
assert_eq!(hex_calldata[..520], expected_input);
|
||||
assert_eq!(hex_calldata[1288..], expected_swaps);
|
||||
println!("{}", hex_calldata);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user