@exodus/ethereum-lib 2.0.3 → 2.0.6

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.0.3",
3
+ "version": "2.0.6",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -21,5 +21,8 @@
21
21
  "peerDependencies": {
22
22
  "@exodus/assets": "8.0.x"
23
23
  },
24
- "gitHead": "afe105853a177b31f0652bb9edb8afbd2e898b80"
24
+ "devDependencies": {
25
+ "@exodus/models": "^8.5.1"
26
+ },
27
+ "gitHead": "38a0f167883abb62d45459bcd747f38a6c5a3b0d"
25
28
  }
@@ -1,11 +1,39 @@
1
1
  import { createSelector } from 'reselect'
2
+ import ms from 'ms'
2
3
 
4
+ const MINUTE = ms('1m')
3
5
  const BumpType = {
4
6
  NONE: 0,
5
7
  CPFP: 1,
6
8
  RBF: 2,
7
9
  }
8
10
 
11
+ function isQueuedPendingTx(tx, activeWalletAccount, getTxLog) {
12
+ const txLog = getTxLog('ethereum', activeWalletAccount)
13
+ if (isQueuedPendingTx.minIndex >= 0 && txLog.getAt(isQueuedPendingTx.minIndex)?.pending) {
14
+ return tx.data?.nonce > txLog.getAt(isQueuedPendingTx.minIndex).data.nonce
15
+ }
16
+ let minPendingNonce = Number.MAX_SAFE_INTEGER
17
+ for (let index = 0; index < txLog.size; index++) {
18
+ const _tx = txLog.getAt(index)
19
+ if (!_tx.pending) continue
20
+ // ignore nonce of a TX that just replaced an another tx
21
+ if (_tx.data?.replacedTxId && Date.now() - _tx.date < MINUTE) continue
22
+ if (_tx.sent && _tx.data?.nonce < minPendingNonce) {
23
+ minPendingNonce = _tx.data.nonce
24
+ isQueuedPendingTx.minIndex = index
25
+ }
26
+ }
27
+
28
+ return tx.data.nonce > minPendingNonce
29
+ }
30
+
31
+ // needs for tests
32
+ export const _refreshCache = () => {
33
+ isQueuedPendingTx.minPendingNonce = null
34
+ isQueuedPendingTx.minIndex = null
35
+ }
36
+
9
37
  export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
10
38
  const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
11
39
  const bumpedGasPrice = usedGasPrice.mul(12).div(10)
@@ -20,6 +48,7 @@ export default (
20
48
  getPersonalNoteByTxIdSelector,
21
49
  getIsRbfEnabledSelector,
22
50
  getIsEnoughBalanceToAccelerateSelector,
51
+ getTxLogSelector,
23
52
  assets
24
53
  ) =>
25
54
  createSelector(
@@ -29,13 +58,15 @@ export default (
29
58
  getPersonalNoteByTxIdSelector,
30
59
  getIsRbfEnabledSelector,
31
60
  getIsEnoughBalanceToAccelerateSelector,
61
+ getTxLogSelector,
32
62
  (
33
63
  getFeeData,
34
64
  getFee,
35
65
  activeWalletAccount,
36
66
  getPersonalNoteByTxId,
37
67
  getIsRbfEnabled,
38
- getIsEnoughBalanceToAccelerate
68
+ getIsEnoughBalanceToAccelerate,
69
+ getTxLog
39
70
  ) => (tx) => {
40
71
  const assetName = tx.coinName
41
72
  const asset = assets[assetName]
@@ -43,6 +74,7 @@ export default (
43
74
  if (!['ETHEREUM_ERC20', 'ETHEREUM_LIKE'].includes(asset.assetType)) return BumpType.NONE
44
75
  if (!tx.pending || !tx.sent || tx.exchange || !tx.data?.gasLimit) return BumpType.NONE
45
76
  if (getPersonalNoteByTxId(tx.txId)?.dapp) return BumpType.NONE
77
+ if (isQueuedPendingTx(tx, activeWalletAccount, getTxLog)) return BumpType.NONE
46
78
 
47
79
  const { gasPrice: currentGasPrice } = getFeeData(assetName)
48
80
  const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)