Skip to content

Commit

Permalink
Replace magic numbers with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcenteno committed Aug 28, 2023
1 parent 4147232 commit 741d8df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/zks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */

Expand Down
11 changes: 5 additions & 6 deletions src/zks_wallet/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 741d8df

Please sign in to comment.