@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": "
|
|
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": "^
|
|
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": "
|
|
39
|
+
"gitHead": "35b8c8c3a9aa2be1287d83d553ede11f174cfe0e"
|
|
40
40
|
}
|
package/src/eth-like-util.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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 (!
|
|
104
|
-
|
|
105
|
-
assetSymbols[
|
|
106
|
-
(await getAssetSymbolFromContract(
|
|
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
|
-
|
|
111
|
-
|
|
110
|
+
assetData.type = 'erc721'
|
|
111
|
+
assetData.title = contractName
|
|
112
112
|
continue
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
if (typeof decimals[
|
|
116
|
-
|
|
115
|
+
if (typeof decimals[assetData.symbol] === 'number') {
|
|
116
|
+
assetData.decimal = decimals[assetData.symbol]
|
|
117
117
|
continue
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
if (isERC20 &&
|
|
120
|
+
if (isERC20 && assetData.contractAddress) {
|
|
121
121
|
const { decimals: assetDecimal } = await getERC20Params({
|
|
122
|
-
address:
|
|
123
|
-
|
|
122
|
+
address: assetData.contractAddress,
|
|
123
|
+
asset,
|
|
124
124
|
paramNames: ['decimals'],
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
|
|
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,
|
|
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
|
-
|
|
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:
|
|
204
|
+
symbol: assetData.symbol,
|
|
203
205
|
balance: delta,
|
|
204
|
-
assetType:
|
|
205
|
-
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 (
|
|
213
|
+
if (assetData.type === 'erc721') {
|
|
212
214
|
account.nft = {
|
|
213
|
-
title: `${
|
|
215
|
+
title: `${assetData.title || assetData.symbol} #${delta}`,
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
willReceive.push(account)
|