@exodus/ethereum-api 2.22.1 → 2.24.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-api",
3
- "version": "2.22.1",
3
+ "version": "2.24.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -9,18 +9,19 @@
9
9
  ],
10
10
  "author": "Exodus Movement, Inc.",
11
11
  "license": "UNLICENSED",
12
- "homepage": "https://github.com/ExodusMovement/ethereum#readme",
12
+ "homepage": "https://github.com/ExodusMovement/assets/tree/main/ethereum",
13
13
  "publishConfig": {
14
14
  "access": "restricted"
15
15
  },
16
16
  "dependencies": {
17
17
  "@exodus/asset-lib": "^3.5.4",
18
18
  "@exodus/crypto": "^1.0.0-rc.0",
19
- "@exodus/ethereum-lib": "^2.20.0",
19
+ "@exodus/ethereum-lib": "^2.21.0",
20
20
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
21
+ "@exodus/fetch": "^1.2.1",
21
22
  "@exodus/simple-retry": "^0.0.6",
22
23
  "@exodus/solidity-contract": "^1.0.1",
23
- "fetchival": "0.3.3",
24
+ "events": "^1.1.1",
24
25
  "idna-uts46-hx": "^2.3.1",
25
26
  "js-sha3": "^0.8.0",
26
27
  "make-concurrent": "4.0.0",
@@ -35,5 +36,5 @@
35
36
  "@exodus/assets-base": "^8.0.136",
36
37
  "@exodus/models": "^8.7.2"
37
38
  },
38
- "gitHead": "6a99fbefed718767bf3f8a81f18881084ffbdb6c"
39
+ "gitHead": "43d1c84ed5ecc17a3970113097ec9ad6d58e4312"
39
40
  }
@@ -4,8 +4,6 @@ import { memoizeLruCache } from '@exodus/asset-lib'
4
4
  import assets from '@exodus/assets'
5
5
  import SolidityContract from '@exodus/solidity-contract'
6
6
 
7
- // Mobile only.
8
- // We should refactor mobile to pass 'asset' instead of 'assetName' so that we can use 'isContractAddress'. But that would touch many assets.
9
7
  export async function isContract(baseAssetName, address) {
10
8
  return getServerByName(baseAssetName).isContract(address)
11
9
  }
@@ -1,9 +1,6 @@
1
1
  import ms from 'ms'
2
2
  import makeConcurrent from 'make-concurrent'
3
- import fetchival from 'fetchival'
4
- // The module in desktop explicitly sets node-fetch. Do we need this?
5
- // import fetch from '../fetch'
6
- // fetchival.fetch = fetch
3
+ import { fetchival } from '@exodus/fetch'
7
4
 
8
5
  const ETHERSCAN_API_URL = 'https://api.etherscan.io/api'
9
6
  const DEFAULT_ETHERSCAN_API_KEY = 'XM3VGRSNW1TMSIR14I9MVFP15X74GNHTRI'
@@ -1,4 +1,4 @@
1
- import { EventEmitter } from 'events'
1
+ import EventEmitter from 'events/' // '/' forces it to use the module from node_modules
2
2
  import ms from 'ms'
3
3
  import WebSocket from '../websocket'
4
4
 
@@ -1,8 +1,8 @@
1
1
  import urlJoin from 'url-join'
2
2
  import url from 'url'
3
- import fetchival from 'fetchival'
4
3
  import ms from 'ms'
5
4
  import createWebSocket from './ws'
5
+ import { fetchival } from '@exodus/fetch'
6
6
  import { retry } from '@exodus/simple-retry'
7
7
  import SolidityContract from '@exodus/solidity-contract'
8
8
  import { bufferToHex } from '@exodus/ethereumjs-util'
@@ -1,5 +1,5 @@
1
1
  import ms from 'ms'
2
- import { EventEmitter } from 'events'
2
+ import EventEmitter from 'events/' // '/' forces it to use the module from node_modules
3
3
  import WebSocket from '../websocket'
4
4
 
5
5
  const RECONNECT_INTERVAL = ms('10s')
@@ -1,4 +1,6 @@
1
1
  import assets from '@exodus/assets'
2
+ import { APPROVE_METHOD_ID } from '@exodus/ethereum-lib'
3
+ import SolidityContract from '@exodus/solidity-contract'
2
4
 
3
5
  import { fetchTxPreview } from './fetch-tx-preview'
4
6
  import { getERC20Params } from '../eth-like-util'
@@ -67,10 +69,35 @@ async function prepareBalanceChanges(internalTransactions, balanceChanges) {
67
69
  return preparedBalanceChanges
68
70
  }
69
71
 
72
+ async function tryToDecodeApprovalTransaction(transaction) {
73
+ if (!transaction?.data.startsWith(APPROVE_METHOD_ID)) return null
74
+
75
+ const contract = SolidityContract.erc20(transaction.to)
76
+ try {
77
+ const decodedInput = contract.decodeInput(transaction.data)
78
+ if (!decodedInput.values) return null
79
+
80
+ const [grantedTo, balance] = decodedInput.values
81
+
82
+ const symbol = (await getAssetSymbolFromContract(transaction.to)).toUpperCase() || 'Token'
83
+
84
+ return [{ grantedTo, balance, symbol, decimals: undefined }] // ToDo: Return 'decimals' in the future once we support changing the approval amount.
85
+ } catch (e) {
86
+ console.error(e.message)
87
+
88
+ return null
89
+ }
90
+ }
91
+
70
92
  export async function simulateAndRetrieveSideEffects(transaction) {
71
93
  const willSend = []
72
94
  const willReceive = []
73
95
 
96
+ const approveTransactionData = await tryToDecodeApprovalTransaction(transaction)
97
+ if (approveTransactionData) {
98
+ return { willApprove: approveTransactionData }
99
+ }
100
+
74
101
  if (!transaction.to) throw new Error(`'to' field is missing in the TX object`)
75
102
 
76
103
  const blocknativeTxObject = {
@@ -4,13 +4,13 @@
4
4
  *
5
5
  * Based on https://github.com/ExodusMovement/fetch/blob/master/core.js , note that chooses native on Desktop
6
6
  */
7
- if (
8
- typeof process !== 'undefined' &&
9
- process &&
10
- (process.type === 'renderer' || process.type === 'worker')
11
- ) {
7
+ if (typeof process !== 'undefined' && (process.type === 'renderer' || process.type === 'worker')) {
12
8
  // THIS IS FOR DESKTOP
13
- module.exports = require('ws')
9
+ if (process.env.EXODUS_DISABLE_WS) {
10
+ module.exports = globalThis.WebSocket
11
+ } else {
12
+ module.exports = require('ws')
13
+ }
14
14
  } else {
15
15
  // eslint-disable-next-line no-undef
16
16
  if (global.window?.WebSocket) {