From 5b11414bcf75592839166ed7027947223f64dc79 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 9 Mar 2024 18:25:12 +0100 Subject: [PATCH 1/6] add --- Cargo.toml | 2 +- src/addresses.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cba92eb..4fddad4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" [dependencies] alloy-primitives = "0.6" -bigdecimal = "0.4.2" +bigdecimal = "=0.4.2" eth_checksum = { version = "0.1.2", optional = true } lazy_static = "1.4" num-bigint = "0.4.4" diff --git a/src/addresses.rs b/src/addresses.rs index 94eec59..e60cd18 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -512,7 +512,7 @@ lazy_static! { } lazy_static! { - pub static ref QUOTER_ADDRESSESES: ChainAddress = { + pub static ref QUOTER_ADDRESSES: ChainAddress = { let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( @@ -552,7 +552,7 @@ lazy_static! { } lazy_static! { - pub static ref ENS_RESGISTER_ADDRESS: AddressMap = + pub static ref ENS_RESGISTER_ADDRESSES: AddressMap = construct_same_address_map(address!("00000000000C2E074eC69A0dFb2997BA6C7d2e1e"), &[]); } From 212b063510d14e09df2ee79e8202410bc92182a3 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 9 Mar 2024 19:06:21 +0100 Subject: [PATCH 2/6] fix readme with a better example --- Cargo.toml | 2 +- README.md | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4fddad4..9cda52c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core" -version = "0.19.0" +version = "0.20.0" edition = "2021" authors = ["malik ", "Shuhui Luo "] description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange" diff --git a/README.md b/README.md index 42df924..8dcca26 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Add this to your Cargo.toml ``` [dependencies] -uniswap-sdk-core = "0.19.0"; +uniswap-sdk-core = "0.20.0"; ``` And this to your code: @@ -35,12 +35,42 @@ The code below shows an example of how you can validate an address // of common dependencies at once. This can be useful if you are working // with multiple parts of the library and want to avoid having // to import each dependency individually. +// Import necessary preludes and types use uniswap_sdk_core::prelude::*; fn main() { - let valid_address: &str = "0x1234567890123456789012345678901234567890"; - assert!(check_valid_ethereum_address(valid_address).is_ok()); + // Define the chain ID, address, decimals, symbol, and name for the token + const CHAIN_ID: u64 = 1; // Ethereum Mainnet + const TOKEN_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; // DAI Token Address + const DECIMALS: u8 = 18; + const SYMBOL: &str = "DAI"; + const NAME: &str = "Dai Stablecoin"; + + // Use the `token!` macro to create a new `Token` instance + let dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME); + + // Example usage of the `Token` methods + println!("Token Address: {}", dai_token.address()); + println!("Is Native: {}", dai_token.is_native()); + + // Example of comparing two tokens + let another_dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME); + println!("Are the tokens equal? {}", dai_token.equals(&another_dai_token)); + + // Example of sorting tokens + let another_token = token!(CHAIN_ID, "0x0000000000000000000000000000000000000002", DECIMALS, "ETH", "Ethereum"); + match dai_token.sorts_before(&another_token) { + Ok(true) => println!("DAI sorts before ETH"), + Ok(false) => println!("DAI does not sort before ETH"), + Err(e) => println!("Error comparing tokens: {:?}", e), + } } +//This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro. +//It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). +//It also compares the DAI token with another DAI token instance to show that two instances of the same token are considered equal. +//Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, assuming the addresses are correctly set up for this comparison. +//Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet). + ``` ## License From 8eaa9e8e678afb65be151424beae779960143a26 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 9 Mar 2024 19:17:52 +0100 Subject: [PATCH 3/6] fix readme with a better example --- src/addresses.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addresses.rs b/src/addresses.rs index ada8c4a..a8b02f8 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -699,4 +699,4 @@ mod tests { address!("3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E") ); } -} \ No newline at end of file +} From 3dc7b460b44e7df0342a49230c4aca3131daf352 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 9 Mar 2024 19:40:54 +0100 Subject: [PATCH 4/6] fix readme with a better example --- src/utils/sqrt.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index 2046044..da3670e 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -7,6 +7,8 @@ use crate::prelude::*; /// * `value`: the value for which to compute the square root, rounded down /// /// returns: BigInt + +#[allow(clippy::assigning_clones)] pub fn sqrt(value: &BigInt) -> Result { if !value >= Zero::zero() { return Err(Error::Incorrect()); From b33962ac5f5167c0ea500da2623fb09e586aedda Mon Sep 17 00:00:00 2001 From: malik Date: Sun, 10 Mar 2024 10:52:00 +0100 Subject: [PATCH 5/6] Update README.md fix Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8dcca26..c8c7b30 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,12 @@ fn main() { Err(e) => println!("Error comparing tokens: {:?}", e), } } -//This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro. -//It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). -//It also compares the DAI token with another DAI token instance to show that two instances of the same token are considered equal. -//Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, assuming the addresses are correctly set up for this comparison. -//Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet). - -``` +\``` +This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro. +It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). +It also compares the DAI token with another DAI token instance to show that two instances of the same token are considered equal. +Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, assuming the addresses are correctly set up for this comparison. +Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet). ## License From 1fe56a8a9e7084149950d5016a02eba8c9a6032f Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Sun, 10 Mar 2024 20:49:07 -0400 Subject: [PATCH 6/6] Update example in README.md The example provided in the README.md was replaced with a more detailed and applicable example. It's now about creating a new Token instance for the DAI token on the Ethereum Mainnet using the `token!` macro. The contextual explanations for each code line have been expanded too for better understanding. --- README.md | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c8c7b30..5d5dd4f 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,13 @@ use uniswap_sdk_core::prelude::*; ## Examples -The code below shows an example of how you can validate an address +The code below shows an example of how to create a new `Token` instance for the DAI token on the Ethereum Mainnet using +the `token!` macro. -``` -// The `prelude` module provides a convenient way to import a number -// of common dependencies at once. This can be useful if you are working -// with multiple parts of the library and want to avoid having -// to import each dependency individually. +```rust +// The `prelude` module provides a convenient way to import a number of common dependencies at +// once. This can be useful if you are working with multiple parts of the library and want to avoid +// having to import each dependency individually. // Import necessary preludes and types use uniswap_sdk_core::prelude::*; @@ -65,12 +65,20 @@ fn main() { Err(e) => println!("Error comparing tokens: {:?}", e), } } -\``` +``` + This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro. -It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). -It also compares the DAI token with another DAI token instance to show that two instances of the same token are considered equal. -Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, assuming the addresses are correctly set up for this comparison. -Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet). + +It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). + +It also compares the DAI token with another DAI token instance to show that two instances of the same token are +considered equal. + +Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, +assuming the addresses are correctly set up for this comparison. + +Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working +with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet). ## License