Skip to content

Commit

Permalink
wip: investigate how to set gas_per_pubdata dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
fborello-lambda committed Sep 20, 2024
1 parent 3ad4a82 commit a1dbfa3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/eip712/transaction_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ impl TryFrom<DeployRequest> for Eip712TransactionRequest {
}
factory_deps.push(request.contract_bytecode.clone());
factory_deps
});
})
.gas_per_pubdata(U256::from(50000_u32));

let contract_deployer = Abi::load(BufReader::new(
File::open(contract_deployer_path).map_err(|e| {
Expand Down
2 changes: 1 addition & 1 deletion src/zk_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use ethers::{
};

use crate::{
eip712::{Eip712Meta, Eip712Transaction, Eip712TransactionRequest},
eip712::{Eip712Transaction, Eip712TransactionRequest},
types::L1TxOverrides,
utils,
};
Expand Down
13 changes: 7 additions & 6 deletions src/zk_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,24 +525,25 @@ where
transaction: Eip712TransactionRequest,
) -> Result<TransactionReceipt, ZKWalletError> {
let mut request: Eip712TransactionRequest = transaction;
let gas_price = self.l2_provider().get_gas_price().await?;

request = request
.from(self.l2_address())
.chain_id(self.l2_provider().get_chainid().await?)
.nonce(
self.l2_provider()
.get_transaction_count(self.l2_address(), None)
.await?,
)
.gas_price(gas_price)
.max_fee_per_gas(gas_price);
);

let custom_data = request.clone().custom_data;
let fee = self.l2_provider().estimate_fee(request.clone()).await?;
let gas = self.l2_provider().zk_estimate_gas(request.clone()).await?;
let gas_price = self.l2_provider().get_gas_price().await?;
request = request
.max_priority_fee_per_gas(fee.max_priority_fee_per_gas)
.gas_limit(fee.gas_limit)
.max_fee_per_gas(fee.max_fee_per_gas);
.gas_limit(gas)
.max_fee_per_gas(fee.max_fee_per_gas)
.gas_price(gas_price);
let signable_data: Eip712Transaction = request.clone().try_into().map_err(|e| {
ZKWalletError::SendEIP712(format!("error converting deploy to eip 712 {e}"))
})?;
Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn signer(
Arc::new(SignerMiddleware::<Provider<Http>, LocalWallet>::new(
provider,
LocalWallet::from_str(&std::env::var("PRIVATE_KEY").unwrap_or(
"0x385c546456b6a603a1cfcaa9ec9494ba4832da08dd6bcf4de9a71e4a01b74924".to_owned(),
"0x850683b40d4a740aa6e745f889a6fdc8327be76e122f5aba645a5b02d0248db8".to_owned(),
))
.unwrap()
.with_chain_id(chain_id),
Expand Down
9 changes: 6 additions & 3 deletions tests/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{fs::File, path::PathBuf};

use common::{
l1_signer, l2_signer, CompiledContract,
};
use common::{l1_signer, l2_signer, CompiledContract};
use ethers::utils::parse_ether;
use zksync_ethers_rs::{
eip712::{DeployRequest, Eip712TransactionRequest},
zk_wallet::ZKWallet,
Expand All @@ -12,6 +11,10 @@ mod common;
#[tokio::test]
async fn test_deploy() {
let zk_wallet = ZKWallet::new(l1_signer().await, l2_signer().await);
zk_wallet
.deposit_base_token(parse_ether("10").unwrap())
.await
.unwrap();
let mut contract_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
contract_path.push("abi/test_contracts/storage_combined.json");
let contract: CompiledContract =
Expand Down

0 comments on commit a1dbfa3

Please sign in to comment.