Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config/chain-workarounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ETHEREUM_NETWORK } from './networks/network.d'

// Networks where we use maxFeePerGas
export const EIP1559Chains = [ETHEREUM_NETWORK.MAINNET, ETHEREUM_NETWORK.RINKEBY, ETHEREUM_NETWORK.XDAI]
6 changes: 3 additions & 3 deletions src/config/networks/xdai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const baseConfig: EnvironmentSettings = {
clientGatewayUrl: 'https://safe-client.gnosis.io/v1',
txServiceUrl: 'https://safe-transaction.xdai.gnosis.io/api/v1',
gasPriceOracles: [],
rpcServiceUrl: 'https://dai.poa.network/',
safeAppsRpcServiceUrl: 'https://dai.poa.network/',
rpcServiceUrl: 'https://rpc.xdaichain.com/oe-only/',
safeAppsRpcServiceUrl: 'https://rpc.xdaichain.com/oe-only/',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the RPC URLs to the ones used by the config-service.

networkExplorerName: 'Blockscout',
networkExplorerUrl: 'https://blockscout.com/poa/xdai',
networkExplorerUrl: 'https://blockscout.com/xdai/mainnet',
networkExplorerApiUrl: 'https://blockscout.com/poa/xdai/api',
}

Expand Down
3 changes: 3 additions & 0 deletions src/logic/hooks/useEstimateSafeCreationGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type SafeCreationEstimationResult = {
gasEstimation: number // Amount of gas needed for execute or approve the transaction
gasCostFormatted: string // Cost of gas in format '< | > 100'
gasLimit: number // Minimum gas requited to execute the Tx
gasPrice: string
}

const estimateGas = async (
Expand All @@ -36,6 +37,7 @@ const estimateGas = async (
const gasCostFormatted = formatAmount(gasCost)

return {
gasPrice,
gasEstimation,
gasCostFormatted,
gasLimit: gasEstimation,
Expand All @@ -51,6 +53,7 @@ export const useEstimateSafeCreationGas = ({
gasEstimation: 0,
gasCostFormatted: '< 0.001',
gasLimit: 0,
gasPrice: '0',
})
const userAccount = useSelector(userAccountSelector)
// Serialize the addresses array so that it doesn't trigger the effect due to the dependencies
Expand Down
12 changes: 2 additions & 10 deletions src/logic/hooks/useEstimateTransactionGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { List } from 'immutable'
import { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'

import { getNetworkId, getNetworkInfo } from 'src/config'
import { getNetworkInfo } from 'src/config'
import {
checkTransactionExecution,
estimateSafeTxGas,
Expand All @@ -20,20 +20,13 @@ import { Confirmation } from 'src/logic/safe/store/models/types/confirmation'
import { checkIfOffChainSignatureIsPossible } from 'src/logic/safe/safeTxSigner'
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { sameString } from 'src/utils/strings'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'

export enum EstimationStatus {
LOADING = 'LOADING',
FAILURE = 'FAILURE',
SUCCESS = 'SUCCESS',
}

// How much to add to gasLimit per network
// Defaults to x1 (i.e. no extra gas)
const EXTRA_GAS_FACTOR = {
[ETHEREUM_NETWORK.ARBITRUM]: 1.2, // +20%
}

export const checkIfTxIsExecution = (
threshold: number,
preApprovingOwner?: string,
Expand Down Expand Up @@ -198,8 +191,7 @@ export const useEstimateTransactionGas = ({

const gasPrice = manualGasPrice ? web3.utils.toWei(manualGasPrice, 'gwei') : await calculateGasPrice()
const gasPriceFormatted = web3.utils.fromWei(gasPrice, 'gwei')
const extraGasMult = EXTRA_GAS_FACTOR[getNetworkId()] || 1
const gasLimit = manualGasLimit || Math.round(ethGasLimitEstimation * extraGasMult).toString()
const gasLimit = manualGasLimit || ethGasLimitEstimation.toString()
const estimatedGasCosts = parseInt(gasLimit, 10) * parseInt(gasPrice, 10)
const gasCost = fromTokenUnit(estimatedGasCosts, nativeCoin.decimals)
const gasCostFormatted = formatAmount(gasCost)
Expand Down
8 changes: 3 additions & 5 deletions src/logic/safe/store/actions/createTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
saveTxToHistory,
tryOffChainSigning,
} from 'src/logic/safe/transactions'
import { estimateSafeTxGas } from 'src/logic/safe/transactions/gas'
import { estimateSafeTxGas, getGasParam } from 'src/logic/safe/transactions/gas'
import * as aboutToExecuteTx from 'src/logic/safe/utils/aboutToExecuteTx'
import { currentSafeCurrentVersion } from 'src/logic/safe/store/selectors'
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
Expand All @@ -32,8 +32,7 @@ import { isTxPendingError } from 'src/logic/wallets/getWeb3'
import { Errors, logError } from 'src/logic/exceptions/CodedException'
import { currentChainId } from 'src/logic/config/store/selectors'
import { generateSafeRoute, history, SAFE_ROUTES } from 'src/routes/routes'
import { getCurrentShortChainName, getNetworkId } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'
import { getCurrentShortChainName } from 'src/config'
import { getContractErrorMessage } from 'src/logic/contracts/safeContractErrors'

export interface CreateTransactionArgs {
Expand Down Expand Up @@ -151,12 +150,11 @@ export const createTransaction =
}

const tx = isExecution ? getExecutionTransaction(txArgs) : getApprovalTransaction(safeInstance, safeTxHash)
const gasParam = getNetworkId() === ETHEREUM_NETWORK.MAINNET ? 'maxFeePerGas' : 'gasPrice'
const sendParams: PayableTx = {
from,
value: 0,
gas: ethParameters?.ethGasLimit,
[gasParam]: ethParameters?.ethGasPriceInGWei,
[getGasParam()]: ethParameters?.ethGasPriceInGWei,
nonce: ethParameters?.ethNonce,
}

Expand Down
6 changes: 2 additions & 4 deletions src/logic/safe/store/actions/processTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ import { Confirmation } from 'src/logic/safe/store/models/types/confirmation'
import { Operation, TransactionStatus } from '@gnosis.pm/safe-react-gateway-sdk'
import { isTxPendingError } from 'src/logic/wallets/getWeb3'
import { Errors, logError } from 'src/logic/exceptions/CodedException'
import { getNetworkId } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'
import { getContractErrorMessage } from 'src/logic/contracts/safeContractErrors'
import { onboardUser } from 'src/components/ConnectButton'
import { getGasParam } from '../../transactions/gas'

interface ProcessTransactionArgs {
approveAndExecute: boolean
Expand Down Expand Up @@ -146,12 +145,11 @@ export const processTransaction =

transaction = isExecution ? getExecutionTransaction(txArgs) : getApprovalTransaction(safeInstance, tx.safeTxHash)

const gasParam = getNetworkId() === ETHEREUM_NETWORK.MAINNET ? 'maxFeePerGas' : 'gasPrice'
const sendParams: PayableTx = {
from,
value: 0,
gas: ethParameters?.ethGasLimit,
[gasParam]: ethParameters?.ethGasPriceInGWei,
[getGasParam()]: ethParameters?.ethGasPriceInGWei,
nonce: ethParameters?.ethNonce,
}

Expand Down
28 changes: 28 additions & 0 deletions src/logic/safe/transactions/__tests__/gas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getNetworkId, setNetworkId } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'
import { getGasParam } from '../gas'

describe('Get gas param', () => {
let initialNetworkId = ETHEREUM_NETWORK.RINKEBY
beforeAll(() => {
initialNetworkId = getNetworkId()
})
afterAll(() => {
setNetworkId(initialNetworkId)
})

it('should return maxFeePerGas for Mainnet', () => {
setNetworkId(ETHEREUM_NETWORK.MAINNET)
expect(getGasParam()).toBe('maxFeePerGas')
})

it('should return gasPrice for Arbitrum', () => {
setNetworkId(ETHEREUM_NETWORK.ARBITRUM)
expect(getGasParam()).toBe('gasPrice')
})

it('should return maxFeePerGas for Rinkeby', () => {
setNetworkId(ETHEREUM_NETWORK.RINKEBY)
expect(getGasParam()).toBe('maxFeePerGas')
})
})
6 changes: 6 additions & 0 deletions src/logic/safe/transactions/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { generateSignaturesFromTxConfirmations } from 'src/logic/safe/safeTxSign
import { fetchSafeTxGasEstimation } from 'src/logic/safe/api/fetchSafeTxGasEstimation'
import { Confirmation } from 'src/logic/safe/store/models/types/confirmation'
import { checksumAddress } from 'src/utils/checksumAddress'
import { EIP1559Chains } from 'src/config/chain-workarounds'
import { getNetworkId } from 'src/config'

type SafeTxGasEstimationProps = {
safeAddress: string
Expand Down Expand Up @@ -224,3 +226,7 @@ export const estimateGasForTransactionApproval = async ({
to: safeAddress,
})
}

export const getGasParam = (): string => {
return EIP1559Chains.includes(getNetworkId()) ? 'maxFeePerGas' : 'gasPrice'
}
4 changes: 2 additions & 2 deletions src/logic/wallets/ethTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { BigNumber } from 'bignumber.js'
import { EthAdapterTransaction } from '@gnosis.pm/safe-core-sdk/dist/src/ethereumLibs/EthAdapter'

import { getSDKWeb3Adapter, getWeb3, getWeb3ReadOnly } from 'src/logic/wallets/getWeb3'
import { getSDKWeb3ReadOnly, getWeb3, getWeb3ReadOnly } from 'src/logic/wallets/getWeb3'
import { getGasPrice, getGasPriceOracles } from 'src/config'
import { GasPriceOracle } from 'src/config/networks/network'
import { CodedException, Errors } from '../exceptions/CodedException'
Expand Down Expand Up @@ -49,7 +49,7 @@ export const calculateGasPrice = async (): Promise<string> => {

export const calculateGasOf = async (txConfig: EthAdapterTransaction): Promise<number> => {
try {
const ethAdapter = getSDKWeb3Adapter(txConfig.from)
const ethAdapter = getSDKWeb3ReadOnly()

return await ethAdapter.estimateGas(txConfig)
} catch (err) {
Expand Down
9 changes: 8 additions & 1 deletion src/logic/wallets/getWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { provider as Provider } from 'web3-core'
import { ContentHash } from 'web3-eth-ens'
import { Web3Adapter } from '@gnosis.pm/safe-core-sdk'

import { sameAddress } from './ethAddresses'
import { sameAddress, ZERO_ADDRESS } from './ethAddresses'
import { EMPTY_DATA } from './ethTransactions'
import { ProviderProps } from './store/model/provider'
import { getRpcServiceUrl, getNetworkId } from 'src/config'
Expand Down Expand Up @@ -119,3 +119,10 @@ export const getSDKWeb3Adapter = (signerAddress: string): Web3Adapter => {
signerAddress,
})
}

export const getSDKWeb3ReadOnly = (): Web3Adapter => {
return new Web3Adapter({
web3: getWeb3ReadOnly(),
signerAddress: ZERO_ADDRESS,
})
}
4 changes: 4 additions & 0 deletions src/routes/CreateSafePage/components/SafeCreationProcess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
FIELD_CREATE_SUGGESTED_SAFE_NAME,
FIELD_CREATE_CUSTOM_SAFE_NAME,
FIELD_NEW_SAFE_PROXY_SALT,
FIELD_NEW_SAFE_GAS_PRICE,
} from '../fields/createSafeFields'
import { getSafeInfo } from 'src/logic/safe/utils/safeInformation'
import { buildSafe } from 'src/logic/safe/store/actions/fetchSafe'
Expand All @@ -34,6 +35,7 @@ import Button from 'src/components/layout/Button'
import { boldFont } from 'src/theme/variables'
import { WELCOME_ROUTE, history, generateSafeRoute, SAFE_ROUTES } from 'src/routes/routes'
import { getCurrentShortChainName } from 'src/config'
import { getGasParam } from 'src/logic/safe/transactions/gas'

type ModalDataType = {
safeAddress: string
Expand Down Expand Up @@ -73,12 +75,14 @@ function SafeCreationProcess(): ReactElement {
const ownerAddresses = ownerFields.map(({ addressFieldName }) => safeCreationFormValues[addressFieldName])
const safeCreationSalt = safeCreationFormValues[FIELD_NEW_SAFE_PROXY_SALT]
const gasLimit = safeCreationFormValues[FIELD_NEW_SAFE_GAS_LIMIT]
const gasPrice = safeCreationFormValues[FIELD_NEW_SAFE_GAS_PRICE]
const deploymentTx = getSafeDeploymentTransaction(ownerAddresses, confirmations, safeCreationSalt)

deploymentTx
.send({
from: userAddressAccount,
gas: gasLimit,
[getGasParam()]: gasPrice,
})
.once('transactionHash', (txHash) => {
saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, {
Expand Down
2 changes: 2 additions & 0 deletions src/routes/CreateSafePage/fields/createSafeFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const FIELD_NEW_SAFE_THRESHOLD = 'newSafeThreshold'
export const FIELD_MAX_OWNER_NUMBER = 'maxOwnerNumber'
export const FIELD_NEW_SAFE_PROXY_SALT = 'safeCreationSalt'
export const FIELD_NEW_SAFE_GAS_LIMIT = 'gasLimit'
export const FIELD_NEW_SAFE_GAS_PRICE = 'gasPrice'
export const FIELD_NEW_SAFE_CREATION_TX_HASH = 'safeCreationTxHash'

export type OwnerFieldItem = {
Expand All @@ -20,6 +21,7 @@ export type CreateSafeFormValues = {
[FIELD_MAX_OWNER_NUMBER]: number
[FIELD_NEW_SAFE_PROXY_SALT]: number
[FIELD_NEW_SAFE_GAS_LIMIT]: number
[FIELD_NEW_SAFE_GAS_PRICE]: string
[FIELD_NEW_SAFE_CREATION_TX_HASH]?: string
}

Expand Down
6 changes: 4 additions & 2 deletions src/routes/CreateSafePage/steps/ReviewNewSafeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FIELD_CREATE_CUSTOM_SAFE_NAME,
FIELD_CREATE_SUGGESTED_SAFE_NAME,
FIELD_NEW_SAFE_GAS_LIMIT,
FIELD_NEW_SAFE_GAS_PRICE,
FIELD_NEW_SAFE_PROXY_SALT,
FIELD_NEW_SAFE_THRESHOLD,
FIELD_SAFE_OWNERS_LIST,
Expand Down Expand Up @@ -49,7 +50,7 @@ function ReviewNewSafeStep(): ReactElement | null {
const safeCreationSalt = createSafeFormValues[FIELD_NEW_SAFE_PROXY_SALT]
const ownerAddresses = owners.map(({ addressFieldName }) => createSafeFormValues[addressFieldName])

const { gasCostFormatted, gasLimit } = useEstimateSafeCreationGas({
const { gasCostFormatted, gasLimit, gasPrice } = useEstimateSafeCreationGas({
addresses: ownerAddresses,
numOwners: numberOfOwners,
safeCreationSalt,
Expand All @@ -58,7 +59,8 @@ function ReviewNewSafeStep(): ReactElement | null {

useEffect(() => {
createSafeForm.change(FIELD_NEW_SAFE_GAS_LIMIT, gasLimit)
}, [gasLimit, createSafeForm])
createSafeForm.change(FIELD_NEW_SAFE_GAS_PRICE, gasPrice)
}, [gasLimit, gasPrice, createSafeForm])

return (
<Row data-testid={'create-safe-review-step'}>
Expand Down