@subwallet/extension-base 1.1.61-1 → 1.1.63-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/koni/background/handlers/Extension.js +21 -7
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -0
- package/cjs/services/chain-service/utils/index.js +3 -1
- 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/koni/background/handlers/Extension.js +21 -7
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -0
- package/services/chain-service/utils/index.js +3 -1
- 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
|
@@ -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({
|
|
@@ -10,6 +10,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
|
10
10
|
var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
|
|
11
11
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
12
12
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
+
var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
|
|
13
14
|
var _types = require("@subwallet/extension-base/types");
|
|
14
15
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
15
16
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
@@ -91,7 +92,8 @@ class NominationPoolHandler extends _base.default {
|
|
|
91
92
|
|
|
92
93
|
const supportedDays = (0, _utils.getSupportedDaysByHistoryDepth)(erasPerDay, parseInt(maxSupportedEras), parseInt(currentEra) / erasPerDay);
|
|
93
94
|
const startEra = parseInt(currentEra) - supportedDays * erasPerDay;
|
|
94
|
-
const [_EraStakeInfo, _totalIssuance, _auctionCounter, _minPoolJoin, ..._eraReward] = await Promise.all([substrateApi.api.query.staking.erasTotalStake.multi([parseInt(currentEra), parseInt(currentEra) - 1]), substrateApi.api.query.balances.totalIssuance(), (_substrateApi$api$
|
|
95
|
+
const [_maxPoolMember, _EraStakeInfo, _totalIssuance, _auctionCounter, _minPoolJoin, ..._eraReward] = await Promise.all([(_substrateApi$api$que2 = substrateApi.api.query.nominationPools) === null || _substrateApi$api$que2 === void 0 ? void 0 : _substrateApi$api$que2.maxPoolMembersPerPool(), substrateApi.api.query.staking.erasTotalStake.multi([parseInt(currentEra), parseInt(currentEra) - 1]), substrateApi.api.query.balances.totalIssuance(), (_substrateApi$api$que3 = substrateApi.api.query.auctions) === null || _substrateApi$api$que3 === void 0 ? void 0 : _substrateApi$api$que3.auctionCounter(), (_substrateApi$api$que4 = substrateApi.api.query.nominationPools) === null || _substrateApi$api$que4 === void 0 ? void 0 : _substrateApi$api$que4.minJoinBond(), substrateApi.api.query.staking.erasValidatorReward.multi([...Array(supportedDays).keys()].map(i => i + startEra))]);
|
|
96
|
+
const maxPoolMembers = _maxPoolMember ? parseInt(_maxPoolMember.toString()) : undefined;
|
|
95
97
|
const [_totalEraStake, _lastTotalStaked] = _EraStakeInfo;
|
|
96
98
|
const validatorEraReward = (0, _utils.getAvgValidatorEraReward)(supportedDays, _eraReward[0]);
|
|
97
99
|
const lastTotalStaked = _lastTotalStaked.toString();
|
|
@@ -137,7 +139,8 @@ class NominationPoolHandler extends _base.default {
|
|
|
137
139
|
// TODO recheck
|
|
138
140
|
unstakingPeriod: unlockingPeriod,
|
|
139
141
|
inflation: inflation
|
|
140
|
-
}
|
|
142
|
+
},
|
|
143
|
+
maxPoolMembers: maxPoolMembers || undefined
|
|
141
144
|
};
|
|
142
145
|
callback(data);
|
|
143
146
|
}));
|
|
@@ -167,7 +170,7 @@ class NominationPoolHandler extends _base.default {
|
|
|
167
170
|
const validatorList = nominations.targets;
|
|
168
171
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
169
172
|
let eraStakerOtherList = [];
|
|
170
|
-
if (
|
|
173
|
+
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
171
174
|
// todo: review all relaychains later
|
|
172
175
|
const _eraStaker = await substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress);
|
|
173
176
|
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
@@ -327,13 +330,13 @@ class NominationPoolHandler extends _base.default {
|
|
|
327
330
|
const nominationPools = [];
|
|
328
331
|
const _allPoolsInfo = await substrateApi.api.query.nominationPools.reversePoolIdLookup.entries();
|
|
329
332
|
await Promise.all(_allPoolsInfo.map(async _poolInfo => {
|
|
330
|
-
var _bondedPool$points;
|
|
333
|
+
var _substrateApi$api$que7, _bondedPool$points;
|
|
331
334
|
const poolAddressList = _poolInfo[0].toHuman();
|
|
332
335
|
const poolAddress = poolAddressList[0];
|
|
333
336
|
const poolId = _poolInfo[1].toPrimitive();
|
|
334
337
|
const poolsPalletId = substrateApi.api.consts.nominationPools.palletId.toString();
|
|
335
338
|
const poolStashAccount = (0, _utils.parsePoolStashAddress)(substrateApi.api, 0, poolId, poolsPalletId);
|
|
336
|
-
const [_nominations, _bondedPool, _metadata, _minimumActiveStake] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.bondedPools(poolId), substrateApi.api.query.nominationPools.metadata(poolId), substrateApi.api.query.staking.minimumActiveStake()]);
|
|
339
|
+
const [_nominations, _bondedPool, _metadata, _minimumActiveStake, _maxPoolMembers] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.bondedPools(poolId), substrateApi.api.query.nominationPools.metadata(poolId), substrateApi.api.query.staking.minimumActiveStake(), (_substrateApi$api$que7 = substrateApi.api.query.nominationPools) === null || _substrateApi$api$que7 === void 0 ? void 0 : _substrateApi$api$que7.maxPoolMembersPerPool()]);
|
|
337
340
|
const minimumActiveStake = _minimumActiveStake.toPrimitive();
|
|
338
341
|
const nominations = _nominations.toJSON();
|
|
339
342
|
const poolMetadata = _metadata.toPrimitive();
|
|
@@ -342,6 +345,7 @@ class NominationPoolHandler extends _base.default {
|
|
|
342
345
|
const isPoolOpen = bondedPool.state === 'Open';
|
|
343
346
|
const isPoolNominating = !!nominations && nominations.targets.length > 0;
|
|
344
347
|
const isPoolEarningReward = bondedPool.points > minimumActiveStake;
|
|
348
|
+
const maxPoolMembers = _maxPoolMembers ? parseInt(_maxPoolMembers.toString()) : undefined;
|
|
345
349
|
nominationPools.push({
|
|
346
350
|
id: poolId,
|
|
347
351
|
address: poolAddress,
|
|
@@ -350,7 +354,8 @@ class NominationPoolHandler extends _base.default {
|
|
|
350
354
|
roles: bondedPool.roles,
|
|
351
355
|
memberCounter: bondedPool.memberCounter,
|
|
352
356
|
state: bondedPool.state,
|
|
353
|
-
isProfitable: isPoolOpen && isPoolNominating && isPoolEarningReward
|
|
357
|
+
isProfitable: isPoolOpen && isPoolNominating && isPoolEarningReward,
|
|
358
|
+
isCrowded: maxPoolMembers ? bondedPool.memberCounter >= maxPoolMembers : false
|
|
354
359
|
});
|
|
355
360
|
}));
|
|
356
361
|
return nominationPools;
|
|
@@ -40,7 +40,7 @@ class EarningService {
|
|
|
40
40
|
yieldPositionSubject = new _rxjs.BehaviorSubject({});
|
|
41
41
|
yieldPositionListSubject = new _rxjs.BehaviorSubject([]); // virtual list of yieldPositionSubject with filter values
|
|
42
42
|
|
|
43
|
-
useOnlineCacheOnly =
|
|
43
|
+
useOnlineCacheOnly = false;
|
|
44
44
|
constructor(state) {
|
|
45
45
|
this.state = state;
|
|
46
46
|
this.dbService = state.dbService;
|
|
@@ -65,7 +65,7 @@ async function parseIdentity(substrateApi, address, children) {
|
|
|
65
65
|
if (substrateApi.api.query.identity) {
|
|
66
66
|
let identity;
|
|
67
67
|
const _parent = await substrateApi.api.query.identity.superOf(address);
|
|
68
|
-
const parentInfo = _parent.toHuman();
|
|
68
|
+
const parentInfo = _parent === null || _parent === void 0 ? void 0 : _parent.toHuman();
|
|
69
69
|
if (parentInfo) {
|
|
70
70
|
const [parentAddress, {
|
|
71
71
|
Raw: data
|
|
@@ -78,8 +78,16 @@ async function parseIdentity(substrateApi, address, children) {
|
|
|
78
78
|
return [compactResult(rs), isReasonable];
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
let identityInfo;
|
|
81
82
|
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
82
|
-
const
|
|
83
|
+
const identityOfMetadata = substrateApi.api.query.identity.identityOf.creator.meta;
|
|
84
|
+
const identityOfReturnType = substrateApi.api.registry.lookup.getName(identityOfMetadata.type.asMap.value);
|
|
85
|
+
if (identityOfReturnType === 'PalletIdentityRegistration') {
|
|
86
|
+
identityInfo = _identity.toHuman();
|
|
87
|
+
} else {
|
|
88
|
+
const _identityInfo = _identity === null || _identity === void 0 ? void 0 : _identity.toHuman();
|
|
89
|
+
identityInfo = _identityInfo ? _identityInfo[0] : undefined;
|
|
90
|
+
}
|
|
83
91
|
if (identityInfo) {
|
|
84
92
|
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t, _identityInfo$judgeme;
|
|
85
93
|
const displayName = (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
@@ -68,17 +68,25 @@ class PriceService {
|
|
|
68
68
|
})();
|
|
69
69
|
}
|
|
70
70
|
async calculatePriceMap() {
|
|
71
|
-
const
|
|
71
|
+
const {
|
|
72
|
+
price24hMap,
|
|
73
|
+
priceMap
|
|
74
|
+
} = this.rawPriceSubject.value;
|
|
72
75
|
const exchangeRateData = this.rawExchangeRateMap.value;
|
|
73
76
|
const currencyKey = this.currency.value;
|
|
74
|
-
if (Object.keys(
|
|
77
|
+
if (Object.keys(this.rawPriceSubject.value).length === 0) {
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
77
80
|
if (Object.keys(exchangeRateData).length === 0) {
|
|
78
81
|
return;
|
|
79
82
|
}
|
|
80
83
|
const finalPriceMap = {
|
|
81
|
-
|
|
84
|
+
priceMap: {
|
|
85
|
+
...priceMap
|
|
86
|
+
},
|
|
87
|
+
price24hMap: {
|
|
88
|
+
...price24hMap
|
|
89
|
+
},
|
|
82
90
|
currency: currencyKey,
|
|
83
91
|
exchangeRateMap: exchangeRateData,
|
|
84
92
|
currencyData: _staticData.staticData[_staticData.StaticKey.CURRENCY_SYMBOL][currencyKey || DEFAULT_CURRENCY]
|
|
@@ -87,8 +95,8 @@ class PriceService {
|
|
|
87
95
|
return finalPriceMap;
|
|
88
96
|
}
|
|
89
97
|
Object.keys(finalPriceMap.price24hMap).forEach(key => {
|
|
90
|
-
finalPriceMap.price24hMap[key]
|
|
91
|
-
finalPriceMap.priceMap[key]
|
|
98
|
+
finalPriceMap.price24hMap[key] *= exchangeRateData[currencyKey].exchange;
|
|
99
|
+
finalPriceMap.priceMap[key] *= exchangeRateData[currencyKey].exchange;
|
|
92
100
|
});
|
|
93
101
|
await this.dbService.updatePriceStore(finalPriceMap);
|
|
94
102
|
return finalPriceMap;
|
|
@@ -119,7 +127,7 @@ class PriceService {
|
|
|
119
127
|
this.priceIds = priceIds || this.getPriceIds();
|
|
120
128
|
|
|
121
129
|
// Update for tokens price
|
|
122
|
-
this.getTokenPrice(this.priceIds,
|
|
130
|
+
this.getTokenPrice(this.priceIds, DEFAULT_CURRENCY).then(() => {
|
|
123
131
|
this.refreshPriceMapByAction();
|
|
124
132
|
}).catch(e => {
|
|
125
133
|
console.error(e);
|
package/constants/staking.d.ts
CHANGED
package/constants/staking.js
CHANGED
|
@@ -8,4 +8,11 @@ export const PREDEFINED_STAKING_POOL = {
|
|
|
8
8
|
aleph: 82,
|
|
9
9
|
availTuringTest: 11
|
|
10
10
|
};
|
|
11
|
+
export const PREDEFINED_EARNING_POOL = {
|
|
12
|
+
polkadot: [39],
|
|
13
|
+
kusama: [80],
|
|
14
|
+
vara_network: [62, 29, 50],
|
|
15
|
+
aleph: [82],
|
|
16
|
+
availTuringTest: [11]
|
|
17
|
+
};
|
|
11
18
|
export const MAX_NOMINATIONS = '16';
|
|
@@ -2969,7 +2969,10 @@ export default class KoniExtension {
|
|
|
2969
2969
|
let registry = new TypeRegistry();
|
|
2970
2970
|
let isEvm = false;
|
|
2971
2971
|
if (isJsonPayload(payload)) {
|
|
2972
|
-
|
|
2972
|
+
/**
|
|
2973
|
+
* Get the metadata for the genesisHash
|
|
2974
|
+
* @todo: need to handle case metadata store in db
|
|
2975
|
+
*/
|
|
2973
2976
|
const currentMetadata = this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
|
|
2974
2977
|
|
|
2975
2978
|
// set the registry before calling the sign function
|
|
@@ -2978,12 +2981,23 @@ export default class KoniExtension {
|
|
|
2978
2981
|
registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
|
|
2979
2982
|
}
|
|
2980
2983
|
const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
|
|
2981
|
-
if (
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2984
|
+
if (!currentMetadata) {
|
|
2985
|
+
/*
|
|
2986
|
+
* Some networks must have metadata to signing,
|
|
2987
|
+
* so if the chain not active (cannot use metadata from api), it must be rejected
|
|
2988
|
+
* */
|
|
2989
|
+
if (chainInfo && (_API_OPTIONS_CHAIN_GROUP.avail.includes(chainInfo.slug) || _API_OPTIONS_CHAIN_GROUP.goldberg.includes(chainInfo.slug)) // The special case for chains that need metadata to signing
|
|
2990
|
+
) {
|
|
2991
|
+
// For case the chain does not have any provider
|
|
2992
|
+
if (!Object.keys(chainInfo.providers).length) {
|
|
2993
|
+
reject(new Error('{{chain}} network does not have any provider to connect, please update metadata from dApp'.replaceAll('{{chain}}', chainInfo.name)));
|
|
2994
|
+
return false;
|
|
2995
|
+
}
|
|
2996
|
+
const isChainActive = this.#koniState.getChainStateByKey(chainInfo.slug).active;
|
|
2997
|
+
if (!isChainActive) {
|
|
2998
|
+
reject(new Error('Please activate {{chain}} network before signing'.replaceAll('{{chain}}', chainInfo.name)));
|
|
2999
|
+
return false;
|
|
3000
|
+
}
|
|
2987
3001
|
registry = this.#koniState.getSubstrateApi(chainInfo.slug).api.registry;
|
|
2988
3002
|
}
|
|
2989
3003
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.63-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1870,10 +1870,10 @@
|
|
|
1870
1870
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1871
1871
|
"@substrate/connect": "^0.8.9",
|
|
1872
1872
|
"@subwallet/chain-list": "0.2.59",
|
|
1873
|
-
"@subwallet/extension-base": "^1.1.
|
|
1874
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1875
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1876
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1873
|
+
"@subwallet/extension-base": "^1.1.63-0",
|
|
1874
|
+
"@subwallet/extension-chains": "^1.1.63-0",
|
|
1875
|
+
"@subwallet/extension-dapp": "^1.1.63-0",
|
|
1876
|
+
"@subwallet/extension-inject": "^1.1.63-0",
|
|
1877
1877
|
"@subwallet/keyring": "^0.1.5",
|
|
1878
1878
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
1879
1879
|
"@walletconnect/sign-client": "^2.8.4",
|
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.1.
|
|
10
|
+
version: '1.1.63-0'
|
|
11
11
|
};
|
|
@@ -448,7 +448,9 @@ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
448
448
|
providerKey
|
|
449
449
|
} = randomizeProvider(currentChainInfo.providers);
|
|
450
450
|
currentChainState.currentProvider = providerKey;
|
|
451
|
-
|
|
451
|
+
if (currentChainState.active) {
|
|
452
|
+
needUpdateChainApiList.push(currentChainInfo);
|
|
453
|
+
}
|
|
452
454
|
}
|
|
453
455
|
needUpdate = true;
|
|
454
456
|
}
|
|
@@ -13,6 +13,7 @@ export declare const _STAKING_CHAIN_GROUP: {
|
|
|
13
13
|
krest_network: string[];
|
|
14
14
|
manta: string[];
|
|
15
15
|
};
|
|
16
|
+
export declare const _UPDATED_RUNTIME_STAKING_GROUP: string[];
|
|
16
17
|
export declare const MaxEraRewardPointsEras = 14;
|
|
17
18
|
export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
|
|
18
19
|
export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
|
|
@@ -18,6 +18,7 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
18
18
|
krest_network: ['krest_network'],
|
|
19
19
|
manta: ['manta_network']
|
|
20
20
|
};
|
|
21
|
+
export const _UPDATED_RUNTIME_STAKING_GROUP = ['kusama', 'polkadot', 'westend', 'availTuringTest', 'avail_mainnet'];
|
|
21
22
|
export const MaxEraRewardPointsEras = 14;
|
|
22
23
|
|
|
23
24
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
@@ -9,6 +9,8 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta
|
|
|
9
9
|
parseNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: ParachainStakingStakeOption[], unstakingInfo: Record<string, number>): Promise<Omit<YieldPositionInfo, keyof BaseYieldPositionInfo>>;
|
|
10
10
|
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
11
11
|
getPoolReward(useAddresses: string[], callBack: (rs: EarningRewardItem) => void): Promise<VoidFunction>;
|
|
12
|
+
getKrestPoolTargets(chainApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
13
|
+
getOtherPoolTargets(chainApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
12
14
|
getPoolTargets(): Promise<ValidatorInfo[]>;
|
|
13
15
|
get defaultSubmitStep(): YieldStepBaseInfo;
|
|
14
16
|
createJoinExtrinsic(data: SubmitJoinNativeStaking, positionInfo?: YieldPositionInfo, bondDest?: string): Promise<[TransactionData, YieldTokenBaseInfo]>;
|
|
@@ -38,6 +38,7 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta
|
|
|
38
38
|
await defaultCallback();
|
|
39
39
|
const substrateApi = await this.substrateApi.isReady;
|
|
40
40
|
const unsub = await substrateApi.api.query.parachainStaking.round(async _round => {
|
|
41
|
+
var _substrateApi$api$con;
|
|
41
42
|
if (cancel) {
|
|
42
43
|
unsub();
|
|
43
44
|
return;
|
|
@@ -49,6 +50,7 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta
|
|
|
49
50
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.stakeDuration.toString(); // in blocks
|
|
50
51
|
const _blockPerRound = substrateApi.api.consts.parachainStaking.defaultBlocksPerRound.toString();
|
|
51
52
|
const maxUnstakeRequests = substrateApi.api.consts.parachainStaking.maxUnstakeRequests.toPrimitive();
|
|
53
|
+
const maxDelegatorsPerCollator = (_substrateApi$api$con = substrateApi.api.consts.parachainStaking.maxDelegatorsPerCollator) === null || _substrateApi$api$con === void 0 ? void 0 : _substrateApi$api$con.toString();
|
|
52
54
|
const blockPerRound = parseFloat(_blockPerRound);
|
|
53
55
|
const roundTime = _STAKING_ERA_LENGTH_MAP[this.chain] || _STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
54
56
|
const blockDuration = roundTime / blockPerRound; // in hours
|
|
@@ -85,7 +87,8 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta
|
|
|
85
87
|
totalApy: undefined,
|
|
86
88
|
// TODO recheck
|
|
87
89
|
unstakingPeriod
|
|
88
|
-
}
|
|
90
|
+
},
|
|
91
|
+
maxPoolMembers: maxDelegatorsPerCollator ? parseInt(maxDelegatorsPerCollator) : undefined
|
|
89
92
|
};
|
|
90
93
|
callback(data);
|
|
91
94
|
});
|
|
@@ -259,60 +262,97 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta
|
|
|
259
262
|
|
|
260
263
|
/* Get pool targets */
|
|
261
264
|
|
|
265
|
+
async getKrestPoolTargets(chainApi) {
|
|
266
|
+
var _chainApi$api$consts$;
|
|
267
|
+
const _allCollators = await chainApi.api.query.parachainStaking.candidatePool.entries();
|
|
268
|
+
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
269
|
+
const maxDelegatorsPerCollator = (_chainApi$api$consts$ = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator) === null || _chainApi$api$consts$ === void 0 ? void 0 : _chainApi$api$consts$.toString();
|
|
270
|
+
const identityPromises = _allCollators.map(collator => {
|
|
271
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
272
|
+
const address = collatorInfo.id;
|
|
273
|
+
return parseIdentity(chainApi, address);
|
|
274
|
+
});
|
|
275
|
+
const identities = await Promise.all(identityPromises);
|
|
276
|
+
return _allCollators.map((_collator, i) => {
|
|
277
|
+
const [identity] = identities[i];
|
|
278
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
279
|
+
const bnTotalStake = new BN(collatorInfo.total);
|
|
280
|
+
const bnOwnStake = new BN(collatorInfo.stake);
|
|
281
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
282
|
+
const isFullDelegatorsSet = collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator);
|
|
283
|
+
let minDelegate = new BN(minDelegatorStake);
|
|
284
|
+
if (isFullDelegatorsSet) {
|
|
285
|
+
const delegatorAmounts = collatorInfo.delegators.map(delegator => new BN(delegator.amount));
|
|
286
|
+
const sortedAmounts = delegatorAmounts.sort((a, b) => a.cmp(b));
|
|
287
|
+
const minDelegateInSet = sortedAmounts[0];
|
|
288
|
+
minDelegate = minDelegate.lt(minDelegateInSet) ? minDelegateInSet : minDelegate;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
address: collatorInfo.id,
|
|
292
|
+
totalStake: bnTotalStake.toString(),
|
|
293
|
+
ownStake: bnOwnStake.toString(),
|
|
294
|
+
otherStake: bnOtherStake.toString(),
|
|
295
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
296
|
+
commission: 0,
|
|
297
|
+
blocked: false,
|
|
298
|
+
isVerified: false,
|
|
299
|
+
minBond: minDelegate.toString(),
|
|
300
|
+
chain: this.chain,
|
|
301
|
+
isCrowded: isFullDelegatorsSet,
|
|
302
|
+
identity
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async getOtherPoolTargets(chainApi) {
|
|
307
|
+
const [_allCollators, _inflationConfig] = await Promise.all([chainApi.api.query.parachainStaking.candidatePool.entries(), chainApi.api.query.parachainStaking.inflationConfig()]);
|
|
308
|
+
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
309
|
+
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
310
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
311
|
+
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
312
|
+
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
313
|
+
const identityPromises = _allCollators.map(collator => {
|
|
314
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
315
|
+
const address = collatorInfo.id;
|
|
316
|
+
return parseIdentity(chainApi, address);
|
|
317
|
+
});
|
|
318
|
+
const identities = await Promise.all(identityPromises);
|
|
319
|
+
return _allCollators.map((_collator, i) => {
|
|
320
|
+
const [identity] = identities[i];
|
|
321
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
322
|
+
const bnTotalStake = new BN(collatorInfo.total);
|
|
323
|
+
const bnOwnStake = new BN(collatorInfo.stake);
|
|
324
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
325
|
+
const isFullDelegatorsSet = collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator);
|
|
326
|
+
let minDelegate = new BN(minDelegatorStake);
|
|
327
|
+
if (isFullDelegatorsSet) {
|
|
328
|
+
const delegatorAmounts = collatorInfo.delegators.map(delegator => new BN(delegator.amount));
|
|
329
|
+
const sortedAmounts = delegatorAmounts.sort((a, b) => a.cmp(b));
|
|
330
|
+
const minDelegateInSet = sortedAmounts[0];
|
|
331
|
+
minDelegate = minDelegate.lt(minDelegateInSet) ? minDelegateInSet : minDelegate;
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
address: collatorInfo.id,
|
|
335
|
+
totalStake: bnTotalStake.toString(),
|
|
336
|
+
ownStake: bnOwnStake.toString(),
|
|
337
|
+
otherStake: bnOtherStake.toString(),
|
|
338
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
339
|
+
commission: 0,
|
|
340
|
+
expectedReturn: delegatorReturn,
|
|
341
|
+
blocked: false,
|
|
342
|
+
isVerified: false,
|
|
343
|
+
minBond: minDelegate.toString(),
|
|
344
|
+
chain: this.chain,
|
|
345
|
+
isCrowded: isFullDelegatorsSet,
|
|
346
|
+
identity
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
}
|
|
262
350
|
async getPoolTargets() {
|
|
263
351
|
const chainApi = await this.substrateApi.isReady;
|
|
264
352
|
if (_STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
|
|
265
|
-
|
|
266
|
-
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
267
|
-
const allCollators = [];
|
|
268
|
-
for (const _collator of _allCollators) {
|
|
269
|
-
const collatorInfo = _collator[1].toPrimitive();
|
|
270
|
-
const bnTotalStake = new BN(collatorInfo.total);
|
|
271
|
-
const bnOwnStake = new BN(collatorInfo.stake);
|
|
272
|
-
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
273
|
-
allCollators.push({
|
|
274
|
-
address: collatorInfo.id,
|
|
275
|
-
totalStake: bnTotalStake.toString(),
|
|
276
|
-
ownStake: bnOwnStake.toString(),
|
|
277
|
-
otherStake: bnOtherStake.toString(),
|
|
278
|
-
nominatorCount: collatorInfo.delegators.length,
|
|
279
|
-
commission: 0,
|
|
280
|
-
blocked: false,
|
|
281
|
-
isVerified: false,
|
|
282
|
-
minBond: '0',
|
|
283
|
-
chain: this.chain,
|
|
284
|
-
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
return allCollators;
|
|
353
|
+
return this.getKrestPoolTargets(chainApi);
|
|
288
354
|
} else {
|
|
289
|
-
|
|
290
|
-
const maxDelegatorsPerCollator = chainApi.api.consts.parachainStaking.maxDelegatorsPerCollator.toString();
|
|
291
|
-
const inflationConfig = _inflationConfig.toHuman();
|
|
292
|
-
const rawDelegatorReturn = inflationConfig.delegator.rewardRate.annual;
|
|
293
|
-
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
294
|
-
const allCollators = [];
|
|
295
|
-
for (const _collator of _allCollators) {
|
|
296
|
-
const collatorInfo = _collator[1].toPrimitive();
|
|
297
|
-
const bnTotalStake = new BN(collatorInfo.total);
|
|
298
|
-
const bnOwnStake = new BN(collatorInfo.stake);
|
|
299
|
-
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
300
|
-
allCollators.push({
|
|
301
|
-
address: collatorInfo.id,
|
|
302
|
-
totalStake: bnTotalStake.toString(),
|
|
303
|
-
ownStake: bnOwnStake.toString(),
|
|
304
|
-
otherStake: bnOtherStake.toString(),
|
|
305
|
-
nominatorCount: collatorInfo.delegators.length,
|
|
306
|
-
commission: 0,
|
|
307
|
-
expectedReturn: delegatorReturn,
|
|
308
|
-
blocked: false,
|
|
309
|
-
isVerified: false,
|
|
310
|
-
minBond: '0',
|
|
311
|
-
chain: this.chain,
|
|
312
|
-
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return allCollators;
|
|
355
|
+
return this.getOtherPoolTargets(chainApi);
|
|
316
356
|
}
|
|
317
357
|
}
|
|
318
358
|
|
|
@@ -7,6 +7,8 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
7
7
|
subscribePoolInfo(callback: (data: YieldPoolInfo) => void): Promise<VoidFunction>;
|
|
8
8
|
parseNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: PalletParachainStakingDelegator): Promise<Omit<YieldPositionInfo, keyof BaseYieldPositionInfo>>;
|
|
9
9
|
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
10
|
+
getMantaPoolTargets(): Promise<ValidatorInfo[]>;
|
|
11
|
+
getParachainPoolTargets(): Promise<ValidatorInfo[]>;
|
|
10
12
|
getPoolTargets(): Promise<ValidatorInfo[]>;
|
|
11
13
|
createJoinExtrinsic(data: SubmitJoinNativeStaking, positionInfo?: YieldPositionInfo): Promise<[TransactionData, YieldTokenBaseInfo]>;
|
|
12
14
|
handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|