@subwallet/extension-base 1.2.16-0 → 1.2.17-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 +2 -1
- package/cjs/koni/api/staking/bonding/utils.js +15 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +38 -4
- package/constants/staking.js +2 -1
- package/koni/api/staking/bonding/utils.d.ts +1 -0
- package/koni/api/staking/bonding/utils.js +14 -0
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/earning-service/handlers/native-staking/relay-chain.js +39 -5
package/cjs/constants/staking.js
CHANGED
|
@@ -20,7 +20,8 @@ const PREDEFINED_EARNING_POOL = {
|
|
|
20
20
|
kusama: [80],
|
|
21
21
|
vara_network: [62, 29, 50],
|
|
22
22
|
aleph: [82],
|
|
23
|
-
availTuringTest: [11]
|
|
23
|
+
availTuringTest: [11],
|
|
24
|
+
avail_mainnet: [4]
|
|
24
25
|
};
|
|
25
26
|
exports.PREDEFINED_EARNING_POOL = PREDEFINED_EARNING_POOL;
|
|
26
27
|
const MAX_NOMINATIONS = '16';
|
|
@@ -26,6 +26,7 @@ exports.getRelayEraRewardMap = getRelayEraRewardMap;
|
|
|
26
26
|
exports.getRelayMaxNominations = getRelayMaxNominations;
|
|
27
27
|
exports.getRelayTopValidatorByPoints = getRelayTopValidatorByPoints;
|
|
28
28
|
exports.getRelayValidatorPointsMap = getRelayValidatorPointsMap;
|
|
29
|
+
exports.getRelayWaitingValidatorList = getRelayWaitingValidatorList;
|
|
29
30
|
exports.getStakingAvailableActionsByChain = getStakingAvailableActionsByChain;
|
|
30
31
|
exports.getStakingAvailableActionsByNominator = getStakingAvailableActionsByNominator;
|
|
31
32
|
exports.getSupportedDaysByHistoryDepth = getSupportedDaysByHistoryDepth;
|
|
@@ -436,6 +437,20 @@ function getRelayBlockedValidatorList(validators) {
|
|
|
436
437
|
}
|
|
437
438
|
return blockValidatorList;
|
|
438
439
|
}
|
|
440
|
+
function getRelayWaitingValidatorList(validators) {
|
|
441
|
+
const waitingValidators = [];
|
|
442
|
+
for (const validator of validators) {
|
|
443
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
444
|
+
const validatorAddress = validator[0].toHuman()[0];
|
|
445
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
446
|
+
const validatorPrefs = validator[1].toHuman();
|
|
447
|
+
const isBlocked = validatorPrefs.blocked;
|
|
448
|
+
if (!isBlocked) {
|
|
449
|
+
waitingValidators.push(validatorAddress);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return waitingValidators;
|
|
453
|
+
}
|
|
439
454
|
function getRelayEraRewardMap(eraRewardPointArray, startEraForPoints) {
|
|
440
455
|
const eraRewardMap = {};
|
|
441
456
|
for (const item of eraRewardPointArray) {
|
package/cjs/packageInfo.js
CHANGED
|
@@ -320,11 +320,20 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
320
320
|
const topValidatorList = (0, _utils.getRelayTopValidatorByPoints)(validatorPointsMap);
|
|
321
321
|
const validators = _validators;
|
|
322
322
|
const blockedValidatorList = (0, _utils.getRelayBlockedValidatorList)(validators);
|
|
323
|
+
const waitingValidatorList = (0, _utils.getRelayWaitingValidatorList)(validators);
|
|
324
|
+
const _waitingValidatorLedger = await chainApi.api.query.staking.ledger.multi(waitingValidatorList);
|
|
325
|
+
const waitingValidatorLedger = {};
|
|
326
|
+
if (_waitingValidatorLedger) {
|
|
327
|
+
waitingValidatorList.forEach((validator, i) => {
|
|
328
|
+
const validatorLedger = _waitingValidatorLedger[i].toPrimitive();
|
|
329
|
+
waitingValidatorLedger[validator] = new _bignumber.default(validatorLedger.total).toFixed();
|
|
330
|
+
});
|
|
331
|
+
}
|
|
323
332
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
324
333
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
325
334
|
const bnTotalEraStake = new _util.BN(_totalEraStake.toString());
|
|
326
335
|
const minBond = _minBond.toPrimitive();
|
|
327
|
-
const [totalStakeMap, allValidatorAddresses, validatorInfoList] = this.parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded);
|
|
336
|
+
const [totalStakeMap, allValidatorAddresses, validatorInfoList] = this.parseEraStakerData(_eraStakers, blockedValidatorList, waitingValidatorLedger, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded);
|
|
328
337
|
const extraInfoMap = {};
|
|
329
338
|
await Promise.all(allValidatorAddresses.map(async address => {
|
|
330
339
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -359,11 +368,15 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
359
368
|
const validatorStake = (0, _utils3.applyDecimal)(totalStakeMap[validator.address], decimals).toNumber();
|
|
360
369
|
return (0, _utils.calculateTernoaValidatorReturn)(rewardPerValidator.toNumber(), validatorStake, commission);
|
|
361
370
|
} else {
|
|
362
|
-
|
|
363
|
-
|
|
371
|
+
if (!totalStakeMap[validator.address]) {
|
|
372
|
+
return totalApy;
|
|
373
|
+
} else {
|
|
374
|
+
const bnValidatorStake = (0, _utils3.applyDecimal)(totalStakeMap[validator.address], decimals);
|
|
375
|
+
return (0, _utils.calculateValidatorStakedReturn)(totalApy, bnValidatorStake, bnAvgStake, commission);
|
|
376
|
+
}
|
|
364
377
|
}
|
|
365
378
|
}
|
|
366
|
-
parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded) {
|
|
379
|
+
parseEraStakerData(_eraStakers, blockedValidatorList, waitingValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded) {
|
|
367
380
|
const totalStakeMap = {};
|
|
368
381
|
const allValidatorAddresses = [];
|
|
369
382
|
const validatorInfoList = [];
|
|
@@ -413,6 +426,27 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
413
426
|
});
|
|
414
427
|
}
|
|
415
428
|
}
|
|
429
|
+
for (const waitingValidator of Object.keys(waitingValidatorList)) {
|
|
430
|
+
if (!allValidatorAddresses.includes(waitingValidator)) {
|
|
431
|
+
allValidatorAddresses.push(waitingValidator);
|
|
432
|
+
validatorInfoList.push({
|
|
433
|
+
address: waitingValidator,
|
|
434
|
+
totalStake: waitingValidatorList[waitingValidator],
|
|
435
|
+
ownStake: waitingValidatorList[waitingValidator],
|
|
436
|
+
otherStake: '0',
|
|
437
|
+
nominatorCount: 0,
|
|
438
|
+
// to be added later
|
|
439
|
+
commission: 0,
|
|
440
|
+
expectedReturn: 0,
|
|
441
|
+
blocked: false,
|
|
442
|
+
isVerified: false,
|
|
443
|
+
minBond: minBond.toString(),
|
|
444
|
+
isCrowded: false,
|
|
445
|
+
eraRewardPoint: '0',
|
|
446
|
+
topQuartile: false
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
416
450
|
return [totalStakeMap, allValidatorAddresses, validatorInfoList];
|
|
417
451
|
}
|
|
418
452
|
/* Get pool targets */
|
package/constants/staking.js
CHANGED
|
@@ -162,6 +162,7 @@ export declare function getSupportedDaysByHistoryDepth(erasPerDay: number, maxSu
|
|
|
162
162
|
export declare function getRelayValidatorPointsMap(eraRewardMap: Record<string, PalletStakingEraRewardPoints>): Record<string, BigNumber>;
|
|
163
163
|
export declare function getRelayTopValidatorByPoints(validatorPointsList: Record<string, BigNumber>): string[];
|
|
164
164
|
export declare function getRelayBlockedValidatorList(validators: any[]): string[];
|
|
165
|
+
export declare function getRelayWaitingValidatorList(validators: any[]): string[];
|
|
165
166
|
export declare function getRelayEraRewardMap(eraRewardPointArray: Codec[], startEraForPoints: number): Record<string, PalletStakingEraRewardPoints>;
|
|
166
167
|
export declare function getRelayMaxNominations(substrateApi: _SubstrateApi): Promise<string>;
|
|
167
168
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
@@ -393,6 +393,20 @@ export function getRelayBlockedValidatorList(validators) {
|
|
|
393
393
|
}
|
|
394
394
|
return blockValidatorList;
|
|
395
395
|
}
|
|
396
|
+
export function getRelayWaitingValidatorList(validators) {
|
|
397
|
+
const waitingValidators = [];
|
|
398
|
+
for (const validator of validators) {
|
|
399
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
400
|
+
const validatorAddress = validator[0].toHuman()[0];
|
|
401
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
402
|
+
const validatorPrefs = validator[1].toHuman();
|
|
403
|
+
const isBlocked = validatorPrefs.blocked;
|
|
404
|
+
if (!isBlocked) {
|
|
405
|
+
waitingValidators.push(validatorAddress);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return waitingValidators;
|
|
409
|
+
}
|
|
396
410
|
export function getRelayEraRewardMap(eraRewardPointArray, startEraForPoints) {
|
|
397
411
|
const eraRewardMap = {};
|
|
398
412
|
for (const item of eraRewardPointArray) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.
|
|
20
|
+
"version": "1.2.17-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2010,10 +2010,10 @@
|
|
|
2010
2010
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2011
2011
|
"@substrate/connect": "^0.8.9",
|
|
2012
2012
|
"@subwallet/chain-list": "0.2.75",
|
|
2013
|
-
"@subwallet/extension-base": "^1.2.
|
|
2014
|
-
"@subwallet/extension-chains": "^1.2.
|
|
2015
|
-
"@subwallet/extension-dapp": "^1.2.
|
|
2016
|
-
"@subwallet/extension-inject": "^1.2.
|
|
2013
|
+
"@subwallet/extension-base": "^1.2.17-0",
|
|
2014
|
+
"@subwallet/extension-chains": "^1.2.17-0",
|
|
2015
|
+
"@subwallet/extension-dapp": "^1.2.17-0",
|
|
2016
|
+
"@subwallet/extension-inject": "^1.2.17-0",
|
|
2017
2017
|
"@subwallet/keyring": "^0.1.5",
|
|
2018
2018
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
2019
2019
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.2.
|
|
10
|
+
version: '1.2.17-0'
|
|
11
11
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { BasicTxErrorType, ExtrinsicType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturnV2, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getAvgValidatorEraReward, getCommission, getMaxValidatorErrorMessage, getMinStakeErrorMessage, getRelayBlockedValidatorList, getRelayEraRewardMap, getRelayMaxNominations, getRelayTopValidatorByPoints, getRelayValidatorPointsMap, getSupportedDaysByHistoryDepth } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
6
|
+
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturnV2, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getAvgValidatorEraReward, getCommission, getMaxValidatorErrorMessage, getMinStakeErrorMessage, getRelayBlockedValidatorList, getRelayEraRewardMap, getRelayMaxNominations, getRelayTopValidatorByPoints, getRelayValidatorPointsMap, getRelayWaitingValidatorList, getSupportedDaysByHistoryDepth } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { _STAKING_CHAIN_GROUP, _UPDATED_RUNTIME_STAKING_GROUP, MaxEraRewardPointsEras } from '@subwallet/extension-base/services/earning-service/constants';
|
|
@@ -313,11 +313,20 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
313
313
|
const topValidatorList = getRelayTopValidatorByPoints(validatorPointsMap);
|
|
314
314
|
const validators = _validators;
|
|
315
315
|
const blockedValidatorList = getRelayBlockedValidatorList(validators);
|
|
316
|
+
const waitingValidatorList = getRelayWaitingValidatorList(validators);
|
|
317
|
+
const _waitingValidatorLedger = await chainApi.api.query.staking.ledger.multi(waitingValidatorList);
|
|
318
|
+
const waitingValidatorLedger = {};
|
|
319
|
+
if (_waitingValidatorLedger) {
|
|
320
|
+
waitingValidatorList.forEach((validator, i) => {
|
|
321
|
+
const validatorLedger = _waitingValidatorLedger[i].toPrimitive();
|
|
322
|
+
waitingValidatorLedger[validator] = new BigN(validatorLedger.total).toFixed();
|
|
323
|
+
});
|
|
324
|
+
}
|
|
316
325
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
317
326
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
318
327
|
const bnTotalEraStake = new BN(_totalEraStake.toString());
|
|
319
328
|
const minBond = _minBond.toPrimitive();
|
|
320
|
-
const [totalStakeMap, allValidatorAddresses, validatorInfoList] = this.parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded);
|
|
329
|
+
const [totalStakeMap, allValidatorAddresses, validatorInfoList] = this.parseEraStakerData(_eraStakers, blockedValidatorList, waitingValidatorLedger, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded);
|
|
321
330
|
const extraInfoMap = {};
|
|
322
331
|
await Promise.all(allValidatorAddresses.map(async address => {
|
|
323
332
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -352,11 +361,15 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
352
361
|
const validatorStake = applyDecimal(totalStakeMap[validator.address], decimals).toNumber();
|
|
353
362
|
return calculateTernoaValidatorReturn(rewardPerValidator.toNumber(), validatorStake, commission);
|
|
354
363
|
} else {
|
|
355
|
-
|
|
356
|
-
|
|
364
|
+
if (!totalStakeMap[validator.address]) {
|
|
365
|
+
return totalApy;
|
|
366
|
+
} else {
|
|
367
|
+
const bnValidatorStake = applyDecimal(totalStakeMap[validator.address], decimals);
|
|
368
|
+
return calculateValidatorStakedReturn(totalApy, bnValidatorStake, bnAvgStake, commission);
|
|
369
|
+
}
|
|
357
370
|
}
|
|
358
371
|
}
|
|
359
|
-
parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded) {
|
|
372
|
+
parseEraStakerData(_eraStakers, blockedValidatorList, waitingValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded) {
|
|
360
373
|
const totalStakeMap = {};
|
|
361
374
|
const allValidatorAddresses = [];
|
|
362
375
|
const validatorInfoList = [];
|
|
@@ -406,6 +419,27 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
406
419
|
});
|
|
407
420
|
}
|
|
408
421
|
}
|
|
422
|
+
for (const waitingValidator of Object.keys(waitingValidatorList)) {
|
|
423
|
+
if (!allValidatorAddresses.includes(waitingValidator)) {
|
|
424
|
+
allValidatorAddresses.push(waitingValidator);
|
|
425
|
+
validatorInfoList.push({
|
|
426
|
+
address: waitingValidator,
|
|
427
|
+
totalStake: waitingValidatorList[waitingValidator],
|
|
428
|
+
ownStake: waitingValidatorList[waitingValidator],
|
|
429
|
+
otherStake: '0',
|
|
430
|
+
nominatorCount: 0,
|
|
431
|
+
// to be added later
|
|
432
|
+
commission: 0,
|
|
433
|
+
expectedReturn: 0,
|
|
434
|
+
blocked: false,
|
|
435
|
+
isVerified: false,
|
|
436
|
+
minBond: minBond.toString(),
|
|
437
|
+
isCrowded: false,
|
|
438
|
+
eraRewardPoint: '0',
|
|
439
|
+
topQuartile: false
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
409
443
|
return [totalStakeMap, allValidatorAddresses, validatorInfoList];
|
|
410
444
|
}
|
|
411
445
|
/* Get pool targets */
|