diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..98e5bb5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,45 @@ +name: Rust Linting + +on: + push: + branches: + - master + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + name: Rust Lint Check + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Cache Cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt, clippy + + - name: Check lint + run: cargo clippy -- -D warnings + + - name: Check formatting + run: cargo fmt -- --check diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5e81d31..61ace3e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,4 +1,4 @@ -name: Rust +name: Rust Tests on: push: diff --git a/Cargo.lock b/Cargo.lock index 4984df3..cfeba35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c0e5e60ff0e0c34c553822dabcfe0f5fece5a8c52f08a915be8c737de4b03fa" +checksum = "9c234f92024707f224510ff82419b2be0e1d8e1fd911defcac5a085cd7f83898" dependencies = [ "alloy-rlp", "bytes", @@ -35,6 +35,7 @@ dependencies = [ "derive_more", "hex-literal", "itoa", + "keccak-asm", "proptest", "rand 0.8.5", "ruint", @@ -312,6 +313,15 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -597,6 +607,16 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "keccak-asm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb8515fff80ed850aea4a1595f2e519c003e2a00a82fe168ebf5269196caf444" +dependencies = [ + "digest 0.10.7", + "sha3-asm", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1222,6 +1242,16 @@ dependencies = [ "keccak", ] +[[package]] +name = "sha3-asm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac61da6b35ad76b195eb4771210f947734321a8d81d7738e1580d953bc7a15e" +dependencies = [ + "cc", + "cfg-if", +] + [[package]] name = "simdutf8" version = "0.1.4" @@ -1397,7 +1427,7 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uniswap-sdk-core-rust" -version = "0.4.0" +version = "0.4.1" dependencies = [ "alloy-primitives", "eth_checksum", @@ -1608,9 +1638,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.30" +version = "0.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 355d4ee..336ef65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "uniswap-sdk-core-rust" -version = "0.4.0" +version = "0.4.1" edition = "2021" -authors = ["malik ", "aurelhino "] +authors = ["malik ", "Shuhui Luo "] description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange" license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -alloy-primitives = "0.5.3" +alloy-primitives = "0.5.4" eth_checksum = "0.1.2" lazy_static = "1.4.0" num-bigint = "0.4.4" diff --git a/src/addresses.rs b/src/addresses.rs index 25975ca..c1e3eac 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -70,16 +70,16 @@ lazy_static! { construct_same_address_map(V2_ROUTER_ADDRESS, &[]); } -impl ChainAddresses { +impl Default for ChainAddresses { /// Networks that share most of the same addresses i.e. Mainnet, Goerli, Optimism, Arbitrum, Polygon - pub fn default() -> Self { - ChainAddresses { - v3_core_factory_address: "0x1F98431c8aD98523631AE4a59f267346ea31F984".to_string(), - multicall_address: "0x1F98415757620B543A52E61c46B32eB19261F984".to_string(), - quoter_address: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6".to_string(), - v3_migrator_address: Some("0xA5644E29708357803b5A882D272c41cC0dF92B34".to_string()), + 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".to_string(), + "0xC36442b4a4522E871399CD717aBDD847Ab11FE88".into(), ), tick_lens_address: None, swap_router02_address: None, @@ -89,17 +89,17 @@ impl ChainAddresses { } pub fn mainnet_address() -> ChainAddresses { - let mut mainnet_addresses = ChainAddresses::default(); - mainnet_addresses.v1_mixed_route_quoter_address = - Some("0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E".to_string()); - mainnet_addresses + ChainAddresses { + v1_mixed_route_quoter_address: Some("0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E".into()), + ..Default::default() + } } pub fn goerli_address() -> ChainAddresses { - let mut mainnet_addresses = ChainAddresses::default(); - mainnet_addresses.v1_mixed_route_quoter_address = - Some("0xBa60b6e6fF25488308789E6e0A65D838be34194e".to_string()); - mainnet_addresses + ChainAddresses { + v1_mixed_route_quoter_address: Some("0xBa60b6e6fF25488308789E6e0A65D838be34194e".into()), + ..Default::default() + } } pub fn optimism_addresses() -> ChainAddresses { @@ -107,11 +107,11 @@ pub fn optimism_addresses() -> ChainAddresses { } pub fn arbitum_one_addresses() -> ChainAddresses { - let mut mainnet_addresses = ChainAddresses::default(); - mainnet_addresses.multicall_address = "0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB".to_string(); - mainnet_addresses.tick_lens_address = - Some("0xbfd8137f7d1516D3ea5cA83523914859ec47F573".to_string()); - mainnet_addresses + ChainAddresses { + multicall_address: "0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB".into(), + tick_lens_address: Some("0xbfd8137f7d1516D3ea5cA83523914859ec47F573".into()), + ..Default::default() + } } pub fn polygon_addresses() -> ChainAddresses { @@ -121,14 +121,14 @@ pub fn polygon_addresses() -> ChainAddresses { /// celo v3 addresses pub fn celo_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xAfE208a311B21f13EF87E33A90049fC17A7acDEc".to_string(), - multicall_address: "0x633987602DE5C4F337e3DbF265303A1080324204".to_string(), - quoter_address: "0x82825d0554fA07f7FC52Ab63c961F330fdEFa8E8".to_string(), - v3_migrator_address: Some("0x3cFd4d48EDfDCC53D3f173F596f621064614C582".to_string()), + 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".to_string(), + "0x3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A".into(), ), - tick_lens_address: Some("0x5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D".to_string()), + tick_lens_address: Some("0x5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D".into()), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -137,15 +137,15 @@ pub fn celo_addresses() -> ChainAddresses { /// BNB v3 addresses pub fn bnb_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7".to_string(), - multicall_address: "0x963Df249eD09c358A4819E39d9Cd5736c3087184".to_string(), - quoter_address: "0x78D78E420Da98ad378D7799bE8f4AF69033EB077".to_string(), - v3_migrator_address: Some("0x32681814957e0C13117ddc0c2aba232b5c9e760f".to_string()), + 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".to_string(), + "0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613".into(), ), - tick_lens_address: Some("0xD9270014D396281579760619CCf4c3af0501A47C".to_string()), - swap_router02_address: Some("0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2".to_string()), + tick_lens_address: Some("0xD9270014D396281579760619CCf4c3af0501A47C".into()), + swap_router02_address: Some("0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2".into()), v1_mixed_route_quoter_address: None, } } @@ -153,14 +153,14 @@ pub fn bnb_addresses() -> ChainAddresses { /// Optimism Goerli addresses pub fn optimism_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0xB656dA17129e7EB733A557f4EBc57B76CFbB5d10".to_string(), - multicall_address: "0x07F2D8a2a02251B62af965f22fC4744A5f96BCCd".to_string(), - quoter_address: "0x9569CbA925c8ca2248772A9A4976A516743A246F".to_string(), - v3_migrator_address: Some("0xf6c55fBe84B1C8c3283533c53F51bC32F5C7Aba8".to_string()), + 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".to_string(), + "0x39Ca85Af2F383190cBf7d7c41ED9202D27426EF6".into(), ), - tick_lens_address: Some("0xe6140Bd164b63E8BfCfc40D5dF952f83e171758e".to_string()), + tick_lens_address: Some("0xe6140Bd164b63E8BfCfc40D5dF952f83e171758e".into()), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -169,14 +169,14 @@ pub fn optimism_goerli_addresses() -> ChainAddresses { /// Arbitrum Goerli v3 addresses pub fn arbitrum_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x4893376342d5D7b3e31d4184c08b265e5aB2A3f6".to_string(), - multicall_address: "0x8260CB40247290317a4c062F3542622367F206Ee".to_string(), - quoter_address: "0x1dd92b83591781D0C6d98d07391eea4b9a6008FA".to_string(), - v3_migrator_address: Some("0xA815919D2584Ac3F76ea9CB62E6Fd40a43BCe0C3".to_string()), + 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".to_string(), + "0x622e4726a167799826d1E1D150b076A7725f5D81".into(), ), - tick_lens_address: Some("0xb52429333da969a0C79a60930a4Bf0020E5D1DE8".to_string()), + tick_lens_address: Some("0xb52429333da969a0C79a60930a4Bf0020E5D1DE8".into()), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -185,14 +185,14 @@ pub fn arbitrum_goerli_addresses() -> ChainAddresses { /// sepolia v3 addresses pub fn sepolia_address() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x0227628f3F023bb0B980b67D528571c95c6DaC1c".to_string(), - multicall_address: "0xD7F33bCdb21b359c8ee6F0251d30E94832baAd07".to_string(), - quoter_address: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3".to_string(), - v3_migrator_address: Some("0x729004182cF005CEC8Bd85df140094b6aCbe8b15".to_string()), + 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".to_string(), + "0x1238536071E1c677A632429e3655c799b22cDA52".into(), ), - tick_lens_address: Some("0xd7f33bcdb21b359c8ee6f0251d30e94832baad07".to_string()), + tick_lens_address: Some("0xd7f33bcdb21b359c8ee6f0251d30e94832baad07".into()), swap_router02_address: None, v1_mixed_route_quoter_address: None, } @@ -201,15 +201,15 @@ pub fn sepolia_address() -> ChainAddresses { /// Avalanche v3 addresses pub fn avalanche_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD".to_string(), - multicall_address: "0x0139141Cd4Ee88dF3Cdb65881D411bAE271Ef0C2".to_string(), - quoter_address: "0xbe0F5544EC67e9B3b2D979aaA43f18Fd87E6257F".to_string(), - v3_migrator_address: Some("0x44f5f1f5E452ea8d29C890E8F6e893fC0f1f0f97".to_string()), + 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".to_string(), + "0x655C406EBFa14EE2006250925e54ec43AD184f8B".into(), ), - tick_lens_address: Some("0xEB9fFC8bf81b4fFd11fb6A63a6B0f098c6e21950".to_string()), - swap_router02_address: Some("0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE".to_string()), + tick_lens_address: Some("0xEB9fFC8bf81b4fFd11fb6A63a6B0f098c6e21950".into()), + swap_router02_address: Some("0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE".into()), v1_mixed_route_quoter_address: None, } } @@ -217,15 +217,15 @@ pub fn avalanche_addresses() -> ChainAddresses { /// Base v3 addresses pub fn base_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x33128a8fC17869897dcE68Ed026d694621f6FDfD".to_string(), - multicall_address: "0x091e99cb1C49331a94dD62755D168E941AbD0693".to_string(), - quoter_address: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a".to_string(), - v3_migrator_address: Some("0x23cF10b1ee3AdfCA73B0eF17C07F7577e7ACd2d7".to_string()), + 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".to_string(), + "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1".into(), ), - tick_lens_address: Some("0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d".to_string()), - swap_router02_address: Some("0x2626664c2603336E57B271c5C0b26F421741e481".to_string()), + tick_lens_address: Some("0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d".into()), + swap_router02_address: Some("0x2626664c2603336E57B271c5C0b26F421741e481".into()), v1_mixed_route_quoter_address: None, } } @@ -233,15 +233,15 @@ pub fn base_addresses() -> ChainAddresses { /// Base Goerli v3 addresses pub fn base_goerli_addresses() -> ChainAddresses { ChainAddresses { - v3_core_factory_address: "0x9323c1d6D800ed51Bd7C6B216cfBec678B7d0BC2".to_string(), - multicall_address: "0xB206027a9E0E13F05eBEFa5D2402Bab3eA716439".to_string(), - quoter_address: "0xedf539058e28E5937dAef3f69cEd0b25fbE66Ae9".to_string(), - v3_migrator_address: Some("0x3efe5d02a04b7351D671Db7008ec6eBA9AD9e3aE".to_string()), + 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".to_string(), + "0x3c61369ef0D1D2AFa70d8feC2F31C5D6Ce134F30".into(), ), - tick_lens_address: Some("0x1acB873Ee909D0c98adB18e4474943249F931b92".to_string()), - swap_router02_address: Some("0x8357227D4eDc78991Db6FDB9bD6ADE250536dE1d".to_string()), + tick_lens_address: Some("0x1acB873Ee909D0c98adB18e4474943249F931b92".into()), + swap_router02_address: Some("0x8357227D4eDc78991Db6FDB9bD6ADE250536dE1d".into()), v1_mixed_route_quoter_address: None, } } @@ -328,7 +328,7 @@ pub fn governance_alpha_v1_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0xC4e172459f1E7939D522503B81AFAaC1014CE6F6".to_string(), + "0xC4e172459f1E7939D522503B81AFAaC1014CE6F6".into(), ); new_map } @@ -337,7 +337,7 @@ pub fn governance_bravo_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x408ED6354d4973f66138C91495F2f2FCbd8724C3".to_string(), + "0x408ED6354d4973f66138C91495F2f2FCbd8724C3".into(), ); new_map } @@ -350,7 +350,7 @@ pub fn merkle_distributor_address() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x090D4613473dEE047c3f2706764f49E0821D256e".to_string(), + "0x090D4613473dEE047c3f2706764f49E0821D256e".into(), ); new_map } @@ -359,7 +359,7 @@ pub fn argent_wallet_detector_address() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8".to_string(), + "0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8".into(), ); new_map } @@ -410,7 +410,7 @@ pub fn socks_controller_addresses() -> AddressMap { let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u32, - "0x65770b5283117639760beA3F867b69b3697a91dd".to_string(), + "0x65770b5283117639760beA3F867b69b3697a91dd".into(), ); new_map } diff --git a/src/entities/ether.rs b/src/entities/ether.rs index 4f37c4a..392cce2 100644 --- a/src/entities/ether.rs +++ b/src/entities/ether.rs @@ -73,7 +73,6 @@ impl Ether { } } - #[cfg(test)] mod tests { use super::*; diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 0fed4e2..e6ca2da 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -29,10 +29,7 @@ impl CurrencyAmount { let numerator = numerator.into(); let denominator = denominator.into(); // Ensure the amount does not exceed MAX_UINT256 - assert!( - numerator.div_floor(&denominator).le(&MAX_UINT256), - "AMOUNT" - ); + assert!(numerator.div_floor(&denominator).le(&MAX_UINT256), "AMOUNT"); let exponent = currency.decimals(); FractionTrait::new( numerator, @@ -88,10 +85,7 @@ impl CurrencyAmount { // Addition of another currency amount to the current amount pub fn add(&self, other: &Self) -> Self { - assert!( - self.meta.currency.equals(&other.meta.currency), - "CURRENCY" - ); + assert!(self.meta.currency.equals(&other.meta.currency), "CURRENCY"); let added = self.as_fraction().add(&other.as_fraction()); Self::from_fractional_amount( self.meta.currency.clone(), @@ -102,10 +96,7 @@ impl CurrencyAmount { // Subtraction of another currency amount from the current amount pub fn subtract(&self, other: &Self) -> Self { - assert!( - self.meta.currency.equals(&other.meta.currency), - "CURRENCY" - ); + assert!(self.meta.currency.equals(&other.meta.currency), "CURRENCY"); let subtracted = self.as_fraction().subtract(&other.as_fraction()); Self::from_fractional_amount( self.meta.currency.clone(), @@ -123,10 +114,7 @@ impl CurrencyAmount { // Convert the currency amount to a string with a fixed number of decimal places pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { - assert!( - decimal_places <= self.meta.currency.decimals(), - "DECIMALS" - ); + assert!(decimal_places <= self.meta.currency.decimals(), "DECIMALS"); self.as_fraction() .divide(&Fraction::new(self.meta.decimal_scale.clone(), 1)) .to_fixed(decimal_places, rounding) diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 791be4d..a926455 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -204,7 +204,6 @@ impl FractionTrait for FractionLike { } } - #[cfg(test)] mod tests { use super::*; diff --git a/src/entities/weth9.rs b/src/entities/weth9.rs index f0fd755..f1fbc10 100644 --- a/src/entities/weth9.rs +++ b/src/entities/weth9.rs @@ -14,10 +14,9 @@ impl Default for WETH9 { } } - /// Implementation for methods specific to the `WETH9` struct. +/// Implementation for methods specific to the `WETH9` struct. impl WETH9 { pub fn new() -> Self { - let mut tokens = HashMap::new(); // Insert predefined WETH tokens for different chains. @@ -181,7 +180,7 @@ impl WETH9 { Self { tokens } } - /// Retrieves the WETH token for a specific chain ID, if it exists. + /// Retrieves the WETH token for a specific chain ID, if it exists. /// /// # Arguments ///