@subwallet/extension-base 1.2.3-1 → 1.2.5-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +0 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +2 -2
- package/cjs/core/logic-validation/transfer.js +0 -7
- package/cjs/core/substrate/nominationpools-pallet.js +11 -1
- package/cjs/core/substrate/system-pallet.js +2 -3
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +10 -119
- package/cjs/koni/api/staking/bonding/utils.js +38 -6
- package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
- package/cjs/koni/api/xcm/utils.js +8 -126
- package/cjs/koni/api/xcm/xTokens.js +10 -8
- package/cjs/koni/api/xcm/xcmPallet.js +6 -6
- package/cjs/koni/background/handlers/Extension.js +90 -113
- package/cjs/koni/background/handlers/Tabs.js +3 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +4 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +6 -3
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/utils/index.js +7 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +104 -113
- package/cjs/services/earning-service/handlers/special.js +3 -3
- package/cjs/services/earning-service/service.js +1 -1
- package/cjs/services/earning-service/utils/index.js +6 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/request-service/constants.js +5 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +32 -12
- package/cjs/services/swap-service/handler/base-handler.js +5 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/core/logic-validation/earning.d.ts +1 -1
- package/core/logic-validation/earning.js +2 -2
- package/core/logic-validation/transfer.js +0 -7
- package/core/substrate/nominationpools-pallet.d.ts +4 -1
- package/core/substrate/nominationpools-pallet.js +8 -1
- package/core/substrate/system-pallet.js +2 -3
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +0 -3
- package/koni/api/dotsama/transfer.js +12 -119
- package/koni/api/staking/bonding/utils.d.ts +6 -2
- package/koni/api/staking/bonding/utils.js +33 -4
- package/koni/api/xcm/polkadotXcm.js +14 -22
- package/koni/api/xcm/utils.d.ts +3 -48
- package/koni/api/xcm/utils.js +5 -114
- package/koni/api/xcm/xTokens.js +12 -10
- package/koni/api/xcm/xcmPallet.js +7 -7
- package/koni/background/handlers/Extension.d.ts +1 -3
- package/koni/background/handlers/Extension.js +8 -28
- package/koni/background/handlers/Tabs.js +3 -2
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -2
- package/page/index.js +4 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +8 -5
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/utils/index.d.ts +3 -2
- package/services/chain-service/utils/index.js +5 -2
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +5 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +106 -115
- package/services/earning-service/handlers/special.js +3 -3
- package/services/earning-service/service.js +1 -1
- package/services/earning-service/utils/index.d.ts +2 -0
- package/services/earning-service/utils/index.js +6 -2
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/services/migration-service/scripts/index.js +2 -2
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +4 -2
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +22 -3
- package/services/swap-service/handler/base-handler.js +5 -3
- package/services/swap-service/handler/hydradx-handler.js +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import BigN from 'bignumber.js';
|
|
1
2
|
export declare type PalletNominationPoolsPoolMember = {
|
|
2
3
|
poolId: number;
|
|
3
4
|
points: number;
|
|
4
5
|
lastRecordedRewardCounter: number;
|
|
5
6
|
unbondingEras: Record<string, number>;
|
|
6
7
|
};
|
|
7
|
-
export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember):
|
|
8
|
+
export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
9
|
+
export declare function _getUnbondingStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
10
|
+
export declare function _getTotalStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import BigN from 'bignumber.js';
|
|
4
5
|
export function _getActiveStakeInNominationPool(memberInfo) {
|
|
5
|
-
return memberInfo.points.toString();
|
|
6
|
+
return new BigN(memberInfo.points.toString());
|
|
7
|
+
}
|
|
8
|
+
export function _getUnbondingStakeInNominationPool(memberInfo) {
|
|
9
|
+
return new BigN(Object.values(memberInfo.unbondingEras).reduce((a, b) => a + b, 0));
|
|
10
|
+
}
|
|
11
|
+
export function _getTotalStakeInNominationPool(memberInfo) {
|
|
12
|
+
return _getActiveStakeInNominationPool(memberInfo).plus(_getUnbondingStakeInNominationPool(memberInfo));
|
|
6
13
|
}
|
|
@@ -62,10 +62,9 @@ function _getSystemPalletTotalBalanceV2(accountInfo) {
|
|
|
62
62
|
function _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode) {
|
|
63
63
|
const bnAppliedExistentialDeposit = new BigN(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
|
|
64
64
|
const bnAppliedFrozen = BigN.max(accountInfo.data.feeFrozen, accountInfo.data.miscFrozen);
|
|
65
|
-
const
|
|
66
|
-
const bnTransferableBalance = bnTotalBalance.minus(BigN.max(bnAppliedFrozen, accountInfo.data.reserved, bnAppliedExistentialDeposit));
|
|
65
|
+
const bnTransferableBalance = new BigN(accountInfo.data.free).minus(BigN.max(bnAppliedFrozen, bnAppliedExistentialDeposit));
|
|
67
66
|
return BigN.max(bnTransferableBalance, 0).toFixed();
|
|
68
67
|
}
|
|
69
68
|
function _getSystemPalletTotalBalanceV1(accountInfo) {
|
|
70
|
-
return new BigN(accountInfo.data.free).toFixed();
|
|
69
|
+
return new BigN(accountInfo.data.free).plus(accountInfo.data.reserved).toFixed();
|
|
71
70
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
export declare function _getXcmDestWeight(originChainInfo: _ChainInfo): "Unlimited" | 5000000000;
|
|
4
|
+
export declare function _getXcmBeneficiary(destChainInfo: _ChainInfo, recipient: _Address, version: number): {
|
|
5
|
+
[x: string]: {
|
|
6
|
+
parents: number;
|
|
7
|
+
interior: {
|
|
8
|
+
X1: {
|
|
9
|
+
AccountId32: {
|
|
10
|
+
network: string | undefined;
|
|
11
|
+
id: Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
AccountKey20?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
AccountKey20: {
|
|
16
|
+
network: string | undefined;
|
|
17
|
+
key: string;
|
|
18
|
+
};
|
|
19
|
+
AccountId32?: undefined;
|
|
20
|
+
} | ({
|
|
21
|
+
AccountId32: {
|
|
22
|
+
network: string | undefined;
|
|
23
|
+
id: Uint8Array;
|
|
24
|
+
};
|
|
25
|
+
AccountKey20?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
AccountKey20: {
|
|
28
|
+
network: string | undefined;
|
|
29
|
+
key: string;
|
|
30
|
+
};
|
|
31
|
+
AccountId32?: undefined;
|
|
32
|
+
})[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function _getXcmMultiAssets(tokenInfo: _ChainAsset, value: string, version: number): {
|
|
37
|
+
[x: string]: {
|
|
38
|
+
id: Record<string, any>;
|
|
39
|
+
fun: {
|
|
40
|
+
Fungible: string;
|
|
41
|
+
};
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
export declare function _getXcmMultiLocation(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, version: number, recipient?: _Address): {
|
|
45
|
+
[x: string]: {
|
|
46
|
+
parents: number;
|
|
47
|
+
interior: unknown;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { _getChainSubstrateAddressPrefix, _getEvmChainId, _getSubstrateParaId, _getSubstrateRelayParent, _getXcmAssetMultilocation, _isChainEvmCompatible, _isSubstrateParaChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
|
|
7
|
+
const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
|
|
8
|
+
const UNLIMITED_WEIGHT = 'Unlimited';
|
|
9
|
+
export function _getXcmDestWeight(originChainInfo) {
|
|
10
|
+
if (['pioneer'].includes(originChainInfo.slug)) {
|
|
11
|
+
return FOUR_INSTRUCTIONS_WEIGHT;
|
|
12
|
+
}
|
|
13
|
+
return UNLIMITED_WEIGHT;
|
|
14
|
+
}
|
|
15
|
+
export function _getXcmBeneficiary(destChainInfo, recipient, version) {
|
|
16
|
+
const receiverLocation = version < 4 // from V4, X1 is also an array
|
|
17
|
+
? _getRecipientLocation(destChainInfo, recipient, version) : [_getRecipientLocation(destChainInfo, recipient, version)];
|
|
18
|
+
return {
|
|
19
|
+
[`V${version}`]: {
|
|
20
|
+
parents: 0,
|
|
21
|
+
interior: {
|
|
22
|
+
X1: receiverLocation
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function _getXcmMultiAssets(tokenInfo, value, version) {
|
|
28
|
+
const assetId = _getAssetIdentifier(tokenInfo, version);
|
|
29
|
+
return {
|
|
30
|
+
[`V${version}`]: [{
|
|
31
|
+
id: assetId,
|
|
32
|
+
fun: {
|
|
33
|
+
Fungible: value
|
|
34
|
+
}
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function _getXcmMultiLocation(originChainInfo, destChainInfo, version, recipient) {
|
|
39
|
+
const isWithinSameConsensus = _isXcmWithinSameConsensus(originChainInfo, destChainInfo);
|
|
40
|
+
const parents = _getMultiLocationParent(originChainInfo, isWithinSameConsensus);
|
|
41
|
+
const interior = _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient);
|
|
42
|
+
return {
|
|
43
|
+
[`V${version}`]: {
|
|
44
|
+
parents,
|
|
45
|
+
interior
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
function _isXcmWithinSameConsensus(originChainInfo, destChainInfo) {
|
|
53
|
+
return _getSubstrateRelayParent(originChainInfo) === destChainInfo.slug || _getSubstrateRelayParent(destChainInfo) === originChainInfo.slug || _getSubstrateRelayParent(originChainInfo) === _getSubstrateRelayParent(destChainInfo);
|
|
54
|
+
}
|
|
55
|
+
function _getMultiLocationParent(originChainInfo, isWithinSameConsensus) {
|
|
56
|
+
let parent = 0; // how many hops up the hierarchy
|
|
57
|
+
|
|
58
|
+
if (_isSubstrateParaChain(originChainInfo)) {
|
|
59
|
+
parent += 1;
|
|
60
|
+
}
|
|
61
|
+
if (!isWithinSameConsensus) {
|
|
62
|
+
parent += 1;
|
|
63
|
+
}
|
|
64
|
+
return parent;
|
|
65
|
+
}
|
|
66
|
+
function _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient) {
|
|
67
|
+
const junctions = [];
|
|
68
|
+
if (isWithinSameConsensus) {
|
|
69
|
+
if (_isSubstrateParaChain(destChainInfo)) {
|
|
70
|
+
junctions.push({
|
|
71
|
+
Parachain: _getSubstrateParaId(destChainInfo)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
junctions.push({
|
|
76
|
+
GlobalConsensus: _getGlobalConsensusJunction(destChainInfo, version)
|
|
77
|
+
});
|
|
78
|
+
if (_isSubstrateParaChain(destChainInfo)) {
|
|
79
|
+
junctions.push({
|
|
80
|
+
Parachain: _getSubstrateParaId(destChainInfo)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (recipient) {
|
|
85
|
+
junctions.push(_getRecipientLocation(destChainInfo, recipient, version));
|
|
86
|
+
}
|
|
87
|
+
if (junctions.length === 0 && !recipient) {
|
|
88
|
+
return 'Here';
|
|
89
|
+
}
|
|
90
|
+
if (version < 4 && junctions.length === 1) {
|
|
91
|
+
return {
|
|
92
|
+
X1: junctions[0]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
[`X${junctions.length}`]: junctions
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function _getGlobalConsensusJunction(destChainInfo, version) {
|
|
100
|
+
let chainSlug = destChainInfo.slug;
|
|
101
|
+
let evmChainId;
|
|
102
|
+
if (_isSubstrateParaChain(destChainInfo)) {
|
|
103
|
+
const relaySlug = _getSubstrateRelayParent(destChainInfo);
|
|
104
|
+
if (!relaySlug) {
|
|
105
|
+
throw Error('Parachain must have a parent chainSlug');
|
|
106
|
+
}
|
|
107
|
+
chainSlug = relaySlug;
|
|
108
|
+
} else {
|
|
109
|
+
evmChainId = _getEvmChainId(destChainInfo);
|
|
110
|
+
}
|
|
111
|
+
if (evmChainId) {
|
|
112
|
+
return {
|
|
113
|
+
Ethereum: {
|
|
114
|
+
chainId: evmChainId
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
switch (chainSlug) {
|
|
119
|
+
case COMMON_CHAIN_SLUGS.POLKADOT:
|
|
120
|
+
return version < 4 ? {
|
|
121
|
+
Polkadot: null
|
|
122
|
+
} : 'Polkadot';
|
|
123
|
+
case COMMON_CHAIN_SLUGS.KUSAMA:
|
|
124
|
+
return version < 4 ? {
|
|
125
|
+
Kusama: null
|
|
126
|
+
} : 'Kusama';
|
|
127
|
+
default:
|
|
128
|
+
return version < 4 ? {
|
|
129
|
+
Rococo: null
|
|
130
|
+
} : 'Rococo';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function _getRecipientLocation(destChainInfo, recipient, version) {
|
|
134
|
+
const network = _getNetworkByVersion(version);
|
|
135
|
+
if (destChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
136
|
+
const ss58Address = evmToAddress(recipient, _getChainSubstrateAddressPrefix(destChainInfo)); // TODO: shouldn't pass addressPrefix directly
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
AccountId32: {
|
|
140
|
+
network,
|
|
141
|
+
id: decodeAddress(ss58Address)
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (_isChainEvmCompatible(destChainInfo)) {
|
|
146
|
+
return {
|
|
147
|
+
AccountKey20: {
|
|
148
|
+
network,
|
|
149
|
+
key: recipient
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
AccountId32: {
|
|
155
|
+
network,
|
|
156
|
+
id: decodeAddress(recipient)
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function _getAssetIdentifier(tokenInfo, version) {
|
|
161
|
+
const assetIdentifier = _getXcmAssetMultilocation(tokenInfo);
|
|
162
|
+
if (!assetIdentifier) {
|
|
163
|
+
throw new Error('Asset must have multilocation');
|
|
164
|
+
}
|
|
165
|
+
return version >= 4 // from V4, Concrete is removed
|
|
166
|
+
? assetIdentifier : {
|
|
167
|
+
Concrete: assetIdentifier
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function _getNetworkByVersion(version) {
|
|
171
|
+
switch (version) {
|
|
172
|
+
case 1:
|
|
173
|
+
case 2:
|
|
174
|
+
return 'Any';
|
|
175
|
+
case 3:
|
|
176
|
+
case 4:
|
|
177
|
+
return undefined;
|
|
178
|
+
default:
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { SupportTransferResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
2
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
3
|
import BigN from 'bignumber.js';
|
|
5
4
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
6
|
-
export declare function checkReferenceCount(networkKey: string, address: string, substrateApiMap: Record<string, _SubstrateApi>, chainInfo: _ChainInfo): Promise<boolean>;
|
|
7
|
-
export declare function checkSupportTransfer(networkKey: string, tokenInfo: _ChainAsset, substrateApiMap: Record<string, _SubstrateApi>, chainInfo: _ChainInfo): Promise<SupportTransferResponse>;
|
|
8
5
|
interface CreateTransferExtrinsicProps {
|
|
9
6
|
substrateApi: _SubstrateApi;
|
|
10
7
|
networkKey: string;
|
|
@@ -4,112 +4,13 @@
|
|
|
4
4
|
import { GearApi } from '@gear-js/api';
|
|
5
5
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
6
6
|
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
7
|
-
import {
|
|
8
|
-
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
|
+
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isBridgedToken, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
10
|
import { getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
11
11
|
import BigN from 'bignumber.js';
|
|
12
12
|
import { BN, u8aToHex } from '@polkadot/util';
|
|
13
13
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
14
|
-
function isRefCount(accountInfo) {
|
|
15
|
-
return !!accountInfo.refcount;
|
|
16
|
-
}
|
|
17
|
-
export async function checkReferenceCount(networkKey, address, substrateApiMap, chainInfo) {
|
|
18
|
-
const apiProps = await substrateApiMap[networkKey].isReady;
|
|
19
|
-
const api = apiProps.api;
|
|
20
|
-
if (_isChainEvmCompatible(chainInfo)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const accountInfo = await api.query.system.account(address);
|
|
26
|
-
return accountInfo ? isRefCount(accountInfo) ? !accountInfo.refcount.isZero() : !accountInfo.consumers.isZero() : false;
|
|
27
|
-
}
|
|
28
|
-
export async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chainInfo) {
|
|
29
|
-
const substrateApi = await substrateApiMap[networkKey].isReady;
|
|
30
|
-
if (!tokenInfo) {
|
|
31
|
-
return {
|
|
32
|
-
supportTransfer: false,
|
|
33
|
-
supportTransferAll: false
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (_isChainEvmCompatible(chainInfo)) {
|
|
37
|
-
return {
|
|
38
|
-
supportTransfer: true,
|
|
39
|
-
supportTransferAll: true
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (tokenInfo.symbol.startsWith(_ZK_ASSET_PREFIX) && _MANTA_ZK_CHAIN_GROUP.includes(tokenInfo.originChain)) {
|
|
43
|
-
return {
|
|
44
|
-
supportTransfer: false,
|
|
45
|
-
supportTransferAll: false
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (_TRANSFER_NOT_SUPPORTED_CHAINS.includes(networkKey)) {
|
|
49
|
-
return {
|
|
50
|
-
supportTransfer: false,
|
|
51
|
-
supportTransferAll: false
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
const api = substrateApi.api;
|
|
55
|
-
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
56
|
-
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
57
|
-
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
58
|
-
const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
59
|
-
const result = {
|
|
60
|
-
supportTransfer: false,
|
|
61
|
-
supportTransferAll: false
|
|
62
|
-
};
|
|
63
|
-
if (!(isTxCurrenciesSupported || isTxBalancesSupported || isTxTokensSupported || isTxEqBalancesSupported)) {
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
if (_isTokenWasmSmartContract(tokenInfo) && api.query.contracts) {
|
|
67
|
-
// for PSP tokens
|
|
68
|
-
return {
|
|
69
|
-
supportTransfer: true,
|
|
70
|
-
supportTransferAll: true
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// TODO: need review
|
|
75
|
-
if (_TRANSFER_CHAIN_GROUP.acala.includes(networkKey) && !_isNativeToken(tokenInfo) && isTxCurrenciesSupported) {
|
|
76
|
-
result.supportTransfer = true;
|
|
77
|
-
result.supportTransferAll = true;
|
|
78
|
-
} else if (_TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !_isNativeToken(tokenInfo) && isTxTokensSupported) {
|
|
79
|
-
result.supportTransfer = true;
|
|
80
|
-
result.supportTransferAll = true;
|
|
81
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
82
|
-
// && !_isNativeToken(tokenInfo) && isTxEqBalancesSupported
|
|
83
|
-
) {
|
|
84
|
-
result.supportTransfer = false;
|
|
85
|
-
result.supportTransferAll = false;
|
|
86
|
-
// } else if (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) && _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
87
|
-
// result.supportTransfer = true;
|
|
88
|
-
// result.supportTransferAll = true;
|
|
89
|
-
} else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
|
|
90
|
-
result.supportTransfer = true;
|
|
91
|
-
result.supportTransferAll = true;
|
|
92
|
-
} else if (_TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !_isNativeToken(tokenInfo) && _BALANCE_TOKEN_GROUP.bitcountry.includes(tokenInfo.symbol)) {
|
|
93
|
-
result.supportTransfer = true;
|
|
94
|
-
result.supportTransferAll = true;
|
|
95
|
-
} else if (_TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
96
|
-
result.supportTransfer = true;
|
|
97
|
-
result.supportTransferAll = true;
|
|
98
|
-
} else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey)) {
|
|
99
|
-
result.supportTransfer = true;
|
|
100
|
-
result.supportTransferAll = true;
|
|
101
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey) && _isNativeToken(tokenInfo)) {
|
|
102
|
-
// result.supportTransfer = true;
|
|
103
|
-
// result.supportTransferAll = true;
|
|
104
|
-
} else if (_TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
105
|
-
result.supportTransfer = true;
|
|
106
|
-
result.supportTransferAll = true;
|
|
107
|
-
} else if (_TRANSFER_CHAIN_GROUP.centrifuge.includes(networkKey)) {
|
|
108
|
-
result.supportTransfer = true;
|
|
109
|
-
result.supportTransferAll = true;
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
14
|
export const createTransferExtrinsic = async ({
|
|
114
15
|
from,
|
|
115
16
|
networkKey,
|
|
@@ -131,11 +32,17 @@ export const createTransferExtrinsic = async ({
|
|
|
131
32
|
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
132
33
|
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
133
34
|
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
134
|
-
// const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
135
35
|
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
136
36
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
137
37
|
|
|
138
|
-
if (
|
|
38
|
+
if (_isBridgedToken(tokenInfo) && api.tx.foreignAssets) {
|
|
39
|
+
const onChainInfo = _getTokenOnChainInfo(tokenInfo);
|
|
40
|
+
if (transferAll) {
|
|
41
|
+
transfer = api.tx.foreignAssets.transfer(onChainInfo, to, value);
|
|
42
|
+
} else {
|
|
43
|
+
transfer = api.tx.foreignAssets.transferKeepAlive(onChainInfo, to, value);
|
|
44
|
+
}
|
|
45
|
+
} else if (_isTokenWasmSmartContract(tokenInfo) && api.query.contracts) {
|
|
139
46
|
const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
140
47
|
// @ts-ignore
|
|
141
48
|
const gasLimit = await getWasmContractGasLimit(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
|
|
@@ -177,25 +84,10 @@ export const createTransferExtrinsic = async ({
|
|
|
177
84
|
} else if (value) {
|
|
178
85
|
transfer = api.tx.tokens.transfer(to, _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo), new BN(value));
|
|
179
86
|
}
|
|
180
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
181
|
-
// && isTxEqBalancesSupported
|
|
182
|
-
) {
|
|
183
|
-
// transfer = api.tx.eqBalances.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
184
|
-
/* empty */
|
|
185
|
-
// } else if (!_isNativeToken(tokenInfo) && (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) || _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol))) {
|
|
186
|
-
// if (transferAll) {
|
|
187
|
-
// transfer = api.tx.kton.transferAll(to, false);
|
|
188
|
-
// } else if (value) {
|
|
189
|
-
// transfer = api.tx.kton.transfer(to, new BN(value));
|
|
190
|
-
// }
|
|
191
87
|
} else if (_TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
192
88
|
transfer = api.tx.currencies.transfer(to, _getTokenOnChainInfo(tokenInfo), value);
|
|
193
89
|
} else if (_TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
194
90
|
transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
195
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey)) {
|
|
196
|
-
// if (_isNativeToken(tokenInfo)) {
|
|
197
|
-
// transfer = api.tx.currencies.transferNativeCurrency(to, value);
|
|
198
|
-
// }
|
|
199
91
|
} else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
200
92
|
transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
201
93
|
} else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
|
|
@@ -236,10 +128,11 @@ export const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) =
|
|
|
236
128
|
} else {
|
|
237
129
|
var _paymentInfo$partialF;
|
|
238
130
|
const substrateApi = api;
|
|
131
|
+
const chainApi = await substrateApi.isReady;
|
|
239
132
|
const [mockTx] = await createTransferExtrinsic({
|
|
240
133
|
from: address,
|
|
241
134
|
networkKey: chainInfo.slug,
|
|
242
|
-
substrateApi,
|
|
135
|
+
substrateApi: chainApi,
|
|
243
136
|
to: address,
|
|
244
137
|
tokenInfo,
|
|
245
138
|
transferAll: true,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
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
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
5
|
import { EarningStatus, PalletStakingEraRewardPoints, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
5
6
|
import BigNumber from 'bignumber.js';
|
|
6
7
|
import { ApiPromise } from '@polkadot/api';
|
|
@@ -158,8 +159,11 @@ export declare function getEarningStatusByNominations(bnTotalActiveStake: BN, no
|
|
|
158
159
|
export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
|
|
159
160
|
export declare function getAvgValidatorEraReward(supportedDays: number, eraRewardHistory: Codec[]): BigNumber;
|
|
160
161
|
export declare function getSupportedDaysByHistoryDepth(erasPerDay: number, maxSupportedEras: number, liveDay?: number): number;
|
|
161
|
-
export declare function
|
|
162
|
-
export declare function
|
|
162
|
+
export declare function getRelayValidatorPointsMap(eraRewardMap: Record<string, PalletStakingEraRewardPoints>): Record<string, BigNumber>;
|
|
163
|
+
export declare function getRelayTopValidatorByPoints(validatorPointsList: Record<string, BigNumber>): string[];
|
|
164
|
+
export declare function getRelayBlockedValidatorList(validators: any[]): string[];
|
|
165
|
+
export declare function getRelayEraRewardMap(eraRewardPointArray: Codec[], startEraForPoints: number): Record<string, PalletStakingEraRewardPoints>;
|
|
166
|
+
export declare function getRelayMaxNominations(substrateApi: _SubstrateApi): Promise<string>;
|
|
163
167
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
164
168
|
export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
|
|
165
169
|
export declare const getExistUnstakeErrorMessage: (chain: string, type?: StakingType, isStakeMore?: boolean) => string;
|
|
@@ -354,13 +354,12 @@ export function getSupportedDaysByHistoryDepth(erasPerDay, maxSupportedEras, liv
|
|
|
354
354
|
return maxSupportDay;
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
export function
|
|
357
|
+
export function getRelayValidatorPointsMap(eraRewardMap) {
|
|
358
358
|
// mapping store validator and totalPoints
|
|
359
359
|
const validatorTotalPointsMap = {};
|
|
360
360
|
Object.values(eraRewardMap).forEach(info => {
|
|
361
361
|
const individual = info.individual;
|
|
362
|
-
Object.entries(individual).forEach(([validator,
|
|
363
|
-
const points = rawPoints.replaceAll(',', '');
|
|
362
|
+
Object.entries(individual).forEach(([validator, points]) => {
|
|
364
363
|
if (!validatorTotalPointsMap[validator]) {
|
|
365
364
|
validatorTotalPointsMap[validator] = new BigNumber(points);
|
|
366
365
|
} else {
|
|
@@ -370,7 +369,7 @@ export function getValidatorPointsMap(eraRewardMap) {
|
|
|
370
369
|
});
|
|
371
370
|
return validatorTotalPointsMap;
|
|
372
371
|
}
|
|
373
|
-
export function
|
|
372
|
+
export function getRelayTopValidatorByPoints(validatorPointsList) {
|
|
374
373
|
const sortValidatorPointsList = Object.fromEntries(Object.entries(validatorPointsList).sort((a, b) => a[1].minus(b[1]).toNumber()).reverse());
|
|
375
374
|
|
|
376
375
|
// keep 50% first validator
|
|
@@ -380,6 +379,36 @@ export function getTopValidatorByPoints(validatorPointsList) {
|
|
|
380
379
|
const top50PercentRecord = Object.fromEntries(top50PercentEntries);
|
|
381
380
|
return Object.keys(top50PercentRecord);
|
|
382
381
|
}
|
|
382
|
+
export function getRelayBlockedValidatorList(validators) {
|
|
383
|
+
const blockValidatorList = [];
|
|
384
|
+
for (const validator of validators) {
|
|
385
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
386
|
+
const validatorAddress = validator[0].toHuman()[0];
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
388
|
+
const validatorPrefs = validator[1].toHuman();
|
|
389
|
+
const isBlocked = validatorPrefs.blocked;
|
|
390
|
+
if (isBlocked) {
|
|
391
|
+
blockValidatorList.push(validatorAddress);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return blockValidatorList;
|
|
395
|
+
}
|
|
396
|
+
export function getRelayEraRewardMap(eraRewardPointArray, startEraForPoints) {
|
|
397
|
+
const eraRewardMap = {};
|
|
398
|
+
for (const item of eraRewardPointArray) {
|
|
399
|
+
eraRewardMap[startEraForPoints] = item.toPrimitive();
|
|
400
|
+
startEraForPoints++;
|
|
401
|
+
}
|
|
402
|
+
return eraRewardMap;
|
|
403
|
+
}
|
|
404
|
+
export async function getRelayMaxNominations(substrateApi) {
|
|
405
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$cal;
|
|
406
|
+
await substrateApi.isReady;
|
|
407
|
+
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16';
|
|
408
|
+
const _maxNominationsByNominationQuota = await ((_substrateApi$api$cal = substrateApi.api.call.stakingApi) === null || _substrateApi$api$cal === void 0 ? void 0 : _substrateApi$api$cal.nominationsQuota(0)); // todo: review param. Currently return constant for all param.
|
|
409
|
+
const maxNominationsByNominationQuota = _maxNominationsByNominationQuota === null || _maxNominationsByNominationQuota === void 0 ? void 0 : _maxNominationsByNominationQuota.toString();
|
|
410
|
+
return maxNominationsByNominationQuota || maxNominations;
|
|
411
|
+
}
|
|
383
412
|
export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
|
|
384
413
|
const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
|
|
385
414
|
const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
|
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
6
|
+
import { _isBridgedToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
|
-
|
|
8
|
-
const version = ['statemint', 'statemine', 'shiden', 'astar'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
9
|
-
const beneficiary = getBeneficiary(destinationChainInfo, recipientAddress, version);
|
|
10
|
-
const destination = getDestinationChainLocation(originChainInfo, destinationChainInfo, version);
|
|
11
|
-
let assetLocation = getTokenLocation(tokenInfo, value, version);
|
|
8
|
+
let version = STABLE_XCM_VERSION;
|
|
12
9
|
let method = 'limitedReserveTransferAssets';
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
parents: 1,
|
|
19
|
-
interior: 'Here'
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
fun: {
|
|
23
|
-
Fungible: value
|
|
24
|
-
}
|
|
25
|
-
}]
|
|
26
|
-
};
|
|
10
|
+
if (_isBridgedToken(tokenInfo)) {
|
|
11
|
+
version = 4;
|
|
12
|
+
method = 'transferAssets';
|
|
13
|
+
}
|
|
14
|
+
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
27
15
|
method = 'limitedTeleportAssets';
|
|
28
16
|
}
|
|
29
|
-
|
|
17
|
+
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
18
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, version);
|
|
19
|
+
const beneficiary = _getXcmBeneficiary(destinationChainInfo, recipientAddress, version);
|
|
20
|
+
const tokenLocation = _getXcmMultiAssets(tokenInfo, value, version);
|
|
21
|
+
return api.tx.polkadotXcm[method](destination, beneficiary, tokenLocation, 0,
|
|
30
22
|
// FeeAssetItem
|
|
31
23
|
weightParam);
|
|
32
24
|
}
|
package/koni/api/xcm/utils.d.ts
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
4
|
-
Limited: number;
|
|
5
|
-
};
|
|
6
|
-
export declare function getReceiverLocation(destinationChainInfo: _ChainInfo, toAddress: string, version?: string): Record<string, any>;
|
|
7
|
-
export declare function getBeneficiary(destinationChainInfo: _ChainInfo, recipientAddress: string, version?: string): {
|
|
8
|
-
[x: string]: {
|
|
9
|
-
parents: number;
|
|
10
|
-
interior: {
|
|
11
|
-
X1: Record<string, any>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function getDestWeight(): string;
|
|
16
|
-
export declare function getTokenLocation(tokenInfo: _ChainAsset, sendingValue: string, version?: string): {
|
|
17
|
-
[x: string]: {
|
|
18
|
-
id: Record<string, any>;
|
|
19
|
-
fun: {
|
|
20
|
-
Fungible: string;
|
|
21
|
-
};
|
|
22
|
-
}[];
|
|
23
|
-
};
|
|
24
|
-
export declare function getDestMultilocation(destinationChainInfo: _ChainInfo, recipient: string, version?: string): {
|
|
25
|
-
[x: string]: {
|
|
26
|
-
parents: number;
|
|
27
|
-
interior: {
|
|
28
|
-
X2: Record<string, any>[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
} | {
|
|
32
|
-
[x: string]: {
|
|
33
|
-
parents: number;
|
|
34
|
-
interior: {
|
|
35
|
-
X1: Record<string, any>;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export declare function getDestinationChainLocation(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, version?: string): {
|
|
40
|
-
[x: string]: {
|
|
41
|
-
parents: number;
|
|
42
|
-
interior: string | {
|
|
43
|
-
X1: {
|
|
44
|
-
Parachain: number;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
export declare const STABLE_XCM_VERSION = 3;
|
|
3
|
+
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|