@exodus/ethereum-api 6.3.29 → 6.3.31
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 +3 -3
- package/src/get-balances.js +38 -14
- package/src/staking/ethereum/api.js +10 -0
- package/src/staking/ethereum/service.js +11 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.31",
|
|
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": "^4.0.0",
|
|
20
20
|
"@exodus/ethereumjs-util": "^7.1.0-exodus.6",
|
|
21
21
|
"@exodus/fetch": "^1.3.0-beta.4",
|
|
22
22
|
"@exodus/simple-retry": "^0.0.6",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@exodus/models": "^8.10.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "fdcd4a653b2de7a722c2d4936b196961f20563fd"
|
|
38
38
|
}
|
package/src/get-balances.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
1
|
+
import { getEthereumBalances, isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
2
|
+
|
|
3
|
+
import { get } from 'lodash'
|
|
2
4
|
|
|
3
5
|
const fixBalance = ({ txLog, balance }) => {
|
|
4
6
|
for (const tx of txLog) {
|
|
@@ -14,25 +16,47 @@ const fixBalance = ({ txLog, balance }) => {
|
|
|
14
16
|
return balance
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
const getBalanceFromAccountState = ({ asset, accountState }) => {
|
|
20
|
+
const isBase = asset.name === asset.baseAsset.name
|
|
21
|
+
return get(
|
|
22
|
+
accountState,
|
|
23
|
+
isBase ? ['balance'] : ['tokenBalances', asset.name],
|
|
24
|
+
asset.currency.ZERO
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const getBalanceFromTxLog = ({ txLog, asset }) => {
|
|
29
|
+
return txLog.size > 0 ? txLog.getMutations().slice(-1)[0].balance : asset.currency.ZERO
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getBalance = ({ asset, accountState, txLog }) => {
|
|
33
|
+
const balance = isRpcBalanceAsset(asset)
|
|
34
|
+
? getBalanceFromAccountState({ asset, accountState })
|
|
35
|
+
: getBalanceFromTxLog({ txLog, asset })
|
|
36
|
+
|
|
37
|
+
const shouldFixBalance = isRpcBalanceAsset(asset)
|
|
38
|
+
|
|
39
|
+
if (['ethereum', 'ethereumgoerli'].includes(asset.name)) {
|
|
40
|
+
const { balance: ethereumBalance } = getEthereumBalances({
|
|
41
|
+
asset,
|
|
42
|
+
liquidBalance: balance,
|
|
43
|
+
accountState,
|
|
44
|
+
})
|
|
45
|
+
return ethereumBalance
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return shouldFixBalance ? fixBalance({ txLog, balance }) : balance
|
|
49
|
+
}
|
|
50
|
+
|
|
17
51
|
/**
|
|
18
52
|
* Api method to return the balance based on either account state balances or tx history.
|
|
19
53
|
*
|
|
20
54
|
* @param asset the asset to get the balances
|
|
21
55
|
* @param txLog the txLog when the balance is transaction based
|
|
22
56
|
* @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
|
|
57
|
+
* @returns {{balance}|null} an object with the balance or null if the balance is unknown
|
|
24
58
|
*/
|
|
25
59
|
export const getBalances = ({ asset, txLog, accountState }) => {
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
60
|
+
const balance = getBalance({ asset, accountState, txLog })
|
|
61
|
+
return { balance }
|
|
38
62
|
}
|
|
@@ -94,6 +94,16 @@ export class EthereumStaking {
|
|
|
94
94
|
return this.asset.currency.baseUnit(userBalance)
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** Return user pending deposited balance. Balance which deposited into validator but not active yet. Pending deposited balance can't be unstake till validator activation */
|
|
98
|
+
async pendingDepositedBalanceOf(address) {
|
|
99
|
+
const userBalance = await this.callReadFunctionContract(
|
|
100
|
+
this.contractAccounting,
|
|
101
|
+
'pendingDepositedBalanceOf',
|
|
102
|
+
address
|
|
103
|
+
)
|
|
104
|
+
return this.asset.currency.baseUnit(userBalance)
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
/** Return user active origin deposited balance */
|
|
98
108
|
async depositedBalanceOf(address) {
|
|
99
109
|
const depositedBalance = await this.callReadFunctionContract(
|
|
@@ -236,14 +236,21 @@ export async function getEthereumStakingInfo({ address, asset }) {
|
|
|
236
236
|
const delegator = address.toLowerCase()
|
|
237
237
|
const staking = new EthereumStaking(asset)
|
|
238
238
|
|
|
239
|
-
const [
|
|
239
|
+
const [
|
|
240
|
+
activeStakedBalance,
|
|
241
|
+
pendingBalance,
|
|
242
|
+
pendingDepositedBalance,
|
|
243
|
+
withdrawRequest,
|
|
244
|
+
rewardsBalance,
|
|
245
|
+
] = await Promise.all([
|
|
240
246
|
staking.autocompoundBalanceOf(delegator),
|
|
241
247
|
staking.pendingBalanceOf(delegator),
|
|
248
|
+
staking.pendingDepositedBalanceOf(delegator),
|
|
242
249
|
staking.withdrawRequest(delegator),
|
|
243
250
|
staking.getLiquidRewards(delegator),
|
|
244
251
|
])
|
|
245
252
|
|
|
246
|
-
const delegatedBalance = activeStakedBalance.add(pendingBalance)
|
|
253
|
+
const delegatedBalance = activeStakedBalance.add(pendingBalance).add(pendingDepositedBalance)
|
|
247
254
|
const minDelegateAmount = currency.defaultUnit(0.1)
|
|
248
255
|
|
|
249
256
|
const {
|
|
@@ -262,8 +269,10 @@ export async function getEthereumStakingInfo({ address, asset }) {
|
|
|
262
269
|
return {
|
|
263
270
|
rewardsBalance,
|
|
264
271
|
isDelegating,
|
|
272
|
+
activeStakedBalance, // balance staked into the validator
|
|
265
273
|
delegatedBalance, // balance staked into the validator + pending
|
|
266
274
|
pendingBalance, // balance waiting to be staked
|
|
275
|
+
pendingDepositedBalance, // balance deposited into validator but not active yet
|
|
267
276
|
minDelegateAmount,
|
|
268
277
|
unclaimedUndelegatedBalance,
|
|
269
278
|
canClaimUndelegatedBalance,
|