예제 #1
0
        public IEnumerator SuggestFee(BigInteger?maxPriorityFeePerGas = null)
        {
            if (maxPriorityFeePerGas == null)
            {
                maxPriorityFeePerGas = DEFAULT_MAX_PRIORITY_FEE_PER_GAS;
            }

            yield return(_ethGetBlockWithTransactionsHashes.SendRequest(BlockParameter.CreateLatest()));

            if (_ethGetBlockWithTransactionsHashes.Exception == null)
            {
                var lastBlock    = _ethGetBlockWithTransactionsHashes.Result;
                var baseFee      = lastBlock.BaseFeePerGas;
                var maxFeePerGas = baseFee.Value * 2 + maxPriorityFeePerGas;
                this.Result = new Fee1559()
                {
                    BaseFee = baseFee,
                    MaxPriorityFeePerGas = maxPriorityFeePerGas,
                    MaxFeePerGas         = maxFeePerGas
                };
            }
            else
            {
                this.Exception = _ethGetBlockWithTransactionsHashes.Exception;
                yield break;
            }
        }
        public IEnumerator SuggestFee(BigInteger?maxPriorityFeePerGas = null)
        {
            yield return(_ethGetBlockWithTransactionsHashes.SendRequest(BlockParameter.CreateLatest()));

            if (_ethGetBlockWithTransactionsHashes.Exception == null)
            {
                var lastBlock = _ethGetBlockWithTransactionsHashes.Result;
                if (lastBlock.BaseFeePerGas == null)
                {
                    this.Result = MedianPriorityFeeHistorySuggestionStrategy.FallbackFeeSuggestion;
                    yield break;
                }
                else
                {
                    var baseFee = lastBlock.BaseFeePerGas;

                    if (maxPriorityFeePerGas == null)
                    {
                        BigInteger?estimatedPriorityFee;
                        if (baseFee.Value < MedianPriorityFeeHistorySuggestionStrategy.PRIORITY_FEE_ESTIMATION_TRIGGER)
                        {
                            estimatedPriorityFee = MedianPriorityFeeHistorySuggestionStrategy.DefaultPriorityFee;
                        }
                        else
                        {
                            yield return(_ethFeeHistory.SendRequest(new HexBigInteger(MedianPriorityFeeHistorySuggestionStrategy.FeeHistoryNumberOfBlocks), new BlockParameter(lastBlock.Number), new double[] {
                                MedianPriorityFeeHistorySuggestionStrategy.FEE_HISTORY_PERCENTILE
                            }));

                            if (_ethFeeHistory.Exception != null)
                            {
                                this.Exception = _ethFeeHistory.Exception;
                                yield break;
                            }
                            else
                            {
                                estimatedPriorityFee = _medianPriorityFeeHistorySuggestionStrategy.EstimatePriorityFee(_ethFeeHistory.Result);
                            }
                        }

                        if (estimatedPriorityFee == null)
                        {
                            this.Result = MedianPriorityFeeHistorySuggestionStrategy.FallbackFeeSuggestion;
                            yield break;
                        }

                        maxPriorityFeePerGas = BigInteger.Max(estimatedPriorityFee.Value, MedianPriorityFeeHistorySuggestionStrategy.DefaultPriorityFee);
                    }

                    this.Result = _medianPriorityFeeHistorySuggestionStrategy.SuggestMaxFeeUsingMultiplier(maxPriorityFeePerGas, baseFee);
                    yield break;
                }
            }
            else
            {
                this.Exception = _ethGetBlockWithTransactionsHashes.Exception;
                yield break;
            }
        }