@exodus/ethereum-lib 2.2.0 → 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.2.0",
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": "956ac273cee5a8979824a68127a6d400ac711e48"
28
+ "gitHead": "1b43dd94263594666e89c4948e728d28e5ffa798"
29
29
  }
@@ -5,6 +5,9 @@ export default new FeeData(
5
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'
@@ -62,6 +62,11 @@ export const _refreshCache = () => {
62
62
  isQueuedPendingTx.minIndex = null
63
63
  }
64
64
 
65
+ const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null } = {}) => ({
66
+ bumpType,
67
+ errorMessage,
68
+ })
69
+
65
70
  export const calculateBumpedGasPrice = (tx, currentGasPrice) => {
66
71
  const usedGasPrice = tx.feeAmount.div(tx.data.gasLimit)
67
72
  const bumpedGasPrice = usedGasPrice.mul(12).div(10)
@@ -101,14 +106,21 @@ export default (
101
106
  ) => (tx) => {
102
107
  const assetName = tx.coinName
103
108
  const asset = assets[assetName]
104
- if (!getIsRbfEnabled(assetName)) return BumpType.NONE
105
- if (!['ETHEREUM_ERC20', 'ETHEREUM_LIKE'].includes(asset.assetType)) return BumpType.NONE
106
- if (!tx.pending || !tx.sent || !tx.data || !tx.data.gasLimit) return BumpType.NONE
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' })
107
117
  const isExchangeTx = getIsExchangeTx(tx.txId)
108
- if (isExchangeTx) return BumpType.NONE
118
+ if (isExchangeTx) return wrapResponseToObject({ errorMessage: 'can not bump an exchange TX' })
109
119
  const personalNote = getPersonalNoteByTxId(tx.txId)
110
- if (personalNote && personalNote.dapp) return BumpType.NONE
111
- if (isQueuedPendingTx(tx, activeWalletAccount, getTxLog)) return BumpType.NONE
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' })
112
124
 
113
125
  const { gasPrice: currentGasPrice } = getFeeData(assetName)
114
126
  const gasPriceToUse = calculateBumpedGasPrice(tx, currentGasPrice)
@@ -117,8 +129,8 @@ export default (
117
129
  if (
118
130
  !getIsEnoughBalanceToAccelerate(activeWalletAccount, asset.baseAsset.name, extraEthNeeded)
119
131
  )
120
- return BumpType.NONE
132
+ return wrapResponseToObject({ errorMessage: 'insufficient funds' })
121
133
 
122
- return BumpType.RBF
134
+ return wrapResponseToObject({ bumpType: BumpType.RBF })
123
135
  }
124
136
  )