diff --git a/csharp/src/Common/Common.csproj b/csharp/src/Common/Common.csproj index f07e35f..e39fffa 100644 --- a/csharp/src/Common/Common.csproj +++ b/csharp/src/Common/Common.csproj @@ -6,6 +6,7 @@ + diff --git a/csharp/src/Common/Extensions/Web3ClientExtensions.cs b/csharp/src/Common/Extensions/Web3ClientExtensions.cs new file mode 100644 index 0000000..6d7a2f6 --- /dev/null +++ b/csharp/src/Common/Extensions/Web3ClientExtensions.cs @@ -0,0 +1,17 @@ +using Nethereum.Hex.HexTypes; +using Nethereum.Web3; +using System.Numerics; + +namespace Train.Solver.Common.Extensions; + +public static class Web3ClientExtensions +{ + public static async Task GetMaxPriorityFeePerGasAsync(this IWeb3 web3) + { + var request = new Nethereum.JsonRpc.Client.RpcRequest(Guid.NewGuid().ToString(), "eth_maxPriorityFeePerGas"); + + var response = await web3.Client.SendRequestAsync(request); + + return new HexBigInteger(response); + } +} \ No newline at end of file diff --git a/csharp/src/Workflow.EVM/Helpers/EthereumEIP1559FeeEstimator.cs b/csharp/src/Workflow.EVM/Helpers/EthereumEIP1559FeeEstimator.cs index 23c4c4d..fefa51a 100644 --- a/csharp/src/Workflow.EVM/Helpers/EthereumEIP1559FeeEstimator.cs +++ b/csharp/src/Workflow.EVM/Helpers/EthereumEIP1559FeeEstimator.cs @@ -16,6 +16,8 @@ public class EthereumEIP1559FeeEstimator(ISmartNodeInvoker smartNodeInvoker) : F public virtual int HighPriorityBlockCount => 5; + private const string MinMaxPriorityFeePerGas = "1"; + public override BigInteger CalculateFee(Block block, Transaction transaction, EVMTransactionReceipt receipt) { return receipt.GasUsed * (block.BaseFeePerGas + transaction.MaxPriorityFeePerGas.Value); @@ -66,15 +68,14 @@ async Task GetFeeAmountAsync( suggestedFees.BaseFee.Value.CompoundInterestRate(MaximumBaseFeeIncreasePerBlock, blockCount); // Node returns 0 but transfer service throws exception in case of 0 - suggestedFees.MaxPriorityFeePerGas += 1; - suggestedFees.MaxPriorityFeePerGas = - suggestedFees.MaxPriorityFeePerGas.Value.PercentageIncrease(feePercentageIncrease); + var maxPriorityFeePerGas = BigInteger.Parse(MinMaxPriorityFeePerGas); + maxPriorityFeePerGas += (await web3.GetMaxPriorityFeePerGasAsync()).PercentageIncrease(feePercentageIncrease); return new Fee( feeCurrency.Symbol, feeCurrency.Decimals, new EIP1559Data( - suggestedFees.MaxPriorityFeePerGas.Value, + maxPriorityFeePerGas, increasedBaseFee, gasLimit)); } diff --git a/csharp/src/Workflow.Solana/Workflow.Solana.csproj b/csharp/src/Workflow.Solana/Workflow.Solana.csproj index 0f1ac09..4a66cc1 100644 --- a/csharp/src/Workflow.Solana/Workflow.Solana.csproj +++ b/csharp/src/Workflow.Solana/Workflow.Solana.csproj @@ -6,7 +6,7 @@ - +