@subwallet/extension-base 1.3.66-0 → 1.3.67-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/cjs/core/substrate/xcm-parser.js +0 -176
- package/cjs/koni/background/handlers/Extension.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/smart-contract.js +54 -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/swap-service/handler/base-handler.js +18 -21
- package/cjs/utils/fee/transfer.js +5 -2
- package/core/substrate/xcm-parser.d.ts +1 -49
- package/core/substrate/xcm-parser.js +1 -173
- package/koni/background/handlers/Extension.js +1 -1
- package/package.json +5 -20
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/smart-contract.d.ts +4 -0
- package/services/balance-service/transfer/smart-contract.js +52 -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/swap-service/handler/base-handler.d.ts +0 -1
- package/services/swap-service/handler/base-handler.js +19 -22
- package/utils/fee/transfer.js +6 -3
- 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
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
import { fetchParaSpellChainMap } from '@subwallet/extension-base/constants/paraspell-chain-map';
|
|
5
5
|
import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
|
|
6
6
|
import { fetchFromProxyService } from '@subwallet/extension-base/utils';
|
|
7
|
+
import BigNumber from 'bignumber.js';
|
|
7
8
|
import { assert, compactToU8a, isHex, u8aConcat, u8aEq } from '@polkadot/util';
|
|
8
9
|
const version = '/v4';
|
|
9
10
|
const paraSpellApi = {
|
|
10
11
|
buildXcm: `${version}/x-transfer`,
|
|
12
|
+
feeXcm: `${version}/xcm-fee`,
|
|
11
13
|
dryRunXcm: `${version}/dry-run`,
|
|
12
|
-
|
|
14
|
+
dryRunPreviewXcm: `${version}/dry-run-preview`
|
|
13
15
|
};
|
|
14
16
|
function txHexToSubmittableExtrinsic(api, hex) {
|
|
15
17
|
try {
|
|
@@ -151,6 +153,51 @@ export async function dryRunXcm(request) {
|
|
|
151
153
|
}
|
|
152
154
|
return await response.json();
|
|
153
155
|
}
|
|
156
|
+
export async function dryRunPreviewXcm(request) {
|
|
157
|
+
var _originTokenInfo$meta3;
|
|
158
|
+
const {
|
|
159
|
+
destinationChain,
|
|
160
|
+
originChain,
|
|
161
|
+
originTokenInfo,
|
|
162
|
+
recipient,
|
|
163
|
+
sender,
|
|
164
|
+
sendingValue
|
|
165
|
+
} = request;
|
|
166
|
+
const paraSpellChainMap = await fetchParaSpellChainMap();
|
|
167
|
+
const paraSpellIdentifyV4 = (_originTokenInfo$meta3 = originTokenInfo.metadata) === null || _originTokenInfo$meta3 === void 0 ? void 0 : _originTokenInfo$meta3.paraSpellIdentifyV4;
|
|
168
|
+
if (!paraSpellIdentifyV4) {
|
|
169
|
+
throw new Error('Token is not support XCM at this time');
|
|
170
|
+
}
|
|
171
|
+
const bodyData = {
|
|
172
|
+
senderAddress: sender,
|
|
173
|
+
address: recipient,
|
|
174
|
+
from: paraSpellChainMap[originChain.slug],
|
|
175
|
+
to: paraSpellChainMap[destinationChain.slug],
|
|
176
|
+
currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
|
|
177
|
+
options: {
|
|
178
|
+
abstractDecimals: false,
|
|
179
|
+
mintFeeAssets: true
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.dryRunPreviewXcm, {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
body: JSON.stringify(bodyData),
|
|
185
|
+
headers: {
|
|
186
|
+
'Content-Type': 'application/json',
|
|
187
|
+
Accept: 'application/json'
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
if (!response.ok) {
|
|
191
|
+
const error = await response.json();
|
|
192
|
+
return {
|
|
193
|
+
origin: {
|
|
194
|
+
success: false,
|
|
195
|
+
failureReason: error.message
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return await response.json();
|
|
200
|
+
}
|
|
154
201
|
export async function estimateXcmFee(request) {
|
|
155
202
|
var _fromTokenInfo$metada;
|
|
156
203
|
const {
|
|
@@ -163,6 +210,8 @@ export async function estimateXcmFee(request) {
|
|
|
163
210
|
} = request;
|
|
164
211
|
const paraSpellChainMap = await fetchParaSpellChainMap();
|
|
165
212
|
const paraSpellIdentifyV4 = (_fromTokenInfo$metada = fromTokenInfo.metadata) === null || _fromTokenInfo$metada === void 0 ? void 0 : _fromTokenInfo$metada.paraSpellIdentifyV4;
|
|
213
|
+
const requestValue = BigNumber(value).gt(0) ? value : '1'; // avoid bug in-case estimate fee sendingValue <= 0;
|
|
214
|
+
|
|
166
215
|
if (!paraSpellIdentifyV4) {
|
|
167
216
|
console.error('Lack of paraspell metadata');
|
|
168
217
|
return undefined;
|
|
@@ -172,7 +221,7 @@ export async function estimateXcmFee(request) {
|
|
|
172
221
|
address: recipient,
|
|
173
222
|
from: paraSpellChainMap[fromChainInfo.slug],
|
|
174
223
|
to: paraSpellChainMap[toChainInfo.slug],
|
|
175
|
-
currency: createParaSpellCurrency(paraSpellIdentifyV4,
|
|
224
|
+
currency: createParaSpellCurrency(paraSpellIdentifyV4, requestValue),
|
|
176
225
|
options: {
|
|
177
226
|
abstractDecimals: false
|
|
178
227
|
}
|
|
@@ -192,8 +241,6 @@ export async function estimateXcmFee(request) {
|
|
|
192
241
|
return await response.json();
|
|
193
242
|
}
|
|
194
243
|
function createParaSpellCurrency(paraSpellIdentifyV4, amount) {
|
|
195
|
-
// todo: handle complex conditions for asset has same symbol in a chain: Id, Multi-location, ...
|
|
196
|
-
// todo: or update all asset to use multi-location
|
|
197
244
|
return {
|
|
198
245
|
...paraSpellIdentifyV4,
|
|
199
246
|
amount
|
|
@@ -208,15 +255,4 @@ export function isChainNotSupportDryRun(str) {
|
|
|
208
255
|
const regex = /(?=.*DryRunApi)(?=.*not available).*/i; // Example: DryRunApi is not available on node Acala
|
|
209
256
|
|
|
210
257
|
return regex.test(str);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// todo: remove
|
|
214
|
-
export const STABLE_XCM_VERSION = 3;
|
|
215
|
-
|
|
216
|
-
// todo: remove
|
|
217
|
-
export function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
|
|
218
|
-
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug) || ['rococo'].includes(originChainInfo.slug) && ['rococo_assethub'].includes(destChainInfo.slug) || ['westend'].includes(originChainInfo.slug) && ['westend_assethub'].includes(destChainInfo.slug);
|
|
219
|
-
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug) || ['rococo'].includes(destChainInfo.slug) && ['rococo_assethub'].includes(originChainInfo.slug) || ['westend'].includes(destChainInfo.slug) && ['westend_assethub'].includes(originChainInfo.slug);
|
|
220
|
-
const isXcmMythos = originChainInfo.slug === 'mythos' && destChainInfo.slug === 'statemint' && tokenSlug === 'mythos-NATIVE-MYTH' || originChainInfo.slug === 'statemint' && destChainInfo.slug === 'mythos' && tokenSlug === 'statemint-LOCAL-MYTH';
|
|
221
|
-
return relayChainToSystemChain || systemChainToRelayChain || isXcmMythos;
|
|
222
258
|
}
|
|
@@ -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 [];
|
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
|
|
|
@@ -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
|
-
}
|