@subwallet/extension-base 1.3.66-0 → 1.3.68-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 +12 -1
- package/cjs/constants/environment.js +1 -3
- package/cjs/constants/index.js +4 -1
- package/cjs/core/substrate/system-pallet.js +4 -0
- package/cjs/core/substrate/xcm-parser.js +0 -176
- package/cjs/koni/api/nft/rari/index.js +1 -1
- package/cjs/koni/background/cron.js +16 -0
- package/cjs/koni/background/handlers/Extension.js +166 -90
- package/cjs/koni/background/handlers/State.js +25 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +31 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +51 -13
- package/cjs/services/balance-service/helpers/subscribe/substrate/utils.js +69 -0
- package/cjs/services/balance-service/index.js +36 -11
- package/cjs/services/balance-service/transfer/smart-contract.js +56 -23
- package/cjs/services/balance-service/transfer/xcm/index.js +30 -44
- package/cjs/services/balance-service/transfer/xcm/utils.js +53 -18
- package/cjs/services/chain-service/constants.js +8 -46
- package/cjs/services/chain-service/handler/EvmChainHandler.js +6 -3
- package/cjs/services/earning-service/handlers/base.js +7 -1
- package/cjs/services/nft-service/index.js +173 -0
- package/cjs/services/swap-service/handler/base-handler.js +18 -21
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/types/balance/index.js +26 -1
- package/cjs/utils/fee/transfer.js +5 -2
- package/cjs/utils/index.js +25 -2
- package/cjs/utils/setup-api-sdk.js +0 -5
- package/constants/environment.d.ts +0 -1
- package/constants/environment.js +0 -1
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/substrate/system-pallet.d.ts +1 -0
- package/core/substrate/system-pallet.js +3 -0
- package/core/substrate/types.d.ts +14 -0
- package/core/substrate/xcm-parser.d.ts +1 -49
- package/core/substrate/xcm-parser.js +1 -173
- package/koni/api/nft/rari/index.js +1 -1
- package/koni/background/cron.d.ts +1 -0
- package/koni/background/cron.js +17 -1
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +88 -14
- package/koni/background/handlers/State.d.ts +4 -0
- package/koni/background/handlers/State.js +25 -0
- package/package.json +16 -21
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.js +31 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +51 -13
- package/services/balance-service/helpers/subscribe/substrate/utils.d.ts +7 -0
- package/services/balance-service/helpers/subscribe/substrate/utils.js +58 -0
- package/services/balance-service/index.d.ts +4 -2
- package/services/balance-service/index.js +26 -6
- package/services/balance-service/transfer/smart-contract.d.ts +4 -0
- package/services/balance-service/transfer/smart-contract.js +54 -23
- package/services/balance-service/transfer/xcm/index.d.ts +2 -2
- package/services/balance-service/transfer/xcm/index.js +18 -32
- package/services/balance-service/transfer/xcm/utils.d.ts +1 -2
- package/services/balance-service/transfer/xcm/utils.js +51 -15
- package/services/chain-service/constants.d.ts +5 -24
- package/services/chain-service/constants.js +6 -35
- package/services/chain-service/handler/EvmChainHandler.js +6 -3
- package/services/earning-service/handlers/base.js +7 -1
- package/services/nft-service/index.d.ts +9 -0
- package/services/nft-service/index.js +165 -0
- package/services/swap-service/handler/base-handler.d.ts +0 -1
- package/services/swap-service/handler/base-handler.js +19 -22
- package/services/transaction-service/index.js +1 -1
- package/services/transaction-service/types.d.ts +2 -1
- package/types/balance/index.d.ts +14 -0
- package/types/balance/index.js +21 -1
- package/utils/fee/transfer.js +6 -3
- package/utils/index.js +25 -2
- package/utils/setup-api-sdk.js +1 -6
- package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +0 -30
- package/cjs/services/balance-service/transfer/xcm/xTokens.js +0 -32
- package/cjs/services/balance-service/transfer/xcm/xcmPallet.js +0 -23
- package/services/balance-service/transfer/xcm/polkadotXcm.d.ts +0 -3
- package/services/balance-service/transfer/xcm/polkadotXcm.js +0 -24
- package/services/balance-service/transfer/xcm/xTokens.d.ts +0 -3
- package/services/balance-service/transfer/xcm/xTokens.js +0 -26
- package/services/balance-service/transfer/xcm/xcmPallet.d.ts +0 -3
- package/services/balance-service/transfer/xcm/xcmPallet.js +0 -17
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NftFullListRequest } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
+
export default class NftService {
|
|
4
|
+
private inProgress;
|
|
5
|
+
private state;
|
|
6
|
+
constructor(state: KoniState);
|
|
7
|
+
fetchEvmCollectionsWithPreview(addresses: string[]): Promise<void>;
|
|
8
|
+
getFullNftInstancesByCollection(request: NftFullListRequest): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
|
+
import { _getEvmChainId } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { baseParseIPFSUrl } from '@subwallet/extension-base/utils';
|
|
7
|
+
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
8
|
+
import { EthereumKeypairTypes } from '@subwallet/keyring/types';
|
|
9
|
+
import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
|
|
10
|
+
function mapSdkToNftItem(rawInstance, chain, collectionId, owner) {
|
|
11
|
+
var _rawInstance$token_ty, _rawInstance$token_ty2, _rawInstance$id;
|
|
12
|
+
const metadata = rawInstance.metadata || {};
|
|
13
|
+
const image = metadata.image || rawInstance.image_url || rawInstance.media_url || '';
|
|
14
|
+
const attributes = Array.isArray(metadata.attributes) ? metadata.attributes : [];
|
|
15
|
+
let rarity;
|
|
16
|
+
const properties = {};
|
|
17
|
+
for (const attr of attributes) {
|
|
18
|
+
try {
|
|
19
|
+
var _attr$trait_type;
|
|
20
|
+
const key = (_attr$trait_type = attr.trait_type) === null || _attr$trait_type === void 0 ? void 0 : _attr$trait_type.trim();
|
|
21
|
+
if (!key) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
let value = attr.value;
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
const lower = value.toLowerCase();
|
|
27
|
+
if (lower === 'true') {
|
|
28
|
+
value = true;
|
|
29
|
+
} else if (lower === 'false') {
|
|
30
|
+
value = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
properties[key] = value;
|
|
34
|
+
if (key.toLowerCase() === 'rarity') {
|
|
35
|
+
rarity = String(value);
|
|
36
|
+
}
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
const hasProperties = Object.keys(properties).length > 0;
|
|
40
|
+
const normalizedType = (_rawInstance$token_ty = rawInstance.token_type) === null || _rawInstance$token_ty === void 0 ? void 0 : (_rawInstance$token_ty2 = _rawInstance$token_ty.replace('-', '')) === null || _rawInstance$token_ty2 === void 0 ? void 0 : _rawInstance$token_ty2.toUpperCase();
|
|
41
|
+
|
|
42
|
+
// Only support ERC721
|
|
43
|
+
if (normalizedType !== 'ERC721') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
id: (_rawInstance$id = rawInstance.id) === null || _rawInstance$id === void 0 ? void 0 : _rawInstance$id.toString(),
|
|
48
|
+
chain,
|
|
49
|
+
collectionId,
|
|
50
|
+
owner: rawInstance.owner || owner,
|
|
51
|
+
originAsset: undefined,
|
|
52
|
+
name: metadata.name || `#${rawInstance.id}`,
|
|
53
|
+
image: baseParseIPFSUrl(image),
|
|
54
|
+
externalUrl: rawInstance.external_app_url || undefined,
|
|
55
|
+
rarity,
|
|
56
|
+
description: metadata.description || undefined,
|
|
57
|
+
properties: hasProperties ? properties : null,
|
|
58
|
+
type: normalizedType === 'ERC721' ? _AssetType.ERC721 : _AssetType.ERC721,
|
|
59
|
+
// currently only support ERC721
|
|
60
|
+
rmrk_ver: undefined,
|
|
61
|
+
onChainOption: undefined,
|
|
62
|
+
assetHubType: undefined
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function mapSdkToCollection(raw, chain) {
|
|
66
|
+
var _raw$token_instances;
|
|
67
|
+
const token = raw.token || {};
|
|
68
|
+
return {
|
|
69
|
+
// must-have
|
|
70
|
+
collectionId: token.address_hash,
|
|
71
|
+
chain,
|
|
72
|
+
originAsset: undefined,
|
|
73
|
+
// optional
|
|
74
|
+
collectionName: token.name || token.symbol || 'Unknown Collection',
|
|
75
|
+
image: token.icon_url || undefined,
|
|
76
|
+
itemCount: Number(raw.amount) || ((_raw$token_instances = raw.token_instances) === null || _raw$token_instances === void 0 ? void 0 : _raw$token_instances.length) || 0,
|
|
77
|
+
externalUrl: undefined
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export default class NftService {
|
|
81
|
+
inProgress = new Set();
|
|
82
|
+
constructor(state) {
|
|
83
|
+
this.state = state;
|
|
84
|
+
}
|
|
85
|
+
async fetchEvmCollectionsWithPreview(addresses) {
|
|
86
|
+
for (const address of addresses) {
|
|
87
|
+
const type = getKeypairTypeByAddress(address);
|
|
88
|
+
const typeValid = [...EthereumKeypairTypes].includes(type);
|
|
89
|
+
if (typeValid) {
|
|
90
|
+
if (this.inProgress.has(address)) {
|
|
91
|
+
console.log(`[NftService] ${address} already running`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
this.inProgress.add(address);
|
|
95
|
+
try {
|
|
96
|
+
const nftDetectionApi = subwalletApiSdk.nftDetectionApi;
|
|
97
|
+
if (!(nftDetectionApi !== null && nftDetectionApi !== void 0 && nftDetectionApi.getEvmNftCollectionsByAddress)) {
|
|
98
|
+
console.warn('[NftService] NftDetectionApi not available');
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const rawData = await nftDetectionApi.getEvmNftCollectionsByAddress(address);
|
|
102
|
+
const allItems = [];
|
|
103
|
+
const allCollections = [];
|
|
104
|
+
for (const [chain, collections] of Object.entries(rawData)) {
|
|
105
|
+
if (!Array.isArray(collections)) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const col of collections) {
|
|
109
|
+
const mappedCollection = mapSdkToCollection(col, chain);
|
|
110
|
+
allCollections.push(mappedCollection);
|
|
111
|
+
if (Array.isArray(col.token_instances)) {
|
|
112
|
+
const items = col.token_instances.map(inst => mapSdkToNftItem(inst, chain, mappedCollection.collectionId, address)).filter(i => Boolean(i));
|
|
113
|
+
allItems.push(...items);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
await this.state.handleDetectedNftCollections(allCollections);
|
|
118
|
+
await this.state.handleDetectedNfts(address, allItems);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.warn(`[NftService] detect error for ${address}`, err);
|
|
121
|
+
} finally {
|
|
122
|
+
this.inProgress.delete(address);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async getFullNftInstancesByCollection(request) {
|
|
128
|
+
const {
|
|
129
|
+
chainInfo,
|
|
130
|
+
contractAddress,
|
|
131
|
+
owners
|
|
132
|
+
} = request;
|
|
133
|
+
const chainId = _getEvmChainId(chainInfo);
|
|
134
|
+
if (!contractAddress || !owners || !chainId) {
|
|
135
|
+
console.warn('[NftService] missing params for getFullNftInstancesByCollection');
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const nftDetectionApi = subwalletApiSdk.nftDetectionApi;
|
|
140
|
+
if (!(nftDetectionApi !== null && nftDetectionApi !== void 0 && nftDetectionApi.getAllNftInstances)) {
|
|
141
|
+
console.warn('[NftService] getAllNftInstances not available');
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const ownerList = Array.isArray(owners) ? owners : [owners];
|
|
145
|
+
for (const eachOwner of ownerList) {
|
|
146
|
+
try {
|
|
147
|
+
const instances = await nftDetectionApi.getAllNftInstances(contractAddress, eachOwner, chainId.toString());
|
|
148
|
+
if (!Array.isArray(instances)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
console.log('FOR TESTER (before)', instances);
|
|
152
|
+
const nftList = instances.map(inst => mapSdkToNftItem(inst, chainInfo.slug, contractAddress, eachOwner)).filter(i => Boolean(i));
|
|
153
|
+
console.log('FOR TESTER (after)', nftList);
|
|
154
|
+
await this.state.handleDetectedNfts(eachOwner, nftList);
|
|
155
|
+
} catch (innerErr) {
|
|
156
|
+
console.warn(`[NftService] getAllNftInstances failed for ${eachOwner}`, innerErr);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(`[NftDetectionService] getFullNftInstancesByCollection error for ${contractAddress}`, err);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -34,7 +34,6 @@ export declare class SwapBaseHandler {
|
|
|
34
34
|
handleBridgeStep(params: SwapSubmitParams, type: string): Promise<SwapSubmitStepData>;
|
|
35
35
|
handleBridgeSubstrate(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
36
36
|
handleBridgeAcross(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
37
|
-
validateSetFeeTokenStep(params: ValidateSwapProcessParams, stepIndex: number): Promise<TransactionError[]>;
|
|
38
37
|
private validateBridgeStep;
|
|
39
38
|
private validateSwapStepV2;
|
|
40
39
|
validateSwapOnlyProcess(params: ValidateSwapProcessParams, swapIndex: number): Promise<TransactionError[]>;
|
|
@@ -7,7 +7,7 @@ import { validateSpendingAndFeePayment } from '@subwallet/extension-base/core/lo
|
|
|
7
7
|
import { _isAccountActive } from '@subwallet/extension-base/core/substrate/system-pallet';
|
|
8
8
|
import { _isAcrossBridgeXcm, _isSnowBridgeXcm, _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
9
9
|
import { _isSufficientToken } from '@subwallet/extension-base/core/utils';
|
|
10
|
-
import { createXcmExtrinsicV2, dryRunXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
10
|
+
import { createXcmExtrinsicV2, dryRunXcmExtrinsicV2, getXcmOriginFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
11
11
|
import { _isAcrossChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
12
12
|
import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
13
13
|
import { _getAssetDecimals, _getAssetOriginChain, _getAssetSymbol, _getChainNativeTokenSlug, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken, _isPureBitcoinChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
@@ -298,21 +298,6 @@ export class SwapBaseHandler {
|
|
|
298
298
|
txData: txData
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
|
-
async validateSetFeeTokenStep(params, stepIndex) {
|
|
302
|
-
if (!params.selectedQuote) {
|
|
303
|
-
return Promise.resolve([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
304
|
-
}
|
|
305
|
-
const feeInfo = params.process.totalFee[stepIndex];
|
|
306
|
-
const feeAmount = feeInfo.feeComponent[0];
|
|
307
|
-
const feeTokenInfo = this.chainService.getAssetBySlug(feeInfo.defaultFeeToken);
|
|
308
|
-
const feeTokenBalance = await this.balanceService.getTransferableBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug);
|
|
309
|
-
const bnFeeTokenBalance = new BigN(feeTokenBalance.value);
|
|
310
|
-
const bnFeeAmount = new BigN(feeAmount.amount);
|
|
311
|
-
if (bnFeeAmount.gte(bnFeeTokenBalance)) {
|
|
312
|
-
return Promise.resolve([new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE)]);
|
|
313
|
-
}
|
|
314
|
-
return [];
|
|
315
|
-
}
|
|
316
301
|
async validateBridgeStep(request) {
|
|
317
302
|
const {
|
|
318
303
|
bnBridgeAmount,
|
|
@@ -377,7 +362,7 @@ export class SwapBaseHandler {
|
|
|
377
362
|
const xcmRequest = {
|
|
378
363
|
originTokenInfo: fromToken,
|
|
379
364
|
destinationTokenInfo: toToken,
|
|
380
|
-
sendingValue: bnBridgeAmount.
|
|
365
|
+
sendingValue: bnBridgeAmount.toFixed(),
|
|
381
366
|
recipient: receiver,
|
|
382
367
|
substrateApi: substrateApi,
|
|
383
368
|
sender: sender,
|
|
@@ -385,11 +370,23 @@ export class SwapBaseHandler {
|
|
|
385
370
|
originChain: fromChain,
|
|
386
371
|
feeInfo
|
|
387
372
|
};
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
373
|
+
if (isFirstBridge) {
|
|
374
|
+
const isDryRunSuccess = await dryRunXcmExtrinsicV2(xcmRequest, false);
|
|
375
|
+
if (!isDryRunSuccess) {
|
|
376
|
+
return [new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
377
|
+
}
|
|
378
|
+
} else {
|
|
379
|
+
const isDryRunPreviewSuccess = await dryRunXcmExtrinsicV2(xcmRequest, true);
|
|
380
|
+
const originFee = await getXcmOriginFee(xcmRequest);
|
|
381
|
+
if (originFee) {
|
|
382
|
+
const isBridgeTokenNativeBalanceEnough = bnFeeTokenBalance.gte(originFee);
|
|
383
|
+
if (!isBridgeTokenNativeBalanceEnough) {
|
|
384
|
+
return [new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (!isDryRunPreviewSuccess) {
|
|
388
|
+
return [new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
389
|
+
}
|
|
393
390
|
}
|
|
394
391
|
}
|
|
395
392
|
return [];
|
|
@@ -127,7 +127,7 @@ export default class TransactionService {
|
|
|
127
127
|
// Check account signing transaction
|
|
128
128
|
|
|
129
129
|
checkSigningAccountForTransaction(validationResponse, chainInfoMap);
|
|
130
|
-
const nativeTokenAvailable = await this.state.balanceService.
|
|
130
|
+
const nativeTokenAvailable = await this.state.balanceService.getBalanceByType(address, chain, nativeTokenInfo.slug, transactionInput.balanceType, extrinsicType);
|
|
131
131
|
|
|
132
132
|
// Check available balance against transaction fee
|
|
133
133
|
checkBalanceWithTransactionFee(validationResponse, transactionInput, nativeTokenInfo, nativeTokenAvailable);
|
|
@@ -2,7 +2,7 @@ import { ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeDat
|
|
|
2
2
|
import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-validation';
|
|
3
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
4
|
import { UniswapOrderInfo } from '@subwallet/extension-base/services/swap-service/handler/uniswap-handler';
|
|
5
|
-
import { BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
|
|
5
|
+
import { BalanceType, BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
|
|
6
6
|
import { Psbt } from 'bitcoinjs-lib';
|
|
7
7
|
import EventEmitter from 'eventemitter3';
|
|
8
8
|
import { TransactionConfig } from 'web3-core';
|
|
@@ -61,6 +61,7 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
|
|
|
61
61
|
resolveOnDone?: boolean;
|
|
62
62
|
skipFeeValidation?: boolean;
|
|
63
63
|
skipFeeRecalculation?: boolean;
|
|
64
|
+
balanceType?: BalanceType;
|
|
64
65
|
}
|
|
65
66
|
export interface SWPermitTransactionInput extends Omit<SWTransactionInput, 'transaction'> {
|
|
66
67
|
transaction?: SWPermitTransaction['transaction'] | null;
|
package/types/balance/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ export interface TokenBalanceRaw {
|
|
|
8
8
|
frozen: BN;
|
|
9
9
|
free: BN;
|
|
10
10
|
}
|
|
11
|
+
export declare enum BalanceType {
|
|
12
|
+
TRANSFERABLE = "transferable",
|
|
13
|
+
TOTAL = "total",
|
|
14
|
+
TOTAL_MINUS_RESERVED = "totalMinusReserved",
|
|
15
|
+
KEEP_ALIVE = "keepAlive"
|
|
16
|
+
}
|
|
11
17
|
/**
|
|
12
18
|
* Balance info of a token on an address
|
|
13
19
|
* @property {string} address - Address
|
|
@@ -18,6 +24,13 @@ export interface TokenBalanceRaw {
|
|
|
18
24
|
* @property {string} locked - Locked balance, cannot be transferred, locked here is only meaningful in the context of token transfer
|
|
19
25
|
* @property {metadata} [metadata] - Could be anything, supposed to be generic to handle various contexts
|
|
20
26
|
*/
|
|
27
|
+
export interface LockedBalanceDetails {
|
|
28
|
+
staking: string;
|
|
29
|
+
governance: string;
|
|
30
|
+
democracy: string;
|
|
31
|
+
reserved: string;
|
|
32
|
+
others: string;
|
|
33
|
+
}
|
|
21
34
|
export interface BalanceItem {
|
|
22
35
|
address: string;
|
|
23
36
|
tokenSlug: string;
|
|
@@ -25,6 +38,7 @@ export interface BalanceItem {
|
|
|
25
38
|
timestamp?: number;
|
|
26
39
|
free: string;
|
|
27
40
|
locked: string;
|
|
41
|
+
lockedDetails?: LockedBalanceDetails;
|
|
28
42
|
metadata?: _BalanceMetadata;
|
|
29
43
|
}
|
|
30
44
|
/** Balance info of all tokens on an address */
|
package/types/balance/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni-ui authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export let BalanceType;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Balance info of a token on an address
|
|
8
|
+
* @property {string} address - Address
|
|
9
|
+
* @property {string} tokenSlug - Slug of token
|
|
10
|
+
* @property {APIItemState} state - State of information
|
|
11
|
+
* @property {number} [timestamp] - Time to get information
|
|
12
|
+
* @property {string} free - Transferable balance
|
|
13
|
+
* @property {string} locked - Locked balance, cannot be transferred, locked here is only meaningful in the context of token transfer
|
|
14
|
+
* @property {metadata} [metadata] - Could be anything, supposed to be generic to handle various contexts
|
|
15
|
+
*/
|
|
16
|
+
(function (BalanceType) {
|
|
17
|
+
BalanceType["TRANSFERABLE"] = "transferable";
|
|
18
|
+
BalanceType["TOTAL"] = "total";
|
|
19
|
+
BalanceType["TOTAL_MINUS_RESERVED"] = "totalMinusReserved";
|
|
20
|
+
BalanceType["KEEP_ALIVE"] = "keepAlive";
|
|
21
|
+
})(BalanceType || (BalanceType = {}));
|
package/utils/fee/transfer.js
CHANGED
|
@@ -6,7 +6,7 @@ import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-p
|
|
|
6
6
|
import { DEFAULT_CARDANO_TTL_OFFSET } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts';
|
|
7
7
|
import { createBitcoinTransaction } from '@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer';
|
|
8
8
|
import { createCardanoTransaction } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
|
|
9
|
-
import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
9
|
+
import { gasSettingsForEWC, getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
10
10
|
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
11
11
|
import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
12
12
|
import { createAcrossBridgeExtrinsic, createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
@@ -191,9 +191,13 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
191
191
|
var _tx$gas;
|
|
192
192
|
// Calculate fee for evm transaction
|
|
193
193
|
const tx = transaction;
|
|
194
|
-
|
|
194
|
+
let gasLimit = ((_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.toString()) || (await evmApi.api.eth.estimateGas(tx)).toString();
|
|
195
195
|
const _feeCustom = feeCustom;
|
|
196
196
|
const combineFee = combineEthFee(fee, feeOption, _feeCustom);
|
|
197
|
+
if (srcChain.slug === 'energy_web_chain') {
|
|
198
|
+
gasLimit = gasSettingsForEWC.gasLimit.toString();
|
|
199
|
+
combineFee.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
|
|
200
|
+
}
|
|
197
201
|
if (combineFee.maxFeePerGas) {
|
|
198
202
|
estimatedFee = new BigN(combineFee.maxFeePerGas).multipliedBy(gasLimit).toFixed(0);
|
|
199
203
|
} else {
|
|
@@ -384,7 +388,6 @@ export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee)
|
|
|
384
388
|
funcCreateExtrinsic = createAvailBridgeExtrinsicFromAvail;
|
|
385
389
|
} else {
|
|
386
390
|
funcCreateExtrinsic = createXcmExtrinsicV2;
|
|
387
|
-
params.sendingValue = '1';
|
|
388
391
|
}
|
|
389
392
|
const extrinsic = await funcCreateExtrinsic(params);
|
|
390
393
|
|
package/utils/index.js
CHANGED
|
@@ -273,13 +273,36 @@ export const stripUrl = url => {
|
|
|
273
273
|
return parts[2];
|
|
274
274
|
};
|
|
275
275
|
export const baseParseIPFSUrl = (input, customDomain) => {
|
|
276
|
-
const selectedDomain = customDomain || getRandomIpfsGateway();
|
|
277
276
|
if (!input || input.length === 0) {
|
|
278
277
|
return undefined;
|
|
279
278
|
}
|
|
280
|
-
|
|
279
|
+
|
|
280
|
+
// Case 1: Return as-is for inline data URLs (e.g. base64-encoded images)
|
|
281
|
+
if (input.startsWith('data:')) {
|
|
281
282
|
return input;
|
|
282
283
|
}
|
|
284
|
+
const selectedDomain = customDomain || getRandomIpfsGateway();
|
|
285
|
+
|
|
286
|
+
// Case 2: Replace Pinata private gateways with a public IPFS gateway
|
|
287
|
+
// ==== EX: https://ikzttp.mypinata.cloud/ipfs/QmYDvPAXtiJg7s8JdRBSLWdgSphQdac8j1YuQNNxcGE1hg/9586.png
|
|
288
|
+
// Case 2b: Blockscout IPFS debug gateway -> rewrite to public gateway
|
|
289
|
+
// ==== EX: http://ipfs-debug.node.blockscout.com/ipfs/QmX2qHy1o27KgmHJSG2wKj2qLiv1gMCJCTn4nxzEVtTdgF
|
|
290
|
+
// Case 2c: http://ipfs.node.blockscout.com/ipfs/QmeTETrnJcG3iowfT3tXtz2jKmyeYbeag3AeYfDk5pBjGg
|
|
291
|
+
|
|
292
|
+
const privateGatewayPattern = /https?:\/\/([^/]*pinata\.cloud|[^/]*\.node\.blockscout\.com)\/ipfs\//;
|
|
293
|
+
if (privateGatewayPattern.test(input)) {
|
|
294
|
+
return input.replace(privateGatewayPattern, selectedDomain);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Case 3: Handle NFT.storage subdomain links (e.g. https://<cid>.ipfs.nftstorage.link/...)
|
|
298
|
+
// Always redirect to selectedDomain to avoid SSL version/cipher mismatch errors
|
|
299
|
+
// ==== EX: https://bafybeias6as7k66hkghst3w4jwk6x5dkfk56oglqh44x6jmok6n7kcvg7m.ipfs.nftstorage.link/0.gif?ext=gif
|
|
300
|
+
const nftStorageMatch = input.match(/^https?:\/\/([a-zA-Z0-9]+)\.ipfs\.nftstorage\.link\/(.*)$/);
|
|
301
|
+
if (nftStorageMatch) {
|
|
302
|
+
const cid = nftStorageMatch[1];
|
|
303
|
+
const pathAndQuery = nftStorageMatch[2] || '';
|
|
304
|
+
return `${selectedDomain}${cid}/${pathAndQuery}`;
|
|
305
|
+
}
|
|
283
306
|
if (isUrl(input) || input.includes('https://') || input.includes('http')) {
|
|
284
307
|
return input;
|
|
285
308
|
}
|
package/utils/setup-api-sdk.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { APP_VERSION, BACKEND_API_URL
|
|
4
|
+
import { APP_VERSION, BACKEND_API_URL } from '@subwallet/extension-base/constants';
|
|
5
5
|
import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
|
|
6
6
|
import { TARGET_ENV } from "./environment.js";
|
|
7
7
|
const CHAIN_LIST_VERSION = process.env.CHAIN_LIST_VERSION;
|
|
@@ -12,9 +12,4 @@ export function setupApiSDK() {
|
|
|
12
12
|
platform: TARGET_ENV,
|
|
13
13
|
chainListVersion: CHAIN_LIST_VERSION
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
// Custom the price history API with other different base URL
|
|
17
|
-
subwalletApiSdk.priceHistoryApi.updateConfig({
|
|
18
|
-
baseUrl: BACKEND_PRICE_HISTORY_URL
|
|
19
|
-
});
|
|
20
15
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getExtrinsicByPolkadotXcmPallet = getExtrinsicByPolkadotXcmPallet;
|
|
7
|
-
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
8
|
-
var _utils = require("@subwallet/extension-base/services/balance-service/transfer/xcm/utils");
|
|
9
|
-
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
|
|
13
|
-
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
14
|
-
let version = _utils.STABLE_XCM_VERSION;
|
|
15
|
-
let method = 'limitedReserveTransferAssets';
|
|
16
|
-
if ((0, _utils2._isBridgedToken)(tokenInfo) && !(0, _xcmParser._isXcmWithinSameConsensus)(originChainInfo, destinationChainInfo)) {
|
|
17
|
-
version = 4;
|
|
18
|
-
method = 'transferAssets';
|
|
19
|
-
}
|
|
20
|
-
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo, tokenInfo.slug)) {
|
|
21
|
-
method = 'limitedTeleportAssets';
|
|
22
|
-
}
|
|
23
|
-
const weightParam = (0, _xcmParser._getXcmDestWeight)(originChainInfo);
|
|
24
|
-
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, version);
|
|
25
|
-
const beneficiary = (0, _xcmParser._getXcmBeneficiary)(destinationChainInfo, recipientAddress, version);
|
|
26
|
-
const tokenLocation = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, version);
|
|
27
|
-
return api.tx.polkadotXcm[method](destination, beneficiary, tokenLocation, 0,
|
|
28
|
-
// FeeAssetItem
|
|
29
|
-
weightParam);
|
|
30
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getExtrinsicByXtokensPallet = getExtrinsicByXtokensPallet;
|
|
7
|
-
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
8
|
-
var _utils = require("@subwallet/extension-base/services/balance-service/transfer/xcm/utils");
|
|
9
|
-
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
|
|
13
|
-
function getCurrencyId(tokenInfo) {
|
|
14
|
-
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
15
|
-
const tokenType = (0, _utils2._getXcmAssetType)(tokenInfo);
|
|
16
|
-
const assetId = (0, _utils2._getXcmAssetId)(tokenInfo);
|
|
17
|
-
return {
|
|
18
|
-
[tokenType]: assetId
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
22
|
-
}
|
|
23
|
-
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
24
|
-
const version = _utils.STABLE_XCM_VERSION;
|
|
25
|
-
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, version, recipientAddress);
|
|
26
|
-
if (!(0, _utils2._getXcmAssetMultilocation)(tokenInfo)) {
|
|
27
|
-
const tokenCurrencyId = getCurrencyId(tokenInfo);
|
|
28
|
-
return api.tx.xTokens.transfer(tokenCurrencyId, value, destination, (0, _xcmParser._getXcmDestWeight)(originChainInfo));
|
|
29
|
-
}
|
|
30
|
-
const tokenMultiAsset = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, version);
|
|
31
|
-
return api.tx.xTokens.transferMultiassets(tokenMultiAsset, 0, destination, (0, _xcmParser._getXcmDestWeight)(originChainInfo));
|
|
32
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getExtrinsicByXcmPalletPallet = getExtrinsicByXcmPalletPallet;
|
|
7
|
-
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
8
|
-
var _utils = require("@subwallet/extension-base/services/balance-service/transfer/xcm/utils");
|
|
9
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
-
|
|
12
|
-
// this pallet is only used by Relaychains
|
|
13
|
-
function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
14
|
-
const weightParam = (0, _xcmParser._getXcmDestWeight)(originChainInfo);
|
|
15
|
-
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, _utils.STABLE_XCM_VERSION);
|
|
16
|
-
const beneficiary = (0, _xcmParser._getXcmBeneficiary)(destinationChainInfo, recipientAddress, _utils.STABLE_XCM_VERSION);
|
|
17
|
-
const tokenLocation = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, _utils.STABLE_XCM_VERSION);
|
|
18
|
-
let method = 'limitedReserveTransferAssets';
|
|
19
|
-
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo)) {
|
|
20
|
-
method = 'limitedTeleportAssets';
|
|
21
|
-
}
|
|
22
|
-
return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
|
|
23
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ApiPromise } from '@polkadot/api';
|
|
3
|
-
export declare function getExtrinsicByPolkadotXcmPallet(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, recipientAddress: string, value: string, api: ApiPromise): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation, _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
|
-
import { _isBridgedToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
-
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
8
|
-
let version = STABLE_XCM_VERSION;
|
|
9
|
-
let method = 'limitedReserveTransferAssets';
|
|
10
|
-
if (_isBridgedToken(tokenInfo) && !_isXcmWithinSameConsensus(originChainInfo, destinationChainInfo)) {
|
|
11
|
-
version = 4;
|
|
12
|
-
method = 'transferAssets';
|
|
13
|
-
}
|
|
14
|
-
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo, tokenInfo.slug)) {
|
|
15
|
-
method = 'limitedTeleportAssets';
|
|
16
|
-
}
|
|
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,
|
|
22
|
-
// FeeAssetItem
|
|
23
|
-
weightParam);
|
|
24
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ApiPromise } from '@polkadot/api';
|
|
3
|
-
export declare function getExtrinsicByXtokensPallet(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, recipientAddress: string, value: string, api: ApiPromise): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
|
-
import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
-
function getCurrencyId(tokenInfo) {
|
|
8
|
-
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
9
|
-
const tokenType = _getXcmAssetType(tokenInfo);
|
|
10
|
-
const assetId = _getXcmAssetId(tokenInfo);
|
|
11
|
-
return {
|
|
12
|
-
[tokenType]: assetId
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo);
|
|
16
|
-
}
|
|
17
|
-
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
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));
|
|
26
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ApiPromise } from '@polkadot/api';
|
|
3
|
-
export declare function getExtrinsicByXcmPalletPallet(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, recipientAddress: string, value: string, api: ApiPromise): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
|
-
// this pallet is only used by Relaychains
|
|
7
|
-
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
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
|
-
let method = 'limitedReserveTransferAssets';
|
|
13
|
-
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
14
|
-
method = 'limitedTeleportAssets';
|
|
15
|
-
}
|
|
16
|
-
return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
|
|
17
|
-
}
|