@exodus/ethereum-api 2.20.0 → 2.21.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.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@exodus/asset-lib": "^3.5.4",
|
|
14
14
|
"@exodus/crypto": "^1.0.0-rc.0",
|
|
15
|
-
"@exodus/ethereum-lib": "^2.
|
|
15
|
+
"@exodus/ethereum-lib": "^2.19.0",
|
|
16
16
|
"@exodus/ethereumjs-util": "^7.1.0-exodus.6",
|
|
17
17
|
"@exodus/simple-retry": "^0.0.6",
|
|
18
18
|
"@exodus/solidity-contract": "^1.0.1",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"@exodus/assets-base": "^8.0.136",
|
|
30
30
|
"@exodus/models": "^8.7.2"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "52d783c8952348157fe767187533498088c52b01"
|
|
33
33
|
}
|
package/src/eth-like-util.js
CHANGED
|
@@ -134,7 +134,9 @@ export const getERC20Params = async ({
|
|
|
134
134
|
})
|
|
135
135
|
)
|
|
136
136
|
|
|
137
|
-
const response = Object.fromEntries(
|
|
137
|
+
const response = Object.fromEntries(
|
|
138
|
+
paramNames.map((paramName, index) => [paramName, paramValues[index]])
|
|
139
|
+
)
|
|
138
140
|
erc20ParamsCache[cacheKey] = response
|
|
139
141
|
|
|
140
142
|
return response
|
|
@@ -7,8 +7,21 @@ const ethDecimals = assets.ethereum.units.ETH
|
|
|
7
7
|
|
|
8
8
|
const ethHexToInt = (hexValue) => parseInt(hexValue, '16')
|
|
9
9
|
|
|
10
|
-
async function
|
|
10
|
+
async function getAssetSymbolFromContract(contractAddress) {
|
|
11
|
+
const { symbol: assetSymbol } = await getERC20Params({
|
|
12
|
+
address: contractAddress,
|
|
13
|
+
assetName: 'ethereum',
|
|
14
|
+
paramNames: ['symbol'],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return assetSymbol
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function prepareBalanceChanges(internalTransactions, balanceChanges) {
|
|
21
|
+
const preparedBalanceChanges = [...balanceChanges]
|
|
22
|
+
|
|
11
23
|
const decimals = {}
|
|
24
|
+
const assetSymbols = {}
|
|
12
25
|
|
|
13
26
|
if (internalTransactions && Array.isArray(internalTransactions)) {
|
|
14
27
|
for (const transaction of internalTransactions) {
|
|
@@ -17,15 +30,27 @@ async function getDecimalsFromSimulatedTx(internalTransactions, balanceChanges)
|
|
|
17
30
|
if (!contractCall) continue
|
|
18
31
|
|
|
19
32
|
if (contractCall.methodName === 'transfer' || contractCall.methodName === 'transferFrom') {
|
|
20
|
-
|
|
33
|
+
const assetSymbol =
|
|
34
|
+
contractCall.contractAlias ||
|
|
35
|
+
(await getAssetSymbolFromContract(contractCall.contractAddress))
|
|
36
|
+
|
|
37
|
+
assetSymbols[contractCall.contractAddress] = assetSymbol
|
|
38
|
+
decimals[assetSymbol] = contractCall.contractDecimals
|
|
21
39
|
}
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
42
|
|
|
25
|
-
for (const balanceChange of
|
|
43
|
+
for (const balanceChange of preparedBalanceChanges) {
|
|
26
44
|
const { asset } = balanceChange
|
|
27
45
|
|
|
46
|
+
if (!asset.symbol) {
|
|
47
|
+
asset.symbol =
|
|
48
|
+
assetSymbols[asset.contractAddress] ||
|
|
49
|
+
(await getAssetSymbolFromContract(asset.contractAddress))
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
if (typeof decimals[asset.symbol] === 'number') {
|
|
53
|
+
asset.decimal = decimals[asset.symbol]
|
|
29
54
|
continue
|
|
30
55
|
}
|
|
31
56
|
|
|
@@ -36,11 +61,10 @@ async function getDecimalsFromSimulatedTx(internalTransactions, balanceChanges)
|
|
|
36
61
|
paramNames: ['decimals'],
|
|
37
62
|
})
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
asset.decimal = assetDecimal
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
|
-
|
|
43
|
-
return decimals
|
|
67
|
+
return preparedBalanceChanges
|
|
44
68
|
}
|
|
45
69
|
|
|
46
70
|
export async function simulateAndRetrieveSideEffects(transaction) {
|
|
@@ -70,16 +94,19 @@ export async function simulateAndRetrieveSideEffects(transaction) {
|
|
|
70
94
|
simulatedBalanceChanges.filter(({ address }) => address === transaction.from)
|
|
71
95
|
|
|
72
96
|
if (sender) {
|
|
73
|
-
const
|
|
97
|
+
const preparedBalanceChanges = await prepareBalanceChanges(
|
|
98
|
+
internalTransactions,
|
|
99
|
+
sender.balanceChanges
|
|
100
|
+
)
|
|
74
101
|
|
|
75
|
-
for (const balanceChange of
|
|
102
|
+
for (const balanceChange of preparedBalanceChanges) {
|
|
76
103
|
const { delta, asset } = balanceChange
|
|
77
104
|
|
|
78
105
|
const account = {
|
|
79
106
|
symbol: asset.symbol,
|
|
80
107
|
balance: delta,
|
|
81
108
|
assetType: asset.type,
|
|
82
|
-
decimal:
|
|
109
|
+
decimal: asset.decimal,
|
|
83
110
|
}
|
|
84
111
|
|
|
85
112
|
if (delta.startsWith('-')) {
|