@subwallet/extension-base 1.0.7-0 → 1.0.7-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/background/KoniTypes.d.ts +4 -5
- package/cjs/constants/index.js +1 -1
- package/cjs/koni/api/staking/bonding/amplitude.js +83 -0
- package/cjs/koni/api/staking/bonding/astar.js +104 -1
- package/cjs/koni/api/staking/bonding/index.js +35 -0
- package/cjs/koni/api/staking/bonding/paraChain.js +97 -0
- package/cjs/koni/api/staking/bonding/relayChain.js +191 -12
- package/cjs/koni/api/staking/index.js +11 -11
- package/cjs/koni/api/staking/paraChain.js +200 -130
- package/cjs/koni/api/staking/relayChain.js +66 -68
- package/cjs/koni/api/staking/subsquidStaking.js +6 -11
- package/cjs/koni/background/cron.js +0 -25
- package/cjs/koni/background/handlers/State.js +17 -19
- package/cjs/koni/background/subscription.js +57 -12
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/utils.js +6 -1
- package/cjs/services/storage-service/DatabaseService.js +7 -3
- package/cjs/services/storage-service/db-stores/ChainStakingMetadata.js +5 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +4 -4
- package/cjs/services/transaction-service/index.js +6 -1
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/staking/bonding/amplitude.d.ts +4 -0
- package/koni/api/staking/bonding/amplitude.js +81 -0
- package/koni/api/staking/bonding/astar.d.ts +4 -0
- package/koni/api/staking/bonding/astar.js +102 -1
- package/koni/api/staking/bonding/index.d.ts +1 -0
- package/koni/api/staking/bonding/index.js +38 -4
- package/koni/api/staking/bonding/paraChain.d.ts +4 -0
- package/koni/api/staking/bonding/paraChain.js +95 -0
- package/koni/api/staking/bonding/relayChain.d.ts +5 -0
- package/koni/api/staking/bonding/relayChain.js +185 -10
- package/koni/api/staking/index.d.ts +4 -4
- package/koni/api/staking/index.js +11 -11
- package/koni/api/staking/paraChain.d.ts +5 -5
- package/koni/api/staking/paraChain.js +201 -131
- package/koni/api/staking/relayChain.d.ts +4 -4
- package/koni/api/staking/relayChain.js +66 -67
- package/koni/api/staking/subsquidStaking.d.ts +1 -1
- package/koni/api/staking/subsquidStaking.js +6 -11
- package/koni/background/cron.js +1 -26
- package/koni/background/handlers/State.d.ts +2 -2
- package/koni/background/handlers/State.js +17 -19
- package/koni/background/subscription.d.ts +2 -1
- package/koni/background/subscription.js +58 -13
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/utils.js +6 -1
- package/services/storage-service/DatabaseService.d.ts +2 -2
- package/services/storage-service/DatabaseService.js +7 -3
- package/services/storage-service/db-stores/ChainStakingMetadata.d.ts +1 -0
- package/services/storage-service/db-stores/ChainStakingMetadata.js +3 -0
- package/services/storage-service/db-stores/NominatorMetadata.d.ts +2 -2
- package/services/storage-service/db-stores/NominatorMetadata.js +4 -4
- package/services/transaction-service/index.js +6 -1
|
@@ -7,7 +7,7 @@ import { getAllSubsquidStaking } from '@subwallet/extension-base/koni/api/stakin
|
|
|
7
7
|
import { _PURE_EVM_CHAINS, _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _isChainEvmCompatible, _isChainSupportSubstrateStaking, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { categoryAddresses } from '@subwallet/extension-base/utils';
|
|
10
|
-
export function stakingOnChainApi(addresses, substrateApiMap,
|
|
10
|
+
export function stakingOnChainApi(addresses, substrateApiMap, chainInfoMap, stakingCallback, nominatorStateCallback) {
|
|
11
11
|
const filteredApiMap = [];
|
|
12
12
|
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
|
|
13
13
|
Object.entries(chainInfoMap).forEach(([networkKey, chainInfo]) => {
|
|
@@ -28,20 +28,20 @@ export function stakingOnChainApi(addresses, substrateApiMap, callback, chainInf
|
|
|
28
28
|
const parentApi = await apiPromise.isReady;
|
|
29
29
|
const useAddresses = _isChainEvmCompatible(chainInfoMap[chain]) ? evmAddresses : substrateAddresses;
|
|
30
30
|
if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
31
|
-
const unsub = await getAmplitudeStakingOnChain(parentApi, useAddresses, chainInfoMap, chain,
|
|
31
|
+
const unsub = await getAmplitudeStakingOnChain(parentApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback);
|
|
32
32
|
unsubList.push(unsub);
|
|
33
33
|
} else if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
34
|
-
const unsub = await getAstarStakingOnChain(parentApi, useAddresses, chainInfoMap, chain,
|
|
34
|
+
const unsub = await getAstarStakingOnChain(parentApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback);
|
|
35
35
|
unsubList.push(unsub);
|
|
36
36
|
} else if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
37
|
-
const unsub = await getParaStakingOnChain(parentApi, useAddresses, chainInfoMap, chain,
|
|
37
|
+
const unsub = await getParaStakingOnChain(parentApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback);
|
|
38
38
|
unsubList.push(unsub);
|
|
39
39
|
} else if (_STAKING_CHAIN_GROUP.relay.includes(chain)) {
|
|
40
|
-
const unsub = await getRelayStakingOnChain(parentApi, useAddresses, chainInfoMap, chain,
|
|
40
|
+
const unsub = await getRelayStakingOnChain(parentApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback);
|
|
41
41
|
unsubList.push(unsub);
|
|
42
42
|
}
|
|
43
43
|
if (_STAKING_CHAIN_GROUP.nominationPool.includes(chain)) {
|
|
44
|
-
const unsub = await getRelayPoolingOnChain(parentApi, useAddresses, chainInfoMap, chain,
|
|
44
|
+
const unsub = await getRelayPoolingOnChain(parentApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback);
|
|
45
45
|
unsubList.push(unsub);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -51,11 +51,11 @@ export function stakingOnChainApi(addresses, substrateApiMap, callback, chainInf
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
export async function getNominationStakingRewardData(addresses, chainInfoMap) {
|
|
54
|
+
export async function getNominationStakingRewardData(addresses, chainInfoMap, callback) {
|
|
55
55
|
// might retrieve from other sources
|
|
56
|
-
|
|
56
|
+
await getAllSubsquidStaking(addresses, chainInfoMap, callback);
|
|
57
57
|
}
|
|
58
|
-
export async function getPoolingStakingRewardData(addresses, networkMap, dotSamaApiMap) {
|
|
58
|
+
export async function getPoolingStakingRewardData(addresses, networkMap, dotSamaApiMap, callback) {
|
|
59
59
|
const activeNetworks = [];
|
|
60
60
|
Object.entries(networkMap).forEach(([key, chainInfo]) => {
|
|
61
61
|
if (_isChainSupportSubstrateStaking(chainInfo) && _isSubstrateRelayChain(chainInfo)) {
|
|
@@ -63,7 +63,7 @@ export async function getPoolingStakingRewardData(addresses, networkMap, dotSama
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
if (activeNetworks.length === 0) {
|
|
66
|
-
return
|
|
66
|
+
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
await getNominationPoolReward(addresses, networkMap, dotSamaApiMap, callback);
|
|
69
69
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { StakingItem, StakingRewardItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { NominatorMetadata, StakingItem, StakingRewardItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
-
export declare function getAmplitudeStakingOnChain(parentApi: _SubstrateApi, useAddresses: string[], networks: Record<string, _ChainInfo>, chain: string, callback: (networkKey: string, rs: StakingItem) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
5
|
-
export declare function getAmplitudeUnclaimedStakingReward(substrateApiMap: Record<string, _SubstrateApi>, addresses: string[], networks: Record<string, _ChainInfo>, chains: string[]): Promise<StakingRewardItem[]>;
|
|
6
|
-
export declare function getParaStakingOnChain(
|
|
7
|
-
export declare function getAstarStakingOnChain(
|
|
4
|
+
export declare function getAmplitudeStakingOnChain(parentApi: _SubstrateApi, useAddresses: string[], networks: Record<string, _ChainInfo>, chain: string, callback: (networkKey: string, rs: StakingItem) => void, nominatorStateCallback: (nominatorMetadata: NominatorMetadata) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
5
|
+
export declare function getAmplitudeUnclaimedStakingReward(substrateApiMap: Record<string, _SubstrateApi>, addresses: string[], networks: Record<string, _ChainInfo>, chains: string[], callBack: (rs: StakingRewardItem) => void): Promise<StakingRewardItem[]>;
|
|
6
|
+
export declare function getParaStakingOnChain(substrateApi: _SubstrateApi, useAddresses: string[], chainInfoMap: Record<string, _ChainInfo>, chain: string, stakingCallback: (networkKey: string, rs: StakingItem) => void, nominatorStateCallback: (nominatorMetadata: NominatorMetadata) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
7
|
+
export declare function getAstarStakingOnChain(substrateApi: _SubstrateApi, useAddresses: string[], chainInfoMap: Record<string, _ChainInfo>, chain: string, stakingCallback: (networkKey: string, rs: StakingItem) => void, nominatorStateCallback: (nominatorMetadata: NominatorMetadata) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
@@ -1,98 +1,143 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { APIItemState, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { APIItemState, StakingStatus, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { subscribeAmplitudeNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/amplitude';
|
|
6
|
+
import { subscribeAstarNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
7
|
+
import { subscribeParaChainNominatorMetadata } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
|
|
5
8
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
9
|
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
10
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
11
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
9
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
10
|
-
function getSingleStakingAmplitude(
|
|
11
|
-
return
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
let _activeBalance = '0';
|
|
15
|
-
if (_stakingData !== null) {
|
|
16
|
-
_activeBalance = _stakingData.amount || _stakingData.total;
|
|
17
|
-
_activeBalance = _activeBalance.replaceAll(',', '');
|
|
18
|
-
}
|
|
19
|
-
const activeBalance = new BN(_activeBalance);
|
|
20
|
-
let unstakingBalance = BN_ZERO;
|
|
21
|
-
if (_unstakingData !== null) {
|
|
22
|
-
Object.values(_unstakingData).forEach(_unstakingAmount => {
|
|
23
|
-
const bnUnstakingAmount = new BN(_unstakingAmount.replaceAll(',', ''));
|
|
24
|
-
unstakingBalance = unstakingBalance.add(bnUnstakingAmount);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const totalBalance = activeBalance.add(unstakingBalance);
|
|
13
|
+
function getSingleStakingAmplitude(substrateApi, address, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
14
|
+
return substrateApi.api.queryMulti([[substrateApi.api.query.parachainStaking.delegatorState, address], [substrateApi.api.query.parachainStaking.unstaking, address]], async ([_delegatorState, _unstaking]) => {
|
|
15
|
+
const delegatorState = _delegatorState.toPrimitive();
|
|
16
|
+
const unstakingInfo = _unstaking.toPrimitive();
|
|
28
17
|
const {
|
|
29
18
|
symbol
|
|
30
|
-
} = _getChainNativeTokenBasicInfo(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
chain
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
} = _getChainNativeTokenBasicInfo(chainInfoMap[chain]);
|
|
20
|
+
const owner = reformatAddress(address, 42);
|
|
21
|
+
if (!delegatorState && !unstakingInfo) {
|
|
22
|
+
stakingCallback(chain, {
|
|
23
|
+
name: chainInfoMap[chain].name,
|
|
24
|
+
chain: chain,
|
|
25
|
+
balance: '0',
|
|
26
|
+
activeBalance: '0',
|
|
27
|
+
unlockingBalance: '0',
|
|
28
|
+
nativeToken: symbol,
|
|
29
|
+
unit: symbol,
|
|
30
|
+
state: APIItemState.READY,
|
|
31
|
+
type: StakingType.NOMINATED,
|
|
32
|
+
address: owner
|
|
33
|
+
});
|
|
34
|
+
nominatorStateCallback({
|
|
35
|
+
chain,
|
|
36
|
+
type: StakingType.NOMINATED,
|
|
37
|
+
address: owner,
|
|
38
|
+
status: StakingStatus.NOT_STAKING,
|
|
39
|
+
activeStake: '0',
|
|
40
|
+
nominations: [],
|
|
41
|
+
unstakings: []
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
const activeBalance = delegatorState ? new BN(delegatorState.amount.toString()) : BN_ZERO;
|
|
45
|
+
let unstakingBalance = BN_ZERO;
|
|
46
|
+
if (unstakingInfo) {
|
|
47
|
+
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
48
|
+
const bnUnstakingAmount = new BN(unstakingAmount.toString());
|
|
49
|
+
unstakingBalance = unstakingBalance.add(bnUnstakingAmount);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const totalBalance = activeBalance.add(unstakingBalance);
|
|
53
|
+
const stakingItem = {
|
|
54
|
+
name: chainInfoMap[chain].name,
|
|
55
|
+
chain: chain,
|
|
56
|
+
balance: totalBalance.toString(),
|
|
57
|
+
activeBalance: activeBalance.toString(),
|
|
58
|
+
unlockingBalance: unstakingBalance.toString(),
|
|
59
|
+
nativeToken: symbol,
|
|
60
|
+
unit: symbol,
|
|
61
|
+
state: APIItemState.READY,
|
|
62
|
+
type: StakingType.NOMINATED,
|
|
63
|
+
address: owner
|
|
64
|
+
};
|
|
65
|
+
stakingCallback(chain, stakingItem);
|
|
66
|
+
const nominatorMetadata = await subscribeAmplitudeNominatorMetadata(chainInfoMap[chain], owner, substrateApi, delegatorState, unstakingInfo);
|
|
67
|
+
nominatorStateCallback(nominatorMetadata);
|
|
68
|
+
}
|
|
44
69
|
});
|
|
45
70
|
}
|
|
46
|
-
function getMultiStakingAmplitude(
|
|
47
|
-
return
|
|
71
|
+
function getMultiStakingAmplitude(substrateApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
72
|
+
return substrateApi.api.query.parachainStaking.delegatorState.multi(useAddresses, async ledgers => {
|
|
48
73
|
if (ledgers) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
const {
|
|
75
|
+
symbol
|
|
76
|
+
} = _getChainNativeTokenBasicInfo(chainInfoMap[chain]);
|
|
77
|
+
const _unstakingStates = await substrateApi.api.query.parachainStaking.unstaking.multi(useAddresses);
|
|
78
|
+
await Promise.all(ledgers.map(async (_delegatorState, i) => {
|
|
53
79
|
const owner = reformatAddress(useAddresses[i], 42);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
const delegatorState = _delegatorState.toPrimitive();
|
|
81
|
+
const unstakingInfo = _unstakingStates[i].toPrimitive();
|
|
82
|
+
if (!delegatorState && !unstakingInfo) {
|
|
83
|
+
stakingCallback(chain, {
|
|
84
|
+
name: chainInfoMap[chain].name,
|
|
85
|
+
chain: chain,
|
|
86
|
+
balance: '0',
|
|
87
|
+
activeBalance: '0',
|
|
88
|
+
unlockingBalance: '0',
|
|
89
|
+
nativeToken: symbol,
|
|
90
|
+
unit: symbol,
|
|
91
|
+
state: APIItemState.READY,
|
|
92
|
+
type: StakingType.NOMINATED,
|
|
93
|
+
address: owner
|
|
66
94
|
});
|
|
95
|
+
nominatorStateCallback({
|
|
96
|
+
chain,
|
|
97
|
+
type: StakingType.NOMINATED,
|
|
98
|
+
address: owner,
|
|
99
|
+
status: StakingStatus.NOT_STAKING,
|
|
100
|
+
activeStake: '0',
|
|
101
|
+
nominations: [],
|
|
102
|
+
unstakings: []
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
const activeBalance = delegatorState ? new BN(delegatorState.amount.toString()) : BN_ZERO;
|
|
106
|
+
let unstakingBalance = BN_ZERO;
|
|
107
|
+
if (unstakingInfo) {
|
|
108
|
+
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
109
|
+
const bnUnstakingAmount = new BN(unstakingAmount.toString());
|
|
110
|
+
unstakingBalance = unstakingBalance.add(bnUnstakingAmount);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const totalBalance = activeBalance.add(unstakingBalance);
|
|
114
|
+
const stakingItem = {
|
|
115
|
+
name: chainInfoMap[chain].name,
|
|
116
|
+
chain: chain,
|
|
117
|
+
balance: totalBalance.toString(),
|
|
118
|
+
activeBalance: activeBalance.toString(),
|
|
119
|
+
unlockingBalance: unstakingBalance.toString(),
|
|
120
|
+
nativeToken: symbol,
|
|
121
|
+
unit: symbol,
|
|
122
|
+
state: APIItemState.READY,
|
|
123
|
+
type: StakingType.NOMINATED,
|
|
124
|
+
address: owner
|
|
125
|
+
};
|
|
126
|
+
stakingCallback(chain, stakingItem);
|
|
127
|
+
const nominatorMetadata = await subscribeAmplitudeNominatorMetadata(chainInfoMap[chain], owner, substrateApi, delegatorState, unstakingInfo);
|
|
128
|
+
nominatorStateCallback(nominatorMetadata);
|
|
67
129
|
}
|
|
68
|
-
|
|
69
|
-
const {
|
|
70
|
-
symbol
|
|
71
|
-
} = _getChainNativeTokenBasicInfo(networks[chain]);
|
|
72
|
-
const stakingItem = {
|
|
73
|
-
name: networks[chain].name,
|
|
74
|
-
chain: chain,
|
|
75
|
-
balance: totalBalance.toString(),
|
|
76
|
-
activeBalance: activeBalance.toString(),
|
|
77
|
-
unlockingBalance: unstakingBalance.toString(),
|
|
78
|
-
nativeToken: symbol,
|
|
79
|
-
unit: symbol,
|
|
80
|
-
state: APIItemState.READY,
|
|
81
|
-
type: StakingType.NOMINATED,
|
|
82
|
-
address: owner
|
|
83
|
-
};
|
|
84
|
-
callback(chain, stakingItem);
|
|
85
|
-
}
|
|
130
|
+
}));
|
|
86
131
|
}
|
|
87
132
|
});
|
|
88
133
|
}
|
|
89
|
-
export function getAmplitudeStakingOnChain(parentApi, useAddresses, networks, chain, callback) {
|
|
134
|
+
export function getAmplitudeStakingOnChain(parentApi, useAddresses, networks, chain, callback, nominatorStateCallback) {
|
|
90
135
|
if (useAddresses.length === 1) {
|
|
91
|
-
return getSingleStakingAmplitude(parentApi, useAddresses[0], networks, chain, callback);
|
|
136
|
+
return getSingleStakingAmplitude(parentApi, useAddresses[0], networks, chain, callback, nominatorStateCallback);
|
|
92
137
|
}
|
|
93
|
-
return getMultiStakingAmplitude(parentApi, useAddresses, networks, chain, callback);
|
|
138
|
+
return getMultiStakingAmplitude(parentApi, useAddresses, networks, chain, callback, nominatorStateCallback);
|
|
94
139
|
}
|
|
95
|
-
export async function getAmplitudeUnclaimedStakingReward(substrateApiMap, addresses, networks, chains) {
|
|
140
|
+
export async function getAmplitudeUnclaimedStakingReward(substrateApiMap, addresses, networks, chains, callBack) {
|
|
96
141
|
if (chains.length === 0) {
|
|
97
142
|
return [];
|
|
98
143
|
}
|
|
@@ -109,42 +154,37 @@ export async function getAmplitudeUnclaimedStakingReward(substrateApiMap, addres
|
|
|
109
154
|
const apiProps = await substrateApiMap[chain].isReady;
|
|
110
155
|
await Promise.all(useAddresses.map(async address => {
|
|
111
156
|
const _unclaimedReward = await apiProps.api.query.parachainStaking.rewards(address);
|
|
112
|
-
|
|
113
|
-
const rewardItem = {
|
|
157
|
+
callBack({
|
|
114
158
|
chain,
|
|
115
159
|
name: networkInfo.name,
|
|
116
160
|
state: APIItemState.READY,
|
|
117
161
|
type: StakingType.NOMINATED,
|
|
118
162
|
address: reformatAddress(address, 42),
|
|
119
|
-
unclaimedReward
|
|
120
|
-
};
|
|
121
|
-
unclaimedRewardList.push(rewardItem);
|
|
163
|
+
unclaimedReward: _unclaimedReward.toString()
|
|
164
|
+
});
|
|
122
165
|
}));
|
|
123
166
|
}
|
|
124
167
|
}));
|
|
125
168
|
return unclaimedRewardList;
|
|
126
169
|
}
|
|
127
|
-
export function getParaStakingOnChain(
|
|
170
|
+
export function getParaStakingOnChain(substrateApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
128
171
|
const {
|
|
129
172
|
symbol
|
|
130
|
-
} = _getChainNativeTokenBasicInfo(
|
|
131
|
-
return
|
|
173
|
+
} = _getChainNativeTokenBasicInfo(chainInfoMap[chain]);
|
|
174
|
+
return substrateApi.api.query.parachainStaking.delegatorState.multi(useAddresses, async ledgers => {
|
|
132
175
|
if (ledgers) {
|
|
133
|
-
|
|
134
|
-
const
|
|
176
|
+
await Promise.all(ledgers.map(async (_delegatorState, i) => {
|
|
177
|
+
const delegatorState = _delegatorState.toPrimitive();
|
|
135
178
|
const owner = reformatAddress(useAddresses[i], 42);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
_unlockingBalance = _unlockingBalance.replaceAll(',', '');
|
|
143
|
-
const totalBalance = new BN(_totalBalance);
|
|
144
|
-
const unlockingBalance = new BN(_unlockingBalance);
|
|
179
|
+
if (delegatorState) {
|
|
180
|
+
const _totalBalance = delegatorState.total;
|
|
181
|
+
// let _unlockingBalance = delegatorState.lessTotal ? delegatorState.lessTotal : delegatorState.requests.lessTotal;
|
|
182
|
+
const _unlockingBalance = delegatorState.lessTotal;
|
|
183
|
+
const totalBalance = new BN(_totalBalance.toString());
|
|
184
|
+
const unlockingBalance = new BN(_unlockingBalance.toString());
|
|
145
185
|
const activeBalance = totalBalance.sub(unlockingBalance);
|
|
146
|
-
|
|
147
|
-
name:
|
|
186
|
+
stakingCallback(chain, {
|
|
187
|
+
name: chainInfoMap[chain].name,
|
|
148
188
|
chain: chain,
|
|
149
189
|
balance: totalBalance.toString(),
|
|
150
190
|
activeBalance: activeBalance.toString(),
|
|
@@ -154,11 +194,12 @@ export function getParaStakingOnChain(parentApi, useAddresses, networks, chain,
|
|
|
154
194
|
state: APIItemState.READY,
|
|
155
195
|
type: StakingType.NOMINATED,
|
|
156
196
|
address: owner
|
|
157
|
-
};
|
|
158
|
-
|
|
197
|
+
});
|
|
198
|
+
const nominatorMetadata = await subscribeParaChainNominatorMetadata(chainInfoMap[chain], owner, substrateApi, delegatorState);
|
|
199
|
+
nominatorStateCallback(nominatorMetadata);
|
|
159
200
|
} else {
|
|
160
|
-
|
|
161
|
-
name:
|
|
201
|
+
stakingCallback(chain, {
|
|
202
|
+
name: chainInfoMap[chain].name,
|
|
162
203
|
chain: chain,
|
|
163
204
|
balance: '0',
|
|
164
205
|
activeBalance: '0',
|
|
@@ -168,49 +209,78 @@ export function getParaStakingOnChain(parentApi, useAddresses, networks, chain,
|
|
|
168
209
|
state: APIItemState.READY,
|
|
169
210
|
type: StakingType.NOMINATED,
|
|
170
211
|
address: owner
|
|
171
|
-
};
|
|
172
|
-
|
|
212
|
+
});
|
|
213
|
+
nominatorStateCallback({
|
|
214
|
+
chain,
|
|
215
|
+
type: StakingType.NOMINATED,
|
|
216
|
+
address: owner,
|
|
217
|
+
status: StakingStatus.NOT_STAKING,
|
|
218
|
+
activeStake: '0',
|
|
219
|
+
nominations: [],
|
|
220
|
+
unstakings: []
|
|
221
|
+
});
|
|
173
222
|
}
|
|
174
|
-
}
|
|
223
|
+
}));
|
|
175
224
|
}
|
|
176
225
|
});
|
|
177
226
|
}
|
|
178
|
-
export function getAstarStakingOnChain(
|
|
227
|
+
export function getAstarStakingOnChain(substrateApi, useAddresses, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
179
228
|
const {
|
|
180
229
|
symbol
|
|
181
|
-
} = _getChainNativeTokenBasicInfo(
|
|
182
|
-
return
|
|
230
|
+
} = _getChainNativeTokenBasicInfo(chainInfoMap[chain]);
|
|
231
|
+
return substrateApi.api.query.dappsStaking.ledger.multi(useAddresses, async ledgers => {
|
|
183
232
|
if (ledgers) {
|
|
184
|
-
|
|
233
|
+
await Promise.all(ledgers.map(async (_ledger, i) => {
|
|
185
234
|
let bnUnlockingBalance = BN_ZERO;
|
|
186
235
|
const owner = reformatAddress(useAddresses[i], 42);
|
|
187
|
-
const ledger =
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
236
|
+
const ledger = _ledger.toPrimitive();
|
|
237
|
+
if (ledger && ledger.locked > 0) {
|
|
238
|
+
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
239
|
+
const _totalStake = ledger.locked;
|
|
240
|
+
const bnTotalStake = new BN(_totalStake.toString());
|
|
241
|
+
for (const chunk of unlockingChunks) {
|
|
242
|
+
const bnChunk = new BN(chunk.amount.toString());
|
|
243
|
+
bnUnlockingBalance = bnUnlockingBalance.add(bnChunk);
|
|
244
|
+
}
|
|
245
|
+
const bnActiveStake = bnTotalStake.sub(bnUnlockingBalance);
|
|
246
|
+
stakingCallback(chain, {
|
|
247
|
+
name: chainInfoMap[chain].name,
|
|
248
|
+
chain: chain,
|
|
249
|
+
balance: bnTotalStake.toString(),
|
|
250
|
+
activeBalance: bnActiveStake.toString(),
|
|
251
|
+
unlockingBalance: bnUnlockingBalance.toString(),
|
|
252
|
+
nativeToken: symbol,
|
|
253
|
+
unit: symbol,
|
|
254
|
+
state: APIItemState.READY,
|
|
255
|
+
type: StakingType.NOMINATED,
|
|
256
|
+
address: owner
|
|
257
|
+
});
|
|
258
|
+
const nominatorMetadata = await subscribeAstarNominatorMetadata(chainInfoMap[chain], owner, substrateApi, ledger);
|
|
259
|
+
nominatorStateCallback(nominatorMetadata);
|
|
260
|
+
} else {
|
|
261
|
+
stakingCallback(chain, {
|
|
262
|
+
name: chainInfoMap[chain].name,
|
|
263
|
+
chain,
|
|
264
|
+
balance: '0',
|
|
265
|
+
activeBalance: '0',
|
|
266
|
+
unlockingBalance: '0',
|
|
267
|
+
nativeToken: symbol,
|
|
268
|
+
unit: symbol,
|
|
269
|
+
state: APIItemState.READY,
|
|
270
|
+
type: StakingType.NOMINATED,
|
|
271
|
+
address: owner
|
|
272
|
+
});
|
|
273
|
+
nominatorStateCallback({
|
|
274
|
+
chain,
|
|
275
|
+
type: StakingType.NOMINATED,
|
|
276
|
+
address: owner,
|
|
277
|
+
status: StakingStatus.NOT_STAKING,
|
|
278
|
+
activeStake: '0',
|
|
279
|
+
nominations: [],
|
|
280
|
+
unstakings: []
|
|
281
|
+
});
|
|
195
282
|
}
|
|
196
|
-
|
|
197
|
-
const bnActiveStake = bnTotalStake.sub(bnUnlockingBalance);
|
|
198
|
-
const stakingItem = {
|
|
199
|
-
name: networks[chain].name,
|
|
200
|
-
chain: chain,
|
|
201
|
-
balance: bnTotalStake.toString(),
|
|
202
|
-
activeBalance: bnActiveStake.toString(),
|
|
203
|
-
unlockingBalance: bnUnlockingBalance.toString(),
|
|
204
|
-
nativeToken: symbol,
|
|
205
|
-
unit: symbol,
|
|
206
|
-
state: APIItemState.READY,
|
|
207
|
-
type: StakingType.NOMINATED,
|
|
208
|
-
address: owner
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// eslint-disable-next-line node/no-callback-literal
|
|
212
|
-
callback(chain, stakingItem);
|
|
213
|
-
}
|
|
283
|
+
}));
|
|
214
284
|
}
|
|
215
285
|
});
|
|
216
286
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { StakingItem, StakingRewardItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { NominatorMetadata, StakingItem, StakingRewardItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
-
export declare function getRelayStakingOnChain(substrateApi: _SubstrateApi, useAddresses: string[], chainInfoMap: Record<string, _ChainInfo>, chain: string,
|
|
5
|
-
export declare function getRelayPoolingOnChain(
|
|
6
|
-
export declare function getNominationPoolReward(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi
|
|
4
|
+
export declare function getRelayStakingOnChain(substrateApi: _SubstrateApi, useAddresses: string[], chainInfoMap: Record<string, _ChainInfo>, chain: string, stakingCallback: (networkKey: string, rs: StakingItem) => void, nominatorStateCallback: (rs: NominatorMetadata) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
5
|
+
export declare function getRelayPoolingOnChain(substrateApi: _SubstrateApi, useAddresses: string[], chainInfoMap: Record<string, _ChainInfo>, chain: string, stakingCallback: (networkKey: string, rs: StakingItem) => void, nominatorStateCallback: (rs: NominatorMetadata) => void): import("@polkadot/api-base/types").UnsubscribePromise;
|
|
6
|
+
export declare function getNominationPoolReward(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, callBack: (rs: StakingRewardItem) => void): Promise<void>;
|