@exodus/ethereum-lib 2.7.2 → 2.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "2.7.2",
3
+ "version": "2.7.4",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -23,5 +23,5 @@
23
23
  "peerDependencies": {
24
24
  "@exodus/assets": "8.0.x"
25
25
  },
26
- "gitHead": "cd08eeb37f107463a6285a9fb151a97e6e1cd2c7"
26
+ "gitHead": "14b8266879ea622f272c94f98e71c1a16dd274f1"
27
27
  }
@@ -5,9 +5,9 @@ export default new FeeData(
5
5
  gasPrice: '20 Gwei',
6
6
  max: '200 Gwei',
7
7
  min: '1 Gwei',
8
- erc20FuelThreshold: '25000000 Gwei',
9
- gasPriceEconomicalRate: 1,
10
- gasPriceMinimumRate: 1,
8
+ erc20FuelThreshold: '2500000 Gwei',
9
+ gasPriceEconomicalRate: 0.8,
10
+ gasPriceMinimumRate: 0.6,
11
11
  },
12
12
  'gasPrice',
13
13
  'bsc'
@@ -79,8 +79,10 @@ const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null }
79
79
  errorMessage,
80
80
  })
81
81
 
82
+ const calculateTxGasPrice = (tx) => tx.feeAmount.div(tx.data.gasLimit)
83
+
82
84
  export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
83
- const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
85
+ const usedGasPrice = calculateTxGasPrice(tx)
84
86
  const bumpedGasPrice = usedGasPrice.mul(12).div(10)
85
87
 
86
88
  return currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
@@ -123,7 +125,7 @@ export default (
123
125
  if (!['ethereum', 'bsc'].includes(baseAssetName))
124
126
  return wrapResponseToObject({ errorMessage: `not an ETH/ERC20/BSC/BEP20 asset supplied` })
125
127
  if (!tx.pending || !tx.sent)
126
- return wrapResponseToObject({ errorMessage: 'can not bump a pending or received TX' })
128
+ return wrapResponseToObject({ errorMessage: 'can not bump a confirmed or received TX' })
127
129
  if (!tx.data || !tx.data.gasLimit)
128
130
  return wrapResponseToObject({ errorMessage: 'data object is missing or corrupted' })
129
131
  const isExchangeTx = getIsExchangeTx(tx.txId)
@@ -134,7 +136,15 @@ export default (
134
136
  if (isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog))
135
137
  return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
136
138
 
137
- const { gasPrice: currentGasPrice } = getFeeData(assetName)
139
+ const { gasPrice: currentGasPrice, gasPriceMinimumRate } = getFeeData(assetName)
140
+ // converting to the smallest unit to avoid rounding errors
141
+ if (
142
+ calculateTxGasPrice(tx)
143
+ .to('wei')
144
+ .gte(currentGasPrice.mul(gasPriceMinimumRate).to('wei'))
145
+ )
146
+ return wrapResponseToObject({ errorMessage: 'the used gas price is still high enough' })
147
+
138
148
  const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
139
149
  const replacementFee = gasPriceToUse.mul(tx.data.gasLimit)
140
150
  const extraEthNeeded = replacementFee.sub(tx.feeAmount)
@@ -1,5 +1,5 @@
1
1
  import ethUtil from 'ethereumjs-util'
2
- import { isEthereumToken, isQuorumToken, currency2buffer } from '../utils'
2
+ import { isToken, currency2buffer } from '../utils'
3
3
  import { CHAIN_IDS } from '../constants'
4
4
 
5
5
  import type { UnsignedTransaction } from '#/app-models'
@@ -25,9 +25,9 @@ export default function createUnsignedTx({
25
25
  const baseAsset = asset.baseAsset
26
26
  if (!chainId) chainId = CHAIN_IDS[baseAsset.name] // mainnet
27
27
 
28
- const isToken = isEthereumToken(asset) || isQuorumToken(asset)
29
- const to = isToken ? asset.contract.address : address
30
- let value = currency2buffer(isToken ? baseAsset.currency.ZERO : amount)
28
+ const _isToken = isToken(asset)
29
+ const to = _isToken ? asset.contract.address : address
30
+ let value = currency2buffer(_isToken ? baseAsset.currency.ZERO : amount)
31
31
 
32
32
  // TODO: check: present on desktop missing on mobile. This insures we never have a buffer specifying 0.
33
33
  // In ETH, a buffer of zero length and a buffer specifying 0 imply different things
@@ -1,6 +1,6 @@
1
1
  /* @flow */
2
2
  import * as ethUtil from 'ethereumjs-util'
3
- import { isEthereumToken, isQuorumToken, buffer2currency } from '../utils'
3
+ import { isToken, buffer2currency } from '../utils'
4
4
  import { CHAIN_IDS } from '../constants'
5
5
 
6
6
  import type { UnsignedTransaction, ParsedTransaction } from '@exodus/models/lib/types'
@@ -10,7 +10,7 @@ export default function parseUnsignedTx(
10
10
  unsignedTx: UnsignedTransaction
11
11
  ): ParsedTransaction {
12
12
  const { txData } = unsignedTx
13
- const isToken = isEthereumToken(asset) || isQuorumToken(asset)
13
+ const _isToken = isToken(asset)
14
14
  const baseAsset = asset.baseAsset
15
15
  const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
16
16
  const gasLimit = ethUtil.bufferToInt(txData.gasLimit)
@@ -18,7 +18,7 @@ export default function parseUnsignedTx(
18
18
  let { to, chainId, data } = txData
19
19
  let amount
20
20
  const fee = gasPrice.mul(gasLimit)
21
- if (isToken) {
21
+ if (_isToken) {
22
22
  const { method, values } = asset.contract.decodeInput(data)
23
23
  if (method === 'transfer' || method === 'approve') {
24
24
  to = values[0]
@@ -10,6 +10,8 @@ const base16 = baseX('0123456789abcdef')
10
10
  export const isEthereumToken = (asset) => asset.assetType === 'ETHEREUM_ERC20'
11
11
  export const isBscToken = (asset) => asset.assetType === 'BSC_BEP20'
12
12
  export const isQuorumToken = (asset) => asset.assetType === 'QUORUM_ERC20'
13
+ export const isToken = (asset) =>
14
+ isEthereumToken(asset) || isBscToken(asset) || isQuorumToken(asset)
13
15
 
14
16
  export function buffer2currency({ asset, value }) {
15
17
  return asset.currency.baseUnit(base10.encode(value)).toDefault()