@exodus/ethereum-lib 2.1.1 → 2.3.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.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@exodus/models": "^8.5.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1b43dd94263594666e89c4948e728d28e5ffa798"
|
|
29
29
|
}
|
package/src/fee-data/ethereum.js
CHANGED
|
@@ -2,9 +2,12 @@ import { FeeData } from '@exodus/asset-lib'
|
|
|
2
2
|
|
|
3
3
|
export default new FeeData(
|
|
4
4
|
{
|
|
5
|
-
gasPrice: '
|
|
5
|
+
gasPrice: '75 Gwei',
|
|
6
6
|
max: '250 Gwei',
|
|
7
7
|
min: '1 Gwei',
|
|
8
|
+
erc20FuelThreshold: '0.025 ETH',
|
|
9
|
+
swapFee: '0.05 ETH',
|
|
10
|
+
gasPriceEconomicalRate: 0.7,
|
|
8
11
|
},
|
|
9
12
|
'gasPrice',
|
|
10
13
|
'ethereum'
|
|
@@ -8,6 +8,27 @@ const BumpType = {
|
|
|
8
8
|
RBF: 2,
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function getPendingNonExchangeTxs(activeWalletAccount, getTxLog, getIsExchangeTx) {
|
|
12
|
+
// check if the tx log even has pending transactions
|
|
13
|
+
const result = isQueuedPendingTx(
|
|
14
|
+
{ data: { nonce: Number.MAX_SAFE_INTEGER } },
|
|
15
|
+
activeWalletAccount,
|
|
16
|
+
getTxLog
|
|
17
|
+
)
|
|
18
|
+
if (!result) return []
|
|
19
|
+
|
|
20
|
+
const txLog = getTxLog('ethereum', activeWalletAccount)
|
|
21
|
+
const pendingNonExchangeTxs = []
|
|
22
|
+
for (let index = isQueuedPendingTx.minIndex; index < txLog.size; index++) {
|
|
23
|
+
const _tx = txLog.getAt(index)
|
|
24
|
+
if (_tx.pending && _tx.sent && !getIsExchangeTx(_tx.txId)) {
|
|
25
|
+
pendingNonExchangeTxs.push(_tx)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return pendingNonExchangeTxs
|
|
30
|
+
}
|
|
31
|
+
|
|
11
32
|
function isQueuedPendingTx(tx, activeWalletAccount, getTxLog) {
|
|
12
33
|
const txLog = getTxLog('ethereum', activeWalletAccount)
|
|
13
34
|
if (!txLog || txLog.size === 0) return false
|
|
@@ -41,6 +62,11 @@ export const _refreshCache = () => {
|
|
|
41
62
|
isQueuedPendingTx.minIndex = null
|
|
42
63
|
}
|
|
43
64
|
|
|
65
|
+
const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null } = {}) => ({
|
|
66
|
+
bumpType,
|
|
67
|
+
errorMessage,
|
|
68
|
+
})
|
|
69
|
+
|
|
44
70
|
export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
|
|
45
71
|
const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
|
|
46
72
|
const bumpedGasPrice = usedGasPrice.mul(12).div(10)
|
|
@@ -80,14 +106,21 @@ export default (
|
|
|
80
106
|
) => (tx) => {
|
|
81
107
|
const assetName = tx.coinName
|
|
82
108
|
const asset = assets[assetName]
|
|
83
|
-
if (!getIsRbfEnabled(assetName))
|
|
84
|
-
|
|
85
|
-
if (!
|
|
109
|
+
if (!getIsRbfEnabled(assetName))
|
|
110
|
+
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` })
|
|
113
|
+
if (!tx.pending || !tx.sent)
|
|
114
|
+
return wrapResponseToObject({ errorMessage: 'can not bump a pending or received TX' })
|
|
115
|
+
if (!tx.data || !tx.data.gasLimit)
|
|
116
|
+
return wrapResponseToObject({ errorMessage: 'data object is missing or corrupted' })
|
|
86
117
|
const isExchangeTx = getIsExchangeTx(tx.txId)
|
|
87
|
-
if (isExchangeTx) return
|
|
118
|
+
if (isExchangeTx) return wrapResponseToObject({ errorMessage: 'can not bump an exchange TX' })
|
|
88
119
|
const personalNote = getPersonalNoteByTxId(tx.txId)
|
|
89
|
-
if (personalNote && personalNote.dapp)
|
|
90
|
-
|
|
120
|
+
if (personalNote && personalNote.dapp)
|
|
121
|
+
return wrapResponseToObject({ errorMessage: 'can not bump a dapp TX' })
|
|
122
|
+
if (isQueuedPendingTx(tx, activeWalletAccount, getTxLog))
|
|
123
|
+
return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
|
|
91
124
|
|
|
92
125
|
const { gasPrice: currentGasPrice } = getFeeData(assetName)
|
|
93
126
|
const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
|
|
@@ -96,8 +129,8 @@ export default (
|
|
|
96
129
|
if (
|
|
97
130
|
!getIsEnoughBalanceToAccelerate(activeWalletAccount, asset.baseAsset.name, extraEthNeeded)
|
|
98
131
|
)
|
|
99
|
-
return
|
|
132
|
+
return wrapResponseToObject({ errorMessage: 'insufficient funds' })
|
|
100
133
|
|
|
101
|
-
return BumpType.RBF
|
|
134
|
+
return wrapResponseToObject({ bumpType: BumpType.RBF })
|
|
102
135
|
}
|
|
103
136
|
)
|
package/src/selectors/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
default as getCanAccelerateTxFactory,
|
|
3
3
|
calculateBumpedGasPrice,
|
|
4
|
+
getPendingNonExchangeTxs,
|
|
4
5
|
} from './get-can-accelerate-tx-factory'
|
|
5
6
|
|
|
6
7
|
export { default as getIsEnoughBalanceToAccelerateSelectorFactory } from './get-is-enough-balance-to-accelerate-factory'
|