Skip to content

Commit

Permalink
Enable EIP 1559 on ropsten
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos authored and rasom committed Aug 19, 2021
1 parent f031d2b commit c0db96e
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ APN_TOPIC=im.status.ethereum.pr
COMMUNITIES_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1
METRICS_ENABLED=0
EIP1559_ENABLED=0
EIP1559_ENABLED=1
1 change: 1 addition & 0 deletions .env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ DATABASE_MANAGEMENT_ENABLED=1
COMMUNITIES_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1
METRICS_ENABLED=0
EIP1559_ENABLED=1
1 change: 1 addition & 0 deletions .env.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ DATABASE_MANAGEMENT_ENABLED=1
COMMUNITIES_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1
METRICS_ENABLED=0
EIP1559_ENABLED=1
1 change: 1 addition & 0 deletions .env.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ BLANK_PREVIEW=0
COMMUNITIES_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1
METRICS_ENABLED=0
EIP1559_ENABLED=1
1 change: 1 addition & 0 deletions .env.release
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ENABLE_ROOT_ALERT=1
MAX_IMAGES_BATCH=1
ENABLE_REFERRAL_INVITE=0
METRICS_ENABLED=0
EIP1559_ENABLED=1
1 change: 1 addition & 0 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"eth_newFilter" {:subscription? true}
"eth_getCode" {}
"eth_syncing" {}
"eth_feeHistory" {}
"net_version" {}
"web3_clientVersion" {}
"shh_generateSymKeyFromPassword" {}
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/ethereum/transactions/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
(defn enrich-transfer
[chain-tokens
{:keys [address blockNumber timestamp from txStatus txHash gasPrice
gasUsed contract value gasLimit input nonce to type id]}]
gasUsed contract value gasLimit input nonce to type id
maxFeePerGas maxPriorityFeePerGas]}]
(let [erc20? (= type "erc20")
failed? (= txStatus "0x0")]
(merge {:address (eip55/address->checksum address)
Expand All @@ -59,6 +60,8 @@
:timestamp (* (decode/uint timestamp) 1000)
:gas-used (str (decode/uint gasUsed))
:gas-price (str (decode/uint gasPrice))
:fee-cap (str (decode/uint maxFeePerGas))
:tip-cap (str (decode/uint maxPriorityFeePerGas))
:gas-limit (str (decode/uint gasLimit))
:nonce (str (decode/uint nonce))
:hash txHash
Expand Down
41 changes: 28 additions & 13 deletions src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,20 @@
(when gasPrice
{:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))})
(when maxPriorityFeePerGas
{:maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex (.decimalPlaces maxPriorityFeePerGas 0)))})
{:maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex
(js/parseInt maxPriorityFeePerGas)))})
(when maxFeePerGas
{:maxFeePerGas (str "0x" (abi-spec/number-to-hex (.decimalPlaces maxFeePerGas 0)))}))]
{:maxFeePerGas (str "0x" (abi-spec/number-to-hex
(js/parseInt maxFeePerGas)))}))]
(when-not in-progress?
{:db (update db :signing/sign assoc :error nil :in-progress? true)
:signing/send-transaction-fx {:tx-obj tx-obj-to-send
:hashed-password hashed-password
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}})))))

(fx/defn prepare-unconfirmed-transaction
[{:keys [db now]} new-tx-hash {:keys [value gasPrice gas data to from hash]} symbol amount]
[{:keys [db now]} new-tx-hash
{:keys [value gasPrice maxFeePerGas maxPriorityFeePerGas gas data to from hash]} symbol amount]
(let [token (tokens/symbol->token (:wallet/all-tokens db) symbol)
from (eip55/address->checksum from)
;;if there is a hash in the tx object that means we resending transaction
Expand All @@ -132,6 +135,8 @@
(money/to-fixed (money/unit->token amount (:decimals token)))
(money/to-fixed (money/bignumber value)))
:gas-price gas-price
:fee-cap maxFeePerGas
:tip-cap maxPriorityFeePerGas
:gas-limit gas-limit}]
(log/info "[signing] prepare-unconfirmed-transaction" tx)
{:db (-> db
Expand Down Expand Up @@ -246,15 +251,25 @@
(prices/update-prices)
#(when-not gas
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
:signing/update-estimated-gas {:obj (dissoc tx-obj :gasPrice)
:signing/update-estimated-gas {:obj (-> tx-obj
(dissoc :gasPrice)
(update :maxFeePerGas
(fn [fee]
(some-> fee
money/bignumber
(money/mul 2)
money/to-hex))))
:success-event :signing/update-estimated-gas-success
:error-event :signing/update-estimated-gas-error}})
#(when-not (or maxFeePerGas gasPrice)
{:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true)
:signing/update-gas-price {:success-event :signing/update-gas-price-success
:error-event :signing/update-gas-price-error
:network-id (get-in (ethereum/current-network db)
[:config :NetworkId])}})))))
(fn [cofx]
(when-not (or maxFeePerGas gasPrice)
{:db (assoc-in (:db cofx) [:signing/edit-fee :gas-price-loading?] true)
:signing/update-gas-price
{:success-callback #(re-frame/dispatch
[:wallet.send/update-gas-price-success :signing/tx %])
:error-callback #(re-frame/dispatch [:signing/update-gas-price-error %])
:network-id (get-in (ethereum/current-network db)
[:config :NetworkId])}}))))))

(fx/defn check-queue [{:keys [db] :as cofx}]
(let [{:signing/keys [tx queue]} db]
Expand Down Expand Up @@ -436,7 +451,7 @@
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
from-address (:address from)
identity (:current-chat-id db)
db (dissoc db :wallet/prepare-transaction)]
db (dissoc db :wallet/prepare-transaction :signing/edit-fee)]
(if to-norm
(fx/merge
cofx
Expand Down Expand Up @@ -474,7 +489,7 @@
to-norm (:address request-parameters)
from-address (:address from)]
(fx/merge cofx
{:db (dissoc db :wallet/prepare-transaction)}
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(fn [cofx]
(sign
cofx
Expand Down Expand Up @@ -502,7 +517,7 @@
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
from-address (:address from)]
(fx/merge cofx
{:db (dissoc db :wallet/prepare-transaction)}
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(sign
{:tx-obj (merge (if (eip1559/sync-enabled?)
{:from from-address
Expand Down
5 changes: 2 additions & 3 deletions src/status_im/signing/eip1559.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
:on-error #(callback nil)}))

(defn sync-enabled? []
(and config/eip1559-enabled?
@activated-on-current-network?))
config/eip1559-enabled?)

(defn enabled? [network-id enabled-callback disabled-callback]
(let [london-activated? (get @activated? network-id)]
(let [london-activated? true]
(cond
(not config/eip1559-enabled?)
(disabled-callback)
Expand Down
Loading

0 comments on commit c0db96e

Please sign in to comment.