Skip to content

Commit

Permalink
fix: gas prices for metamask
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Dec 2, 2022
1 parent ee157f4 commit b02150f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
17 changes: 10 additions & 7 deletions packages/wallet-ts/src/broadcaster/Web3Broadcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { SendTransactionOptions } from '../wallets/types'
import {
DEFAULT_GAS_PRICE,
GAS_LIMIT_MULTIPLIER,
GAS_PRICE_MULTIPLIER,
INJ_DENOM,
TIP_IN_GWEI,
TX_DEFAULTS_GAS,
} from '../utils/constants'

Expand Down Expand Up @@ -110,13 +110,14 @@ export class Web3Broadcaster {
from: address,
to: tokenAddress,
gas: new BigNumberInWei(gas.times(GAS_LIMIT_MULTIPLIER).toFixed(0))
.decimalPlaces(0)
.toNumber()
.toString(16),
maxFeePerGas: new BigNumberInWei(gasPrice)
.times(GAS_PRICE_MULTIPLIER)
.decimalPlaces(0)
.toNumber()
.toString(16),
maxPriorityFeePerGas: '0x77359400' /* 2 gwei in hex */,
maxPriorityFeePerGas: TIP_IN_GWEI.toString(16),
data,
}
}
Expand Down Expand Up @@ -167,13 +168,14 @@ export class Web3Broadcaster {
from: address,
to: peggyContractAddress,
gas: new BigNumberInWei(gas.times(GAS_LIMIT_MULTIPLIER).toFixed(0))
.decimalPlaces(0)
.toNumber()
.toString(16),
maxFeePerGas: new BigNumberInWei(gasPrice)
.times(GAS_PRICE_MULTIPLIER)
.decimalPlaces(0)
.toNumber()
.toString(16),
maxPriorityFeePerGas: '0x77359400' /* 2 gwei in hex */,
maxPriorityFeePerGas: TIP_IN_GWEI.toString(16),
data,
}
}
Expand Down Expand Up @@ -229,13 +231,14 @@ export class Web3Broadcaster {
from: address,
to: peggyContractAddress,
gas: new BigNumberInWei(gas.times(GAS_LIMIT_MULTIPLIER).toFixed(0))
.decimalPlaces(0)
.toNumber()
.toString(16),
maxFeePerGas: new BigNumberInWei(gasPrice)
.times(GAS_PRICE_MULTIPLIER)
.decimalPlaces(0)
.toNumber()
.toString(16),
maxPriorityFeePerGas: '0x77359400' /* 2 gwei in hex */,
maxPriorityFeePerGas: TIP_IN_GWEI.toString(16),
data: abiEncodedData,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@injectivelabs/exceptions'
import { DirectSignResponse } from '@cosmjs/proto-signing'
import { TxRaw } from '@injectivelabs/chain-api/cosmos/tx/v1beta1/tx_pb'
import { TIP_IN_GWEI } from 'packages/wallet-ts/src/utils'
import {
ConcreteWalletStrategy,
EthereumWalletStrategyArgs,
Expand Down Expand Up @@ -230,7 +231,7 @@ export default class LedgerBase
gasLimit: addHexPrefix(txData.gas),
maxFeePerGas: addHexPrefix(txData.gasPrice || txData.maxFeePerGas),
maxPriorityFeePerGas: addHexPrefix(
txData.maxPriorityFeePerGas || '0x77359400' /* 2 Gwei in HEX */,
txData.maxPriorityFeePerGas || TIP_IN_GWEI.toString(16),
),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@injectivelabs/exceptions'
import { DirectSignResponse } from '@cosmjs/proto-signing'
import { TxRaw } from '@injectivelabs/chain-api/cosmos/tx/v1beta1/tx_pb'
import { TIP_IN_GWEI } from 'packages/wallet-ts/src/utils'
import {
ConcreteWalletStrategy,
EthereumWalletStrategyArgs,
Expand Down Expand Up @@ -254,7 +255,7 @@ export default class Trezor
gasLimit: addHexPrefix(txData.gas),
maxFeePerGas: addHexPrefix(txData.gasPrice || txData.maxFeePerGas),
maxPriorityFeePerGas: addHexPrefix(
txData.maxPriorityFeePerGas || '0x77359400' /* 2 Gwei in HEX */,
txData.maxPriorityFeePerGas || TIP_IN_GWEI.toString(16),
),
}
const tx = FeeMarketEIP1559Transaction.fromTxData(eip1559TxData, {
Expand Down
3 changes: 3 additions & 0 deletions packages/wallet-ts/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { BigNumberInBase } from '@injectivelabs/utils'

export const GWEI_IN_WEI: BigNumberInBase = new BigNumberInBase(1000000000)
export const TIP_IN_GWEI: BigNumberInBase = new BigNumberInBase(2).times(
GWEI_IN_WEI,
)
export const GAS_LIMIT_MULTIPLIER = 1.2
export const GAS_PRICE_MULTIPLIER = 1.1
export const TX_DEFAULTS_GAS = 80_000_000
Expand Down

0 comments on commit b02150f

Please sign in to comment.