Skip to content

Commit

Permalink
Removed clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniezka1927 committed Dec 4, 2023
1 parent 159acca commit 6ee5921
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/contracts/collections/pool_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl PoolKeys {
Ok(())
}

#[allow(dead_code)]
pub fn remove(&mut self, pool_key: PoolKey) -> Result<(), InvariantError> {
let index = self
.pool_keys
Expand Down
1 change: 1 addition & 0 deletions src/contracts/collections/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl Pools {
Ok(())
}

#[allow(dead_code)]
pub fn remove(&mut self, pool_key: PoolKey) -> Result<(), InvariantError> {
self.get(pool_key)?;

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
contract::{CalculateSwapResult, Hop, QuoteResult},
contracts::{FeeTier, Pool, PoolKey, Position, Tick},
math::{
liquidity::Liquidity, percentage::Percentage, sqrt_price::sqrt_price::SqrtPrice,
liquidity::Liquidity, percentage::Percentage, ratio::sqrt_price::SqrtPrice,
token_amount::TokenAmount,
},
InvariantError,
Expand Down
7 changes: 6 additions & 1 deletion src/contracts/logic/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use decimal::*;
use traceable_result::*;

use crate::math::liquidity::Liquidity;
use crate::math::sqrt_price::sqrt_price::{calculate_sqrt_price, SqrtPrice};
use crate::math::ratio::sqrt_price::{calculate_sqrt_price, SqrtPrice};
use crate::math::token_amount::TokenAmount;
use crate::math::MAX_TICK;

Expand All @@ -19,6 +19,7 @@ pub struct SingleTokenLiquidity {
pub amount: TokenAmount,
}

#[allow(dead_code)]
pub fn get_liquidity(
x: TokenAmount,
y: TokenAmount,
Expand Down Expand Up @@ -92,6 +93,7 @@ pub fn get_liquidity(
})
}

#[allow(dead_code)]
pub fn get_liquidity_by_x(
x: TokenAmount,
lower_tick: i32,
Expand Down Expand Up @@ -164,6 +166,7 @@ pub fn get_liquidity_by_x_sqrt_price(
})
}

#[allow(dead_code)]
pub fn get_liquidity_by_y(
y: TokenAmount,
lower_tick: i32,
Expand All @@ -187,6 +190,7 @@ pub fn get_liquidity_by_y(
))
}

#[allow(dead_code)]
pub fn get_liquidity_by_y_sqrt_price(
y: TokenAmount,
lower_sqrt_price: SqrtPrice,
Expand Down Expand Up @@ -235,6 +239,7 @@ pub fn get_liquidity_by_y_sqrt_price(
})
}

#[allow(dead_code)]
pub fn calculate_x(
nominator: SqrtPrice,
denominator: SqrtPrice,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/storage/oracle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::math::types::sqrt_price::sqrt_price::SqrtPrice;
use crate::math::types::ratio::sqrt_price::SqrtPrice;
use ink::prelude::{vec, vec::Vec};

#[derive(Default, Debug, PartialEq, Clone, scale::Decode, scale::Encode)]
Expand Down
10 changes: 7 additions & 3 deletions src/contracts/storage/pool.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use super::{FeeTier, Oracle, Tick}; // Tickmap
// use crate::contracts::
use crate::{
contracts::PoolKey,
math::{
math::*,
sqrt_price::sqrt_price::calculate_sqrt_price,
clamm::*,
types::{
fee_growth::FeeGrowth,
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{log::get_tick_at_sqrt_price, sqrt_price::SqrtPrice},
ratio::{
log::get_tick_at_sqrt_price,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
},
token_amount::TokenAmount,
},
},
};

use decimal::*;
use ink::primitives::AccountId;
use traceable_result::*;
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/storage/position.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{Pool, PoolKey, Tick}; // Tickmap
use crate::{
math::{
math::*,
clamm::*,
types::{
fee_growth::{calculate_fee_growth_inside, FeeGrowth},
liquidity::Liquidity,
sqrt_price::sqrt_price::SqrtPrice,
ratio::sqrt_price::SqrtPrice,
token_amount::TokenAmount,
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/storage/tick.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::math::types::{
fee_growth::FeeGrowth, liquidity::Liquidity, sqrt_price::sqrt_price::calculate_sqrt_price,
sqrt_price::sqrt_price::SqrtPrice,
fee_growth::FeeGrowth, liquidity::Liquidity, ratio::sqrt_price::calculate_sqrt_price,
ratio::sqrt_price::SqrtPrice,
};

use traceable_result::*;
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Tick {
mod tests {
use decimal::{Decimal, Factories};

use crate::math::math::calculate_max_liquidity_per_tick;
use crate::math::clamm::calculate_max_liquidity_per_tick;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/storage/tickmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::contracts::PoolKey;
use crate::math::{
types::sqrt_price::sqrt_price::{calculate_sqrt_price, SqrtPrice},
types::ratio::sqrt_price::{calculate_sqrt_price, SqrtPrice},
MAX_TICK,
};
use ink::storage::Mapping;
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
extern crate alloc;
mod contracts;
pub mod math;

#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum InvariantError {
Expand Down Expand Up @@ -41,15 +40,15 @@ pub mod contract {
use crate::contracts::PoolKeys;
use crate::contracts::Tick;
use crate::contracts::Tickmap;
use crate::contracts::{FeeTier, FeeTiers, PoolKey, Pools, Position, Positions, Ticks}; //
use crate::contracts::{FeeTier, FeeTiers, PoolKey, Pools, Position, Positions, Ticks};
use crate::math::calculate_min_amount_out;
use crate::math::check_tick;
use crate::math::percentage::Percentage;
use crate::math::sqrt_price::log::get_tick_at_sqrt_price;
use crate::math::sqrt_price::sqrt_price::SqrtPrice;
use crate::math::ratio::log::get_tick_at_sqrt_price;
use crate::math::ratio::sqrt_price::SqrtPrice;
use crate::math::token_amount::TokenAmount;
use crate::math::types::liquidity::Liquidity;
// use crate
use crate::math::types::liquidity::Liquidity; //
// use crate
use crate::math::{compute_swap_step, MAX_SQRT_PRICE, MIN_SQRT_PRICE};
use decimal::*;
use ink::contract_ref;
Expand Down Expand Up @@ -189,7 +188,7 @@ pub mod contract {
sqrt_price_limit: SqrtPrice,
) -> Result<CalculateSwapResult, InvariantError> {
let current_timestamp = self.env().block_timestamp();
let caller = self.env().caller();
// let caller = self.env().caller();
if amount.is_zero() {
return Err(InvariantError::AmountIsZero);
}
Expand Down Expand Up @@ -300,6 +299,7 @@ pub mod contract {
})
}

#[allow(dead_code)]
fn remove_tick(&mut self, key: PoolKey, index: i32) -> Result<(), InvariantError> {
self.ticks.remove(key, index)?;

Expand Down Expand Up @@ -557,7 +557,7 @@ pub mod contract {
crossed_tick_indexes.push(tick.index);
}

if crossed_tick_indexes.len() > 0 {
if !crossed_tick_indexes.is_empty() {
self.emit_cross_tick_event(caller, pool_key, crossed_tick_indexes);
}

Expand Down Expand Up @@ -1070,8 +1070,8 @@ pub mod contract {
use crate::contracts::{get_liquidity, get_liquidity_by_x, get_liquidity_by_y};
use crate::math::fee_growth::FeeGrowth;
use crate::math::get_delta_y;
use crate::math::sqrt_price::log::get_tick_at_sqrt_price;
use crate::math::sqrt_price::sqrt_price::{calculate_sqrt_price, get_max_tick};
use crate::math::ratio::log::get_tick_at_sqrt_price;
use crate::math::ratio::sqrt_price::{calculate_sqrt_price, get_max_tick};
use crate::math::MAX_TICK;
use ink::prelude::vec;
use ink::prelude::vec::Vec;

Check warning on line 1077 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Uint and e2e tests + linit

unused import: `ink::prelude::vec::Vec`
Expand Down
2 changes: 1 addition & 1 deletion src/math/math.rs → src/math/clamm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use decimal::*;
use traceable_result::*;

use crate::math::consts::*;
use crate::math::types::{liquidity::*, percentage::*, sqrt_price::sqrt_price::*, token_amount::*};
use crate::math::types::{liquidity::*, percentage::*, ratio::sqrt_price::*, token_amount::*};

#[derive(PartialEq, Debug, Copy, Clone)]
pub struct SwapResult {
Expand Down
4 changes: 2 additions & 2 deletions src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod clamm;
pub mod consts;
pub mod math;
pub mod types;
pub use clamm::*;
pub use consts::*;
pub use math::*;
pub use types::*;
2 changes: 1 addition & 1 deletion src/math/types/fee_growth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
use super::*;
use crate::math::consts::MAX_TICK;
// use crate::math::calculate_sqrt_price;
use crate::math::types::sqrt_price::sqrt_price::SqrtPrice;
use crate::math::types::ratio::sqrt_price::SqrtPrice;
// use decimal::{BetweenDecimals, Decimal, Factories};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/math/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pub mod fee_growth;
pub mod fixed_point;
pub mod liquidity;
pub mod percentage;
pub mod ratio;
pub mod seconds_per_liquidity;
pub mod sqrt_price;
pub mod token_amount;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use traceable_result::*;

use crate::math::consts::*;
use crate::math::types::sqrt_price::sqrt_price::SqrtPrice;
use crate::math::types::ratio::sqrt_price::SqrtPrice;

const LOG2_SCALE: u8 = 32;
const LOG2_DOUBLE_SCALE: u8 = 64;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/math/types/token_amount.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use decimal::*;
use traceable_result::*;

use super::sqrt_price::sqrt_price::SqrtPrice;
use super::ratio::sqrt_price::SqrtPrice;

#[decimal(0)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, scale::Decode, scale::Encode)]
Expand Down

0 comments on commit 6ee5921

Please sign in to comment.