Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Replace gasPrice with maxFeePerGas; remove gasnow; update web3 (#2863)
Browse files Browse the repository at this point in the history
* Replace gasPrice with maxFeePerGas; remove gasnow; update web3

* Update web3 patches

* Quotes 🤦

* Use etherscan API

* 1e9 -> 1e8

* Pass API keys from GH secrects

* Fallback to eth.getGasPrice
  • Loading branch information
katspaugh authored Oct 20, 2021
1 parent 053396f commit e582c19
Show file tree
Hide file tree
Showing 13 changed files with 1,254 additions and 2,880 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy-mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ env:
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN_MAINNET }}
REACT_APP_GOOGLE_ANALYTICS: ${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID_MAINNET }}
REACT_APP_GNOSIS_APPS_URL: ${{ secrets.REACT_APP_GNOSIS_APPS_URL_PROD }}
REACT_APP_ETHGASSTATION_API_KEY: ${{ secrets.REACT_APP_ETHGASSTATION_API_KEY_MAINNET }}
REACT_APP_ETHERSCAN_API_KEY: ${{ secrets.REACT_APP_ETHERSCAN_API_KEY }}
REACT_APP_ETHGASSTATION_API_KEY: ${{ secrets.REACT_APP_ETHGASSTATION_API_KEY }}

jobs:
debug:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy-rinkeby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ env:
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN_RINKEBY }}
REACT_APP_GOOGLE_ANALYTICS: ${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID_RINKEBY }}
REACT_APP_GNOSIS_APPS_URL: ${{ secrets.REACT_APP_GNOSIS_APPS_URL_PROD }}
REACT_APP_ETHGASSTATION_API_KEY: ${{ secrets.REACT_APP_ETHGASSTATION_API_KEY_RINKEBY }}
REACT_APP_ETHERSCAN_API_KEY: ${{ secrets.REACT_APP_ETHERSCAN_API_KEY }}
REACT_APP_ETHGASSTATION_API_KEY: ${{ secrets.REACT_APP_ETHGASSTATION_API_KEY }}

jobs:
debug:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"@gnosis.pm/safe-core-sdk": "^0.3.1",
"@gnosis.pm/safe-deployments": "^1.2.0",
"@gnosis.pm/safe-react-components": "^0.8.0",
"@gnosis.pm/safe-react-gateway-sdk": "^2.3.0",
"@gnosis.pm/safe-react-gateway-sdk": "2.3.0",
"@ledgerhq/hw-transport-node-hid-singleton": "6.3.0",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.0",
Expand Down Expand Up @@ -236,10 +236,10 @@
"reselect": "^4.0.0",
"semver": "^7.3.2",
"styled-components": "^5.3.0",
"web3": "1.3.6",
"web3-core": "^1.3.6",
"web3-eth-contract": "^1.3.6",
"web3-utils": "^1.3.6"
"web3": "1.6.0",
"web3-core": "^1.6.0",
"web3-eth-contract": "^1.6.0",
"web3-utils": "^1.6.0"
},
"devDependencies": {
"@gnosis.pm/safe-core-sdk-types": "^0.1.1",
Expand Down
6 changes: 3 additions & 3 deletions patches/web3-eth+1.3.6.patch → patches/web3-eth+1.6.0.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node_modules/web3-eth/src/getNetworkType.js b/node_modules/web3-eth/src/getNetworkType.js
index 3be3a20..88edbd9 100644
index 5f9b9b3..8c83b18 100644
--- a/node_modules/web3-eth/src/getNetworkType.js
+++ b/node_modules/web3-eth/src/getNetworkType.js
@@ -63,6 +63,14 @@ var getNetworkType = function (callback) {
@@ -61,6 +61,14 @@ var getNetworkType = function (callback) {
id === 42) {
returnValue = 'kovan';
}
Expand All @@ -15,5 +15,5 @@ index 3be3a20..88edbd9 100644
+ returnValue = 'volta';
+ }

if (_.isFunction(callback)) {
if (typeof callback === 'function') {
callback(null, returnValue);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/web3-eth-ens/src/config.js b/node_modules/web3-eth-ens/src/config.js
index b12e5f5..e0abf2d 100644
index b12e5f5..f5baccd 100644
--- a/node_modules/web3-eth-ens/src/config.js
+++ b/node_modules/web3-eth-ens/src/config.js
@@ -30,7 +30,9 @@ var config = {
Expand All @@ -9,7 +9,7 @@ index b12e5f5..e0abf2d 100644
- goerli: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
+ goerli: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
+ energyWebChain: "0x0A6d64413c07E10E890220BBE1c49170080C6Ca0",
+ volta: "0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac",
+ volta: "0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac"
},
// These ids obtained at ensdomains docs:
// https://docs.ens.domains/contract-developer-guide/writing-a-resolver
5 changes: 0 additions & 5 deletions src/config/networks/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const baseConfig: EnvironmentSettings = {
txServiceUrl: 'http://localhost:8000/api/v1',
safeUrl: 'http://localhost:3000/app',
gasPriceOracles: [
{
url: 'https://www.gasnow.org/api/v3/gas/price?utm_source=:gnosis_safe',
gasParameter: 'fast',
gweiFactor: '1',
},
{
url: 'https://ethgasstation.info/json/ethgasAPI.json',
gasParameter: 'fast',
Expand Down
9 changes: 5 additions & 4 deletions src/config/networks/mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import EtherLogo from 'src/config/assets/token_eth.svg'
import { EnvironmentSettings, ETHEREUM_LAYER, ETHEREUM_NETWORK, NetworkConfig } from 'src/config/networks/network.d'
import { WALLETS } from 'src/config/networks/network.d'
import { ETHGASSTATION_API_KEY, ETHERSCAN_API_KEY } from 'src/utils/constants'

const baseConfig: EnvironmentSettings = {
clientGatewayUrl: 'https://safe-client.staging.gnosisdev.com/v1',
txServiceUrl: 'https://safe-transaction.mainnet.staging.gnosisdev.com/api/v1',
safeUrl: 'https://gnosis-safe.io/app',
gasPriceOracles: [
{
url: 'https://www.gasnow.org/api/v3/gas/price?utm_source=:gnosis_safe',
gasParameter: 'fast',
gweiFactor: '1',
url: `https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=${ETHERSCAN_API_KEY}`,
gasParameter: 'FastGasPrice',
gweiFactor: '1e9',
},
{
url: 'https://ethgasstation.info/json/ethgasAPI.json',
url: `https://ethgasstation.info/json/ethgasAPI.json?api-key=${ETHGASSTATION_API_KEY}`,
gasParameter: 'fast',
gweiFactor: '1e8',
},
Expand Down
10 changes: 5 additions & 5 deletions src/config/networks/rinkeby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import {
NetworkConfig,
WALLETS,
} from 'src/config/networks/network.d'
import { ETHGASSTATION_API_KEY } from 'src/utils/constants'
import { ETHGASSTATION_API_KEY, ETHERSCAN_API_KEY } from 'src/utils/constants'

const baseConfig: EnvironmentSettings = {
clientGatewayUrl: 'https://safe-client.staging.gnosisdev.com/v1',
txServiceUrl: 'https://safe-transaction.rinkeby.staging.gnosisdev.com/api/v1',
safeUrl: 'https://rinkeby.gnosis-safe.io/app',
gasPriceOracles: [
{
url: 'https://www.gasnow.org/api/v3/gas/price?utm_source=:gnosis_safe',
gasParameter: 'fast',
gweiFactor: '1',
url: `https://api-rinkeby.etherscan.io/api?module=gastracker&action=gasoracle&apikey=${ETHERSCAN_API_KEY}`,
gasParameter: 'FastGasPrice',
gweiFactor: '1e9',
},
{
url: 'https://ethgasstation.info/json/ethgasAPI.json',
url: `https://ethgasstation.info/json/ethgasAPI.json?api-key=${ETHGASSTATION_API_KEY}`,
gasParameter: 'fast',
gweiFactor: '1e8',
},
Expand Down
2 changes: 1 addition & 1 deletion src/logic/safe/store/actions/createTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const createTransaction =
from,
value: 0,
gas: ethParameters?.ethGasLimit,
gasPrice: ethParameters?.ethGasPriceInGWei,
maxFeePerGas: ethParameters?.ethGasPriceInGWei,
nonce: ethParameters?.ethNonce,
}

Expand Down
2 changes: 1 addition & 1 deletion src/logic/safe/store/actions/processTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const processTransaction =
from,
value: 0,
gas: ethParameters?.ethGasLimit,
gasPrice: ethParameters?.ethGasPriceInGWei,
maxFeePerGas: ethParameters?.ethGasPriceInGWei,
nonce: ethParameters?.ethNonce,
}

Expand Down
17 changes: 12 additions & 5 deletions src/logic/wallets/ethTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import axios from 'axios'
import { BigNumber } from 'bignumber.js'
import { EthAdapterTransaction } from '@gnosis.pm/safe-core-sdk/dist/src/ethereumLibs/EthAdapter'

import { getSDKWeb3Adapter, getWeb3 } from 'src/logic/wallets/getWeb3'
import { getSDKWeb3Adapter, getWeb3, web3ReadOnly } from 'src/logic/wallets/getWeb3'
import { getGasPrice, getGasPriceOracles } from 'src/config'
import { GasPriceOracle } from 'src/config/networks/network'
import { CodedException, Errors } from '../exceptions/CodedException'

export const EMPTY_DATA = '0x'
/**
* The magic number is from web3.js
* @see https://github.com/ChainSafe/web3.js/blob/c70722b919ac81e45760b9648c4b92fd8d0eeee1/packages/web3-core-method/src/index.js#L869
*/
const FIXED_GAS_FEE = '2.5'

const fetchGasPrice = async (gasPriceOracle: GasPriceOracle): Promise<string> => {
const { url, gasParameter, gweiFactor } = gasPriceOracle
const { data: response } = await axios.get(url)
const data = response.data || response // Sometimes the data comes with a data parameter
const data = response.data || response.result || response // Sometimes the data comes with a data parameter
return new BigNumber(data[gasParameter]).multipliedBy(gweiFactor).toString()
}

Expand All @@ -34,9 +39,11 @@ export const calculateGasPrice = async (): Promise<string> => {
}
}
}
// If no oracle worked we return an error
const err = new CodedException(Errors._611, 'gasPrice or gasPriceOracle not set in config')
return Promise.reject(err)

// A fallback based on the latest mined blocks when none of the oracles are working
const fixedFee = web3ReadOnly.utils.toWei(FIXED_GAS_FEE, 'gwei')
const lastFee = await web3ReadOnly.eth.getGasPrice()
return BigNumber.sum(fixedFee, lastFee).toString()
}

export const calculateGasOf = async (txConfig: EthAdapterTransaction): Promise<number> => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const LATEST_SAFE_VERSION = process.env.REACT_APP_LATEST_SAFE_VERSION ||
export const APP_VERSION = process.env.REACT_APP_APP_VERSION || 'not-defined'
export const COLLECTIBLES_SOURCE = process.env.REACT_APP_COLLECTIBLES_SOURCE || 'Gnosis'
export const TIMEOUT = process.env.NODE_ENV === 'test' ? 1500 : 5000
export const ETHERSCAN_API_KEY = process.env.REACT_APP_ETHERSCAN_API_KEY
export const ETHERSCAN_API_KEY = process.env.REACT_APP_ETHERSCAN_API_KEY || ''
export const ETHGASSTATION_API_KEY = process.env.REACT_APP_ETHGASSTATION_API_KEY
export const CONFIG_SERVICE_URL =
process.env.CONFIG_SERVICE_URL || IS_PRODUCTION
Expand Down
Loading

0 comments on commit e582c19

Please sign in to comment.