Skip to content

Commit

Permalink
fix(wallet): fix maxPriorityFeePerGas hiegher than maxFeePerGas
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Mar 15, 2024
1 parent 9fd3b23 commit 3f1fcbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/main/java/io/zksync/ZkSyncWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ public RemoteCall<TransactionReceipt> sendMessageToL1(byte[] message, @Nullable
}

private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transaction, BigInteger nonce) {
return estimateAndSend(transaction, nonce, BigInteger.ZERO);
}

private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transaction, BigInteger nonce, BigInteger maxPriorityFeePerGas) {
return CompletableFuture
.supplyAsync(() -> {
long chainId = signer.getDomain().join().getChainId().getValue().longValue();
Expand All @@ -493,7 +497,7 @@ private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transa
transaction.getTo(),
transaction.getValueNumber(),
transaction.getData(),
BigInteger.valueOf(100000000L), // TODO: Estimate correct one
maxPriorityFeePerGas,
gasPrice,
transaction.getFrom(),
transaction.getEip712Meta()
Expand All @@ -514,4 +518,4 @@ private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transa
});
}

}
}
17 changes: 12 additions & 5 deletions src/main/java/io/zksync/protocol/account/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ public CompletableFuture<BigInteger> getDeploymentNonce(){
*/
public RemoteCall<TransactionReceipt> 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());
Expand All @@ -135,11 +137,13 @@ public RemoteCall<TransactionReceipt> transfer(TransferTransaction tx) {
public RemoteCall<TransactionReceipt> 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());
Expand Down Expand Up @@ -390,8 +394,11 @@ public RemoteCall<TransactionReceipt> sendMessageToL1(byte[] message, @Nullable
});
}


private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transaction, BigInteger nonce) {
return estimateAndSend(transaction, nonce, BigInteger.ZERO);
}

private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transaction, BigInteger nonce, BigInteger maxPriorityFeePerGas) {
return CompletableFuture
.supplyAsync(() -> {
long chainId = providerL2.ethChainId().sendAsync().join().getChainId().longValue();
Expand All @@ -405,7 +412,7 @@ private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transa
transaction.getTo(),
transaction.getValueNumber(),
transaction.getData(),
BigInteger.valueOf(100000000L), // TODO: Estimate correct one
maxPriorityFeePerGas,
gasPrice,
transaction.getFrom(),
transaction.getEip712Meta()
Expand All @@ -424,4 +431,4 @@ private CompletableFuture<EthSendTransaction> estimateAndSend(Transaction transa
}
});
}
}
}

0 comments on commit 3f1fcbf

Please sign in to comment.