@subwallet/extension-base 1.1.24-0 → 1.1.24-2
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 +2 -25
- package/cjs/constants/index.js +9 -3
- 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 +5 -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/koni/api/tokens/evm/balance.js +5 -1
- package/cjs/koni/api/tokens/evm/transfer.js +8 -4
- package/cjs/koni/background/cron.js +2 -2
- package/cjs/koni/background/handlers/Extension.js +5 -5
- package/cjs/koni/background/handlers/Mobile.js +1 -1
- package/cjs/koni/background/handlers/State.js +123 -44
- package/cjs/koni/background/subscription.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +53 -0
- package/cjs/services/balance-service/helpers/subscribe/balance.js +111 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +95 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +113 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +324 -0
- package/cjs/services/balance-service/index.js +41 -16
- package/cjs/services/chain-service/constants.js +4 -3
- package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
- package/cjs/services/history-service/index.js +12 -8
- package/cjs/services/migration-service/scripts/MigrateProvider.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +7 -2
- package/cjs/services/storage-service/db-stores/Balance.js +9 -9
- package/cjs/services/subscan-service/index.js +66 -22
- package/cjs/services/transaction-service/index.js +4 -3
- package/cjs/types/balance.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/{address.js → account.js} +32 -2
- package/cjs/utils/eth.js +7 -2
- package/cjs/utils/index.js +12 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- 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 +5 -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/koni/api/tokens/evm/balance.js +5 -1
- package/koni/api/tokens/evm/transfer.d.ts +1 -1
- package/koni/api/tokens/evm/transfer.js +8 -4
- package/koni/background/cron.js +3 -3
- package/koni/background/handlers/Extension.js +5 -5
- package/koni/background/handlers/Mobile.js +1 -1
- package/koni/background/handlers/State.d.ts +6 -4
- package/koni/background/handlers/State.js +111 -33
- package/koni/background/subscription.js +2 -2
- package/package.json +40 -15
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.d.ts +9 -0
- package/services/balance-service/helpers/group.js +46 -0
- package/services/balance-service/helpers/subscribe/balance.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/balance.js +103 -0
- package/services/balance-service/helpers/subscribe/evm.d.ts +5 -0
- package/services/balance-service/helpers/subscribe/evm.js +87 -0
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +105 -0
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/index.js +316 -0
- package/services/balance-service/index.d.ts +24 -5
- package/services/balance-service/index.js +40 -14
- package/services/chain-service/constants.js +4 -3
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
- package/services/history-service/index.js +12 -8
- package/services/migration-service/scripts/MigrateProvider.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +4 -2
- package/services/storage-service/DatabaseService.js +7 -2
- package/services/storage-service/databases/index.d.ts +2 -1
- package/services/storage-service/db-stores/Balance.d.ts +2 -2
- package/services/storage-service/db-stores/Balance.js +9 -9
- package/services/subscan-service/index.d.ts +11 -5
- package/services/subscan-service/index.js +66 -26
- package/services/subscan-service/types.d.ts +4 -0
- package/services/transaction-service/index.js +5 -4
- package/types/balance.d.ts +40 -0
- package/types/balance.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account.d.ts +15 -0
- package/utils/{address.js → account.js} +28 -0
- package/utils/eth.d.ts +1 -0
- package/utils/eth.js +4 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/koni/api/dotsama/balance.d.ts +0 -6
- package/koni/api/dotsama/balance.js +0 -451
- package/utils/address.d.ts +0 -5
|
@@ -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
|
};
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
export async function getEVMBalance(networkKey, addresses, evmApiMap) {
|
|
5
5
|
const web3Api = evmApiMap[networkKey];
|
|
6
6
|
return await Promise.all(addresses.map(async address => {
|
|
7
|
-
|
|
7
|
+
try {
|
|
8
|
+
return await web3Api.api.eth.getBalance(address);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return '0';
|
|
11
|
+
}
|
|
8
12
|
}));
|
|
9
13
|
}
|
|
@@ -13,5 +13,5 @@ interface HandleTransferBalanceResultProps {
|
|
|
13
13
|
export declare const handleTransferBalanceResult: ({ callback, changeValue, networkKey, receipt, response, updateState }: HandleTransferBalanceResultProps) => void;
|
|
14
14
|
export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
|
|
15
15
|
export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
|
|
16
|
-
export declare function getERC721Transaction(web3Api: _EvmApi, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
|
|
16
|
+
export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
|
|
17
17
|
export {};
|
|
@@ -5,6 +5,7 @@ import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/backgrou
|
|
|
5
5
|
import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
|
|
6
6
|
import { _BALANCE_PARSING_CHAIN_GROUP, EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
8
|
+
import { recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
|
|
8
9
|
import { BN, hexToBn } from '@polkadot/util';
|
|
9
10
|
export const handleTransferBalanceResult = ({
|
|
10
11
|
callback,
|
|
@@ -35,7 +36,8 @@ export const handleTransferBalanceResult = ({
|
|
|
35
36
|
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, evmApiMap) {
|
|
36
37
|
const networkKey = chainInfo.slug;
|
|
37
38
|
const web3Api = evmApiMap[networkKey];
|
|
38
|
-
const
|
|
39
|
+
const _price = await web3Api.api.eth.getGasPrice();
|
|
40
|
+
const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
|
|
39
41
|
const transactionObject = {
|
|
40
42
|
gasPrice: gasPrice,
|
|
41
43
|
to: to,
|
|
@@ -69,11 +71,12 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
|
|
|
69
71
|
return erc20Contract.methods.transfer(to, transferValue).encodeABI();
|
|
70
72
|
}
|
|
71
73
|
const transferData = generateTransferData(to, transferValue);
|
|
72
|
-
const [gasLimit,
|
|
74
|
+
const [gasLimit, _price] = await Promise.all([
|
|
73
75
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
74
76
|
erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
75
77
|
from
|
|
76
78
|
}), evmApi.api.eth.getGasPrice()]);
|
|
79
|
+
const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
|
|
77
80
|
const transactionObject = {
|
|
78
81
|
gasPrice: gasPrice,
|
|
79
82
|
gas: gasLimit,
|
|
@@ -87,14 +90,15 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
|
|
|
87
90
|
}
|
|
88
91
|
return [transactionObject, transferValue];
|
|
89
92
|
}
|
|
90
|
-
export async function getERC721Transaction(web3Api, contractAddress, senderAddress, recipientAddress, tokenId) {
|
|
93
|
+
export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
|
|
91
94
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
92
95
|
const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
|
|
93
|
-
const [gasLimit,
|
|
96
|
+
const [gasLimit, _price] = await Promise.all([
|
|
94
97
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
95
98
|
contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
|
|
96
99
|
from: senderAddress
|
|
97
100
|
}), web3Api.api.eth.getGasPrice()]);
|
|
101
|
+
const gasPrice = recalculateGasPrice(_price, chain);
|
|
98
102
|
return {
|
|
99
103
|
from: senderAddress,
|
|
100
104
|
gasPrice,
|
package/koni/background/cron.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL,
|
|
4
|
+
import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { Subject } from 'rxjs';
|
|
@@ -104,8 +104,8 @@ export class KoniCron {
|
|
|
104
104
|
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
105
105
|
this.resetNft(currentAccountInfo.address);
|
|
106
106
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
107
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
108
|
-
this.addCron('
|
|
107
|
+
// this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
108
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
109
109
|
this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
110
110
|
} else {
|
|
111
111
|
this.setStakingRewardReady();
|
|
@@ -28,9 +28,8 @@ import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/reques
|
|
|
28
28
|
import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
|
|
29
29
|
import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
|
|
30
30
|
import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
31
|
-
import { isSameAddress, reformatAddress, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
32
|
-
import {
|
|
33
|
-
import { createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
|
|
31
|
+
import { convertSubjectInfoToAddresses, isSameAddress, reformatAddress, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
32
|
+
import { createTransactionFromRLP, recalculateGasPrice, signatureToHex } from '@subwallet/extension-base/utils/eth';
|
|
34
33
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
35
34
|
import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
|
|
36
35
|
import { createPair } from '@subwallet/keyring';
|
|
@@ -1725,7 +1724,7 @@ export default class KoniExtension {
|
|
|
1725
1724
|
} = inputData;
|
|
1726
1725
|
const contractAddress = params.contractAddress;
|
|
1727
1726
|
const tokenId = params.tokenId;
|
|
1728
|
-
const transaction = await getERC721Transaction(this.#koniState.getEvmApi(networkKey), contractAddress, senderAddress, recipientAddress, tokenId);
|
|
1727
|
+
const transaction = await getERC721Transaction(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId);
|
|
1729
1728
|
|
|
1730
1729
|
// this.addContact(recipientAddress);
|
|
1731
1730
|
|
|
@@ -1872,7 +1871,8 @@ export default class KoniExtension {
|
|
|
1872
1871
|
// null address
|
|
1873
1872
|
from: address
|
|
1874
1873
|
};
|
|
1875
|
-
const
|
|
1874
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
1875
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
1876
1876
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
1877
1877
|
estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
|
|
1878
1878
|
} else {
|
|
@@ -108,7 +108,7 @@ export default class Mobile {
|
|
|
108
108
|
if (storage) {
|
|
109
109
|
const storageData = JSON.parse(storage);
|
|
110
110
|
for (const key in storageData) {
|
|
111
|
-
localStorage.setItem(key,
|
|
111
|
+
localStorage.setItem(key, storageData[key]);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
if (indexedDB) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
3
|
-
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2,
|
|
3
|
+
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
|
|
5
5
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
6
6
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
@@ -20,6 +20,7 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
|
|
|
20
20
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
21
21
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
22
22
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
23
|
+
import { BalanceItem, BalanceJson, BalanceMap } from '@subwallet/extension-base/types';
|
|
23
24
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
24
25
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
25
26
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -83,7 +84,7 @@ export default class KoniState {
|
|
|
83
84
|
saveMetadata(meta: MetadataDef): void;
|
|
84
85
|
sign(url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning>;
|
|
85
86
|
get authSubjectV2(): BehaviorSubject<import("@subwallet/extension-base/background/types").AuthorizeRequest[]>;
|
|
86
|
-
generateDefaultBalanceMap():
|
|
87
|
+
generateDefaultBalanceMap(): BalanceMap;
|
|
87
88
|
private afterChainServiceInit;
|
|
88
89
|
init(): Promise<void>;
|
|
89
90
|
initMantaPay(password: string): Promise<void>;
|
|
@@ -151,12 +152,13 @@ export default class KoniState {
|
|
|
151
152
|
getAllAddresses(): string[];
|
|
152
153
|
private removeInactiveChainBalances;
|
|
153
154
|
getBalance(reset?: boolean): BalanceJson;
|
|
154
|
-
getStoredBalance(address: string): Promise<
|
|
155
|
+
getStoredBalance(address: string): Promise<BalanceMap>;
|
|
155
156
|
handleSwitchAccount(newAddress: string): Promise<void>;
|
|
156
157
|
resetBalanceMap(newAddress: string): Promise<void>;
|
|
157
158
|
resetCrowdloanMap(newAddress: string): Promise<void>;
|
|
158
159
|
resetStaking(newAddress: string): void;
|
|
159
|
-
|
|
160
|
+
/** Note: items must be same tokenSlug */
|
|
161
|
+
setBalanceItem(items: BalanceItem[]): void;
|
|
160
162
|
private updateBalanceStore;
|
|
161
163
|
subscribeBalance(): Subject<BalanceJson>;
|
|
162
164
|
getCrowdloan(reset?: boolean): CrowdloanJson;
|