From a838941b73b89325723c8ecf920db4004e3f8a1c Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:33:10 -0500 Subject: [PATCH] Refactor code to replace 'meta.currency' with 'currency' (#39) This commit refines the uniswap-v3-sdk's source code by replacing occurrences of '.meta.currency' with '.currency'. The change covers several .rs files, from 'swap_router.rs' to 'nonfungible_position_manager.rs', effectively streamlining the code for improved clarity and readability. The 'uniswap-sdk-core' version is also updated from 0.15.0 to 0.16.0. --- Cargo.toml | 4 +- src/entities/pool.rs | 16 +- src/entities/route.rs | 32 ++-- src/entities/trade.rs | 177 ++++++++--------------- src/extensions/price_tick_conversions.rs | 5 +- src/nonfungible_position_manager.rs | 14 +- src/swap_router.rs | 28 ++-- src/utils/mod.rs | 6 +- src/utils/price_tick_conversions.rs | 9 +- 9 files changed, 106 insertions(+), 185 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55dfcc3..6a3a628 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-v3-sdk" -version = "0.24.1" +version = "0.24.2" edition = "2021" authors = ["Shuhui Luo "] description = "Uniswap V3 SDK for Rust" @@ -30,7 +30,7 @@ regex = { version = "1.10", optional = true } ruint = "1.11" serde_json = { version = "1.0", optional = true } thiserror = "1.0" -uniswap-sdk-core = "0.15.0" +uniswap-sdk-core = "0.16.0" uniswap_v3_math = "0.4.1" [features] diff --git a/src/entities/pool.rs b/src/entities/pool.rs index a7bfdf5..73712e5 100644 --- a/src/entities/pool.rs +++ b/src/entities/pool.rs @@ -222,9 +222,9 @@ where input_amount: CurrencyAmount, sqrt_price_limit_x96: Option, ) -> Result<(CurrencyAmount, Self)> { - assert!(self.involves_token(&input_amount.meta.currency), "TOKEN"); + assert!(self.involves_token(&input_amount.currency), "TOKEN"); - let zero_for_one = input_amount.meta.currency.equals(&self.token0); + let zero_for_one = input_amount.currency.equals(&self.token0); let (output_amount, sqrt_ratio_x96, liquidity, _) = self._swap( zero_for_one, @@ -263,9 +263,9 @@ where output_amount: CurrencyAmount, sqrt_price_limit_x96: Option, ) -> Result<(CurrencyAmount, Self)> { - assert!(self.involves_token(&output_amount.meta.currency), "TOKEN"); + assert!(self.involves_token(&output_amount.currency), "TOKEN"); - let zero_for_one = output_amount.meta.currency.equals(&self.token1); + let zero_for_one = output_amount.currency.equals(&self.token1); let (input_amount, sqrt_ratio_x96, liquidity, _) = self._swap( zero_for_one, @@ -696,7 +696,7 @@ mod tests { fn get_output_amount_usdc_to_dai() -> Result<()> { let (output_amount, _) = POOL.get_output_amount(CurrencyAmount::from_raw_amount(USDC.clone(), 100)?, None)?; - assert!(output_amount.meta.currency.equals(&DAI.clone())); + assert!(output_amount.currency.equals(&DAI.clone())); assert_eq!(output_amount.quotient(), 98.into()); Ok(()) } @@ -705,7 +705,7 @@ mod tests { fn get_output_amount_dai_to_usdc() -> Result<()> { let (output_amount, _) = POOL.get_output_amount(CurrencyAmount::from_raw_amount(DAI.clone(), 100)?, None)?; - assert!(output_amount.meta.currency.equals(&USDC.clone())); + assert!(output_amount.currency.equals(&USDC.clone())); assert_eq!(output_amount.quotient(), 98.into()); Ok(()) } @@ -714,7 +714,7 @@ mod tests { fn get_input_amount_usdc_to_dai() -> Result<()> { let (input_amount, _) = POOL.get_input_amount(CurrencyAmount::from_raw_amount(DAI.clone(), 98)?, None)?; - assert!(input_amount.meta.currency.equals(&USDC.clone())); + assert!(input_amount.currency.equals(&USDC.clone())); assert_eq!(input_amount.quotient(), 100.into()); Ok(()) } @@ -723,7 +723,7 @@ mod tests { fn get_input_amount_dai_to_usdc() -> Result<()> { let (input_amount, _) = POOL.get_input_amount(CurrencyAmount::from_raw_amount(USDC.clone(), 98)?, None)?; - assert!(input_amount.meta.currency.equals(&DAI.clone())); + assert!(input_amount.currency.equals(&DAI.clone())); assert_eq!(input_amount.quotient(), 100.into()); Ok(()) } diff --git a/src/entities/route.rs b/src/entities/route.rs index 5f93aa5..86af5fc 100644 --- a/src/entities/route.rs +++ b/src/entities/route.rs @@ -213,8 +213,8 @@ mod tests { let mut route = Route::new(vec![POOL_0_1.clone()], TOKEN0.clone(), TOKEN1.clone()); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.2000"); - assert_eq!(price.meta.base_currency, TOKEN0.clone()); - assert_eq!(price.meta.quote_currency, TOKEN1.clone()); + assert_eq!(price.base_currency, TOKEN0.clone()); + assert_eq!(price.quote_currency, TOKEN1.clone()); } #[test] @@ -229,8 +229,8 @@ mod tests { let mut route = Route::new(vec![POOL_0_1.clone()], TOKEN1.clone(), TOKEN0.clone()); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "5.0000"); - assert_eq!(price.meta.base_currency, TOKEN1.clone()); - assert_eq!(price.meta.quote_currency, TOKEN0.clone()); + assert_eq!(price.base_currency, TOKEN1.clone()); + assert_eq!(price.quote_currency, TOKEN0.clone()); } #[test] @@ -242,8 +242,8 @@ mod tests { ); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.1000"); - assert_eq!(price.meta.base_currency, TOKEN0.clone()); - assert_eq!(price.meta.quote_currency, TOKEN2.clone()); + assert_eq!(price.base_currency, TOKEN0.clone()); + assert_eq!(price.quote_currency, TOKEN2.clone()); } #[test] @@ -255,8 +255,8 @@ mod tests { ); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "10.0000"); - assert_eq!(price.meta.base_currency, TOKEN2.clone()); - assert_eq!(price.meta.quote_currency, TOKEN0.clone()); + assert_eq!(price.base_currency, TOKEN2.clone()); + assert_eq!(price.quote_currency, TOKEN0.clone()); } #[test] @@ -264,8 +264,8 @@ mod tests { let mut route = Route::new(vec![POOL_0_WETH.clone()], ETHER.clone(), TOKEN0.clone()); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.3333"); - assert_eq!(price.meta.base_currency, ETHER.clone()); - assert_eq!(price.meta.quote_currency, TOKEN0.clone()); + assert_eq!(price.base_currency, ETHER.clone()); + assert_eq!(price.quote_currency, TOKEN0.clone()); } #[test] @@ -273,8 +273,8 @@ mod tests { let mut route = Route::new(vec![POOL_1_WETH.clone()], TOKEN1.clone(), WETH.clone()); let price = route.mid_price().unwrap(); assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.1429"); - assert_eq!(price.meta.base_currency, TOKEN1.clone()); - assert_eq!(price.meta.quote_currency, WETH.clone()); + assert_eq!(price.base_currency, TOKEN1.clone()); + assert_eq!(price.quote_currency, WETH.clone()); } #[test] @@ -289,8 +289,8 @@ mod tests { price.to_significant(4, Rounding::RoundHalfUp).unwrap(), "0.009524" ); - assert_eq!(price.meta.base_currency, ETHER.clone()); - assert_eq!(price.meta.quote_currency, WETH.clone()); + assert_eq!(price.base_currency, ETHER.clone()); + assert_eq!(price.quote_currency, WETH.clone()); } #[test] @@ -305,8 +305,8 @@ mod tests { price.to_significant(4, Rounding::RoundHalfUp).unwrap(), "0.009524" ); - assert_eq!(price.meta.base_currency, WETH.clone()); - assert_eq!(price.meta.quote_currency, ETHER.clone()); + assert_eq!(price.base_currency, WETH.clone()); + assert_eq!(price.quote_currency, ETHER.clone()); } } } diff --git a/src/entities/trade.rs b/src/entities/trade.rs index a318ec8..a6e37a0 100644 --- a/src/entities/trade.rs +++ b/src/entities/trade.rs @@ -17,17 +17,15 @@ pub fn trade_comparator assert!( a.swaps[0] .input_amount - .meta .currency - .equals(&b.swaps[0].input_amount.meta.currency), + .equals(&b.swaps[0].input_amount.currency), "INPUT_CURRENCY" ); assert!( a.swaps[0] .output_amount - .meta .currency - .equals(&b.swaps[0].output_amount.meta.currency), + .equals(&b.swaps[0].output_amount.currency), "OUTPUT_CURRENCY" ); let a_input = a.input_amount_ref().unwrap().as_fraction(); @@ -117,8 +115,8 @@ where /// * `swaps`: The routes through which the trade occurs /// * `trade_type`: The type of trade, exact input or exact output fn new(swaps: Vec>, trade_type: TradeType) -> Result { - let input_currency = &swaps[0].input_amount.meta.currency.wrapped(); - let output_currency = &swaps[0].output_amount.meta.currency.wrapped(); + let input_currency = &swaps[0].input_amount.currency.wrapped(); + let output_currency = &swaps[0].output_amount.currency.wrapped(); for Swap { route, .. } in &swaps { assert!( input_currency.equals(&route.input.wrapped()), @@ -196,11 +194,7 @@ where match trade_type { TradeType::ExactInput => { assert!( - amount - .meta - .currency - .wrapped() - .equals(&route.input.wrapped()), + amount.currency.wrapped().equals(&route.input.wrapped()), "INPUT" ); amounts[0] = amount.wrapped()?; @@ -222,11 +216,7 @@ where } TradeType::ExactOutput => { assert!( - amount - .meta - .currency - .wrapped() - .equals(&route.output.wrapped()), + amount.currency.wrapped().equals(&route.output.wrapped()), "OUTPUT" ); amounts[length - 1] = amount.wrapped()?; @@ -341,21 +331,19 @@ where let token_out = currency_out.wrapped(); for pool in &pools { // pool irrelevant - if !pool.token0.equals(&amount_in.meta.currency) - && !pool.token1.equals(&amount_in.meta.currency) + if !pool.token0.equals(&amount_in.currency) && !pool.token1.equals(&amount_in.currency) { continue; } let (amount_out, _) = pool.get_output_amount(amount_in.clone(), None)?; // we have arrived at the output token, so this is the final trade of one of the paths - if !amount_out.meta.currency.is_native() && amount_out.meta.currency.equals(&token_out) - { + if !amount_out.currency.is_native() && amount_out.currency.equals(&token_out) { let mut next_pools = current_pools.clone(); next_pools.push(pool.clone()); let trade = Self::from_route( Route::new( next_pools, - currency_amount_in.meta.currency.clone(), + currency_amount_in.currency.clone(), currency_out.clone(), ), currency_amount_in.wrapped()?, @@ -432,21 +420,21 @@ where let token_in = currency_in.wrapped(); for pool in &pools { // pool irrelevant - if !pool.token0.equals(&amount_out.meta.currency) - && !pool.token1.equals(&amount_out.meta.currency) + if !pool.token0.equals(&amount_out.currency) + && !pool.token1.equals(&amount_out.currency) { continue; } let (amount_in, _) = pool.get_input_amount(amount_out.clone(), None)?; // we have arrived at the input token, so this is the first trade of one of the paths - if amount_in.meta.currency.equals(&token_in) { + if amount_in.currency.equals(&token_in) { let mut next_pools = vec![pool.clone()]; next_pools.extend(current_pools.clone()); let trade = Self::from_route( Route::new( next_pools, currency_in.clone(), - currency_amount_out.meta.currency.clone(), + currency_amount_out.currency.clone(), ), currency_amount_out.wrapped()?, TradeType::ExactOutput, @@ -502,7 +490,7 @@ where return Ok(input_amount.clone()); } let mut total = - CurrencyAmount::from_raw_amount(self.swaps[0].input_amount.meta.currency.clone(), 0)?; + CurrencyAmount::from_raw_amount(self.swaps[0].input_amount.currency.clone(), 0)?; for Swap { input_amount, .. } in &self.swaps { total = total.add(input_amount)?; } @@ -521,7 +509,7 @@ where return Ok(output_amount.clone()); } let mut total = - CurrencyAmount::from_raw_amount(self.swaps[0].output_amount.meta.currency.clone(), 0)?; + CurrencyAmount::from_raw_amount(self.swaps[0].output_amount.currency.clone(), 0)?; for Swap { output_amount, .. } in &self.swaps { total = total.add(output_amount)?; } @@ -542,8 +530,8 @@ where let input_amount = self.input_amount()?; let output_amount = self.output_amount()?; let execution_price = Price::new( - input_amount.meta.currency.clone(), - output_amount.meta.currency.clone(), + input_amount.currency.clone(), + output_amount.currency.clone(), input_amount.quotient(), output_amount.quotient(), ); @@ -557,7 +545,7 @@ where return Ok(price_impact.clone()); } let mut spot_output_amount = - CurrencyAmount::from_raw_amount(self.output_amount()?.meta.currency, 0)?; + CurrencyAmount::from_raw_amount(self.output_amount()?.currency.clone(), 0)?; for Swap { route, input_amount, @@ -600,7 +588,7 @@ where * Percent::new(output_amount.quotient(), 1)) .quotient(); CurrencyAmount::from_raw_amount( - output_amount.meta.currency.clone(), + output_amount.currency.clone(), slippage_adjusted_amount_out, ) .map_err(|e| e.into()) @@ -628,11 +616,8 @@ where let slippage_adjusted_amount_in = ((Percent::new(1, 1) + slippage_tolerance) * Percent::new(amount_in.quotient(), 1)) .quotient(); - CurrencyAmount::from_raw_amount( - amount_in.meta.currency.clone(), - slippage_adjusted_amount_in, - ) - .map_err(|e| e.into()) + CurrencyAmount::from_raw_amount(amount_in.currency.clone(), slippage_adjusted_amount_in) + .map_err(|e| e.into()) } /// Return the execution price after accounting for slippage tolerance @@ -645,8 +630,8 @@ where slippage_tolerance: Percent, ) -> Result> { Ok(Price::new( - self.input_amount()?.meta.currency.clone(), - self.output_amount()?.meta.currency.clone(), + self.input_amount()?.currency.clone(), + self.output_amount()?.currency.clone(), self.maximum_amount_in(slippage_tolerance.clone(), None)? .quotient(), self.minimum_amount_out(slippage_tolerance, None)? @@ -673,8 +658,8 @@ mod tests { .to_u128() .unwrap(); Pool::new_with_tick_data_provider( - reserve0.meta.currency.clone(), - reserve1.meta.currency.clone(), + reserve0.currency.clone(), + reserve1.currency.clone(), fee_amount, sqrt_ratio_x96, liquidity, @@ -765,8 +750,8 @@ mod tests { TradeType::ExactInput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, ETHER.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, TOKEN0.clone()); + assert_eq!(trade.input_amount().unwrap().currency, ETHER.clone()); + assert_eq!(trade.output_amount().unwrap().currency, TOKEN0.clone()); } #[test] @@ -777,8 +762,8 @@ mod tests { TradeType::ExactOutput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, ETHER.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, TOKEN0.clone()); + assert_eq!(trade.input_amount().unwrap().currency, ETHER.clone()); + assert_eq!(trade.output_amount().unwrap().currency, TOKEN0.clone()); } #[test] @@ -789,8 +774,8 @@ mod tests { TradeType::ExactOutput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, TOKEN0.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, ETHER.clone()); + assert_eq!(trade.input_amount().unwrap().currency, TOKEN0.clone()); + assert_eq!(trade.output_amount().unwrap().currency, ETHER.clone()); } #[test] @@ -801,8 +786,8 @@ mod tests { TradeType::ExactInput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, TOKEN0.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, ETHER.clone()); + assert_eq!(trade.input_amount().unwrap().currency, TOKEN0.clone()); + assert_eq!(trade.output_amount().unwrap().currency, ETHER.clone()); } } @@ -819,8 +804,8 @@ mod tests { TradeType::ExactInput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, ETHER.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, TOKEN0.clone()); + assert_eq!(trade.input_amount().unwrap().currency, ETHER.clone()); + assert_eq!(trade.output_amount().unwrap().currency, TOKEN0.clone()); } #[test] @@ -843,8 +828,8 @@ mod tests { TradeType::ExactOutput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, ETHER.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, TOKEN0.clone()); + assert_eq!(trade.input_amount().unwrap().currency, ETHER.clone()); + assert_eq!(trade.output_amount().unwrap().currency, TOKEN0.clone()); } #[test] @@ -867,8 +852,8 @@ mod tests { TradeType::ExactOutput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, TOKEN0.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, ETHER.clone()); + assert_eq!(trade.input_amount().unwrap().currency, TOKEN0.clone()); + assert_eq!(trade.output_amount().unwrap().currency, ETHER.clone()); } #[test] @@ -891,8 +876,8 @@ mod tests { TradeType::ExactInput, ) .unwrap(); - assert_eq!(trade.input_amount().unwrap().meta.currency, TOKEN0.clone()); - assert_eq!(trade.output_amount().unwrap().meta.currency, ETHER.clone()); + assert_eq!(trade.input_amount().unwrap().currency, TOKEN0.clone()); + assert_eq!(trade.output_amount().unwrap().currency, ETHER.clone()); } #[test] @@ -1703,10 +1688,7 @@ mod tests { .unwrap() .take(); assert_eq!(result.len(), 2); - assert_eq!( - result[0].input_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[0].input_amount().unwrap().currency, ETHER.clone()); assert_eq!( result[0].swaps[0].route.token_path, vec![ @@ -1716,22 +1698,13 @@ mod tests { TOKEN3.clone(), ] ); - assert_eq!( - result[0].output_amount().unwrap().meta.currency, - TOKEN3.clone() - ); - assert_eq!( - result[1].input_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[0].output_amount().unwrap().currency, TOKEN3.clone()); + assert_eq!(result[1].input_amount().unwrap().currency, ETHER.clone()); assert_eq!( result[1].swaps[0].route.token_path, vec![ETHER.wrapped(), TOKEN0.clone(), TOKEN3.clone()] ); - assert_eq!( - result[1].output_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[1].output_amount().unwrap().currency, TOKEN3.clone()); } #[test] @@ -1753,22 +1726,13 @@ mod tests { .unwrap() .take(); assert_eq!(result.len(), 2); - assert_eq!( - result[0].input_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[0].input_amount().unwrap().currency, TOKEN3.clone()); assert_eq!( result[0].swaps[0].route.token_path, vec![TOKEN3.clone(), TOKEN0.clone(), ETHER.wrapped()] ); - assert_eq!( - result[0].output_amount().unwrap().meta.currency, - ETHER.clone() - ); - assert_eq!( - result[1].input_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[0].output_amount().unwrap().currency, ETHER.clone()); + assert_eq!(result[1].input_amount().unwrap().currency, TOKEN3.clone()); assert_eq!( result[1].swaps[0].route.token_path, vec![ @@ -1778,10 +1742,7 @@ mod tests { ETHER.wrapped(), ] ); - assert_eq!( - result[1].output_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[1].output_amount().unwrap().currency, ETHER.clone()); } } @@ -2209,10 +2170,7 @@ mod tests { .unwrap() .take(); assert_eq!(result.len(), 2); - assert_eq!( - result[0].input_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[0].input_amount().unwrap().currency, ETHER.clone()); assert_eq!( result[0].swaps[0].route.token_path, vec![ @@ -2222,22 +2180,13 @@ mod tests { TOKEN3.clone(), ] ); - assert_eq!( - result[0].output_amount().unwrap().meta.currency, - TOKEN3.clone() - ); - assert_eq!( - result[1].input_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[0].output_amount().unwrap().currency, TOKEN3.clone()); + assert_eq!(result[1].input_amount().unwrap().currency, ETHER.clone()); assert_eq!( result[1].swaps[0].route.token_path, vec![ETHER.wrapped(), TOKEN0.clone(), TOKEN3.clone()] ); - assert_eq!( - result[1].output_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[1].output_amount().unwrap().currency, TOKEN3.clone()); } #[test] @@ -2259,22 +2208,13 @@ mod tests { .unwrap() .take(); assert_eq!(result.len(), 2); - assert_eq!( - result[0].input_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[0].input_amount().unwrap().currency, TOKEN3.clone()); assert_eq!( result[0].swaps[0].route.token_path, vec![TOKEN3.clone(), TOKEN0.clone(), ETHER.wrapped()] ); - assert_eq!( - result[0].output_amount().unwrap().meta.currency, - ETHER.clone() - ); - assert_eq!( - result[1].input_amount().unwrap().meta.currency, - TOKEN3.clone() - ); + assert_eq!(result[0].output_amount().unwrap().currency, ETHER.clone()); + assert_eq!(result[1].input_amount().unwrap().currency, TOKEN3.clone()); assert_eq!( result[1].swaps[0].route.token_path, vec![ @@ -2284,10 +2224,7 @@ mod tests { ETHER.wrapped(), ] ); - assert_eq!( - result[1].output_amount().unwrap().meta.currency, - ETHER.clone() - ); + assert_eq!(result[1].output_amount().unwrap().currency, ETHER.clone()); } } } diff --git a/src/extensions/price_tick_conversions.rs b/src/extensions/price_tick_conversions.rs index 7ea1266..1400b2f 100644 --- a/src/extensions/price_tick_conversions.rs +++ b/src/extensions/price_tick_conversions.rs @@ -116,10 +116,7 @@ pub fn sqrt_ratio_x96_to_price( /// Same as [`price_to_closest_tick`] but returns [`MIN_TICK`] or [`MAX_TICK`] if the price is outside Uniswap's range. pub fn price_to_closest_tick_safe(price: &Price) -> Result { - let sorted = price - .meta - .base_currency - .sorts_before(&price.meta.quote_currency)?; + let sorted = price.base_currency.sorts_before(&price.quote_currency)?; if price.as_fraction() < *MIN_PRICE { Ok(if sorted { MIN_TICK } else { MAX_TICK }) } else if price.as_fraction() > *MAX_PRICE { diff --git a/src/nonfungible_position_manager.rs b/src/nonfungible_position_manager.rs index 36b7fa0..c2dd8dd 100644 --- a/src/nonfungible_position_manager.rs +++ b/src/nonfungible_position_manager.rs @@ -215,8 +215,8 @@ pub fn add_call_parameters

( fn encode_collect(options: CollectOptions) -> Vec> { let mut calldatas: Vec> = vec![]; - let involves_eth = options.expected_currency_owed0.meta.currency.is_native() - || options.expected_currency_owed1.meta.currency.is_native(); + let involves_eth = options.expected_currency_owed0.currency.is_native() + || options.expected_currency_owed1.currency.is_native(); // collect calldatas.push( @@ -239,13 +239,13 @@ fn encode_collect(options: CollectOptions) -> Vec> { let eth_amount: U256; let token: Token; let token_amount: U256; - if options.expected_currency_owed0.meta.currency.is_native() { + if options.expected_currency_owed0.currency.is_native() { eth_amount = big_int_to_u256(options.expected_currency_owed0.quotient()); - token = options.expected_currency_owed1.meta.currency.wrapped(); + token = options.expected_currency_owed1.currency.wrapped(); token_amount = big_int_to_u256(options.expected_currency_owed1.quotient()); } else { eth_amount = big_int_to_u256(options.expected_currency_owed1.quotient()); - token = options.expected_currency_owed0.meta.currency.wrapped(); + token = options.expected_currency_owed0.currency.wrapped(); token_amount = big_int_to_u256(options.expected_currency_owed0.quotient()); } @@ -343,11 +343,11 @@ pub fn remove_call_parameters

( token_id, // add the underlying value to the expected currency already owed expected_currency_owed0: expected_currency_owed0.add(&CurrencyAmount::from_raw_amount( - expected_currency_owed0.meta.currency.clone(), + expected_currency_owed0.currency.clone(), u256_to_big_int(amount0_min), )?)?, expected_currency_owed1: expected_currency_owed1.add(&CurrencyAmount::from_raw_amount( - expected_currency_owed1.meta.currency.clone(), + expected_currency_owed1.currency.clone(), u256_to_big_int(amount1_min), )?)?, recipient: options.collect_options.recipient, diff --git a/src/swap_router.rs b/src/swap_router.rs index a83afad..373539c 100644 --- a/src/swap_router.rs +++ b/src/swap_router.rs @@ -40,27 +40,17 @@ pub fn swap_call_parameters) -> Result { - let sorted = price - .meta - .base_currency - .sorts_before(&price.meta.quote_currency)?; + let sorted = price.base_currency.sorts_before(&price.quote_currency)?; let sqrt_ratio_x96 = if sorted { encode_sqrt_ratio_x96(price.numerator(), price.denominator()) } else { @@ -46,8 +43,8 @@ pub fn price_to_closest_tick(price: &Price) -> Result { }; let tick = get_tick_at_sqrt_ratio(sqrt_ratio_x96)?; let next_tick_price = tick_to_price( - price.meta.base_currency.clone(), - price.meta.quote_currency.clone(), + price.base_currency.clone(), + price.quote_currency.clone(), tick + 1, )?; Ok(if sorted {