@exodus/ethereum-lib 2.9.3 → 2.10.1

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.9.3",
3
+ "version": "2.10.1",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -11,9 +11,9 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@exodus/asset-lib": "^3.4.0",
14
- "@exodus/ethereumjs-common": "^2.4.0-exodus.3",
15
- "@exodus/ethereumjs-tx": "^3.3.0-exodus.3",
16
- "@exodus/ethereumjs-util": "^7.1.0-exodus.3",
14
+ "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
15
+ "@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
16
+ "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
17
17
  "@exodus/models": "^8.5.12",
18
18
  "@exodus/solidity-contract": "^0.1.3",
19
19
  "base-x": "^3.0.2",
@@ -24,5 +24,5 @@
24
24
  "peerDependencies": {
25
25
  "@exodus/assets": "8.0.x"
26
26
  },
27
- "gitHead": "eae6b9f748f998f441875426e473d37f5a9809dc"
27
+ "gitHead": "d4013194fcf671424c87a455fb4c95e97b54f9a9"
28
28
  }
@@ -82,11 +82,24 @@ const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null }
82
82
 
83
83
  const calculateTxGasPrice = (tx) => tx.feeAmount.div(tx.data.gasLimit)
84
84
 
85
- export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
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
99
  const usedGasPrice = calculateTxGasPrice(tx)
87
100
  const bumpedGasPrice = usedGasPrice.mul(12).div(10)
88
101
 
89
- return currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
102
+ return { bumpedGasPrice: currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice }
90
103
  }
91
104
 
92
105
  export default (
@@ -120,14 +133,15 @@ export default (
120
133
  getIsExchangeTx
121
134
  ) => (tx) => {
122
135
  const assetName = tx.coinName
123
- const baseAssetName = assets[assetName].baseAsset.name
136
+ const baseAsset = assets[assetName].baseAsset
137
+ const baseAssetName = baseAsset.name
124
138
  if (!getIsRbfEnabled(assetName))
125
139
  return wrapResponseToObject({ errorMessage: 'rbf is disabled' })
126
140
  if (!isEthereumLike(assets[assetName]))
127
141
  return wrapResponseToObject({ errorMessage: `not an ETH/ERC20/BSC/BEP20 asset supplied` })
128
142
  if (!tx.pending || !tx.sent)
129
143
  return wrapResponseToObject({ errorMessage: 'can not bump a confirmed or received TX' })
130
- if (!tx.data || !tx.data.gasLimit)
144
+ if (!tx.data || !(tx.data.gasLimit || tx.data.tipGasPrice))
131
145
  return wrapResponseToObject({ errorMessage: 'data object is missing or corrupted' })
132
146
  const isExchangeTx = getIsExchangeTx(tx.txId)
133
147
  if (isExchangeTx) return wrapResponseToObject({ errorMessage: 'can not bump an exchange TX' })
@@ -137,16 +151,29 @@ export default (
137
151
  if (isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog))
138
152
  return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
139
153
 
140
- const { gasPrice: currentGasPrice, gasPriceMinimumRate } = getFeeData(assetName)
154
+ const {
155
+ gasPrice: currentGasPrice,
156
+ gasPriceMinimumRate,
157
+ eip1559Enabled,
158
+ baseFee: currentBaseFee,
159
+ baseFeeMultiplier,
160
+ } = getFeeData(assetName)
141
161
  // converting to the smallest unit to avoid rounding errors
142
162
  if (
163
+ !eip1559Enabled &&
143
164
  calculateTxGasPrice(tx)
144
165
  .to('wei')
145
166
  .gte(currentGasPrice.mul(gasPriceMinimumRate).to('wei'))
146
167
  )
147
168
  return wrapResponseToObject({ errorMessage: 'the used gas price is still high enough' })
148
169
 
149
- const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
170
+ const { bumpedGasPrice: gasPriceToUse } = calculateBumpedGasPrice({
171
+ baseAsset,
172
+ tx,
173
+ currentGasPrice,
174
+ currentBaseFee,
175
+ baseFeeMultiplier,
176
+ })
150
177
  const replacementFee = gasPriceToUse.mul(tx.data.gasLimit)
151
178
  const extraEthNeeded = replacementFee.sub(tx.feeAmount)
152
179
  if (!getIsEnoughBalanceToAccelerate(activeWalletAccount, baseAssetName, extraEthNeeded))
@@ -33,7 +33,10 @@ export default function signUnsignedTx(
33
33
  )
34
34
  } else {
35
35
  // Legacy tx
36
- tx = Transaction.fromTxData({ gasPrice, ...txData }, { common: new Common({ chain }) })
36
+ tx = Transaction.fromTxData(
37
+ { gasPrice, ...txData },
38
+ { common: Common.custom({ chainId: chain }) }
39
+ )
37
40
  }
38
41
 
39
42
  const signedTx = tx.sign(privateKey)