feat: Add SequentialSwap integration test with regular approvals
Improve docstrings --- don't change below this line --- ENG-4306 Took 20 minutes
This commit is contained in:
@@ -83,7 +83,7 @@ impl SingleSwapStrategyEncoder {
|
||||
Ok(Self { permit2, selector, swap_encoder_registry, router_address })
|
||||
}
|
||||
|
||||
/// Encodes information necessary for performing a single swap against a given executor for
|
||||
/// Encodes information necessary for performing a single hop against a given executor for
|
||||
/// a protocol.
|
||||
fn encode_swap_header(&self, executor_address: Bytes, protocol_data: Vec<u8>) -> Vec<u8> {
|
||||
let mut encoded = Vec::new();
|
||||
@@ -202,7 +202,7 @@ impl StrategyEncoder for SingleSwapStrategyEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the encoder for a swap strategy which supports single swaps.
|
||||
/// Represents the encoder for a swap strategy which supports sequential swaps.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
||||
@@ -253,7 +253,7 @@ impl SequentialSwapStrategyEncoder {
|
||||
})
|
||||
}
|
||||
|
||||
/// Encodes information necessary for performing a single swap against a given executor for
|
||||
/// Encodes information necessary for performing a single hop against a given executor for
|
||||
/// a protocol.
|
||||
fn encode_swap_header(&self, executor_address: Bytes, protocol_data: Vec<u8>) -> Vec<u8> {
|
||||
let mut encoded = Vec::new();
|
||||
@@ -373,7 +373,7 @@ impl StrategyEncoder for SequentialSwapStrategyEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the encoder for a swap strategy which supports single, sequential and split swaps.
|
||||
/// Represents the encoder for a swap strategy which supports split swaps.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
||||
@@ -439,7 +439,7 @@ impl SplitSwapStrategyEncoder {
|
||||
})
|
||||
}
|
||||
|
||||
/// Encodes information necessary for performing a single swap against a given executor for
|
||||
/// Encodes information necessary for performing a single hop against a given executor for
|
||||
/// a protocol as part of a split swap solution.
|
||||
fn encode_swap_header(
|
||||
&self,
|
||||
@@ -1416,8 +1416,6 @@ mod tests {
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: wbtc.clone(),
|
||||
// This represents the remaining 50%, but to avoid any rounding errors we set this to
|
||||
// 0 to signify "the remainder of the WETH value". It should still be very close to 50%
|
||||
split: 0f64,
|
||||
};
|
||||
let swap_wbtc_usdc = Swap {
|
||||
@@ -1459,6 +1457,68 @@ mod tests {
|
||||
println!("{}", _hex_calldata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sequential_swap_strategy_encoder_no_permit2() {
|
||||
// Note: This test does not assert anything. It is only used to obtain integration test
|
||||
// data for our router solidity test.
|
||||
//
|
||||
// Performs a split swap from WETH to USDC though WBTC and DAI using USV2 pools
|
||||
//
|
||||
// WETH ───(USV2)──> WBTC ───(USV2)──> USDC
|
||||
|
||||
let weth = weth();
|
||||
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
|
||||
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
|
||||
|
||||
let swap_weth_wbtc = Swap {
|
||||
component: ProtocolComponent {
|
||||
id: "0xBb2b8038a1640196FbE3e38816F3e67Cba72D940".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: wbtc.clone(),
|
||||
split: 0f64,
|
||||
};
|
||||
let swap_wbtc_usdc = Swap {
|
||||
component: ProtocolComponent {
|
||||
id: "0x004375Dff511095CC5A197A54140a24eFEF3A416".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: wbtc.clone(),
|
||||
token_out: usdc.clone(),
|
||||
split: 0f64,
|
||||
};
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SequentialSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
swap_encoder_registry,
|
||||
None,
|
||||
Bytes::from_str("0x3Ede3eCa2a72B3aeCC820E955B36f38437D01395").unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let solution = Solution {
|
||||
exact_out: false,
|
||||
given_token: weth,
|
||||
given_amount: BigUint::from_str("1_000000000000000000").unwrap(),
|
||||
checked_token: usdc,
|
||||
expected_amount: None,
|
||||
checked_amount: Some(BigUint::from_str("26173932").unwrap()),
|
||||
sender: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
receiver: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").unwrap(),
|
||||
swaps: vec![swap_weth_wbtc, swap_wbtc_usdc],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (calldata, _) = encoder
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("{}", _hex_calldata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_encoding_strategy_usv4() {
|
||||
// Performs a sequential swap from USDC to PEPE though ETH using two consecutive USV4 pools
|
||||
|
||||
Reference in New Issue
Block a user