@exodus/ethereum-api 2.12.0 → 2.13.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 +4 -3
- package/src/exodus-eth-server/api.js +12 -3
- package/src/get-balances.js +38 -0
- package/src/index.js +1 -0
- package/src/tx-log/ethereum-monitor.js +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@exodus/asset-lib": "^3.5.4",
|
|
14
|
-
"@exodus/
|
|
14
|
+
"@exodus/crypto": "^1.0.0-rc.0",
|
|
15
|
+
"@exodus/ethereum-lib": "^2.13.5",
|
|
15
16
|
"@exodus/ethereumjs-util": "^7.1.0-exodus.6",
|
|
16
17
|
"@exodus/simple-retry": "^0.0.6",
|
|
17
18
|
"fetchival": "0.3.3",
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"@exodus/assets-base": "^8.0.136",
|
|
28
29
|
"@exodus/models": "^8.7.2"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "7d9f726b6115d756d5fbed46664d466972c0f314"
|
|
31
32
|
}
|
|
@@ -6,6 +6,7 @@ import createWebSocket from './ws'
|
|
|
6
6
|
import { retry } from '@exodus/simple-retry'
|
|
7
7
|
import { simpleErc20 } from '@exodus/solidity-contract'
|
|
8
8
|
import { bufferToHex } from '@exodus/ethereumjs-util'
|
|
9
|
+
import { randomUUID } from '@exodus/crypto/randomUUID'
|
|
9
10
|
|
|
10
11
|
const RETRY_DELAYS = ['10s']
|
|
11
12
|
|
|
@@ -18,10 +19,10 @@ export function create(defaultURL) {
|
|
|
18
19
|
return url.format(obj)
|
|
19
20
|
})
|
|
20
21
|
|
|
21
|
-
async function request(module, params = {}, version = 'v1') {
|
|
22
|
+
async function request(module, params = {}, { version = 'v1', method = 'get' } = {}) {
|
|
22
23
|
const url = urlJoin(version === 'v1' ? API_URL : API_URL.replace('v1', version), module)
|
|
23
24
|
try {
|
|
24
|
-
return await fetchival(url, { timeout: ms('15s') })
|
|
25
|
+
return await fetchival(url, { timeout: ms('15s') })[method](params)
|
|
25
26
|
} catch (err) {
|
|
26
27
|
let nerr = err
|
|
27
28
|
if (err.response && err.response.status === 500) {
|
|
@@ -106,7 +107,7 @@ export function create(defaultURL) {
|
|
|
106
107
|
address,
|
|
107
108
|
...opts,
|
|
108
109
|
},
|
|
109
|
-
'v2'
|
|
110
|
+
{ version: 'v2' }
|
|
110
111
|
)
|
|
111
112
|
},
|
|
112
113
|
|
|
@@ -229,5 +230,13 @@ export function create(defaultURL) {
|
|
|
229
230
|
method: 'net_version',
|
|
230
231
|
})
|
|
231
232
|
},
|
|
233
|
+
|
|
234
|
+
async proxyToCoinNode(requestData) {
|
|
235
|
+
if (!requestData.jsonrpc) requestData.jsonrpc = '2.0'
|
|
236
|
+
if (!requestData.id) requestData.id = randomUUID()
|
|
237
|
+
if (!requestData.params) requestData.params = []
|
|
238
|
+
|
|
239
|
+
return request('proxy', requestData, { version: 'v2', method: 'post' })
|
|
240
|
+
},
|
|
232
241
|
}
|
|
233
242
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
2
|
+
|
|
3
|
+
const fixBalance = ({ txLog, balance }) => {
|
|
4
|
+
for (const tx of txLog) {
|
|
5
|
+
// TODO: pending can only be less than a few minutes old, we can only search the latest txs to improve performance
|
|
6
|
+
if (tx.sent && tx.pending && !tx.error) {
|
|
7
|
+
// coinAmount is negative for sent tx
|
|
8
|
+
balance = balance.sub(tx.coinAmount.abs())
|
|
9
|
+
if (tx.coinAmount.unitType.equals(tx.feeAmount.unitType)) {
|
|
10
|
+
balance = balance.sub(tx.feeAmount)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return balance
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Api method to return the balance based on either account state balances or tx history.
|
|
19
|
+
*
|
|
20
|
+
* @param asset the asset to get the balances
|
|
21
|
+
* @param txLog the txLog when the balance is transaction based
|
|
22
|
+
* @param accountState the account state when the balance is loaded from RPC
|
|
23
|
+
* @returns {{balance}|null} an object with the balance or null if the balance is unknown/zero
|
|
24
|
+
*/
|
|
25
|
+
export const getBalances = ({ asset, txLog, accountState }) => {
|
|
26
|
+
if (isRpcBalanceAsset(asset)) {
|
|
27
|
+
const balance =
|
|
28
|
+
asset.baseAsset.name === asset.name
|
|
29
|
+
? accountState?.balance
|
|
30
|
+
: accountState?.tokenBalances?.[asset.name]
|
|
31
|
+
return balance && !balance.isZero ? { balance: fixBalance({ txLog, balance }) } : null
|
|
32
|
+
}
|
|
33
|
+
return txLog.size
|
|
34
|
+
? {
|
|
35
|
+
balance: txLog.getMutations().slice(-1)[0].balance,
|
|
36
|
+
}
|
|
37
|
+
: null
|
|
38
|
+
}
|
package/src/index.js
CHANGED
|
@@ -224,9 +224,8 @@ export class EthereumMonitor extends BaseMonitor {
|
|
|
224
224
|
.filter((token) => isRpcBalanceAsset(token) && token.contract.address)
|
|
225
225
|
.map(async (token) => {
|
|
226
226
|
const { confirmed } = await server.balanceOf(ourWalletAddress, token.contract.address)
|
|
227
|
-
const value = confirmed[token.contract.address]
|
|
228
|
-
|
|
229
|
-
return { [token.name]: balance }
|
|
227
|
+
const value = token.currency.baseUnit(confirmed[token.contract.address] || 0)
|
|
228
|
+
return value.isZero ? {} : { [token.name]: value }
|
|
230
229
|
})
|
|
231
230
|
))
|
|
232
231
|
)
|