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

fix issue #50 #56

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-sdk-core"
version = "0.19.0"
version = "0.20.0"
edition = "2021"
authors = ["malik <[email protected]>", "Shuhui Luo <twitter.com/aureliano_law>"]
description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange"
Expand Down
55 changes: 46 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,21 +28,58 @@ 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::*;

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

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigInt, Error> {
if !value >= Zero::zero() {
return Err(Error::Incorrect());
Expand Down
Loading