@subwallet/extension-base 1.1.32-beta.0 → 1.1.33-beta.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/background/KoniTypes.d.ts +1 -0
- package/background/KoniTypes.js +1 -0
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +97 -62
- package/cjs/koni/api/staking/paraChain.js +31 -5
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Tabs.js +19 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +3 -2
- package/cjs/services/earning-service/constants/chains.js +3 -2
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +110 -65
- package/cjs/services/earning-service/service.js +32 -12
- package/cjs/services/history-service/index.js +12 -8
- package/cjs/services/transaction-service/index.js +62 -13
- package/cjs/utils/fetchEvmChainInfo.js +20 -0
- package/cjs/utils/index.js +24 -0
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +97 -62
- package/koni/api/staking/bonding/utils.d.ts +4 -0
- package/koni/api/staking/paraChain.js +31 -5
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Tabs.js +20 -3
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +3 -2
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +3 -2
- package/services/earning-service/handlers/liquid-staking/bifrost.js +2 -2
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +1 -1
- package/services/earning-service/handlers/native-staking/amplitude.js +110 -65
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +33 -13
- package/services/event-service/types.d.ts +1 -0
- package/services/history-service/index.js +12 -8
- package/services/transaction-service/index.d.ts +5 -0
- package/services/transaction-service/index.js +49 -1
- package/services/transaction-service/types.d.ts +1 -0
- package/types/yield/info/chain/info.d.ts +1 -0
- package/utils/fetchEvmChainInfo.d.ts +17 -0
- package/utils/fetchEvmChainInfo.js +14 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +3 -1
package/background/KoniTypes.js
CHANGED
|
@@ -103,6 +103,7 @@ export let ExtrinsicStatus;
|
|
|
103
103
|
ExtrinsicStatus["SUCCESS"] = "success";
|
|
104
104
|
ExtrinsicStatus["FAIL"] = "fail";
|
|
105
105
|
ExtrinsicStatus["CANCELLED"] = "cancelled";
|
|
106
|
+
ExtrinsicStatus["TIMEOUT"] = "timeout";
|
|
106
107
|
ExtrinsicStatus["UNKNOWN"] = "unknown";
|
|
107
108
|
})(ExtrinsicStatus || (ExtrinsicStatus = {}));
|
|
108
109
|
export let BasicTxErrorType;
|
|
@@ -118,6 +118,7 @@ exports.ExtrinsicStatus = ExtrinsicStatus;
|
|
|
118
118
|
ExtrinsicStatus["SUCCESS"] = "success";
|
|
119
119
|
ExtrinsicStatus["FAIL"] = "fail";
|
|
120
120
|
ExtrinsicStatus["CANCELLED"] = "cancelled";
|
|
121
|
+
ExtrinsicStatus["TIMEOUT"] = "timeout";
|
|
121
122
|
ExtrinsicStatus["UNKNOWN"] = "unknown";
|
|
122
123
|
})(ExtrinsicStatus || (exports.ExtrinsicStatus = ExtrinsicStatus = {}));
|
|
123
124
|
let BasicTxErrorType;
|
|
@@ -15,6 +15,7 @@ exports.subscribeAmplitudeStakingMetadata = subscribeAmplitudeStakingMetadata;
|
|
|
15
15
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
16
16
|
var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
|
|
17
17
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
18
|
+
var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
|
|
18
19
|
var _utils2 = require("@subwallet/extension-base/services/earning-service/utils");
|
|
19
20
|
var _types = require("@subwallet/extension-base/types");
|
|
20
21
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
@@ -32,7 +33,7 @@ function subscribeAmplitudeStakingMetadata(chain, substrateApi, callback) {
|
|
|
32
33
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.stakeDuration.toString();
|
|
33
34
|
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
34
35
|
const blockPerRound = parseFloat(_blockPerRound);
|
|
35
|
-
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chain] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound;
|
|
36
|
+
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chain] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound;
|
|
36
37
|
const unstakingPeriod = blockDuration * parseInt(unstakingDelay);
|
|
37
38
|
callback(chain, {
|
|
38
39
|
chain,
|
|
@@ -74,46 +75,52 @@ async function subscribeAmplitudeNominatorMetadata(chainInfo, address, substrate
|
|
|
74
75
|
const nominationList = [];
|
|
75
76
|
const unstakingList = [];
|
|
76
77
|
const minDelegatorStake = substrateApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
78
|
+
const hasUnstakingInfo = unstakingInfo && Object.values(unstakingInfo).length > 0;
|
|
77
79
|
let activeStake = '0';
|
|
78
80
|
if (delegatorState) {
|
|
79
81
|
// delegatorState can be null while unstaking all
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const identityPromises = delegatorState.map(delegate => (0, _utils2.parseIdentity)(substrateApi, delegate.owner));
|
|
83
|
+
const identities = await Promise.all(identityPromises);
|
|
84
|
+
for (let i = 0; i < delegatorState.length; i++) {
|
|
85
|
+
const delegate = delegatorState[i];
|
|
86
|
+
const [identity] = identities[i];
|
|
87
|
+
activeStake = delegate.amount.toString();
|
|
88
|
+
const bnActiveStake = new _util.BN(activeStake);
|
|
89
|
+
let delegationStatus = _types.EarningStatus.NOT_EARNING;
|
|
90
|
+
if (bnActiveStake.gt(_util.BN_ZERO) && bnActiveStake.gte(new _util.BN(minDelegatorStake))) {
|
|
91
|
+
delegationStatus = _types.EarningStatus.EARNING_REWARD;
|
|
92
|
+
}
|
|
93
|
+
nominationList.push({
|
|
94
|
+
status: delegationStatus,
|
|
95
|
+
chain: chainInfo.slug,
|
|
96
|
+
validatorAddress: delegate.owner,
|
|
97
|
+
activeStake: delegate.amount.toString(),
|
|
98
|
+
validatorMinStake: '0',
|
|
99
|
+
hasUnstaking: hasUnstakingInfo,
|
|
100
|
+
validatorIdentity: identity
|
|
101
|
+
});
|
|
86
102
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
if (unstakingInfo && Object.values(unstakingInfo).length > 0) {
|
|
98
|
-
const _currentBlockInfo = await substrateApi.api.rpc.chain.getHeader();
|
|
99
|
-
const currentBlockInfo = _currentBlockInfo.toPrimitive();
|
|
100
|
-
const currentBlockNumber = currentBlockInfo.number;
|
|
101
|
-
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
102
|
-
const blockPerRound = parseFloat(_blockPerRound);
|
|
103
|
-
const nearestUnstakingBlock = Object.keys(unstakingInfo)[0];
|
|
104
|
-
const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
|
|
105
|
-
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
103
|
+
if (hasUnstakingInfo) {
|
|
104
|
+
const _currentBlockInfo = await substrateApi.api.rpc.chain.getHeader();
|
|
105
|
+
const currentBlockInfo = _currentBlockInfo.toPrimitive();
|
|
106
|
+
const currentBlockNumber = currentBlockInfo.number;
|
|
107
|
+
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
108
|
+
const blockPerRound = parseFloat(_blockPerRound);
|
|
109
|
+
for (const [unstakingBlock, unstakingAmount] of Object.entries(unstakingInfo)) {
|
|
110
|
+
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
106
111
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
const isClaimable = parseInt(unstakingBlock) - currentBlockNumber < 0;
|
|
113
|
+
const remainingBlock = parseInt(unstakingBlock) - currentBlockNumber;
|
|
114
|
+
const waitingTime = remainingBlock * blockDuration;
|
|
115
|
+
unstakingList.push({
|
|
116
|
+
chain: chainInfo.slug,
|
|
117
|
+
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
118
|
+
claimable: unstakingAmount.toString(),
|
|
119
|
+
waitingTime,
|
|
120
|
+
validatorAddress: undefined
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
117
124
|
}
|
|
118
125
|
const stakingStatus = (0, _utils.getEarningStatusByNominations)(new _util.BN(activeStake), nominationList);
|
|
119
126
|
return {
|
|
@@ -210,33 +217,61 @@ async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
210
217
|
}
|
|
211
218
|
async function getAmplitudeCollatorsInfo(chain, substrateApi) {
|
|
212
219
|
const chainApi = await substrateApi.isReady;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
220
|
+
|
|
221
|
+
// Noted: Krest do not have reward
|
|
222
|
+
if (_constants2._STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
223
|
+
const _allCollators = await chainApi.api.query.parachainStaking.candidatePool.entries();
|
|
224
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
225
|
+
const allCollators = [];
|
|
226
|
+
for (const _collator of _allCollators) {
|
|
227
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
228
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
229
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
230
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
231
|
+
allCollators.push({
|
|
232
|
+
address: collatorInfo.id,
|
|
233
|
+
totalStake: bnTotalStake.toString(),
|
|
234
|
+
ownStake: bnOwnStake.toString(),
|
|
235
|
+
otherStake: bnOtherStake.toString(),
|
|
236
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
237
|
+
commission: 0,
|
|
238
|
+
blocked: false,
|
|
239
|
+
isVerified: false,
|
|
240
|
+
minBond: '0',
|
|
241
|
+
chain,
|
|
242
|
+
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return allCollators;
|
|
246
|
+
} else {
|
|
247
|
+
const [_allCollators, _inflationConfig] = await Promise.all([chainApi.api.query.parachainStaking.candidatePool.entries(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
248
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
249
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
250
|
+
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
251
|
+
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
252
|
+
const allCollators = [];
|
|
253
|
+
for (const _collator of _allCollators) {
|
|
254
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
255
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
256
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
257
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
258
|
+
allCollators.push({
|
|
259
|
+
address: collatorInfo.id,
|
|
260
|
+
totalStake: bnTotalStake.toString(),
|
|
261
|
+
ownStake: bnOwnStake.toString(),
|
|
262
|
+
otherStake: bnOtherStake.toString(),
|
|
263
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
264
|
+
commission: 0,
|
|
265
|
+
expectedReturn: delegatorReturn,
|
|
266
|
+
blocked: false,
|
|
267
|
+
isVerified: false,
|
|
268
|
+
minBond: '0',
|
|
269
|
+
chain,
|
|
270
|
+
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return allCollators;
|
|
238
274
|
}
|
|
239
|
-
return allCollators;
|
|
240
275
|
}
|
|
241
276
|
async function getAmplitudeBondingExtrinsic(substrateApi, amount, selectedValidatorInfo, nominatorMetadata) {
|
|
242
277
|
const chainApi = await substrateApi.isReady;
|
|
@@ -23,7 +23,15 @@ var _utilCrypto = require("@polkadot/util-crypto");
|
|
|
23
23
|
function getSingleStakingAmplitude(substrateApi, address, chainInfoMap, chain, stakingCallback, nominatorStateCallback) {
|
|
24
24
|
return substrateApi.api.queryMulti([[substrateApi.api.query.parachainStaking.delegatorState, address], [substrateApi.api.query.parachainStaking.unstaking, address]], async _ref => {
|
|
25
25
|
let [_delegatorState, _unstaking] = _ref;
|
|
26
|
-
|
|
26
|
+
let delegatorState = [];
|
|
27
|
+
if (_constants._STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
28
|
+
const krestDelegatorState = _delegatorState.toPrimitive();
|
|
29
|
+
const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
|
|
30
|
+
delegatorState = delegatorState.concat(delegates);
|
|
31
|
+
} else {
|
|
32
|
+
const delegate = _delegatorState.toPrimitive();
|
|
33
|
+
delegatorState.push(delegate);
|
|
34
|
+
}
|
|
27
35
|
const unstakingInfo = _unstaking.toPrimitive();
|
|
28
36
|
const {
|
|
29
37
|
symbol
|
|
@@ -52,8 +60,13 @@ function getSingleStakingAmplitude(substrateApi, address, chainInfoMap, chain, s
|
|
|
52
60
|
unstakings: []
|
|
53
61
|
});
|
|
54
62
|
} else {
|
|
55
|
-
|
|
63
|
+
let activeBalance = _util.BN_ZERO;
|
|
56
64
|
let unstakingBalance = _util.BN_ZERO;
|
|
65
|
+
for (const delegate of delegatorState) {
|
|
66
|
+
var _delegate$amount;
|
|
67
|
+
const amount = new _util.BN((_delegate$amount = delegate.amount) === null || _delegate$amount === void 0 ? void 0 : _delegate$amount.toString());
|
|
68
|
+
activeBalance = activeBalance.add(amount);
|
|
69
|
+
}
|
|
57
70
|
if (unstakingInfo) {
|
|
58
71
|
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
59
72
|
const bnUnstakingAmount = new _util.BN(unstakingAmount.toString());
|
|
@@ -88,7 +101,15 @@ function getMultiStakingAmplitude(substrateApi, useAddresses, chainInfoMap, chai
|
|
|
88
101
|
const _unstakingStates = await substrateApi.api.query.parachainStaking.unstaking.multi(useAddresses);
|
|
89
102
|
await Promise.all(ledgers.map(async (_delegatorState, i) => {
|
|
90
103
|
const owner = (0, _utils2.reformatAddress)(useAddresses[i], 42);
|
|
91
|
-
|
|
104
|
+
let delegatorState = [];
|
|
105
|
+
if (_constants._STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
106
|
+
const krestDelegatorState = _delegatorState.toPrimitive();
|
|
107
|
+
const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
|
|
108
|
+
delegatorState = delegatorState.concat(delegates);
|
|
109
|
+
} else {
|
|
110
|
+
const delegate = _delegatorState.toPrimitive();
|
|
111
|
+
delegatorState.push(delegate);
|
|
112
|
+
}
|
|
92
113
|
const unstakingInfo = _unstakingStates[i].toPrimitive();
|
|
93
114
|
if (!delegatorState && !unstakingInfo) {
|
|
94
115
|
stakingCallback(chain, {
|
|
@@ -113,8 +134,13 @@ function getMultiStakingAmplitude(substrateApi, useAddresses, chainInfoMap, chai
|
|
|
113
134
|
unstakings: []
|
|
114
135
|
});
|
|
115
136
|
} else {
|
|
116
|
-
|
|
137
|
+
let activeBalance = _util.BN_ZERO;
|
|
117
138
|
let unstakingBalance = _util.BN_ZERO;
|
|
139
|
+
for (const delegate of delegatorState) {
|
|
140
|
+
var _delegate$amount2;
|
|
141
|
+
const amount = new _util.BN((_delegate$amount2 = delegate.amount) === null || _delegate$amount2 === void 0 ? void 0 : _delegate$amount2.toString());
|
|
142
|
+
activeBalance = activeBalance.add(amount);
|
|
143
|
+
}
|
|
118
144
|
if (unstakingInfo) {
|
|
119
145
|
Object.values(unstakingInfo).forEach(unstakingAmount => {
|
|
120
146
|
const bnUnstakingAmount = new _util.BN(unstakingAmount.toString());
|
|
@@ -160,7 +186,7 @@ async function getAmplitudeUnclaimedStakingReward(substrateApiMap, addresses, ne
|
|
|
160
186
|
});
|
|
161
187
|
const unclaimedRewardList = [];
|
|
162
188
|
await Promise.all(chains.map(async chain => {
|
|
163
|
-
if (_constants._STAKING_CHAIN_GROUP.amplitude.includes(chain) && !_constants._STAKING_CHAIN_GROUP.kilt.includes(chain)) {
|
|
189
|
+
if (_constants._STAKING_CHAIN_GROUP.amplitude.includes(chain) && !_constants._STAKING_CHAIN_GROUP.kilt.includes(chain) && !_constants._STAKING_CHAIN_GROUP.krest_network.includes(chain)) {
|
|
164
190
|
const networkInfo = networks[chain];
|
|
165
191
|
const apiProps = await substrateApiMap[chain].isReady;
|
|
166
192
|
await Promise.all(useAddresses.map(async address => {
|
|
@@ -25,6 +25,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
25
25
|
}
|
|
26
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
27
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden', 'centrifuge'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden', 'centrifuge', 'manta_network'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
29
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
30
30
|
}
|
|
@@ -424,15 +424,32 @@ class KoniTabs {
|
|
|
424
424
|
} = _ref13;
|
|
425
425
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
426
426
|
const chainId = params[0].chainId;
|
|
427
|
+
const chainIdDec = parseInt(chainId, 16);
|
|
427
428
|
const evmState = await this.getEvmState(url);
|
|
428
429
|
if (evmState.chainId === chainId) {
|
|
429
430
|
return null;
|
|
430
431
|
}
|
|
431
|
-
const [networkKey] = this.#koniState.findNetworkKeyByChainId(
|
|
432
|
+
const [networkKey] = this.#koniState.findNetworkKeyByChainId(chainIdDec);
|
|
432
433
|
if (networkKey) {
|
|
433
434
|
await this.#koniState.switchEvmNetworkByUrl((0, _utils2.stripUrl)(url), networkKey);
|
|
434
435
|
} else {
|
|
435
|
-
|
|
436
|
+
const onlineData = await (0, _utils2.getEVMChainInfo)(chainIdDec);
|
|
437
|
+
if (onlineData) {
|
|
438
|
+
const chainData = {
|
|
439
|
+
chainId: chainId,
|
|
440
|
+
rpcUrls: onlineData.rpc.filter(url => url.startsWith('https://')),
|
|
441
|
+
chainName: onlineData.name,
|
|
442
|
+
blockExplorerUrls: onlineData.explorers.map(explorer => explorer.url),
|
|
443
|
+
nativeCurrency: onlineData.nativeCurrency,
|
|
444
|
+
requestId: id
|
|
445
|
+
};
|
|
446
|
+
await this.addEvmChain(id, url, {
|
|
447
|
+
method: 'wallet_addEthereumChain',
|
|
448
|
+
params: [chainData]
|
|
449
|
+
});
|
|
450
|
+
} else {
|
|
451
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'This network is currently not supported');
|
|
452
|
+
}
|
|
436
453
|
}
|
|
437
454
|
return null;
|
|
438
455
|
}
|
package/cjs/packageInfo.js
CHANGED
|
@@ -40,7 +40,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
40
40
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
41
41
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
42
42
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude'],
|
|
43
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari'],
|
|
43
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network'],
|
|
44
44
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
45
45
|
// perhaps there are some runtime updates
|
|
46
46
|
centrifuge: ['centrifuge']
|
|
@@ -97,7 +97,8 @@ const _STAKING_ERA_LENGTH_MAP = {
|
|
|
97
97
|
creditcoin: 24,
|
|
98
98
|
vara_network: 12,
|
|
99
99
|
goldberg_testnet: 24,
|
|
100
|
-
manta_network: 6
|
|
100
|
+
manta_network: 6,
|
|
101
|
+
krest_network: 4
|
|
101
102
|
};
|
|
102
103
|
exports._STAKING_ERA_LENGTH_MAP = _STAKING_ERA_LENGTH_MAP;
|
|
103
104
|
const _EXPECTED_BLOCK_TIME = {
|
|
@@ -11,7 +11,7 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
11
11
|
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
|
|
12
12
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network'],
|
|
13
13
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
14
|
-
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
|
|
14
|
+
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
|
|
15
15
|
// amplitude and kilt only share some common logic
|
|
16
16
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
17
17
|
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet'],
|
|
@@ -20,7 +20,8 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
20
20
|
// A0 has distinct tokenomics
|
|
21
21
|
ternoa: ['ternoa', 'ternoa_alphanet'],
|
|
22
22
|
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
|
|
23
|
-
lending: ['interlay']
|
|
23
|
+
lending: ['interlay'],
|
|
24
|
+
krest_network: ['krest_network']
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
@@ -247,7 +247,7 @@ class BifrostLiquidStakingPoolHandler extends _base.default {
|
|
|
247
247
|
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
248
248
|
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
249
249
|
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
250
|
-
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount,
|
|
250
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount, undefined, undefined).paymentInfo(_constants2.fakeAddress);
|
|
251
251
|
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
252
252
|
return {
|
|
253
253
|
amount: mintFeeInfo.partialFee.toString(),
|
|
@@ -264,7 +264,7 @@ class BifrostLiquidStakingPoolHandler extends _base.default {
|
|
|
264
264
|
const substrateApi = await this.substrateApi.isReady;
|
|
265
265
|
const inputTokenSlug = this.inputAsset;
|
|
266
266
|
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
267
|
-
const extrinsic = substrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount, undefined);
|
|
267
|
+
const extrinsic = substrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount, undefined, undefined);
|
|
268
268
|
return {
|
|
269
269
|
txChain: this.chain,
|
|
270
270
|
extrinsicType: _KoniTypes.ExtrinsicType.MINT_VDOT,
|
|
@@ -55,6 +55,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
55
55
|
const minDelegatorStake = substrateApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
56
56
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.stakeDuration.toString(); // in blocks
|
|
57
57
|
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
58
|
+
const maxUnstakeRequests = substrateApi.api.consts.parachainStaking.maxUnstakeRequests.toPrimitive();
|
|
58
59
|
const blockPerRound = parseFloat(_blockPerRound);
|
|
59
60
|
const roundTime = _constants._STAKING_ERA_LENGTH_MAP[this.chain] || _constants._STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
60
61
|
const blockDuration = roundTime / blockPerRound; // in hours
|
|
@@ -75,7 +76,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
75
76
|
slug: this.nativeToken.slug
|
|
76
77
|
}],
|
|
77
78
|
maxCandidatePerFarmer: parseInt(maxDelegations),
|
|
78
|
-
maxWithdrawalRequestPerFarmer:
|
|
79
|
+
maxWithdrawalRequestPerFarmer: maxUnstakeRequests,
|
|
79
80
|
// by default
|
|
80
81
|
earningThreshold: {
|
|
81
82
|
join: minDelegatorStake,
|
|
@@ -109,48 +110,54 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
109
110
|
const nominationList = [];
|
|
110
111
|
const unstakingList = [];
|
|
111
112
|
const minDelegatorStake = substrateApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
113
|
+
const hasUnstakingInfo = unstakingInfo && Object.values(unstakingInfo).length > 0;
|
|
112
114
|
let activeStake = '0';
|
|
113
115
|
let unstakingBalance = '0';
|
|
114
116
|
if (delegatorState) {
|
|
115
117
|
// delegatorState can be null while unstaking all
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
const identityPromises = delegatorState.map(delegate => (0, _utils2.parseIdentity)(substrateApi, delegate.owner));
|
|
119
|
+
const identities = await Promise.all(identityPromises);
|
|
120
|
+
for (let i = 0; i < delegatorState.length; i++) {
|
|
121
|
+
const delegate = delegatorState[i];
|
|
122
|
+
const [identity] = identities[i];
|
|
123
|
+
activeStake = delegate.amount.toString();
|
|
124
|
+
const bnActiveStake = new _util.BN(activeStake);
|
|
125
|
+
let delegationStatus = _types.EarningStatus.NOT_EARNING;
|
|
126
|
+
if (bnActiveStake.gt(_util.BN_ZERO) && bnActiveStake.gte(new _util.BN(minDelegatorStake))) {
|
|
127
|
+
delegationStatus = _types.EarningStatus.EARNING_REWARD;
|
|
128
|
+
}
|
|
129
|
+
nominationList.push({
|
|
130
|
+
status: delegationStatus,
|
|
131
|
+
chain: chainInfo.slug,
|
|
132
|
+
validatorAddress: delegate.owner,
|
|
133
|
+
activeStake: delegate.amount.toString(),
|
|
134
|
+
validatorMinStake: '0',
|
|
135
|
+
hasUnstaking: hasUnstakingInfo,
|
|
136
|
+
validatorIdentity: identity
|
|
137
|
+
});
|
|
122
138
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (unstakingInfo && Object.values(unstakingInfo).length > 0) {
|
|
134
|
-
const _currentBlockInfo = await substrateApi.api.rpc.chain.getHeader();
|
|
135
|
-
const currentBlockInfo = _currentBlockInfo.toPrimitive();
|
|
136
|
-
const currentBlockNumber = currentBlockInfo.number;
|
|
137
|
-
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
138
|
-
const blockPerRound = parseFloat(_blockPerRound);
|
|
139
|
-
const nearestUnstakingBlock = Object.keys(unstakingInfo)[0];
|
|
140
|
-
const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
|
|
141
|
-
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
139
|
+
if (hasUnstakingInfo) {
|
|
140
|
+
const _currentBlockInfo = await substrateApi.api.rpc.chain.getHeader();
|
|
141
|
+
const currentBlockInfo = _currentBlockInfo.toPrimitive();
|
|
142
|
+
const currentBlockNumber = currentBlockInfo.number;
|
|
143
|
+
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
144
|
+
const blockPerRound = parseFloat(_blockPerRound);
|
|
145
|
+
for (const [unstakingBlock, unstakingAmount] of Object.entries(unstakingInfo)) {
|
|
146
|
+
const blockDuration = (_constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
142
147
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const isClaimable = parseInt(unstakingBlock) - currentBlockNumber < 0;
|
|
149
|
+
const remainingBlock = parseInt(unstakingBlock) - currentBlockNumber;
|
|
150
|
+
const waitingTime = remainingBlock * blockDuration;
|
|
151
|
+
unstakingBalance = unstakingAmount.toString();
|
|
152
|
+
unstakingList.push({
|
|
153
|
+
chain: chainInfo.slug,
|
|
154
|
+
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
155
|
+
claimable: unstakingAmount.toString(),
|
|
156
|
+
waitingTime,
|
|
157
|
+
validatorAddress: undefined
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
154
161
|
}
|
|
155
162
|
const totalBalance = new _util.BN(activeStake).add(new _util.BN(unstakingBalance));
|
|
156
163
|
const stakingStatus = (0, _utils.getEarningStatusByNominations)(new _util.BN(activeStake), nominationList);
|
|
@@ -179,8 +186,20 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
179
186
|
const _unstakingStates = await substrateApi.api.query.parachainStaking.unstaking.multi(useAddresses);
|
|
180
187
|
await Promise.all(ledgers.map(async (_delegatorState, i) => {
|
|
181
188
|
const owner = (0, _utils3.reformatAddress)(useAddresses[i], 42);
|
|
182
|
-
|
|
189
|
+
let delegatorState = [];
|
|
183
190
|
const unstakingInfo = _unstakingStates[i].toPrimitive();
|
|
191
|
+
if (_constants2._STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
|
|
192
|
+
const krestDelegatorState = _delegatorState.toPrimitive();
|
|
193
|
+
const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
|
|
194
|
+
if (delegates) {
|
|
195
|
+
delegatorState = delegatorState.concat(delegates);
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
const delegate = _delegatorState.toPrimitive();
|
|
199
|
+
if (delegate) {
|
|
200
|
+
delegatorState.push(delegate);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
184
203
|
if (!delegatorState && !unstakingInfo) {
|
|
185
204
|
resultCallback({
|
|
186
205
|
...defaultInfo,
|
|
@@ -221,7 +240,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
221
240
|
let cancel = false;
|
|
222
241
|
const substrateApi = this.substrateApi;
|
|
223
242
|
await substrateApi.isReady;
|
|
224
|
-
if (!_constants2._STAKING_CHAIN_GROUP.kilt.includes(this.chain)) {
|
|
243
|
+
if (!_constants2._STAKING_CHAIN_GROUP.kilt.includes(this.chain) && !_constants2._STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
|
|
225
244
|
await Promise.all(useAddresses.map(async address => {
|
|
226
245
|
const _unclaimedReward = await substrateApi.api.query.parachainStaking.rewards(address);
|
|
227
246
|
if (cancel) {
|
|
@@ -247,33 +266,59 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
247
266
|
|
|
248
267
|
async getPoolTargets() {
|
|
249
268
|
const chainApi = await this.substrateApi.isReady;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
if (_constants2._STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
|
|
270
|
+
const _allCollators = await chainApi.api.query.parachainStaking.candidatePool.entries();
|
|
271
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
272
|
+
const allCollators = [];
|
|
273
|
+
for (const _collator of _allCollators) {
|
|
274
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
275
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
276
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
277
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
278
|
+
allCollators.push({
|
|
279
|
+
address: collatorInfo.id,
|
|
280
|
+
totalStake: bnTotalStake.toString(),
|
|
281
|
+
ownStake: bnOwnStake.toString(),
|
|
282
|
+
otherStake: bnOtherStake.toString(),
|
|
283
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
284
|
+
commission: 0,
|
|
285
|
+
blocked: false,
|
|
286
|
+
isVerified: false,
|
|
287
|
+
minBond: '0',
|
|
288
|
+
chain: this.chain,
|
|
289
|
+
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return allCollators;
|
|
293
|
+
} else {
|
|
294
|
+
const [_allCollators, _inflationConfig] = await Promise.all([chainApi.api.query.parachainStaking.candidatePool.entries(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
295
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
296
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
297
|
+
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
298
|
+
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
299
|
+
const allCollators = [];
|
|
300
|
+
for (const _collator of _allCollators) {
|
|
301
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
302
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
303
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
304
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
305
|
+
allCollators.push({
|
|
306
|
+
address: collatorInfo.id,
|
|
307
|
+
totalStake: bnTotalStake.toString(),
|
|
308
|
+
ownStake: bnOwnStake.toString(),
|
|
309
|
+
otherStake: bnOtherStake.toString(),
|
|
310
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
311
|
+
commission: 0,
|
|
312
|
+
expectedReturn: delegatorReturn,
|
|
313
|
+
blocked: false,
|
|
314
|
+
isVerified: false,
|
|
315
|
+
minBond: '0',
|
|
316
|
+
chain: this.chain,
|
|
317
|
+
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return allCollators;
|
|
275
321
|
}
|
|
276
|
-
return allCollators;
|
|
277
322
|
}
|
|
278
323
|
|
|
279
324
|
/* Get pool targets */
|