@exodus/ethereum-api 5.1.0 → 6.0.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-api",
3
- "version": "5.1.0",
3
+ "version": "6.0.1",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@exodus/asset-lib": "^3.7.1",
18
18
  "@exodus/crypto": "^1.0.0-rc.0",
19
- "@exodus/ethereum-lib": "^2.26.9",
19
+ "@exodus/ethereum-lib": "^3.0.0",
20
20
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
21
21
  "@exodus/fetch": "^1.2.1",
22
22
  "@exodus/simple-retry": "^0.0.6",
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "@exodus/models": "^8.10.4"
38
38
  },
39
- "gitHead": "6c1abd66e1224acbb391007b9ab261e5c09376e7"
39
+ "gitHead": "35b8c8c3a9aa2be1287d83d553ede11f174cfe0e"
40
40
  }
@@ -1,8 +1,8 @@
1
+ import assert from 'minimalistic-assert'
1
2
  import { normalizeTxId, isEthereumLikeAsset, isEthereumLikeToken, ABI } from '@exodus/ethereum-lib'
2
- import { getServerByName, getServer } from './exodus-eth-server'
3
3
  import { memoizeLruCache } from '@exodus/asset-lib'
4
- import assets from '@exodus/assets'
5
4
  import SolidityContract from '@exodus/solidity-contract'
5
+ import { getServerByName, getServer } from './exodus-eth-server'
6
6
 
7
7
  export async function isContract(baseAssetName, address) {
8
8
  return getServerByName(baseAssetName).isContract(address)
@@ -86,18 +86,9 @@ const ERC20BytesParams = new SolidityContract(ABI.erc20BytesParams)
86
86
  const DEFAULT_PARAM_NAMES = ['decimals', 'name', 'symbol']
87
87
  const erc20ParamsCache = {}
88
88
 
89
- export const getERC20Params = async ({
90
- assetName,
91
- address,
92
- paramNames = DEFAULT_PARAM_NAMES,
93
- } = {}) => {
94
- const asset = assets[assetName]
95
- if (!asset) {
96
- throw new Error(`${assetName} not found`)
97
- }
98
- if (!address) {
99
- throw new Error(`Token address should be provided, got: ${address}`)
100
- }
89
+ export const getERC20Params = async ({ asset, address, paramNames = DEFAULT_PARAM_NAMES } = {}) => {
90
+ assert(asset, 'getERC20Params(): asset required')
91
+ assert(address, 'getERC20Params(): address required')
101
92
 
102
93
  const cacheKey = `${address}:${paramNames}`
103
94
  if (erc20ParamsCache[cacheKey]) {
@@ -107,7 +107,8 @@ export default class ClarityServer extends EventEmitter {
107
107
  const timeout = setTimeout(() => reject(new Error('Transactions Timeout')), 300000)
108
108
  socket.emit('getTransactions', cursor, (nextCursor) => {
109
109
  clearTimeout(timeout)
110
- resolve(Buffer.from(nextCursor))
110
+ const uintArray = new Uint8Array(nextCursor)
111
+ resolve(Buffer.from(uintArray))
111
112
  })
112
113
  })
113
114
  .catch((error) => console.error(error))
@@ -1,4 +1,5 @@
1
- import assets from '@exodus/assets'
1
+ import assert from 'minimalistic-assert'
2
+ import { asset as ethereum } from '@exodus/ethereum-meta'
2
3
  import {
3
4
  checkIsERC721InputData,
4
5
  checkIsNFTInputData,
@@ -9,14 +10,14 @@ import SolidityContract from '@exodus/solidity-contract'
9
10
  import { fetchTxPreview } from './fetch-tx-preview'
10
11
  import { getERC20Params } from '../eth-like-util'
11
12
 
12
- const ethDecimals = assets.ethereum.units.ETH
13
+ const ethDecimals = ethereum.units.ETH
13
14
 
14
15
  const ethHexToInt = (hexValue) => parseInt(hexValue, '16')
15
16
 
16
- async function getAssetSymbolFromContract(contractAddress) {
17
+ async function getAssetSymbolFromContract(contractAddress, asset) {
17
18
  const { symbol: assetSymbol } = await getERC20Params({
18
19
  address: contractAddress,
19
- assetName: 'ethereum',
20
+ asset,
20
21
  paramNames: ['symbol'],
21
22
  })
22
23
 
@@ -53,12 +54,11 @@ async function prepareBalanceChanges(
53
54
  internalTransactions,
54
55
  balanceChanges,
55
56
  transactionInput,
56
- assetName = 'ethereum'
57
+ asset
57
58
  ) {
58
59
  const assetNameToSymbolMap = Object.create(null)
59
60
  assetNameToSymbolMap['ethereum'] = 'ETH' // Refactor after blowfish integration
60
61
 
61
- const asset = assets[assetName]
62
62
  const preparedBalanceChanges = [...balanceChanges]
63
63
 
64
64
  const decimals = Object.create(null)
@@ -85,7 +85,7 @@ async function prepareBalanceChanges(
85
85
  if (isERC20) {
86
86
  const assetSymbol =
87
87
  contractCall.contractAlias ||
88
- (await getAssetSymbolFromContract(contractCall.contractAddress))
88
+ (await getAssetSymbolFromContract(contractCall.contractAddress, asset))
89
89
 
90
90
  assetSymbols[contractCall.contractAddress] = assetSymbol
91
91
  decimals[assetSymbol] = contractCall.contractDecimals
@@ -98,40 +98,40 @@ async function prepareBalanceChanges(
98
98
  }
99
99
 
100
100
  for (const balanceChange of preparedBalanceChanges) {
101
- const { asset } = balanceChange
101
+ const { asset: assetData } = balanceChange
102
102
 
103
- if (!asset.symbol) {
104
- asset.symbol =
105
- assetSymbols[asset.contractAddress] ||
106
- (await getAssetSymbolFromContract(asset.contractAddress))
103
+ if (!assetData.symbol) {
104
+ assetData.symbol =
105
+ assetSymbols[assetData.contractAddress] ||
106
+ (await getAssetSymbolFromContract(assetData.contractAddress, asset))
107
107
  }
108
108
 
109
109
  if (isERC721) {
110
- asset.type = 'erc721'
111
- asset.title = contractName
110
+ assetData.type = 'erc721'
111
+ assetData.title = contractName
112
112
  continue
113
113
  }
114
114
 
115
- if (typeof decimals[asset.symbol] === 'number') {
116
- asset.decimal = decimals[asset.symbol]
115
+ if (typeof decimals[assetData.symbol] === 'number') {
116
+ assetData.decimal = decimals[assetData.symbol]
117
117
  continue
118
118
  }
119
119
 
120
- if (isERC20 && asset.contractAddress) {
120
+ if (isERC20 && assetData.contractAddress) {
121
121
  const { decimals: assetDecimal } = await getERC20Params({
122
- address: asset.contractAddress,
123
- assetName: 'ethereum',
122
+ address: assetData.contractAddress,
123
+ asset,
124
124
  paramNames: ['decimals'],
125
125
  })
126
126
 
127
- asset.decimal = assetDecimal
127
+ assetData.decimal = assetDecimal
128
128
  }
129
129
  }
130
130
 
131
131
  return maybeRemoveDuplicates(preparedBalanceChanges)
132
132
  }
133
133
 
134
- async function tryToDecodeApprovalTransaction(transaction) {
134
+ async function tryToDecodeApprovalTransaction(transaction, asset) {
135
135
  if (!transaction?.data.startsWith(APPROVE_METHOD_ID)) return null
136
136
 
137
137
  const contract = SolidityContract.erc20(transaction.to)
@@ -142,7 +142,7 @@ async function tryToDecodeApprovalTransaction(transaction) {
142
142
  const [grantedTo, balance] = decodedInput.values
143
143
 
144
144
  const symbol =
145
- (await getAssetSymbolFromContract(transaction.to))?.toUpperCase() || 'Unknown Token'
145
+ (await getAssetSymbolFromContract(transaction.to, asset))?.toUpperCase() || 'Unknown Token'
146
146
 
147
147
  return [{ grantedTo, balance, symbol, decimals: undefined }] // ToDo: Return 'decimals' in the future once we support changing the approval amount.
148
148
  } catch (e) {
@@ -152,11 +152,13 @@ async function tryToDecodeApprovalTransaction(transaction) {
152
152
  }
153
153
  }
154
154
 
155
- export async function retrieveSideEffects({ transaction, assetName, shouldSimulate = true }) {
155
+ export async function retrieveSideEffects({ transaction, asset, shouldSimulate = true }) {
156
+ assert(asset, 'retrieveSideEffects(): asset is required')
157
+
156
158
  const willSend = []
157
159
  const willReceive = []
158
160
 
159
- const approveTransactionData = await tryToDecodeApprovalTransaction(transaction)
161
+ const approveTransactionData = await tryToDecodeApprovalTransaction(transaction, asset)
160
162
  if (approveTransactionData) {
161
163
  return { willApprove: approveTransactionData }
162
164
  }
@@ -192,25 +194,25 @@ export async function retrieveSideEffects({ transaction, assetName, shouldSimula
192
194
  internalTransactions,
193
195
  sender.balanceChanges,
194
196
  transaction.data,
195
- assetName
197
+ asset
196
198
  )
197
199
 
198
200
  for (const balanceChange of preparedBalanceChanges) {
199
- const { delta, asset } = balanceChange
201
+ const { delta, asset: assetData } = balanceChange
200
202
 
201
203
  const account = {
202
- symbol: asset.symbol,
204
+ symbol: assetData.symbol,
203
205
  balance: delta,
204
- assetType: asset.type,
205
- decimal: asset.decimal,
206
+ assetType: assetData.type,
207
+ decimal: assetData.decimal,
206
208
  }
207
209
 
208
210
  if (delta.startsWith('-')) {
209
211
  willSend.push(account)
210
212
  } else {
211
- if (asset.type === 'erc721') {
213
+ if (assetData.type === 'erc721') {
212
214
  account.nft = {
213
- title: `${asset.title || asset.symbol} #${delta}`,
215
+ title: `${assetData.title || assetData.symbol} #${delta}`,
214
216
  }
215
217
  }
216
218
  willReceive.push(account)