From 82eebf9b807d48c1d94a13aee8750263f011b9cd Mon Sep 17 00:00:00 2001 From: woocash2 Date: Mon, 14 Oct 2024 15:29:22 +0200 Subject: [PATCH] fmt --- amm/contracts/router_v2/lib.rs | 60 ++++++++++++++++++++-------------- amm/traits/router_v2.rs | 6 +--- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/amm/contracts/router_v2/lib.rs b/amm/contracts/router_v2/lib.rs index f217edc..0e6a270 100755 --- a/amm/contracts/router_v2/lib.rs +++ b/amm/contracts/router_v2/lib.rs @@ -64,7 +64,10 @@ pub mod router_v2 { /// Returns StablePool for `pool_id`. /// Adds the StablePool to the cache. #[inline] - fn get_and_cache_stable_pool(&mut self, pool_id: AccountId) -> Result { + fn get_and_cache_stable_pool( + &mut self, + pool_id: AccountId, + ) -> Result { match self.get_and_cache_pool(pool_id)? { Pool::StablePool(pool) => Ok(pool), Pool::Pair(_) => Err(RouterV2Error::InvalidPoolAddress), @@ -131,11 +134,9 @@ pub mod router_v2 { let n_pools = path.len(); let mut amounts = vec![0; n_pools + 1]; amounts[n_pools] = amount_out; - amounts[n_pools - 1] = self.get_and_cache_pool(path[n_pools - 1].pool_id)?.get_amount_in( - path[n_pools - 1].token_in, - token_out, - amount_out, - )?; + amounts[n_pools - 1] = self + .get_and_cache_pool(path[n_pools - 1].pool_id)? + .get_amount_in(path[n_pools - 1].token_in, token_out, amount_out)?; for i in (0..n_pools - 1).rev() { amounts[i] = self.get_and_cache_pool(path[i].pool_id)?.get_amount_in( path[i].token_in, @@ -166,11 +167,9 @@ pub mod router_v2 { amounts[i], )?; } - amounts[n_pools] = self.get_and_cache_pool(path[n_pools - 1].pool_id)?.get_amount_out( - path[n_pools - 1].token_in, - token_out, - amounts[n_pools - 1], - )?; + amounts[n_pools] = self + .get_and_cache_pool(path[n_pools - 1].pool_id)? + .get_amount_out(path[n_pools - 1].token_in, token_out, amounts[n_pools - 1])?; Ok(amounts) } @@ -205,7 +204,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != token_out && to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != token_out && to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let amounts = self.calculate_amounts_out(amount_in, &path, token_out)?; ensure!( @@ -233,7 +235,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != token_out && to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != token_out && to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let amounts = self.calculate_amounts_in(amount_out, &path, token_out)?; ensure!( @@ -260,7 +265,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != token_out && to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != token_out && to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let received_value = self.env().transferred_value(); let wnative = self.wnative; @@ -286,7 +294,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let wnative = self.wnative; let amounts = self.calculate_amounts_in(amount_out, &path, wnative)?; @@ -317,7 +328,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let wnative = self.wnative; let amounts = self.calculate_amounts_out(amount_in, &path, wnative)?; @@ -348,7 +362,10 @@ pub mod router_v2 { deadline: u64, ) -> Result, RouterV2Error> { check_timestamp(deadline)?; - ensure!(to != token_out && to != self.env().account_id(), RouterV2Error::InvalidRecipient); + ensure!( + to != token_out && to != self.env().account_id(), + RouterV2Error::InvalidRecipient + ); ensure!(!path.is_empty(), RouterV2Error::EmptyPath); let wnative = self.wnative; let received_native = self.env().transferred_value(); @@ -537,13 +554,8 @@ pub mod router_v2 { to: AccountId, deadline: u64, ) -> Result, RouterV2Error> { - self.get_and_cache_stable_pool(pool)?.remove_liquidity_by_share( - share_amount, - min_amounts, - to, - deadline, - self.wnative, - ) + self.get_and_cache_stable_pool(pool)? + .remove_liquidity_by_share(share_amount, min_amounts, to, deadline, self.wnative) } } diff --git a/amm/traits/router_v2.rs b/amm/traits/router_v2.rs index bd98ab2..f972dd2 100644 --- a/amm/traits/router_v2.rs +++ b/amm/traits/router_v2.rs @@ -1,9 +1,5 @@ use crate::{Balance, FactoryError, MathError, PairError, StablePoolError}; -use ink::{ - prelude::vec::Vec, - primitives::AccountId, - LangError, -}; +use ink::{prelude::vec::Vec, primitives::AccountId, LangError}; use psp22::PSP22Error; /// Specifies the pool for the trade and the input token of this trade (token to sell).