Skip to content

Commit f72e4c2

Browse files
authored
Merge pull request #56 from malik672/upstream
fix issue #50
2 parents 41108c1 + 1fe56a8 commit f72e4c2

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uniswap-sdk-core"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
edition = "2021"
55
authors = ["malik <aremumalik05@gmail.com>", "Shuhui Luo <twitter.com/aureliano_law>"]
66
description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange"

README.md

+46-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Add this to your Cargo.toml
1717

1818
```
1919
[dependencies]
20-
uniswap-sdk-core = "0.19.0";
20+
uniswap-sdk-core = "0.20.0";
2121
```
2222

2323
And this to your code:
@@ -28,21 +28,58 @@ use uniswap_sdk_core::prelude::*;
2828

2929
## Examples
3030

31-
The code below shows an example of how you can validate an address
31+
The code below shows an example of how to create a new `Token` instance for the DAI token on the Ethereum Mainnet using
32+
the `token!` macro.
3233

33-
```
34-
// The `prelude` module provides a convenient way to import a number
35-
// of common dependencies at once. This can be useful if you are working
36-
// with multiple parts of the library and want to avoid having
37-
// to import each dependency individually.
34+
```rust
35+
// The `prelude` module provides a convenient way to import a number of common dependencies at
36+
// once. This can be useful if you are working with multiple parts of the library and want to avoid
37+
// having to import each dependency individually.
38+
// Import necessary preludes and types
3839
use uniswap_sdk_core::prelude::*;
3940

4041
fn main() {
41-
let valid_address: &str = "0x1234567890123456789012345678901234567890";
42-
assert!(check_valid_ethereum_address(valid_address).is_ok());
42+
// Define the chain ID, address, decimals, symbol, and name for the token
43+
const CHAIN_ID: u64 = 1; // Ethereum Mainnet
44+
const TOKEN_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; // DAI Token Address
45+
const DECIMALS: u8 = 18;
46+
const SYMBOL: &str = "DAI";
47+
const NAME: &str = "Dai Stablecoin";
48+
49+
// Use the `token!` macro to create a new `Token` instance
50+
let dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME);
51+
52+
// Example usage of the `Token` methods
53+
println!("Token Address: {}", dai_token.address());
54+
println!("Is Native: {}", dai_token.is_native());
55+
56+
// Example of comparing two tokens
57+
let another_dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME);
58+
println!("Are the tokens equal? {}", dai_token.equals(&another_dai_token));
59+
60+
// Example of sorting tokens
61+
let another_token = token!(CHAIN_ID, "0x0000000000000000000000000000000000000002", DECIMALS, "ETH", "Ethereum");
62+
match dai_token.sorts_before(&another_token) {
63+
Ok(true) => println!("DAI sorts before ETH"),
64+
Ok(false) => println!("DAI does not sort before ETH"),
65+
Err(e) => println!("Error comparing tokens: {:?}", e),
66+
}
4367
}
4468
```
4569

70+
This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro.
71+
72+
It then prints the token's address and checks if it's a native token (which it isn't, so it prints false).
73+
74+
It also compares the DAI token with another DAI token instance to show that two instances of the same token are
75+
considered equal.
76+
77+
Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH,
78+
assuming the addresses are correctly set up for this comparison.
79+
80+
Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working
81+
with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet).
82+
4683
## License
4784

4885
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

src/utils/sqrt.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::prelude::*;
77
/// * `value`: the value for which to compute the square root, rounded down
88
///
99
/// returns: BigInt
10+
11+
#[allow(clippy::assigning_clones)]
1012
pub fn sqrt(value: &BigInt) -> Result<BigInt, Error> {
1113
if !value >= Zero::zero() {
1214
return Err(Error::Incorrect());

0 commit comments

Comments
 (0)