Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add support for Blast chain #64

Merged
merged 21 commits into from
May 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed documentations and refactored some documentations
malik672 committed Apr 17, 2024
commit 29dc0cbb99b161df1c42e0c66f14cc681d3d491a
2 changes: 1 addition & 1 deletion src/addresses.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ pub struct ChainAddresses {
v1_mixed_route_quoter_address: Option<Address>,
}

///
/// Represents default networks which are Mainnet, Goerli, Sepolia
pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, ChainId::SEPOLIA];

/// returns a hashmap of key pair input of chainid to address
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ pub enum Rounding {
}

lazy_static! {
///
///Represnts Maximum amount contained in a uint256
pub static ref MAX_UINT256: BigInt =
BigInt::from_bytes_be(Sign::Plus, &U256::MAX.to_be_bytes::<32>());
}
18 changes: 6 additions & 12 deletions src/entities/base_currency.rs
Original file line number Diff line number Diff line change
@@ -6,27 +6,21 @@ use alloy_primitives::ChainId;

/// `CurrencyLike` is a generic struct representing a currency with a specific chain ID,
/// decimals, symbol, name, and additional metadata.
///
/// This struct is used to abstract the details of different currencies, allowing for
/// a unified way to handle various types of currencies in the Uniswap SDK Core.
///
/// # Generics
///
/// - `M`: The type of the additional metadata associated with the currency.
pub struct CurrencyLike<M> {
///

/// The chain ID on which this currency resides
pub chain_id: ChainId,

///
/// represents the deciamls for the prticular currency
pub decimals: u8,

///
/// The symbol of the currency, i.e. a short textual non-unique identifier
pub symbol: Option<String>,

///
/// The name of the currency, i.e. a descriptive textual non-unique identifier
pub name: Option<String>,

///
/// Metadata associated with the currency
pub meta: M,
}

23 changes: 11 additions & 12 deletions src/entities/fractions/fraction.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
use crate::prelude::*;
use std::ops::{Add, Deref, Mul, Sub};

///
/// struct to represent a fraction
#[derive(Clone, Debug)]
pub struct FractionLike<M> {
numerator: BigInt,
@@ -74,15 +74,16 @@ where
{
}

///
/// Trait defining common operations for fractions with metadata
pub trait FractionBase<M>: Sized {
///

/// Constructor method for creating a new Fraction with metadata
fn new(numerator: impl Into<BigInt>, denominator: impl Into<BigInt>, meta: M) -> Self;

///
/// Accessor method for retrieving metadata
fn meta(&self) -> M;

///
/// Accessor method for retrieving metadata
fn numerator(&self) -> BigInt;

/// Accessor method for retrieving the denominator
@@ -112,7 +113,8 @@ pub trait FractionBase<M>: Sized {
BigDecimal::from(self.numerator()).div(BigDecimal::from(self.denominator()))
}

///
/// Converts the fraction to a string with a specified number of significant digits and rounding
/// strategy
fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> Result<String, Error> {
if significant_digits == 0 {
return Err(Error::Incorrect());
@@ -126,7 +128,8 @@ pub trait FractionBase<M>: Sized {
Ok(quotient.normalized().to_string())
}

///
/// Converts the fraction to a string with a fixed number of decimal places and rounding
/// strategy
fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String {
let rounding_strategy = to_rounding_strategy(rounding);
self.to_decimal()
@@ -177,7 +180,7 @@ impl<M> PartialEq for FractionLike<M>
where
M: Clone + PartialEq,
{
///
/// Checks if the current fraction is equal to another fraction
fn eq(&self, other: &Self) -> bool {
self.numerator() * other.denominator() == other.numerator() * self.denominator()
&& self.meta() == other.meta()
@@ -207,7 +210,6 @@ where
impl<M: Clone> Add for FractionLike<M> {
type Output = Self;

///
fn add(self, other: Self) -> Self::Output {
if self.denominator == other.denominator() {
FractionBase::new(
@@ -228,7 +230,6 @@ impl<M: Clone> Add for FractionLike<M> {
impl<M: Clone> Sub for FractionLike<M> {
type Output = Self;

///
fn sub(self, other: Self) -> Self::Output {
if self.denominator == other.denominator() {
FractionBase::new(
@@ -249,7 +250,6 @@ impl<M: Clone> Sub for FractionLike<M> {
impl<M: Clone> Mul for FractionLike<M> {
type Output = Self;

///
fn mul(self, other: Self) -> Self::Output {
FractionBase::new(
self.numerator() * other.numerator(),
@@ -262,7 +262,6 @@ impl<M: Clone> Mul for FractionLike<M> {
impl<M: Clone> Div for FractionLike<M> {
type Output = Self;

///
/// There's little to no possibility of an error, so unwrap can be used
fn div(self, other: Self) -> Self::Output {
FractionBase::new(
12 changes: 3 additions & 9 deletions src/entities/fractions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/// This module represents currency, including the currency type and the amount as a fraction, also
/// including. methods for arithmetic operations, conversions to and from string representations,
/// and checks for validity.
/// This module represents currency, including the currency type and the amount as a fraction.
pub mod currency_amount;
/// This module contains with precise division results, avoiding floating-point arithmetic issues,
/// also including operations like addition, subtraction, multiplication, and division, as well as
/// conversions to other formats.
/// This module contains with precise division results, avoiding floating-point arithmetic issues.
pub mod fraction;
/// A module represents a percentage as a fraction, with methods for arithmetic and string
/// conversions, it also includes methods for precise calculations involving percentages and ensures
/// accurate representation of percentage values.
/// A module represents a percentage.
pub mod percent;
/// A module represents' a price as a ratio between two currencies, with methods for arithmetic and
/// string conversions.
12 changes: 6 additions & 6 deletions src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
///
/// Module represnting base currency
pub mod base_currency;
///
/// Module representing currency
pub mod currency;
///
/// Module representing ether
pub mod ether;
///
/// Module represnting fractions
pub mod fractions;
///
/// Module represnting token
pub mod token;
///
/// Module representing Weth9
pub mod weth9;
10 changes: 5 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -3,23 +3,23 @@ use crate::prelude::*;
/// Represents errors that can occur in the context of currency operations.
#[derive(Debug, Error, Clone, Copy)]
pub enum Error {
///
/// Triggers when compared Chain Ids do not match
#[error("Chain IDs do not match: {0} and {1}")]
ChainIdMismatch(u64, u64),

///
/// Triggers when comapred addresses are not the smae
#[error("Addresses are equal")]
EqualAddresses,

///
/// Triggers when it tries to exceed the max uint
#[error("amount has exceeded MAX_UINT256")]
MaxUint,

///
///Triggers when the Compared values are not equal
#[error("not equal")]
NotEqual(),

///
/// Triggers when The value is inccorrrect
#[error("incorrect")]
Incorrect(),
}
7 changes: 4 additions & 3 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
///
/// Module that contains various methods to comput price
pub mod compute_price_impact;
///

/// Module that contains various methods to sort
pub mod sorted_insert;
///
/// Module that contains various methods to compute square root
pub mod sqrt;
#[cfg(feature = "validate_parse_address")]
pub mod validate_and_parse_address;