[#12989] Use higher base fee value for default tx fee calculation
This commit is contained in:
parent
111064f747
commit
eefc2ede81
|
@ -8,6 +8,7 @@
|
||||||
[status-im.signing.eip1559 :as eip1559]
|
[status-im.signing.eip1559 :as eip1559]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.popover.core :as popover]
|
[status-im.popover.core :as popover]
|
||||||
|
[status-im.ethereum.core :as ethereum]
|
||||||
[clojure.string :as string]))
|
[clojure.string :as string]))
|
||||||
|
|
||||||
(def min-gas-price-wei ^js (money/bignumber 1))
|
(def min-gas-price-wei ^js (money/bignumber 1))
|
||||||
|
@ -318,48 +319,42 @@
|
||||||
;; fee might be very small and using this value might slow transaction
|
;; fee might be very small and using this value might slow transaction
|
||||||
(def minimum-base-fee (money/->wei :gwei (money/bignumber 1)))
|
(def minimum-base-fee (money/->wei :gwei (money/bignumber 1)))
|
||||||
|
|
||||||
(defn recommended-base-fee [current perc20 perc80]
|
(defn recommended-base-fee [current perc20]
|
||||||
(let [fee
|
(let [fee
|
||||||
(cond (and (money/greater-than-or-equals current perc20)
|
(cond (money/greater-than-or-equals current perc20)
|
||||||
(money/greater-than-or-equals perc80 current))
|
|
||||||
current
|
current
|
||||||
|
|
||||||
(money/greater-than perc20 current)
|
(money/greater-than perc20 current)
|
||||||
perc20
|
perc20)]
|
||||||
|
|
||||||
:else
|
|
||||||
perc80)]
|
|
||||||
(if (money/greater-than minimum-base-fee fee)
|
(if (money/greater-than minimum-base-fee fee)
|
||||||
minimum-base-fee
|
minimum-base-fee
|
||||||
fee)))
|
fee)))
|
||||||
|
|
||||||
(defn slow-base-fee [_ perc10] perc10)
|
(defn slow-base-fee [_ perc10] perc10)
|
||||||
|
|
||||||
(defn fast-base-fee [current _]
|
(defn fast-base-fee [current]
|
||||||
(let [fee (money/mul current 2)]
|
(let [fee (money/mul current 2)]
|
||||||
(if (money/greater-than minimum-base-fee fee)
|
(if (money/greater-than minimum-base-fee fee)
|
||||||
(money/mul minimum-base-fee 2)
|
(money/mul minimum-base-fee 2)
|
||||||
fee)))
|
fee)))
|
||||||
|
|
||||||
(defn check-base-fee [{:keys [baseFeePerGas]}]
|
(defn check-base-fee [{:keys [baseFeePerGas testnet?]}]
|
||||||
(let [all-base-fees (mapv money/bignumber baseFeePerGas)
|
(let [all-base-fees (mapv money/bignumber baseFeePerGas)
|
||||||
next-base-fee (peek all-base-fees)
|
next-base-fee (peek all-base-fees)
|
||||||
previous-fees (subvec all-base-fees 0 101)
|
previous-fees (subvec all-base-fees 0 101)
|
||||||
current-base-fee (peek previous-fees)
|
current-base-fee (peek previous-fees)
|
||||||
percentiles (calc-percentiles previous-fees [10 20 80])]
|
percentiles (calc-percentiles previous-fees [10 20 80])]
|
||||||
{:normal-base-fee (money/to-hex
|
{:normal-base-fee (money/to-hex
|
||||||
(recommended-base-fee
|
(if testnet?
|
||||||
next-base-fee
|
(fast-base-fee next-base-fee)
|
||||||
(get percentiles 20)
|
(recommended-base-fee
|
||||||
(get percentiles 80)))
|
next-base-fee
|
||||||
|
(get percentiles 20))))
|
||||||
:slow-base-fee (money/to-hex
|
:slow-base-fee (money/to-hex
|
||||||
(slow-base-fee
|
(slow-base-fee
|
||||||
next-base-fee
|
next-base-fee
|
||||||
(get percentiles 10)))
|
(get percentiles 10)))
|
||||||
:fast-base-fee (money/to-hex
|
:fast-base-fee (money/to-hex (fast-base-fee next-base-fee))
|
||||||
(fast-base-fee
|
|
||||||
next-base-fee
|
|
||||||
(get percentiles 80)))
|
|
||||||
:current-base-fee (money/to-hex current-base-fee)}))
|
:current-base-fee (money/to-hex current-base-fee)}))
|
||||||
|
|
||||||
(defn max-priority-fee-hex [gas-price base-fee]
|
(defn max-priority-fee-hex [gas-price base-fee]
|
||||||
|
@ -369,7 +364,8 @@
|
||||||
|
|
||||||
(fx/defn header-fetched
|
(fx/defn header-fetched
|
||||||
{:events [::header-fetched]}
|
{:events [::header-fetched]}
|
||||||
[_ {:keys [error-callback success-callback fee-history] :as params}]
|
[{{:networks/keys [current-network networks]} :db}
|
||||||
|
{:keys [error-callback success-callback fee-history] :as params}]
|
||||||
{::json-rpc/call
|
{::json-rpc/call
|
||||||
[;; NOTE(rasom): eth_maxPriorityFeePerGas is not supported by some networks
|
[;; NOTE(rasom): eth_maxPriorityFeePerGas is not supported by some networks
|
||||||
;; so it is more reliable to calculate maxPriorityFeePerGas using the value
|
;; so it is more reliable to calculate maxPriorityFeePerGas using the value
|
||||||
|
@ -377,7 +373,10 @@
|
||||||
{:method "eth_gasPrice"
|
{:method "eth_gasPrice"
|
||||||
:on-success #(success-callback
|
:on-success #(success-callback
|
||||||
(let [{:keys [current-base-fee] :as base-fees}
|
(let [{:keys [current-base-fee] :as base-fees}
|
||||||
(check-base-fee fee-history)]
|
(check-base-fee
|
||||||
|
(assoc fee-history
|
||||||
|
:testnet? (ethereum/testnet?
|
||||||
|
(get-in networks [current-network :config :NetworkId]))))]
|
||||||
(merge {:max-priority-fee
|
(merge {:max-priority-fee
|
||||||
(max-priority-fee-hex % current-base-fee)}
|
(max-priority-fee-hex % current-base-fee)}
|
||||||
base-fees)))
|
base-fees)))
|
||||||
|
|
Loading…
Reference in New Issue