Skip to content

Commit eefc2ed

Browse files
committed
[#12989] Use higher base fee value for default tx fee calculation
1 parent 111064f commit eefc2ed

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/status_im/signing/gas.cljs

+18-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[status-im.signing.eip1559 :as eip1559]
99
[taoensso.timbre :as log]
1010
[status-im.popover.core :as popover]
11+
[status-im.ethereum.core :as ethereum]
1112
[clojure.string :as string]))
1213

1314
(def min-gas-price-wei ^js (money/bignumber 1))
@@ -318,48 +319,42 @@
318319
;; fee might be very small and using this value might slow transaction
319320
(def minimum-base-fee (money/->wei :gwei (money/bignumber 1)))
320321

321-
(defn recommended-base-fee [current perc20 perc80]
322+
(defn recommended-base-fee [current perc20]
322323
(let [fee
323-
(cond (and (money/greater-than-or-equals current perc20)
324-
(money/greater-than-or-equals perc80 current))
324+
(cond (money/greater-than-or-equals current perc20)
325325
current
326326

327327
(money/greater-than perc20 current)
328-
perc20
329-
330-
:else
331-
perc80)]
328+
perc20)]
332329
(if (money/greater-than minimum-base-fee fee)
333330
minimum-base-fee
334331
fee)))
335332

336333
(defn slow-base-fee [_ perc10] perc10)
337334

338-
(defn fast-base-fee [current _]
335+
(defn fast-base-fee [current]
339336
(let [fee (money/mul current 2)]
340337
(if (money/greater-than minimum-base-fee fee)
341338
(money/mul minimum-base-fee 2)
342339
fee)))
343340

344-
(defn check-base-fee [{:keys [baseFeePerGas]}]
341+
(defn check-base-fee [{:keys [baseFeePerGas testnet?]}]
345342
(let [all-base-fees (mapv money/bignumber baseFeePerGas)
346343
next-base-fee (peek all-base-fees)
347344
previous-fees (subvec all-base-fees 0 101)
348345
current-base-fee (peek previous-fees)
349346
percentiles (calc-percentiles previous-fees [10 20 80])]
350347
{:normal-base-fee (money/to-hex
351-
(recommended-base-fee
352-
next-base-fee
353-
(get percentiles 20)
354-
(get percentiles 80)))
348+
(if testnet?
349+
(fast-base-fee next-base-fee)
350+
(recommended-base-fee
351+
next-base-fee
352+
(get percentiles 20))))
355353
:slow-base-fee (money/to-hex
356354
(slow-base-fee
357355
next-base-fee
358356
(get percentiles 10)))
359-
:fast-base-fee (money/to-hex
360-
(fast-base-fee
361-
next-base-fee
362-
(get percentiles 80)))
357+
:fast-base-fee (money/to-hex (fast-base-fee next-base-fee))
363358
:current-base-fee (money/to-hex current-base-fee)}))
364359

365360
(defn max-priority-fee-hex [gas-price base-fee]
@@ -369,15 +364,19 @@
369364

370365
(fx/defn header-fetched
371366
{:events [::header-fetched]}
372-
[_ {:keys [error-callback success-callback fee-history] :as params}]
367+
[{{:networks/keys [current-network networks]} :db}
368+
{:keys [error-callback success-callback fee-history] :as params}]
373369
{::json-rpc/call
374370
[;; NOTE(rasom): eth_maxPriorityFeePerGas is not supported by some networks
375371
;; so it is more reliable to calculate maxPriorityFeePerGas using the value
376372
;; returned by eth_gasPrice and current base fee.
377373
{:method "eth_gasPrice"
378374
:on-success #(success-callback
379375
(let [{:keys [current-base-fee] :as base-fees}
380-
(check-base-fee fee-history)]
376+
(check-base-fee
377+
(assoc fee-history
378+
:testnet? (ethereum/testnet?
379+
(get-in networks [current-network :config :NetworkId]))))]
381380
(merge {:max-priority-fee
382381
(max-priority-fee-hex % current-base-fee)}
383382
base-fees)))

0 commit comments

Comments
 (0)