@exodus/ethereum-lib 2.6.0 → 2.7.0

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.6.0",
3
+ "version": "2.7.0",
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": "4453c1bb550cdf09b6851ab7c1c2d092eca8e792"
26
+ "gitHead": "71d126e789b161f5877db4a651a641061f00c7af"
27
27
  }
@@ -8,16 +8,28 @@ const BumpType = {
8
8
  RBF: 2,
9
9
  }
10
10
 
11
+ // Legacy compatibility with wallets
11
12
  export function getPendingNonExchangeTxs(activeWalletAccount, getTxLog, getIsExchangeTx) {
13
+ console.log('Using deprecated function getPendingNonExchangeTxs()')
14
+ return getAssetPendingNonExchangeTxs('ethereum', activeWalletAccount, getTxLog, getIsExchangeTx)
15
+ }
16
+
17
+ export function getAssetPendingNonExchangeTxs(
18
+ baseAssetName,
19
+ activeWalletAccount,
20
+ getTxLog,
21
+ getIsExchangeTx
22
+ ) {
12
23
  // check if the tx log even has pending transactions
13
24
  const result = isQueuedPendingTx(
14
25
  { data: { nonce: Number.MAX_SAFE_INTEGER } },
26
+ baseAssetName,
15
27
  activeWalletAccount,
16
28
  getTxLog
17
29
  )
18
30
  if (!result) return []
19
31
 
20
- const txLog = getTxLog('ethereum', activeWalletAccount)
32
+ const txLog = getTxLog(baseAssetName, activeWalletAccount)
21
33
  const pendingNonExchangeTxs = []
22
34
  for (let index = isQueuedPendingTx.minIndex; index < txLog.size; index++) {
23
35
  const _tx = txLog.getAt(index)
@@ -29,8 +41,8 @@ export function getPendingNonExchangeTxs(activeWalletAccount, getTxLog, getIsExc
29
41
  return pendingNonExchangeTxs
30
42
  }
31
43
 
32
- function isQueuedPendingTx(tx, activeWalletAccount, getTxLog) {
33
- const txLog = getTxLog('ethereum', activeWalletAccount)
44
+ function isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog) {
45
+ const txLog = getTxLog(baseAssetName, activeWalletAccount)
34
46
  if (!txLog || txLog.size === 0) return false
35
47
 
36
48
  const txAtMinIndex = txLog.getAt(isQueuedPendingTx.minIndex)
@@ -105,11 +117,11 @@ export default (
105
117
  getIsExchangeTx
106
118
  ) => (tx) => {
107
119
  const assetName = tx.coinName
108
- const asset = assets[assetName]
120
+ const baseAssetName = assets[assetName].baseAsset.name
109
121
  if (!getIsRbfEnabled(assetName))
110
122
  return wrapResponseToObject({ errorMessage: 'rbf is disabled' })
111
- if (!['ETHEREUM_ERC20', 'ETHEREUM_LIKE'].includes(asset.assetType))
112
- return wrapResponseToObject({ errorMessage: `not an ETH/ERC20 asset supplied` })
123
+ if (!['ethereum', 'bsc'].includes(baseAssetName))
124
+ return wrapResponseToObject({ errorMessage: `not an ETH/ERC20/BSC/BEP20 asset supplied` })
113
125
  if (!tx.pending || !tx.sent)
114
126
  return wrapResponseToObject({ errorMessage: 'can not bump a pending or received TX' })
115
127
  if (!tx.data || !tx.data.gasLimit)
@@ -119,16 +131,14 @@ export default (
119
131
  const personalNote = getPersonalNoteByTxId(tx.txId)
120
132
  if (personalNote && personalNote.dapp)
121
133
  return wrapResponseToObject({ errorMessage: 'can not bump a dapp TX' })
122
- if (isQueuedPendingTx(tx, activeWalletAccount, getTxLog))
134
+ if (isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog))
123
135
  return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
124
136
 
125
137
  const { gasPrice: currentGasPrice } = getFeeData(assetName)
126
138
  const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
127
139
  const replacementFee = gasPriceToUse.mul(tx.data.gasLimit)
128
140
  const extraEthNeeded = replacementFee.sub(tx.feeAmount)
129
- if (
130
- !getIsEnoughBalanceToAccelerate(activeWalletAccount, asset.baseAsset.name, extraEthNeeded)
131
- )
141
+ if (!getIsEnoughBalanceToAccelerate(activeWalletAccount, baseAssetName, extraEthNeeded))
132
142
  return wrapResponseToObject({ errorMessage: 'insufficient funds' })
133
143
 
134
144
  return wrapResponseToObject({ bumpType: BumpType.RBF })
@@ -2,6 +2,7 @@ export {
2
2
  default as getCanAccelerateTxFactory,
3
3
  calculateBumpedGasPrice,
4
4
  getPendingNonExchangeTxs,
5
+ getAssetPendingNonExchangeTxs,
5
6
  } from './get-can-accelerate-tx-factory'
6
7
 
7
8
  export { default as getIsEnoughBalanceToAccelerateSelectorFactory } from './get-is-enough-balance-to-accelerate-factory'
@@ -0,0 +1,15 @@
1
+ const defaultMultiplier = 1.1
2
+
3
+ // if a wallet has 0 ETH the deposit needed should be more than the fee needed by <multiplier>
4
+ // if a wallet has <N> ETH, the deposit needed should be the fee * <multiplier> - <N>
5
+ export default function({ fee, balance, multiplier = defaultMultiplier }) {
6
+ if (typeof multiplier !== 'number' || multiplier < 1) multiplier = defaultMultiplier
7
+ if (balance.gt(fee)) return balance.unitType.ZERO
8
+
9
+ return fee
10
+ .mul(multiplier)
11
+ .toDefault()
12
+ .sub(balance)
13
+ .toFixed(4, 'ceil')
14
+ .toString()
15
+ }
package/src/utils.js CHANGED
@@ -6,6 +6,7 @@ const base10 = baseX('0123456789')
6
6
  const base16 = baseX('0123456789abcdef')
7
7
 
8
8
  export const isEthereumToken = (asset) => asset.assetType === 'ETHEREUM_ERC20'
9
+ export const isBscToken = (asset) => asset.assetType === 'BSC_BEP20'
9
10
  export const isQuorumToken = (asset) => asset.assetType === 'QUORUM_ERC20'
10
11
 
11
12
  export function buffer2currency({ asset, value }) {