feat: Add estimated_amount_in to Swap. Add SwapBuilder
Use SwapBuilder everywhere inside crate Integration tests will be done later --- don't change below this line --- ENG-4696 Took 1 hour 56 minutes Took 4 minutes
This commit is contained in:
@@ -518,7 +518,6 @@ mod tests {
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use crate::encoding::models::Swap;
|
||||
|
||||
fn eth_chain() -> Chain {
|
||||
Chain::Ethereum
|
||||
@@ -539,8 +538,8 @@ mod tests {
|
||||
}
|
||||
|
||||
mod single {
|
||||
|
||||
use super::*;
|
||||
use crate::encoding::models::SwapBuilder;
|
||||
#[test]
|
||||
fn test_single_swap_strategy_encoder() {
|
||||
// Performs a single swap from WETH to DAI on a USV2 pool, with no grouping
|
||||
@@ -549,18 +548,16 @@ mod tests {
|
||||
let weth = Bytes::from_str("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").unwrap();
|
||||
let dai = Bytes::from_str("0x6b175474e89094c44da98b954eedeac495271d0f").unwrap();
|
||||
|
||||
let swap = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: dai.clone(),
|
||||
split: 0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
weth.clone(),
|
||||
dai.clone(),
|
||||
)
|
||||
.build();
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SingleSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
@@ -611,18 +608,16 @@ mod tests {
|
||||
|
||||
let checked_amount = BigUint::from_str("1_640_000000000000000000").unwrap();
|
||||
|
||||
let swap = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: dai.clone(),
|
||||
split: 0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
weth.clone(),
|
||||
dai.clone(),
|
||||
)
|
||||
.build();
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SingleSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
@@ -672,6 +667,7 @@ mod tests {
|
||||
|
||||
mod sequential {
|
||||
use super::*;
|
||||
use crate::encoding::models::SwapBuilder;
|
||||
|
||||
#[test]
|
||||
fn test_sequential_swap_strategy_encoder_no_permit2() {
|
||||
@@ -683,30 +679,26 @@ mod tests {
|
||||
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
|
||||
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
|
||||
|
||||
let swap_weth_wbtc = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_weth_wbtc = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0xBb2b8038a1640196FbE3e38816F3e67Cba72D940".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: wbtc.clone(),
|
||||
split: 0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
let swap_wbtc_usdc = Swap {
|
||||
component: ProtocolComponent {
|
||||
weth.clone(),
|
||||
wbtc.clone(),
|
||||
)
|
||||
.build();
|
||||
let swap_wbtc_usdc = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0x004375Dff511095CC5A197A54140a24eFEF3A416".to_string(),
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: wbtc.clone(),
|
||||
token_out: usdc.clone(),
|
||||
split: 0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
wbtc.clone(),
|
||||
usdc.clone(),
|
||||
)
|
||||
.build();
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SequentialSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
@@ -764,6 +756,7 @@ mod tests {
|
||||
|
||||
mod split {
|
||||
use super::*;
|
||||
use crate::encoding::models::SwapBuilder;
|
||||
|
||||
#[test]
|
||||
fn test_split_input_cyclic_swap() {
|
||||
@@ -779,8 +772,8 @@ mod tests {
|
||||
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
|
||||
|
||||
// USDC -> WETH (Pool 1) - 60% of input
|
||||
let swap_usdc_weth_pool1 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_usdc_weth_pool1 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), /* USDC-WETH USV3
|
||||
* Pool 1 */
|
||||
protocol_system: "uniswap_v3".to_string(),
|
||||
@@ -794,16 +787,15 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: usdc.clone(),
|
||||
token_out: weth.clone(),
|
||||
split: 0.6f64, // 60% of input
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
usdc.clone(),
|
||||
weth.clone(),
|
||||
)
|
||||
.split(0.6f64)
|
||||
.build();
|
||||
|
||||
// USDC -> WETH (Pool 2) - 40% of input (remaining)
|
||||
let swap_usdc_weth_pool2 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_usdc_weth_pool2 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".to_string(), /* USDC-WETH USV3
|
||||
* Pool 2 */
|
||||
protocol_system: "uniswap_v3".to_string(),
|
||||
@@ -817,16 +809,14 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: usdc.clone(),
|
||||
token_out: weth.clone(),
|
||||
split: 0f64,
|
||||
user_data: None, // Remaining 40%
|
||||
protocol_state: None,
|
||||
};
|
||||
usdc.clone(),
|
||||
weth.clone(),
|
||||
)
|
||||
.build();
|
||||
|
||||
// WETH -> USDC (Pool 2)
|
||||
let swap_weth_usdc_pool2 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_weth_usdc_pool2 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc".to_string(), /* USDC-WETH USV2
|
||||
* Pool 2 */
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
@@ -840,13 +830,10 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: usdc.clone(),
|
||||
split: 0.0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
|
||||
weth.clone(),
|
||||
usdc.clone(),
|
||||
)
|
||||
.build();
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SplitSwapStrategyEncoder::new(
|
||||
eth_chain(),
|
||||
@@ -935,8 +922,8 @@ mod tests {
|
||||
let weth = Bytes::from_str("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").unwrap();
|
||||
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
|
||||
|
||||
let swap_usdc_weth_v2 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_usdc_weth_v2 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc".to_string(), // USDC-WETH USV2
|
||||
protocol_system: "uniswap_v2".to_string(),
|
||||
static_attributes: {
|
||||
@@ -949,15 +936,13 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: usdc.clone(),
|
||||
token_out: weth.clone(),
|
||||
split: 0.0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
usdc.clone(),
|
||||
weth.clone(),
|
||||
)
|
||||
.build();
|
||||
|
||||
let swap_weth_usdc_v3_pool1 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_weth_usdc_v3_pool1 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), /* USDC-WETH USV3
|
||||
* Pool 1 */
|
||||
protocol_system: "uniswap_v3".to_string(),
|
||||
@@ -971,17 +956,16 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: usdc.clone(),
|
||||
split: 0.6f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
weth.clone(),
|
||||
usdc.clone(),
|
||||
)
|
||||
.split(0.6f64)
|
||||
.build();
|
||||
|
||||
let swap_weth_usdc_v3_pool2 = Swap {
|
||||
component: ProtocolComponent {
|
||||
let swap_weth_usdc_v3_pool2 = SwapBuilder::new(
|
||||
ProtocolComponent {
|
||||
id: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".to_string(), /* USDC-WETH USV3
|
||||
* Pool 2 */
|
||||
* Pool 1 */
|
||||
protocol_system: "uniswap_v3".to_string(),
|
||||
static_attributes: {
|
||||
let mut attrs = HashMap::new();
|
||||
@@ -993,12 +977,10 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: usdc.clone(),
|
||||
split: 0.0f64,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
};
|
||||
weth.clone(),
|
||||
usdc.clone(),
|
||||
)
|
||||
.build();
|
||||
|
||||
let swap_encoder_registry = get_swap_encoder_registry();
|
||||
let encoder = SplitSwapStrategyEncoder::new(
|
||||
|
||||
Reference in New Issue
Block a user