From daaa7831d61519ebe78a93d4fb3dd8d234fcfc47 Mon Sep 17 00:00:00 2001 From: petarTxFusion Date: Fri, 15 Mar 2024 17:29:32 +0100 Subject: [PATCH] fix(wallet): fix `maxPriorityFeePerGas` hiegher than `maxFeePerGas` --- src/main/java/io/zksync/ZkSyncWallet.java | 8 ++++++-- .../java/io/zksync/protocol/account/Wallet.java | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/zksync/ZkSyncWallet.java b/src/main/java/io/zksync/ZkSyncWallet.java index d7d3ed1..0506e27 100644 --- a/src/main/java/io/zksync/ZkSyncWallet.java +++ b/src/main/java/io/zksync/ZkSyncWallet.java @@ -480,6 +480,10 @@ public RemoteCall sendMessageToL1(byte[] message, @Nullable } private CompletableFuture estimateAndSend(Transaction transaction, BigInteger nonce) { + return estimateAndSend(transaction, nonce, BigInteger.ZERO); + } + + private CompletableFuture estimateAndSend(Transaction transaction, BigInteger nonce, BigInteger maxPriorityFeePerGas) { return CompletableFuture .supplyAsync(() -> { long chainId = signer.getDomain().join().getChainId().getValue().longValue(); @@ -493,7 +497,7 @@ private CompletableFuture estimateAndSend(Transaction transa transaction.getTo(), transaction.getValueNumber(), transaction.getData(), - BigInteger.valueOf(100000000L), // TODO: Estimate correct one + maxPriorityFeePerGas, gasPrice, transaction.getFrom(), transaction.getEip712Meta() @@ -514,4 +518,4 @@ private CompletableFuture estimateAndSend(Transaction transa }); } -} +} \ No newline at end of file diff --git a/src/main/java/io/zksync/protocol/account/Wallet.java b/src/main/java/io/zksync/protocol/account/Wallet.java index 689f9f7..dbce38f 100644 --- a/src/main/java/io/zksync/protocol/account/Wallet.java +++ b/src/main/java/io/zksync/protocol/account/Wallet.java @@ -112,11 +112,13 @@ public CompletableFuture getDeploymentNonce(){ */ public RemoteCall transfer(TransferTransaction tx) { return new RemoteCall<>(() -> { + tx.options = tx.options == null ? new TransactionOptions() : tx.options; + BigInteger maxPriorityFeePerGas = tx.options.getMaxPriorityFeePerGas() == null ? BigInteger.ZERO : tx.options.getMaxPriorityFeePerGas(); BigInteger nonceToUse = getNonce().send(); Transaction estimate = providerL2.getTransferTransaction(tx, transactionManager, gasProvider); - EthSendTransaction sent = estimateAndSend(estimate, nonceToUse).join(); + EthSendTransaction sent = estimateAndSend(estimate, nonceToUse, maxPriorityFeePerGas).join(); try { return this.transactionReceiptProcessor.waitForTransactionReceipt(sent.getTransactionHash()); @@ -135,11 +137,13 @@ public RemoteCall transfer(TransferTransaction tx) { public RemoteCall withdraw(WithdrawTransaction tx) { tx.tokenAddress = tx.tokenAddress == null ? ZkSyncAddresses.ETH_ADDRESS : tx.tokenAddress; tx.from = tx.from == null ? getAddress() : tx.from; + tx.options = tx.options == null ? new TransactionOptions() : tx.options; + BigInteger maxPriorityFeePerGas = tx.options.getMaxPriorityFeePerGas() == null ? BigInteger.ZERO : tx.options.getMaxPriorityFeePerGas(); return new RemoteCall<>(() -> { Transaction transaction = providerL2.getWithdrawTransaction(tx, gasProvider, transactionManager); - EthSendTransaction sent = estimateAndSend(transaction, getNonce().send()).join(); + EthSendTransaction sent = estimateAndSend(transaction, getNonce().send(), maxPriorityFeePerGas).join(); try { return this.transactionReceiptProcessor.waitForTransactionReceipt(sent.getTransactionHash()); @@ -390,8 +394,11 @@ public RemoteCall sendMessageToL1(byte[] message, @Nullable }); } - private CompletableFuture estimateAndSend(Transaction transaction, BigInteger nonce) { + return estimateAndSend(transaction, nonce, BigInteger.ZERO); + } + + private CompletableFuture estimateAndSend(Transaction transaction, BigInteger nonce, BigInteger maxPriorityFeePerGas) { return CompletableFuture .supplyAsync(() -> { long chainId = providerL2.ethChainId().sendAsync().join().getChainId().longValue(); @@ -405,7 +412,7 @@ private CompletableFuture estimateAndSend(Transaction transa transaction.getTo(), transaction.getValueNumber(), transaction.getData(), - BigInteger.valueOf(100000000L), // TODO: Estimate correct one + maxPriorityFeePerGas, gasPrice, transaction.getFrom(), transaction.getEip712Meta() @@ -424,4 +431,4 @@ private CompletableFuture estimateAndSend(Transaction transa } }); } -} +} \ No newline at end of file