@subwallet/extension-base 1.1.24-1 → 1.1.24-3
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/cjs/constants/staking.js +2 -1
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -4
- package/cjs/koni/api/staking/bonding/astar.js +4 -0
- package/cjs/koni/api/staking/bonding/index.js +4 -0
- package/cjs/koni/api/staking/bonding/paraChain.js +9 -20
- package/cjs/koni/api/staking/bonding/relayChain.js +41 -23
- package/cjs/koni/api/staking/bonding/utils.js +67 -16
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +4 -3
- package/cjs/services/history-service/subscan-history.js +2 -1
- package/constants/staking.js +2 -1
- package/koni/api/staking/bonding/amplitude.d.ts +3 -0
- package/koni/api/staking/bonding/amplitude.js +6 -4
- package/koni/api/staking/bonding/astar.d.ts +3 -0
- package/koni/api/staking/bonding/astar.js +4 -0
- package/koni/api/staking/bonding/index.d.ts +3 -0
- package/koni/api/staking/bonding/index.js +4 -0
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +9 -20
- package/koni/api/staking/bonding/relayChain.d.ts +3 -0
- package/koni/api/staking/bonding/relayChain.js +41 -24
- package/koni/api/staking/bonding/utils.d.ts +15 -2
- package/koni/api/staking/bonding/utils.js +69 -18
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +4 -3
- package/services/history-service/subscan-history.js +2 -1
|
@@ -1158,6 +1158,7 @@ export interface NominationPoolInfo extends Pick<PalletNominationPoolsBondedPool
|
|
|
1158
1158
|
address: string;
|
|
1159
1159
|
name?: string;
|
|
1160
1160
|
bondedAmount: string;
|
|
1161
|
+
isProfitable: boolean;
|
|
1161
1162
|
}
|
|
1162
1163
|
export declare enum UnstakingStatus {
|
|
1163
1164
|
CLAIMABLE = "CLAIMABLE",
|
package/cjs/constants/staking.js
CHANGED
|
@@ -75,8 +75,7 @@ async function subscribeAmplitudeNominatorMetadata(chainInfo, address, substrate
|
|
|
75
75
|
let activeStake = '0';
|
|
76
76
|
if (delegatorState) {
|
|
77
77
|
// delegatorState can be null while unstaking all
|
|
78
|
-
const
|
|
79
|
-
const identity = identityInfo ? (0, _utils.parseIdentity)(identityInfo) : undefined;
|
|
78
|
+
const [identity] = await (0, _utils.parseIdentity)(substrateApi, delegatorState.owner);
|
|
80
79
|
activeStake = delegatorState.amount.toString();
|
|
81
80
|
const bnActiveStake = new _util.BN(activeStake);
|
|
82
81
|
let delegationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
@@ -125,6 +124,10 @@ async function subscribeAmplitudeNominatorMetadata(chainInfo, address, substrate
|
|
|
125
124
|
unstakings: unstakingList
|
|
126
125
|
};
|
|
127
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Deprecated
|
|
130
|
+
* */
|
|
128
131
|
async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
129
132
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
130
133
|
return;
|
|
@@ -151,8 +154,7 @@ async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
151
154
|
let activeStake = '0';
|
|
152
155
|
if (delegatorState) {
|
|
153
156
|
// delegatorState can be null while unstaking all
|
|
154
|
-
const
|
|
155
|
-
const identity = identityInfo ? (0, _utils.parseIdentity)(identityInfo) : undefined;
|
|
157
|
+
const [identity] = await (0, _utils.parseIdentity)(substrateApi, delegatorState.owner);
|
|
156
158
|
activeStake = delegatorState.amount.toString();
|
|
157
159
|
const bnActiveStake = new _util.BN(activeStake);
|
|
158
160
|
let delegationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
@@ -164,6 +164,10 @@ async function subscribeAstarNominatorMetadata(chainInfo, address, substrateApi,
|
|
|
164
164
|
status: stakingStatus
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Deprecated
|
|
170
|
+
* */
|
|
167
171
|
async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
168
172
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
169
173
|
return;
|
|
@@ -48,6 +48,10 @@ async function getChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
48
48
|
}
|
|
49
49
|
return (0, _relayChain.getRelayChainStakingMetadata)(chainInfo, substrateApi);
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Deprecated
|
|
54
|
+
* */
|
|
51
55
|
async function getNominatorMetadata(chainInfo, address, substrateApi) {
|
|
52
56
|
if (_constants._STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
53
57
|
return (0, _astar.getAstarNominatorMetadata)(chainInfo, address, substrateApi);
|
|
@@ -45,7 +45,7 @@ function validateParaChainUnbondingCondition(amount, nominatorMetadata, chainSta
|
|
|
45
45
|
const bnChainMinStake = new _util.BN(chainStakingMetadata.minStake || '0');
|
|
46
46
|
const bnCollatorMinStake = new _util.BN(targetNomination.validatorMinStake || '0');
|
|
47
47
|
const bnMinStake = _util.BN.max(bnCollatorMinStake, bnChainMinStake);
|
|
48
|
-
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainStakingMetadata.chain);
|
|
48
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainStakingMetadata.chain, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type);
|
|
49
49
|
if (targetNomination.hasUnstaking) {
|
|
50
50
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
|
|
51
51
|
}
|
|
@@ -63,7 +63,7 @@ function validateParaChainBondingCondition(chainInfo, amount, selectedCollators,
|
|
|
63
63
|
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
64
64
|
const minStakeErrorMessage = (0, _utils.getMinStakeErrorMessage)(chainInfo, bnMinStake);
|
|
65
65
|
const maxValidatorErrorMessage = (0, _utils.getMaxValidatorErrorMessage)(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
|
|
66
|
-
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, true);
|
|
66
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type, true);
|
|
67
67
|
if (!nominatorMetadata || nominatorMetadata.status === _KoniTypes.StakingStatus.NOT_STAKING) {
|
|
68
68
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
69
69
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
@@ -170,13 +170,10 @@ async function subscribeParaChainNominatorMetadata(chainInfo, address, substrate
|
|
|
170
170
|
const roundInfo = _roundInfo.toPrimitive();
|
|
171
171
|
const currentRound = roundInfo.current;
|
|
172
172
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
173
|
-
|
|
174
|
-
const [_delegationScheduledRequests, _identity, _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), (_substrateApi$api$que = substrateApi.api.query.identity) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.identityOf(delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
173
|
+
const [_delegationScheduledRequests, [identity], _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), (0, _utils.parseIdentity)(substrateApi, delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
175
174
|
const collatorInfo = _collatorInfo.toPrimitive();
|
|
176
175
|
const minDelegation = collatorInfo === null || collatorInfo === void 0 ? void 0 : collatorInfo.lowestTopDelegationAmount.toString();
|
|
177
|
-
const identityInfo = _identity === null || _identity === void 0 ? void 0 : _identity.toHuman();
|
|
178
176
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
179
|
-
const identity = (0, _utils.parseIdentity)(identityInfo);
|
|
180
177
|
let hasUnstaking = false;
|
|
181
178
|
let delegationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
182
179
|
|
|
@@ -238,6 +235,10 @@ async function subscribeParaChainNominatorMetadata(chainInfo, address, substrate
|
|
|
238
235
|
unstakings: Object.values(unstakingMap)
|
|
239
236
|
};
|
|
240
237
|
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Deprecated
|
|
241
|
+
* */
|
|
241
242
|
async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
242
243
|
if ((0, _utils2._isChainEvmCompatible)(chainInfo) && !(0, _utilCrypto.isEthereumAddress)(address)) {
|
|
243
244
|
return;
|
|
@@ -261,14 +262,12 @@ async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
261
262
|
}
|
|
262
263
|
let bnTotalActiveStake = _util.BN_ZERO;
|
|
263
264
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
264
|
-
const [_delegationScheduledRequests,
|
|
265
|
+
const [_delegationScheduledRequests, [identity], _roundInfo, _collatorInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), (0, _utils.parseIdentity)(substrateApi, delegation.owner), chainApi.api.query.parachainStaking.round(), chainApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
265
266
|
const rawCollatorInfo = _collatorInfo.toHuman();
|
|
266
267
|
const minDelegation = (rawCollatorInfo === null || rawCollatorInfo === void 0 ? void 0 : rawCollatorInfo.lowestTopDelegationAmount).replaceAll(',', '');
|
|
267
|
-
const identityInfo = _identity.toHuman();
|
|
268
268
|
const roundInfo = _roundInfo.toPrimitive();
|
|
269
269
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
270
270
|
const currentRound = roundInfo.current;
|
|
271
|
-
const identity = (0, _utils.parseIdentity)(identityInfo);
|
|
272
271
|
let hasUnstaking = false;
|
|
273
272
|
let delegationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
274
273
|
|
|
@@ -358,19 +357,9 @@ async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
358
357
|
}
|
|
359
358
|
const extraInfoMap = {};
|
|
360
359
|
await Promise.all(allCollators.map(async collator => {
|
|
361
|
-
|
|
362
|
-
const [_info, _identity] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (_apiProps$api$query = apiProps.api.query) === null || _apiProps$api$query === void 0 ? void 0 : (_apiProps$api$query$i = _apiProps$api$query.identity) === null || _apiProps$api$query$i === void 0 ? void 0 : _apiProps$api$query$i.identityOf(collator.address) // some chains might not have identity pallet
|
|
363
|
-
]);
|
|
360
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils.parseIdentity)(apiProps, collator.address)]);
|
|
364
361
|
const rawInfo = _info.toHuman();
|
|
365
|
-
const rawIdentity = _identity ? _identity.toHuman() : null;
|
|
366
362
|
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
367
|
-
let isReasonable = false;
|
|
368
|
-
let identity;
|
|
369
|
-
if (rawIdentity !== null) {
|
|
370
|
-
// Check if identity is eth address
|
|
371
|
-
isReasonable = rawIdentity.judgements.length > 0;
|
|
372
|
-
identity = (0, _utils.parseIdentity)(rawIdentity);
|
|
373
|
-
}
|
|
374
363
|
extraInfoMap[collator.address] = {
|
|
375
364
|
identity,
|
|
376
365
|
isVerified: isReasonable,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -28,6 +29,7 @@ var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils")
|
|
|
28
29
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
29
30
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
30
31
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
32
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
31
33
|
var _i18next = require("i18next");
|
|
32
34
|
var _util = require("@polkadot/util");
|
|
33
35
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -58,7 +60,7 @@ function validatePoolBondingCondition(chainInfo, amount, selectedPool, address,
|
|
|
58
60
|
let bnTotalStake = new _util.BN(amount);
|
|
59
61
|
const bnMinStake = new _util.BN(chainStakingMetadata.minJoinNominationPool || '0');
|
|
60
62
|
const minStakeErrorMessage = (0, _utils.getMinStakeErrorMessage)(chainInfo, bnMinStake);
|
|
61
|
-
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, true);
|
|
63
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type, true);
|
|
62
64
|
if (selectedPool.state !== 'Open') {
|
|
63
65
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL));
|
|
64
66
|
}
|
|
@@ -214,13 +216,13 @@ async function subscribeRelayChainNominatorMetadata(chainInfo, address, substrat
|
|
|
214
216
|
if (nominations) {
|
|
215
217
|
const validatorList = nominations.targets;
|
|
216
218
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
217
|
-
var _chainApi$api$query$i;
|
|
218
219
|
let nominationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
219
|
-
const [
|
|
220
|
+
const [[identity], _eraStaker] = await Promise.all([(0, _utils.parseIdentity)(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
220
221
|
const eraStaker = _eraStaker.toPrimitive();
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
223
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
224
|
+
});
|
|
225
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
224
226
|
return nominator.who;
|
|
225
227
|
});
|
|
226
228
|
if (!topNominators.includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
@@ -278,6 +280,10 @@ async function subscribeRelayChainNominatorMetadata(chainInfo, address, substrat
|
|
|
278
280
|
isBondedBefore: bonded !== null
|
|
279
281
|
};
|
|
280
282
|
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Deprecated
|
|
286
|
+
* */
|
|
281
287
|
async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
282
288
|
var _chainApi$api$query10, _chainApi$api$query11, _chainApi$api$query12, _chainApi$api$query13, _chainApi$api$query14, _chainApi$api$query15, _chainApi$api$query16, _chainApi$api$query17, _chainApi$api$query18, _chainApi$api$query19, _chainApi$api$query20, _chainApi$api$query21, _chainApi$api$query22, _chainApi$api$query23;
|
|
283
289
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
@@ -315,11 +321,12 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
315
321
|
const validatorList = nominations.targets;
|
|
316
322
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
317
323
|
let nominationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
318
|
-
const [
|
|
324
|
+
const [[identity], _eraStaker] = await Promise.all([(0, _utils.parseIdentity)(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
319
325
|
const eraStaker = _eraStaker.toPrimitive();
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
326
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
327
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
328
|
+
});
|
|
329
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
323
330
|
return nominator.who;
|
|
324
331
|
});
|
|
325
332
|
if (!topNominators.includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
@@ -393,7 +400,10 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
|
|
|
393
400
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
394
401
|
const _eraStaker = await substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
395
402
|
const eraStaker = _eraStaker.toPrimitive();
|
|
396
|
-
const
|
|
403
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
404
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
405
|
+
});
|
|
406
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
397
407
|
return nominator.who;
|
|
398
408
|
}).slice(0, maxNominatorRewardedPerValidator);
|
|
399
409
|
if (topNominators.includes((0, _utils3.reformatAddress)(poolStashAccount, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
@@ -471,7 +481,10 @@ async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi)
|
|
|
471
481
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
472
482
|
const _eraStaker = await chainApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
473
483
|
const eraStaker = _eraStaker.toPrimitive();
|
|
474
|
-
const
|
|
484
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
485
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
486
|
+
});
|
|
487
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
475
488
|
return nominator.who;
|
|
476
489
|
}).slice(0, maxNominatorRewardedPerValidator);
|
|
477
490
|
if (topNominators.includes((0, _utils3.reformatAddress)(poolStashAccount, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
@@ -568,20 +581,14 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
568
581
|
}
|
|
569
582
|
const extraInfoMap = {};
|
|
570
583
|
await Promise.all(allValidators.map(async address => {
|
|
571
|
-
var _chainApi$api$query24, _chainApi$api$query25, _identityInfo$judgeme;
|
|
572
584
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
573
|
-
const [_commissionInfo,
|
|
585
|
+
const [_commissionInfo, [identity, isVerified]] = await Promise.all([chainApi.api.query.staking.validators(address), (0, _utils.parseIdentity)(chainApi, address)]);
|
|
574
586
|
const commissionInfo = _commissionInfo.toHuman();
|
|
575
|
-
const identityInfo = _identityInfo ? _identityInfo.toHuman() : null;
|
|
576
|
-
let identity;
|
|
577
|
-
if (identityInfo !== null) {
|
|
578
|
-
identity = (0, _utils.parseIdentity)(identityInfo);
|
|
579
|
-
}
|
|
580
587
|
extraInfoMap[address] = {
|
|
581
588
|
commission: commissionInfo.commission,
|
|
582
589
|
blocked: commissionInfo.blocked,
|
|
583
590
|
identity,
|
|
584
|
-
isVerified:
|
|
591
|
+
isVerified: isVerified
|
|
585
592
|
};
|
|
586
593
|
}));
|
|
587
594
|
const bnAvgStake = bnTotalEraStake.divn(validatorInfoList.length).div(bnDecimals);
|
|
@@ -613,10 +620,20 @@ async function getRelayPoolsInfo(chain, substrateApi) {
|
|
|
613
620
|
const poolAddressList = _poolInfo[0].toHuman();
|
|
614
621
|
const poolAddress = poolAddressList[0];
|
|
615
622
|
const poolId = _poolInfo[1].toPrimitive();
|
|
616
|
-
const
|
|
623
|
+
const poolsPalletId = substrateApi.api.consts.nominationPools.palletId.toString();
|
|
624
|
+
const poolStashAccount = (0, _utils.parsePoolStashAddress)(substrateApi.api, 0, poolId, poolsPalletId);
|
|
625
|
+
const [_nominations, _bondedPool, _metadata, _minimumActiveStake] = await Promise.all([chainApi.api.query.staking.nominators(poolStashAccount), chainApi.api.query.nominationPools.bondedPools(poolId), chainApi.api.query.nominationPools.metadata(poolId), chainApi.api.query.staking.minimumActiveStake()]);
|
|
626
|
+
const minimumActiveStake = _minimumActiveStake.toPrimitive();
|
|
627
|
+
const nominations = _nominations.toJSON();
|
|
617
628
|
const poolMetadata = _metadata.toPrimitive();
|
|
618
629
|
const bondedPool = _bondedPool.toPrimitive();
|
|
619
|
-
|
|
630
|
+
|
|
631
|
+
// const poolName = transformPoolName(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
|
|
632
|
+
|
|
633
|
+
const poolName = (0, _util.isHex)(poolMetadata) ? (0, _util.hexToString)(poolMetadata) : poolMetadata;
|
|
634
|
+
const isPoolOpen = bondedPool.state === 'Open';
|
|
635
|
+
const isPoolNominating = !!nominations && nominations.targets.length > 0;
|
|
636
|
+
const isPoolEarningReward = bondedPool.points > minimumActiveStake;
|
|
620
637
|
nominationPools.push({
|
|
621
638
|
id: poolId,
|
|
622
639
|
address: poolAddress,
|
|
@@ -624,7 +641,8 @@ async function getRelayPoolsInfo(chain, substrateApi) {
|
|
|
624
641
|
bondedAmount: ((_bondedPool$points = bondedPool.points) === null || _bondedPool$points === void 0 ? void 0 : _bondedPool$points.toString()) || '0',
|
|
625
642
|
roles: bondedPool.roles,
|
|
626
643
|
memberCounter: bondedPool.memberCounter,
|
|
627
|
-
state: bondedPool.state
|
|
644
|
+
state: bondedPool.state,
|
|
645
|
+
isProfitable: isPoolOpen && isPoolNominating && isPoolEarningReward
|
|
628
646
|
});
|
|
629
647
|
}));
|
|
630
648
|
return nominationPools;
|
|
@@ -57,22 +57,63 @@ function parsePoolStashAddress(api, index, poolId, poolsPalletId) {
|
|
|
57
57
|
function transformPoolName(input) {
|
|
58
58
|
return input.replace(/[^\x20-\x7E]/g, '');
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @returns
|
|
63
|
+
* <p>
|
|
64
|
+
* [0] - identity
|
|
65
|
+
* </p>
|
|
66
|
+
* <p>
|
|
67
|
+
* [1] - isReasonable (isVerified)
|
|
68
|
+
* </p>
|
|
69
|
+
* */
|
|
70
|
+
async function parseIdentity(substrateApi, address, children) {
|
|
71
|
+
const compactResult = rs => {
|
|
72
|
+
const result = [];
|
|
73
|
+
if (rs) {
|
|
74
|
+
result.push(rs);
|
|
75
|
+
}
|
|
76
|
+
if (children) {
|
|
77
|
+
result.push(children);
|
|
78
|
+
}
|
|
79
|
+
if (result.length > 0) {
|
|
80
|
+
return result.join('/');
|
|
71
81
|
} else {
|
|
72
|
-
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
if (substrateApi.api.query.identity) {
|
|
86
|
+
let identity;
|
|
87
|
+
const _parent = await substrateApi.api.query.identity.superOf(address);
|
|
88
|
+
const parentInfo = _parent.toHuman();
|
|
89
|
+
if (parentInfo) {
|
|
90
|
+
const [parentAddress, {
|
|
91
|
+
Raw: data
|
|
92
|
+
}] = parentInfo;
|
|
93
|
+
const child = (0, _util.isHex)(data) ? (0, _util.hexToString)(data) : data;
|
|
94
|
+
if (!(0, _utils2.isSameAddress)(address, parentAddress)) {
|
|
95
|
+
const [rs, isReasonable] = await parseIdentity(substrateApi, parentAddress, child);
|
|
96
|
+
return [compactResult(rs), isReasonable];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
100
|
+
const identityInfo = _identity.toHuman();
|
|
101
|
+
if (identityInfo) {
|
|
102
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
103
|
+
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;
|
|
104
|
+
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
105
|
+
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
106
|
+
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
107
|
+
const isReasonable = identityInfo.judgements.length > 0;
|
|
108
|
+
if (displayName && !displayName.startsWith('0x')) {
|
|
109
|
+
identity = displayName;
|
|
110
|
+
} else {
|
|
111
|
+
identity = twitter || web || riot;
|
|
112
|
+
}
|
|
113
|
+
return [compactResult(identity), isReasonable];
|
|
73
114
|
}
|
|
74
115
|
}
|
|
75
|
-
return
|
|
116
|
+
return [undefined, false];
|
|
76
117
|
}
|
|
77
118
|
function getInflationParams(networkKey) {
|
|
78
119
|
return _constants._KNOWN_CHAIN_INFLATION_PARAMS[networkKey] || _constants._SUBSTRATE_DEFAULT_INFLATION_PARAMS;
|
|
@@ -330,7 +371,7 @@ const getMaxValidatorErrorMessage = (chainInfo, max) => {
|
|
|
330
371
|
});
|
|
331
372
|
};
|
|
332
373
|
exports.getMaxValidatorErrorMessage = getMaxValidatorErrorMessage;
|
|
333
|
-
const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
374
|
+
const getExistUnstakeErrorMessage = (chain, type, isStakeMore) => {
|
|
334
375
|
const label = getValidatorLabel(chain);
|
|
335
376
|
if (!isStakeMore) {
|
|
336
377
|
switch (label) {
|
|
@@ -339,7 +380,12 @@ const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
|
339
380
|
case 'Collator':
|
|
340
381
|
return (0, _i18next.t)('You can unstake from a collator once');
|
|
341
382
|
case 'Validator':
|
|
342
|
-
|
|
383
|
+
{
|
|
384
|
+
if (type === _KoniTypes.StakingType.POOLED) {
|
|
385
|
+
return (0, _i18next.t)('You can unstake from a pool once');
|
|
386
|
+
}
|
|
387
|
+
return (0, _i18next.t)('You can unstake from a validator once');
|
|
388
|
+
}
|
|
343
389
|
}
|
|
344
390
|
} else {
|
|
345
391
|
switch (label) {
|
|
@@ -348,7 +394,12 @@ const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
|
348
394
|
case 'Collator':
|
|
349
395
|
return (0, _i18next.t)('You cannot stake more for a collator you are unstaking from');
|
|
350
396
|
case 'Validator':
|
|
351
|
-
|
|
397
|
+
{
|
|
398
|
+
if (type === _KoniTypes.StakingType.POOLED) {
|
|
399
|
+
return (0, _i18next.t)('You cannot stake more for a pool you are unstaking from');
|
|
400
|
+
}
|
|
401
|
+
return (0, _i18next.t)('You cannot stake more for a validator you are unstaking from');
|
|
402
|
+
}
|
|
352
403
|
}
|
|
353
404
|
}
|
|
354
405
|
};
|
package/cjs/packageInfo.js
CHANGED
|
@@ -66,13 +66,13 @@ const _NFT_CHAIN_GROUP = {
|
|
|
66
66
|
// Staking--------------------------------------------------------------------------------------------------------------
|
|
67
67
|
exports._NFT_CHAIN_GROUP = _NFT_CHAIN_GROUP;
|
|
68
68
|
const _STAKING_CHAIN_GROUP = {
|
|
69
|
-
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network'],
|
|
69
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
|
|
70
70
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari'],
|
|
71
71
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
72
72
|
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
|
|
73
73
|
// amplitude and kilt only share some common logic
|
|
74
74
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
75
|
-
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network'],
|
|
75
|
+
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet'],
|
|
76
76
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
77
77
|
aleph: ['aleph', 'alephTest'],
|
|
78
78
|
// A0 has distinct tokenomics
|
|
@@ -109,7 +109,8 @@ const _STAKING_ERA_LENGTH_MAP = {
|
|
|
109
109
|
edgeware: 6,
|
|
110
110
|
kate: 6,
|
|
111
111
|
creditcoin: 24,
|
|
112
|
-
vara_network: 12
|
|
112
|
+
vara_network: 12,
|
|
113
|
+
goldberg_testnet: 24
|
|
113
114
|
};
|
|
114
115
|
exports._STAKING_ERA_LENGTH_MAP = _STAKING_ERA_LENGTH_MAP;
|
|
115
116
|
const _PARACHAIN_INFLATION_DISTRIBUTION = {
|
|
@@ -7,6 +7,7 @@ exports.parseSubscanExtrinsicData = parseSubscanExtrinsicData;
|
|
|
7
7
|
exports.parseSubscanTransferData = parseSubscanTransferData;
|
|
8
8
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
9
|
var _subscanExtrinsicParserHelper = require("@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
11
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
11
12
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
12
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -83,7 +84,7 @@ function parseSubscanTransferData(address, transferItem, chainInfo) {
|
|
|
83
84
|
chainType,
|
|
84
85
|
from,
|
|
85
86
|
fromName: transferItem.from_account_display.display,
|
|
86
|
-
direction: address
|
|
87
|
+
direction: (0, _utils.isSameAddress)(address, from) ? _KoniTypes.TransactionDirection.SEND : _KoniTypes.TransactionDirection.RECEIVED,
|
|
87
88
|
blockNumber: transferItem.block_num,
|
|
88
89
|
blockHash: '',
|
|
89
90
|
chain: chainInfo.slug,
|
package/constants/staking.js
CHANGED
|
@@ -6,6 +6,9 @@ import { Codec } from '@polkadot/types/types';
|
|
|
6
6
|
export declare function subscribeAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
|
|
7
7
|
export declare function getAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
8
|
export declare function subscribeAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: ParachainStakingStakeOption, unstakingInfo: Record<string, number>): Promise<NominatorMetadata>;
|
|
9
|
+
/**
|
|
10
|
+
* Deprecated
|
|
11
|
+
* */
|
|
9
12
|
export declare function getAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
10
13
|
export declare function getAmplitudeCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
11
14
|
export declare function getAmplitudeBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, selectedValidatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
@@ -61,8 +61,7 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
|
|
|
61
61
|
let activeStake = '0';
|
|
62
62
|
if (delegatorState) {
|
|
63
63
|
// delegatorState can be null while unstaking all
|
|
64
|
-
const
|
|
65
|
-
const identity = identityInfo ? parseIdentity(identityInfo) : undefined;
|
|
64
|
+
const [identity] = await parseIdentity(substrateApi, delegatorState.owner);
|
|
66
65
|
activeStake = delegatorState.amount.toString();
|
|
67
66
|
const bnActiveStake = new BN(activeStake);
|
|
68
67
|
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
@@ -111,6 +110,10 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
|
|
|
111
110
|
unstakings: unstakingList
|
|
112
111
|
};
|
|
113
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Deprecated
|
|
116
|
+
* */
|
|
114
117
|
export async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
115
118
|
if (isEthereumAddress(address)) {
|
|
116
119
|
return;
|
|
@@ -137,8 +140,7 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
137
140
|
let activeStake = '0';
|
|
138
141
|
if (delegatorState) {
|
|
139
142
|
// delegatorState can be null while unstaking all
|
|
140
|
-
const
|
|
141
|
-
const identity = identityInfo ? parseIdentity(identityInfo) : undefined;
|
|
143
|
+
const [identity] = await parseIdentity(substrateApi, delegatorState.owner);
|
|
142
144
|
activeStake = delegatorState.amount.toString();
|
|
143
145
|
const bnActiveStake = new BN(activeStake);
|
|
144
146
|
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
@@ -6,6 +6,9 @@ import { Codec } from '@polkadot/types/types';
|
|
|
6
6
|
export declare function subscribeAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
|
|
7
7
|
export declare function getAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
8
|
export declare function subscribeAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, ledger: PalletDappsStakingAccountLedger): Promise<NominatorMetadata>;
|
|
9
|
+
/**
|
|
10
|
+
* Deprecated
|
|
11
|
+
* */
|
|
9
12
|
export declare function getAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
10
13
|
export declare function getAstarDappsInfo(networkKey: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
11
14
|
export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappInfo: ValidatorInfo): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
@@ -148,6 +148,10 @@ export async function subscribeAstarNominatorMetadata(chainInfo, address, substr
|
|
|
148
148
|
status: stakingStatus
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Deprecated
|
|
154
|
+
* */
|
|
151
155
|
export async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
152
156
|
if (isEthereumAddress(address)) {
|
|
153
157
|
return;
|
|
@@ -5,6 +5,9 @@ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/
|
|
|
5
5
|
export declare function validateUnbondingCondition(nominatorMetadata: NominatorMetadata, amount: string, chain: string, chainStakingMetadata: ChainStakingMetadata, selectedValidator?: string): TransactionError[];
|
|
6
6
|
export declare function validateBondingCondition(chainInfo: _ChainInfo, amount: string, selectedValidators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
7
7
|
export declare function getChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
|
+
/**
|
|
9
|
+
* Deprecated
|
|
10
|
+
* */
|
|
8
11
|
export declare function getNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
9
12
|
export declare function getValidatorsInfo(networkKey: string, substrateApi: _SubstrateApi, decimals: number, chainStakingMetadata: ChainStakingMetadata): Promise<ValidatorInfo[]>;
|
|
10
13
|
export declare function getNominationPoolsInfo(chain: string, substrateApi: _SubstrateApi): Promise<import("@subwallet/extension-base/background/KoniTypes").NominationPoolInfo[]>;
|
|
@@ -31,6 +31,10 @@ export async function getChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
31
31
|
}
|
|
32
32
|
return getRelayChainStakingMetadata(chainInfo, substrateApi);
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Deprecated
|
|
37
|
+
* */
|
|
34
38
|
export async function getNominatorMetadata(chainInfo, address, substrateApi) {
|
|
35
39
|
if (_STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
36
40
|
return getAstarNominatorMetadata(chainInfo, address, substrateApi);
|
|
@@ -9,6 +9,9 @@ export declare function validateParaChainBondingCondition(chainInfo: _ChainInfo,
|
|
|
9
9
|
export declare function subscribeParaChainStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
|
|
10
10
|
export declare function getParaChainStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
11
11
|
export declare function subscribeParaChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: PalletParachainStakingDelegator): Promise<NominatorMetadata>;
|
|
12
|
+
/**
|
|
13
|
+
* Deprecated
|
|
14
|
+
* */
|
|
12
15
|
export declare function getParaChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
13
16
|
export declare function getParachainCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
14
17
|
export declare function getParaBondingExtrinsic(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, amount: string, selectedCollatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
@@ -27,7 +27,7 @@ export function validateParaChainUnbondingCondition(amount, nominatorMetadata, c
|
|
|
27
27
|
const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
|
|
28
28
|
const bnCollatorMinStake = new BN(targetNomination.validatorMinStake || '0');
|
|
29
29
|
const bnMinStake = BN.max(bnCollatorMinStake, bnChainMinStake);
|
|
30
|
-
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainStakingMetadata.chain);
|
|
30
|
+
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainStakingMetadata.chain, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type);
|
|
31
31
|
if (targetNomination.hasUnstaking) {
|
|
32
32
|
errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
|
|
33
33
|
}
|
|
@@ -45,7 +45,7 @@ export function validateParaChainBondingCondition(chainInfo, amount, selectedCol
|
|
|
45
45
|
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
46
46
|
const minStakeErrorMessage = getMinStakeErrorMessage(chainInfo, bnMinStake);
|
|
47
47
|
const maxValidatorErrorMessage = getMaxValidatorErrorMessage(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
|
|
48
|
-
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, true);
|
|
48
|
+
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type, true);
|
|
49
49
|
if (!nominatorMetadata || nominatorMetadata.status === StakingStatus.NOT_STAKING) {
|
|
50
50
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
51
51
|
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
@@ -152,13 +152,10 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
152
152
|
const roundInfo = _roundInfo.toPrimitive();
|
|
153
153
|
const currentRound = roundInfo.current;
|
|
154
154
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
155
|
-
|
|
156
|
-
const [_delegationScheduledRequests, _identity, _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), (_substrateApi$api$que = substrateApi.api.query.identity) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.identityOf(delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
155
|
+
const [_delegationScheduledRequests, [identity], _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), parseIdentity(substrateApi, delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
157
156
|
const collatorInfo = _collatorInfo.toPrimitive();
|
|
158
157
|
const minDelegation = collatorInfo === null || collatorInfo === void 0 ? void 0 : collatorInfo.lowestTopDelegationAmount.toString();
|
|
159
|
-
const identityInfo = _identity === null || _identity === void 0 ? void 0 : _identity.toHuman();
|
|
160
158
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
161
|
-
const identity = parseIdentity(identityInfo);
|
|
162
159
|
let hasUnstaking = false;
|
|
163
160
|
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
164
161
|
|
|
@@ -220,6 +217,10 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
220
217
|
unstakings: Object.values(unstakingMap)
|
|
221
218
|
};
|
|
222
219
|
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Deprecated
|
|
223
|
+
* */
|
|
223
224
|
export async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
224
225
|
if (_isChainEvmCompatible(chainInfo) && !isEthereumAddress(address)) {
|
|
225
226
|
return;
|
|
@@ -243,14 +244,12 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
243
244
|
}
|
|
244
245
|
let bnTotalActiveStake = BN_ZERO;
|
|
245
246
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
246
|
-
const [_delegationScheduledRequests,
|
|
247
|
+
const [_delegationScheduledRequests, [identity], _roundInfo, _collatorInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), parseIdentity(substrateApi, delegation.owner), chainApi.api.query.parachainStaking.round(), chainApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
247
248
|
const rawCollatorInfo = _collatorInfo.toHuman();
|
|
248
249
|
const minDelegation = (rawCollatorInfo === null || rawCollatorInfo === void 0 ? void 0 : rawCollatorInfo.lowestTopDelegationAmount).replaceAll(',', '');
|
|
249
|
-
const identityInfo = _identity.toHuman();
|
|
250
250
|
const roundInfo = _roundInfo.toPrimitive();
|
|
251
251
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
252
252
|
const currentRound = roundInfo.current;
|
|
253
|
-
const identity = parseIdentity(identityInfo);
|
|
254
253
|
let hasUnstaking = false;
|
|
255
254
|
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
256
255
|
|
|
@@ -340,19 +339,9 @@ export async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
340
339
|
}
|
|
341
340
|
const extraInfoMap = {};
|
|
342
341
|
await Promise.all(allCollators.map(async collator => {
|
|
343
|
-
|
|
344
|
-
const [_info, _identity] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (_apiProps$api$query = apiProps.api.query) === null || _apiProps$api$query === void 0 ? void 0 : (_apiProps$api$query$i = _apiProps$api$query.identity) === null || _apiProps$api$query$i === void 0 ? void 0 : _apiProps$api$query$i.identityOf(collator.address) // some chains might not have identity pallet
|
|
345
|
-
]);
|
|
342
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), parseIdentity(apiProps, collator.address)]);
|
|
346
343
|
const rawInfo = _info.toHuman();
|
|
347
|
-
const rawIdentity = _identity ? _identity.toHuman() : null;
|
|
348
344
|
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
349
|
-
let isReasonable = false;
|
|
350
|
-
let identity;
|
|
351
|
-
if (rawIdentity !== null) {
|
|
352
|
-
// Check if identity is eth address
|
|
353
|
-
isReasonable = rawIdentity.judgements.length > 0;
|
|
354
|
-
identity = parseIdentity(rawIdentity);
|
|
355
|
-
}
|
|
356
345
|
extraInfoMap[collator.address] = {
|
|
357
346
|
identity,
|
|
358
347
|
isVerified: isReasonable,
|
|
@@ -26,6 +26,9 @@ export declare function validateRelayBondingCondition(chainInfo: _ChainInfo, amo
|
|
|
26
26
|
export declare function subscribeRelayChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
|
|
27
27
|
export declare function getRelayChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
28
28
|
export declare function subscribeRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, ledger: PalletStakingStakingLedger): Promise<NominatorMetadata>;
|
|
29
|
+
/**
|
|
30
|
+
* Deprecated
|
|
31
|
+
* */
|
|
29
32
|
export declare function getRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
30
33
|
export declare function subscribeRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, poolMemberInfo: PalletNominationPoolsPoolMember): Promise<NominatorMetadata>;
|
|
31
34
|
export declare function getRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
@@ -7,8 +7,9 @@ import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculat
|
|
|
7
7
|
import { _STAKING_CHAIN_GROUP, _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 { reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
|
+
import BigN from 'bignumber.js';
|
|
10
11
|
import { t } from 'i18next';
|
|
11
|
-
import { BN, BN_ZERO } from '@polkadot/util';
|
|
12
|
+
import { BN, BN_ZERO, hexToString, isHex } from '@polkadot/util';
|
|
12
13
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
13
14
|
export function validateRelayUnbondingCondition(amount, chainStakingMetadata, nominatorMetadata) {
|
|
14
15
|
const errors = [];
|
|
@@ -34,7 +35,7 @@ export function validatePoolBondingCondition(chainInfo, amount, selectedPool, ad
|
|
|
34
35
|
let bnTotalStake = new BN(amount);
|
|
35
36
|
const bnMinStake = new BN(chainStakingMetadata.minJoinNominationPool || '0');
|
|
36
37
|
const minStakeErrorMessage = getMinStakeErrorMessage(chainInfo, bnMinStake);
|
|
37
|
-
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, true);
|
|
38
|
+
const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type, true);
|
|
38
39
|
if (selectedPool.state !== 'Open') {
|
|
39
40
|
errors.push(new TransactionError(StakingTxErrorType.INACTIVE_NOMINATION_POOL));
|
|
40
41
|
}
|
|
@@ -190,13 +191,13 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
190
191
|
if (nominations) {
|
|
191
192
|
const validatorList = nominations.targets;
|
|
192
193
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
193
|
-
var _chainApi$api$query$i;
|
|
194
194
|
let nominationStatus = StakingStatus.NOT_EARNING;
|
|
195
|
-
const [
|
|
195
|
+
const [[identity], _eraStaker] = await Promise.all([parseIdentity(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
196
196
|
const eraStaker = _eraStaker.toPrimitive();
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
198
|
+
return new BigN(b.value).minus(a.value).toNumber();
|
|
199
|
+
});
|
|
200
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
200
201
|
return nominator.who;
|
|
201
202
|
});
|
|
202
203
|
if (!topNominators.includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
@@ -254,6 +255,10 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
254
255
|
isBondedBefore: bonded !== null
|
|
255
256
|
};
|
|
256
257
|
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Deprecated
|
|
261
|
+
* */
|
|
257
262
|
export async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
258
263
|
var _chainApi$api$query10, _chainApi$api$query11, _chainApi$api$query12, _chainApi$api$query13, _chainApi$api$query14, _chainApi$api$query15, _chainApi$api$query16, _chainApi$api$query17, _chainApi$api$query18, _chainApi$api$query19, _chainApi$api$query20, _chainApi$api$query21, _chainApi$api$query22, _chainApi$api$query23;
|
|
259
264
|
if (isEthereumAddress(address)) {
|
|
@@ -291,11 +296,12 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
291
296
|
const validatorList = nominations.targets;
|
|
292
297
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
293
298
|
let nominationStatus = StakingStatus.NOT_EARNING;
|
|
294
|
-
const [
|
|
299
|
+
const [[identity], _eraStaker] = await Promise.all([parseIdentity(chainApi, validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
295
300
|
const eraStaker = _eraStaker.toPrimitive();
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
301
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
302
|
+
return new BigN(b.value).minus(a.value).toNumber();
|
|
303
|
+
});
|
|
304
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
299
305
|
return nominator.who;
|
|
300
306
|
});
|
|
301
307
|
if (!topNominators.includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
@@ -369,7 +375,10 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
|
|
|
369
375
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
370
376
|
const _eraStaker = await substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
371
377
|
const eraStaker = _eraStaker.toPrimitive();
|
|
372
|
-
const
|
|
378
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
379
|
+
return new BigN(b.value).minus(a.value).toNumber();
|
|
380
|
+
});
|
|
381
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
373
382
|
return nominator.who;
|
|
374
383
|
}).slice(0, maxNominatorRewardedPerValidator);
|
|
375
384
|
if (topNominators.includes(reformatAddress(poolStashAccount, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
@@ -446,7 +455,10 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
446
455
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
447
456
|
const _eraStaker = await chainApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
448
457
|
const eraStaker = _eraStaker.toPrimitive();
|
|
449
|
-
const
|
|
458
|
+
const sortedNominators = eraStaker.others.sort((a, b) => {
|
|
459
|
+
return new BigN(b.value).minus(a.value).toNumber();
|
|
460
|
+
});
|
|
461
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
450
462
|
return nominator.who;
|
|
451
463
|
}).slice(0, maxNominatorRewardedPerValidator);
|
|
452
464
|
if (topNominators.includes(reformatAddress(poolStashAccount, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
@@ -542,20 +554,14 @@ export async function getRelayValidatorsInfo(chain, substrateApi, decimals, chai
|
|
|
542
554
|
}
|
|
543
555
|
const extraInfoMap = {};
|
|
544
556
|
await Promise.all(allValidators.map(async address => {
|
|
545
|
-
var _chainApi$api$query24, _chainApi$api$query25, _identityInfo$judgeme;
|
|
546
557
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
547
|
-
const [_commissionInfo,
|
|
558
|
+
const [_commissionInfo, [identity, isVerified]] = await Promise.all([chainApi.api.query.staking.validators(address), parseIdentity(chainApi, address)]);
|
|
548
559
|
const commissionInfo = _commissionInfo.toHuman();
|
|
549
|
-
const identityInfo = _identityInfo ? _identityInfo.toHuman() : null;
|
|
550
|
-
let identity;
|
|
551
|
-
if (identityInfo !== null) {
|
|
552
|
-
identity = parseIdentity(identityInfo);
|
|
553
|
-
}
|
|
554
560
|
extraInfoMap[address] = {
|
|
555
561
|
commission: commissionInfo.commission,
|
|
556
562
|
blocked: commissionInfo.blocked,
|
|
557
563
|
identity,
|
|
558
|
-
isVerified:
|
|
564
|
+
isVerified: isVerified
|
|
559
565
|
};
|
|
560
566
|
}));
|
|
561
567
|
const bnAvgStake = bnTotalEraStake.divn(validatorInfoList.length).div(bnDecimals);
|
|
@@ -587,10 +593,20 @@ export async function getRelayPoolsInfo(chain, substrateApi) {
|
|
|
587
593
|
const poolAddressList = _poolInfo[0].toHuman();
|
|
588
594
|
const poolAddress = poolAddressList[0];
|
|
589
595
|
const poolId = _poolInfo[1].toPrimitive();
|
|
590
|
-
const
|
|
596
|
+
const poolsPalletId = substrateApi.api.consts.nominationPools.palletId.toString();
|
|
597
|
+
const poolStashAccount = parsePoolStashAddress(substrateApi.api, 0, poolId, poolsPalletId);
|
|
598
|
+
const [_nominations, _bondedPool, _metadata, _minimumActiveStake] = await Promise.all([chainApi.api.query.staking.nominators(poolStashAccount), chainApi.api.query.nominationPools.bondedPools(poolId), chainApi.api.query.nominationPools.metadata(poolId), chainApi.api.query.staking.minimumActiveStake()]);
|
|
599
|
+
const minimumActiveStake = _minimumActiveStake.toPrimitive();
|
|
600
|
+
const nominations = _nominations.toJSON();
|
|
591
601
|
const poolMetadata = _metadata.toPrimitive();
|
|
592
602
|
const bondedPool = _bondedPool.toPrimitive();
|
|
593
|
-
|
|
603
|
+
|
|
604
|
+
// const poolName = transformPoolName(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
|
|
605
|
+
|
|
606
|
+
const poolName = isHex(poolMetadata) ? hexToString(poolMetadata) : poolMetadata;
|
|
607
|
+
const isPoolOpen = bondedPool.state === 'Open';
|
|
608
|
+
const isPoolNominating = !!nominations && nominations.targets.length > 0;
|
|
609
|
+
const isPoolEarningReward = bondedPool.points > minimumActiveStake;
|
|
594
610
|
nominationPools.push({
|
|
595
611
|
id: poolId,
|
|
596
612
|
address: poolAddress,
|
|
@@ -598,7 +614,8 @@ export async function getRelayPoolsInfo(chain, substrateApi) {
|
|
|
598
614
|
bondedAmount: ((_bondedPool$points = bondedPool.points) === null || _bondedPool$points === void 0 ? void 0 : _bondedPool$points.toString()) || '0',
|
|
599
615
|
roles: bondedPool.roles,
|
|
600
616
|
memberCounter: bondedPool.memberCounter,
|
|
601
|
-
state: bondedPool.state
|
|
617
|
+
state: bondedPool.state,
|
|
618
|
+
isProfitable: isPoolOpen && isPoolNominating && isPoolEarningReward
|
|
602
619
|
});
|
|
603
620
|
}));
|
|
604
621
|
return nominationPools;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
3
|
import { NominationInfo, NominatorMetadata, StakingStatus, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
5
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
6
|
import { ApiPromise } from '@polkadot/api';
|
|
6
7
|
import { BN } from '@polkadot/util';
|
|
7
8
|
export interface PalletNominationPoolsPoolMember {
|
|
@@ -93,6 +94,9 @@ export interface PalletIdentityRegistration {
|
|
|
93
94
|
};
|
|
94
95
|
};
|
|
95
96
|
}
|
|
97
|
+
export declare type PalletIdentitySuper = [string, {
|
|
98
|
+
Raw: string;
|
|
99
|
+
}];
|
|
96
100
|
export interface ValidatorExtraInfo {
|
|
97
101
|
commission: string;
|
|
98
102
|
blocked: false;
|
|
@@ -109,7 +113,16 @@ export interface TernoaStakingRewardsStakingRewardsData {
|
|
|
109
113
|
}
|
|
110
114
|
export declare function parsePoolStashAddress(api: ApiPromise, index: number, poolId: number, poolsPalletId: string): string;
|
|
111
115
|
export declare function transformPoolName(input: string): string;
|
|
112
|
-
|
|
116
|
+
/**
|
|
117
|
+
* @returns
|
|
118
|
+
* <p>
|
|
119
|
+
* [0] - identity
|
|
120
|
+
* </p>
|
|
121
|
+
* <p>
|
|
122
|
+
* [1] - isReasonable (isVerified)
|
|
123
|
+
* </p>
|
|
124
|
+
* */
|
|
125
|
+
export declare function parseIdentity(substrateApi: _SubstrateApi, address: string, children?: string): Promise<[string | undefined, boolean]>;
|
|
113
126
|
export declare function getInflationParams(networkKey: string): _SubstrateInflationParams;
|
|
114
127
|
export declare function calcInflationUniformEraPayout(totalIssuance: BN, yearlyInflationInTokens: number): number;
|
|
115
128
|
export declare function calcInflationRewardCurve(minInflation: number, stakedFraction: number, idealStake: number, idealInterest: number, falloff: number): number;
|
|
@@ -162,4 +175,4 @@ export declare function getStakingStatusByNominations(bnTotalActiveStake: BN, no
|
|
|
162
175
|
export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
|
|
163
176
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
164
177
|
export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
|
|
165
|
-
export declare const getExistUnstakeErrorMessage: (chain: string, isStakeMore?: boolean) => string;
|
|
178
|
+
export declare const getExistUnstakeErrorMessage: (chain: string, type?: StakingType, isStakeMore?: boolean) => string;
|
|
@@ -5,10 +5,10 @@ import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extensio
|
|
|
5
5
|
import { getAstarWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
6
6
|
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
-
import { detectTranslate, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
|
+
import { detectTranslate, isSameAddress, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
|
|
10
10
|
import { t } from 'i18next';
|
|
11
|
-
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
11
|
+
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, hexToString, isHex, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
12
12
|
export let PalletParachainStakingRequestType;
|
|
13
13
|
(function (PalletParachainStakingRequestType) {
|
|
14
14
|
PalletParachainStakingRequestType["REVOKE"] = "revoke";
|
|
@@ -27,22 +27,63 @@ export function parsePoolStashAddress(api, index, poolId, poolsPalletId) {
|
|
|
27
27
|
export function transformPoolName(input) {
|
|
28
28
|
return input.replace(/[^\x20-\x7E]/g, '');
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @returns
|
|
33
|
+
* <p>
|
|
34
|
+
* [0] - identity
|
|
35
|
+
* </p>
|
|
36
|
+
* <p>
|
|
37
|
+
* [1] - isReasonable (isVerified)
|
|
38
|
+
* </p>
|
|
39
|
+
* */
|
|
40
|
+
export async function parseIdentity(substrateApi, address, children) {
|
|
41
|
+
const compactResult = rs => {
|
|
42
|
+
const result = [];
|
|
43
|
+
if (rs) {
|
|
44
|
+
result.push(rs);
|
|
45
|
+
}
|
|
46
|
+
if (children) {
|
|
47
|
+
result.push(children);
|
|
48
|
+
}
|
|
49
|
+
if (result.length > 0) {
|
|
50
|
+
return result.join('/');
|
|
41
51
|
} else {
|
|
42
|
-
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (substrateApi.api.query.identity) {
|
|
56
|
+
let identity;
|
|
57
|
+
const _parent = await substrateApi.api.query.identity.superOf(address);
|
|
58
|
+
const parentInfo = _parent.toHuman();
|
|
59
|
+
if (parentInfo) {
|
|
60
|
+
const [parentAddress, {
|
|
61
|
+
Raw: data
|
|
62
|
+
}] = parentInfo;
|
|
63
|
+
const child = isHex(data) ? hexToString(data) : data;
|
|
64
|
+
if (!isSameAddress(address, parentAddress)) {
|
|
65
|
+
const [rs, isReasonable] = await parseIdentity(substrateApi, parentAddress, child);
|
|
66
|
+
return [compactResult(rs), isReasonable];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
70
|
+
const identityInfo = _identity.toHuman();
|
|
71
|
+
if (identityInfo) {
|
|
72
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
73
|
+
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;
|
|
74
|
+
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
75
|
+
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
76
|
+
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
77
|
+
const isReasonable = identityInfo.judgements.length > 0;
|
|
78
|
+
if (displayName && !displayName.startsWith('0x')) {
|
|
79
|
+
identity = displayName;
|
|
80
|
+
} else {
|
|
81
|
+
identity = twitter || web || riot;
|
|
82
|
+
}
|
|
83
|
+
return [compactResult(identity), isReasonable];
|
|
43
84
|
}
|
|
44
85
|
}
|
|
45
|
-
return
|
|
86
|
+
return [undefined, false];
|
|
46
87
|
}
|
|
47
88
|
export function getInflationParams(networkKey) {
|
|
48
89
|
return _KNOWN_CHAIN_INFLATION_PARAMS[networkKey] || _SUBSTRATE_DEFAULT_INFLATION_PARAMS;
|
|
@@ -297,7 +338,7 @@ export const getMaxValidatorErrorMessage = (chainInfo, max) => {
|
|
|
297
338
|
}
|
|
298
339
|
});
|
|
299
340
|
};
|
|
300
|
-
export const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
341
|
+
export const getExistUnstakeErrorMessage = (chain, type, isStakeMore) => {
|
|
301
342
|
const label = getValidatorLabel(chain);
|
|
302
343
|
if (!isStakeMore) {
|
|
303
344
|
switch (label) {
|
|
@@ -306,7 +347,12 @@ export const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
|
306
347
|
case 'Collator':
|
|
307
348
|
return t('You can unstake from a collator once');
|
|
308
349
|
case 'Validator':
|
|
309
|
-
|
|
350
|
+
{
|
|
351
|
+
if (type === StakingType.POOLED) {
|
|
352
|
+
return t('You can unstake from a pool once');
|
|
353
|
+
}
|
|
354
|
+
return t('You can unstake from a validator once');
|
|
355
|
+
}
|
|
310
356
|
}
|
|
311
357
|
} else {
|
|
312
358
|
switch (label) {
|
|
@@ -315,7 +361,12 @@ export const getExistUnstakeErrorMessage = (chain, isStakeMore) => {
|
|
|
315
361
|
case 'Collator':
|
|
316
362
|
return t('You cannot stake more for a collator you are unstaking from');
|
|
317
363
|
case 'Validator':
|
|
318
|
-
|
|
364
|
+
{
|
|
365
|
+
if (type === StakingType.POOLED) {
|
|
366
|
+
return t('You cannot stake more for a pool you are unstaking from');
|
|
367
|
+
}
|
|
368
|
+
return t('You cannot stake more for a validator you are unstaking from');
|
|
369
|
+
}
|
|
319
370
|
}
|
|
320
371
|
}
|
|
321
372
|
};
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.24-
|
|
20
|
+
"version": "1.1.24-3",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1347,11 +1347,11 @@
|
|
|
1347
1347
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1348
1348
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1349
1349
|
"@substrate/connect": "^0.7.26",
|
|
1350
|
-
"@subwallet/chain-list": "0.2.
|
|
1351
|
-
"@subwallet/extension-base": "^1.1.24-
|
|
1352
|
-
"@subwallet/extension-chains": "^1.1.24-
|
|
1353
|
-
"@subwallet/extension-dapp": "^1.1.24-
|
|
1354
|
-
"@subwallet/extension-inject": "^1.1.24-
|
|
1350
|
+
"@subwallet/chain-list": "0.2.27",
|
|
1351
|
+
"@subwallet/extension-base": "^1.1.24-3",
|
|
1352
|
+
"@subwallet/extension-chains": "^1.1.24-3",
|
|
1353
|
+
"@subwallet/extension-dapp": "^1.1.24-3",
|
|
1354
|
+
"@subwallet/extension-inject": "^1.1.24-3",
|
|
1355
1355
|
"@subwallet/keyring": "^0.1.1",
|
|
1356
1356
|
"@subwallet/ui-keyring": "^0.1.1",
|
|
1357
1357
|
"@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.24-
|
|
10
|
+
version: '1.1.24-3'
|
|
11
11
|
};
|
|
@@ -53,13 +53,13 @@ export const _NFT_CHAIN_GROUP = {
|
|
|
53
53
|
// Staking--------------------------------------------------------------------------------------------------------------
|
|
54
54
|
|
|
55
55
|
export const _STAKING_CHAIN_GROUP = {
|
|
56
|
-
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network'],
|
|
56
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
|
|
57
57
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari'],
|
|
58
58
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
59
59
|
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
|
|
60
60
|
// amplitude and kilt only share some common logic
|
|
61
61
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
62
|
-
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network'],
|
|
62
|
+
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet'],
|
|
63
63
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
64
64
|
aleph: ['aleph', 'alephTest'],
|
|
65
65
|
// A0 has distinct tokenomics
|
|
@@ -95,7 +95,8 @@ export const _STAKING_ERA_LENGTH_MAP = {
|
|
|
95
95
|
edgeware: 6,
|
|
96
96
|
kate: 6,
|
|
97
97
|
creditcoin: 24,
|
|
98
|
-
vara_network: 12
|
|
98
|
+
vara_network: 12,
|
|
99
|
+
goldberg_testnet: 24
|
|
99
100
|
};
|
|
100
101
|
export const _PARACHAIN_INFLATION_DISTRIBUTION = {
|
|
101
102
|
moonbeam: {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ChainType, ExtrinsicStatus, ExtrinsicType, TransactionDirection } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { getExtrinsicParserKey, subscanExtrinsicParserMap, supportedExtrinsicParser } from '@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper';
|
|
6
|
+
import { isSameAddress } from '@subwallet/extension-base/utils';
|
|
6
7
|
import { decodeAddress, encodeAddress, isEthereumAddress } from '@polkadot/util-crypto';
|
|
7
8
|
function autoFormatAddress(address) {
|
|
8
9
|
try {
|
|
@@ -76,7 +77,7 @@ export function parseSubscanTransferData(address, transferItem, chainInfo) {
|
|
|
76
77
|
chainType,
|
|
77
78
|
from,
|
|
78
79
|
fromName: transferItem.from_account_display.display,
|
|
79
|
-
direction: address
|
|
80
|
+
direction: isSameAddress(address, from) ? TransactionDirection.SEND : TransactionDirection.RECEIVED,
|
|
80
81
|
blockNumber: transferItem.block_num,
|
|
81
82
|
blockHash: '',
|
|
82
83
|
chain: chainInfo.slug,
|