@exodus/ethereum-lib 2.13.1 → 2.13.3

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.13.1",
3
+ "version": "2.13.3",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -10,7 +10,7 @@
10
10
  "access": "restricted"
11
11
  },
12
12
  "dependencies": {
13
- "@exodus/asset-lib": "^3.4.0",
13
+ "@exodus/asset-lib": "^3.5.4",
14
14
  "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
15
15
  "@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
16
16
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
@@ -24,5 +24,5 @@
24
24
  "peerDependencies": {
25
25
  "@exodus/assets": "8.0.x"
26
26
  },
27
- "gitHead": "0266f50330e737c4cce09987e490a103f6cbfa8c"
27
+ "gitHead": "163192db3e616071238360a14577e6a5c570a51e"
28
28
  }
package/src/constants.js CHANGED
@@ -5,6 +5,7 @@ export const CHAIN_IDS = {
5
5
  matic: 137,
6
6
  avalanchec: 43114,
7
7
  fantommainnet: 250,
8
+ harmonymainnet: 1666600000,
8
9
  }
9
10
  export const MIN_GASPRICE = 1e9 // 1 gwei
10
11
  export const DEFAULT_FEE_MONITOR_INTERVAL = '1m'
@@ -15,6 +16,7 @@ export const CONFIRMATIONS_NUMBER = {
15
16
  matic: 355,
16
17
  avalanchec: 30,
17
18
  fantommainnet: 3,
19
+ harmonymainnet: 6,
18
20
  }
19
21
  export const ETHEREUM_LIKE_ASSETS = [
20
22
  'bsc',
@@ -23,6 +25,7 @@ export const ETHEREUM_LIKE_ASSETS = [
23
25
  'matic',
24
26
  'avalanchec',
25
27
  'fantommainnet',
28
+ 'harmonymainnet',
26
29
  ]
27
30
  export const ETHEREUM_LIKE_TOKEN_TYPES = [
28
31
  'ETHEREUM_ERC20',
@@ -0,0 +1,14 @@
1
+ import { FeeData } from '@exodus/asset-lib'
2
+
3
+ export default new FeeData(
4
+ {
5
+ gasPrice: '10 Gwei',
6
+ max: '700 Gwei',
7
+ min: '30 Gwei',
8
+ fuelThreshold: '2500000 Gwei',
9
+ gasPriceEconomicalRate: 0.8,
10
+ gasPriceMinimumRate: 0.6,
11
+ },
12
+ 'gasPrice',
13
+ 'harmonymainnet'
14
+ )
@@ -4,3 +4,4 @@ export { default as bsc } from './bsc'
4
4
  export { default as matic } from './polygon'
5
5
  export { default as avalanchec } from './avalanchec'
6
6
  export { default as fantommainnet } from './fantom'
7
+ export { default as harmonymainnet } from './harmony'
@@ -1,14 +1,10 @@
1
1
  // A super-selector that returns all the current data needed for a tick of the ETH monitor.
2
2
 
3
- export default function getDeriveDataNeededForTick({
4
- getAccountState,
5
- getConfirmationsNumber,
6
- getReceiveAddress,
7
- }) {
3
+ export default function getDeriveDataNeededForTick(aci) {
8
4
  return async function({ assetName, walletAccount }) {
9
- const receiveAddress = await getReceiveAddress({ assetName, walletAccount })
10
- const currentAccountState = await getAccountState({ assetName, walletAccount })
11
- const minimumConfirmations = await getConfirmationsNumber({ assetName })
5
+ const receiveAddress = await aci.getReceiveAddress({ assetName, walletAccount })
6
+ const currentAccountState = await aci.getAccountState({ assetName, walletAccount })
7
+ const minimumConfirmations = await aci.getConfirmationsNumber({ assetName })
12
8
  return {
13
9
  ourWalletAddress: receiveAddress.toLowerCase(),
14
10
  currentAccountState,
@@ -3,7 +3,7 @@ import getSenderNonceKey from './get-sender-nonce-key'
3
3
 
4
4
  const UNCONFIRMED_TX_LIMIT = ms('5m')
5
5
 
6
- export default function getDeriveTransactionsToCheck({ getTxHistory }) {
6
+ export default function getDeriveTransactionsToCheck({ getTxLog }) {
7
7
  return async ({ assetName: _assetName, walletAccount, tokens, ourWalletAddress }) => {
8
8
  const pendingTransactionsToCheck = {}
9
9
  const pendingTransactionsGroupedByAddressAndNonce = {}
@@ -11,7 +11,7 @@ export default function getDeriveTransactionsToCheck({ getTxHistory }) {
11
11
  const now = Date.now()
12
12
 
13
13
  for (const assetName of [_assetName, ...tokens.map(({ name }) => name)]) {
14
- const txSet = await getTxHistory({ assetName, walletAccount })
14
+ const txSet = await getTxLog({ assetName, walletAccount })
15
15
  for (const tx of txSet) {
16
16
  // ERC20 sends have an entry in ETH and one in the ERC20 log so we just want the ETH one
17
17
  if (
@@ -1,5 +1,6 @@
1
1
  import lodash from 'lodash'
2
2
  import getValueOfTransfers from './get-value-of-transfers'
3
+ import { FEE_PAYMENT_PREFIX } from '../utils'
3
4
 
4
5
  // For ETH transactions, we store an array of token names inside
5
6
  // the TX model. This array is used to display text in the UI for
@@ -12,7 +13,6 @@ export default function getNamesOfTokensTransferredByServerTx({
12
13
  tokensByAddress,
13
14
  ourWalletAddress,
14
15
  serverTx,
15
- FEE_PAYMENT_PREFIX,
16
16
  }) {
17
17
  // Treat smart contract ETH transfer transactions as ETH transfers, not token transfers
18
18
  if (!getValueOfTransfers(ourWalletAddress, asset, serverTx.internal || []).isZero) {
@@ -3,8 +3,8 @@ export { default as getAllLogItemsByAsset } from './get-all-log-items-by-asset'
3
3
  export { default as isConfirmedServerTx } from './is-confirmed-server-tx'
4
4
  export { default as isConsideredSentTokenTx } from './is-considered-sent-token-tx'
5
5
  export { default as getHistoryFromServer } from './get-history-from-server'
6
+ export { default as getLogItemsFromServerTx } from './get-log-items-from-server-tx'
6
7
  export { default as checkPendingTransactions } from './check-pending-transactions'
7
8
  export { default as getDeriveTransactionsToCheck } from './get-derive-transactions-to-check'
8
- export { subscribeToWSNotifications, enableWSUpdates } from './ws-updates'
9
9
 
10
10
  export type { PendingTransactionsDictionary } from './types'
@@ -3,6 +3,7 @@ import * as ethUtil from '@exodus/ethereumjs-util'
3
3
  import assets from '@exodus/assets'
4
4
  import { ETHEREUM_LIKE_ASSETS, ETHEREUM_LIKE_TOKEN_TYPES } from '../constants'
5
5
  import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs-tx'
6
+ import { uniq } from 'lodash'
6
7
 
7
8
  export { default as calculateExtraEth } from './calculate-extra-eth'
8
9
 
@@ -70,3 +71,25 @@ export function deserialize(hex) {
70
71
 
71
72
  const getTxType = (serializedTx: string) => serializedTx.slice(2, 4)
72
73
  export const isEip1559Tx = (serializedTx: string) => getTxType(serializedTx) === '02'
74
+
75
+ export const APPROVE_METHOD_ID = '0x095ea7b3'
76
+
77
+ export const FEE_PAYMENT_PREFIX = '0xfee0'
78
+
79
+ export const isApproveTx = (tx) => tx?.data?.data?.startsWith(APPROVE_METHOD_ID)
80
+
81
+ export const isFeePaymentTx = (tx) => tx?.data?.data?.startsWith(FEE_PAYMENT_PREFIX)
82
+
83
+ export const isRpcBalanceAsset = (asset) => ['bsc', 'matic', 'babydoge_bsc'].includes(asset.name)
84
+
85
+ export const getAssetAddresses = (asset) => {
86
+ // It seems to be two schemas of assets. The original and the transformed by the client.
87
+ // Can we unify?
88
+ const addresses = [
89
+ asset.contract?.address, // asset in wallets:
90
+ asset.contract?.current, // asset in @exodus/assets:
91
+ ...(asset.addresses?.previous || []), // asset in wallets:
92
+ ...(asset.contract?.previous || []), // asset in @exodus/assets:
93
+ ]
94
+ return uniq(addresses.filter((a) => a && typeof a === 'string'))
95
+ }
@@ -1,59 +0,0 @@
1
- import ms from 'ms'
2
-
3
- const subscribedToAddressNotificationsMap = new Map()
4
- const UPDATE_LOOP_INTERVAL = ms('5m')
5
-
6
- export function subscribeToWSNotifications({
7
- addressesByWalletAccount,
8
- tick,
9
- getState,
10
- server,
11
- beforeStart = false,
12
- }) {
13
- Object.entries(addressesByWalletAccount).forEach(([walletAccount, addresses]) => {
14
- const address = String(Array.from(addresses)[0]).toLowerCase() // Only check m/0/0
15
- const mapKey = `${server.getURL()}:${address}` // different chains might have the same addresses
16
- if (subscribedToAddressNotificationsMap.has(mapKey)) return
17
-
18
- server.ws.watch(address)
19
- server.ws.events.on(`address-${address}`, () => {
20
- tick({ refresh: false, getState, walletAccount })
21
- })
22
- subscribedToAddressNotificationsMap.set(mapKey, true)
23
- if (!beforeStart) {
24
- // tick for a new wallet account
25
- tick({ refresh: false, getState, walletAccount })
26
- }
27
- })
28
- }
29
-
30
- export function enableWSUpdates({
31
- interval,
32
- server,
33
- timer,
34
- dispatch,
35
- getState,
36
- tickAllWalletAccounts,
37
- tick,
38
- addressesByWalletAccount,
39
- beforeStart = false,
40
- }) {
41
- const defaultInterval = interval
42
-
43
- subscribeToWSNotifications({
44
- server,
45
- getState,
46
- beforeStart,
47
- tick,
48
- addressesByWalletAccount,
49
- })
50
-
51
- server.ws.events.on('open', () => {
52
- timer.setNewInterval(UPDATE_LOOP_INTERVAL)
53
- })
54
- server.ws.events.on('close', async () => {
55
- await timer.setNewInterval(defaultInterval)
56
- return tickAllWalletAccounts({ dispatch, getState })
57
- })
58
- server.ws.open()
59
- }