@exodus/ethereum-lib 2.2.0 → 2.3.1

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.1",
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": "92d4717b906fd92d37c90d8ba41f3c314cd65534"
29
29
  }
package/src/constants.js CHANGED
@@ -1,7 +1,8 @@
1
- export const CHAIN_IDS = { ethereum: 1, ethereumclassic: 61 }
1
+ export const CHAIN_IDS = { ethereum: 1, ethereumclassic: 61, quorum: 10 }
2
2
  export const MIN_GASPRICE = 1e9 // 1 gwei
3
3
  export const DEFAULT_FEE_MONITOR_INTERVAL = '1m'
4
4
  export const CONFIRMATIONS_NUMBER = {
5
5
  ethereum: 30,
6
6
  ethereumclassic: 5000,
7
+ quorum: 4,
7
8
  }
@@ -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'
@@ -1,2 +1,3 @@
1
1
  export { default as ethereum } from './ethereum'
2
2
  export { default as ethereumclassic } from './ethereumclassic'
3
+ export { default as quorum } from './quorum'
@@ -0,0 +1,11 @@
1
+ import { FeeData } from '@exodus/asset-lib'
2
+
3
+ export default new FeeData(
4
+ {
5
+ gasPrice: '0 Gwei',
6
+ max: '0 Gwei',
7
+ min: '0 Gwei',
8
+ },
9
+ 'gasPrice',
10
+ 'quorum'
11
+ )
@@ -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
  )
@@ -1,5 +1,5 @@
1
1
  import ethUtil from 'ethereumjs-util'
2
- import { isEthereumToken, currency2buffer, getBaseAsset } from '../utils'
2
+ import { isEthereumToken, isQuorumToken, currency2buffer, getBaseAsset } from '../utils'
3
3
  import { CHAIN_IDS } from '../constants'
4
4
 
5
5
  import type { UnsignedTransaction } from '#/app-models'
@@ -25,7 +25,7 @@ export default function createUnsignedTx({
25
25
  const baseAsset = getBaseAsset(asset)
26
26
  if (!chainId) chainId = CHAIN_IDS[baseAsset.name] // mainnet
27
27
 
28
- const isToken = isEthereumToken(asset)
28
+ const isToken = isEthereumToken(asset) || isQuorumToken(asset)
29
29
  const to = isToken ? asset.contract.address : address
30
30
  let value = currency2buffer(isToken ? baseAsset.currency.ZERO : amount)
31
31
 
@@ -1,6 +1,6 @@
1
1
  /* @flow */
2
2
  import * as ethUtil from 'ethereumjs-util'
3
- import { isEthereumToken, buffer2currency, getBaseAsset } from '../utils'
3
+ import { isEthereumToken, isQuorumToken, buffer2currency, getBaseAsset } from '../utils'
4
4
  import { CHAIN_IDS } from '../constants'
5
5
 
6
6
  import type { UnsignedTransaction, ParsedTransaction } from '@exodus/models/lib/types'
@@ -10,7 +10,7 @@ export default function parseUnsignedTx(
10
10
  unsignedTx: UnsignedTransaction
11
11
  ): ParsedTransaction {
12
12
  const { txData } = unsignedTx
13
- const isToken = isEthereumToken(asset)
13
+ const isToken = isEthereumToken(asset) || isQuorumToken(asset)
14
14
  const baseAsset = getBaseAsset(asset)
15
15
  const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
16
16
  const gasLimit = ethUtil.bufferToInt(txData.gasLimit)
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 isQuorumToken = (asset) => asset.assetType === 'QUORUM_ERC20'
9
10
 
10
11
  export function buffer2currency({ asset, value }) {
11
12
  return asset.currency.baseUnit(base10.encode(value)).toDefault()
@@ -34,5 +35,5 @@ export function normalizeTxId(txId: string): string {
34
35
  }
35
36
 
36
37
  export function getBaseAsset(asset) {
37
- return isEthereumToken(asset) ? assets.ethereum : asset
38
+ return isEthereumToken(asset) ? assets.ethereum : isQuorumToken(asset) ? assets.quorum : asset
38
39
  }