@@ -17,7 +17,7 @@ Add this to your Cargo.toml
17
17
18
18
```
19
19
[dependencies]
20
- uniswap-sdk-core = "0.19 .0";
20
+ uniswap-sdk-core = "0.20 .0";
21
21
```
22
22
23
23
And this to your code:
@@ -28,21 +28,58 @@ use uniswap_sdk_core::prelude::*;
28
28
29
29
## Examples
30
30
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.
32
33
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
38
39
use uniswap_sdk_core :: prelude :: * ;
39
40
40
41
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
+ }
43
67
}
44
68
```
45
69
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
+
46
83
## License
47
84
48
85
This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
0 commit comments