From f7b361e2523e62919d99706dc49b0b60ab8c3726 Mon Sep 17 00:00:00 2001 From: Juraj Piar Date: Tue, 19 Sep 2023 00:29:25 +0100 Subject: [PATCH] Revert "Revert "refactor(ticker): extracts get_testnet_addr_mapping"" This reverts commit 8b9639be9dff8ba92e90ade101b18a7cb5039004. --- Cargo.lock | 160 ++++++++++++++---- .../src/fee_ticker/ticker_api/coingecko.rs | 56 +++--- etc/token-lists/localhost.json | 4 +- etc/token-lists/testnet.json | 4 +- 4 files changed, 169 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87eb2656e..c515e67d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -822,10 +822,10 @@ name = "block_revert" version = "1.0.0" dependencies = [ "anyhow", - "ethabi", + "ethabi 16.0.0", "structopt", "tokio", - "web3", + "web3 0.18.0", "zksync_config", "zksync_eth_client", "zksync_storage", @@ -898,6 +898,12 @@ dependencies = [ "iovec", ] +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + [[package]] name = "bytes" version = "1.1.0" @@ -1498,6 +1504,22 @@ dependencies = [ "serde", ] +[[package]] +name = "ethabi" +version = "14.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01317735d563b3bad2d5f90d2e1799f414165408251abb762510f40e790e69a" +dependencies = [ + "anyhow", + "ethereum-types 0.11.0", + "hex", + "serde", + "serde_json", + "sha3", + "thiserror", + "uint", +] + [[package]] name = "ethabi" version = "16.0.0" @@ -4000,10 +4022,10 @@ name = "remove_proofs" version = "1.0.0" dependencies = [ "anyhow", - "ethabi", + "ethabi 16.0.0", "structopt", "tokio", - "web3", + "web3 0.18.0", "zksync_config", "zksync_eth_client", "zksync_storage", @@ -4060,6 +4082,33 @@ dependencies = [ "sha3", ] +[[package]] +name = "rif_rollup_wallet_generator" +version = "1.0.0" +dependencies = [ + "anyhow", + "async-trait", + "ethabi 14.1.0", + "hex", + "jsonrpc-core 17.1.0", + "num", + "reqwest", + "serde", + "serde_json", + "sha2 0.8.2", + "thiserror", + "tokio", + "web3 0.16.0", + "zksync", + "zksync_config", + "zksync_crypto", + "zksync_eth_client", + "zksync_eth_signer", + "zksync_test_account", + "zksync_types", + "zksync_utils", +] + [[package]] name = "ring" version = "0.16.20" @@ -4615,6 +4664,21 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "soketto" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c71ed3d54db0a699f4948e1bb3e45b450fa31fe602621dee6680361d569c88" +dependencies = [ + "base64 0.12.3", + "bytes 0.5.6", + "futures 0.3.17", + "httparse", + "log 0.4.14", + "rand 0.7.3", + "sha-1 0.9.8", +] + [[package]] name = "soketto" version = "0.7.1" @@ -5618,6 +5682,40 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web3" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc4c18ae15621f764fab919f7e4a83d87163494cbc3460884debef7c6bc1bc6b" +dependencies = [ + "arrayvec 0.5.2", + "base64 0.13.0", + "bytes 1.1.0", + "derive_more", + "ethabi 14.1.0", + "ethereum-types 0.11.0", + "futures 0.3.17", + "futures-timer", + "headers", + "hex", + "jsonrpc-core 17.1.0", + "log 0.4.14", + "parking_lot 0.11.2", + "pin-project", + "reqwest", + "rlp", + "secp256k1 0.20.3", + "serde", + "serde_json", + "soketto 0.4.2", + "tiny-keccak 2.0.2", + "tokio", + "tokio-stream", + "tokio-util", + "url 2.2.2", + "web3-async-native-tls", +] + [[package]] name = "web3" version = "0.18.0" @@ -5628,7 +5726,7 @@ dependencies = [ "base64 0.13.0", "bytes 1.1.0", "derive_more", - "ethabi", + "ethabi 16.0.0", "ethereum-types 0.12.1", "futures 0.3.17", "futures-timer", @@ -5645,7 +5743,7 @@ dependencies = [ "secp256k1 0.21.3", "serde", "serde_json", - "soketto", + "soketto 0.7.1", "tiny-keccak 2.0.2", "tokio", "tokio-stream", @@ -5840,7 +5938,7 @@ version = "0.3.0" dependencies = [ "anyhow", "async-trait", - "ethabi", + "ethabi 16.0.0", "hex", "jsonrpc-core 17.1.0", "num", @@ -5850,7 +5948,7 @@ dependencies = [ "sha2 0.8.2", "thiserror", "tokio", - "web3", + "web3 0.18.0", "zksync_config", "zksync_crypto", "zksync_eth_client", @@ -5874,7 +5972,7 @@ dependencies = [ "chrono", "criterion", "ctrlc", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "hex", "hyper 0.14.14", @@ -5903,7 +6001,7 @@ dependencies = [ "tiny-keccak 1.5.0", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_api_client", "zksync_api_types", "zksync_balancer", @@ -5971,7 +6069,7 @@ name = "zksync_basic_types" version = "1.0.0" dependencies = [ "serde", - "web3", + "web3 0.18.0", ] [[package]] @@ -6010,7 +6108,7 @@ dependencies = [ name = "zksync_contracts" version = "1.0.0" dependencies = [ - "ethabi", + "ethabi 16.0.0", "serde_json", ] @@ -6024,7 +6122,7 @@ dependencies = [ "async-trait", "chrono", "ctrlc", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "itertools 0.9.0", "metrics", @@ -6036,7 +6134,7 @@ dependencies = [ "tiny-keccak 1.5.0", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_api_types", "zksync_balancer", "zksync_config", @@ -6061,7 +6159,7 @@ version = "1.0.0" dependencies = [ "base64 0.13.0", "bincode", - "ethabi", + "ethabi 16.0.0", "fnv", "franklin-crypto", "hex", @@ -6085,7 +6183,7 @@ dependencies = [ "async-trait", "chrono", "db_test_macro", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "hex", "jsonrpc-core 18.0.0", @@ -6096,7 +6194,7 @@ dependencies = [ "tiny-keccak 1.5.0", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_config", "zksync_contracts", "zksync_crypto", @@ -6111,7 +6209,7 @@ name = "zksync_eth_client" version = "1.0.0" dependencies = [ "anyhow", - "ethabi", + "ethabi 16.0.0", "hex", "metrics", "parity-crypto 0.8.0", @@ -6119,7 +6217,7 @@ dependencies = [ "sha3", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_config", "zksync_contracts", "zksync_eth_signer", @@ -6134,7 +6232,7 @@ dependencies = [ "async-trait", "chrono", "ctrlc", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "hex", "lazy_static", @@ -6144,7 +6242,7 @@ dependencies = [ "serde_json", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_basic_types", "zksync_config", "zksync_contracts", @@ -6175,7 +6273,7 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "web3", + "web3 0.18.0", "zksync_types", ] @@ -6204,7 +6302,7 @@ dependencies = [ "anyhow", "async-trait", "chrono", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "hex", "log 0.4.14", @@ -6212,7 +6310,7 @@ dependencies = [ "num", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_api", "zksync_config", "zksync_contracts", @@ -6235,7 +6333,7 @@ dependencies = [ "tokio", "tokio-stream", "vlog", - "web3", + "web3 0.18.0", "zksync_config", "zksync_eth_client", "zksync_utils", @@ -6316,7 +6414,7 @@ dependencies = [ "structopt", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_circuit", "zksync_config", "zksync_crypto", @@ -6389,7 +6487,7 @@ dependencies = [ "serde_json", "thiserror", "vlog", - "web3", + "web3 0.18.0", "zksync_crypto", "zksync_types", "zksync_utils", @@ -6441,7 +6539,7 @@ name = "zksync_testkit" version = "1.0.0" dependencies = [ "anyhow", - "ethabi", + "ethabi 16.0.0", "futures 0.3.17", "itertools 0.9.0", "num", @@ -6450,7 +6548,7 @@ dependencies = [ "structopt", "tokio", "vlog", - "web3", + "web3 0.18.0", "zksync_circuit", "zksync_config", "zksync_contracts", @@ -6485,7 +6583,7 @@ dependencies = [ "bigdecimal", "chrono", "criterion", - "ethabi", + "ethabi 16.0.0", "hex", "itertools 0.9.0", "num", @@ -6498,7 +6596,7 @@ dependencies = [ "thiserror", "tiny-keccak 1.5.0", "vlog", - "web3", + "web3 0.18.0", "zksync_basic_types", "zksync_crypto", "zksync_utils", diff --git a/core/bin/zksync_api/src/fee_ticker/ticker_api/coingecko.rs b/core/bin/zksync_api/src/fee_ticker/ticker_api/coingecko.rs index ea7b1b3f0..011989d4a 100644 --- a/core/bin/zksync_api/src/fee_ticker/ticker_api/coingecko.rs +++ b/core/bin/zksync_api/src/fee_ticker/ticker_api/coingecko.rs @@ -47,26 +47,7 @@ impl CoinGeckoAPI { let network = zksync_config.chain.eth.network; // Get tokens from etc/tokens/testnet.json and etc/tokens/mainnet.json - let address_mapping = if network == Network::Testnet { - let testnet_tokens_file = Path::new("etc/tokens/testnet.json"); - let mainnet_tokens_file = Path::new("etc/tokens/mainnet.json"); - - let testnet_tokens_file = File::open(testnet_tokens_file)?; - let mainnet_tokens_file = File::open(mainnet_tokens_file)?; - - let testnet_tokens: Vec = TokenInfo::from_json(testnet_tokens_file)?; - let mainnet_tokens: Vec = TokenInfo::from_json(mainnet_tokens_file)?; - - let mut address_mapping = HashMap::new(); - - for (testnet_token, mainnet_token) in testnet_tokens.iter().zip(mainnet_tokens.iter()) { - address_mapping.insert(testnet_token.address, mainnet_token.address); - } - - address_mapping - } else { - HashMap::new() - }; + let address_mapping = get_testnet_addr_mapping(network)?; // create a testnet to mainnet address mapping let token_list_url = base_url @@ -103,6 +84,27 @@ impl CoinGeckoAPI { } } +fn get_testnet_addr_mapping(network: Network) -> Result, anyhow::Error> { + let mut address_mapping = HashMap::new(); + + if network == Network::Testnet { + let testnet_tokens_file = Path::new("etc/tokens/testnet.json"); + let mainnet_tokens_file = Path::new("etc/tokens/mainnet.json"); + + let testnet_tokens_file = File::open(testnet_tokens_file)?; + let mainnet_tokens_file = File::open(mainnet_tokens_file)?; + + let testnet_tokens: Vec = TokenInfo::from_json(testnet_tokens_file)?; + let mainnet_tokens: Vec = TokenInfo::from_json(mainnet_tokens_file)?; + + for (testnet_token, mainnet_token) in testnet_tokens.iter().zip(mainnet_tokens.iter()) { + address_mapping.insert(testnet_token.address, mainnet_token.address); + } + } + + Ok(address_mapping) +} + #[async_trait] impl TokenPriceAPI for CoinGeckoAPI { async fn get_price(&self, token: &Token) -> Result { @@ -233,4 +235,18 @@ mod tests { .await .expect("Failed to get data from ticker"); } + + #[test] + fn should_return_empty_map_for_non_testnet() { + let actual_map = get_testnet_addr_mapping(Network::Mainnet).unwrap(); + + assert!(actual_map.is_empty()); + } + + #[test] + fn should_return_mapping_for_testnet() { + let actual_map = get_testnet_addr_mapping(Network::Testnet).unwrap(); + + assert!(!actual_map.is_empty()); + } } diff --git a/etc/token-lists/localhost.json b/etc/token-lists/localhost.json index 768d50519..ca3c812a8 100644 --- a/etc/token-lists/localhost.json +++ b/etc/token-lists/localhost.json @@ -7,8 +7,8 @@ }, { "decimals": 18, - "symbol": "rDOC", - "name": "rDOC", + "symbol": "RDOC", + "name": "RDOC", "address": "0x33F3e4Fd2584EBA630890662a2F0E11087fd512e" } ] diff --git a/etc/token-lists/testnet.json b/etc/token-lists/testnet.json index e2865c31e..3c1f0c1fe 100644 --- a/etc/token-lists/testnet.json +++ b/etc/token-lists/testnet.json @@ -8,8 +8,8 @@ { "address": "0xC3De9f38581F83e281F260D0ddBAac0E102Ff9F8", "decimals": 18, - "symbol": "rDOC", - "name": "rDOC" + "symbol": "RDOC", + "name": "RDOC" } ] \ No newline at end of file