@subwallet/extension-base 1.1.61-1 → 1.1.62-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/cjs/constants/staking.js +9 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -0
- package/cjs/services/earning-service/constants/chains.js +3 -1
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +91 -51
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +119 -106
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +21 -14
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +11 -6
- package/cjs/services/earning-service/service.js +1 -1
- package/cjs/services/earning-service/utils/index.js +10 -2
- package/cjs/services/price-service/index.js +14 -6
- package/constants/staking.d.ts +1 -0
- package/constants/staking.js +7 -0
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -0
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +1 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +2 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +91 -51
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +2 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +119 -106
- package/services/earning-service/handlers/native-staking/relay-chain.js +22 -15
- package/services/earning-service/handlers/nomination-pool/index.js +11 -6
- package/services/earning-service/service.js +1 -1
- package/services/earning-service/utils/index.js +10 -2
- package/services/price-service/index.js +14 -6
- package/types/yield/info/chain/info.d.ts +2 -0
- package/types/yield/info/chain/target.d.ts +1 -0
- package/types/yield/info/pallet.d.ts +6 -0
- package/utils/staticData/currencySymbol.json +9 -9
package/cjs/constants/staking.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.PREDEFINED_STAKING_POOL = exports.MAX_NOMINATIONS = void 0;
|
|
6
|
+
exports.PREDEFINED_STAKING_POOL = exports.PREDEFINED_EARNING_POOL = exports.MAX_NOMINATIONS = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -15,5 +15,13 @@ const PREDEFINED_STAKING_POOL = {
|
|
|
15
15
|
availTuringTest: 11
|
|
16
16
|
};
|
|
17
17
|
exports.PREDEFINED_STAKING_POOL = PREDEFINED_STAKING_POOL;
|
|
18
|
+
const PREDEFINED_EARNING_POOL = {
|
|
19
|
+
polkadot: [39],
|
|
20
|
+
kusama: [80],
|
|
21
|
+
vara_network: [62, 29, 50],
|
|
22
|
+
aleph: [82],
|
|
23
|
+
availTuringTest: [11]
|
|
24
|
+
};
|
|
25
|
+
exports.PREDEFINED_EARNING_POOL = PREDEFINED_EARNING_POOL;
|
|
18
26
|
const MAX_NOMINATIONS = '16';
|
|
19
27
|
exports.MAX_NOMINATIONS = MAX_NOMINATIONS;
|
package/cjs/packageInfo.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._STAKING_CHAIN_GROUP = exports.ST_LIQUID_TOKEN_ABI = exports.MaxEraRewardPointsEras = exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = exports.MANTA_MIN_DELEGATION = void 0;
|
|
6
|
+
exports._UPDATED_RUNTIME_STAKING_GROUP = exports._STAKING_CHAIN_GROUP = exports.ST_LIQUID_TOKEN_ABI = exports.MaxEraRewardPointsEras = exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = exports.MANTA_MIN_DELEGATION = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -25,6 +25,8 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
25
25
|
manta: ['manta_network']
|
|
26
26
|
};
|
|
27
27
|
exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
|
|
28
|
+
const _UPDATED_RUNTIME_STAKING_GROUP = ['kusama', 'polkadot', 'westend', 'availTuringTest', 'avail_mainnet'];
|
|
29
|
+
exports._UPDATED_RUNTIME_STAKING_GROUP = _UPDATED_RUNTIME_STAKING_GROUP;
|
|
28
30
|
const MaxEraRewardPointsEras = 14;
|
|
29
31
|
|
|
30
32
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
@@ -45,6 +45,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
45
45
|
await defaultCallback();
|
|
46
46
|
const substrateApi = await this.substrateApi.isReady;
|
|
47
47
|
const unsub = await substrateApi.api.query.parachainStaking.round(async _round => {
|
|
48
|
+
var _substrateApi$api$con;
|
|
48
49
|
if (cancel) {
|
|
49
50
|
unsub();
|
|
50
51
|
return;
|
|
@@ -56,6 +57,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
56
57
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.stakeDuration.toString(); // in blocks
|
|
57
58
|
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
58
59
|
const maxUnstakeRequests = substrateApi.api.consts.parachainStaking.maxUnstakeRequests.toPrimitive();
|
|
60
|
+
const maxDelegatorsPerCollator = (_substrateApi$api$con = substrateApi.api.consts.parachainStaking.maxDelegatorsPerCollator) === null || _substrateApi$api$con === void 0 ? void 0 : _substrateApi$api$con.toString();
|
|
59
61
|
const blockPerRound = parseFloat(_blockPerRound);
|
|
60
62
|
const roundTime = _constants._STAKING_ERA_LENGTH_MAP[this.chain] || _constants._STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
61
63
|
const blockDuration = roundTime / blockPerRound; // in hours
|
|
@@ -92,7 +94,8 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
92
94
|
totalApy: undefined,
|
|
93
95
|
// TODO recheck
|
|
94
96
|
unstakingPeriod
|
|
95
|
-
}
|
|
97
|
+
},
|
|
98
|
+
maxPoolMembers: maxDelegatorsPerCollator ? parseInt(maxDelegatorsPerCollator) : undefined
|
|
96
99
|
};
|
|
97
100
|
callback(data);
|
|
98
101
|
});
|
|
@@ -266,60 +269,97 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
266
269
|
|
|
267
270
|
/* Get pool targets */
|
|
268
271
|
|
|
272
|
+
async getKrestPoolTargets(chainApi) {
|
|
273
|
+
var _chainApi$api$consts$;
|
|
274
|
+
const _allCollators = await chainApi.api.query.parachainStaking.candidatePool.entries();
|
|
275
|
+
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
276
|
+
const maxDelegatorsPerCollator = (_chainApi$api$consts$ = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator) === null || _chainApi$api$consts$ === void 0 ? void 0 : _chainApi$api$consts$.toString();
|
|
277
|
+
const identityPromises = _allCollators.map(collator => {
|
|
278
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
279
|
+
const address = collatorInfo.id;
|
|
280
|
+
return (0, _utils2.parseIdentity)(chainApi, address);
|
|
281
|
+
});
|
|
282
|
+
const identities = await Promise.all(identityPromises);
|
|
283
|
+
return _allCollators.map((_collator, i) => {
|
|
284
|
+
const [identity] = identities[i];
|
|
285
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
286
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
287
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
288
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
289
|
+
const isFullDelegatorsSet = collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator);
|
|
290
|
+
let minDelegate = new _util.BN(minDelegatorStake);
|
|
291
|
+
if (isFullDelegatorsSet) {
|
|
292
|
+
const delegatorAmounts = collatorInfo.delegators.map(delegator => new _util.BN(delegator.amount));
|
|
293
|
+
const sortedAmounts = delegatorAmounts.sort((a, b) => a.cmp(b));
|
|
294
|
+
const minDelegateInSet = sortedAmounts[0];
|
|
295
|
+
minDelegate = minDelegate.lt(minDelegateInSet) ? minDelegateInSet : minDelegate;
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
address: collatorInfo.id,
|
|
299
|
+
totalStake: bnTotalStake.toString(),
|
|
300
|
+
ownStake: bnOwnStake.toString(),
|
|
301
|
+
otherStake: bnOtherStake.toString(),
|
|
302
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
303
|
+
commission: 0,
|
|
304
|
+
blocked: false,
|
|
305
|
+
isVerified: false,
|
|
306
|
+
minBond: minDelegate.toString(),
|
|
307
|
+
chain: this.chain,
|
|
308
|
+
isCrowded: isFullDelegatorsSet,
|
|
309
|
+
identity
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async getOtherPoolTargets(chainApi) {
|
|
314
|
+
const [_allCollators, _inflationConfig] = await Promise.all([chainApi.api.query.parachainStaking.candidatePool.entries(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
315
|
+
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
316
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
317
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
318
|
+
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
319
|
+
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
320
|
+
const identityPromises = _allCollators.map(collator => {
|
|
321
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
322
|
+
const address = collatorInfo.id;
|
|
323
|
+
return (0, _utils2.parseIdentity)(chainApi, address);
|
|
324
|
+
});
|
|
325
|
+
const identities = await Promise.all(identityPromises);
|
|
326
|
+
return _allCollators.map((_collator, i) => {
|
|
327
|
+
const [identity] = identities[i];
|
|
328
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
329
|
+
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
330
|
+
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
331
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
332
|
+
const isFullDelegatorsSet = collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator);
|
|
333
|
+
let minDelegate = new _util.BN(minDelegatorStake);
|
|
334
|
+
if (isFullDelegatorsSet) {
|
|
335
|
+
const delegatorAmounts = collatorInfo.delegators.map(delegator => new _util.BN(delegator.amount));
|
|
336
|
+
const sortedAmounts = delegatorAmounts.sort((a, b) => a.cmp(b));
|
|
337
|
+
const minDelegateInSet = sortedAmounts[0];
|
|
338
|
+
minDelegate = minDelegate.lt(minDelegateInSet) ? minDelegateInSet : minDelegate;
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
address: collatorInfo.id,
|
|
342
|
+
totalStake: bnTotalStake.toString(),
|
|
343
|
+
ownStake: bnOwnStake.toString(),
|
|
344
|
+
otherStake: bnOtherStake.toString(),
|
|
345
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
346
|
+
commission: 0,
|
|
347
|
+
expectedReturn: delegatorReturn,
|
|
348
|
+
blocked: false,
|
|
349
|
+
isVerified: false,
|
|
350
|
+
minBond: minDelegate.toString(),
|
|
351
|
+
chain: this.chain,
|
|
352
|
+
isCrowded: isFullDelegatorsSet,
|
|
353
|
+
identity
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
269
357
|
async getPoolTargets() {
|
|
270
358
|
const chainApi = await this.substrateApi.isReady;
|
|
271
359
|
if (_constants2._STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
|
|
272
|
-
|
|
273
|
-
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
274
|
-
const allCollators = [];
|
|
275
|
-
for (const _collator of _allCollators) {
|
|
276
|
-
const collatorInfo = _collator[1].toPrimitive();
|
|
277
|
-
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
278
|
-
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
279
|
-
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
280
|
-
allCollators.push({
|
|
281
|
-
address: collatorInfo.id,
|
|
282
|
-
totalStake: bnTotalStake.toString(),
|
|
283
|
-
ownStake: bnOwnStake.toString(),
|
|
284
|
-
otherStake: bnOtherStake.toString(),
|
|
285
|
-
nominatorCount: collatorInfo.delegators.length,
|
|
286
|
-
commission: 0,
|
|
287
|
-
blocked: false,
|
|
288
|
-
isVerified: false,
|
|
289
|
-
minBond: '0',
|
|
290
|
-
chain: this.chain,
|
|
291
|
-
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
return allCollators;
|
|
360
|
+
return this.getKrestPoolTargets(chainApi);
|
|
295
361
|
} else {
|
|
296
|
-
|
|
297
|
-
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
298
|
-
const inflationConfig = _inflationConfig.toHuman();
|
|
299
|
-
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
300
|
-
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
301
|
-
const allCollators = [];
|
|
302
|
-
for (const _collator of _allCollators) {
|
|
303
|
-
const collatorInfo = _collator[1].toPrimitive();
|
|
304
|
-
const bnTotalStake = new _util.BN(collatorInfo.total);
|
|
305
|
-
const bnOwnStake = new _util.BN(collatorInfo.stake);
|
|
306
|
-
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
307
|
-
allCollators.push({
|
|
308
|
-
address: collatorInfo.id,
|
|
309
|
-
totalStake: bnTotalStake.toString(),
|
|
310
|
-
ownStake: bnOwnStake.toString(),
|
|
311
|
-
otherStake: bnOtherStake.toString(),
|
|
312
|
-
nominatorCount: collatorInfo.delegators.length,
|
|
313
|
-
commission: 0,
|
|
314
|
-
expectedReturn: delegatorReturn,
|
|
315
|
-
blocked: false,
|
|
316
|
-
isVerified: false,
|
|
317
|
-
minBond: '0',
|
|
318
|
-
chain: this.chain,
|
|
319
|
-
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
return allCollators;
|
|
362
|
+
return this.getOtherPoolTargets(chainApi);
|
|
323
363
|
}
|
|
324
364
|
}
|
|
325
365
|
|
|
@@ -61,7 +61,7 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
61
61
|
await defaultCallback();
|
|
62
62
|
await chainApi.isReady;
|
|
63
63
|
const unsub = await chainApi.api.query.parachainStaking.round(async _round => {
|
|
64
|
-
var _chainApi$api$consts, _chainApi$api$consts$, _chainApi$api$consts$2;
|
|
64
|
+
var _chainApi$api$consts, _chainApi$api$consts$, _chainApi$api$consts$2, _chainApi$api$consts$3, _chainApi$api$consts$4, _chainApi$api$query$p, _chainApi$api$query$p2;
|
|
65
65
|
if (cancel) {
|
|
66
66
|
unsub();
|
|
67
67
|
return;
|
|
@@ -70,11 +70,14 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
70
70
|
const round = (0, _utils3.parseRawNumber)(roundObj.current);
|
|
71
71
|
const maxDelegations = (_chainApi$api$consts = chainApi.api.consts) === null || _chainApi$api$consts === void 0 ? void 0 : (_chainApi$api$consts$ = _chainApi$api$consts.parachainStaking) === null || _chainApi$api$consts$ === void 0 ? void 0 : (_chainApi$api$consts$2 = _chainApi$api$consts$.maxDelegationsPerDelegator) === null || _chainApi$api$consts$2 === void 0 ? void 0 : _chainApi$api$consts$2.toString();
|
|
72
72
|
const unstakingDelay = chainApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
|
|
73
|
+
const maxTopDelegatorsPerCollator = (_chainApi$api$consts$3 = chainApi.api.consts.parachainStaking.maxTopDelegationsPerCandidate) === null || _chainApi$api$consts$3 === void 0 ? void 0 : _chainApi$api$consts$3.toPrimitive();
|
|
74
|
+
const maxDelegatorsPerCollator = (_chainApi$api$consts$4 = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator) === null || _chainApi$api$consts$4 === void 0 ? void 0 : _chainApi$api$consts$4.toPrimitive();
|
|
75
|
+
const maxPoolMembers = maxTopDelegatorsPerCollator || maxDelegatorsPerCollator || undefined;
|
|
73
76
|
let _unvestedAllocation;
|
|
74
77
|
if (chainApi.api.query.vesting && chainApi.api.query.vesting.totalUnvestedAllocation) {
|
|
75
78
|
_unvestedAllocation = await chainApi.api.query.vesting.totalUnvestedAllocation();
|
|
76
79
|
}
|
|
77
|
-
const [_totalStake, _totalIssuance, _inflation] = await Promise.all([chainApi.api.query.parachainStaking.staked(round), chainApi.api.query.balances.totalIssuance(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
80
|
+
const [_totalStake, _totalIssuance, _inflation] = await Promise.all([(_chainApi$api$query$p = chainApi.api.query.parachainStaking) !== null && _chainApi$api$query$p !== void 0 && _chainApi$api$query$p.staked ? (_chainApi$api$query$p2 = chainApi.api.query.parachainStaking) === null || _chainApi$api$query$p2 === void 0 ? void 0 : _chainApi$api$query$p2.staked(round) : chainApi.api.query.parachainStaking.total(), chainApi.api.query.balances.totalIssuance(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
78
81
|
let unvestedAllocation;
|
|
79
82
|
if (_unvestedAllocation) {
|
|
80
83
|
const rawUnvestedAllocation = _unvestedAllocation.toString();
|
|
@@ -120,7 +123,8 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
120
123
|
tvl: totalStake.toString(),
|
|
121
124
|
unstakingPeriod: unstakingPeriod,
|
|
122
125
|
inflation
|
|
123
|
-
}
|
|
126
|
+
},
|
|
127
|
+
maxPoolMembers
|
|
124
128
|
};
|
|
125
129
|
callback(data);
|
|
126
130
|
});
|
|
@@ -273,102 +277,44 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
273
277
|
/* Subscribe pool position */
|
|
274
278
|
|
|
275
279
|
/* Get pool targets */
|
|
276
|
-
|
|
277
|
-
|
|
280
|
+
async getMantaPoolTargets() {
|
|
281
|
+
var _this$chainInfo$subst;
|
|
278
282
|
const apiProps = await this.substrateApi.isReady;
|
|
279
283
|
const allCollators = [];
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const DECIMAL = (_this$chainInfo$subst = this.chainInfo.substrateInfo) === null || _this$chainInfo$subst === void 0 ? void 0 : _this$chainInfo$subst.decimals;
|
|
283
|
-
const POINTS_PER_BLOCK = _constants2.MANTA_VALIDATOR_POINTS_PER_BLOCK; // producing 1 block will get 20 points for validator
|
|
284
|
+
const DECIMAL = (_this$chainInfo$subst = this.chainInfo.substrateInfo) === null || _this$chainInfo$subst === void 0 ? void 0 : _this$chainInfo$subst.decimals;
|
|
285
|
+
const POINTS_PER_BLOCK = _constants2.MANTA_VALIDATOR_POINTS_PER_BLOCK; // producing 1 block will get 20 points for validator
|
|
284
286
|
|
|
285
|
-
|
|
287
|
+
const [_allCollators, _collatorCommission, _allCollatorsPool, _selectedCollators, _round, _totalIssuance, _inflationConfig] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission(), apiProps.api.query.parachainStaking.candidatePool(), apiProps.api.query.parachainStaking.selectedCandidates(), apiProps.api.query.parachainStaking.round(), apiProps.api.query.balances.totalIssuance(), apiProps.api.query.parachainStaking.inflationConfig()]);
|
|
286
288
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
// noted: Annual Inflation = Total Issuance * Annual Inflation Percent
|
|
290
|
+
const round = _round.toPrimitive();
|
|
291
|
+
const totalIssuance = _totalIssuance.toString();
|
|
292
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
293
|
+
const annualInflationPercent = parseFloat(inflationConfig.annual.ideal.slice(0, -1)) / 100;
|
|
294
|
+
const bnAnnualInflation = new _bignumber.default(totalIssuance).multipliedBy(annualInflationPercent);
|
|
293
295
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const collatorInfo = collator[1].toPrimitive();
|
|
309
|
-
const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
|
|
310
|
-
const bnOwnStake = new _util.BN(collatorInfo.bond);
|
|
311
|
-
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
312
|
-
const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
|
|
313
|
-
allCollators.push({
|
|
314
|
-
commission: 0,
|
|
315
|
-
address: collatorAddress,
|
|
316
|
-
totalStake: bnTotalStake.toString(),
|
|
317
|
-
ownStake: bnOwnStake.toString(),
|
|
318
|
-
otherStake: bnOtherStake.toString(),
|
|
319
|
-
nominatorCount: collatorInfo.delegationCount,
|
|
320
|
-
blocked: false,
|
|
321
|
-
isVerified: false,
|
|
322
|
-
minBond: bnMinBond.toString(),
|
|
323
|
-
chain: this.chain,
|
|
324
|
-
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
await Promise.all(allCollators.map(async collator => {
|
|
329
|
-
if (allCollatorsPool.includes(collator.address)) {
|
|
330
|
-
// noted: number of blocks = total points / points per block
|
|
331
|
-
const _collatorPoints = await apiProps.api.query.parachainStaking.awardedPts(parseInt(round.current) - 1, collator.address);
|
|
332
|
-
const collatorPoints = _collatorPoints.toPrimitive();
|
|
333
|
-
const blocksPreviousRound = collatorPoints / POINTS_PER_BLOCK;
|
|
334
|
-
collator.expectedReturn = calculateMantaNominatorReturn(DECIMAL, collatorCommissionPercent, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, new _bignumber.default(collator.totalStake), false);
|
|
335
|
-
}
|
|
336
|
-
}));
|
|
337
|
-
const extraInfoMap = {};
|
|
338
|
-
await Promise.all(allCollators.map(async collator => {
|
|
339
|
-
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils2.parseIdentity)(apiProps, collator.address)]);
|
|
340
|
-
const rawInfo = _info.toHuman();
|
|
341
|
-
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
342
|
-
extraInfoMap[collator.address] = {
|
|
343
|
-
identity,
|
|
344
|
-
isVerified: isReasonable,
|
|
345
|
-
active
|
|
346
|
-
};
|
|
347
|
-
}));
|
|
348
|
-
for (const validator of allCollators) {
|
|
349
|
-
validator.blocked = !extraInfoMap[validator.address].active;
|
|
350
|
-
validator.identity = extraInfoMap[validator.address].identity;
|
|
351
|
-
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
352
|
-
// @ts-ignore
|
|
353
|
-
validator.commission = collatorCommission;
|
|
354
|
-
}
|
|
355
|
-
return allCollators;
|
|
356
|
-
} else {
|
|
357
|
-
const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
|
|
358
|
-
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
359
|
-
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
360
|
-
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
361
|
-
for (const collator of _allCollators) {
|
|
362
|
-
const _collatorAddress = collator[0].toHuman();
|
|
363
|
-
const collatorAddress = _collatorAddress[0];
|
|
296
|
+
// noted: allCollatorsPool -> all candidate collators; selectedCollators -> candidate collators selected in current round
|
|
297
|
+
const allCollatorsPoolInfo = _allCollatorsPool.toPrimitive();
|
|
298
|
+
const allCollatorsPool = allCollatorsPoolInfo.map(collator => collator.owner.toString());
|
|
299
|
+
const selectedCollators = _selectedCollators.toPrimitive();
|
|
300
|
+
const totalActiveCollators = selectedCollators.length;
|
|
301
|
+
const bnCollatorExpectedBlocksPerRound = new _bignumber.default(round.length).dividedBy(allCollatorsPool.length);
|
|
302
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
303
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
304
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
305
|
+
const collatorCommissionPercent = collatorCommission / 100;
|
|
306
|
+
for (const collator of _allCollators) {
|
|
307
|
+
const _collatorAddress = collator[0].toHuman();
|
|
308
|
+
const collatorAddress = _collatorAddress[0];
|
|
309
|
+
if (allCollatorsPool.includes(collatorAddress)) {
|
|
364
310
|
const collatorInfo = collator[1].toPrimitive();
|
|
365
311
|
const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
|
|
366
312
|
const bnOwnStake = new _util.BN(collatorInfo.bond);
|
|
367
313
|
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
368
314
|
const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
|
|
315
|
+
const maxNominatorRewarded = parseInt(maxDelegationPerCollator);
|
|
369
316
|
allCollators.push({
|
|
370
317
|
commission: 0,
|
|
371
|
-
expectedReturn: 0,
|
|
372
318
|
address: collatorAddress,
|
|
373
319
|
totalStake: bnTotalStake.toString(),
|
|
374
320
|
ownStake: bnOwnStake.toString(),
|
|
@@ -378,28 +324,95 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
378
324
|
isVerified: false,
|
|
379
325
|
minBond: bnMinBond.toString(),
|
|
380
326
|
chain: this.chain,
|
|
381
|
-
isCrowded:
|
|
327
|
+
isCrowded: collatorInfo.delegationCount ? collatorInfo.delegationCount >= maxNominatorRewarded : false
|
|
382
328
|
});
|
|
383
329
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
active
|
|
393
|
-
};
|
|
394
|
-
}));
|
|
395
|
-
for (const validator of allCollators) {
|
|
396
|
-
validator.blocked = !extraInfoMap[validator.address].active;
|
|
397
|
-
validator.identity = extraInfoMap[validator.address].identity;
|
|
398
|
-
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
399
|
-
// @ts-ignore
|
|
400
|
-
validator.commission = collatorCommission;
|
|
330
|
+
}
|
|
331
|
+
await Promise.all(allCollators.map(async collator => {
|
|
332
|
+
if (allCollatorsPool.includes(collator.address)) {
|
|
333
|
+
// noted: number of blocks = total points / points per block
|
|
334
|
+
const _collatorPoints = await apiProps.api.query.parachainStaking.awardedPts(parseInt(round.current) - 1, collator.address);
|
|
335
|
+
const collatorPoints = _collatorPoints.toPrimitive();
|
|
336
|
+
const blocksPreviousRound = collatorPoints / POINTS_PER_BLOCK;
|
|
337
|
+
collator.expectedReturn = calculateMantaNominatorReturn(DECIMAL, collatorCommissionPercent, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, new _bignumber.default(collator.totalStake), false);
|
|
401
338
|
}
|
|
402
|
-
|
|
339
|
+
}));
|
|
340
|
+
const extraInfoMap = {};
|
|
341
|
+
await Promise.all(allCollators.map(async collator => {
|
|
342
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils2.parseIdentity)(apiProps, collator.address)]);
|
|
343
|
+
const rawInfo = _info.toHuman();
|
|
344
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
345
|
+
extraInfoMap[collator.address] = {
|
|
346
|
+
identity,
|
|
347
|
+
isVerified: isReasonable,
|
|
348
|
+
active
|
|
349
|
+
};
|
|
350
|
+
}));
|
|
351
|
+
for (const validator of allCollators) {
|
|
352
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
353
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
354
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
355
|
+
// @ts-ignore
|
|
356
|
+
validator.commission = collatorCommission;
|
|
357
|
+
}
|
|
358
|
+
return allCollators;
|
|
359
|
+
}
|
|
360
|
+
async getParachainPoolTargets() {
|
|
361
|
+
const apiProps = await this.substrateApi.isReady;
|
|
362
|
+
const allCollators = [];
|
|
363
|
+
const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
|
|
364
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
365
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
366
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
367
|
+
for (const collator of _allCollators) {
|
|
368
|
+
const _collatorAddress = collator[0].toHuman();
|
|
369
|
+
const collatorAddress = _collatorAddress[0];
|
|
370
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
371
|
+
const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
|
|
372
|
+
const bnOwnStake = new _util.BN(collatorInfo.bond);
|
|
373
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
374
|
+
const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
|
|
375
|
+
const maxNominatorRewarded = parseInt(maxDelegationPerCollator);
|
|
376
|
+
allCollators.push({
|
|
377
|
+
commission: 0,
|
|
378
|
+
expectedReturn: 0,
|
|
379
|
+
address: collatorAddress,
|
|
380
|
+
totalStake: bnTotalStake.toString(),
|
|
381
|
+
ownStake: bnOwnStake.toString(),
|
|
382
|
+
otherStake: bnOtherStake.toString(),
|
|
383
|
+
nominatorCount: collatorInfo.delegationCount,
|
|
384
|
+
blocked: false,
|
|
385
|
+
isVerified: false,
|
|
386
|
+
minBond: bnMinBond.toString(),
|
|
387
|
+
chain: this.chain,
|
|
388
|
+
isCrowded: collatorInfo.delegationCount ? collatorInfo.delegationCount >= maxNominatorRewarded : false
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const extraInfoMap = {};
|
|
392
|
+
await Promise.all(allCollators.map(async collator => {
|
|
393
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils2.parseIdentity)(apiProps, collator.address)]);
|
|
394
|
+
const rawInfo = _info.toHuman();
|
|
395
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
396
|
+
extraInfoMap[collator.address] = {
|
|
397
|
+
identity,
|
|
398
|
+
isVerified: isReasonable,
|
|
399
|
+
active
|
|
400
|
+
};
|
|
401
|
+
}));
|
|
402
|
+
for (const validator of allCollators) {
|
|
403
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
404
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
405
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
406
|
+
// @ts-ignore
|
|
407
|
+
validator.commission = collatorCommission;
|
|
408
|
+
}
|
|
409
|
+
return allCollators;
|
|
410
|
+
}
|
|
411
|
+
async getPoolTargets() {
|
|
412
|
+
if (_constants2._STAKING_CHAIN_GROUP.manta.includes(this.chain)) {
|
|
413
|
+
return this.getMantaPoolTargets();
|
|
414
|
+
} else {
|
|
415
|
+
return this.getParachainPoolTargets();
|
|
403
416
|
}
|
|
404
417
|
}
|
|
405
418
|
|
|
@@ -51,20 +51,22 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
51
51
|
await defaultCallback();
|
|
52
52
|
await substrateApi.isReady;
|
|
53
53
|
const unsub = await ((_substrateApi$api$que = substrateApi.api.query.staking) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.currentEra(async _currentEra => {
|
|
54
|
-
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$cal, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
54
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3, _substrateApi$api$cal, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
55
55
|
if (cancel) {
|
|
56
56
|
unsub();
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
let maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16';
|
|
60
|
+
const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
61
|
+
const maxNominatorRewarded = (_substrateApi$api$con3 = substrateApi.api.consts.staking.maxNominatorRewardedPerValidator) === null || _substrateApi$api$con3 === void 0 ? void 0 : _substrateApi$api$con3.toString();
|
|
60
62
|
const _maxNominationsByNominationQuota = await ((_substrateApi$api$cal = substrateApi.api.call.stakingApi) === null || _substrateApi$api$cal === void 0 ? void 0 : _substrateApi$api$cal.nominationsQuota(0)); // todo: review param. Currently return constant for all param.
|
|
61
63
|
const maxNominationsByNominationQuota = _maxNominationsByNominationQuota === null || _maxNominationsByNominationQuota === void 0 ? void 0 : _maxNominationsByNominationQuota.toString();
|
|
62
64
|
maxNominations = maxNominationsByNominationQuota !== null && maxNominationsByNominationQuota !== void 0 ? maxNominationsByNominationQuota : maxNominations;
|
|
63
65
|
const currentEra = _currentEra.toString();
|
|
64
66
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
65
67
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
66
|
-
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString();
|
|
67
|
-
const erasPerDay = 24 / _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug]; // Can be exactly calculate from babe.epochDuration * blockTime * staking.sessionsPerEra
|
|
68
|
+
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString(); // todo: handle case historyDepth undefined
|
|
69
|
+
const erasPerDay = 24 / _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default; // Can be exactly calculate from babe.epochDuration * blockTime * staking.sessionsPerEra
|
|
68
70
|
|
|
69
71
|
const supportedDays = (0, _utils.getSupportedDaysByHistoryDepth)(erasPerDay, parseInt(maxSupportedEras), parseInt(currentEra) / erasPerDay);
|
|
70
72
|
const startEra = parseInt(currentEra) - supportedDays * erasPerDay;
|
|
@@ -117,7 +119,8 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
117
119
|
// TODO recheck
|
|
118
120
|
unstakingPeriod: unlockingPeriod,
|
|
119
121
|
inflation: inflation
|
|
120
|
-
}
|
|
122
|
+
},
|
|
123
|
+
maxPoolMembers: unlimitedNominatorRewarded ? undefined : maxNominatorRewarded ? parseInt(maxNominatorRewarded) : undefined
|
|
121
124
|
};
|
|
122
125
|
callback(data);
|
|
123
126
|
}));
|
|
@@ -151,7 +154,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
151
154
|
let nominationStatus = _types.EarningStatus.NOT_EARNING;
|
|
152
155
|
let eraStakerOtherList = [];
|
|
153
156
|
let identity;
|
|
154
|
-
if (
|
|
157
|
+
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
155
158
|
// todo: review all relaychains later
|
|
156
159
|
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress)]);
|
|
157
160
|
identity = _identity;
|
|
@@ -305,7 +308,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
305
308
|
const endEraForPoints = parseInt(activeEra) - 1;
|
|
306
309
|
let startEraForPoints = Math.max(endEraForPoints - maxEraRewardPointsEras + 1, 0);
|
|
307
310
|
let _eraStakersPromise;
|
|
308
|
-
if (
|
|
311
|
+
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
309
312
|
// todo: review all relaychains later
|
|
310
313
|
_eraStakersPromise = chainApi.api.query.staking.erasStakersOverview.entries(parseInt(currentEra));
|
|
311
314
|
} else {
|
|
@@ -346,7 +349,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
346
349
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
347
350
|
const rawValidatorInfo = item[0].toHuman();
|
|
348
351
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
349
|
-
const rawValidatorStat = item[1].
|
|
352
|
+
const rawValidatorStat = item[1].toPrimitive();
|
|
350
353
|
const validatorAddress = rawValidatorInfo[1];
|
|
351
354
|
if (!blockValidatorList.includes(validatorAddress)) {
|
|
352
355
|
var _validatorPointsMap$v;
|
|
@@ -354,16 +357,20 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
354
357
|
if (topValidatorList.includes(validatorAddress)) {
|
|
355
358
|
isTopQuartile = true;
|
|
356
359
|
}
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
const bnTotalStake = new _util.BN(rawTotalStake.replaceAll(',', ''));
|
|
360
|
-
const bnOwnStake = new _util.BN(rawOwnStake.replaceAll(',', ''));
|
|
360
|
+
const bnTotalStake = new _util.BN(rawValidatorStat.total);
|
|
361
|
+
const bnOwnStake = new _util.BN(rawValidatorStat.own);
|
|
361
362
|
const otherStake = bnTotalStake.sub(bnOwnStake);
|
|
362
363
|
totalStakeMap[validatorAddress] = bnTotalStake;
|
|
363
364
|
let nominatorCount = 0;
|
|
364
|
-
if (
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
366
|
+
nominatorCount = rawValidatorStat.nominatorCount;
|
|
367
|
+
} else {
|
|
368
|
+
if ('others' in rawValidatorStat) {
|
|
369
|
+
// todo: handle interfaces and types better
|
|
370
|
+
// @ts-ignore
|
|
371
|
+
const others = rawValidatorStat.others;
|
|
372
|
+
nominatorCount = others.length;
|
|
373
|
+
}
|
|
367
374
|
}
|
|
368
375
|
allValidators.push(validatorAddress);
|
|
369
376
|
validatorInfoList.push({
|