@exodus/ethereum-lib 1.2.0 → 1.2.2

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": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -21,5 +21,5 @@
21
21
  "peerDependencies": {
22
22
  "@exodus/assets": "8.0.x"
23
23
  },
24
- "gitHead": "2e5d344cb8f52ccd17e37dfa73db49a95a927e96"
24
+ "gitHead": "0c3b4952a99f9157becc9a3754a34e289a0a1095"
25
25
  }
@@ -6,12 +6,20 @@ const BumpType = {
6
6
  RBF: 2,
7
7
  }
8
8
 
9
+ export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
10
+ const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
11
+ const bumpedGasPrice = usedGasPrice.mul(12).div(10)
12
+
13
+ return currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
14
+ }
15
+
9
16
  export default (
10
17
  getFeeDataSelector,
11
18
  getFeeSelector,
12
19
  getWalletAccountBalancesSelector,
13
20
  activeWalletAccountSelector,
14
- getPersonalNoteByTxIdSelector
21
+ getPersonalNoteByTxIdSelector,
22
+ assets
15
23
  ) =>
16
24
  createSelector(
17
25
  getFeeDataSelector,
@@ -22,20 +30,18 @@ export default (
22
30
  (getFeeData, getFee, getWalletAccountBalances, activeWalletAccount, getPersonalNoteByTxId) => (
23
31
  tx
24
32
  ) => {
25
- if (!['ethereum', 'ethereumclassic'].includes(tx.coinName)) return BumpType.NONE
26
- if (!tx.pending || !tx.sent || tx.exchange) return BumpType.NONE
33
+ const assetName = tx.coinName
34
+ const asset = assets[assetName]
35
+ if (!['ETHEREUM_ERC20', 'ETHEREUM_LIKE'].includes(asset.assetType)) return BumpType.NONE
36
+ if (!tx.pending || !tx.sent || tx.exchange || !tx.data?.gasLimit) return BumpType.NONE
27
37
  if (getPersonalNoteByTxId(tx.txId)?.dapp) return BumpType.NONE
28
38
 
29
39
  const walletAccountBalances = getWalletAccountBalances(activeWalletAccount)
30
- const assetName = tx.coinName
31
40
  const { gasPrice: currentGasPrice } = getFeeData(assetName)
32
- const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
33
- // new gas price should be at least 20% higher and not less than the current gas price
34
- const bumpedGasPrice = usedGasPrice.mul(12).div(10)
35
- const gasPriceToUse = currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
41
+ const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
36
42
  const replacementFee = gasPriceToUse.mul(tx.data.gasLimit)
37
43
  const extraEthNeeded = replacementFee.sub(tx.feeAmount)
38
- if (walletAccountBalances[assetName].lt(extraEthNeeded)) return BumpType.NONE
44
+ if (walletAccountBalances[asset.baseAsset.name].lt(extraEthNeeded)) return BumpType.NONE
39
45
 
40
46
  return BumpType.RBF
41
47
  }
@@ -1 +1,4 @@
1
- export { default as getCanAccelerateTxFactory } from './get-can-accelerate-tx-factory'
1
+ export {
2
+ default as getCanAccelerateTxFactory,
3
+ calculateBumpedGasPrice,
4
+ } from './get-can-accelerate-tx-factory'