From 741d8df1bc3c127973103c6865f006055c074cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20P=2E=20Centeno?= Date: Mon, 28 Aug 2023 15:49:05 -0300 Subject: [PATCH] Replace magic numbers with constants --- src/zks_utils.rs | 2 ++ src/zks_wallet/wallet.rs | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/zks_utils.rs b/src/zks_utils.rs index 9dd7e8c..65c11ca 100644 --- a/src/zks_utils.rs +++ b/src/zks_utils.rs @@ -13,6 +13,7 @@ use std::str::FromStr; pub const ETH_CHAIN_ID: u16 = 0x9; pub const ERA_CHAIN_ID: u16 = 0x10E; +pub const ERA_MAINNET_CHAIN_ID: u16 = 324; pub const EIP712_TX_TYPE: u8 = 0x71; // The large L2 gas per pubdata to sign. This gas is enough to ensure that // any reasonable limit will be accepted. Note, that the operator is NOT required to @@ -35,6 +36,7 @@ pub const MAX_GAS_PER_PUBDATA_BYTE: u64 = MAX_L2_TX_GAS_LIMIT / GUARANTEED_PUBDA pub const RECOMMENDED_DEPOSIT_L1_GAS_LIMIT: u64 = 10000000; pub const RECOMMENDED_DEPOSIT_L2_GAS_LIMIT: u64 = 10000000; pub const DEPOSIT_GAS_PER_PUBDATA_LIMIT: u64 = 800; +pub const DEFAULT_ERC20_DEPOSIT_GAS_LIMIT: u64 = 300000_u64; /* Contracts */ diff --git a/src/zks_wallet/wallet.rs b/src/zks_wallet/wallet.rs index ed7de3c..03acd6b 100644 --- a/src/zks_wallet/wallet.rs +++ b/src/zks_wallet/wallet.rs @@ -3,7 +3,7 @@ pub mod deposit_request; use self::deposit_request::DepositRequest; use super::{Overrides, ZKSWalletError}; -use crate::zks_utils::DEPOSIT_GAS_PER_PUBDATA_LIMIT; +use crate::zks_utils::{DEPOSIT_GAS_PER_PUBDATA_LIMIT, DEFAULT_ERC20_DEPOSIT_GAS_LIMIT, ERA_MAINNET_CHAIN_ID}; use crate::{ abi, contracts::main_contract::{MainContract, MainContractInstance}, @@ -336,15 +336,14 @@ where let gas_limit: U256 = { let address_str = format!("{l1_token_address:?}"); - let default_erc20_deposit_gas_limit = 300000_u64; // FIXME make it a constant. - let is_mainnet = self.get_era_provider()?.get_chainid().await? == 324_i32.into(); + let is_mainnet = self.get_era_provider()?.get_chainid().await? == ERA_MAINNET_CHAIN_ID.into(); if is_mainnet { (*ERC20_DEPOSIT_GAS_LIMITS) .get(&address_str) - .unwrap_or(&default_erc20_deposit_gas_limit) - .to_owned() // FIXME fix unwrap + .unwrap_or(&DEFAULT_ERC20_DEPOSIT_GAS_LIMIT) + .to_owned() } else { - default_erc20_deposit_gas_limit + DEFAULT_ERC20_DEPOSIT_GAS_LIMIT } } .into();