Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
woocash2 committed Oct 14, 2024
1 parent 363e1dc commit 82eebf9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
60 changes: 36 additions & 24 deletions amm/contracts/router_v2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StablePool, RouterV2Error> {
fn get_and_cache_stable_pool(
&mut self,
pool_id: AccountId,
) -> Result<StablePool, RouterV2Error> {
match self.get_and_cache_pool(pool_id)? {
Pool::StablePool(pool) => Ok(pool),
Pool::Pair(_) => Err(RouterV2Error::InvalidPoolAddress),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -205,7 +204,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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!(
Expand Down Expand Up @@ -233,7 +235,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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!(
Expand All @@ -260,7 +265,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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;
Expand All @@ -286,7 +294,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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)?;
Expand Down Expand Up @@ -317,7 +328,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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)?;
Expand Down Expand Up @@ -348,7 +362,10 @@ pub mod router_v2 {
deadline: u64,
) -> Result<Vec<u128>, 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();
Expand Down Expand Up @@ -537,13 +554,8 @@ pub mod router_v2 {
to: AccountId,
deadline: u64,
) -> Result<Vec<u128>, 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)
}
}

Expand Down
6 changes: 1 addition & 5 deletions amm/traits/router_v2.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand Down

0 comments on commit 82eebf9

Please sign in to comment.