Skip to content

Commit

Permalink
Merge pull request #52 from malik672/feat(macro)
Browse files Browse the repository at this point in the history
feat(macro): Update token macro and fix address formatting
  • Loading branch information
malik672 authored Mar 3, 2024
2 parents e2d34d4 + 85e037e commit 61743f6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
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.17.0"
version = "0.17.1"
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
39 changes: 36 additions & 3 deletions src/entities/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,65 @@ impl Token {
/// Shorthand macro to create a token
#[macro_export]
macro_rules! token {
($chain_id:expr, $address:literal, $decimals:expr) => {
Token::new(
$chain_id,
address!($address),
$decimals,
None,
None,
None,
None,
)
};
($chain_id:expr, $address:expr, $decimals:expr) => {
Token::new(
$chain_id,
$address.parse::<Address>().unwrap(),
$address.to_string().parse::<Address>().unwrap(),
$decimals,
None,
None,
None,
None,
)
};
($chain_id:expr, $address:literal, $decimals:expr, $symbol:expr) => {
Token::new(
$chain_id,
address!($address),
$decimals,
Some($symbol.to_string()),
None,
None,
None,
)
};
($chain_id:expr, $address:expr, $decimals:expr, $symbol:expr) => {
Token::new(
$chain_id,
$address.parse::<Address>().unwrap(),
$address.to_string().parse::<Address>().unwrap(),
$decimals,
Some($symbol.to_string()),
None,
None,
None,
)
};
($chain_id:expr, $address:literal, $decimals:expr, $symbol:expr, $name:expr) => {
Token::new(
$chain_id,
address!($address),
$decimals,
Some($symbol.to_string()),
Some($name.to_string()),
None,
None,
)
};
($chain_id:expr, $address:expr, $decimals:expr, $symbol:expr, $name:expr) => {
Token::new(
$chain_id,
$address.parse::<Address>().unwrap(),
$address.to_string().parse::<Address>().unwrap(),
$decimals,
Some($symbol.to_string()),
Some($name.to_string()),
Expand Down
26 changes: 13 additions & 13 deletions src/entities/weth9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl WETH9 {
1,
token!(
1,
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -35,7 +35,7 @@ impl WETH9 {
3,
token!(
3,
"0xc778417E063141139Fce010982780140Aa0cD5Ab",
"c778417E063141139Fce010982780140Aa0cD5Ab",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -45,7 +45,7 @@ impl WETH9 {
4,
token!(
4,
"0xc778417E063141139Fce010982780140Aa0cD5Ab",
"c778417E063141139Fce010982780140Aa0cD5Ab",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -55,7 +55,7 @@ impl WETH9 {
5,
token!(
5,
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"B4FBF271143F4FBf7B91A5ded31805e42b2208d6",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -65,7 +65,7 @@ impl WETH9 {
42,
token!(
42,
"0xd0A1E359811322d97991E03f863a0C30C2cF029C",
"d0A1E359811322d97991E03f863a0C30C2cF029C",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -75,7 +75,7 @@ impl WETH9 {
10,
token!(
10,
"0x4200000000000000000000000000000000000006",
"4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -85,7 +85,7 @@ impl WETH9 {
69,
token!(
69,
"0x4200000000000000000000000000000000000006",
"4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -95,7 +95,7 @@ impl WETH9 {
42161,
token!(
42161,
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"82aF49447D8a07e3bd95BD0d56f35241523fBab1",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -105,7 +105,7 @@ impl WETH9 {
421611,
token!(
421611,
"0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681",
"B47e6A5f8b33b3F17603C83a0535A9dcD7E32681",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -115,7 +115,7 @@ impl WETH9 {
8453,
token!(
8453,
"0x4200000000000000000000000000000000000006",
"4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether"
Expand All @@ -125,7 +125,7 @@ impl WETH9 {
56,
token!(
56,
"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
"bb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
18,
"WBNB",
"Wrapped BNB"
Expand All @@ -135,7 +135,7 @@ impl WETH9 {
137,
token!(
137,
"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
18,
"WMATIC",
"Wrapped MATIC"
Expand All @@ -145,7 +145,7 @@ impl WETH9 {
43114,
token!(
43114,
"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
"B31f66AA3C1e785363F0875A1B74E27b85FD66c7",
18,
"WAVAX",
"Wrapped AVAX"
Expand Down

0 comments on commit 61743f6

Please sign in to comment.