Skip to content

Commit 42e8959

Browse files
authored
Merge pull request #106 from malik672/dep
2 parents 72c240c + 0b9f909 commit 42e8959

File tree

6 files changed

+56
-60
lines changed

6 files changed

+56
-60
lines changed

Cargo.toml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uniswap-sdk-core"
3-
version = "4.0.0-rc3"
3+
version = "4.0.0-rc4"
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"
@@ -12,20 +12,18 @@ keywords = ["sdk-core", "ethereum", "sdk"]
1212
exclude = [".github", ".gitignore", "rustfmt.toml"]
1313

1414
[dependencies]
15-
alloy-primitives = { version = ">=0.8.5", features = ["map-fxhash"] }
15+
alloy-primitives = { version = ">=0.8.5", default-features = false, features = ["map-fxhash"] }
1616
bnum = "0.12.0"
17-
derive_more = { version = "1.0.0", features = ["deref"] }
17+
derive_more = { version = "2", default-features = false, features = ["deref", "from"] }
1818
eth_checksum = { version = "0.1.2", optional = true }
19-
fastnum = { version = "0.1.9", default-features = false, features = ["libm", "numtraits"] }
19+
fastnum = { version = "0.1.11", default-features = false, features = ["numtraits"] }
2020
lazy_static = "1.5"
21-
num-integer = "0.1.46"
21+
num-integer = { version = "0.1", default-features = false }
22+
num-traits = { version = "0.2.19", default-features = false, features = ["libm"] }
2223
regex = { version = "1.11", optional = true }
2324
thiserror = { version = "2", default-features = false }
2425

2526
[features]
2627
default = []
27-
std = ["fastnum/std", "thiserror/std"]
28+
std = ["alloy-primitives/std", "derive_more/std", "fastnum/std", "num-integer/std", "thiserror/std"]
2829
validate_parse_address = ["eth_checksum", "regex"]
29-
30-
[lib]
31-
doctest = true

README.md

+34-37
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ exchange.**
1212

1313
Add this to your Cargo.toml
1414

15-
```
15+
```toml
1616
[dependencies]
1717
uniswap-sdk-core = "4.0.0"
1818
```
1919

2020
And this to your code:
2121

22-
```
22+
```rust
2323
use uniswap_sdk_core::prelude::*;
2424
```
2525

@@ -29,48 +29,43 @@ By default, this library does not depend on the standard library (`std`). Howeve
2929

3030
## Examples
3131

32+
The code below shows an example of how to create a new `Token` instance for the DAI token on the Ethereum Mainnet using
33+
the `token!` macro.
34+
3235
<details>
33-
<summary>The code below shows an example of how to create a new `Token` instance for the DAI token on the Ethereum Mainnet using
34-
the `token!` macro.</summary>
36+
<summary>Click to expand</summary>
3537

3638
```rust
37-
// The `prelude` module provides a convenient way to import a number of common dependencies at
38-
// once. This can be useful if you are working with multiple parts of the library and want to avoid
39-
// having to import each dependency individually.
40-
// Import necessary preludes and types
39+
// Import necessary preludes and token macro
4140
use uniswap_sdk_core::{prelude::*, token};
4241

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

72-
</details>
73-
7469
This example demonstrates how to create a `Token` instance for DAI on the Ethereum Mainnet using the `token!` macro.
7570

7671
It then prints the token's address and checks if it's a native token (which it isn't, so it prints false).
@@ -84,14 +79,16 @@ assuming the addresses are correctly set up for this comparison.
8479
Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working
8580
with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet).
8681

82+
</details>
83+
8784
## Contribution
8885

8986
Contributions are welcome! If you find a bug or have suggestions for improvements, feel free to open an issue or submit
9087
a pull request on the [GitHub repository](https://github.com/malik672/uniswap-sdk-core-rust).
9188

9289
## License
9390

94-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
91+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
9592

9693
## Acknowledgments
9794

src/addresses.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::prelude::*;
22
use alloy_primitives::address;
33
use lazy_static::lazy_static;
44

5-
pub type AddressMap = FxHashMap<u64, Address>;
5+
pub type AddressMap = HashMap<u64, Address>;
66

77
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
88
pub struct ChainAddresses {
@@ -381,8 +381,8 @@ lazy_static! {
381381
/// This map is used to look up the addresses of various Uniswap contracts
382382
/// for a given network. The keys in the map are the network IDs, and the values
383383
/// are the corresponding contract addresses.
384-
pub static ref CHAIN_TO_ADDRESSES_MAP: FxHashMap<u64, ChainAddresses> = {
385-
FxHashMap::from_iter([
384+
pub static ref CHAIN_TO_ADDRESSES_MAP: HashMap<u64, ChainAddresses> = {
385+
HashMap::from_iter([
386386
(ChainId::MAINNET as u64, MAINNET_ADDRESSES),
387387
(ChainId::OPTIMISM as u64, OPTIMISM_ADDRESSES),
388388
(ChainId::ARBITRUM_ONE as u64, ARBITUM_ONE_ADDRESSES),

src/entities/weth9.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloc::string::ToString;
66
#[derive(Clone, PartialEq, Debug)]
77
pub struct WETH9 {
88
/// A mapping of chain IDs to corresponding WETH tokens.
9-
tokens: FxHashMap<u64, Token>,
9+
tokens: HashMap<u64, Token>,
1010
}
1111

1212
/// Default implementation for [`WETH9`], creating an instance with predefined WETH tokens on
@@ -31,7 +31,7 @@ impl WETH9 {
3131
#[inline]
3232
#[must_use]
3333
pub fn new() -> Self {
34-
let tokens = FxHashMap::from_iter([
34+
let tokens = HashMap::from_iter([
3535
(1, Self::on_chain(1).unwrap()),
3636
(3, Self::on_chain(3).unwrap()),
3737
(4, Self::on_chain(4).unwrap()),

src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//! # uniswap-sdk-core
2-
//!
3-
//! The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap
4-
//! decentralized exchange.
5-
6-
#![cfg_attr(not(any(feature = "std", test)), no_std)]
1+
#![doc = include_str!("../README.md")]
2+
#![cfg_attr(not(feature = "std"), no_std)]
73
#![warn(
84
missing_copy_implementations,
95
missing_debug_implementations,
@@ -22,6 +18,7 @@
2218
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
2319

2420
extern crate alloc;
21+
use num_traits as _;
2522

2623
/// Contains functionality related to All Contracts deployed and supported by the Uniswap SDK.
2724
pub mod addresses;
@@ -46,8 +43,11 @@ pub mod utils;
4643
pub mod prelude {
4744
pub use crate::{addresses::*, chains::*, constants::*, entities::*, error::Error, utils::*};
4845

49-
pub use alloc::{string::String, vec::Vec};
50-
pub use alloy_primitives::{map::rustc_hash::FxHashMap, Address, Bytes, B256, U256};
46+
pub use alloc::{
47+
string::{String, ToString},
48+
vec::Vec,
49+
};
50+
pub use alloy_primitives::{map::HashMap, Address, Bytes, B256, U256};
5151
pub use bnum;
5252
pub use fastnum;
5353
pub use num_integer::Integer;
@@ -59,5 +59,5 @@ pub mod prelude {
5959
}
6060

6161
/// Contains examples of how Uniswap sdk core can be used
62-
#[cfg(test)]
62+
#[cfg(all(feature = "std", test))]
6363
mod examples;

src/utils/sorted_insert.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn sorted_insert<T: Clone>(
3737
#[cfg(test)]
3838
mod tests {
3939
use super::*;
40+
use alloc::vec;
4041

4142
fn cmp(a: &i32, b: &i32) -> Ordering {
4243
a.cmp(b)

0 commit comments

Comments
 (0)