@exodus/ethereum-lib 2.10.2 → 2.10.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.10.2",
3
+ "version": "2.10.4",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -24,5 +24,5 @@
24
24
  "peerDependencies": {
25
25
  "@exodus/assets": "8.0.x"
26
26
  },
27
- "gitHead": "a352b5ebc98ee831c4c8c8a5d055d70e15801401"
27
+ "gitHead": "704f2a8459929ab1c12653de7df84d1406b67e0f"
28
28
  }
package/src/constants.js CHANGED
@@ -9,3 +9,4 @@ export const CONFIRMATIONS_NUMBER = {
9
9
  }
10
10
  export const ETHEREUM_LIKE_ASSETS = ['bsc', 'ethereum', 'ethereumclassic', 'matic']
11
11
  export const ETHEREUM_LIKE_TOKEN_TYPES = ['ETHEREUM_ERC20', 'BSC_BEP20', 'MATIC_ERC20']
12
+ export const BUMP_RATE = 1.2
@@ -11,10 +11,7 @@ export default new FeeData(
11
11
  gasPriceMinimumRate: 0.5,
12
12
  enableFeeDelegation: false,
13
13
  tipGasPrice: '2 Gwei',
14
- minTipGasPrice: '1 Gwei',
15
- maxTipGasPrice: '5 Gwei',
16
- baseFeeMultiplier: 1.6019, // 1.125^4
17
- eip1559Enabled: false,
14
+ eip1559Enabled: true,
18
15
  },
19
16
  'gasPrice',
20
17
  'ethereum'
@@ -7,19 +7,11 @@ export default class EthereumLikeFeeMonitor extends FeeMonitor {
7
7
  interval = DEFAULT_FEE_MONITOR_INTERVAL,
8
8
  assetName,
9
9
  getGasPrice,
10
- getBaseFee,
11
10
  minGasPrice = 0,
12
11
  }) {
13
12
  super({ updateFee, interval, assetName })
14
13
  this.getGasPrice = getGasPrice
15
14
  this.minGasPrice = minGasPrice
16
- this.getBaseFee = getBaseFee
17
- this.eip1559Enabled = true
18
- }
19
-
20
- setEip1559Enabled(bool = true) {
21
- // bool set by remote-config
22
- this.eip1559Enabled = bool
23
15
  }
24
16
 
25
17
  async fetchFee() {
@@ -33,15 +25,8 @@ export default class EthereumLikeFeeMonitor extends FeeMonitor {
33
25
  gasPrice = this.minGasPrice
34
26
  }
35
27
 
36
- if (this.asset.name === 'ethereum' && this.eip1559Enabled) {
37
- const baseFee = parseInt(await this.getBaseFee(), 16)
38
- return {
39
- gasPrice: `${gasPrice} wei`,
40
- baseFee: `${baseFee} wei`,
41
- eip1559Enabled: this.eip1559Enabled,
42
- }
28
+ return {
29
+ gasPrice: `${gasPrice} wei`,
43
30
  }
44
-
45
- return { gasPrice: `${gasPrice} wei` }
46
31
  }
47
32
  }
@@ -1,6 +1,7 @@
1
1
  import { createSelector } from 'reselect'
2
2
  import ms from 'ms'
3
3
  import { isEthereumLike } from '../utils'
4
+ import { BUMP_RATE } from '../constants'
4
5
 
5
6
  const MINUTE = ms('1m')
6
7
  const BumpType = {
@@ -82,24 +83,22 @@ const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null }
82
83
 
83
84
  const calculateTxGasPrice = (tx) => tx.feeAmount.div(tx.data.gasLimit)
84
85
 
85
- export const calculateBumpedGasPrice = ({
86
- baseAsset,
87
- tx,
88
- currentGasPrice,
89
- currentBaseFee,
90
- baseFeeMultiplier,
91
- }) => {
92
- if (tx.data?.tipGasPrice) {
93
- // EIP1559 tx
94
- const bumpedTipGasPrice = baseAsset.currency.baseUnit(tx.data.tipGasPrice).mul(2)
95
- const bumpedGasPrice = currentBaseFee.mul(baseFeeMultiplier).add(bumpedTipGasPrice) // we are fetching a fresh baseFee, no need to multiply by baseFeeMultiplier
96
- return { bumpedGasPrice, bumpedTipGasPrice }
97
- }
98
-
86
+ export const calculateBumpedGasPrice = ({ baseAsset, tx, currentGasPrice, eip1559Enabled }) => {
99
87
  const usedGasPrice = calculateTxGasPrice(tx)
100
- const bumpedGasPrice = usedGasPrice.mul(12).div(10)
101
-
102
- return { bumpedGasPrice: currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice }
88
+ let bumpedGasPrice = usedGasPrice.mul(BUMP_RATE)
89
+ bumpedGasPrice = currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
90
+
91
+ const tipGasPrice = tx.data?.tipGasPrice
92
+ ? baseAsset.currency.baseUnit(tx.data.tipGasPrice).to('Gwei')
93
+ : baseAsset.currency.parse('2 Gwei') // we bump a legacy tx by an EIP1559 tx
94
+ const bumpedTipGasPrice = tipGasPrice.mul(BUMP_RATE)
95
+
96
+ return eip1559Enabled
97
+ ? {
98
+ bumpedTipGasPrice,
99
+ bumpedGasPrice,
100
+ }
101
+ : { bumpedGasPrice }
103
102
  }
104
103
 
105
104
  export default (
@@ -151,13 +150,9 @@ export default (
151
150
  if (isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog))
152
151
  return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
153
152
 
154
- const {
155
- gasPrice: currentGasPrice,
156
- gasPriceMinimumRate,
157
- eip1559Enabled,
158
- baseFee: currentBaseFee,
159
- baseFeeMultiplier,
160
- } = getFeeData(assetName)
153
+ const { gasPrice: currentGasPrice, gasPriceMinimumRate, eip1559Enabled } = getFeeData(
154
+ assetName
155
+ )
161
156
  // converting to the smallest unit to avoid rounding errors
162
157
  if (
163
158
  !eip1559Enabled &&
@@ -171,8 +166,7 @@ export default (
171
166
  baseAsset,
172
167
  tx,
173
168
  currentGasPrice,
174
- currentBaseFee,
175
- baseFeeMultiplier,
169
+ eip1559Enabled,
176
170
  })
177
171
  const replacementFee = gasPriceToUse.mul(tx.data.gasLimit)
178
172
  const extraEthNeeded = replacementFee.sub(tx.feeAmount)
@@ -63,10 +63,5 @@ export function deserialize(hex) {
63
63
  }
64
64
  }
65
65
 
66
- export function gasPriceFromFeeData(feeData) {
67
- const { baseFeeMultiplier, baseFee, tipGasPrice, gasPrice, eip1559Enabled } = feeData
68
-
69
- return eip1559Enabled
70
- ? { gasPrice: baseFee.mul(baseFeeMultiplier).add(tipGasPrice), tipGasPrice }
71
- : { gasPrice }
72
- }
66
+ const getTxType = (serializedTx: string) => serializedTx.slice(2, 4)
67
+ export const isEip1559Tx = (serializedTx: string) => getTxType(serializedTx) === '02'