Skip to content

Commit

Permalink
Gas adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper committed May 23, 2024
1 parent fb0dcf7 commit b9f1792
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Thirdweb/Thirdweb.Transactions/ThirdwebTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public static async Task<BigInteger> EstimateGasPrice(ThirdwebTransaction transa
var fees = await rpc.SendRequestAsync<JToken>("zks_estimateFee", transaction.Input, "latest");
var maxFee = fees["max_fee_per_gas"].ToObject<HexBigInteger>().Value;
var maxPriorityFee = fees["max_priority_fee_per_gas"].ToObject<HexBigInteger>().Value;
return (maxFee, maxPriorityFee == 0 ? maxFee : maxPriorityFee);
maxPriorityFee = maxPriorityFee == 0 ? maxFee : maxPriorityFee;
return withBump ? (maxFee * 10 / 9, maxPriorityFee * 10 / 9) : (maxFee, maxPriorityFee);
}

var gasPrice = await EstimateGasPrice(transaction, withBump);
Expand Down Expand Up @@ -210,10 +211,16 @@ public static async Task<BigInteger> EstimateGasLimit(ThirdwebTransaction transa
else
{
var rpc = ThirdwebRPC.GetRpcInstance(transaction._client, transaction.Input.ChainId.Value);
var hex = IsZkSyncTransaction(transaction)
? (await rpc.SendRequestAsync<JToken>("zks_estimateFee", transaction.Input, "latest"))["gas_limit"].ToString()
: await rpc.SendRequestAsync<string>("eth_estimateGas", transaction.Input, "latest");
return new HexBigInteger(hex).Value;
if (IsZkSyncTransaction(transaction))
{
var hex = (await rpc.SendRequestAsync<JToken>("zks_estimateFee", transaction.Input, "latest"))["gas_limit"].ToString();
return new HexBigInteger(hex).Value * 10 / 7;
}
else
{
var hex = await rpc.SendRequestAsync<string>("eth_estimateGas", transaction.Input, "latest");
return new HexBigInteger(hex).Value;
}
}
}

Expand Down Expand Up @@ -260,7 +267,7 @@ public static async Task<string> Send(ThirdwebTransaction transaction)
From = new HexBigInteger(transaction.Input.From).Value,
To = new HexBigInteger(transaction.Input.To).Value,
GasLimit = transaction.Input.Gas.Value,
GasPerPubdataByteLimit = 50000,
GasPerPubdataByteLimit = transaction.Input.ZkSync?.GasPerPubdataByteLimit ?? 50000,
MaxFeePerGas = transaction.Input.MaxFeePerGas?.Value ?? transaction.Input.GasPrice.Value,
MaxPriorityFeePerGas = transaction.Input.MaxPriorityFeePerGas?.Value ?? transaction.Input.GasPrice.Value,
Paymaster = transaction.Input.ZkSync.Value.Paymaster,
Expand Down

0 comments on commit b9f1792

Please sign in to comment.