diff --git a/Cargo.lock b/Cargo.lock index d8c3ffb..90902a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,7 +390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -584,9 +584,9 @@ checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "num-bigint" @@ -736,9 +736,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.71" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" +checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" dependencies = [ "unicode-ident", ] @@ -771,9 +771,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" dependencies = [ "proc-macro2", ] @@ -1001,7 +1001,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1067,7 +1067,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.44", ] [[package]] @@ -1109,9 +1109,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.43" +version = "2.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" dependencies = [ "proc-macro2", "quote", @@ -1126,35 +1126,35 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "thiserror" -version = "1.0.52" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" +checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.52" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" +checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.44", ] [[package]] @@ -1232,7 +1232,7 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uniswap-sdk-core-rust" -version = "0.5.0" +version = "0.6.0" dependencies = [ "alloy-primitives", "bigdecimal", @@ -1303,37 +1303,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1342,93 +1318,51 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.0" @@ -1470,5 +1404,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.44", ] diff --git a/Cargo.toml b/Cargo.toml index 023793c..0d4a880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core-rust" -version = "0.5.0" +version = "0.6.0" edition = "2021" authors = ["malik ", "Shuhui Luo "] description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange" diff --git a/src/addresses.rs b/src/addresses.rs index 2426cd9..faca5fb 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -1,28 +1,29 @@ use crate::prelude::*; -type AddressMap = HashMap; + +type AddressMap = HashMap; type ChainMap = HashMap; -type ChainAddress = HashMap; +type ChainAddress = HashMap; #[derive(Clone)] pub struct ChainAddresses { - v3_core_factory_address: String, - multicall_address: String, - quoter_address: String, - v3_migrator_address: Option, - nonfungible_position_manager_address: Option, - tick_lens_address: Option, - swap_router02_address: Option, - v1_mixed_route_quoter_address: Option, + v3_core_factory_address: Address, + multicall_address: Address, + quoter_address: Address, + v3_migrator_address: Option
, + nonfungible_position_manager_address: Option
, + tick_lens_address: Option
, + swap_router02_address: Option
, + v1_mixed_route_quoter_address: Option
, } pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, ChainId::SEPOLIA]; -pub fn construct_same_address_map(address: &str, additional_networks: &[ChainId]) -> AddressMap { +pub fn construct_same_address_map(address: Address, additional_networks: &[ChainId]) -> AddressMap { let mut networks = DEFAULT_NETWORKS.to_vec(); networks.extend_from_slice(additional_networks); let mut map = AddressMap::new(); for chain_id in networks { - map.insert(chain_id as u32, String::from(address)); + map.insert(chain_id as u32, address); } map } @@ -30,7 +31,7 @@ pub fn construct_same_address_map(address: &str, additional_networks: &[ChainId] lazy_static! { #[derive(Copy, Clone)] pub static ref UNI_ADDRESSES: AddressMap = construct_same_address_map( - "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984"), &[ ChainId::OPTIMISM, ChainId::ARBITRUMONE, @@ -41,9 +42,10 @@ lazy_static! { ); } -pub const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS: &str = "0x8B799381ac40b838BBA4131ffB26197C432AFe78"; +pub const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS: Address = + address!("8B799381ac40b838BBA4131ffB26197C432AFe78"); -pub const V2_FACTORY_ADDRESS: &str = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"; +pub const V2_FACTORY_ADDRESS: Address = address!("5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"); lazy_static! { pub static ref V2_FACTORY_ADDRESSES: AddressMap = construct_same_address_map( @@ -60,7 +62,7 @@ lazy_static! { ); } -pub const V2_ROUTER_ADDRESS: &str = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"; +pub const V2_ROUTER_ADDRESS: Address = address!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); lazy_static! { pub static ref V2_ROUTER_ADDRESSES: AddressMap = @@ -71,13 +73,13 @@ impl Default for ChainAddresses { /// Networks that share most of the same addresses i.e. Mainnet, Goerli, Optimism, Arbitrum, Polygon fn default() -> Self { Self { - v3_core_factory_address: "0x1F98431c8aD98523631AE4a59f267346ea31F984".into(), - multicall_address: "0x1F98415757620B543A52E61c46B32eB19261F984".into(), - quoter_address: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6".into(), - v3_migrator_address: Some("0xA5644E29708357803b5A882D272c41cC0dF92B34".into()), - nonfungible_position_manager_address: Some( - "0xC36442b4a4522E871399CD717aBDD847Ab11FE88".into(), - ), + v3_core_factory_address: address!("1F98431c8aD98523631AE4a59f267346ea31F984"), + multicall_address: address!("1F98415757620B543A52E61c46B32eB19261F984"), + quoter_address: address!("b27308f9F90D607463bb33eA1BeBb41C27CE5AB6"), + v3_migrator_address: Some(address!("A5644E29708357803b5A882D272c41cC0dF92B34")), + nonfungible_position_manager_address: Some(address!( + "C36442b4a4522E871399CD717aBDD847Ab11FE88" + )), tick_lens_address: None, swap_router02_address: None, v1_mixed_route_quoter_address: None, @@ -87,14 +89,14 @@ impl Default for ChainAddresses { pub fn mainnet_address() -> ChainAddresses { ChainAddresses { - v1_mixed_route_quoter_address: Some("0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E".into()), + v1_mixed_route_quoter_address: Some(address!("84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E")), ..Default::default() } } pub fn goerli_address() -> ChainAddresses { ChainAddresses { - v1_mixed_route_quoter_address: Some("0xBa60b6e6fF25488308789E6e0A65D838be34194e".into()), + v1_mixed_route_quoter_address: Some(address!("Ba60b6e6fF25488308789E6e0A65D838be34194e")), ..Default::default() } } @@ -105,8 +107,8 @@ pub fn optimism_addresses() -> ChainAddresses { pub fn arbitum_one_addresses() -> ChainAddresses { ChainAddresses { - multicall_address: "0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB".into(), - tick_lens_address: Some("0xbfd8137f7d1516D3ea5cA83523914859ec47F573".into()), + multicall_address: address!("adF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB"), + tick_lens_address: Some(address!("bfd8137f7d1516D3ea5cA83523914859ec47F573")), ..Default::default() } } @@ -118,14 +120,14 @@ pub fn polygon_addresses() -> ChainAddresses { /// celo v3 addresses pub fn celo_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xAfE208a311B21f13EF87E33A90049fC17A7acDEc".into(), - multicall_address: "0x633987602DE5C4F337e3DbF265303A1080324204".into(), - quoter_address: "0x82825d0554fA07f7FC52Ab63c961F330fdEFa8E8".into(), - v3_migrator_address: Some("0x3cFd4d48EDfDCC53D3f173F596f621064614C582".into()), - nonfungible_position_manager_address: Some( - "0x3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A".into(), - ), - tick_lens_address: Some("0x5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D".into()), + v3_core_factory_address: address!("AfE208a311B21f13EF87E33A90049fC17A7acDEc"), + multicall_address: address!("633987602DE5C4F337e3DbF265303A1080324204"), + quoter_address: address!("82825d0554fA07f7FC52Ab63c961F330fdEFa8E8"), + v3_migrator_address: Some(address!("3cFd4d48EDfDCC53D3f173F596f621064614C582")), + nonfungible_position_manager_address: Some(address!( + "3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A" + )), + tick_lens_address: Some(address!("5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D")), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -134,15 +136,15 @@ pub fn celo_addresses() -> ChainAddresses { /// BNB v3 addresses pub fn bnb_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7".into(), - multicall_address: "0x963Df249eD09c358A4819E39d9Cd5736c3087184".into(), - quoter_address: "0x78D78E420Da98ad378D7799bE8f4AF69033EB077".into(), - v3_migrator_address: Some("0x32681814957e0C13117ddc0c2aba232b5c9e760f".into()), - nonfungible_position_manager_address: Some( - "0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613".into(), - ), - tick_lens_address: Some("0xD9270014D396281579760619CCf4c3af0501A47C".into()), - swap_router02_address: Some("0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2".into()), + v3_core_factory_address: address!("dB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7"), + multicall_address: address!("963Df249eD09c358A4819E39d9Cd5736c3087184"), + quoter_address: address!("78D78E420Da98ad378D7799bE8f4AF69033EB077"), + v3_migrator_address: Some(address!("32681814957e0C13117ddc0c2aba232b5c9e760f")), + nonfungible_position_manager_address: Some(address!( + "7b8A01B39D58278b5DE7e48c8449c9f4F5170613" + )), + tick_lens_address: Some(address!("D9270014D396281579760619CCf4c3af0501A47C")), + swap_router02_address: Some(address!("B971eF87ede563556b2ED4b1C0b0019111Dd85d2")), v1_mixed_route_quoter_address: None, } } @@ -150,14 +152,14 @@ pub fn bnb_addresses() -> ChainAddresses { /// Optimism Goerli addresses pub fn optimism_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xB656dA17129e7EB733A557f4EBc57B76CFbB5d10".into(), - multicall_address: "0x07F2D8a2a02251B62af965f22fC4744A5f96BCCd".into(), - quoter_address: "0x9569CbA925c8ca2248772A9A4976A516743A246F".into(), - v3_migrator_address: Some("0xf6c55fBe84B1C8c3283533c53F51bC32F5C7Aba8".into()), - nonfungible_position_manager_address: Some( - "0x39Ca85Af2F383190cBf7d7c41ED9202D27426EF6".into(), - ), - tick_lens_address: Some("0xe6140Bd164b63E8BfCfc40D5dF952f83e171758e".into()), + v3_core_factory_address: address!("B656dA17129e7EB733A557f4EBc57B76CFbB5d10"), + multicall_address: address!("07F2D8a2a02251B62af965f22fC4744A5f96BCCd"), + quoter_address: address!("9569CbA925c8ca2248772A9A4976A516743A246F"), + v3_migrator_address: Some(address!("f6c55fBe84B1C8c3283533c53F51bC32F5C7Aba8")), + nonfungible_position_manager_address: Some(address!( + "39Ca85Af2F383190cBf7d7c41ED9202D27426EF6" + )), + tick_lens_address: Some(address!("e6140Bd164b63E8BfCfc40D5dF952f83e171758e")), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -166,14 +168,14 @@ pub fn optimism_goerli_addresses() -> ChainAddresses { /// Arbitrum Goerli v3 addresses pub fn arbitrum_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x4893376342d5D7b3e31d4184c08b265e5aB2A3f6".into(), - multicall_address: "0x8260CB40247290317a4c062F3542622367F206Ee".into(), - quoter_address: "0x1dd92b83591781D0C6d98d07391eea4b9a6008FA".into(), - v3_migrator_address: Some("0xA815919D2584Ac3F76ea9CB62E6Fd40a43BCe0C3".into()), - nonfungible_position_manager_address: Some( - "0x622e4726a167799826d1E1D150b076A7725f5D81".into(), - ), - tick_lens_address: Some("0xb52429333da969a0C79a60930a4Bf0020E5D1DE8".into()), + v3_core_factory_address: address!("4893376342d5D7b3e31d4184c08b265e5aB2A3f6"), + multicall_address: address!("8260CB40247290317a4c062F3542622367F206Ee"), + quoter_address: address!("1dd92b83591781D0C6d98d07391eea4b9a6008FA"), + v3_migrator_address: Some(address!("A815919D2584Ac3F76ea9CB62E6Fd40a43BCe0C3")), + nonfungible_position_manager_address: Some(address!( + "622e4726a167799826d1E1D150b076A7725f5D81" + )), + tick_lens_address: Some(address!("b52429333da969a0C79a60930a4Bf0020E5D1DE8")), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -182,14 +184,14 @@ pub fn arbitrum_goerli_addresses() -> ChainAddresses { /// sepolia v3 addresses pub fn sepolia_address() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x0227628f3F023bb0B980b67D528571c95c6DaC1c".into(), - multicall_address: "0xD7F33bCdb21b359c8ee6F0251d30E94832baAd07".into(), - quoter_address: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3".into(), - v3_migrator_address: Some("0x729004182cF005CEC8Bd85df140094b6aCbe8b15".into()), - nonfungible_position_manager_address: Some( - "0x1238536071E1c677A632429e3655c799b22cDA52".into(), - ), - tick_lens_address: Some("0xd7f33bcdb21b359c8ee6f0251d30e94832baad07".into()), + v3_core_factory_address: address!("0227628f3F023bb0B980b67D528571c95c6DaC1c"), + multicall_address: address!("D7F33bCdb21b359c8ee6F0251d30E94832baAd07"), + quoter_address: address!("Ed1f6473345F45b75F8179591dd5bA1888cf2FB3"), + v3_migrator_address: Some(address!("729004182cF005CEC8Bd85df140094b6aCbe8b15")), + nonfungible_position_manager_address: Some(address!( + "1238536071E1c677A632429e3655c799b22cDA52" + )), + tick_lens_address: Some(address!("d7f33bcdb21b359c8ee6f0251d30e94832baad07")), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -198,15 +200,15 @@ pub fn sepolia_address() -> ChainAddresses { /// Avalanche v3 addresses pub fn avalanche_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD".into(), - multicall_address: "0x0139141Cd4Ee88dF3Cdb65881D411bAE271Ef0C2".into(), - quoter_address: "0xbe0F5544EC67e9B3b2D979aaA43f18Fd87E6257F".into(), - v3_migrator_address: Some("0x44f5f1f5E452ea8d29C890E8F6e893fC0f1f0f97".into()), - nonfungible_position_manager_address: Some( - "0x655C406EBFa14EE2006250925e54ec43AD184f8B".into(), - ), - tick_lens_address: Some("0xEB9fFC8bf81b4fFd11fb6A63a6B0f098c6e21950".into()), - swap_router02_address: Some("0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE".into()), + v3_core_factory_address: address!("740b1c1de25031C31FF4fC9A62f554A55cdC1baD"), + multicall_address: address!("0139141Cd4Ee88dF3Cdb65881D411bAE271Ef0C2"), + quoter_address: address!("be0F5544EC67e9B3b2D979aaA43f18Fd87E6257F"), + v3_migrator_address: Some(address!("44f5f1f5E452ea8d29C890E8F6e893fC0f1f0f97")), + nonfungible_position_manager_address: Some(address!( + "655C406EBFa14EE2006250925e54ec43AD184f8B" + )), + tick_lens_address: Some(address!("EB9fFC8bf81b4fFd11fb6A63a6B0f098c6e21950")), + swap_router02_address: Some(address!("bb00FF08d01D300023C629E8fFfFcb65A5a578cE")), v1_mixed_route_quoter_address: None, } } @@ -214,15 +216,15 @@ pub fn avalanche_addresses() -> ChainAddresses { /// Base v3 addresses pub fn base_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x33128a8fC17869897dcE68Ed026d694621f6FDfD".into(), - multicall_address: "0x091e99cb1C49331a94dD62755D168E941AbD0693".into(), - quoter_address: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a".into(), - v3_migrator_address: Some("0x23cF10b1ee3AdfCA73B0eF17C07F7577e7ACd2d7".into()), - nonfungible_position_manager_address: Some( - "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1".into(), - ), - tick_lens_address: Some("0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d".into()), - swap_router02_address: Some("0x2626664c2603336E57B271c5C0b26F421741e481".into()), + v3_core_factory_address: address!("33128a8fC17869897dcE68Ed026d694621f6FDfD"), + multicall_address: address!("091e99cb1C49331a94dD62755D168E941AbD0693"), + quoter_address: address!("3d4e44Eb1374240CE5F1B871ab261CD16335B76a"), + v3_migrator_address: Some(address!("23cF10b1ee3AdfCA73B0eF17C07F7577e7ACd2d7")), + nonfungible_position_manager_address: Some(address!( + "03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1" + )), + tick_lens_address: Some(address!("0CdeE061c75D43c82520eD998C23ac2991c9ac6d")), + swap_router02_address: Some(address!("2626664c2603336E57B271c5C0b26F421741e481")), v1_mixed_route_quoter_address: None, } } @@ -230,15 +232,15 @@ pub fn base_addresses() -> ChainAddresses { /// Base Goerli v3 addresses pub fn base_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x9323c1d6D800ed51Bd7C6B216cfBec678B7d0BC2".into(), - multicall_address: "0xB206027a9E0E13F05eBEFa5D2402Bab3eA716439".into(), - quoter_address: "0xedf539058e28E5937dAef3f69cEd0b25fbE66Ae9".into(), - v3_migrator_address: Some("0x3efe5d02a04b7351D671Db7008ec6eBA9AD9e3aE".into()), - nonfungible_position_manager_address: Some( - "0x3c61369ef0D1D2AFa70d8feC2F31C5D6Ce134F30".into(), - ), - tick_lens_address: Some("0x1acB873Ee909D0c98adB18e4474943249F931b92".into()), - swap_router02_address: Some("0x8357227D4eDc78991Db6FDB9bD6ADE250536dE1d".into()), + v3_core_factory_address: address!("9323c1d6D800ed51Bd7C6B216cfBec678B7d0BC2"), + multicall_address: address!("B206027a9E0E13F05eBEFa5D2402Bab3eA716439"), + quoter_address: address!("edf539058e28E5937dAef3f69cEd0b25fbE66Ae9"), + v3_migrator_address: Some(address!("3efe5d02a04b7351D671Db7008ec6eBA9AD9e3aE")), + nonfungible_position_manager_address: Some(address!( + "3c61369ef0D1D2AFa70d8feC2F31C5D6Ce134F30" + )), + tick_lens_address: Some(address!("1acB873Ee909D0c98adB18e4474943249F931b92")), + swap_router02_address: Some(address!("8357227D4eDc78991Db6FDB9bD6ADE250536dE1d")), v1_mixed_route_quoter_address: None, } } @@ -277,8 +279,7 @@ pub fn v3_factory_addresses() -> ChainAddress { CHAIN_TO_ADDRESSES_MAP .get(&(memo as u32)) .unwrap() - .v3_core_factory_address - .clone(), + .v3_core_factory_address, ); } chain_add @@ -294,7 +295,6 @@ pub fn v3_migrator_addresses() -> ChainAddress { .get(&(memo as u32)) .unwrap() .v3_migrator_address - .clone() .unwrap(), ); } @@ -310,44 +310,46 @@ pub fn multicall_addresses() -> ChainAddress { CHAIN_TO_ADDRESSES_MAP .get(&(memo as u32)) .unwrap() - .multicall_address - .clone(), + .multicall_address, ); } chain_add } +/// The oldest V0 governance address pub fn governance_alpha_v0_addresses() -> AddressMap { - construct_same_address_map("0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F", &[]) + construct_same_address_map(address!("5e4be8Bc9637f0EAA1A755019e06A68ce081D58F"), &[]) } +/// The older V1 governance address pub fn governance_alpha_v1_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0xC4e172459f1E7939D522503B81AFAaC1014CE6F6".into(), + address!("C4e172459f1E7939D522503B81AFAaC1014CE6F6"), ); new_map } +/// The latest governor bravo that is currently admin of timelock pub fn governance_bravo_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x408ED6354d4973f66138C91495F2f2FCbd8724C3".into(), + address!("408ED6354d4973f66138C91495F2f2FCbd8724C3"), ); new_map } pub fn timelock_addresses() -> AddressMap { - construct_same_address_map("0x1a9C8182C09F50C8318d769245beA5", &[]) + construct_same_address_map(address!("1a9C8182C09F50C8318d769245beA52c32BE35BC"), &[]) } pub fn merkle_distributor_address() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x090D4613473dEE047c3f2706764f49E0821D256e".into(), + address!("090D4613473dEE047c3f2706764f49E0821D256e"), ); new_map } @@ -356,7 +358,7 @@ pub fn argent_wallet_detector_address() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8".into(), + address!("eca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8"), ); new_map } @@ -369,8 +371,7 @@ pub fn quoter_address() -> ChainAddress { CHAIN_TO_ADDRESSES_MAP .get(&(memo as u32)) .unwrap() - .quoter_address - .clone(), + .quoter_address, ); } chain_add @@ -391,7 +392,6 @@ pub fn nonfungible_position_manager_address() -> ChainAddress { .get(&(memo as u32)) .unwrap() .nonfungible_position_manager_address - .clone() .unwrap(), ); } @@ -400,14 +400,14 @@ pub fn nonfungible_position_manager_address() -> ChainAddress { } pub fn ens_resgister_address_map() -> AddressMap { - construct_same_address_map("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", &[]) + construct_same_address_map(address!("00000000000C2E074eC69A0dFb2997BA6C7d2e1e"), &[]) } pub fn socks_controller_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x65770b5283117639760beA3F867b69b3697a91dd".into(), + address!("65770b5283117639760beA3F867b69b3697a91dd"), ); new_map } @@ -427,7 +427,6 @@ pub fn tick_lens_addresses() -> ChainAddress { .get(&(memo as u32)) .unwrap() .tick_lens_address - .clone() .unwrap(), ); } @@ -450,7 +449,6 @@ pub fn v1_mixed_route_quoter_address() -> ChainAddress { .get(&(memo as u32)) .unwrap() .v1_mixed_route_quoter_address - .clone() .unwrap(), ); } @@ -458,15 +456,14 @@ pub fn v1_mixed_route_quoter_address() -> ChainAddress { chain_add } -pub fn swap_router02_address(chain_id: u32) -> String { +pub fn swap_router02_address(chain_id: u32) -> Address { if chain_id == ChainId::BNB as u32 { CHAIN_TO_ADDRESSES_MAP .get(&chain_id) .unwrap() .swap_router02_address - .clone() .unwrap() } else { - "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45".into() + address!("68b3465833fb72A70ecDF485E0e4C7bD8665Fc45") } } diff --git a/src/entities/currency.rs b/src/entities/currency.rs index 9e49e79..6077683 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -88,16 +88,14 @@ impl BaseCurrency for Currency { #[cfg(test)] mod tests { use super::*; - use lazy_static::lazy_static; + use crate::token; const ADDRESS_ZERO: &str = "0x0000000000000000000000000000000000000000"; const ADDRESS_ONE: &str = "0x0000000000000000000000000000000000000001"; lazy_static! { - static ref TOKEN0: Token = - Token::new(1, ADDRESS_ZERO.to_string(), 18, None, None, None, None,); - static ref TOKEN1: Token = - Token::new(1, ADDRESS_ONE.to_string(), 18, None, None, None, None,); + static ref TOKEN0: Token = token!(1, ADDRESS_ZERO, 18); + static ref TOKEN1: Token = token!(1, ADDRESS_ONE, 18); } #[test] @@ -122,14 +120,6 @@ mod tests { #[test] fn equals_token0_is_equal_to_another_token0() { - assert!(TOKEN0.equals(&Token::new( - 1, - ADDRESS_ZERO.to_owned(), - 18, - Some("symbol".to_owned()), - Some("name".to_owned()), - None, - None - ))); + assert!(TOKEN0.equals(&token!(1, ADDRESS_ZERO, 18, "symbol", "name"))); } } diff --git a/src/entities/ether.rs b/src/entities/ether.rs index 1cab0d8..c6431b5 100644 --- a/src/entities/ether.rs +++ b/src/entities/ether.rs @@ -1,4 +1,5 @@ use crate::prelude::*; + // Lazy static cache for Ether instances lazy_static! { static ref ETHER_CACHE: Mutex> = Mutex::new(HashMap::new()); @@ -67,7 +68,6 @@ impl Ether { #[cfg(test)] mod tests { use super::*; - use crate::entities::currency::Currency; #[test] fn test_static_constructor_uses_cache() { diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index fe1e54a..a737153 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -129,34 +129,15 @@ impl CurrencyAmount { #[cfg(test)] mod tests { use super::*; - use crate::entities::{ - currency::Currency, ether::Ether, fractions::percent::Percent, token::Token, - }; - use lazy_static::lazy_static; + use crate::token; // Constants for testing const ADDRESS_ONE: &str = "0x0000000000000000000000000000000000000001"; // Lazy static variables for testing currencies lazy_static! { - static ref TOKEN18: Currency = Currency::Token(Token::new( - 1, - ADDRESS_ONE.to_string(), - 18, - None, - None, - None, - None, - )); - static ref TOKEN0: Currency = Currency::Token(Token::new( - 1, - ADDRESS_ONE.to_string(), - 0, - None, - None, - None, - None, - )); + static ref TOKEN18: Currency = Currency::Token(token!(1, ADDRESS_ONE, 18)); + static ref TOKEN0: Currency = Currency::Token(token!(1, ADDRESS_ONE, 0)); } // Unit tests diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index b90d204..6f2af44 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -20,7 +20,7 @@ impl Fraction { } // Function to convert the custom Rounding enum to `bigdecimal`'s `RoundingMode` -fn to_rounding_strategy(rounding: Rounding) -> RoundingMode { +const fn to_rounding_strategy(rounding: Rounding) -> RoundingMode { match rounding { Rounding::RoundDown => RoundingMode::Down, Rounding::RoundHalfUp => RoundingMode::HalfUp, diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index 46a012f..003c722 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -39,7 +39,6 @@ impl Percent { #[cfg(test)] mod tests { use super::*; - use crate::constants::Rounding; #[test] fn test_add() { diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index 92fce9d..e2c8c54 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -126,40 +126,15 @@ where #[cfg(test)] mod test { use super::*; - use crate::entities::{currency::Currency, token::Token}; - use lazy_static::lazy_static; + use crate::token; const ADDRESS_ZERO: &str = "0x0000000000000000000000000000000000000000"; const ADDRESS_ONE: &str = "0x0000000000000000000000000000000000000001"; lazy_static! { - static ref TOKEN0: Currency = Currency::Token(Token::new( - 1, - ADDRESS_ZERO.to_string(), - 18, - None, - None, - None, - None, - )); - static ref TOKEN0_6: Currency = Currency::Token(Token::new( - 1, - ADDRESS_ZERO.to_string(), - 6, - None, - None, - None, - None, - )); - static ref TOKEN1: Currency = Currency::Token(Token::new( - 1, - ADDRESS_ONE.to_string(), - 18, - None, - None, - None, - None, - )); + static ref TOKEN0: Currency = Currency::Token(token!(1, ADDRESS_ZERO, 18)); + static ref TOKEN0_6: Currency = Currency::Token(token!(1, ADDRESS_ZERO, 6)); + static ref TOKEN1: Currency = Currency::Token(token!(1, ADDRESS_ONE, 18)); } #[test] diff --git a/src/entities/token.rs b/src/entities/token.rs index 3b00a0a..0f90cef 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -79,6 +79,44 @@ impl Token { } } +/// Short hand macro to create a token +#[macro_export] +macro_rules! token { + ($chain_id:expr, $address:expr, $decimals:expr) => { + Token::new( + $chain_id, + $address.to_string(), + $decimals, + None, + None, + None, + None, + ) + }; + ($chain_id:expr, $address:expr, $decimals:expr, $symbol:expr) => { + Token::new( + $chain_id, + $address.to_string(), + $decimals, + Some($symbol.to_string()), + None, + None, + None, + ) + }; + ($chain_id:expr, $address:expr, $decimals:expr, $symbol:expr, $name:expr) => { + Token::new( + $chain_id, + $address.to_string(), + $decimals, + Some($symbol.to_string()), + Some($name.to_string()), + None, + None, + ) + }; +} + #[cfg(test)] mod tests { //should test for neg chain_id or neg decimals or neg buy_fee or neg sell_fee, but the compiler will panic by itself, so no need @@ -90,24 +128,8 @@ mod tests { #[test] fn test_token() { - let token = Token::new( - 2, - ADDRESS_ONE.to_string(), - 18, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); - let token_1 = Token::new( - 2, - ADDRESS_TWO.to_string(), - 18, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(2, ADDRESS_ONE, 18, "Test", "Te"); + let token_1 = token!(2, ADDRESS_TWO, 18, "Test", "Te"); assert!(token.address().eq(&ADDRESS_ONE.parse::
().unwrap())); assert!(token_1 @@ -118,212 +140,73 @@ mod tests { #[test] #[should_panic(expected = "DECIMALS")] fn test_expect_revert_overflow_dec() { - let _token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 255, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let _token = token!(4, ADDRESS_ONE, 255, "Test", "Te"); } #[test] fn test_false_if_diff_chain_id() { - let token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); - let token_1 = Token::new( - 3, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(4, ADDRESS_ONE, 25, "Test", "Te"); + let token_1 = token!(3, ADDRESS_ONE, 25, "Test", "Te"); assert!(!token.equals(&token_1)); } #[test] fn test_diff_name() { - let token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("TeW".to_string()), - None, - None, - ); - let token_1 = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(4, ADDRESS_ONE, 25, "Test", "TeW"); + let token_1 = token!(4, ADDRESS_ONE, 25, "Test", "Te"); assert!(token.equals(&token_1), "true even if names differ"); } #[test] fn test_diff_symbol() { - let token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); - let token_1 = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("WETest".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(4, ADDRESS_ONE, 25, "Test", "Te"); + let token_1 = token!(4, ADDRESS_ONE, 25, "WETest", "Te"); assert!(token.equals(&token_1), "true even if symbols differ"); } #[test] fn test_false_if_diff_address() { - let token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); - let token_1 = Token::new( - 4, - DAI_MAINNET.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(4, ADDRESS_ONE, 25, "Test", "Te"); + let token_1 = token!(4, DAI_MAINNET, 25, "Test", "Te"); assert!(!token.equals(&token_1)); } #[test] fn test_true_if_diff_decimals() { - assert!( - Token::new(1, ADDRESS_ONE.to_string(), 9, None, None, None, None,).equals(&Token::new( - 1, - ADDRESS_ONE.to_string(), - 18, - None, - None, - None, - None, - )) - ); + assert!(token!(1, ADDRESS_ONE, 9).equals(&token!(1, ADDRESS_ONE, 18))); } #[test] fn test_assert_both_tokens() { - let token = Token::new( - 4, - ADDRESS_ONE.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); - - let token_1 = Token::new( - 4, - DAI_MAINNET.to_string(), - 25, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(4, ADDRESS_ONE, 25, "Test", "Te"); + let token_1 = token!(4, DAI_MAINNET, 25, "Test", "Te"); assert_eq!(token.equals(&token_1), token_1.equals(&token)); } #[test] fn test_true_on_reference_equality() { - let token = Token::new( - 1, - ADDRESS_ONE.to_string(), - 18, - Some("Test".to_string()), - Some("Te".to_string()), - None, - None, - ); + let token = token!(1, ADDRESS_ONE, 18, "Test", "Te"); assert!(token.equals(&token)); } #[test] fn test_true_if_same_address() { - let token = Token::new( - 1, - ADDRESS_ONE.to_string(), - 9, - Some("abc".to_string()), - Some("def".to_string()), - None, - None, - ); - let token_1 = Token::new( - 1, - ADDRESS_ONE.to_string(), - 18, - Some("ghi".to_string()), - Some("jkl".to_string()), - None, - None, - ); + let token = token!(1, ADDRESS_ONE, 9, "abc", "def"); + let token_1 = token!(1, ADDRESS_ONE, 18, "ghi", "jkl"); assert!(token.equals(&token_1)); } #[test] fn test_true_if_one_token_is_checksummed_and_the_other_is_not() { - let token_a = Token::new( - 1, - DAI_MAINNET.to_string(), - 18, - Some("DAI".to_string()), - None, - None, - None, - ); - let token_b = Token::new( - 1, - DAI_MAINNET.to_string().to_lowercase(), - 18, - Some("DAI".to_string()), - None, - None, - None, - ); + let token_a = token!(1, DAI_MAINNET, 18, "DAI"); + let token_b = token!(1, DAI_MAINNET, 18, "DAI"); assert!(token_a.equals(&token_b)); } diff --git a/src/entities/weth9.rs b/src/entities/weth9.rs index 1b6cf0d..d138fd7 100644 --- a/src/entities/weth9.rs +++ b/src/entities/weth9.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{prelude::*, token}; /// `WETH9` represents the WETH9 contract and provides information about WETH tokens on different Ethereum chains. pub struct WETH9 { @@ -21,158 +21,132 @@ impl WETH9 { // Insert predefined WETH tokens for different chains. tokens.insert( 1, - Token::new( + token!( 1, - "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".to_string(), + "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 3, - Token::new( + token!( 3, - "0xc778417E063141139Fce010982780140Aa0cD5Ab".to_string(), + "0xc778417E063141139Fce010982780140Aa0cD5Ab", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 4, - Token::new( + token!( 4, - "0xc778417E063141139Fce010982780140Aa0cD5Ab".to_string(), + "0xc778417E063141139Fce010982780140Aa0cD5Ab", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 5, - Token::new( + token!( 5, - "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6".to_string(), + "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 42, - Token::new( + token!( 42, - "0xd0A1E359811322d97991E03f863a0C30C2cF029C".to_string(), + "0xd0A1E359811322d97991E03f863a0C30C2cF029C", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 10, - Token::new( + token!( 10, - "0x4200000000000000000000000000000000000006".to_string(), + "0x4200000000000000000000000000000000000006", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 69, - Token::new( + token!( 69, - "0x4200000000000000000000000000000000000006".to_string(), + "0x4200000000000000000000000000000000000006", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 42161, - Token::new( + token!( 42161, - "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1".to_string(), + "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 421611, - Token::new( + token!( 421611, - "0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681".to_string(), + "0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 8453, - Token::new( + token!( 8453, - "0x4200000000000000000000000000000000000006".to_string(), + "0x4200000000000000000000000000000000000006", 18, - Some("WETH".to_string()), - Some("Wrapped Ether".to_string()), - None, - None, + "WETH", + "Wrapped Ether" ), ); tokens.insert( 56, - Token::new( + token!( 56, - "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c".to_string(), + "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 18, - Some("WBNB".to_string()), - Some("Wrapped BNB".to_string()), - None, - None, + "WBNB", + "Wrapped BNB" ), ); tokens.insert( 137, - Token::new( + token!( 137, - "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270".to_string(), + "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 18, - Some("WMATIC".to_string()), - Some("Wrapped MATIC".to_string()), - None, - None, + "WMATIC", + "Wrapped MATIC" ), ); tokens.insert( 43114, - Token::new( + token!( 43114, - "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7".to_string(), + "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 18, - Some("WAVAX".to_string()), - Some("Wrapped AVAX".to_string()), - None, - None, + "WAVAX", + "Wrapped AVAX" ), ); diff --git a/src/prelude.rs b/src/prelude.rs index 56f2d7f..9eb63cd 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -3,17 +3,19 @@ pub use crate::{ constants::{Rounding, MAX_UINT256}, entities::{ base_currency::{BaseCurrency, CurrencyLike}, - currency::CurrencyTrait, + currency::{Currency, CurrencyTrait}, ether::Ether, fractions::{ currency_amount::CurrencyAmount, fraction::{Fraction, FractionLike, FractionTrait}, + percent::Percent, + price::Price, }, token::Token, weth9::WETH9, }, }; -pub use alloy_primitives::Address; +pub use alloy_primitives::{address, Address}; pub use bigdecimal::{BigDecimal, RoundingMode}; pub use lazy_static::lazy_static; pub use num_bigint::{BigInt, BigUint, ToBigInt, ToBigUint}; diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index ecbb3b2..5d8d149 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -36,7 +36,6 @@ pub fn sqrt(value: &BigInt) -> BigInt { #[cfg(test)] mod tests { use super::*; - use num_traits::Num; #[test] fn test_sqrt_0_1000() {