@subwallet/extension-base 1.0.2-1b → 1.0.2-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 +34 -16
- package/background/KoniTypes.js +7 -6
- package/background/errors/TransactionError.js +1 -21
- package/cjs/background/KoniTypes.js +7 -6
- package/cjs/background/errors/TransactionError.js +0 -20
- package/cjs/constants/index.js +26 -8
- package/cjs/koni/api/dotsama/balance.js +224 -49
- package/cjs/koni/api/dotsama/transfer.js +29 -30
- package/cjs/koni/api/nft/acala_nft/index.js +1 -4
- package/cjs/koni/api/nft/bit.country/index.js +1 -4
- package/cjs/koni/api/nft/evm_nft/index.js +3 -7
- package/cjs/koni/api/nft/index.js +6 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -4
- package/cjs/koni/api/nft/rmrk_nft/index.js +1 -8
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -4
- package/cjs/koni/api/nft/unique_nft/index.js +1 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +111 -169
- package/cjs/koni/api/nft/wasm_nft/utils.js +7 -11
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -13
- package/cjs/koni/api/staking/bonding/astar.js +13 -15
- package/cjs/koni/api/staking/bonding/index.js +10 -22
- package/cjs/koni/api/staking/bonding/paraChain.js +2 -85
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -119
- package/cjs/koni/api/staking/bonding/utils.js +8 -27
- package/cjs/koni/api/tokens/wasm/index.js +4 -5
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +13 -18
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +6 -9
- package/cjs/koni/background/cron.js +47 -150
- package/cjs/koni/background/handlers/Extension.js +64 -106
- package/cjs/koni/background/handlers/State.js +21 -19
- package/cjs/koni/background/handlers/Tabs.js +1 -8
- package/cjs/koni/background/subscription.js +29 -32
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +8 -13
- package/cjs/services/chain-service/handler/light-client/index.js +0 -2
- package/cjs/services/chain-service/index.js +7 -6
- package/cjs/services/event-service/index.js +1 -5
- package/cjs/services/event-service/types.js +1 -11
- package/cjs/services/history-service/index.js +10 -16
- package/cjs/services/history-service/subsquid-multi-chain-history.js +9 -12
- package/cjs/services/price-service/coingecko.js +1 -0
- package/cjs/services/price-service/index.js +3 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/cjs/services/storage-service/DatabaseService.js +33 -52
- package/cjs/services/storage-service/db-stores/Nft.js +17 -4
- package/cjs/services/transaction-service/event-parser/index.js +48 -20
- package/cjs/services/transaction-service/index.js +14 -23
- package/cjs/utils/index.js +14 -7
- package/constants/index.d.ts +13 -7
- package/constants/index.js +13 -7
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +197 -22
- package/koni/api/dotsama/transfer.js +4 -5
- package/koni/api/nft/acala_nft/index.js +1 -3
- package/koni/api/nft/bit.country/index.js +1 -3
- package/koni/api/nft/evm_nft/index.js +3 -6
- package/koni/api/nft/index.d.ts +2 -1
- package/koni/api/nft/index.js +6 -3
- package/koni/api/nft/karura_nft/index.js +1 -3
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +1 -8
- package/koni/api/nft/statemine_nft/index.js +1 -3
- package/koni/api/nft/unique_nft/index.js +1 -5
- package/koni/api/nft/wasm_nft/index.d.ts +2 -0
- package/koni/api/nft/wasm_nft/index.js +109 -167
- package/koni/api/nft/wasm_nft/utils.d.ts +5 -7
- package/koni/api/nft/wasm_nft/utils.js +5 -7
- package/koni/api/staking/bonding/amplitude.d.ts +1 -0
- package/koni/api/staking/bonding/amplitude.js +10 -15
- package/koni/api/staking/bonding/astar.js +6 -8
- package/koni/api/staking/bonding/index.d.ts +1 -4
- package/koni/api/staking/bonding/index.js +13 -23
- package/koni/api/staking/bonding/paraChain.d.ts +0 -3
- package/koni/api/staking/bonding/paraChain.js +5 -86
- package/koni/api/staking/bonding/relayChain.d.ts +1 -5
- package/koni/api/staking/bonding/relayChain.js +18 -118
- package/koni/api/staking/bonding/utils.d.ts +2 -3
- package/koni/api/staking/bonding/utils.js +9 -27
- package/koni/api/tokens/wasm/index.js +4 -5
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +6 -5
- package/koni/api/xcm/utils.js +10 -15
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +9 -10
- package/koni/background/cron.d.ts +1 -6
- package/koni/background/cron.js +48 -151
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +67 -108
- package/koni/background/handlers/State.d.ts +6 -5
- package/koni/background/handlers/State.js +21 -19
- package/koni/background/handlers/Tabs.js +1 -8
- package/koni/background/subscription.js +30 -31
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +9 -14
- package/services/chain-service/handler/light-client/index.d.ts +1 -17
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +881 -1041
- package/services/chain-service/helper/psp34_abi.json +1808 -2964
- package/services/chain-service/index.js +7 -6
- package/services/event-service/index.js +1 -5
- package/services/event-service/types.d.ts +9 -5
- package/services/event-service/types.js +1 -4
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +10 -16
- package/services/history-service/subsquid-multi-chain-history.js +11 -15
- package/services/price-service/coingecko.js +1 -0
- package/services/price-service/index.js +3 -2
- package/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/services/storage-service/DatabaseService.d.ts +0 -1
- package/services/storage-service/DatabaseService.js +33 -52
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +16 -4
- package/services/transaction-service/event-parser/index.js +49 -21
- package/services/transaction-service/index.js +14 -23
- package/utils/index.d.ts +1 -1
- package/utils/index.js +12 -6
- package/cjs/koni/api/tokens/wasm/utils.js +0 -63
- package/koni/api/tokens/wasm/utils.d.ts +0 -6
- package/koni/api/tokens/wasm/utils.js +0 -54
|
@@ -1,86 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getBondedValidators, getParaCurrentInflation, getStakingStatusByNominations, isUnstakeAll, parseIdentity } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
4
|
+
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { getBondedValidators, getParaCurrentInflation, isUnstakeAll, parseIdentity } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
6
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
7
|
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
-
import {
|
|
8
|
+
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
9
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
11
10
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
12
|
-
export function validateParaChainUnbondingCondition(amount, nominatorMetadata, chainStakingMetadata, selectedCollator) {
|
|
13
|
-
const errors = [];
|
|
14
|
-
let targetNomination;
|
|
15
|
-
for (const nomination of nominatorMetadata.nominations) {
|
|
16
|
-
if (isSameAddress(nomination.validatorAddress, selectedCollator)) {
|
|
17
|
-
targetNomination = nomination;
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!targetNomination) {
|
|
22
|
-
errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
23
|
-
return errors;
|
|
24
|
-
}
|
|
25
|
-
const bnActiveStake = new BN(targetNomination.activeStake);
|
|
26
|
-
const bnRemainingStake = bnActiveStake.sub(new BN(amount));
|
|
27
|
-
const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
|
|
28
|
-
const bnCollatorMinStake = new BN(targetNomination.validatorMinStake || '0');
|
|
29
|
-
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
30
|
-
if (targetNomination.hasUnstaking) {
|
|
31
|
-
errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
32
|
-
}
|
|
33
|
-
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(bnMinStake))) {
|
|
34
|
-
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
35
|
-
}
|
|
36
|
-
return errors;
|
|
37
|
-
}
|
|
38
|
-
export function validateParaChainBondingCondition(chainInfo, amount, selectedCollators, address, chainStakingMetadata, nominatorMetadata) {
|
|
39
|
-
const errors = [];
|
|
40
|
-
const selectedCollator = selectedCollators[0];
|
|
41
|
-
let bnTotalStake = new BN(amount);
|
|
42
|
-
const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
|
|
43
|
-
const bnCollatorMinStake = new BN(selectedCollator.minBond || '0');
|
|
44
|
-
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
45
|
-
if (!nominatorMetadata) {
|
|
46
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
47
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
48
|
-
}
|
|
49
|
-
return errors;
|
|
50
|
-
}
|
|
51
|
-
const {
|
|
52
|
-
bondedValidators
|
|
53
|
-
} = getBondedValidators(nominatorMetadata.nominations);
|
|
54
|
-
const parsedSelectedCollatorAddress = reformatAddress(selectedCollator.address, 0);
|
|
55
|
-
if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
|
|
56
|
-
// new delegation
|
|
57
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
58
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
59
|
-
}
|
|
60
|
-
const delegationCount = nominatorMetadata.nominations.length + 1;
|
|
61
|
-
if (delegationCount > chainStakingMetadata.maxValidatorPerNominator) {
|
|
62
|
-
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
let currentDelegationAmount = '0';
|
|
66
|
-
let hasUnstaking = false;
|
|
67
|
-
for (const delegation of nominatorMetadata.nominations) {
|
|
68
|
-
if (reformatAddress(delegation.validatorAddress, 0) === parsedSelectedCollatorAddress) {
|
|
69
|
-
currentDelegationAmount = delegation.activeStake;
|
|
70
|
-
hasUnstaking = !!delegation.hasUnstaking && delegation.hasUnstaking;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
bnTotalStake = bnTotalStake.add(new BN(currentDelegationAmount));
|
|
75
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
76
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
77
|
-
}
|
|
78
|
-
if (hasUnstaking) {
|
|
79
|
-
errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return errors;
|
|
83
|
-
}
|
|
84
11
|
export async function getParaChainStakingMetadata(chain, substrateApi) {
|
|
85
12
|
const chainApi = await substrateApi.isReady;
|
|
86
13
|
const _round = (await chainApi.api.query.parachainStaking.round()).toHuman();
|
|
@@ -134,16 +61,13 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
134
61
|
}
|
|
135
62
|
let bnTotalActiveStake = BN_ZERO;
|
|
136
63
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
137
|
-
const [_delegationScheduledRequests, _identity, _roundInfo
|
|
138
|
-
const rawCollatorInfo = _collatorInfo.toHuman();
|
|
139
|
-
const minDelegation = (rawCollatorInfo === null || rawCollatorInfo === void 0 ? void 0 : rawCollatorInfo.lowestTopDelegationAmount).replaceAll(',', '');
|
|
64
|
+
const [_delegationScheduledRequests, _identity, _roundInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), chainApi.api.query.identity.identityOf(delegation.owner), chainApi.api.query.parachainStaking.round()]);
|
|
140
65
|
const identityInfo = _identity.toHuman();
|
|
141
66
|
const roundInfo = _roundInfo.toPrimitive();
|
|
142
67
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
143
68
|
const currentRound = roundInfo.current;
|
|
144
69
|
const identity = parseIdentity(identityInfo);
|
|
145
70
|
let hasUnstaking = false;
|
|
146
|
-
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
147
71
|
|
|
148
72
|
// parse unstaking info
|
|
149
73
|
if (delegationScheduledRequests) {
|
|
@@ -170,13 +94,10 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
170
94
|
const bnStake = new BN(delegation.amount);
|
|
171
95
|
const bnUnstakeBalance = unstakingMap[delegation.owner] ? new BN(unstakingMap[delegation.owner].claimable) : BN_ZERO;
|
|
172
96
|
const bnActiveStake = bnStake.sub(bnUnstakeBalance);
|
|
173
|
-
if (bnActiveStake.gt(BN_ZERO) && bnActiveStake.gte(new BN(minDelegation))) {
|
|
174
|
-
delegationStatus = StakingStatus.EARNING_REWARD;
|
|
175
|
-
}
|
|
176
97
|
bnTotalActiveStake = bnTotalActiveStake.add(bnActiveStake);
|
|
177
98
|
nominationList.push({
|
|
178
99
|
chain,
|
|
179
|
-
status:
|
|
100
|
+
status: StakingStatus.NOT_EARNING,
|
|
180
101
|
validatorAddress: delegation.owner,
|
|
181
102
|
validatorIdentity: identity,
|
|
182
103
|
activeStake: bnActiveStake.toString(),
|
|
@@ -188,11 +109,9 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
188
109
|
const collatorInfo = _collatorInfo.toPrimitive();
|
|
189
110
|
nomination.validatorMinStake = collatorInfo.lowestTopDelegationAmount.toString();
|
|
190
111
|
}));
|
|
191
|
-
const stakingStatus = getStakingStatusByNominations(bnTotalActiveStake, nominationList);
|
|
192
112
|
return {
|
|
193
113
|
chain,
|
|
194
114
|
type: StakingType.NOMINATED,
|
|
195
|
-
status: stakingStatus,
|
|
196
115
|
address: address,
|
|
197
116
|
activeStake: bnTotalActiveStake.toString(),
|
|
198
117
|
nominations: nominationList,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
2
|
import { ChainStakingMetadata, NominationPoolInfo, NominatorMetadata, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
4
|
export interface PalletStakingNominations {
|
|
@@ -18,10 +17,7 @@ export interface PalletStakingStakingLedger {
|
|
|
18
17
|
unlocking: UnlockingChunk[];
|
|
19
18
|
claimedRewards: number[];
|
|
20
19
|
}
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function validatePoolBondingCondition(chainInfo: _ChainInfo, amount: string, selectedPool: NominationPoolInfo, address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
23
|
-
export declare function validateRelayBondingCondition(chainInfo: _ChainInfo, amount: string, selectedValidators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
24
|
-
export declare function getRelayChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
20
|
+
export declare function getRelayChainStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
25
21
|
export declare function getRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
26
22
|
export declare function getRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
27
23
|
export declare function getRelayValidatorsInfo(chain: string, substrateApi: _SubstrateApi, decimals: number, chainStakingMetadata: ChainStakingMetadata): Promise<ValidatorInfo[]>;
|
|
@@ -1,99 +1,23 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { StakingStatus, StakingTxErrorType, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
5
|
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateValidatorStakedReturn, getCommission, parseIdentity, parsePoolStashAddress, transformPoolName } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
6
|
import { _STAKING_CHAIN_GROUP, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
|
-
import {
|
|
7
|
+
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
8
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
9
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
11
10
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
12
|
-
export function
|
|
13
|
-
|
|
14
|
-
const bnActiveStake = new BN(nominatorMetadata.activeStake);
|
|
15
|
-
const bnRemainingStake = bnActiveStake.sub(new BN(amount));
|
|
16
|
-
const minStake = new BN(chainStakingMetadata.minPoolBonding || '0');
|
|
17
|
-
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
18
|
-
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
19
|
-
}
|
|
20
|
-
if (nominatorMetadata.unstakings.length > chainStakingMetadata.maxWithdrawalRequestPerValidator) {
|
|
21
|
-
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_UNSTAKING));
|
|
22
|
-
}
|
|
23
|
-
return errors;
|
|
24
|
-
}
|
|
25
|
-
export function validatePoolBondingCondition(chainInfo, amount, selectedPool, address, chainStakingMetadata, nominatorMetadata) {
|
|
26
|
-
// cannot stake when unstake all
|
|
27
|
-
// amount >= min stake
|
|
28
|
-
const errors = [];
|
|
29
|
-
let bnTotalStake = new BN(amount);
|
|
30
|
-
const bnMinStake = new BN(chainStakingMetadata.minPoolBonding || '0');
|
|
31
|
-
if (nominatorMetadata) {
|
|
32
|
-
const bnCurrentActiveStake = new BN(nominatorMetadata.activeStake);
|
|
33
|
-
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
34
|
-
if (!bnCurrentActiveStake.gt(BN_ZERO)) {
|
|
35
|
-
errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
39
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
40
|
-
}
|
|
41
|
-
return errors;
|
|
42
|
-
}
|
|
43
|
-
export function validateRelayBondingCondition(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata) {
|
|
44
|
-
const errors = [];
|
|
45
|
-
let bnTotalStake = new BN(amount);
|
|
46
|
-
const bnMinStake = new BN(chainStakingMetadata.minStake);
|
|
47
|
-
if (!nominatorMetadata) {
|
|
48
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
49
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
50
|
-
}
|
|
51
|
-
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
52
|
-
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
53
|
-
}
|
|
54
|
-
return errors;
|
|
55
|
-
}
|
|
56
|
-
const bnCurrentActiveStake = new BN(nominatorMetadata.activeStake);
|
|
57
|
-
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
58
|
-
if (!bnTotalStake.gte(bnMinStake)) {
|
|
59
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
60
|
-
}
|
|
61
|
-
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
62
|
-
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
63
|
-
}
|
|
64
|
-
return errors;
|
|
65
|
-
}
|
|
66
|
-
export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
67
|
-
var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$s, _chainApi$api$query2, _chainApi$api$query2$, _chainApi$api$query3, _chainApi$api$query3$;
|
|
68
|
-
const chain = chainInfo.slug;
|
|
69
|
-
const {
|
|
70
|
-
decimals
|
|
71
|
-
} = _getChainNativeTokenBasicInfo(chainInfo);
|
|
11
|
+
export async function getRelayChainStakingMetadata(chain, substrateApi) {
|
|
12
|
+
var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$n;
|
|
72
13
|
const chainApi = await substrateApi.isReady;
|
|
73
14
|
const _era = await chainApi.api.query.staking.currentEra();
|
|
74
15
|
const currentEra = _era.toString();
|
|
75
16
|
const maxNominations = chainApi.api.consts.staking.maxNominations.toString();
|
|
76
17
|
const maxUnlockingChunks = chainApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
77
18
|
const unlockingEras = chainApi.api.consts.staking.bondingDuration.toString();
|
|
78
|
-
const [_totalEraStake, _totalIssuance, _auctionCounter, _minimumActiveStake,
|
|
79
|
-
const
|
|
80
|
-
const nominatorList = [];
|
|
81
|
-
for (const item of eraStakers) {
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
83
|
-
const rawValidatorStat = item[1].toHuman();
|
|
84
|
-
const eraNominators = rawValidatorStat.others;
|
|
85
|
-
for (const nominator of eraNominators) {
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
87
|
-
if (!nominatorList.includes(nominator.who)) {
|
|
88
|
-
nominatorList.push(nominator.who);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
93
|
-
const minNominatorBond = _minNominatorBond.toString();
|
|
94
|
-
const bnMinActiveStake = new BN(minActiveStake);
|
|
95
|
-
const bnMinNominatorBond = new BN(minNominatorBond);
|
|
96
|
-
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
19
|
+
const [_totalEraStake, _totalIssuance, _auctionCounter, _minimumActiveStake, _minPoolJoin] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.balances.totalIssuance(), (_chainApi$api$query$a = chainApi.api.query.auctions) === null || _chainApi$api$query$a === void 0 ? void 0 : _chainApi$api$query$a.auctionCounter(), chainApi.api.query.staking.minimumActiveStake(), (_chainApi$api$query = chainApi.api.query) === null || _chainApi$api$query === void 0 ? void 0 : (_chainApi$api$query$n = _chainApi$api$query.nominationPools) === null || _chainApi$api$query$n === void 0 ? void 0 : _chainApi$api$query$n.minJoinBond()]);
|
|
20
|
+
const minStake = _minimumActiveStake.toString();
|
|
97
21
|
const minPoolJoin = (_minPoolJoin === null || _minPoolJoin === void 0 ? void 0 : _minPoolJoin.toString()) || undefined;
|
|
98
22
|
const rawTotalEraStake = _totalEraStake.toString();
|
|
99
23
|
const rawTotalIssuance = _totalIssuance.toString();
|
|
@@ -111,30 +35,21 @@ export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
111
35
|
expectedReturn,
|
|
112
36
|
// in %, annually
|
|
113
37
|
inflation,
|
|
114
|
-
minStake
|
|
115
|
-
minPoolBonding: (10 ** decimals).toString(),
|
|
116
|
-
// default is 1
|
|
38
|
+
minStake,
|
|
117
39
|
maxValidatorPerNominator: parseInt(maxNominations),
|
|
118
40
|
maxWithdrawalRequestPerValidator: parseInt(maxUnlockingChunks),
|
|
119
41
|
allowCancelUnstaking: true,
|
|
120
42
|
unstakingPeriod: unlockingPeriod,
|
|
121
|
-
minJoinNominationPool: minPoolJoin
|
|
122
|
-
nominatorCount: nominatorList.length
|
|
43
|
+
minJoinNominationPool: minPoolJoin
|
|
123
44
|
};
|
|
124
45
|
}
|
|
125
46
|
export async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
126
|
-
var _chainApi$api$query4, _chainApi$api$query4$, _chainApi$api$query5, _chainApi$api$query5$, _chainApi$api$query6, _chainApi$api$query6$, _chainApi$api$query7, _chainApi$api$query7$, _chainApi$api$query8, _chainApi$api$query8$, _chainApi$api$query9, _chainApi$api$query9$, _chainApi$api$query10, _chainApi$api$query11;
|
|
127
47
|
if (isEthereumAddress(address)) {
|
|
128
48
|
return;
|
|
129
49
|
}
|
|
130
50
|
const chain = chainInfo.slug;
|
|
131
51
|
const chainApi = await substrateApi.isReady;
|
|
132
|
-
const [_ledger, _nominations, _currentEra, _bonded
|
|
133
|
-
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
134
|
-
const minNominatorBond = _minNominatorBond.toString();
|
|
135
|
-
const bnMinActiveStake = new BN(minActiveStake);
|
|
136
|
-
const bnMinNominatorBond = new BN(minNominatorBond);
|
|
137
|
-
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
52
|
+
const [_ledger, _nominations, _currentEra, _bonded] = await Promise.all([chainApi.api.query.staking.ledger(address), chainApi.api.query.staking.nominators(address), chainApi.api.query.staking.currentEra(), chainApi.api.query.staking.bonded(address)]);
|
|
138
53
|
const _maxNominatorRewardedPerValidator = chainApi.api.consts.staking.maxNominatorRewardedPerValidator.toString();
|
|
139
54
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
140
55
|
const ledger = _ledger.toPrimitive();
|
|
@@ -144,6 +59,7 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
144
59
|
if (!ledger) {
|
|
145
60
|
return;
|
|
146
61
|
}
|
|
62
|
+
let stakingStatus = StakingStatus.NOT_EARNING;
|
|
147
63
|
const activeStake = ledger.active.toString();
|
|
148
64
|
const nominationList = [];
|
|
149
65
|
const unstakingList = [];
|
|
@@ -158,10 +74,7 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
158
74
|
const topNominators = eraStaker.others.map(nominator => {
|
|
159
75
|
return nominator.who;
|
|
160
76
|
});
|
|
161
|
-
if (
|
|
162
|
-
// if nominator has target but not in nominator list
|
|
163
|
-
nominationStatus = StakingStatus.WAITING;
|
|
164
|
-
} else if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
77
|
+
if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes(reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo)))) {
|
|
165
78
|
// if address in top nominators
|
|
166
79
|
nominationStatus = StakingStatus.EARNING_REWARD;
|
|
167
80
|
}
|
|
@@ -175,20 +88,11 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
175
88
|
}));
|
|
176
89
|
}
|
|
177
90
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (nomination.status === StakingStatus.EARNING_REWARD) {
|
|
184
|
-
// only need 1 earning nomination to count
|
|
185
|
-
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
186
|
-
} else if (nomination.status === StakingStatus.WAITING) {
|
|
187
|
-
waitingNominationCount += 1;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (waitingNominationCount === nominationList.length) {
|
|
191
|
-
stakingStatus = StakingStatus.WAITING;
|
|
91
|
+
for (const nomination of nominationList) {
|
|
92
|
+
if (nomination.status === StakingStatus.EARNING_REWARD) {
|
|
93
|
+
// only need 1 earning nomination to count
|
|
94
|
+
stakingStatus = StakingStatus.EARNING_REWARD;
|
|
95
|
+
break;
|
|
192
96
|
}
|
|
193
97
|
}
|
|
194
98
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
@@ -266,10 +170,6 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
266
170
|
waitingTime: waitingTime > 0 ? waitingTime : 0
|
|
267
171
|
});
|
|
268
172
|
});
|
|
269
|
-
const bnActiveStake = new BN(poolMemberInfo.points.toString());
|
|
270
|
-
if (!bnActiveStake.gt(BN_ZERO)) {
|
|
271
|
-
stakingStatus = StakingStatus.NOT_EARNING;
|
|
272
|
-
}
|
|
273
173
|
return {
|
|
274
174
|
chain: chainInfo.slug,
|
|
275
175
|
type: StakingType.POOLED,
|
|
@@ -330,9 +230,9 @@ export async function getRelayValidatorsInfo(chain, substrateApi, decimals, chai
|
|
|
330
230
|
}
|
|
331
231
|
const extraInfoMap = {};
|
|
332
232
|
await Promise.all(allValidators.map(async address => {
|
|
333
|
-
var _chainApi$api$
|
|
233
|
+
var _chainApi$api$query2, _chainApi$api$query2$, _identityInfo$judgeme;
|
|
334
234
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
335
|
-
const [_commissionInfo, _identityInfo] = await Promise.all([chainApi.api.query.staking.validators(address), (_chainApi$api$
|
|
235
|
+
const [_commissionInfo, _identityInfo] = await Promise.all([chainApi.api.query.staking.validators(address), (_chainApi$api$query2 = chainApi.api.query) === null || _chainApi$api$query2 === void 0 ? void 0 : (_chainApi$api$query2$ = _chainApi$api$query2.identity) === null || _chainApi$api$query2$ === void 0 ? void 0 : _chainApi$api$query2$.identityOf(address)]);
|
|
336
236
|
const commissionInfo = _commissionInfo.toHuman();
|
|
337
237
|
const identityInfo = _identityInfo ? _identityInfo.toHuman() : null;
|
|
338
238
|
let identity;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { NominationInfo, NominatorMetadata,
|
|
2
|
+
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
4
4
|
import { ApiPromise } from '@polkadot/api';
|
|
5
5
|
import { BN } from '@polkadot/util';
|
|
@@ -149,7 +149,6 @@ export declare enum StakingAction {
|
|
|
149
149
|
CANCEL_UNSTAKE = "CANCEL_UNSTAKE"
|
|
150
150
|
}
|
|
151
151
|
export declare function getStakingAvailableActionsByChain(chain: string, type: StakingType): StakingAction[];
|
|
152
|
-
export declare function getStakingAvailableActionsByNominator(nominatorMetadata: NominatorMetadata
|
|
152
|
+
export declare function getStakingAvailableActionsByNominator(nominatorMetadata: NominatorMetadata): StakingAction[];
|
|
153
153
|
export declare function isActionFromValidator(stakingType: StakingType, chain: string): boolean;
|
|
154
154
|
export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
|
|
155
|
-
export declare function getStakingStatusByNominations(bnTotalActiveStake: BN, nominationList: NominationInfo[]): StakingStatus;
|
|
@@ -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 {
|
|
4
|
+
import { StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
6
|
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
@@ -125,8 +125,11 @@ export function getBondedValidators(nominations) {
|
|
|
125
125
|
const bondedValidators = [];
|
|
126
126
|
let nominationCount = 0;
|
|
127
127
|
for (const nomination of nominations) {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const bnActiveStake = new BN(nomination.activeStake);
|
|
129
|
+
if (bnActiveStake.gt(BN_ZERO)) {
|
|
130
|
+
nominationCount += 1;
|
|
131
|
+
bondedValidators.push(reformatAddress(nomination.validatorAddress, 0));
|
|
132
|
+
}
|
|
130
133
|
}
|
|
131
134
|
return {
|
|
132
135
|
nominationCount,
|
|
@@ -168,15 +171,13 @@ export function getStakingAvailableActionsByChain(chain, type) {
|
|
|
168
171
|
}
|
|
169
172
|
return [StakingAction.STAKE, StakingAction.UNSTAKE, StakingAction.WITHDRAW, StakingAction.CANCEL_UNSTAKE];
|
|
170
173
|
}
|
|
171
|
-
export function getStakingAvailableActionsByNominator(nominatorMetadata
|
|
174
|
+
export function getStakingAvailableActionsByNominator(nominatorMetadata) {
|
|
172
175
|
const result = [StakingAction.STAKE];
|
|
173
176
|
const bnActiveStake = new BN(nominatorMetadata.activeStake);
|
|
174
177
|
if (nominatorMetadata.activeStake && bnActiveStake.gt(BN_ZERO)) {
|
|
175
178
|
result.push(StakingAction.UNSTAKE);
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
const bnUnclaimedReward = new BN(unclaimedReward || '0');
|
|
179
|
-
if ((nominatorMetadata.type === StakingType.POOLED || isAmplitudeNetwork) && bnUnclaimedReward.gt(BN_ZERO) || isAstarNetwork) {
|
|
179
|
+
const isChainAllowClaimReward = _STAKING_CHAIN_GROUP.amplitude.includes(nominatorMetadata.chain) || _STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain);
|
|
180
|
+
if (nominatorMetadata.type === StakingType.POOLED || isChainAllowClaimReward) {
|
|
180
181
|
result.push(StakingAction.CLAIM_REWARD);
|
|
181
182
|
}
|
|
182
183
|
}
|
|
@@ -218,23 +219,4 @@ export function getWithdrawalInfo(nominatorMetadata) {
|
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
return result;
|
|
221
|
-
}
|
|
222
|
-
export function getStakingStatusByNominations(bnTotalActiveStake, nominationList) {
|
|
223
|
-
let stakingStatus = StakingStatus.EARNING_REWARD;
|
|
224
|
-
if (bnTotalActiveStake.isZero()) {
|
|
225
|
-
stakingStatus = StakingStatus.NOT_EARNING;
|
|
226
|
-
} else {
|
|
227
|
-
let invalidDelegationCount = 0;
|
|
228
|
-
for (const nomination of nominationList) {
|
|
229
|
-
if (nomination.status === StakingStatus.NOT_EARNING) {
|
|
230
|
-
invalidDelegationCount += 1;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (invalidDelegationCount > 0 && invalidDelegationCount < nominationList.length) {
|
|
234
|
-
stakingStatus = StakingStatus.PARTIALLY_EARNING;
|
|
235
|
-
} else if (invalidDelegationCount === nominationList.length) {
|
|
236
|
-
stakingStatus = StakingStatus.NOT_EARNING;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return stakingStatus;
|
|
240
222
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
5
4
|
import { _PSP22_ABI, _PSP34_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
6
5
|
import { ContractPromise } from '@polkadot/api-contract';
|
|
7
6
|
export function getPSP22ContractPromise(apiPromise, contractAddress) {
|
|
@@ -15,10 +14,10 @@ export async function getPSP34TransferExtrinsic(networkKey, substrateApi, sender
|
|
|
15
14
|
const onChainOption = params.onChainOption;
|
|
16
15
|
try {
|
|
17
16
|
const contractPromise = getPSP34ContractPromise(substrateApi.api, contractAddress);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const transferQuery = await contractPromise.query['psp34::transfer'](senderAddress, {
|
|
18
|
+
gasLimit: -1
|
|
19
|
+
}, recipientAddress, onChainOption, {});
|
|
20
|
+
const gasLimit = transferQuery.gasRequired.toString();
|
|
22
21
|
return contractPromise.tx['psp34::transfer']({
|
|
23
22
|
gasLimit
|
|
24
23
|
}, recipientAddress, onChainOption, {});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { getBeneficiary,
|
|
4
|
+
import { FOUR_INSTRUCTIONS_WEIGHT, getBeneficiary, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
5
5
|
import { _getSubstrateParaId, _getXcmAssetMultilocation, _isSubstrateParaChain, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
function getDestinationChainLocation(destinationChainInfo) {
|
|
7
7
|
if (_isSubstrateParaChain(destinationChainInfo)) {
|
|
@@ -36,7 +36,7 @@ function getAssetLocation(tokenInfo, sendingValue) {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
39
|
-
const weightParam =
|
|
39
|
+
const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? POLKADOT_UNLIMITED_WEIGHT : FOUR_INSTRUCTIONS_WEIGHT;
|
|
40
40
|
const beneficiary = getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress);
|
|
41
41
|
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
42
42
|
const assetLocation = getAssetLocation(tokenInfo, value);
|
package/koni/api/xcm/utils.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
export declare const FOUR_INSTRUCTIONS_WEIGHT
|
|
3
|
-
export declare const FOUR_INSTRUCTIONS_LIMITED_WEIGHT: {
|
|
2
|
+
export declare const FOUR_INSTRUCTIONS_WEIGHT: {
|
|
4
3
|
Limited: number;
|
|
5
4
|
};
|
|
5
|
+
export declare const POLKADOT_LIMITED_WEIGHT = 1000000000;
|
|
6
|
+
export declare const POLKADOT_UNLIMITED_WEIGHT = "Unlimited";
|
|
6
7
|
export declare function getReceiverLocation(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, toAddress: string): Record<string, any>;
|
|
7
|
-
export declare function getBeneficiary(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, recipientAddress: string
|
|
8
|
-
|
|
8
|
+
export declare function getBeneficiary(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, recipientAddress: string): {
|
|
9
|
+
V1: {
|
|
9
10
|
parents: number;
|
|
10
11
|
interior: {
|
|
11
12
|
X1: Record<string, any>;
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
|
-
export declare
|
|
16
|
+
export declare const NETWORK_USE_UNLIMITED_WEIGHT: string[];
|
package/koni/api/xcm/utils.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
-
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { _getChainSubstrateAddressPrefix, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
|
|
7
|
-
export const FOUR_INSTRUCTIONS_WEIGHT =
|
|
8
|
-
export const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
|
|
7
|
+
export const FOUR_INSTRUCTIONS_WEIGHT = {
|
|
9
8
|
Limited: 5000000000
|
|
10
9
|
};
|
|
10
|
+
export const POLKADOT_LIMITED_WEIGHT = 1000000000;
|
|
11
|
+
export const POLKADOT_UNLIMITED_WEIGHT = 'Unlimited';
|
|
11
12
|
|
|
12
13
|
// get multilocation for destination chain from a parachain
|
|
13
14
|
|
|
14
15
|
export function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
if (destinationChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM || destinationChainInfo.slug === 'astarEvm') {
|
|
18
|
+
const ss58Address = evmToAddress(toAddress, _getChainSubstrateAddressPrefix(destinationChainInfo));
|
|
18
19
|
return {
|
|
19
20
|
AccountId32: {
|
|
20
21
|
network: 'Any',
|
|
@@ -37,10 +38,10 @@ export function getReceiverLocation(originChainInfo, destinationChainInfo, toAdd
|
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
export function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress
|
|
41
|
+
export function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress) {
|
|
41
42
|
const receiverLocation = getReceiverLocation(originChainInfo, destinationChainInfo, recipientAddress);
|
|
42
43
|
return {
|
|
43
|
-
|
|
44
|
+
V1: {
|
|
44
45
|
parents: 0,
|
|
45
46
|
interior: {
|
|
46
47
|
X1: receiverLocation
|
|
@@ -48,10 +49,4 @@ export function getBeneficiary(originChainInfo, destinationChainInfo, recipientA
|
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
|
-
export
|
|
52
|
-
return 'Unlimited';
|
|
53
|
-
// return api.tx.xTokens.transfer.meta.args[3].type.toString() ===
|
|
54
|
-
// 'XcmV2WeightLimit'
|
|
55
|
-
// ? 'Unlimited'
|
|
56
|
-
// : FOUR_INSTRUCTIONS_WEIGHT;
|
|
57
|
-
}
|
|
52
|
+
export const NETWORK_USE_UNLIMITED_WEIGHT = ['acala', 'karura', 'statemint', 'moonriver'];
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { FOUR_INSTRUCTIONS_WEIGHT,
|
|
4
|
+
import { FOUR_INSTRUCTIONS_WEIGHT, getReceiverLocation, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
5
5
|
import { _XCM_TYPE } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
6
|
import { _getSubstrateParaId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType, _getXcmTransferType, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
7
|
function getCurrencyId(tokenInfo) {
|
|
@@ -48,6 +48,6 @@ function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo,
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
51
|
-
const weightParam =
|
|
51
|
+
const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? POLKADOT_UNLIMITED_WEIGHT : FOUR_INSTRUCTIONS_WEIGHT;
|
|
52
52
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, recipientAddress), weightParam);
|
|
53
53
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { getBeneficiary,
|
|
4
|
+
import { FOUR_INSTRUCTIONS_WEIGHT, getBeneficiary, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
5
5
|
import { _getSubstrateParaId } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
-
function getDestinationChainLocation(destinationChainInfo
|
|
6
|
+
function getDestinationChainLocation(destinationChainInfo) {
|
|
7
7
|
return {
|
|
8
|
-
|
|
8
|
+
V1: {
|
|
9
9
|
parents: 0,
|
|
10
10
|
interior: {
|
|
11
11
|
X1: {
|
|
@@ -15,10 +15,10 @@ function getDestinationChainLocation(destinationChainInfo, version = 'V1') {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
function getTokenLocation(sendingValue
|
|
18
|
+
function getTokenLocation(sendingValue) {
|
|
19
19
|
return {
|
|
20
20
|
// always native token of relaychain
|
|
21
|
-
|
|
21
|
+
V1: [{
|
|
22
22
|
id: {
|
|
23
23
|
Concrete: {
|
|
24
24
|
parents: 0,
|
|
@@ -34,11 +34,10 @@ function getTokenLocation(sendingValue, version = 'V2') {
|
|
|
34
34
|
|
|
35
35
|
// this pallet is only used by Relaychains
|
|
36
36
|
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
37
|
-
const weightParam =
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const tokenLocation = getTokenLocation(value, xcmVer);
|
|
37
|
+
const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? POLKADOT_UNLIMITED_WEIGHT : FOUR_INSTRUCTIONS_WEIGHT;
|
|
38
|
+
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
39
|
+
const beneficiary = getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress);
|
|
40
|
+
const tokenLocation = getTokenLocation(value);
|
|
42
41
|
let method = 'limitedReserveTransferAssets';
|
|
43
42
|
if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
|
|
44
43
|
method = 'limitedTeleportAssets';
|