@exodus/ethereum-lib 2.19.2 → 2.19.4

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,8 +1,12 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "2.19.2",
3
+ "version": "2.19.4",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
+ "files": [
7
+ "src",
8
+ "!src/**/__tests__"
9
+ ],
6
10
  "author": "Exodus Movement, Inc.",
7
11
  "license": "UNLICENSED",
8
12
  "homepage": "https://github.com/ExodusMovement/ethereum#readme",
@@ -24,5 +28,5 @@
24
28
  "peerDependencies": {
25
29
  "@exodus/assets": "8.0.x"
26
30
  },
27
- "gitHead": "c04eff51885ea6e09d5d2a6c7a3c8c89a2eb2416"
31
+ "gitHead": "f5f2bd5dcde6504d06ba68f01385d8215c82d224"
28
32
  }
package/src/constants.js CHANGED
@@ -1,3 +1,13 @@
1
+ export const DEFAULT_SERVER_URLS = {
2
+ ethereum: 'https://geth.a.exodus.io/wallet/v1/',
3
+ ethereumclassic: 'https://getc.a.exodus.io/wallet/v1/',
4
+ bsc: 'https://bsc.a.exodus.io/wallet/v1/',
5
+ matic: 'https://polygon.a.exodus.io/wallet/v1/',
6
+ avalanchec: 'https://avax-c.a.exodus.io/wallet/v1/',
7
+ fantommainnet: 'https://fantom.a.exodus.io/wallet/v1/',
8
+ harmonymainnet: 'https://harmony.a.exodus.io/wallet/v1/',
9
+ }
10
+
1
11
  export const CHAIN_IDS = {
2
12
  ethereum: 1,
3
13
  ethereumclassic: 61,
@@ -12,10 +12,7 @@ export default function getAllLogItemsByAsset({
12
12
  assets,
13
13
  }) {
14
14
  const allAssets = [asset, ...tokensByAddress.values()]
15
- const logItemsByAsset = allAssets.reduce((allItems, asset) => {
16
- allItems[asset.name] = []
17
- return allItems
18
- }, {})
15
+ const logItemsByAsset = Object.fromEntries(allAssets.map((asset) => [asset.name, []]))
19
16
 
20
17
  allTransactionsFromServer.forEach((serverTx) => {
21
18
  const logItemsByAssetForServerTx = getLogItemsFromServerTx({
@@ -3,11 +3,13 @@ import getSenderNonceKey from './get-sender-nonce-key'
3
3
 
4
4
  const UNCONFIRMED_TX_LIMIT = ms('5m')
5
5
 
6
+ const mapToObject = (map) => Object.fromEntries([...map.entries()]) // only for string keys
7
+
6
8
  export default function getDeriveTransactionsToCheck({ getTxLog }) {
7
9
  return async ({ assetName: _assetName, walletAccount, tokens, ourWalletAddress }) => {
8
- const pendingTransactionsToCheck = {}
9
- const pendingTransactionsGroupedByAddressAndNonce = {}
10
- const simulatedTransactions = {}
10
+ const pendingTransactionsToCheck = new Map()
11
+ const pendingTransactionsGroupedByAddressAndNonce = new Map()
12
+ const simulatedTransactions = new Map()
11
13
  const now = Date.now()
12
14
 
13
15
  for (const assetName of [_assetName, ...tokens.map(({ name }) => name)]) {
@@ -15,33 +17,35 @@ export default function getDeriveTransactionsToCheck({ getTxLog }) {
15
17
  for (const tx of txSet) {
16
18
  // ERC20 sends have an entry in ETH and one in the ERC20 log so we just want the ETH one
17
19
  if (
18
- !pendingTransactionsToCheck[tx.txId] &&
20
+ !pendingTransactionsToCheck.has(tx.txId) &&
19
21
  tx.pending &&
20
22
  now - tx.date.getTime() > UNCONFIRMED_TX_LIMIT
21
23
  ) {
22
- pendingTransactionsToCheck[tx.txId] = { tx, assetName }
24
+ pendingTransactionsToCheck.set(tx.txId, { tx, assetName })
23
25
  }
24
- if (tx.meta.simulated) simulatedTransactions[tx.txId] = tx
26
+ if (tx.meta.simulated) simulatedTransactions.set(tx.txId, tx)
25
27
 
26
28
  const senderNonceKey = getSenderNonceKey(tx, ourWalletAddress)
27
29
  if (
28
30
  tx.pending &&
29
- !pendingTransactionsGroupedByAddressAndNonce[senderNonceKey] &&
31
+ !pendingTransactionsGroupedByAddressAndNonce.has(senderNonceKey) &&
30
32
  !tx.dropped
31
33
  ) {
32
- pendingTransactionsGroupedByAddressAndNonce[senderNonceKey] = {
34
+ pendingTransactionsGroupedByAddressAndNonce.set(senderNonceKey, {
33
35
  tx,
34
36
  replaced: false,
35
37
  assetName,
36
- }
38
+ })
37
39
  }
38
40
  }
39
41
  }
40
42
 
41
43
  return {
42
- pendingTransactionsToCheck,
43
- pendingTransactionsGroupedByAddressAndNonce,
44
- simulatedTransactions,
44
+ pendingTransactionsToCheck: mapToObject(pendingTransactionsToCheck),
45
+ pendingTransactionsGroupedByAddressAndNonce: mapToObject(
46
+ pendingTransactionsGroupedByAddressAndNonce
47
+ ),
48
+ simulatedTransactions: mapToObject(simulatedTransactions),
45
49
  }
46
50
  }
47
51
  }
@@ -37,7 +37,7 @@ export default function getLogItemsFromServerTx({
37
37
  dropped: false,
38
38
  }
39
39
 
40
- const logItemsForServerTx = {}
40
+ const logItemsForServerTxEntries = []
41
41
 
42
42
  {
43
43
  const sendingTransferPresent = ethereumTransfers.some(({ from }) => from === ourWalletAddress)
@@ -51,28 +51,30 @@ export default function getLogItemsFromServerTx({
51
51
  sendingTransferPresent,
52
52
  receivingTransferPresent,
53
53
  })
54
- logItemsForServerTx[asset.name] = {
55
- ...logItemCommonProperties,
56
- coinAmount,
57
- coinName: asset.name,
58
- data: {
59
- data: serverTx.data || '0x',
60
- nonce,
61
- gasLimit,
54
+ logItemsForServerTxEntries.push([
55
+ asset.name,
56
+ {
57
+ ...logItemCommonProperties,
58
+ coinAmount,
59
+ coinName: asset.name,
60
+ data: {
61
+ data: serverTx.data || '0x',
62
+ nonce,
63
+ gasLimit,
64
+ },
65
+ from: ourWalletWasSender ? [] : [serverTx.from],
66
+ to: ourWalletWasSender ? toAddress : undefined,
67
+ selfSend,
68
+ tokens: getNamesOfTokensTransferredByServerTx({
69
+ asset,
70
+ tokensByAddress,
71
+ serverTx,
72
+ ourWalletAddress,
73
+ }),
62
74
  },
63
- from: ourWalletWasSender ? [] : [serverTx.from],
64
- to: ourWalletWasSender ? toAddress : undefined,
65
- selfSend,
66
- tokens: getNamesOfTokensTransferredByServerTx({
67
- asset,
68
- tokensByAddress,
69
- serverTx,
70
- ourWalletAddress,
71
- }),
72
- }
75
+ ])
73
76
  }
74
77
  }
75
-
76
78
  // handle erc20
77
79
  Object.entries(tokenTransfersByTokenName).forEach(([tokenName, tokenTransfers]) => {
78
80
  const sendingTransferPresent = tokenTransfers.some(({ from }) => from === ourWalletAddress)
@@ -103,18 +105,21 @@ export default function getLogItemsFromServerTx({
103
105
  receivingTransferPresent,
104
106
  })
105
107
 
106
- logItemsForServerTx[tokenName] = {
107
- ...logItemCommonProperties,
108
- coinAmount,
109
- coinName: tokenName,
110
- data: { nonce, gasLimit },
111
- from: isConsideredSent ? [] : tokenFromAddresses,
112
- to: isConsideredSent ? tokenTransferToAddress : undefined,
113
- selfSend,
114
- }
108
+ logItemsForServerTxEntries.push([
109
+ tokenName,
110
+ {
111
+ ...logItemCommonProperties,
112
+ coinAmount,
113
+ coinName: tokenName,
114
+ data: { nonce, gasLimit },
115
+ from: isConsideredSent ? [] : tokenFromAddresses,
116
+ to: isConsideredSent ? tokenTransferToAddress : undefined,
117
+ selfSend,
118
+ },
119
+ ])
115
120
  })
116
121
 
117
- return logItemsForServerTx
122
+ return Object.fromEntries(logItemsForServerTxEntries)
118
123
  }
119
124
 
120
125
  const tryFindExternalRecipient = (transfers, ourWalletAddress) =>