@subwallet/extension-base 1.2.3-0 → 1.2.4-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 +4 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +47 -0
- package/cjs/core/logic-validation/swap.js +99 -0
- package/cjs/core/logic-validation/transfer.js +212 -0
- package/cjs/core/substrate/nominationpools-pallet.js +22 -0
- package/cjs/core/substrate/system-pallet.js +77 -0
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +58 -122
- package/cjs/koni/api/staking/bonding/utils.js +1 -1
- package/cjs/koni/api/xcm/index.js +30 -2
- 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 +223 -356
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +4 -27
- package/cjs/services/balance-service/helpers/subscribe/index.js +2 -30
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +46 -82
- package/cjs/services/balance-service/index.js +11 -9
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/index.js +0 -1
- package/cjs/services/chain-service/utils/index.js +13 -2
- package/cjs/services/earning-service/handlers/base.js +1 -1
- package/cjs/services/earning-service/handlers/special.js +11 -12
- 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/swap-service/handler/base-handler.js +30 -44
- package/cjs/services/swap-service/handler/chainflip-handler.js +23 -21
- package/cjs/services/swap-service/handler/hydradx-handler.js +41 -39
- package/cjs/services/swap-service/index.js +6 -0
- package/cjs/services/swap-service/utils.js +8 -49
- package/cjs/services/transaction-service/index.js +66 -155
- package/core/logic-validation/earning.d.ts +10 -0
- package/core/logic-validation/earning.js +37 -0
- package/core/logic-validation/swap.d.ts +8 -0
- package/core/logic-validation/swap.js +89 -0
- package/core/logic-validation/transfer.d.ts +16 -0
- package/core/logic-validation/transfer.js +199 -0
- package/core/substrate/nominationpools-pallet.d.ts +10 -0
- package/core/substrate/nominationpools-pallet.js +13 -0
- package/core/substrate/system-pallet.d.ts +27 -0
- package/core/substrate/system-pallet.js +70 -0
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +3 -4
- package/koni/api/dotsama/transfer.js +54 -118
- package/koni/api/staking/bonding/relayChain.d.ts +2 -1
- package/koni/api/staking/bonding/utils.js +1 -1
- package/koni/api/xcm/index.d.ts +2 -0
- package/koni/api/xcm/index.js +27 -1
- 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 +6 -8
- package/koni/background/handlers/Extension.js +117 -247
- package/package.json +39 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.js +4 -27
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/index.js +2 -30
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +31 -66
- package/services/balance-service/index.d.ts +7 -6
- package/services/balance-service/index.js +12 -10
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/index.js +0 -1
- package/services/chain-service/utils/index.d.ts +4 -2
- package/services/chain-service/utils/index.js +9 -2
- package/services/earning-service/handlers/base.js +1 -1
- package/services/earning-service/handlers/nomination-pool/index.d.ts +2 -1
- package/services/earning-service/handlers/special.js +11 -12
- 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/swap-service/handler/base-handler.d.ts +3 -2
- package/services/swap-service/handler/base-handler.js +28 -42
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
- package/services/swap-service/handler/chainflip-handler.js +4 -2
- package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
- package/services/swap-service/handler/hydradx-handler.js +8 -6
- package/services/swap-service/index.js +7 -1
- package/services/swap-service/utils.d.ts +2 -4
- package/services/swap-service/utils.js +7 -47
- package/services/transaction-service/index.d.ts +1 -1
- package/services/transaction-service/index.js +30 -119
- package/services/transaction-service/types.d.ts +1 -0
- package/types/balance/index.d.ts +6 -10
- package/types/yield/info/pallet.d.ts +0 -6
|
@@ -4,110 +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, _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
|
+
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
9
10
|
import { getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
11
|
+
import BigN from 'bignumber.js';
|
|
10
12
|
import { BN, u8aToHex } from '@polkadot/util';
|
|
11
13
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
12
|
-
function isRefCount(accountInfo) {
|
|
13
|
-
return !!accountInfo.refcount;
|
|
14
|
-
}
|
|
15
|
-
export async function checkReferenceCount(networkKey, address, substrateApiMap, chainInfo) {
|
|
16
|
-
const apiProps = await substrateApiMap[networkKey].isReady;
|
|
17
|
-
const api = apiProps.api;
|
|
18
|
-
if (_isChainEvmCompatible(chainInfo)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
const accountInfo = await api.query.system.account(address);
|
|
24
|
-
return accountInfo ? isRefCount(accountInfo) ? !accountInfo.refcount.isZero() : !accountInfo.consumers.isZero() : false;
|
|
25
|
-
}
|
|
26
|
-
export async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chainInfo) {
|
|
27
|
-
const substrateApi = await substrateApiMap[networkKey].isReady;
|
|
28
|
-
if (!tokenInfo) {
|
|
29
|
-
return {
|
|
30
|
-
supportTransfer: false,
|
|
31
|
-
supportTransferAll: false
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (_isChainEvmCompatible(chainInfo)) {
|
|
35
|
-
return {
|
|
36
|
-
supportTransfer: true,
|
|
37
|
-
supportTransferAll: true
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (tokenInfo.symbol.startsWith(_ZK_ASSET_PREFIX) && _MANTA_ZK_CHAIN_GROUP.includes(tokenInfo.originChain)) {
|
|
41
|
-
return {
|
|
42
|
-
supportTransfer: false,
|
|
43
|
-
supportTransferAll: false
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (_TRANSFER_NOT_SUPPORTED_CHAINS.includes(networkKey)) {
|
|
47
|
-
return {
|
|
48
|
-
supportTransfer: false,
|
|
49
|
-
supportTransferAll: false
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const api = substrateApi.api;
|
|
53
|
-
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
54
|
-
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
55
|
-
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
56
|
-
const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
57
|
-
const result = {
|
|
58
|
-
supportTransfer: false,
|
|
59
|
-
supportTransferAll: false
|
|
60
|
-
};
|
|
61
|
-
if (!(isTxCurrenciesSupported || isTxBalancesSupported || isTxTokensSupported || isTxEqBalancesSupported)) {
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
if (_isTokenWasmSmartContract(tokenInfo) && api.query.contracts) {
|
|
65
|
-
// for PSP tokens
|
|
66
|
-
return {
|
|
67
|
-
supportTransfer: true,
|
|
68
|
-
supportTransferAll: true
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// TODO: need review
|
|
73
|
-
if (_TRANSFER_CHAIN_GROUP.acala.includes(networkKey) && !_isNativeToken(tokenInfo) && isTxCurrenciesSupported) {
|
|
74
|
-
result.supportTransfer = true;
|
|
75
|
-
result.supportTransferAll = true;
|
|
76
|
-
} else if (_TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !_isNativeToken(tokenInfo) && isTxTokensSupported) {
|
|
77
|
-
result.supportTransfer = true;
|
|
78
|
-
result.supportTransferAll = true;
|
|
79
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
80
|
-
// && !_isNativeToken(tokenInfo) && isTxEqBalancesSupported
|
|
81
|
-
) {
|
|
82
|
-
result.supportTransfer = false;
|
|
83
|
-
result.supportTransferAll = false;
|
|
84
|
-
// } else if (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) && _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
85
|
-
// result.supportTransfer = true;
|
|
86
|
-
// result.supportTransferAll = true;
|
|
87
|
-
} else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
|
|
88
|
-
result.supportTransfer = true;
|
|
89
|
-
result.supportTransferAll = true;
|
|
90
|
-
} else if (_TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !_isNativeToken(tokenInfo) && _BALANCE_TOKEN_GROUP.bitcountry.includes(tokenInfo.symbol)) {
|
|
91
|
-
result.supportTransfer = true;
|
|
92
|
-
result.supportTransferAll = true;
|
|
93
|
-
} else if (_TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
94
|
-
result.supportTransfer = true;
|
|
95
|
-
result.supportTransferAll = true;
|
|
96
|
-
} else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey)) {
|
|
97
|
-
result.supportTransfer = true;
|
|
98
|
-
result.supportTransferAll = true;
|
|
99
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey) && _isNativeToken(tokenInfo)) {
|
|
100
|
-
// result.supportTransfer = true;
|
|
101
|
-
// result.supportTransferAll = true;
|
|
102
|
-
} else if (_TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
103
|
-
result.supportTransfer = true;
|
|
104
|
-
result.supportTransferAll = true;
|
|
105
|
-
} else if (_TRANSFER_CHAIN_GROUP.centrifuge.includes(networkKey)) {
|
|
106
|
-
result.supportTransfer = true;
|
|
107
|
-
result.supportTransferAll = true;
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
14
|
export const createTransferExtrinsic = async ({
|
|
112
15
|
from,
|
|
113
16
|
networkKey,
|
|
@@ -129,11 +32,17 @@ export const createTransferExtrinsic = async ({
|
|
|
129
32
|
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
130
33
|
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
131
34
|
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
132
|
-
// const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
133
35
|
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
134
36
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
135
37
|
|
|
136
|
-
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) {
|
|
137
46
|
const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
138
47
|
// @ts-ignore
|
|
139
48
|
const gasLimit = await getWasmContractGasLimit(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
|
|
@@ -175,25 +84,10 @@ export const createTransferExtrinsic = async ({
|
|
|
175
84
|
} else if (value) {
|
|
176
85
|
transfer = api.tx.tokens.transfer(to, _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo), new BN(value));
|
|
177
86
|
}
|
|
178
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
179
|
-
// && isTxEqBalancesSupported
|
|
180
|
-
) {
|
|
181
|
-
// transfer = api.tx.eqBalances.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
182
|
-
/* empty */
|
|
183
|
-
// } else if (!_isNativeToken(tokenInfo) && (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) || _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol))) {
|
|
184
|
-
// if (transferAll) {
|
|
185
|
-
// transfer = api.tx.kton.transferAll(to, false);
|
|
186
|
-
// } else if (value) {
|
|
187
|
-
// transfer = api.tx.kton.transfer(to, new BN(value));
|
|
188
|
-
// }
|
|
189
87
|
} else if (_TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
190
88
|
transfer = api.tx.currencies.transfer(to, _getTokenOnChainInfo(tokenInfo), value);
|
|
191
89
|
} else if (_TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !_isNativeToken(tokenInfo)) {
|
|
192
90
|
transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
193
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey)) {
|
|
194
|
-
// if (_isNativeToken(tokenInfo)) {
|
|
195
|
-
// transfer = api.tx.currencies.transferNativeCurrency(to, value);
|
|
196
|
-
// }
|
|
197
91
|
} else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
198
92
|
transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
199
93
|
} else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
|
|
@@ -211,4 +105,46 @@ export const createTransferExtrinsic = async ({
|
|
|
211
105
|
}
|
|
212
106
|
}
|
|
213
107
|
return [transfer, transferAmount || value];
|
|
108
|
+
};
|
|
109
|
+
export const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) => {
|
|
110
|
+
try {
|
|
111
|
+
let estimatedFee;
|
|
112
|
+
if (_isChainEvmCompatible(chainInfo) && _isTokenTransferredByEvm(tokenInfo)) {
|
|
113
|
+
const web3 = api;
|
|
114
|
+
const transaction = {
|
|
115
|
+
value: 0,
|
|
116
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
117
|
+
// null address
|
|
118
|
+
from: address
|
|
119
|
+
};
|
|
120
|
+
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
121
|
+
const priority = await calculateGasFeeParams(web3, chainInfo.slug);
|
|
122
|
+
if (priority.baseGasFee) {
|
|
123
|
+
const maxFee = priority.maxFeePerGas;
|
|
124
|
+
estimatedFee = maxFee.multipliedBy(gasLimit);
|
|
125
|
+
} else {
|
|
126
|
+
estimatedFee = new BigN(priority.gasPrice).multipliedBy(gasLimit);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
var _paymentInfo$partialF;
|
|
130
|
+
const substrateApi = api;
|
|
131
|
+
const chainApi = await substrateApi.isReady;
|
|
132
|
+
const [mockTx] = await createTransferExtrinsic({
|
|
133
|
+
from: address,
|
|
134
|
+
networkKey: chainInfo.slug,
|
|
135
|
+
substrateApi: chainApi,
|
|
136
|
+
to: address,
|
|
137
|
+
tokenInfo,
|
|
138
|
+
transferAll: true,
|
|
139
|
+
value: '1000000000000000000'
|
|
140
|
+
});
|
|
141
|
+
const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
|
|
142
|
+
estimatedFee = new BigN((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0'); // todo: should handle error case instead of setting fee to 0
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return estimatedFee;
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.error('error mocking tx fee', e);
|
|
148
|
+
return new BigN(0);
|
|
149
|
+
}
|
|
214
150
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
3
|
import { ChainStakingMetadata, NominatorMetadata, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { PalletNominationPoolsPoolMember } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
|
|
4
5
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
|
-
import { NominationPoolInfo
|
|
6
|
+
import { NominationPoolInfo } from '@subwallet/extension-base/types';
|
|
6
7
|
export interface PalletStakingNominations {
|
|
7
8
|
targets: string[];
|
|
8
9
|
submittedIn: number;
|
|
@@ -383,7 +383,7 @@ export function getTopValidatorByPoints(validatorPointsList) {
|
|
|
383
383
|
export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
|
|
384
384
|
const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
|
|
385
385
|
const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
|
|
386
|
-
return t('Insufficient stake.
|
|
386
|
+
return t('Insufficient stake. You need to stake at least {{number}} {{tokenSymbol}} to earn rewards', {
|
|
387
387
|
replace: {
|
|
388
388
|
tokenSymbol: tokenInfo.symbol,
|
|
389
389
|
number
|
package/koni/api/xcm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import BigN from 'bignumber.js';
|
|
3
4
|
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
4
5
|
interface CreateXcmExtrinsicProps {
|
|
5
6
|
originTokenInfo: _ChainAsset;
|
|
@@ -10,4 +11,5 @@ interface CreateXcmExtrinsicProps {
|
|
|
10
11
|
chainInfoMap: Record<string, _ChainInfo>;
|
|
11
12
|
}
|
|
12
13
|
export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
14
|
+
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, address: string, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
13
15
|
export {};
|
package/koni/api/xcm/index.js
CHANGED
|
@@ -5,7 +5,10 @@ import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/koni/
|
|
|
5
5
|
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/koni/api/xcm/xcmPallet';
|
|
6
6
|
import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/koni/api/xcm/xTokens';
|
|
7
7
|
import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
|
-
import { _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
+
import BigN from 'bignumber.js';
|
|
10
|
+
import { u8aToHex } from '@polkadot/util';
|
|
11
|
+
import { addressToEvm, isEthereumAddress } from '@polkadot/util-crypto';
|
|
9
12
|
export const createXcmExtrinsic = async ({
|
|
10
13
|
chainInfoMap,
|
|
11
14
|
destinationTokenInfo,
|
|
@@ -31,4 +34,27 @@ export const createXcmExtrinsic = async ({
|
|
|
31
34
|
extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
32
35
|
}
|
|
33
36
|
return extrinsic;
|
|
37
|
+
};
|
|
38
|
+
export const getXcmMockTxFee = async (substrateApi, chainInfoMap, address, originTokenInfo, destinationTokenInfo) => {
|
|
39
|
+
try {
|
|
40
|
+
var _paymentInfo$partialF;
|
|
41
|
+
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
42
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
43
|
+
|
|
44
|
+
// mock receiving account from sender
|
|
45
|
+
const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(destChainInfo) && !_isChainEvmCompatible(originChainInfo) ? u8aToHex(addressToEvm(address)) : address;
|
|
46
|
+
const mockTx = await createXcmExtrinsic({
|
|
47
|
+
chainInfoMap,
|
|
48
|
+
destinationTokenInfo,
|
|
49
|
+
originTokenInfo,
|
|
50
|
+
recipient: recipient,
|
|
51
|
+
sendingValue: '1000000000000000000',
|
|
52
|
+
substrateApi
|
|
53
|
+
});
|
|
54
|
+
const paymentInfo = await mockTx.paymentInfo(address);
|
|
55
|
+
return new BigN((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0');
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error('error mocking xcm tx fee', e);
|
|
58
|
+
return new BigN(0);
|
|
59
|
+
}
|
|
34
60
|
};
|
|
@@ -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;
|
package/koni/api/xcm/utils.js
CHANGED
|
@@ -1,118 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Limited: 5000000000
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// get multilocation for destination chain from a parachain
|
|
13
|
-
|
|
14
|
-
export function getReceiverLocation(destinationChainInfo, toAddress, version) {
|
|
15
|
-
const network = version && version === 'V3' ? undefined : 'Any';
|
|
16
|
-
if (destinationChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
17
|
-
const ss58Address = evmToAddress(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
AccountId32: {
|
|
21
|
-
network,
|
|
22
|
-
id: decodeAddress(ss58Address)
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (_isChainEvmCompatible(destinationChainInfo)) {
|
|
27
|
-
return {
|
|
28
|
-
AccountKey20: {
|
|
29
|
-
network,
|
|
30
|
-
key: toAddress
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
AccountId32: {
|
|
36
|
-
network,
|
|
37
|
-
id: decodeAddress(toAddress)
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function getBeneficiary(destinationChainInfo, recipientAddress, version = 'V1') {
|
|
42
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
|
|
43
|
-
return {
|
|
44
|
-
[version]: {
|
|
45
|
-
parents: 0,
|
|
46
|
-
interior: {
|
|
47
|
-
X1: receiverLocation
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export function getDestWeight() {
|
|
53
|
-
return 'Unlimited';
|
|
54
|
-
}
|
|
55
|
-
export function getTokenLocation(tokenInfo, sendingValue, version = 'V1') {
|
|
56
|
-
if (!_isNativeToken(tokenInfo)) {
|
|
57
|
-
const multilocation = _getXcmAssetMultilocation(tokenInfo);
|
|
58
|
-
return {
|
|
59
|
-
[version]: [{
|
|
60
|
-
id: multilocation,
|
|
61
|
-
fun: {
|
|
62
|
-
Fungible: sendingValue
|
|
63
|
-
}
|
|
64
|
-
}]
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
[version]: [{
|
|
69
|
-
id: {
|
|
70
|
-
Concrete: {
|
|
71
|
-
parents: 0,
|
|
72
|
-
interior: 'Here'
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
fun: {
|
|
76
|
-
Fungible: sendingValue
|
|
77
|
-
}
|
|
78
|
-
}]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export function getDestMultilocation(destinationChainInfo, recipient, version = 'V1') {
|
|
82
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipient, version);
|
|
83
|
-
if (_isSubstrateParaChain(destinationChainInfo)) {
|
|
84
|
-
const interior = {
|
|
85
|
-
X2: [{
|
|
86
|
-
Parachain: _getSubstrateParaId(destinationChainInfo)
|
|
87
|
-
}, receiverLocation]
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
[version]: {
|
|
91
|
-
parents: 1,
|
|
92
|
-
interior
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
[version]: {
|
|
98
|
-
parents: 1,
|
|
99
|
-
interior: {
|
|
100
|
-
X1: receiverLocation
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
export function getDestinationChainLocation(originChainInfo, destinationChainInfo, version = 'V1') {
|
|
106
|
-
const parents = _isSubstrateRelayChain(originChainInfo) ? 0 : 1;
|
|
107
|
-
const interior = _isSubstrateParaChain(destinationChainInfo) ? {
|
|
108
|
-
X1: {
|
|
109
|
-
Parachain: _getSubstrateParaId(destinationChainInfo)
|
|
110
|
-
}
|
|
111
|
-
} : 'Here';
|
|
112
|
-
return {
|
|
113
|
-
[version]: {
|
|
114
|
-
parents,
|
|
115
|
-
interior
|
|
116
|
-
}
|
|
117
|
-
};
|
|
4
|
+
export const STABLE_XCM_VERSION = 3;
|
|
5
|
+
export function isUseTeleportProtocol(originChainInfo, destChainInfo) {
|
|
6
|
+
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug);
|
|
7
|
+
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug);
|
|
8
|
+
return relayChainToSystemChain || systemChainToRelayChain;
|
|
118
9
|
}
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
6
|
+
import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
function getCurrencyId(tokenInfo) {
|
|
7
|
-
if (['
|
|
8
|
-
return _getXcmAssetMultilocation(tokenInfo);
|
|
9
|
-
} else if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
8
|
+
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
10
9
|
const tokenType = _getXcmAssetType(tokenInfo);
|
|
11
10
|
const assetId = _getXcmAssetId(tokenInfo);
|
|
12
11
|
return {
|
|
13
12
|
[tokenType]: assetId
|
|
14
13
|
};
|
|
15
|
-
} else if (['pioneer'].includes(tokenInfo.originChain)) {
|
|
16
|
-
return _getXcmAssetMultilocation(tokenInfo);
|
|
17
14
|
}
|
|
18
15
|
return _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo);
|
|
19
16
|
}
|
|
20
17
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
const version = STABLE_XCM_VERSION;
|
|
19
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, version, recipientAddress);
|
|
20
|
+
if (!_getXcmAssetMultilocation(tokenInfo)) {
|
|
21
|
+
const tokenCurrencyId = getCurrencyId(tokenInfo);
|
|
22
|
+
return api.tx.xTokens.transfer(tokenCurrencyId, value, destination, _getXcmDestWeight(originChainInfo));
|
|
23
|
+
}
|
|
24
|
+
const tokenMultiAsset = _getXcmMultiAssets(tokenInfo, value, version);
|
|
25
|
+
return api.tx.xTokens.transferMultiassets(tokenMultiAsset, 0, destination, _getXcmDestWeight(originChainInfo));
|
|
24
26
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
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';
|
|
5
6
|
// this pallet is only used by Relaychains
|
|
6
7
|
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
|
-
const weightParam =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const tokenLocation = getTokenLocation(tokenInfo, value, xcmVer);
|
|
8
|
+
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
9
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, STABLE_XCM_VERSION);
|
|
10
|
+
const beneficiary = _getXcmBeneficiary(destinationChainInfo, recipientAddress, STABLE_XCM_VERSION);
|
|
11
|
+
const tokenLocation = _getXcmMultiAssets(tokenInfo, value, STABLE_XCM_VERSION);
|
|
12
12
|
let method = 'limitedReserveTransferAssets';
|
|
13
|
-
if (
|
|
13
|
+
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
14
14
|
method = 'limitedTeleportAssets';
|
|
15
15
|
}
|
|
16
16
|
return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
|
|
@@ -124,9 +124,7 @@ export default class KoniExtension {
|
|
|
124
124
|
private subscribeStaking;
|
|
125
125
|
private subscribeHistory;
|
|
126
126
|
private subscribeHistoryByChainAndAddress;
|
|
127
|
-
private validateTransfer;
|
|
128
127
|
private makeTransfer;
|
|
129
|
-
private validateCrossChainTransfer;
|
|
130
128
|
private makeCrossChainTransfer;
|
|
131
129
|
private evmNftSubmitTransaction;
|
|
132
130
|
private upsertChain;
|
|
@@ -140,12 +138,11 @@ export default class KoniExtension {
|
|
|
140
138
|
private upsertCustomToken;
|
|
141
139
|
private deleteCustomAsset;
|
|
142
140
|
private validateCustomAsset;
|
|
143
|
-
private
|
|
144
|
-
private
|
|
145
|
-
private
|
|
146
|
-
private
|
|
147
|
-
private
|
|
148
|
-
private transferGetExistentialDeposit;
|
|
141
|
+
private getAddressTransferableBalance;
|
|
142
|
+
private getMaxTransferable;
|
|
143
|
+
private getXcmMaxTransferable;
|
|
144
|
+
private getNativeTokenMaxTransferable;
|
|
145
|
+
private subscribeAddressTransferableBalance;
|
|
149
146
|
private substrateNftSubmitTransaction;
|
|
150
147
|
private enableChains;
|
|
151
148
|
private getAccountMeta;
|
|
@@ -182,6 +179,7 @@ export default class KoniExtension {
|
|
|
182
179
|
private keyringMigrateMasterPassword;
|
|
183
180
|
private keyringUnlock;
|
|
184
181
|
private keyringLock;
|
|
182
|
+
keyringLockSubscribe(cb: (state: boolean) => void): any;
|
|
185
183
|
private keyringExportMnemonic;
|
|
186
184
|
private resetWallet;
|
|
187
185
|
private signingApprovePasswordV2;
|