@@ -12,14 +12,14 @@ exchange.**
12
12
13
13
Add this to your Cargo.toml
14
14
15
- ```
15
+ ``` toml
16
16
[dependencies ]
17
17
uniswap-sdk-core = " 4.0.0"
18
18
```
19
19
20
20
And this to your code:
21
21
22
- ```
22
+ ``` rust
23
23
use uniswap_sdk_core :: prelude :: * ;
24
24
```
25
25
@@ -29,48 +29,43 @@ By default, this library does not depend on the standard library (`std`). Howeve
29
29
30
30
## Examples
31
31
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
+
32
35
<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 >
35
37
36
38
``` 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
41
40
use uniswap_sdk_core :: {prelude :: * , token};
42
41
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 ),
69
66
}
70
67
```
71
68
72
- </details >
73
-
74
69
This example demonstrates how to create a ` Token ` instance for DAI on the Ethereum Mainnet using the ` token! ` macro.
75
70
76
71
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.
84
79
Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working
85
80
with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet).
86
81
82
+ </details >
83
+
87
84
## Contribution
88
85
89
86
Contributions are welcome! If you find a bug or have suggestions for improvements, feel free to open an issue or submit
90
87
a pull request on the [ GitHub repository] ( https://github.com/malik672/uniswap-sdk-core-rust ) .
91
88
92
89
## License
93
90
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.
95
92
96
93
## Acknowledgments
97
94
0 commit comments