@@ -44,7 +44,6 @@ pub fn encode_swap(
4444 sell_token : & Token ,
4545 buy_token : & Token ,
4646 amount_in : BigUint ,
47- expected_amount_out : BigUint ,
4847 chain : Chain ,
4948) -> miette:: Result < ( Solution , Transaction ) > {
5049 let solution = create_solution (
@@ -53,7 +52,6 @@ pub fn encode_swap(
5352 sell_token. clone ( ) ,
5453 buy_token. clone ( ) ,
5554 amount_in. clone ( ) ,
56- expected_amount_out. clone ( ) ,
5755 ) ?;
5856 let encoded_solution = {
5957 let encoder = TychoRouterEncoderBuilder :: new ( )
@@ -81,7 +79,6 @@ fn create_solution(
8179 sell_token : Token ,
8280 buy_token : Token ,
8381 amount_in : BigUint ,
84- expected_amount_out : BigUint ,
8582) -> miette:: Result < Solution > {
8683 let user_address = Bytes :: from_str ( USER_ADDR ) . into_diagnostic ( ) ?;
8784
@@ -92,26 +89,16 @@ fn create_solution(
9289 . estimated_amount_in ( amount_in. clone ( ) )
9390 . build ( ) ;
9491
95- // Compute a minimum amount out
96- //
97- // # ⚠️ Important Responsibility Note
98- // For maximum security, in production code, this minimum amount out should be computed
99- // from a third-party source.
100- let slippage = 0.0025 ; // 0.25% slippage
101- let bps = BigUint :: from ( 10_000u32 ) ;
102- let slippage_percent = BigUint :: from ( ( slippage * 10000.0 ) as u32 ) ;
103- let multiplier = & bps - slippage_percent;
104- let min_amount_out = ( expected_amount_out * & multiplier) / & bps;
105-
106- // Then we create a solution object with the previous swap
10792 Ok ( Solution {
10893 sender : user_address. clone ( ) ,
10994 receiver : user_address,
11095 given_token : sell_token. address ,
11196 given_amount : amount_in,
11297 checked_token : buy_token. address ,
11398 exact_out : false , // it's an exact in solution
114- checked_amount : min_amount_out,
99+ // We want to keep track of how bad the slippage really is and not just error at execution
100+ // time. NEVER DO THIS IN PRODUCTION!
101+ checked_amount : BigUint :: from ( 1u64 ) ,
115102 swaps : vec ! [ simple_swap] ,
116103 ..Default :: default ( )
117104 } )
0 commit comments