@paraspell/sdk-core 13.11.0 → 14.0.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/README.md +1 -1
- package/dist/index.d.ts +110 -199
- package/dist/index.mjs +891 -1623
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2.js';
|
|
2
|
-
import { isChainEvm, getAssetsObject, InvalidCurrencyError,
|
|
2
|
+
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isSymbolMatch, isAssetEqual, isStableCoinAsset, isBridgedSystemAsset, isSymbolSpecifier, normalizeLocation, getNativeAssetSymbol, getEdFromAssetOrThrow, extractAssetLocation, hasDryRunSupport, normalizeSymbol, Native, getOtherAssets, canonicalizeLocation, getAssetsObjectImpl, getAssetsImpl, getNativeAssetsImpl, getOtherAssetsImpl, findAssetInfoImpl, findAssetInfoOrThrowImpl, findAssetInfoOnDestImpl, findAssetOnDestOrThrowImpl, findNativeAssetInfoImpl, findNativeAssetInfoOrThrowImpl, isChainEvmImpl, getNativeAssetSymbolImpl, getRelayChainSymbolImpl, hasDryRunSupportImpl, hasXcmPaymentApiSupportImpl, getExistentialDepositOrThrowImpl, normalizeCustomAssets } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
|
-
import { isAddress, pad, toHex, getAddress, concat, keccak256, isHex, createPublicClient, http,
|
|
6
|
-
import { getXcmPallet,
|
|
5
|
+
import { isAddress, pad, toHex, getAddress, concat, keccak256, isHex, createPublicClient, http, formatUnits as formatUnits$1, parseUnits as parseUnits$1 } from 'viem';
|
|
6
|
+
import { getXcmPallet, getOtherAssetsPallets, getNativeAssetsPallet, getSupportedPalletsDetails, ASSETS_PALLETS, NATIVE_ASSETS_PALLET_PRIORITY, OTHER_ASSETS_PALLET_PRIORITY, hasPalletImpl, getXcmPalletImpl } from '@paraspell/pallets';
|
|
7
7
|
export * from '@paraspell/pallets';
|
|
8
|
-
import { isTLocation, replaceBigInt, isExternalChain, Version, isRelayChain, isSubstrateBridge, Parents, deepEqual, isTrustedChain, isCustomChain, hasJunction,
|
|
8
|
+
import { isTLocation, replaceBigInt, isExternalChain, CHAINS, Version, isRelayChain, isSubstrateBridge, Parents, deepEqual, isTrustedChain, isCustomChain, hasJunction, isSnowbridge, getJunctionValue, ETHEREUM_BRIDGE_ORIGINS, isBridge, RELAYCHAINS, DEFAULT_SS58_PREFIX } from '@paraspell/sdk-common';
|
|
9
9
|
export * from '@paraspell/sdk-common';
|
|
10
10
|
import { mainnet, sepolia, moonbeam, moonriver } from 'viem/chains';
|
|
11
11
|
|
|
@@ -534,24 +534,19 @@ var DryRunFailedError = /*#__PURE__*/function (_Error) {
|
|
|
534
534
|
/**
|
|
535
535
|
* Constructs a new DryRunFailedError.
|
|
536
536
|
*
|
|
537
|
-
* @param
|
|
538
|
-
* @param
|
|
539
|
-
* @param prefix - Optional. A short sentence prepended to the message
|
|
537
|
+
* @param error - The dry-run error. Its `chain` marks which chain failed.
|
|
538
|
+
* @param prefix - Optional. A short sentence prepended to the message.
|
|
540
539
|
*/
|
|
541
|
-
function DryRunFailedError(
|
|
540
|
+
function DryRunFailedError(error, prefix) {
|
|
542
541
|
var _this;
|
|
543
542
|
_classCallCheck(this, DryRunFailedError);
|
|
544
|
-
var message = "Dry run failed: ".concat(reason);
|
|
545
|
-
if (dryRunType) {
|
|
546
|
-
message = "Dry run on ".concat(dryRunType, " failed: ").concat(reason);
|
|
547
|
-
}
|
|
543
|
+
var message = "Dry run on ".concat(error.chain, " failed: ").concat(error.reason);
|
|
548
544
|
if (prefix) {
|
|
549
545
|
message = "".concat(prefix, " ").concat(message);
|
|
550
546
|
}
|
|
551
547
|
_this = _callSuper(this, DryRunFailedError, [message]);
|
|
552
548
|
_this.name = 'DryRunFailedError';
|
|
553
|
-
_this.
|
|
554
|
-
_this.dryRunType = dryRunType;
|
|
549
|
+
_this.dryRunError = error;
|
|
555
550
|
return _this;
|
|
556
551
|
}
|
|
557
552
|
_inherits(DryRunFailedError, _Error);
|
|
@@ -2209,9 +2204,6 @@ var assertCurrencyCore = function assertCurrencyCore(value) {
|
|
|
2209
2204
|
if (Array.isArray(value)) {
|
|
2210
2205
|
throw new InvalidCurrencyError('An array of currencies is not supported here. Provide a single currency selector ({ symbol }, { id }, or { location }).');
|
|
2211
2206
|
}
|
|
2212
|
-
if (_typeof(value) === 'object' && 'location' in value && isOverrideLocationSpecifier(value.location)) {
|
|
2213
|
-
throw new InvalidCurrencyError('Override location specifier is not supported here. Provide a regular location.');
|
|
2214
|
-
}
|
|
2215
2207
|
};
|
|
2216
2208
|
var assertSenderSource = function assertSenderSource(sender) {
|
|
2217
2209
|
if (sender === undefined) {
|
|
@@ -2246,6 +2238,29 @@ var assertExtensionInstalled = function assertExtensionInstalled(extension, exte
|
|
|
2246
2238
|
}
|
|
2247
2239
|
};
|
|
2248
2240
|
|
|
2241
|
+
/**
|
|
2242
|
+
* Retrieves the chain name corresponding to a specified parachain ID.
|
|
2243
|
+
*
|
|
2244
|
+
* @param paraId - The parachain ID.
|
|
2245
|
+
* @returns The chain name if found; otherwise, null.
|
|
2246
|
+
*/
|
|
2247
|
+
var getTChain = function getTChain(paraId, ecosystem) {
|
|
2248
|
+
var _CHAINS$find;
|
|
2249
|
+
return (_CHAINS$find = CHAINS.find(function (chain) {
|
|
2250
|
+
return getParaId(chain) === paraId && (getChain(chain).ecosystem === ecosystem || chain === ecosystem);
|
|
2251
|
+
})) !== null && _CHAINS$find !== void 0 ? _CHAINS$find : null;
|
|
2252
|
+
};
|
|
2253
|
+
/**
|
|
2254
|
+
* Retrieves the substrate chain name corresponding to a specified parachain ID.
|
|
2255
|
+
*
|
|
2256
|
+
* @param paraId - The parachain ID.
|
|
2257
|
+
* @returns The substrate chain name if found; otherwise, null.
|
|
2258
|
+
*/
|
|
2259
|
+
var getTSubstrateChain = function getTSubstrateChain(paraId, ecosystem) {
|
|
2260
|
+
var chain = getTChain(paraId, ecosystem);
|
|
2261
|
+
return chain && !isExternalChain(chain) ? chain : null;
|
|
2262
|
+
};
|
|
2263
|
+
|
|
2249
2264
|
var createBuyExecution = function createBuyExecution(asset, weight) {
|
|
2250
2265
|
return [{
|
|
2251
2266
|
BuyExecution: {
|
|
@@ -2411,89 +2426,6 @@ var handleTransactUsingSend = /*#__PURE__*/function () {
|
|
|
2411
2426
|
};
|
|
2412
2427
|
}();
|
|
2413
2428
|
|
|
2414
|
-
var buildClaimAssetsParams = function buildClaimAssetsParams(options) {
|
|
2415
|
-
var assets = options.assets,
|
|
2416
|
-
version = options.version;
|
|
2417
|
-
var beneficiary = createBeneficiaryLocation(options);
|
|
2418
|
-
return {
|
|
2419
|
-
assets: addXcmVersionHeader(assets, version),
|
|
2420
|
-
beneficiary: addXcmVersionHeader(beneficiary, version)
|
|
2421
|
-
};
|
|
2422
|
-
};
|
|
2423
|
-
|
|
2424
|
-
var resolveAssets$1 = function resolveAssets(_ref, version) {
|
|
2425
|
-
var api = _ref.api,
|
|
2426
|
-
chain = _ref.chain,
|
|
2427
|
-
currency = _ref.currency;
|
|
2428
|
-
var normalizeAsset = function normalizeAsset(amount, currency) {
|
|
2429
|
-
var asset = api.findAssetInfoOrThrow(chain, currency);
|
|
2430
|
-
var abstracted = abstractDecimals(amount, asset.decimals, api);
|
|
2431
|
-
return createAsset(version, abstracted, localizeLocation(chain, asset.location));
|
|
2432
|
-
};
|
|
2433
|
-
if (Array.isArray(currency)) {
|
|
2434
|
-
if (currency.every(function (asset) {
|
|
2435
|
-
return isTAsset(asset);
|
|
2436
|
-
})) {
|
|
2437
|
-
return currency.map(function (asset) {
|
|
2438
|
-
return _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
2439
|
-
fun: {
|
|
2440
|
-
Fungible: BigInt(asset.fun.Fungible)
|
|
2441
|
-
}
|
|
2442
|
-
});
|
|
2443
|
-
});
|
|
2444
|
-
} else {
|
|
2445
|
-
return currency.map(function (currency) {
|
|
2446
|
-
return normalizeAsset(currency.amount, currency);
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
return [normalizeAsset(currency.amount, currency)];
|
|
2451
|
-
};
|
|
2452
|
-
|
|
2453
|
-
/**
|
|
2454
|
-
* @deprecated Asset claim functionality is deprecated and will be removed in v14.
|
|
2455
|
-
*/
|
|
2456
|
-
var claimAssets = /*#__PURE__*/function () {
|
|
2457
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
2458
|
-
var api, chain, address, pallets, supportedPallet, version, assets, params, call;
|
|
2459
|
-
return _regenerator().w(function (_context) {
|
|
2460
|
-
while (1) switch (_context.n) {
|
|
2461
|
-
case 0:
|
|
2462
|
-
api = options.api, chain = options.chain, address = options.address;
|
|
2463
|
-
validateAddress(api, address, chain, true);
|
|
2464
|
-
_context.n = 1;
|
|
2465
|
-
return api.init(chain, TX_CLIENT_TIMEOUT_MS);
|
|
2466
|
-
case 1:
|
|
2467
|
-
pallets = getSupportedPallets(chain);
|
|
2468
|
-
supportedPallet = pallets.find(function (p) {
|
|
2469
|
-
return p === 'PolkadotXcm' || p === 'XcmPallet';
|
|
2470
|
-
});
|
|
2471
|
-
if (supportedPallet) {
|
|
2472
|
-
_context.n = 2;
|
|
2473
|
-
break;
|
|
2474
|
-
}
|
|
2475
|
-
throw new UnsupportedOperationError('Unsupported pallet for asset claim');
|
|
2476
|
-
case 2:
|
|
2477
|
-
version = getChainVersion(api, chain);
|
|
2478
|
-
assets = resolveAssets$1(options, version);
|
|
2479
|
-
params = buildClaimAssetsParams(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
2480
|
-
version: version,
|
|
2481
|
-
assets: assets
|
|
2482
|
-
}));
|
|
2483
|
-
call = {
|
|
2484
|
-
module: supportedPallet,
|
|
2485
|
-
method: 'claim_assets',
|
|
2486
|
-
params: params
|
|
2487
|
-
};
|
|
2488
|
-
return _context.a(2, api.deserializeExtrinsics(call));
|
|
2489
|
-
}
|
|
2490
|
-
}, _callee);
|
|
2491
|
-
}));
|
|
2492
|
-
return function claimAssets(_x) {
|
|
2493
|
-
return _ref.apply(this, arguments);
|
|
2494
|
-
};
|
|
2495
|
-
}();
|
|
2496
|
-
|
|
2497
2429
|
var BaseAssetsPallet = /*#__PURE__*/_createClass(function BaseAssetsPallet(palletName) {
|
|
2498
2430
|
_classCallCheck(this, BaseAssetsPallet);
|
|
2499
2431
|
this.palletName = palletName;
|
|
@@ -3578,88 +3510,6 @@ var resolveAsset = function resolveAsset(currency, origin, destination, assetChe
|
|
|
3578
3510
|
return api.findAssetInfo(origin, currency, dest);
|
|
3579
3511
|
};
|
|
3580
3512
|
|
|
3581
|
-
var assertNotRawAssets = function assertNotRawAssets(currency) {
|
|
3582
|
-
if (Array.isArray(currency) && currency.length > 0 && currency.every(function (asset) {
|
|
3583
|
-
return isTAsset(asset);
|
|
3584
|
-
})) {
|
|
3585
|
-
throw new InvalidCurrencyError('Raw asset overrides are no longer supported. Please use custom assets instead.');
|
|
3586
|
-
}
|
|
3587
|
-
};
|
|
3588
|
-
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
3589
|
-
if (Array.isArray(currency)) {
|
|
3590
|
-
if (currency.length === 0) {
|
|
3591
|
-
throw new InvalidCurrencyError('Overridden assets cannot be empty');
|
|
3592
|
-
}
|
|
3593
|
-
if (currency.length === 1) {
|
|
3594
|
-
throw new InvalidCurrencyError('Please provide more than one asset');
|
|
3595
|
-
}
|
|
3596
|
-
assertNotRawAssets(currency);
|
|
3597
|
-
if (!feeAsset) {
|
|
3598
|
-
throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
|
|
3599
|
-
}
|
|
3600
|
-
}
|
|
3601
|
-
};
|
|
3602
|
-
var validateDestination = function validateDestination(origin, destination, api) {
|
|
3603
|
-
if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
3604
|
-
throw new ScenarioNotSupportedError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
3605
|
-
}
|
|
3606
|
-
if (typeof destination === 'string' && isExternalChain(destination) && !ETHEREUM_BRIDGE_ORIGINS.includes(origin)) {
|
|
3607
|
-
throw new ScenarioNotSupportedError("Transfers to Ethereum are only supported from: ".concat(ETHEREUM_BRIDGE_ORIGINS.join(', ')));
|
|
3608
|
-
}
|
|
3609
|
-
var isLocationDestination = _typeof(destination) === 'object';
|
|
3610
|
-
var isBridgeTransfer = !isTLocation(destination) && isBridge(origin, destination);
|
|
3611
|
-
if (!isLocationDestination) {
|
|
3612
|
-
var originRelayChainSymbol = api.getRelayChainSymbol(origin);
|
|
3613
|
-
var destinationRelayChainSymbol = api.getRelayChainSymbol(destination);
|
|
3614
|
-
if (!isBridgeTransfer && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
3615
|
-
throw new ScenarioNotSupportedError('Origin and destination must share the same relay chain unless using a bridge.');
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
if (isRelayChain(origin) && typeof destination === 'string' && !isExternalChain(destination)) {
|
|
3619
|
-
var chain = getChain(destination);
|
|
3620
|
-
if (!chain.isRelayToParaEnabled()) {
|
|
3621
|
-
throw new ScenarioNotSupportedError({
|
|
3622
|
-
chain: destination,
|
|
3623
|
-
scenario: 'RelayToPara'
|
|
3624
|
-
});
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
};
|
|
3628
|
-
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
3629
|
-
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
3630
|
-
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
3631
|
-
}
|
|
3632
|
-
if (!assetCheckEnabled && 'id' in currency) {
|
|
3633
|
-
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
3634
|
-
}
|
|
3635
|
-
};
|
|
3636
|
-
var validateTransact = function validateTransact(_ref) {
|
|
3637
|
-
var api = _ref.api,
|
|
3638
|
-
from = _ref.from,
|
|
3639
|
-
to = _ref.to,
|
|
3640
|
-
sender = _ref.sender,
|
|
3641
|
-
address = _ref.recipient,
|
|
3642
|
-
currency = _ref.currency,
|
|
3643
|
-
transactOptions = _ref.transactOptions;
|
|
3644
|
-
var call = transactOptions === null || transactOptions === void 0 ? void 0 : transactOptions.call;
|
|
3645
|
-
if (!call) return;
|
|
3646
|
-
if (from === to) {
|
|
3647
|
-
throw new UnsupportedOperationError('Cannot use transact options with local transfers.');
|
|
3648
|
-
}
|
|
3649
|
-
if (Array.isArray(currency)) {
|
|
3650
|
-
throw new UnsupportedOperationError('Cannot use transact options with multiple currencies.');
|
|
3651
|
-
}
|
|
3652
|
-
if (typeof call === 'string' && !isHex(call)) {
|
|
3653
|
-
throw new ValidationError('Transact call hex must be a valid hex string.');
|
|
3654
|
-
}
|
|
3655
|
-
if (isChainEvm(from) || typeof to === 'string' && isChainEvm(to)) {
|
|
3656
|
-
throw new UnsupportedOperationError('Transact option is only supported for Substrate to Substrate scenarios.');
|
|
3657
|
-
}
|
|
3658
|
-
if (typeof address === 'string' && sender && !compareAddresses(api, address, sender)) {
|
|
3659
|
-
return new ValidationError('Sender address must match the destination address for transact to work.');
|
|
3660
|
-
}
|
|
3661
|
-
};
|
|
3662
|
-
|
|
3663
3513
|
var resolveCurrency = function resolveCurrency(api, currency, resolvedFeeAsset, origin, destination, onAsset) {
|
|
3664
3514
|
var dest = !isTLocation(destination) ? destination : null;
|
|
3665
3515
|
if (Array.isArray(currency)) {
|
|
@@ -3667,7 +3517,6 @@ var resolveCurrency = function resolveCurrency(api, currency, resolvedFeeAsset,
|
|
|
3667
3517
|
if (!resolvedFeeAsset) {
|
|
3668
3518
|
throw new InvalidCurrencyError('Fee asset is required when providing more than one asset');
|
|
3669
3519
|
}
|
|
3670
|
-
assertNotRawAssets(currency);
|
|
3671
3520
|
var assets = currency.map(function (item) {
|
|
3672
3521
|
if (item.amount === AMOUNT_ALL) {
|
|
3673
3522
|
throw new InvalidCurrencyError('Provided assets cannot use amount all. Please specify amount.');
|
|
@@ -3712,7 +3561,6 @@ var resolveFeeAsset = function resolveFeeAsset(api, feeAsset, origin, destinatio
|
|
|
3712
3561
|
if (!Array.isArray(currency) && !origin.startsWith('Hydration') && origin !== 'AssetHubPolkadot') {
|
|
3713
3562
|
throw new ScenarioNotSupportedError("Fee asset is not supported on ".concat(origin));
|
|
3714
3563
|
}
|
|
3715
|
-
assertNotRawAssets(currency);
|
|
3716
3564
|
var dest = !isTLocation(destination) ? destination : null;
|
|
3717
3565
|
var asset = api.findAssetInfo(origin, feeAsset, dest);
|
|
3718
3566
|
if (!asset) {
|
|
@@ -3838,17 +3686,10 @@ var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge,
|
|
|
3838
3686
|
feeAsset = options.feeAsset,
|
|
3839
3687
|
origin = options.from,
|
|
3840
3688
|
destination = options.to;
|
|
3841
|
-
if ('location' in currency && isOverrideLocationSpecifier(currency.location)) {
|
|
3842
|
-
return currency.location.value;
|
|
3843
|
-
}
|
|
3844
3689
|
if (Array.isArray(currency)) {
|
|
3845
3690
|
if (!feeAsset) {
|
|
3846
3691
|
throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
|
|
3847
3692
|
}
|
|
3848
|
-
if ('location' in feeAsset && isOverrideLocationSpecifier(feeAsset.location)) {
|
|
3849
|
-
throw new InvalidCurrencyError('Fee asset cannot be an overridden location specifier');
|
|
3850
|
-
}
|
|
3851
|
-
assertNotRawAssets(currency);
|
|
3852
3693
|
var version = getChainVersion(api, origin);
|
|
3853
3694
|
var _resolveCurrency = resolveCurrency(api, currency, resolvedFeeAsset, origin, destination, function (asset) {
|
|
3854
3695
|
return validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
|
|
@@ -3863,11 +3704,80 @@ var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge,
|
|
|
3863
3704
|
return undefined;
|
|
3864
3705
|
};
|
|
3865
3706
|
|
|
3866
|
-
var
|
|
3867
|
-
if (
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3707
|
+
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
3708
|
+
if (Array.isArray(currency)) {
|
|
3709
|
+
if (currency.length === 0) {
|
|
3710
|
+
throw new InvalidCurrencyError('Overridden assets cannot be empty');
|
|
3711
|
+
}
|
|
3712
|
+
if (currency.length === 1) {
|
|
3713
|
+
throw new InvalidCurrencyError('Please provide more than one asset');
|
|
3714
|
+
}
|
|
3715
|
+
if (!feeAsset) {
|
|
3716
|
+
throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
};
|
|
3720
|
+
var validateDestination = function validateDestination(origin, destination, api) {
|
|
3721
|
+
if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
3722
|
+
throw new ScenarioNotSupportedError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
3723
|
+
}
|
|
3724
|
+
if (typeof destination === 'string' && isExternalChain(destination) && !ETHEREUM_BRIDGE_ORIGINS.some(function (o) {
|
|
3725
|
+
return o === origin;
|
|
3726
|
+
})) {
|
|
3727
|
+
throw new ScenarioNotSupportedError("Transfers to Ethereum are only supported from: ".concat(ETHEREUM_BRIDGE_ORIGINS.join(', ')));
|
|
3728
|
+
}
|
|
3729
|
+
var isLocationDestination = _typeof(destination) === 'object';
|
|
3730
|
+
var isBridgeTransfer = !isTLocation(destination) && isBridge(origin, destination);
|
|
3731
|
+
if (!isLocationDestination) {
|
|
3732
|
+
var originRelayChainSymbol = api.getRelayChainSymbol(origin);
|
|
3733
|
+
var destinationRelayChainSymbol = api.getRelayChainSymbol(destination);
|
|
3734
|
+
if (!isBridgeTransfer && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
3735
|
+
throw new ScenarioNotSupportedError('Origin and destination must share the same relay chain unless using a bridge.');
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
if (isRelayChain(origin) && typeof destination === 'string' && !isExternalChain(destination)) {
|
|
3739
|
+
var chain = getChain(destination);
|
|
3740
|
+
if (!chain.isRelayToParaEnabled()) {
|
|
3741
|
+
throw new ScenarioNotSupportedError({
|
|
3742
|
+
chain: destination,
|
|
3743
|
+
scenario: 'RelayToPara'
|
|
3744
|
+
});
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
};
|
|
3748
|
+
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
3749
|
+
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
3750
|
+
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
3751
|
+
}
|
|
3752
|
+
if (!assetCheckEnabled && 'id' in currency) {
|
|
3753
|
+
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
3754
|
+
}
|
|
3755
|
+
};
|
|
3756
|
+
var validateTransact = function validateTransact(_ref) {
|
|
3757
|
+
var api = _ref.api,
|
|
3758
|
+
from = _ref.from,
|
|
3759
|
+
to = _ref.to,
|
|
3760
|
+
sender = _ref.sender,
|
|
3761
|
+
address = _ref.recipient,
|
|
3762
|
+
currency = _ref.currency,
|
|
3763
|
+
transactOptions = _ref.transactOptions;
|
|
3764
|
+
var call = transactOptions === null || transactOptions === void 0 ? void 0 : transactOptions.call;
|
|
3765
|
+
if (!call) return;
|
|
3766
|
+
if (from === to) {
|
|
3767
|
+
throw new UnsupportedOperationError('Cannot use transact options with local transfers.');
|
|
3768
|
+
}
|
|
3769
|
+
if (Array.isArray(currency)) {
|
|
3770
|
+
throw new UnsupportedOperationError('Cannot use transact options with multiple currencies.');
|
|
3771
|
+
}
|
|
3772
|
+
if (typeof call === 'string' && !isHex(call)) {
|
|
3773
|
+
throw new ValidationError('Transact call hex must be a valid hex string.');
|
|
3774
|
+
}
|
|
3775
|
+
if (isChainEvm(from) || typeof to === 'string' && isChainEvm(to)) {
|
|
3776
|
+
throw new UnsupportedOperationError('Transact option is only supported for Substrate to Substrate scenarios.');
|
|
3777
|
+
}
|
|
3778
|
+
if (typeof address === 'string' && sender && !compareAddresses(api, address, sender)) {
|
|
3779
|
+
return new ValidationError('Sender address must match the destination address for transact to work.');
|
|
3780
|
+
}
|
|
3871
3781
|
};
|
|
3872
3782
|
|
|
3873
3783
|
var resolveTransferParams = function resolveTransferParams(options) {
|
|
@@ -3885,7 +3795,7 @@ var resolveTransferParams = function resolveTransferParams(options) {
|
|
|
3885
3795
|
validateDestinationAddress(address, destination, api);
|
|
3886
3796
|
if (sender) validateAddress(api, sender, origin, false);
|
|
3887
3797
|
var isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
|
|
3888
|
-
var assetCheckEnabled =
|
|
3798
|
+
var assetCheckEnabled = !Array.isArray(currency);
|
|
3889
3799
|
validateAssetSpecifiers(assetCheckEnabled, currency);
|
|
3890
3800
|
var asset = resolveAsset(currency, origin, destination, assetCheckEnabled, api);
|
|
3891
3801
|
var resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
@@ -4038,177 +3948,42 @@ var getMythosOriginFee = /*#__PURE__*/function () {
|
|
|
4038
3948
|
};
|
|
4039
3949
|
}();
|
|
4040
3950
|
|
|
3951
|
+
var evmExtension;
|
|
3952
|
+
var registerEvmExtension = function registerEvmExtension(extension) {
|
|
3953
|
+
evmExtension = extension;
|
|
3954
|
+
};
|
|
3955
|
+
var getEvmExtensionOrThrow = function getEvmExtensionOrThrow() {
|
|
3956
|
+
assertExtensionInstalled(evmExtension, 'EVM', '@paraspell/evm', 'using an EVM origin');
|
|
3957
|
+
return evmExtension;
|
|
3958
|
+
};
|
|
3959
|
+
|
|
3960
|
+
var evmSnowbridgeExtension;
|
|
3961
|
+
var registerEvmSnowbridgeExtension = function registerEvmSnowbridgeExtension(extension) {
|
|
3962
|
+
evmSnowbridgeExtension = extension;
|
|
3963
|
+
};
|
|
3964
|
+
var getEvmSnowbridgeExtensionOrThrow = function getEvmSnowbridgeExtensionOrThrow() {
|
|
3965
|
+
assertExtensionInstalled(evmSnowbridgeExtension, 'EVM Snowbridge', '@paraspell/evm-snowbridge', 'using Ethereum as an origin');
|
|
3966
|
+
return evmSnowbridgeExtension;
|
|
3967
|
+
};
|
|
3968
|
+
|
|
3969
|
+
var swapExtension;
|
|
3970
|
+
var registerSwapExtension = function registerSwapExtension(extension) {
|
|
3971
|
+
swapExtension = extension;
|
|
3972
|
+
};
|
|
3973
|
+
var getSwapExtensionOrThrow = function getSwapExtensionOrThrow() {
|
|
3974
|
+
assertExtensionInstalled(swapExtension, 'swap', '@paraspell/swap', 'using swap features');
|
|
3975
|
+
return swapExtension;
|
|
3976
|
+
};
|
|
3977
|
+
|
|
3978
|
+
var API_TYPES = ['PAPI', 'PJS', 'DEDOT'];
|
|
3979
|
+
|
|
4041
3980
|
/**
|
|
4042
|
-
*
|
|
4043
|
-
*
|
|
4044
|
-
* @deprecated Asset claim functionality is deprecated and will be removed in v14.
|
|
3981
|
+
* The options for the batch builder.
|
|
4045
3982
|
*/
|
|
4046
|
-
var
|
|
4047
|
-
|
|
4048
|
-
_classCallCheck(this, AssetClaimBuilder);
|
|
4049
|
-
this.api = api;
|
|
4050
|
-
this._options = options !== null && options !== void 0 ? options : {};
|
|
4051
|
-
}
|
|
3983
|
+
var BatchMode;
|
|
3984
|
+
(function (BatchMode) {
|
|
4052
3985
|
/**
|
|
4053
|
-
*
|
|
4054
|
-
*
|
|
4055
|
-
* @param assets - An array of assets to claim in a multi-asset format.
|
|
4056
|
-
* @returns An instance of Builder
|
|
4057
|
-
*/
|
|
4058
|
-
return _createClass(AssetClaimBuilder, [{
|
|
4059
|
-
key: "currency",
|
|
4060
|
-
value: function currency(_currency) {
|
|
4061
|
-
return new AssetClaimBuilder(this.api, _objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
4062
|
-
currency: _currency
|
|
4063
|
-
}));
|
|
4064
|
-
}
|
|
4065
|
-
/**
|
|
4066
|
-
* Sets the sender address.
|
|
4067
|
-
*
|
|
4068
|
-
* @param address - The sender address.
|
|
4069
|
-
* @returns
|
|
4070
|
-
*/
|
|
4071
|
-
}, {
|
|
4072
|
-
key: "sender",
|
|
4073
|
-
value: function sender(_sender) {
|
|
4074
|
-
var isPath = typeof _sender === 'string' && _sender.startsWith('//');
|
|
4075
|
-
var isPathOrSigner = isPath || isSenderSigner(_sender);
|
|
4076
|
-
var address = isPathOrSigner ? this.api.deriveAddress(_sender) : _sender;
|
|
4077
|
-
return new AssetClaimBuilder(this.api, _objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
4078
|
-
sender: address,
|
|
4079
|
-
senderSource: isPathOrSigner ? _sender : undefined
|
|
4080
|
-
}));
|
|
4081
|
-
}
|
|
4082
|
-
/**
|
|
4083
|
-
* Specifies the account address on which the assets will be claimed.
|
|
4084
|
-
*
|
|
4085
|
-
* @param address - The destination account address.
|
|
4086
|
-
* @returns An instance of Builder
|
|
4087
|
-
*/
|
|
4088
|
-
}, {
|
|
4089
|
-
key: "address",
|
|
4090
|
-
value: function address(_address) {
|
|
4091
|
-
var isPath = typeof _address === 'string' && _address.startsWith('//');
|
|
4092
|
-
var resolvedAddress = isPath ? this.api.deriveAddress(_address) : _address;
|
|
4093
|
-
return new AssetClaimBuilder(this.api, _objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
4094
|
-
address: resolvedAddress
|
|
4095
|
-
}));
|
|
4096
|
-
}
|
|
4097
|
-
/**
|
|
4098
|
-
* Sets the XCM version to be used for the asset claim.
|
|
4099
|
-
*
|
|
4100
|
-
* @param version - The XCM version.
|
|
4101
|
-
* @returns An instance of Builder
|
|
4102
|
-
*/
|
|
4103
|
-
}, {
|
|
4104
|
-
key: "xcmVersion",
|
|
4105
|
-
value: function xcmVersion(version) {
|
|
4106
|
-
return new AssetClaimBuilder(this.api, _objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
4107
|
-
version: version
|
|
4108
|
-
}));
|
|
4109
|
-
}
|
|
4110
|
-
/**
|
|
4111
|
-
* Builds and returns the asset claim extrinsic.
|
|
4112
|
-
*
|
|
4113
|
-
* @returns A Promise that resolves to the asset claim extrinsic.
|
|
4114
|
-
*/
|
|
4115
|
-
}, {
|
|
4116
|
-
key: "build",
|
|
4117
|
-
value: function build() {
|
|
4118
|
-
return claimAssets(_objectSpread2({
|
|
4119
|
-
api: this.api
|
|
4120
|
-
}, this._options));
|
|
4121
|
-
}
|
|
4122
|
-
}, {
|
|
4123
|
-
key: "signAndSubmit",
|
|
4124
|
-
value: function () {
|
|
4125
|
-
var _signAndSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
4126
|
-
var sender, tx;
|
|
4127
|
-
return _regenerator().w(function (_context) {
|
|
4128
|
-
while (1) switch (_context.n) {
|
|
4129
|
-
case 0:
|
|
4130
|
-
sender = this._options.senderSource;
|
|
4131
|
-
assertSenderSource(sender);
|
|
4132
|
-
if (!isViemSigner(sender)) {
|
|
4133
|
-
_context.n = 1;
|
|
4134
|
-
break;
|
|
4135
|
-
}
|
|
4136
|
-
throw new UnsupportedOperationError('Asset claim with a viem WalletClient signer is not supported.');
|
|
4137
|
-
case 1:
|
|
4138
|
-
_context.n = 2;
|
|
4139
|
-
return claimAssets(_objectSpread2({
|
|
4140
|
-
api: this.api
|
|
4141
|
-
}, this._options));
|
|
4142
|
-
case 2:
|
|
4143
|
-
tx = _context.v;
|
|
4144
|
-
return _context.a(2, this.api.signAndSubmit(tx, sender));
|
|
4145
|
-
}
|
|
4146
|
-
}, _callee, this);
|
|
4147
|
-
}));
|
|
4148
|
-
function signAndSubmit() {
|
|
4149
|
-
return _signAndSubmit.apply(this, arguments);
|
|
4150
|
-
}
|
|
4151
|
-
return signAndSubmit;
|
|
4152
|
-
}()
|
|
4153
|
-
/**
|
|
4154
|
-
* Returns the API instance used by the builder.
|
|
4155
|
-
*
|
|
4156
|
-
* @returns The API instance.
|
|
4157
|
-
*/
|
|
4158
|
-
}, {
|
|
4159
|
-
key: "getApi",
|
|
4160
|
-
value: function getApi() {
|
|
4161
|
-
return this.api.api;
|
|
4162
|
-
}
|
|
4163
|
-
/**
|
|
4164
|
-
* Disconnects the API.
|
|
4165
|
-
*
|
|
4166
|
-
* @returns A Promise that resolves when the API is disconnected.
|
|
4167
|
-
*/
|
|
4168
|
-
}, {
|
|
4169
|
-
key: "disconnect",
|
|
4170
|
-
value: function disconnect() {
|
|
4171
|
-
return this.api.disconnect(true);
|
|
4172
|
-
}
|
|
4173
|
-
}]);
|
|
4174
|
-
}();
|
|
4175
|
-
|
|
4176
|
-
var evmExtension;
|
|
4177
|
-
var registerEvmExtension = function registerEvmExtension(extension) {
|
|
4178
|
-
evmExtension = extension;
|
|
4179
|
-
};
|
|
4180
|
-
var getEvmExtensionOrThrow = function getEvmExtensionOrThrow() {
|
|
4181
|
-
assertExtensionInstalled(evmExtension, 'EVM', '@paraspell/evm', 'using an EVM origin');
|
|
4182
|
-
return evmExtension;
|
|
4183
|
-
};
|
|
4184
|
-
|
|
4185
|
-
var evmSnowbridgeExtension;
|
|
4186
|
-
var registerEvmSnowbridgeExtension = function registerEvmSnowbridgeExtension(extension) {
|
|
4187
|
-
evmSnowbridgeExtension = extension;
|
|
4188
|
-
};
|
|
4189
|
-
var getEvmSnowbridgeExtensionOrThrow = function getEvmSnowbridgeExtensionOrThrow() {
|
|
4190
|
-
assertExtensionInstalled(evmSnowbridgeExtension, 'EVM Snowbridge', '@paraspell/evm-snowbridge', 'using Ethereum as an origin');
|
|
4191
|
-
return evmSnowbridgeExtension;
|
|
4192
|
-
};
|
|
4193
|
-
|
|
4194
|
-
var swapExtension;
|
|
4195
|
-
var registerSwapExtension = function registerSwapExtension(extension) {
|
|
4196
|
-
swapExtension = extension;
|
|
4197
|
-
};
|
|
4198
|
-
var getSwapExtensionOrThrow = function getSwapExtensionOrThrow() {
|
|
4199
|
-
assertExtensionInstalled(swapExtension, 'swap', '@paraspell/swap', 'using swap features');
|
|
4200
|
-
return swapExtension;
|
|
4201
|
-
};
|
|
4202
|
-
|
|
4203
|
-
var API_TYPES = ['PAPI', 'PJS', 'DEDOT'];
|
|
4204
|
-
|
|
4205
|
-
/**
|
|
4206
|
-
* The options for the batch builder.
|
|
4207
|
-
*/
|
|
4208
|
-
var BatchMode;
|
|
4209
|
-
(function (BatchMode) {
|
|
4210
|
-
/**
|
|
4211
|
-
* Does not commit if one of the calls in the batch fails.
|
|
3986
|
+
* Does not commit if one of the calls in the batch fails.
|
|
4212
3987
|
*/
|
|
4213
3988
|
BatchMode["BATCH_ALL"] = "BATCH_ALL";
|
|
4214
3989
|
/**
|
|
@@ -4519,7 +4294,7 @@ var buildDryRun = function buildDryRun(api, tx, options, bypassOptions) {
|
|
|
4519
4294
|
};
|
|
4520
4295
|
|
|
4521
4296
|
/**
|
|
4522
|
-
* A builder class for constructing Para-to-Para, Para-to-Relay, Relay-to-Para transactions
|
|
4297
|
+
* A builder class for constructing Para-to-Para, Para-to-Relay, Relay-to-Para transactions.
|
|
4523
4298
|
*/
|
|
4524
4299
|
var GeneralBuilder = /*#__PURE__*/function () {
|
|
4525
4300
|
function GeneralBuilder(api, batchManager, options) {
|
|
@@ -4556,20 +4331,6 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
4556
4331
|
paraIdTo: paraIdTo
|
|
4557
4332
|
}));
|
|
4558
4333
|
}
|
|
4559
|
-
/**
|
|
4560
|
-
* Initiates the process to claim assets from a specified chain.
|
|
4561
|
-
*
|
|
4562
|
-
* @deprecated Asset claim functionality is deprecated and will be removed in v14.
|
|
4563
|
-
* @param chain - The chain from which to claim assets.
|
|
4564
|
-
* @returns An instance of Builder
|
|
4565
|
-
*/
|
|
4566
|
-
}, {
|
|
4567
|
-
key: "claimFrom",
|
|
4568
|
-
value: function claimFrom(chain) {
|
|
4569
|
-
return new AssetClaimBuilder(this.api, {
|
|
4570
|
-
chain: chain
|
|
4571
|
-
});
|
|
4572
|
-
}
|
|
4573
4334
|
/**
|
|
4574
4335
|
* Specifies the currency to be used in the transaction. Symbol, ID, location or multi-asset.
|
|
4575
4336
|
*
|
|
@@ -5006,11 +4767,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
5006
4767
|
});
|
|
5007
4768
|
case 1:
|
|
5008
4769
|
dryRunResult = _context8.v;
|
|
5009
|
-
if (!dryRunResult.
|
|
4770
|
+
if (!dryRunResult.dryRunError) {
|
|
5010
4771
|
_context8.n = 2;
|
|
5011
4772
|
break;
|
|
5012
4773
|
}
|
|
5013
|
-
throw new DryRunFailedError(dryRunResult.
|
|
4774
|
+
throw new DryRunFailedError(dryRunResult.dryRunError, 'XCM format check failed.');
|
|
5014
4775
|
case 2:
|
|
5015
4776
|
return _context8.a(2);
|
|
5016
4777
|
}
|
|
@@ -6104,10 +5865,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
6104
5865
|
break;
|
|
6105
5866
|
}
|
|
6106
5867
|
return _context3.a(2, {
|
|
6107
|
-
dryRunError: dryRunResult.
|
|
6108
|
-
dryRunSubError: dryRunResult.failureSubReason,
|
|
6109
|
-
dryRunErrorIndex: dryRunResult.failureIndex,
|
|
6110
|
-
dryRunErrorInstruction: dryRunResult.failureInstruction
|
|
5868
|
+
dryRunError: dryRunResult.dryRunError
|
|
6111
5869
|
});
|
|
6112
5870
|
case 5:
|
|
6113
5871
|
_context3.n = 6;
|
|
@@ -6117,10 +5875,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
6117
5875
|
return _context3.a(2, {
|
|
6118
5876
|
fee: _fee2,
|
|
6119
5877
|
feeType: 'paymentInfo',
|
|
6120
|
-
dryRunError: dryRunResult.
|
|
6121
|
-
dryRunSubError: dryRunResult.failureSubReason,
|
|
6122
|
-
dryRunErrorIndex: dryRunResult.failureIndex,
|
|
6123
|
-
dryRunErrorInstruction: dryRunResult.failureInstruction,
|
|
5878
|
+
dryRunError: dryRunResult.dryRunError,
|
|
6124
5879
|
sufficient: false,
|
|
6125
5880
|
asset: currentAsset
|
|
6126
5881
|
});
|
|
@@ -6142,41 +5897,32 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
6142
5897
|
};
|
|
6143
5898
|
}();
|
|
6144
5899
|
|
|
6145
|
-
var
|
|
6146
|
-
var
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
};
|
|
6157
|
-
};
|
|
6158
|
-
var getFailureInfo$1 = function getFailureInfo(result) {
|
|
6159
|
-
var orderedChecks = [{
|
|
6160
|
-
chain: 'origin',
|
|
6161
|
-
chainResult: result.origin
|
|
6162
|
-
}, {
|
|
6163
|
-
chain: 'destination',
|
|
6164
|
-
chainResult: result.destination
|
|
6165
|
-
}].concat(_toConsumableArray(result.hops.map(function (hop) {
|
|
6166
|
-
return {
|
|
6167
|
-
chain: hop.chain,
|
|
6168
|
-
chainResult: hop.result
|
|
6169
|
-
};
|
|
5900
|
+
var getDryRunError = function getDryRunError(_ref) {
|
|
5901
|
+
var origin = _ref.origin,
|
|
5902
|
+
destination = _ref.destination,
|
|
5903
|
+
hops = _ref.hops;
|
|
5904
|
+
var toCandidate = function toCandidate(chainKind, entry) {
|
|
5905
|
+
return _objectSpread2({
|
|
5906
|
+
chainKind: chainKind
|
|
5907
|
+
}, entry);
|
|
5908
|
+
};
|
|
5909
|
+
var candidates = [toCandidate('origin', origin)].concat(_toConsumableArray(destination ? [toCandidate('destination', destination)] : []), _toConsumableArray(hops.map(function (hop) {
|
|
5910
|
+
return toCandidate('hop', hop);
|
|
6170
5911
|
})));
|
|
6171
|
-
var _iterator = _createForOfIteratorHelper(
|
|
5912
|
+
var _iterator = _createForOfIteratorHelper(candidates),
|
|
6172
5913
|
_step;
|
|
6173
5914
|
try {
|
|
6174
5915
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5916
|
+
var _result$dryRunError;
|
|
6175
5917
|
var _step$value = _step.value,
|
|
5918
|
+
chainKind = _step$value.chainKind,
|
|
6176
5919
|
chain = _step$value.chain,
|
|
6177
|
-
|
|
6178
|
-
if (
|
|
6179
|
-
return
|
|
5920
|
+
result = _step$value.result;
|
|
5921
|
+
if ((_result$dryRunError = result.dryRunError) !== null && _result$dryRunError !== void 0 && _result$dryRunError.reason) {
|
|
5922
|
+
return _objectSpread2({
|
|
5923
|
+
chainKind: chainKind,
|
|
5924
|
+
chain: chain
|
|
5925
|
+
}, result.dryRunError);
|
|
6180
5926
|
}
|
|
6181
5927
|
}
|
|
6182
5928
|
} catch (err) {
|
|
@@ -6184,7 +5930,7 @@ var getFailureInfo$1 = function getFailureInfo(result) {
|
|
|
6184
5930
|
} finally {
|
|
6185
5931
|
_iterator.f();
|
|
6186
5932
|
}
|
|
6187
|
-
return
|
|
5933
|
+
return undefined;
|
|
6188
5934
|
};
|
|
6189
5935
|
|
|
6190
5936
|
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
@@ -6234,1013 +5980,97 @@ var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
|
6234
5980
|
};
|
|
6235
5981
|
}();
|
|
6236
5982
|
|
|
6237
|
-
var
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
{
|
|
6241
|
-
internalType: "address",
|
|
6242
|
-
name: "currencyAddress",
|
|
6243
|
-
type: "address"
|
|
6244
|
-
},
|
|
6245
|
-
{
|
|
6246
|
-
internalType: "uint256",
|
|
6247
|
-
name: "amount",
|
|
6248
|
-
type: "uint256"
|
|
6249
|
-
},
|
|
6250
|
-
{
|
|
6251
|
-
components: [
|
|
6252
|
-
{
|
|
6253
|
-
internalType: "uint8",
|
|
6254
|
-
name: "parents",
|
|
6255
|
-
type: "uint8"
|
|
6256
|
-
},
|
|
6257
|
-
{
|
|
6258
|
-
internalType: "bytes[]",
|
|
6259
|
-
name: "interior",
|
|
6260
|
-
type: "bytes[]"
|
|
6261
|
-
}
|
|
6262
|
-
],
|
|
6263
|
-
internalType: "struct Xtokens.Multilocation",
|
|
6264
|
-
name: "destination",
|
|
6265
|
-
type: "tuple"
|
|
6266
|
-
},
|
|
6267
|
-
{
|
|
6268
|
-
internalType: "uint64",
|
|
6269
|
-
name: "weight",
|
|
6270
|
-
type: "uint64"
|
|
6271
|
-
}
|
|
6272
|
-
],
|
|
6273
|
-
name: "transfer",
|
|
6274
|
-
outputs: [
|
|
6275
|
-
],
|
|
6276
|
-
stateMutability: "nonpayable",
|
|
6277
|
-
type: "function"
|
|
6278
|
-
},
|
|
6279
|
-
{
|
|
6280
|
-
inputs: [
|
|
6281
|
-
{
|
|
6282
|
-
components: [
|
|
6283
|
-
{
|
|
6284
|
-
internalType: "address",
|
|
6285
|
-
name: "currencyAddress",
|
|
6286
|
-
type: "address"
|
|
6287
|
-
},
|
|
6288
|
-
{
|
|
6289
|
-
internalType: "uint256",
|
|
6290
|
-
name: "amount",
|
|
6291
|
-
type: "uint256"
|
|
6292
|
-
}
|
|
6293
|
-
],
|
|
6294
|
-
internalType: "struct Xtokens.Currency[]",
|
|
6295
|
-
name: "currencies",
|
|
6296
|
-
type: "tuple[]"
|
|
6297
|
-
},
|
|
6298
|
-
{
|
|
6299
|
-
internalType: "uint32",
|
|
6300
|
-
name: "feeItem",
|
|
6301
|
-
type: "uint32"
|
|
6302
|
-
},
|
|
6303
|
-
{
|
|
6304
|
-
components: [
|
|
6305
|
-
{
|
|
6306
|
-
internalType: "uint8",
|
|
6307
|
-
name: "parents",
|
|
6308
|
-
type: "uint8"
|
|
6309
|
-
},
|
|
6310
|
-
{
|
|
6311
|
-
internalType: "bytes[]",
|
|
6312
|
-
name: "interior",
|
|
6313
|
-
type: "bytes[]"
|
|
6314
|
-
}
|
|
6315
|
-
],
|
|
6316
|
-
internalType: "struct Xtokens.Multilocation",
|
|
6317
|
-
name: "destination",
|
|
6318
|
-
type: "tuple"
|
|
6319
|
-
},
|
|
6320
|
-
{
|
|
6321
|
-
internalType: "uint64",
|
|
6322
|
-
name: "weight",
|
|
6323
|
-
type: "uint64"
|
|
6324
|
-
}
|
|
6325
|
-
],
|
|
6326
|
-
name: "transferMultiCurrencies",
|
|
6327
|
-
outputs: [
|
|
6328
|
-
],
|
|
6329
|
-
stateMutability: "nonpayable",
|
|
6330
|
-
type: "function"
|
|
6331
|
-
}
|
|
6332
|
-
];
|
|
6333
|
-
|
|
6334
|
-
// Partially inspired by Moonbeam XCM-SDK
|
|
6335
|
-
// https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts#L126
|
|
6336
|
-
var getDestinationLocation = function getDestinationLocation(api, address, destination) {
|
|
6337
|
-
var _getAssetsObject = getAssetsObject(destination),
|
|
6338
|
-
isEVM = _getAssetsObject.isEVM;
|
|
6339
|
-
var accountType = isEVM ? '03' : '01';
|
|
6340
|
-
var addressHex = api.accountToHex(address, false);
|
|
6341
|
-
var acc = "0x".concat(accountType).concat(addressHex, "00");
|
|
6342
|
-
var _getChainConfig = getChainConfig(destination),
|
|
6343
|
-
paraId = _getChainConfig.paraId;
|
|
6344
|
-
return [1, paraId ? ["0x0000000".concat(paraId.toString(16)), acc] : [acc]];
|
|
6345
|
-
};
|
|
6346
|
-
|
|
6347
|
-
var abi$1 = [{
|
|
6348
|
-
inputs: [{
|
|
6349
|
-
internalType: 'address',
|
|
6350
|
-
name: 'recipient_',
|
|
6351
|
-
type: 'address'
|
|
6352
|
-
}, {
|
|
6353
|
-
internalType: 'uint256',
|
|
6354
|
-
name: 'amount_',
|
|
6355
|
-
type: 'uint256'
|
|
6356
|
-
}],
|
|
6357
|
-
name: 'transfer',
|
|
6358
|
-
outputs: [{
|
|
6359
|
-
internalType: 'bool',
|
|
6360
|
-
name: '',
|
|
6361
|
-
type: 'bool'
|
|
6362
|
-
}],
|
|
6363
|
-
stateMutability: 'nonpayable',
|
|
6364
|
-
type: 'function'
|
|
6365
|
-
}];
|
|
6366
|
-
var transferMoonbeamLocal = /*#__PURE__*/function () {
|
|
6367
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(client, assetInfo, _ref) {
|
|
6368
|
-
var signer, recipient, contract;
|
|
6369
|
-
return _regenerator().w(function (_context) {
|
|
6370
|
-
while (1) switch (_context.n) {
|
|
6371
|
-
case 0:
|
|
6372
|
-
signer = _ref.signer, recipient = _ref.recipient;
|
|
6373
|
-
assertHasId(assetInfo);
|
|
6374
|
-
contract = getContract({
|
|
6375
|
-
abi: abi$1,
|
|
6376
|
-
address: assetInfo.assetId,
|
|
6377
|
-
client: {
|
|
6378
|
-
"public": client,
|
|
6379
|
-
wallet: signer
|
|
6380
|
-
}
|
|
6381
|
-
});
|
|
6382
|
-
return _context.a(2, contract.write.transfer([recipient, assetInfo.amount]));
|
|
6383
|
-
}
|
|
6384
|
-
}, _callee);
|
|
6385
|
-
}));
|
|
6386
|
-
return function transferMoonbeamLocal(_x, _x2, _x3) {
|
|
6387
|
-
return _ref2.apply(this, arguments);
|
|
6388
|
-
};
|
|
6389
|
-
}();
|
|
6390
|
-
|
|
6391
|
-
var U_64_MAX = 18446744073709551615n;
|
|
6392
|
-
var CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000804';
|
|
6393
|
-
var NATIVE_ASSET_ID = '0x0000000000000000000000000000000000000802';
|
|
6394
|
-
// Partially inspired by Moonbeam XCM-SDK
|
|
6395
|
-
var transferMoonbeamEvm = /*#__PURE__*/function () {
|
|
6396
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
6397
|
-
var _usdtAsset$assetId;
|
|
6398
|
-
var api, from, to, signer, recipient, currency, foundAsset, amount, client, contract, asset, destLocation, weight, createTx, multiCurrencySymbols, useMultiAssets, usdtAsset, tx, _t;
|
|
5983
|
+
var traverseXcmHops = /*#__PURE__*/function () {
|
|
5984
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
|
|
5985
|
+
var api, origin, destination, asset, initialForwardedXcms, initialDestParaId, swapConfig, processHop, shouldContinue, extractNextHopData, currentOrigin, forwardedXcms, nextParaId, currentAsset, hasPassedExchange, hops, destinationResult, nextChain, hopApi, isDestination, hopResult, _extractNextHopData, newXcms, destParaId;
|
|
6399
5986
|
return _regenerator().w(function (_context) {
|
|
6400
|
-
while (1) switch (_context.n) {
|
|
5987
|
+
while (1) switch (_context.p = _context.n) {
|
|
6401
5988
|
case 0:
|
|
6402
|
-
api =
|
|
6403
|
-
|
|
6404
|
-
|
|
5989
|
+
api = config.api, origin = config.origin, destination = config.destination, asset = config.asset, initialForwardedXcms = config.initialForwardedXcms, initialDestParaId = config.initialDestParaId, swapConfig = config.swapConfig, processHop = config.processHop, shouldContinue = config.shouldContinue, extractNextHopData = config.extractNextHopData;
|
|
5990
|
+
currentOrigin = origin;
|
|
5991
|
+
forwardedXcms = initialForwardedXcms;
|
|
5992
|
+
nextParaId = initialDestParaId;
|
|
5993
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? api.findAssetInfoOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo) : asset;
|
|
5994
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
5995
|
+
hops = [];
|
|
5996
|
+
case 1:
|
|
5997
|
+
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length > 0 && forwardedXcms[1].length > 0 && ('disconnect' in api.api ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
5998
|
+
_context.n = 10;
|
|
6405
5999
|
break;
|
|
6406
6000
|
}
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
if (!('location' in currency && isOverrideLocationSpecifier(currency.location))) {
|
|
6001
|
+
nextChain = getTSubstrateChain(nextParaId, api.getRelayChainOf(origin));
|
|
6002
|
+
if (nextChain) {
|
|
6410
6003
|
_context.n = 2;
|
|
6411
6004
|
break;
|
|
6412
6005
|
}
|
|
6413
|
-
throw new
|
|
6006
|
+
throw new RoutingResolutionError("Unable to find TChain for paraId ".concat(nextParaId));
|
|
6414
6007
|
case 2:
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6008
|
+
hopApi = api.clone();
|
|
6009
|
+
_context.p = 3;
|
|
6010
|
+
_context.n = 4;
|
|
6011
|
+
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
6012
|
+
case 4:
|
|
6013
|
+
// true if this hop should be treated as the destination
|
|
6014
|
+
// - normally when nextChain === destination
|
|
6015
|
+
// - but if swap is required, only after (or on) the exchange hop
|
|
6016
|
+
isDestination = nextChain === destination && (!swapConfig || hasPassedExchange || nextChain === swapConfig.exchangeChain);
|
|
6017
|
+
_context.n = 5;
|
|
6018
|
+
return processHop({
|
|
6019
|
+
api: hopApi,
|
|
6020
|
+
currentChain: nextChain,
|
|
6021
|
+
currentOrigin: currentOrigin,
|
|
6022
|
+
currentAsset: currentAsset,
|
|
6023
|
+
forwardedXcms: forwardedXcms,
|
|
6024
|
+
hasPassedExchange: hasPassedExchange,
|
|
6025
|
+
isDestination: isDestination
|
|
6420
6026
|
});
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6027
|
+
case 5:
|
|
6028
|
+
hopResult = _context.v;
|
|
6029
|
+
if (!isDestination) {
|
|
6030
|
+
hops.push({
|
|
6031
|
+
chain: nextChain,
|
|
6032
|
+
result: hopResult
|
|
6033
|
+
});
|
|
6424
6034
|
}
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
}), options));
|
|
6428
|
-
case 3:
|
|
6429
|
-
contract = getContract({
|
|
6430
|
-
abi: abi$2,
|
|
6431
|
-
address: CONTRACT_ADDRESS,
|
|
6432
|
-
client: {
|
|
6433
|
-
"public": client,
|
|
6434
|
-
wallet: signer
|
|
6435
|
-
}
|
|
6436
|
-
});
|
|
6437
|
-
if (!(foundAsset.symbol === getNativeAssetSymbol(from))) {
|
|
6438
|
-
_context.n = 4;
|
|
6439
|
-
break;
|
|
6035
|
+
if (isDestination) {
|
|
6036
|
+
destinationResult = hopResult;
|
|
6440
6037
|
}
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
break;
|
|
6444
|
-
case 4:
|
|
6445
|
-
if (!(foundAsset.assetId === undefined)) {
|
|
6446
|
-
_context.n = 5;
|
|
6038
|
+
if (shouldContinue(hopResult)) {
|
|
6039
|
+
_context.n = 6;
|
|
6447
6040
|
break;
|
|
6448
6041
|
}
|
|
6449
|
-
|
|
6450
|
-
case 5:
|
|
6451
|
-
asset = formatAssetIdToERC20(foundAsset.assetId);
|
|
6042
|
+
return _context.a(3, 10);
|
|
6452
6043
|
case 6:
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
return contract.write[func](args);
|
|
6458
|
-
};
|
|
6459
|
-
multiCurrencySymbols = ['xcPINK', 'xcDED', 'xcSTINK', 'xcWIFD', 'xcNCTR'];
|
|
6460
|
-
useMultiAssets = from === 'Moonbeam' && to === 'AssetHubPolkadot' && multiCurrencySymbols.includes(foundAsset.symbol);
|
|
6461
|
-
usdtAsset = api.findAssetInfoOrThrow(from, {
|
|
6462
|
-
symbol: 'xcUSDT'
|
|
6463
|
-
}, to);
|
|
6464
|
-
assertHasId(usdtAsset);
|
|
6465
|
-
if (!useMultiAssets) {
|
|
6466
|
-
_context.n = 8;
|
|
6467
|
-
break;
|
|
6044
|
+
// Update state for next iteration
|
|
6045
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
6046
|
+
hasPassedExchange = true;
|
|
6047
|
+
currentAsset = api.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
6468
6048
|
}
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6049
|
+
_extractNextHopData = extractNextHopData(hopResult), newXcms = _extractNextHopData.forwardedXcms, destParaId = _extractNextHopData.destParaId;
|
|
6050
|
+
forwardedXcms = newXcms;
|
|
6051
|
+
nextParaId = destParaId;
|
|
6052
|
+
currentOrigin = nextChain;
|
|
6473
6053
|
case 7:
|
|
6474
|
-
|
|
6475
|
-
_context.n =
|
|
6476
|
-
|
|
6054
|
+
_context.p = 7;
|
|
6055
|
+
_context.n = 8;
|
|
6056
|
+
return hopApi.disconnect();
|
|
6477
6057
|
case 8:
|
|
6478
|
-
_context.
|
|
6479
|
-
return createTx('transfer', [asset, amount.toString(), destLocation, weight]);
|
|
6058
|
+
return _context.f(7);
|
|
6480
6059
|
case 9:
|
|
6481
|
-
|
|
6060
|
+
_context.n = 1;
|
|
6061
|
+
break;
|
|
6482
6062
|
case 10:
|
|
6483
|
-
|
|
6484
|
-
|
|
6063
|
+
return _context.a(2, _objectSpread2(_objectSpread2({
|
|
6064
|
+
hops: hops
|
|
6065
|
+
}, destinationResult && {
|
|
6066
|
+
destination: destinationResult
|
|
6067
|
+
}), {}, {
|
|
6068
|
+
lastProcessedChain: currentOrigin
|
|
6069
|
+
}));
|
|
6485
6070
|
}
|
|
6486
|
-
}, _callee);
|
|
6071
|
+
}, _callee, null, [[3,, 7, 9]]);
|
|
6487
6072
|
}));
|
|
6488
|
-
return function
|
|
6489
|
-
return _ref.apply(this, arguments);
|
|
6490
|
-
};
|
|
6491
|
-
}();
|
|
6492
|
-
|
|
6493
|
-
var createX1Payload = function createX1Payload(version, junction) {
|
|
6494
|
-
return version === Version.V3 ? {
|
|
6495
|
-
X1: junction
|
|
6496
|
-
} : {
|
|
6497
|
-
X1: [junction]
|
|
6498
|
-
};
|
|
6499
|
-
};
|
|
6500
|
-
|
|
6501
|
-
var createAccountPayload = function createAccountPayload(api, address) {
|
|
6502
|
-
return isAddress(address) ? {
|
|
6503
|
-
AccountKey20: {
|
|
6504
|
-
key: address
|
|
6505
|
-
}
|
|
6506
|
-
} : {
|
|
6507
|
-
AccountId32: {
|
|
6508
|
-
id: api.accountToHex(address)
|
|
6509
|
-
}
|
|
6510
|
-
};
|
|
6511
|
-
};
|
|
6512
|
-
var createBeneficiaryLocXTokens = function createBeneficiaryLocXTokens(_ref) {
|
|
6513
|
-
var api = _ref.api,
|
|
6514
|
-
recipient = _ref.recipient,
|
|
6515
|
-
origin = _ref.origin,
|
|
6516
|
-
destination = _ref.destination,
|
|
6517
|
-
version = _ref.version,
|
|
6518
|
-
paraId = _ref.paraId;
|
|
6519
|
-
if (isTLocation(recipient)) {
|
|
6520
|
-
return recipient;
|
|
6521
|
-
}
|
|
6522
|
-
var scenario = resolveScenario(origin, destination);
|
|
6523
|
-
var accountPayload = createAccountPayload(api, recipient);
|
|
6524
|
-
if (scenario === 'ParaToRelay') {
|
|
6525
|
-
return {
|
|
6526
|
-
parents: Parents.ONE,
|
|
6527
|
-
interior: createX1Payload(version, {
|
|
6528
|
-
AccountId32: {
|
|
6529
|
-
id: api.accountToHex(recipient)
|
|
6530
|
-
}
|
|
6531
|
-
})
|
|
6532
|
-
};
|
|
6533
|
-
} else if (scenario === 'ParaToPara') {
|
|
6534
|
-
return {
|
|
6535
|
-
parents: Parents.ONE,
|
|
6536
|
-
interior: {
|
|
6537
|
-
X2: [{
|
|
6538
|
-
Parachain: paraId
|
|
6539
|
-
}, accountPayload]
|
|
6540
|
-
}
|
|
6541
|
-
};
|
|
6542
|
-
}
|
|
6543
|
-
return {
|
|
6544
|
-
parents: Parents.ZERO,
|
|
6545
|
-
interior: createX1Payload(version, accountPayload)
|
|
6546
|
-
};
|
|
6547
|
-
};
|
|
6548
|
-
var createBeneficiaryLocation = function createBeneficiaryLocation(_ref2) {
|
|
6549
|
-
var api = _ref2.api,
|
|
6550
|
-
address = _ref2.address,
|
|
6551
|
-
version = _ref2.version;
|
|
6552
|
-
if (isTLocation(address)) return address;
|
|
6553
|
-
var accountPayload = createAccountPayload(api, address);
|
|
6554
|
-
return {
|
|
6555
|
-
parents: Parents.ZERO,
|
|
6556
|
-
interior: createX1Payload(version, accountPayload)
|
|
6557
|
-
};
|
|
6558
|
-
};
|
|
6559
|
-
|
|
6560
|
-
var createDestination = function createDestination(api, version, origin, destination, chainId, junction, parents) {
|
|
6561
|
-
var isLocDestination = isTLocation(destination);
|
|
6562
|
-
var isSubBridge = !isLocDestination && !isExternalChain(destination) && isSubstrateBridge(origin, destination);
|
|
6563
|
-
if (isSubBridge) {
|
|
6564
|
-
return {
|
|
6565
|
-
parents: Parents.TWO,
|
|
6566
|
-
interior: {
|
|
6567
|
-
X2: [{
|
|
6568
|
-
GlobalConsensus: api.getRelayChainOf(destination)
|
|
6569
|
-
}, {
|
|
6570
|
-
Parachain: chainId
|
|
6571
|
-
}]
|
|
6572
|
-
}
|
|
6573
|
-
};
|
|
6574
|
-
}
|
|
6575
|
-
var isSb = !isLocDestination && isSnowbridge(origin, destination);
|
|
6576
|
-
if (isSb) {
|
|
6577
|
-
return {
|
|
6578
|
-
parents: Parents.TWO,
|
|
6579
|
-
interior: {
|
|
6580
|
-
X1: [getEthereumJunction(api, origin)]
|
|
6581
|
-
}
|
|
6582
|
-
};
|
|
6583
|
-
}
|
|
6584
|
-
var scenario = resolveScenario(origin, destination);
|
|
6585
|
-
var parentsResolved = parents !== null && parents !== void 0 ? parents : scenario === 'RelayToPara' ? Parents.ZERO : Parents.ONE;
|
|
6586
|
-
var interior = scenario === 'ParaToRelay' ? 'Here' : createX1Payload(version, junction !== null && junction !== void 0 ? junction : {
|
|
6587
|
-
Parachain: chainId
|
|
6588
|
-
});
|
|
6589
|
-
return isLocDestination ? destination : {
|
|
6590
|
-
parents: parentsResolved,
|
|
6591
|
-
interior: interior
|
|
6592
|
-
};
|
|
6593
|
-
};
|
|
6594
|
-
var createVersionedDestination = function createVersionedDestination(api, version, origin, destination, chainId, junction, parents) {
|
|
6595
|
-
var plainDestination = createDestination(api, version, origin, destination, chainId, junction, parents);
|
|
6596
|
-
return addXcmVersionHeader(plainDestination, version);
|
|
6597
|
-
};
|
|
6598
|
-
|
|
6599
|
-
var getChainLocation = function getChainLocation(chain, destChain, customCtx) {
|
|
6600
|
-
var fromRelay = isRelayChain(chain);
|
|
6601
|
-
var toRelay = isRelayChain(destChain);
|
|
6602
|
-
var parents = fromRelay ? Parents.ZERO : Parents.ONE;
|
|
6603
|
-
var interior = toRelay ? 'Here' : {
|
|
6604
|
-
X1: [{
|
|
6605
|
-
Parachain: getParaIdImpl(destChain, customCtx)
|
|
6606
|
-
}]
|
|
6607
|
-
};
|
|
6608
|
-
return {
|
|
6609
|
-
parents: parents,
|
|
6610
|
-
interior: interior
|
|
6611
|
-
};
|
|
6612
|
-
};
|
|
6613
|
-
|
|
6614
|
-
/**
|
|
6615
|
-
* This function localizes a location by removing the `Parachain` junction
|
|
6616
|
-
* if it exists. The `parents` field is set to `0` either if a `Parachain` was removed
|
|
6617
|
-
* or if the resulting interior is `'Here'` and the chain is a relay chain.
|
|
6618
|
-
*
|
|
6619
|
-
* @param chain - The current chain
|
|
6620
|
-
* @param location - The location to localize
|
|
6621
|
-
* @returns The localized location
|
|
6622
|
-
*/
|
|
6623
|
-
var localizeLocationInner = function localizeLocationInner(chain, location, origin, resolveRelay, resolveParaId) {
|
|
6624
|
-
var _Object$keys$;
|
|
6625
|
-
var targetRelay = isExternalChain(chain) ? undefined : resolveRelay(chain).toLowerCase();
|
|
6626
|
-
var originRelay = origin && !isExternalChain(origin) ? resolveRelay(origin).toLowerCase() : undefined;
|
|
6627
|
-
var locationConsensus = getJunctionValue(location, 'GlobalConsensus');
|
|
6628
|
-
var locationRelay = locationConsensus ? (_Object$keys$ = Object.keys(locationConsensus)[0]) === null || _Object$keys$ === void 0 ? void 0 : _Object$keys$.toLowerCase() : undefined;
|
|
6629
|
-
var ecosystemDiffers = targetRelay && originRelay && originRelay !== targetRelay;
|
|
6630
|
-
var junctions = location.interior === 'Here' ? [] : Object.values(location.interior).flat().filter(function (junction) {
|
|
6631
|
-
return _typeof(junction) === 'object' && junction !== null;
|
|
6632
|
-
});
|
|
6633
|
-
var junctionCount = junctions.length;
|
|
6634
|
-
var isLocationOnTargetRelay = targetRelay !== undefined && locationRelay === targetRelay;
|
|
6635
|
-
// Check if target is an external chain and location's GlobalConsensus matches it
|
|
6636
|
-
var isLocationOnTargetExternal = isExternalChain(chain) && locationRelay === chain.toLowerCase();
|
|
6637
|
-
if (!origin && locationRelay && targetRelay && locationRelay !== targetRelay) {
|
|
6638
|
-
return location;
|
|
6639
|
-
}
|
|
6640
|
-
if (origin && ecosystemDiffers && location.parents === Parents.TWO && originRelay !== undefined && targetRelay !== undefined && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null)) && junctionCount === 1) {
|
|
6641
|
-
return RELAY_LOCATION;
|
|
6642
|
-
}
|
|
6643
|
-
var newInterior = location.interior;
|
|
6644
|
-
var parachainRemoved = false;
|
|
6645
|
-
if (location.interior !== 'Here') {
|
|
6646
|
-
var paraId = resolveParaId(chain);
|
|
6647
|
-
var filteredJunctions = junctions.filter(function (junction) {
|
|
6648
|
-
if ('GlobalConsensus' in junction && (isLocationOnTargetRelay || isLocationOnTargetExternal)) {
|
|
6649
|
-
return false;
|
|
6650
|
-
}
|
|
6651
|
-
if ('Parachain' in junction && (!ecosystemDiffers || isLocationOnTargetRelay)) {
|
|
6652
|
-
var paraJunctionId = getJunctionValue(location, 'Parachain');
|
|
6653
|
-
if (paraJunctionId === paraId) {
|
|
6654
|
-
parachainRemoved = true;
|
|
6655
|
-
return false;
|
|
6656
|
-
}
|
|
6657
|
-
}
|
|
6658
|
-
return true;
|
|
6659
|
-
});
|
|
6660
|
-
if (filteredJunctions.length === 0) {
|
|
6661
|
-
newInterior = 'Here';
|
|
6662
|
-
} else {
|
|
6663
|
-
newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
|
|
6664
|
-
}
|
|
6665
|
-
}
|
|
6666
|
-
var isOriginRelayHere = deepEqual(location, RELAY_LOCATION);
|
|
6667
|
-
var hasGlobalConsensus = hasJunction(location, 'GlobalConsensus');
|
|
6668
|
-
if (origin && isExternalChain(chain) && originRelay !== undefined && isOriginRelayHere && !hasGlobalConsensus) {
|
|
6669
|
-
return {
|
|
6670
|
-
parents: Parents.ONE,
|
|
6671
|
-
interior: {
|
|
6672
|
-
X1: [{
|
|
6673
|
-
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
6674
|
-
}]
|
|
6675
|
-
}
|
|
6676
|
-
};
|
|
6677
|
-
}
|
|
6678
|
-
if (isExternalChain(chain) && location.parents === Parents.TWO && RELAYCHAINS.some(function (relay) {
|
|
6679
|
-
return deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, relay.toLowerCase(), null));
|
|
6680
|
-
})) {
|
|
6681
|
-
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
6682
|
-
parents: Parents.ONE
|
|
6683
|
-
});
|
|
6684
|
-
}
|
|
6685
|
-
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus && originRelay !== undefined) {
|
|
6686
|
-
return {
|
|
6687
|
-
parents: Parents.TWO,
|
|
6688
|
-
interior: {
|
|
6689
|
-
X2: [{
|
|
6690
|
-
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
6691
|
-
}, {
|
|
6692
|
-
Parachain: resolveParaId(origin)
|
|
6693
|
-
}]
|
|
6694
|
-
}
|
|
6695
|
-
};
|
|
6696
|
-
}
|
|
6697
|
-
if (origin && ecosystemDiffers && newInterior !== 'Here' && !hasGlobalConsensus && originRelay !== undefined) {
|
|
6698
|
-
var _junctions = Object.values(newInterior).flat().filter(function (junction) {
|
|
6699
|
-
return _typeof(junction) === 'object' && junction !== null;
|
|
6700
|
-
});
|
|
6701
|
-
var updatedJunctions = [{
|
|
6702
|
-
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
6703
|
-
}].concat(_toConsumableArray(_junctions));
|
|
6704
|
-
return {
|
|
6705
|
-
parents: Parents.TWO,
|
|
6706
|
-
interior: _defineProperty({}, "X".concat(updatedJunctions.length), updatedJunctions)
|
|
6707
|
-
};
|
|
6708
|
-
}
|
|
6709
|
-
var shouldSetParentsToZero = parachainRemoved || newInterior === 'Here' && isRelayChain(chain) || isLocationOnTargetExternal;
|
|
6710
|
-
return {
|
|
6711
|
-
parents: shouldSetParentsToZero ? Parents.ZERO : location.parents,
|
|
6712
|
-
interior: newInterior
|
|
6713
|
-
};
|
|
6714
|
-
};
|
|
6715
|
-
var localizeLocation = function localizeLocation(chain, location, origin) {
|
|
6716
|
-
return localizeLocationInner(chain, location, origin, function (c) {
|
|
6717
|
-
return getRelayChainOf(c);
|
|
6718
|
-
}, function (c) {
|
|
6719
|
-
return getParaId(c);
|
|
6720
|
-
});
|
|
6721
|
-
};
|
|
6722
|
-
var localizeLocationImpl = function localizeLocationImpl(api, chain, location, origin) {
|
|
6723
|
-
return localizeLocationInner(chain, location, origin, function (c) {
|
|
6724
|
-
return getRelayChainOfImpl(api, c);
|
|
6725
|
-
}, function (c) {
|
|
6726
|
-
return getParaIdImpl(c, api._customCtx);
|
|
6727
|
-
});
|
|
6728
|
-
};
|
|
6729
|
-
|
|
6730
|
-
var reverseTransformLocation = function reverseTransformLocation(location) {
|
|
6731
|
-
var parachainJunction = {
|
|
6732
|
-
Parachain: 1000
|
|
6733
|
-
};
|
|
6734
|
-
var alreadyHasP1000 = location.interior !== 'Here' && Object.values(location.interior).flat().some(function (j) {
|
|
6735
|
-
return _typeof(j) === 'object' && j !== null && 'Parachain' in j && j.Parachain === 1000;
|
|
6736
|
-
});
|
|
6737
|
-
if (alreadyHasP1000) {
|
|
6738
|
-
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
6739
|
-
parents: Parents.ONE
|
|
6740
|
-
});
|
|
6741
|
-
}
|
|
6742
|
-
var existingJunctions = location.interior === 'Here' ? [] // no other junctions
|
|
6743
|
-
: Object.values(location.interior).flat();
|
|
6744
|
-
var allJunctions = [parachainJunction].concat(_toConsumableArray(existingJunctions));
|
|
6745
|
-
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
6746
|
-
parents: Parents.ONE,
|
|
6747
|
-
interior: _defineProperty({}, "X".concat(allJunctions.length), allJunctions)
|
|
6748
|
-
});
|
|
6749
|
-
};
|
|
6750
|
-
|
|
6751
|
-
var createMainInstruction = function createMainInstruction(api, origin, asset, ethAsset, recipient, messageId) {
|
|
6752
|
-
assertHasId(ethAsset);
|
|
6753
|
-
var interiorSb = ethAsset.symbol === 'ETH' ? {
|
|
6754
|
-
Here: null
|
|
6755
|
-
} : {
|
|
6756
|
-
X1: [{
|
|
6757
|
-
AccountKey20: {
|
|
6758
|
-
network: null,
|
|
6759
|
-
key: ethAsset.assetId
|
|
6760
|
-
}
|
|
6761
|
-
}]
|
|
6762
|
-
};
|
|
6763
|
-
var isAssetNativeToPolkadot = !deepEqual(getJunctionValue(asset.location, 'GlobalConsensus'), {
|
|
6764
|
-
Ethereum: {
|
|
6765
|
-
chainId: 1
|
|
6766
|
-
}
|
|
6767
|
-
// MYTH needs to use InitiateReserveWithdraw
|
|
6768
|
-
}) && origin !== 'Mythos';
|
|
6769
|
-
var beneficiary = {
|
|
6770
|
-
parents: Parents.ZERO,
|
|
6771
|
-
interior: {
|
|
6772
|
-
X1: [{
|
|
6773
|
-
AccountKey20: {
|
|
6774
|
-
network: null,
|
|
6775
|
-
key: recipient
|
|
6776
|
-
}
|
|
6777
|
-
}]
|
|
6778
|
-
}
|
|
6779
|
-
};
|
|
6780
|
-
var makeBuyExecution = function makeBuyExecution(feesId) {
|
|
6781
|
-
return {
|
|
6782
|
-
BuyExecution: {
|
|
6783
|
-
fees: {
|
|
6784
|
-
id: feesId,
|
|
6785
|
-
fun: {
|
|
6786
|
-
Fungible: 1n
|
|
6787
|
-
}
|
|
6788
|
-
},
|
|
6789
|
-
weight_limit: 'Unlimited'
|
|
6790
|
-
}
|
|
6791
|
-
};
|
|
6792
|
-
};
|
|
6793
|
-
var makeDepositAsset = function makeDepositAsset() {
|
|
6794
|
-
return {
|
|
6795
|
-
DepositAsset: {
|
|
6796
|
-
assets: {
|
|
6797
|
-
Wild: {
|
|
6798
|
-
AllCounted: 1
|
|
6799
|
-
}
|
|
6800
|
-
},
|
|
6801
|
-
beneficiary: beneficiary
|
|
6802
|
-
}
|
|
6803
|
-
};
|
|
6804
|
-
};
|
|
6805
|
-
var commonXcm = function commonXcm(feesId) {
|
|
6806
|
-
return [makeBuyExecution(feesId), makeDepositAsset(), {
|
|
6807
|
-
SetTopic: messageId
|
|
6808
|
-
}];
|
|
6809
|
-
};
|
|
6810
|
-
var ethJunction = getEthereumJunction(api, origin);
|
|
6811
|
-
if (isAssetNativeToPolkadot) {
|
|
6812
|
-
var assetEcosystem = RELAYCHAINS.find(function (chain) {
|
|
6813
|
-
return asset.symbol.includes(getNativeAssetSymbol(chain));
|
|
6814
|
-
});
|
|
6815
|
-
if (!assetEcosystem) throw new UnsupportedOperationError('Unsupported native polkadot asset');
|
|
6816
|
-
return {
|
|
6817
|
-
DepositReserveAsset: {
|
|
6818
|
-
assets: {
|
|
6819
|
-
Wild: {
|
|
6820
|
-
AllOf: {
|
|
6821
|
-
id: asset.location,
|
|
6822
|
-
fun: 'Fungible'
|
|
6823
|
-
}
|
|
6824
|
-
}
|
|
6825
|
-
},
|
|
6826
|
-
dest: {
|
|
6827
|
-
parents: Parents.TWO,
|
|
6828
|
-
interior: {
|
|
6829
|
-
X1: [ethJunction]
|
|
6830
|
-
}
|
|
6831
|
-
},
|
|
6832
|
-
xcm: commonXcm({
|
|
6833
|
-
parents: Parents.ONE,
|
|
6834
|
-
interior: {
|
|
6835
|
-
X1: [{
|
|
6836
|
-
GlobalConsensus: _defineProperty({}, assetEcosystem.toLowerCase(), null)
|
|
6837
|
-
}]
|
|
6838
|
-
}
|
|
6839
|
-
})
|
|
6840
|
-
}
|
|
6841
|
-
};
|
|
6842
|
-
}
|
|
6843
|
-
return {
|
|
6844
|
-
InitiateReserveWithdraw: {
|
|
6845
|
-
assets: {
|
|
6846
|
-
Wild: {
|
|
6847
|
-
AllOf: {
|
|
6848
|
-
id: ethAsset.location,
|
|
6849
|
-
fun: 'Fungible'
|
|
6850
|
-
}
|
|
6851
|
-
}
|
|
6852
|
-
},
|
|
6853
|
-
reserve: {
|
|
6854
|
-
parents: Parents.TWO,
|
|
6855
|
-
interior: {
|
|
6856
|
-
X1: [ethJunction]
|
|
6857
|
-
}
|
|
6858
|
-
},
|
|
6859
|
-
xcm: commonXcm({
|
|
6860
|
-
parents: Parents.ZERO,
|
|
6861
|
-
interior: interiorSb
|
|
6862
|
-
})
|
|
6863
|
-
}
|
|
6864
|
-
};
|
|
6865
|
-
};
|
|
6866
|
-
var createEthereumBridgeInstructions = function createEthereumBridgeInstructions(_ref, origin, messageId, ethAsset) {
|
|
6867
|
-
var api = _ref.api,
|
|
6868
|
-
sender = _ref.sender,
|
|
6869
|
-
recipient = _ref.recipient,
|
|
6870
|
-
assetInfo = _ref.assetInfo,
|
|
6871
|
-
ahAddress = _ref.ahAddress,
|
|
6872
|
-
version = _ref.version;
|
|
6873
|
-
assertSender(sender);
|
|
6874
|
-
if (isChainEvm(origin) && !ahAddress) {
|
|
6875
|
-
throw new MissingParameterError('ahAddress');
|
|
6876
|
-
}
|
|
6877
|
-
return [{
|
|
6878
|
-
SetAppendix: origin === 'Mythos' ? [] : [{
|
|
6879
|
-
DepositAsset: {
|
|
6880
|
-
assets: {
|
|
6881
|
-
Wild: 'All'
|
|
6882
|
-
},
|
|
6883
|
-
beneficiary: createBeneficiaryLocation({
|
|
6884
|
-
api: api,
|
|
6885
|
-
address: isChainEvm(origin) ? ahAddress : sender,
|
|
6886
|
-
version: version
|
|
6887
|
-
})
|
|
6888
|
-
}
|
|
6889
|
-
}]
|
|
6890
|
-
}, createMainInstruction(api, origin, assetInfo, ethAsset, recipient, messageId), {
|
|
6891
|
-
SetTopic: messageId
|
|
6892
|
-
}];
|
|
6893
|
-
};
|
|
6894
|
-
var createCustomXcmOnDest = function createCustomXcmOnDest(options, origin, messageId, ethAsset) {
|
|
6895
|
-
var api = options.api,
|
|
6896
|
-
sender = options.sender,
|
|
6897
|
-
recipient = options.recipient,
|
|
6898
|
-
assetInfo = options.assetInfo,
|
|
6899
|
-
ahAddress = options.ahAddress,
|
|
6900
|
-
version = options.version;
|
|
6901
|
-
assertSender(sender);
|
|
6902
|
-
var instructions = createEthereumBridgeInstructions({
|
|
6903
|
-
api: api,
|
|
6904
|
-
sender: sender,
|
|
6905
|
-
recipient: recipient,
|
|
6906
|
-
assetInfo: assetInfo,
|
|
6907
|
-
ahAddress: ahAddress,
|
|
6908
|
-
version: version
|
|
6909
|
-
}, origin, messageId, ethAsset);
|
|
6910
|
-
return _defineProperty({}, version, instructions);
|
|
6911
|
-
};
|
|
6912
|
-
|
|
6913
|
-
var generateMessageId = /*#__PURE__*/function () {
|
|
6914
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, senderAddress, sourceParaId, tokenAddress, recipient, amount) {
|
|
6915
|
-
var accountNextId, sourceAccountHex, entropy;
|
|
6916
|
-
return _regenerator().w(function (_context) {
|
|
6917
|
-
while (1) switch (_context.n) {
|
|
6918
|
-
case 0:
|
|
6919
|
-
_context.n = 1;
|
|
6920
|
-
return api.getFromRpc('system', 'accountNextIndex', senderAddress);
|
|
6921
|
-
case 1:
|
|
6922
|
-
accountNextId = _context.v;
|
|
6923
|
-
sourceAccountHex = api.accountToHex(senderAddress);
|
|
6924
|
-
entropy = new Uint8Array([].concat(_toConsumableArray(api.stringToUint8a(sourceParaId.toString())), _toConsumableArray(api.hexToUint8a(sourceAccountHex)), _toConsumableArray(api.stringToUint8a(accountNextId)), _toConsumableArray(api.hexToUint8a(tokenAddress)), _toConsumableArray(api.stringToUint8a(recipient)), _toConsumableArray(api.stringToUint8a(amount.toString()))));
|
|
6925
|
-
return _context.a(2, api.blake2AsHex(entropy));
|
|
6926
|
-
}
|
|
6927
|
-
}, _callee);
|
|
6928
|
-
}));
|
|
6929
|
-
return function generateMessageId(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
6930
|
-
return _ref.apply(this, arguments);
|
|
6931
|
-
};
|
|
6932
|
-
}();
|
|
6933
|
-
|
|
6934
|
-
var getBridgeStatus = /*#__PURE__*/function () {
|
|
6935
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api) {
|
|
6936
|
-
return _regenerator().w(function (_context) {
|
|
6937
|
-
while (1) switch (_context.p = _context.n) {
|
|
6938
|
-
case 0:
|
|
6939
|
-
_context.n = 1;
|
|
6940
|
-
return api.init('BridgeHubPolkadot');
|
|
6941
|
-
case 1:
|
|
6942
|
-
_context.p = 1;
|
|
6943
|
-
_context.n = 2;
|
|
6944
|
-
return api.getBridgeStatus();
|
|
6945
|
-
case 2:
|
|
6946
|
-
return _context.a(2, _context.v);
|
|
6947
|
-
case 3:
|
|
6948
|
-
_context.p = 3;
|
|
6949
|
-
_context.n = 4;
|
|
6950
|
-
return api.disconnect();
|
|
6951
|
-
case 4:
|
|
6952
|
-
return _context.f(3);
|
|
6953
|
-
case 5:
|
|
6954
|
-
return _context.a(2);
|
|
6955
|
-
}
|
|
6956
|
-
}, _callee, null, [[1,, 3, 5]]);
|
|
6957
|
-
}));
|
|
6958
|
-
return function getBridgeStatus(_x) {
|
|
6959
|
-
return _ref.apply(this, arguments);
|
|
6960
|
-
};
|
|
6961
|
-
}();
|
|
6962
|
-
|
|
6963
|
-
var abi = [
|
|
6964
|
-
{
|
|
6965
|
-
inputs: [
|
|
6966
|
-
{
|
|
6967
|
-
components: [
|
|
6968
|
-
{
|
|
6969
|
-
internalType: "uint8",
|
|
6970
|
-
name: "parents",
|
|
6971
|
-
type: "uint8"
|
|
6972
|
-
},
|
|
6973
|
-
{
|
|
6974
|
-
internalType: "bytes[]",
|
|
6975
|
-
name: "interior",
|
|
6976
|
-
type: "bytes[]"
|
|
6977
|
-
}
|
|
6978
|
-
],
|
|
6979
|
-
internalType: "struct XCM.Location",
|
|
6980
|
-
name: "dest",
|
|
6981
|
-
type: "tuple"
|
|
6982
|
-
},
|
|
6983
|
-
{
|
|
6984
|
-
components: [
|
|
6985
|
-
{
|
|
6986
|
-
internalType: "address",
|
|
6987
|
-
name: "asset",
|
|
6988
|
-
type: "address"
|
|
6989
|
-
},
|
|
6990
|
-
{
|
|
6991
|
-
internalType: "uint256",
|
|
6992
|
-
name: "amount",
|
|
6993
|
-
type: "uint256"
|
|
6994
|
-
}
|
|
6995
|
-
],
|
|
6996
|
-
internalType: "struct XCM.AssetAddressInfo[]",
|
|
6997
|
-
name: "assets",
|
|
6998
|
-
type: "tuple[]"
|
|
6999
|
-
},
|
|
7000
|
-
{
|
|
7001
|
-
internalType: "enum XCM.TransferType",
|
|
7002
|
-
name: "assetsTransferType",
|
|
7003
|
-
type: "uint8"
|
|
7004
|
-
},
|
|
7005
|
-
{
|
|
7006
|
-
internalType: "uint8",
|
|
7007
|
-
name: "remoteFeesIdIndex",
|
|
7008
|
-
type: "uint8"
|
|
7009
|
-
},
|
|
7010
|
-
{
|
|
7011
|
-
internalType: "enum XCM.TransferType",
|
|
7012
|
-
name: "feesTransferType",
|
|
7013
|
-
type: "uint8"
|
|
7014
|
-
},
|
|
7015
|
-
{
|
|
7016
|
-
internalType: "bytes",
|
|
7017
|
-
name: "customXcmOnDest",
|
|
7018
|
-
type: "bytes"
|
|
7019
|
-
}
|
|
7020
|
-
],
|
|
7021
|
-
name: "transferAssetsUsingTypeAndThenAddress",
|
|
7022
|
-
outputs: [
|
|
7023
|
-
],
|
|
7024
|
-
stateMutability: "nonpayable",
|
|
7025
|
-
type: "function"
|
|
7026
|
-
}
|
|
7027
|
-
];
|
|
7028
|
-
|
|
7029
|
-
// https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
|
|
7030
|
-
var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
|
|
7031
|
-
var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
|
|
7032
|
-
var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
7033
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(from, _ref) {
|
|
7034
|
-
var _signer$account;
|
|
7035
|
-
var api, to, signer, recipient, ahAddress, currency, bridgeStatus, foundAsset, amount, ethAsset, contract, sender, messageId, version, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
|
|
7036
|
-
return _regenerator().w(function (_context) {
|
|
7037
|
-
while (1) switch (_context.n) {
|
|
7038
|
-
case 0:
|
|
7039
|
-
api = _ref.api, to = _ref.to, signer = _ref.signer, recipient = _ref.recipient, ahAddress = _ref.ahAddress, currency = _ref.currency;
|
|
7040
|
-
if (ahAddress) {
|
|
7041
|
-
_context.n = 1;
|
|
7042
|
-
break;
|
|
7043
|
-
}
|
|
7044
|
-
throw new MissingParameterError('ahAddress');
|
|
7045
|
-
case 1:
|
|
7046
|
-
_context.n = 2;
|
|
7047
|
-
return getBridgeStatus(api.clone());
|
|
7048
|
-
case 2:
|
|
7049
|
-
bridgeStatus = _context.v;
|
|
7050
|
-
if (!(bridgeStatus !== 'Normal')) {
|
|
7051
|
-
_context.n = 3;
|
|
7052
|
-
break;
|
|
7053
|
-
}
|
|
7054
|
-
throw new BridgeHaltedError();
|
|
7055
|
-
case 3:
|
|
7056
|
-
if (!Array.isArray(currency)) {
|
|
7057
|
-
_context.n = 4;
|
|
7058
|
-
break;
|
|
7059
|
-
}
|
|
7060
|
-
throw new UnsupportedOperationError('Multi-assets are not yet supported for EVM transfers');
|
|
7061
|
-
case 4:
|
|
7062
|
-
if (!('location' in currency && isOverrideLocationSpecifier(currency.location))) {
|
|
7063
|
-
_context.n = 5;
|
|
7064
|
-
break;
|
|
7065
|
-
}
|
|
7066
|
-
throw new UnsupportedOperationError('Override location is not supported for EVM transfers');
|
|
7067
|
-
case 5:
|
|
7068
|
-
foundAsset = api.findAssetInfoOrThrow(from, currency, to);
|
|
7069
|
-
amount = abstractDecimals(currency.amount, foundAsset.decimals, api);
|
|
7070
|
-
ethAsset = api.findAssetInfoOrThrow('Ethereum', {
|
|
7071
|
-
symbol: foundAsset.symbol
|
|
7072
|
-
});
|
|
7073
|
-
contract = getContract({
|
|
7074
|
-
abi: abi,
|
|
7075
|
-
address: xcmInterfacePrecompile,
|
|
7076
|
-
client: {
|
|
7077
|
-
"public": createPublicClient({
|
|
7078
|
-
chain: signer.chain,
|
|
7079
|
-
transport: http()
|
|
7080
|
-
}),
|
|
7081
|
-
wallet: signer
|
|
7082
|
-
}
|
|
7083
|
-
});
|
|
7084
|
-
sender = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
|
|
7085
|
-
assertSender(sender);
|
|
7086
|
-
assertHasId(ethAsset);
|
|
7087
|
-
_context.n = 6;
|
|
7088
|
-
return api.init(from, TX_CLIENT_TIMEOUT_MS);
|
|
7089
|
-
case 6:
|
|
7090
|
-
_context.n = 7;
|
|
7091
|
-
return generateMessageId(api, sender, getParaId(from), ethAsset.assetId, recipient, amount);
|
|
7092
|
-
case 7:
|
|
7093
|
-
messageId = _context.v;
|
|
7094
|
-
version = Version.V4;
|
|
7095
|
-
customXcm = createCustomXcmOnDest({
|
|
7096
|
-
api: api,
|
|
7097
|
-
recipient: recipient,
|
|
7098
|
-
sender: sender,
|
|
7099
|
-
ahAddress: ahAddress,
|
|
7100
|
-
assetInfo: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
|
|
7101
|
-
amount: amount
|
|
7102
|
-
}),
|
|
7103
|
-
version: version
|
|
7104
|
-
}, from, messageId, ethAsset);
|
|
7105
|
-
_context.n = 8;
|
|
7106
|
-
return api.objectToHex(customXcm, 'XcmVersionedXcm', version);
|
|
7107
|
-
case 8:
|
|
7108
|
-
customXcmOnDest = _context.v;
|
|
7109
|
-
_context.n = 9;
|
|
7110
|
-
return api.createApiForChain('AssetHubPolkadot');
|
|
7111
|
-
case 9:
|
|
7112
|
-
assetHubApi = _context.v;
|
|
7113
|
-
_context.n = 10;
|
|
7114
|
-
return getParaEthTransferFees(assetHubApi);
|
|
7115
|
-
case 10:
|
|
7116
|
-
_yield$getParaEthTran = _context.v;
|
|
7117
|
-
_yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
|
|
7118
|
-
bridgeFee = _yield$getParaEthTran2[0];
|
|
7119
|
-
executionFee = _yield$getParaEthTran2[1];
|
|
7120
|
-
transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
|
|
7121
|
-
// https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
|
|
7122
|
-
createTx = function createTx(func, args) {
|
|
7123
|
-
return contract.write[func](args);
|
|
7124
|
-
};
|
|
7125
|
-
numberToHex32 = function numberToHex32(num) {
|
|
7126
|
-
return typeof num !== 'number' || isNaN(num) ? function () {
|
|
7127
|
-
throw new NumberFormatError('Input must be a valid number');
|
|
7128
|
-
}() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
|
|
7129
|
-
}; // Execute the custom XCM message with the precompile
|
|
7130
|
-
_context.n = 11;
|
|
7131
|
-
return createTx('transferAssetsUsingTypeAndThenAddress', [
|
|
7132
|
-
// This represents (1,X1(Parachain(1000)))
|
|
7133
|
-
[1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
|
|
7134
|
-
// Assets including fee and the ERC20 asset, with fee be the first
|
|
7135
|
-
[[XCDOT, transferFee], [ethAsset.assetId, amount.toString()]],
|
|
7136
|
-
// The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
|
|
7137
|
-
2,
|
|
7138
|
-
// index for the fee
|
|
7139
|
-
0,
|
|
7140
|
-
// The TransferType corresponding to fee asset
|
|
7141
|
-
2, customXcmOnDest]);
|
|
7142
|
-
case 11:
|
|
7143
|
-
tx = _context.v;
|
|
7144
|
-
return _context.a(2, tx);
|
|
7145
|
-
}
|
|
7146
|
-
}, _callee);
|
|
7147
|
-
}));
|
|
7148
|
-
return function transferMoonbeamToEth(_x, _x2) {
|
|
7149
|
-
return _ref2.apply(this, arguments);
|
|
7150
|
-
};
|
|
7151
|
-
}();
|
|
7152
|
-
|
|
7153
|
-
var traverseXcmHops = /*#__PURE__*/function () {
|
|
7154
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
|
|
7155
|
-
var api, origin, destination, asset, initialForwardedXcms, initialDestParaId, swapConfig, processHop, shouldContinue, extractNextHopData, currentOrigin, forwardedXcms, nextParaId, currentAsset, hasPassedExchange, hops, destinationResult, nextChain, hopApi, isDestination, hopResult, _extractNextHopData, newXcms, destParaId;
|
|
7156
|
-
return _regenerator().w(function (_context) {
|
|
7157
|
-
while (1) switch (_context.p = _context.n) {
|
|
7158
|
-
case 0:
|
|
7159
|
-
api = config.api, origin = config.origin, destination = config.destination, asset = config.asset, initialForwardedXcms = config.initialForwardedXcms, initialDestParaId = config.initialDestParaId, swapConfig = config.swapConfig, processHop = config.processHop, shouldContinue = config.shouldContinue, extractNextHopData = config.extractNextHopData;
|
|
7160
|
-
currentOrigin = origin;
|
|
7161
|
-
forwardedXcms = initialForwardedXcms;
|
|
7162
|
-
nextParaId = initialDestParaId;
|
|
7163
|
-
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? api.findAssetInfoOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo) : asset;
|
|
7164
|
-
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
7165
|
-
hops = [];
|
|
7166
|
-
case 1:
|
|
7167
|
-
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length > 0 && forwardedXcms[1].length > 0 && ('disconnect' in api.api ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
7168
|
-
_context.n = 10;
|
|
7169
|
-
break;
|
|
7170
|
-
}
|
|
7171
|
-
nextChain = getTChain(nextParaId, api.getRelayChainOf(origin));
|
|
7172
|
-
if (nextChain) {
|
|
7173
|
-
_context.n = 2;
|
|
7174
|
-
break;
|
|
7175
|
-
}
|
|
7176
|
-
throw new RoutingResolutionError("Unable to find TChain for paraId ".concat(nextParaId));
|
|
7177
|
-
case 2:
|
|
7178
|
-
hopApi = api.clone();
|
|
7179
|
-
_context.p = 3;
|
|
7180
|
-
_context.n = 4;
|
|
7181
|
-
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
7182
|
-
case 4:
|
|
7183
|
-
// true if this hop should be treated as the destination
|
|
7184
|
-
// - normally when nextChain === destination
|
|
7185
|
-
// - but if swap is required, only after (or on) the exchange hop
|
|
7186
|
-
isDestination = nextChain === destination && (!swapConfig || hasPassedExchange || nextChain === swapConfig.exchangeChain);
|
|
7187
|
-
_context.n = 5;
|
|
7188
|
-
return processHop({
|
|
7189
|
-
api: hopApi,
|
|
7190
|
-
currentChain: nextChain,
|
|
7191
|
-
currentOrigin: currentOrigin,
|
|
7192
|
-
currentAsset: currentAsset,
|
|
7193
|
-
forwardedXcms: forwardedXcms,
|
|
7194
|
-
hasPassedExchange: hasPassedExchange,
|
|
7195
|
-
isDestination: isDestination
|
|
7196
|
-
});
|
|
7197
|
-
case 5:
|
|
7198
|
-
hopResult = _context.v;
|
|
7199
|
-
if (!isDestination) {
|
|
7200
|
-
hops.push({
|
|
7201
|
-
chain: nextChain,
|
|
7202
|
-
result: hopResult
|
|
7203
|
-
});
|
|
7204
|
-
}
|
|
7205
|
-
if (isDestination) {
|
|
7206
|
-
destinationResult = hopResult;
|
|
7207
|
-
}
|
|
7208
|
-
if (shouldContinue(hopResult)) {
|
|
7209
|
-
_context.n = 6;
|
|
7210
|
-
break;
|
|
7211
|
-
}
|
|
7212
|
-
return _context.a(3, 10);
|
|
7213
|
-
case 6:
|
|
7214
|
-
// Update state for next iteration
|
|
7215
|
-
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
7216
|
-
hasPassedExchange = true;
|
|
7217
|
-
currentAsset = api.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
7218
|
-
}
|
|
7219
|
-
_extractNextHopData = extractNextHopData(hopResult), newXcms = _extractNextHopData.forwardedXcms, destParaId = _extractNextHopData.destParaId;
|
|
7220
|
-
forwardedXcms = newXcms;
|
|
7221
|
-
nextParaId = destParaId;
|
|
7222
|
-
currentOrigin = nextChain;
|
|
7223
|
-
case 7:
|
|
7224
|
-
_context.p = 7;
|
|
7225
|
-
_context.n = 8;
|
|
7226
|
-
return hopApi.disconnect();
|
|
7227
|
-
case 8:
|
|
7228
|
-
return _context.f(7);
|
|
7229
|
-
case 9:
|
|
7230
|
-
_context.n = 1;
|
|
7231
|
-
break;
|
|
7232
|
-
case 10:
|
|
7233
|
-
return _context.a(2, _objectSpread2(_objectSpread2({
|
|
7234
|
-
hops: hops
|
|
7235
|
-
}, destinationResult && {
|
|
7236
|
-
destination: destinationResult
|
|
7237
|
-
}), {}, {
|
|
7238
|
-
lastProcessedChain: currentOrigin
|
|
7239
|
-
}));
|
|
7240
|
-
}
|
|
7241
|
-
}, _callee, null, [[3,, 7, 9]]);
|
|
7242
|
-
}));
|
|
7243
|
-
return function traverseXcmHops(_x) {
|
|
6073
|
+
return function traverseXcmHops(_x) {
|
|
7244
6074
|
return _ref.apply(this, arguments);
|
|
7245
6075
|
};
|
|
7246
6076
|
}();
|
|
@@ -7279,7 +6109,7 @@ var addEthereumBridgeFees = /*#__PURE__*/function () {
|
|
|
7279
6109
|
|
|
7280
6110
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
7281
6111
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7282
|
-
var api, origin, destination, currency, tx, sender, feeAsset, swapConfig, version, bypassOptions, _options$useRootOrigi, useRootOrigin, resolvedFeeAsset, _resolveCurrency, assets, asset, amount, resolvedVersion, originDryRun, isMythosToEthereum, originDryModified, initialForwardedXcms, initialDestParaId, processHop, traversalResult, bridgeHubChain, assetHubChain, bridgeHubHop, processedBridgeHub, bridgeHubHopIndex, result, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9;
|
|
6112
|
+
var api, origin, destination, currency, tx, sender, feeAsset, swapConfig, version, bypassOptions, _options$useRootOrigi, useRootOrigin, resolvedFeeAsset, _resolveCurrency, assets, asset, amount, resolvedVersion, originDryRun, isMythosToEthereum, originDryModified, initialForwardedXcms, initialDestParaId, processHop, traversalResult, bridgeHubChain, assetHubChain, bridgeHubHop, processedBridgeHub, bridgeHubHopIndex, result, dryRunError, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9;
|
|
7283
6113
|
return _regenerator().w(function (_context2) {
|
|
7284
6114
|
while (1) switch (_context2.n) {
|
|
7285
6115
|
case 0:
|
|
@@ -7310,10 +6140,11 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
7310
6140
|
break;
|
|
7311
6141
|
}
|
|
7312
6142
|
return _context2.a(2, {
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
6143
|
+
success: false,
|
|
6144
|
+
dryRunError: _objectSpread2({
|
|
6145
|
+
chainKind: 'origin',
|
|
6146
|
+
chain: origin
|
|
6147
|
+
}, originDryRun.dryRunError),
|
|
7317
6148
|
origin: originDryRun,
|
|
7318
6149
|
hops: []
|
|
7319
6150
|
});
|
|
@@ -7370,7 +6201,9 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
7370
6201
|
return _context.a(2, {
|
|
7371
6202
|
success: false,
|
|
7372
6203
|
asset: currentAsset,
|
|
7373
|
-
|
|
6204
|
+
dryRunError: {
|
|
6205
|
+
reason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
6206
|
+
}
|
|
7374
6207
|
});
|
|
7375
6208
|
case 1:
|
|
7376
6209
|
_context.n = 2;
|
|
@@ -7466,7 +6299,21 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
7466
6299
|
destination: traversalResult.destination,
|
|
7467
6300
|
hops: traversalResult.hops
|
|
7468
6301
|
};
|
|
7469
|
-
|
|
6302
|
+
dryRunError = getDryRunError({
|
|
6303
|
+
origin: {
|
|
6304
|
+
chain: origin,
|
|
6305
|
+
result: result.origin
|
|
6306
|
+
},
|
|
6307
|
+
destination: result.destination ? {
|
|
6308
|
+
chain: destination,
|
|
6309
|
+
result: result.destination
|
|
6310
|
+
} : undefined,
|
|
6311
|
+
hops: result.hops
|
|
6312
|
+
});
|
|
6313
|
+
return _context2.a(2, _objectSpread2({
|
|
6314
|
+
success: !dryRunError,
|
|
6315
|
+
dryRunError: dryRunError
|
|
6316
|
+
}, result));
|
|
7470
6317
|
}
|
|
7471
6318
|
}, _callee2);
|
|
7472
6319
|
}));
|
|
@@ -7763,10 +6610,12 @@ var getBypassResultWithRetries = /*#__PURE__*/function () {
|
|
|
7763
6610
|
maxRetries = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : MAX_INCREASE_RETRIES;
|
|
7764
6611
|
bumpStep = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : INCREASE_BUMP_STEP;
|
|
7765
6612
|
getResultError = function getResultError(res) {
|
|
7766
|
-
|
|
6613
|
+
var _res$dryRunError;
|
|
6614
|
+
return (_res$dryRunError = res.dryRunError) === null || _res$dryRunError === void 0 ? void 0 : _res$dryRunError.reason;
|
|
7767
6615
|
};
|
|
7768
6616
|
isFailedToTransact = function isFailedToTransact(res) {
|
|
7769
|
-
|
|
6617
|
+
var _res$dryRunError2, _res$dryRunError3;
|
|
6618
|
+
return ((_res$dryRunError2 = res.dryRunError) === null || _res$dryRunError2 === void 0 ? void 0 : _res$dryRunError2.reason) === FAILED_TO_TRANSACT_ASSET || ((_res$dryRunError3 = res.dryRunError) === null || _res$dryRunError3 === void 0 ? void 0 : _res$dryRunError3.subReason) === FAILED_TO_TRANSACT_ASSET;
|
|
7770
6619
|
};
|
|
7771
6620
|
isAmountTooLow = function isAmountTooLow(e) {
|
|
7772
6621
|
return e instanceof AmountTooLowError;
|
|
@@ -8004,10 +6853,7 @@ var getOriginXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
8004
6853
|
break;
|
|
8005
6854
|
}
|
|
8006
6855
|
return _context.a(2, {
|
|
8007
|
-
dryRunError: dryRunResult.
|
|
8008
|
-
dryRunSubError: dryRunResult.failureSubReason,
|
|
8009
|
-
dryRunErrorIndex: dryRunResult.failureIndex,
|
|
8010
|
-
dryRunErrorInstruction: dryRunResult.failureInstruction,
|
|
6856
|
+
dryRunError: dryRunResult.dryRunError,
|
|
8011
6857
|
asset: dryRunResult.asset
|
|
8012
6858
|
});
|
|
8013
6859
|
case 6:
|
|
@@ -8021,10 +6867,7 @@ var getOriginXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
8021
6867
|
fee: _paddedFee,
|
|
8022
6868
|
asset: dryRunResult.asset,
|
|
8023
6869
|
feeType: 'paymentInfo',
|
|
8024
|
-
dryRunError: dryRunResult.
|
|
8025
|
-
dryRunSubError: dryRunResult.failureSubReason,
|
|
8026
|
-
dryRunErrorIndex: dryRunResult.failureIndex,
|
|
8027
|
-
dryRunErrorInstruction: dryRunResult.failureInstruction,
|
|
6870
|
+
dryRunError: dryRunResult.dryRunError,
|
|
8028
6871
|
sufficient: false
|
|
8029
6872
|
});
|
|
8030
6873
|
case 8:
|
|
@@ -8096,49 +6939,9 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
8096
6939
|
};
|
|
8097
6940
|
}();
|
|
8098
6941
|
|
|
8099
|
-
var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
8100
|
-
var _chains$origin, _chains$destination;
|
|
8101
|
-
// Check standard chains first for backwards compatibility
|
|
8102
|
-
if ((_chains$origin = chains.origin) !== null && _chains$origin !== void 0 && _chains$origin.dryRunError) return {
|
|
8103
|
-
failureChain: 'origin',
|
|
8104
|
-
failureReason: chains.origin.dryRunError,
|
|
8105
|
-
failureSubReason: chains.origin.dryRunSubError,
|
|
8106
|
-
failureIndex: chains.origin.dryRunErrorIndex,
|
|
8107
|
-
failureInstruction: chains.origin.dryRunErrorInstruction
|
|
8108
|
-
};
|
|
8109
|
-
if ((_chains$destination = chains.destination) !== null && _chains$destination !== void 0 && _chains$destination.dryRunError) return {
|
|
8110
|
-
failureChain: 'destination',
|
|
8111
|
-
failureReason: chains.destination.dryRunError,
|
|
8112
|
-
failureSubReason: chains.destination.dryRunSubError,
|
|
8113
|
-
failureIndex: chains.destination.dryRunErrorIndex,
|
|
8114
|
-
failureInstruction: chains.destination.dryRunErrorInstruction
|
|
8115
|
-
};
|
|
8116
|
-
// Check hops for failures
|
|
8117
|
-
var _iterator = _createForOfIteratorHelper(hops),
|
|
8118
|
-
_step;
|
|
8119
|
-
try {
|
|
8120
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
8121
|
-
var hop = _step.value;
|
|
8122
|
-
if (hop.result.dryRunError) {
|
|
8123
|
-
return {
|
|
8124
|
-
failureChain: hop.chain,
|
|
8125
|
-
failureReason: hop.result.dryRunError,
|
|
8126
|
-
failureSubReason: hop.result.dryRunSubError,
|
|
8127
|
-
failureIndex: hop.result.dryRunErrorIndex,
|
|
8128
|
-
failureInstruction: hop.result.dryRunErrorInstruction
|
|
8129
|
-
};
|
|
8130
|
-
}
|
|
8131
|
-
}
|
|
8132
|
-
} catch (err) {
|
|
8133
|
-
_iterator.e(err);
|
|
8134
|
-
} finally {
|
|
8135
|
-
_iterator.f();
|
|
8136
|
-
}
|
|
8137
|
-
return {};
|
|
8138
|
-
};
|
|
8139
6942
|
var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
8140
6943
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
8141
|
-
var api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, resolvedFeeAsset, _resolveCurrency, asset, resolvedVersion, _yield$getOriginXcmFe, originFeeRaw, originAsset, originFeeType, originDryRunError,
|
|
6944
|
+
var api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, resolvedFeeAsset, _resolveCurrency, asset, resolvedVersion, _yield$getOriginXcmFe, originFeeRaw, originAsset, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, isMythosToEthereum, originFee, destApi, destFeeRes, _result, _dryRunError, processHop, traversalResult, destFee, destAsset, destFeeType, destDryRunError, destSufficient, destResult, _inferFeeAsset2, _destApi, destFallback, bridgeHubChain, assetHubChain, bridgeHubHop, processedBridgeHub, _bridgeHubChain, bridgeHubHopIndex, convertToFeeDetail, result, dryRunError, _t, _t2, _t3, _t4;
|
|
8142
6945
|
return _regenerator().w(function (_context2) {
|
|
8143
6946
|
while (1) switch (_context2.p = _context2.n) {
|
|
8144
6947
|
case 0:
|
|
@@ -8165,9 +6968,6 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8165
6968
|
originAsset = _yield$getOriginXcmFe.asset;
|
|
8166
6969
|
originFeeType = _yield$getOriginXcmFe.feeType;
|
|
8167
6970
|
originDryRunError = _yield$getOriginXcmFe.dryRunError;
|
|
8168
|
-
originDryRunSubError = _yield$getOriginXcmFe.dryRunSubError;
|
|
8169
|
-
originDryRunErrorIndex = _yield$getOriginXcmFe.dryRunErrorIndex;
|
|
8170
|
-
originDryRunErrorInstruction = _yield$getOriginXcmFe.dryRunErrorInstruction;
|
|
8171
6971
|
initialForwardedXcm = _yield$getOriginXcmFe.forwardedXcms;
|
|
8172
6972
|
initialDestParaId = _yield$getOriginXcmFe.destParaId;
|
|
8173
6973
|
originWeight = _yield$getOriginXcmFe.weight;
|
|
@@ -8222,7 +7022,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8222
7022
|
case 7:
|
|
8223
7023
|
destFeeRes = _context2.v;
|
|
8224
7024
|
_result = {
|
|
8225
|
-
origin: _objectSpread2(_objectSpread2(_objectSpread2(
|
|
7025
|
+
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
8226
7026
|
fee: originFee
|
|
8227
7027
|
}), originFeeType && {
|
|
8228
7028
|
feeType: originFeeType
|
|
@@ -8231,12 +7031,6 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8231
7031
|
asset: originAsset
|
|
8232
7032
|
}, originDryRunError && {
|
|
8233
7033
|
dryRunError: originDryRunError
|
|
8234
|
-
}), originDryRunSubError && {
|
|
8235
|
-
dryRunSubError: originDryRunSubError
|
|
8236
|
-
}), originDryRunErrorIndex !== undefined && {
|
|
8237
|
-
dryRunErrorIndex: originDryRunErrorIndex
|
|
8238
|
-
}), originDryRunErrorInstruction && {
|
|
8239
|
-
dryRunErrorInstruction: originDryRunErrorInstruction
|
|
8240
7034
|
}),
|
|
8241
7035
|
destination: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee ? {
|
|
8242
7036
|
fee: destFeeRes.fee
|
|
@@ -8251,16 +7045,21 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8251
7045
|
}),
|
|
8252
7046
|
hops: []
|
|
8253
7047
|
};
|
|
8254
|
-
|
|
8255
|
-
origin:
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
7048
|
+
_dryRunError = getDryRunError({
|
|
7049
|
+
origin: {
|
|
7050
|
+
chain: origin,
|
|
7051
|
+
result: _result.origin
|
|
7052
|
+
},
|
|
7053
|
+
destination: {
|
|
7054
|
+
chain: destination,
|
|
7055
|
+
result: _result.destination
|
|
7056
|
+
},
|
|
7057
|
+
hops: _result.hops
|
|
7058
|
+
});
|
|
7059
|
+
return _context2.a(2, _objectSpread2(_objectSpread2({
|
|
7060
|
+
success: !_dryRunError
|
|
7061
|
+
}, _result), {}, {
|
|
7062
|
+
dryRunError: _dryRunError
|
|
8264
7063
|
}));
|
|
8265
7064
|
case 8:
|
|
8266
7065
|
_context2.p = 8;
|
|
@@ -8354,9 +7153,6 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8354
7153
|
destFee = destResult.fee;
|
|
8355
7154
|
destFeeType = destResult.feeType;
|
|
8356
7155
|
destDryRunError = destResult.dryRunError;
|
|
8357
|
-
destDryRunSubError = destResult.dryRunSubError;
|
|
8358
|
-
destDryRunErrorIndex = destResult.dryRunErrorIndex;
|
|
8359
|
-
destDryRunErrorInstruction = destResult.dryRunErrorInstruction;
|
|
8360
7156
|
destSufficient = destResult.sufficient;
|
|
8361
7157
|
destAsset = destResult.asset;
|
|
8362
7158
|
_context2.n = 16;
|
|
@@ -8446,10 +7242,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8446
7242
|
sufficient: result.sufficient
|
|
8447
7243
|
}), {}, {
|
|
8448
7244
|
asset: result.asset,
|
|
8449
|
-
dryRunError: result.dryRunError
|
|
8450
|
-
dryRunSubError: result.dryRunSubError,
|
|
8451
|
-
dryRunErrorIndex: result.dryRunErrorIndex,
|
|
8452
|
-
dryRunErrorInstruction: result.dryRunErrorInstruction
|
|
7245
|
+
dryRunError: result.dryRunError
|
|
8453
7246
|
});
|
|
8454
7247
|
};
|
|
8455
7248
|
result = {
|
|
@@ -8461,20 +7254,14 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8461
7254
|
sufficient: sufficientOriginFee
|
|
8462
7255
|
}), {}, {
|
|
8463
7256
|
asset: originAsset,
|
|
8464
|
-
dryRunError: originDryRunError
|
|
8465
|
-
dryRunSubError: originDryRunSubError,
|
|
8466
|
-
dryRunErrorIndex: originDryRunErrorIndex,
|
|
8467
|
-
dryRunErrorInstruction: originDryRunErrorInstruction
|
|
7257
|
+
dryRunError: originDryRunError
|
|
8468
7258
|
}),
|
|
8469
7259
|
destination: {
|
|
8470
7260
|
fee: destFee,
|
|
8471
7261
|
feeType: destFeeType,
|
|
8472
7262
|
sufficient: destSufficient,
|
|
8473
7263
|
asset: destAsset,
|
|
8474
|
-
dryRunError: destDryRunError
|
|
8475
|
-
dryRunSubError: destDryRunSubError,
|
|
8476
|
-
dryRunErrorIndex: destDryRunErrorIndex,
|
|
8477
|
-
dryRunErrorInstruction: destDryRunErrorInstruction
|
|
7264
|
+
dryRunError: destDryRunError
|
|
8478
7265
|
},
|
|
8479
7266
|
hops: traversalResult.hops.map(function (hop) {
|
|
8480
7267
|
return {
|
|
@@ -8483,16 +7270,21 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
8483
7270
|
};
|
|
8484
7271
|
})
|
|
8485
7272
|
};
|
|
8486
|
-
|
|
8487
|
-
origin:
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8494
|
-
|
|
8495
|
-
|
|
7273
|
+
dryRunError = getDryRunError({
|
|
7274
|
+
origin: {
|
|
7275
|
+
chain: origin,
|
|
7276
|
+
result: result.origin
|
|
7277
|
+
},
|
|
7278
|
+
destination: {
|
|
7279
|
+
chain: destination,
|
|
7280
|
+
result: result.destination
|
|
7281
|
+
},
|
|
7282
|
+
hops: result.hops
|
|
7283
|
+
});
|
|
7284
|
+
return _context2.a(2, _objectSpread2(_objectSpread2({
|
|
7285
|
+
success: !dryRunError
|
|
7286
|
+
}, result), {}, {
|
|
7287
|
+
dryRunError: dryRunError
|
|
8496
7288
|
}));
|
|
8497
7289
|
}
|
|
8498
7290
|
}, _callee2, null, [[5,, 8, 10]]);
|
|
@@ -8599,8 +7391,37 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
8599
7391
|
}
|
|
8600
7392
|
}, _callee2, null, [[1,, 3, 5]]);
|
|
8601
7393
|
}));
|
|
8602
|
-
return function getXcmFee(_x2) {
|
|
8603
|
-
return _ref2.apply(this, arguments);
|
|
7394
|
+
return function getXcmFee(_x2) {
|
|
7395
|
+
return _ref2.apply(this, arguments);
|
|
7396
|
+
};
|
|
7397
|
+
}();
|
|
7398
|
+
|
|
7399
|
+
var getBridgeStatus = /*#__PURE__*/function () {
|
|
7400
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api) {
|
|
7401
|
+
return _regenerator().w(function (_context) {
|
|
7402
|
+
while (1) switch (_context.p = _context.n) {
|
|
7403
|
+
case 0:
|
|
7404
|
+
_context.n = 1;
|
|
7405
|
+
return api.init('BridgeHubPolkadot');
|
|
7406
|
+
case 1:
|
|
7407
|
+
_context.p = 1;
|
|
7408
|
+
_context.n = 2;
|
|
7409
|
+
return api.getBridgeStatus();
|
|
7410
|
+
case 2:
|
|
7411
|
+
return _context.a(2, _context.v);
|
|
7412
|
+
case 3:
|
|
7413
|
+
_context.p = 3;
|
|
7414
|
+
_context.n = 4;
|
|
7415
|
+
return api.disconnect();
|
|
7416
|
+
case 4:
|
|
7417
|
+
return _context.f(3);
|
|
7418
|
+
case 5:
|
|
7419
|
+
return _context.a(2);
|
|
7420
|
+
}
|
|
7421
|
+
}, _callee, null, [[1,, 3, 5]]);
|
|
7422
|
+
}));
|
|
7423
|
+
return function getBridgeStatus(_x) {
|
|
7424
|
+
return _ref.apply(this, arguments);
|
|
8604
7425
|
};
|
|
8605
7426
|
}();
|
|
8606
7427
|
|
|
@@ -8851,7 +7672,6 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8851
7672
|
}
|
|
8852
7673
|
throw new MissingParameterError('ahAddress', "ahAddress is required for EVM origin ".concat(origin, "."));
|
|
8853
7674
|
case 1:
|
|
8854
|
-
assertNotRawAssets(currency);
|
|
8855
7675
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
8856
7676
|
_context2.n = 2;
|
|
8857
7677
|
return api.init(origin);
|
|
@@ -9071,20 +7891,23 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
9071
7891
|
};
|
|
9072
7892
|
}();
|
|
9073
7893
|
|
|
7894
|
+
var toSelectors = function toSelectors(currency) {
|
|
7895
|
+
return Array.isArray(currency) ? currency : [currency];
|
|
7896
|
+
};
|
|
9074
7897
|
var getMinTransferableAmountInternal = /*#__PURE__*/function () {
|
|
9075
7898
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref) {
|
|
9076
|
-
var api, origin, sender, recipient, destination, currency, feeAsset, buildTx, builder, version, resolvedFeeAsset, _resolveCurrency, assets, selectors, toResult, destApi, nativeAssetInfo, result, minAmounts, buildMinCurrency, createTx, amounts, tx, dryRunResult, _t;
|
|
7899
|
+
var api, origin, sender, recipient, destination, currency, feeAsset, buildTx, builder, version, resolvedFeeAsset, _resolveCurrency, assets, isMulti, selectors, toResult, destApi, nativeAssetInfo, result, minAmounts, buildMinCurrency, createTx, amounts, tx, dryRunResult, _t;
|
|
9077
7900
|
return _regenerator().w(function (_context3) {
|
|
9078
7901
|
while (1) switch (_context3.p = _context3.n) {
|
|
9079
7902
|
case 0:
|
|
9080
7903
|
api = _ref.api, origin = _ref.origin, sender = _ref.sender, recipient = _ref.recipient, destination = _ref.destination, currency = _ref.currency, feeAsset = _ref.feeAsset, buildTx = _ref.buildTx, builder = _ref.builder, version = _ref.version;
|
|
9081
7904
|
validateAddress(api, sender, origin, false);
|
|
9082
|
-
assertNotRawAssets(currency);
|
|
9083
7905
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
9084
7906
|
_resolveCurrency = resolveCurrency(api, currency, resolvedFeeAsset, origin, destination), assets = _resolveCurrency.assets;
|
|
9085
|
-
|
|
7907
|
+
isMulti = Array.isArray(currency);
|
|
7908
|
+
selectors = toSelectors(currency);
|
|
9086
7909
|
toResult = function toResult(values) {
|
|
9087
|
-
return
|
|
7910
|
+
return isMulti ? values : values[0];
|
|
9088
7911
|
};
|
|
9089
7912
|
destApi = api.clone();
|
|
9090
7913
|
_context3.n = 1;
|
|
@@ -9099,7 +7922,7 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
9099
7922
|
buildTx: buildTx,
|
|
9100
7923
|
sender: sender,
|
|
9101
7924
|
recipient: recipient,
|
|
9102
|
-
currency:
|
|
7925
|
+
currency: isMulti ? selectors : _objectSpread2(_objectSpread2({}, selectors[0]), {}, {
|
|
9103
7926
|
amount: assets[0].amount
|
|
9104
7927
|
}),
|
|
9105
7928
|
feeAsset: feeAsset,
|
|
@@ -9145,8 +7968,7 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
9145
7968
|
case 3:
|
|
9146
7969
|
minAmounts = _context3.v;
|
|
9147
7970
|
buildMinCurrency = function buildMinCurrency(amounts) {
|
|
9148
|
-
|
|
9149
|
-
return Array.isArray(currency) ? currency.map(function (item, index) {
|
|
7971
|
+
return isMulti ? selectors.map(function (item, index) {
|
|
9150
7972
|
return _objectSpread2(_objectSpread2({}, item), {}, {
|
|
9151
7973
|
amount: amounts[index]
|
|
9152
7974
|
});
|
|
@@ -9218,7 +8040,7 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
9218
8040
|
});
|
|
9219
8041
|
case 11:
|
|
9220
8042
|
dryRunResult = _context3.v;
|
|
9221
|
-
if (
|
|
8043
|
+
if (dryRunResult.success) {
|
|
9222
8044
|
_context3.n = 12;
|
|
9223
8045
|
break;
|
|
9224
8046
|
}
|
|
@@ -9390,7 +8212,6 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
9390
8212
|
case 0:
|
|
9391
8213
|
api = options.api, sender = options.sender, chain = options.origin, destination = options.destination, currency = options.currency, feeAsset = options.feeAsset;
|
|
9392
8214
|
validateAddress(api, sender, chain, false);
|
|
9393
|
-
assertNotRawAssets(currency);
|
|
9394
8215
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, chain, destination, currency) : undefined;
|
|
9395
8216
|
return _context5.a(2, Array.isArray(currency) ? getTransferableAmountForAssets(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
9396
8217
|
currency: currency
|
|
@@ -9434,6 +8255,264 @@ var getTransferableAmount = /*#__PURE__*/function () {
|
|
|
9434
8255
|
};
|
|
9435
8256
|
}();
|
|
9436
8257
|
|
|
8258
|
+
var createX1Payload = function createX1Payload(version, junction) {
|
|
8259
|
+
return version === Version.V3 ? {
|
|
8260
|
+
X1: junction
|
|
8261
|
+
} : {
|
|
8262
|
+
X1: [junction]
|
|
8263
|
+
};
|
|
8264
|
+
};
|
|
8265
|
+
|
|
8266
|
+
var createAccountPayload = function createAccountPayload(api, address) {
|
|
8267
|
+
return isAddress(address) ? {
|
|
8268
|
+
AccountKey20: {
|
|
8269
|
+
key: address
|
|
8270
|
+
}
|
|
8271
|
+
} : {
|
|
8272
|
+
AccountId32: {
|
|
8273
|
+
id: api.accountToHex(address)
|
|
8274
|
+
}
|
|
8275
|
+
};
|
|
8276
|
+
};
|
|
8277
|
+
var createBeneficiaryLocXTokens = function createBeneficiaryLocXTokens(_ref) {
|
|
8278
|
+
var api = _ref.api,
|
|
8279
|
+
recipient = _ref.recipient,
|
|
8280
|
+
origin = _ref.origin,
|
|
8281
|
+
destination = _ref.destination,
|
|
8282
|
+
version = _ref.version,
|
|
8283
|
+
paraId = _ref.paraId;
|
|
8284
|
+
if (isTLocation(recipient)) {
|
|
8285
|
+
return recipient;
|
|
8286
|
+
}
|
|
8287
|
+
var scenario = resolveScenario(origin, destination);
|
|
8288
|
+
var accountPayload = createAccountPayload(api, recipient);
|
|
8289
|
+
if (scenario === 'ParaToRelay') {
|
|
8290
|
+
return {
|
|
8291
|
+
parents: Parents.ONE,
|
|
8292
|
+
interior: createX1Payload(version, {
|
|
8293
|
+
AccountId32: {
|
|
8294
|
+
id: api.accountToHex(recipient)
|
|
8295
|
+
}
|
|
8296
|
+
})
|
|
8297
|
+
};
|
|
8298
|
+
} else if (scenario === 'ParaToPara') {
|
|
8299
|
+
return {
|
|
8300
|
+
parents: Parents.ONE,
|
|
8301
|
+
interior: {
|
|
8302
|
+
X2: [{
|
|
8303
|
+
Parachain: paraId
|
|
8304
|
+
}, accountPayload]
|
|
8305
|
+
}
|
|
8306
|
+
};
|
|
8307
|
+
}
|
|
8308
|
+
return {
|
|
8309
|
+
parents: Parents.ZERO,
|
|
8310
|
+
interior: createX1Payload(version, accountPayload)
|
|
8311
|
+
};
|
|
8312
|
+
};
|
|
8313
|
+
var createBeneficiaryLocation = function createBeneficiaryLocation(_ref2) {
|
|
8314
|
+
var api = _ref2.api,
|
|
8315
|
+
address = _ref2.address,
|
|
8316
|
+
version = _ref2.version;
|
|
8317
|
+
if (isTLocation(address)) return address;
|
|
8318
|
+
var accountPayload = createAccountPayload(api, address);
|
|
8319
|
+
return {
|
|
8320
|
+
parents: Parents.ZERO,
|
|
8321
|
+
interior: createX1Payload(version, accountPayload)
|
|
8322
|
+
};
|
|
8323
|
+
};
|
|
8324
|
+
|
|
8325
|
+
var createDestination = function createDestination(api, version, origin, destination, chainId, junction, parents) {
|
|
8326
|
+
var isLocDestination = isTLocation(destination);
|
|
8327
|
+
var isSubBridge = !isLocDestination && !isExternalChain(destination) && isSubstrateBridge(origin, destination);
|
|
8328
|
+
if (isSubBridge) {
|
|
8329
|
+
return {
|
|
8330
|
+
parents: Parents.TWO,
|
|
8331
|
+
interior: {
|
|
8332
|
+
X2: [{
|
|
8333
|
+
GlobalConsensus: api.getRelayChainOf(destination)
|
|
8334
|
+
}, {
|
|
8335
|
+
Parachain: chainId
|
|
8336
|
+
}]
|
|
8337
|
+
}
|
|
8338
|
+
};
|
|
8339
|
+
}
|
|
8340
|
+
var isSb = !isLocDestination && isSnowbridge(origin, destination);
|
|
8341
|
+
if (isSb) {
|
|
8342
|
+
return {
|
|
8343
|
+
parents: Parents.TWO,
|
|
8344
|
+
interior: {
|
|
8345
|
+
X1: [getEthereumJunction(api, origin)]
|
|
8346
|
+
}
|
|
8347
|
+
};
|
|
8348
|
+
}
|
|
8349
|
+
var scenario = resolveScenario(origin, destination);
|
|
8350
|
+
var parentsResolved = parents !== null && parents !== void 0 ? parents : scenario === 'RelayToPara' ? Parents.ZERO : Parents.ONE;
|
|
8351
|
+
var interior = scenario === 'ParaToRelay' ? 'Here' : createX1Payload(version, junction !== null && junction !== void 0 ? junction : {
|
|
8352
|
+
Parachain: chainId
|
|
8353
|
+
});
|
|
8354
|
+
return isLocDestination ? destination : {
|
|
8355
|
+
parents: parentsResolved,
|
|
8356
|
+
interior: interior
|
|
8357
|
+
};
|
|
8358
|
+
};
|
|
8359
|
+
var createVersionedDestination = function createVersionedDestination(api, version, origin, destination, chainId, junction, parents) {
|
|
8360
|
+
var plainDestination = createDestination(api, version, origin, destination, chainId, junction, parents);
|
|
8361
|
+
return addXcmVersionHeader(plainDestination, version);
|
|
8362
|
+
};
|
|
8363
|
+
|
|
8364
|
+
var getChainLocation = function getChainLocation(chain, destChain, customCtx) {
|
|
8365
|
+
var fromRelay = isRelayChain(chain);
|
|
8366
|
+
var toRelay = isRelayChain(destChain);
|
|
8367
|
+
var parents = fromRelay ? Parents.ZERO : Parents.ONE;
|
|
8368
|
+
var interior = toRelay ? 'Here' : {
|
|
8369
|
+
X1: [{
|
|
8370
|
+
Parachain: getParaIdImpl(destChain, customCtx)
|
|
8371
|
+
}]
|
|
8372
|
+
};
|
|
8373
|
+
return {
|
|
8374
|
+
parents: parents,
|
|
8375
|
+
interior: interior
|
|
8376
|
+
};
|
|
8377
|
+
};
|
|
8378
|
+
|
|
8379
|
+
/**
|
|
8380
|
+
* This function localizes a location by removing the `Parachain` junction
|
|
8381
|
+
* if it exists. The `parents` field is set to `0` either if a `Parachain` was removed
|
|
8382
|
+
* or if the resulting interior is `'Here'` and the chain is a relay chain.
|
|
8383
|
+
*
|
|
8384
|
+
* @param chain - The current chain
|
|
8385
|
+
* @param location - The location to localize
|
|
8386
|
+
* @returns The localized location
|
|
8387
|
+
*/
|
|
8388
|
+
var localizeLocationInner = function localizeLocationInner(chain, location, origin, resolveRelay, resolveParaId) {
|
|
8389
|
+
var _Object$keys$;
|
|
8390
|
+
var targetRelay = isExternalChain(chain) ? undefined : resolveRelay(chain).toLowerCase();
|
|
8391
|
+
var originRelay = origin && !isExternalChain(origin) ? resolveRelay(origin).toLowerCase() : undefined;
|
|
8392
|
+
var locationConsensus = getJunctionValue(location, 'GlobalConsensus');
|
|
8393
|
+
var locationRelay = locationConsensus ? (_Object$keys$ = Object.keys(locationConsensus)[0]) === null || _Object$keys$ === void 0 ? void 0 : _Object$keys$.toLowerCase() : undefined;
|
|
8394
|
+
var ecosystemDiffers = targetRelay && originRelay && originRelay !== targetRelay;
|
|
8395
|
+
var junctions = location.interior === 'Here' ? [] : Object.values(location.interior).flat().filter(function (junction) {
|
|
8396
|
+
return _typeof(junction) === 'object' && junction !== null;
|
|
8397
|
+
});
|
|
8398
|
+
var junctionCount = junctions.length;
|
|
8399
|
+
var isLocationOnTargetRelay = targetRelay !== undefined && locationRelay === targetRelay;
|
|
8400
|
+
// Check if target is an external chain and location's GlobalConsensus matches it
|
|
8401
|
+
var isLocationOnTargetExternal = isExternalChain(chain) && locationRelay === chain.toLowerCase();
|
|
8402
|
+
if (!origin && locationRelay && targetRelay && locationRelay !== targetRelay) {
|
|
8403
|
+
return location;
|
|
8404
|
+
}
|
|
8405
|
+
if (origin && ecosystemDiffers && location.parents === Parents.TWO && originRelay !== undefined && targetRelay !== undefined && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null)) && junctionCount === 1) {
|
|
8406
|
+
return RELAY_LOCATION;
|
|
8407
|
+
}
|
|
8408
|
+
var newInterior = location.interior;
|
|
8409
|
+
var parachainRemoved = false;
|
|
8410
|
+
if (location.interior !== 'Here') {
|
|
8411
|
+
var paraId = resolveParaId(chain);
|
|
8412
|
+
var filteredJunctions = junctions.filter(function (junction) {
|
|
8413
|
+
if ('GlobalConsensus' in junction && (isLocationOnTargetRelay || isLocationOnTargetExternal)) {
|
|
8414
|
+
return false;
|
|
8415
|
+
}
|
|
8416
|
+
if ('Parachain' in junction && (!ecosystemDiffers || isLocationOnTargetRelay)) {
|
|
8417
|
+
var paraJunctionId = getJunctionValue(location, 'Parachain');
|
|
8418
|
+
if (paraJunctionId === paraId) {
|
|
8419
|
+
parachainRemoved = true;
|
|
8420
|
+
return false;
|
|
8421
|
+
}
|
|
8422
|
+
}
|
|
8423
|
+
return true;
|
|
8424
|
+
});
|
|
8425
|
+
if (filteredJunctions.length === 0) {
|
|
8426
|
+
newInterior = 'Here';
|
|
8427
|
+
} else {
|
|
8428
|
+
newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
|
|
8429
|
+
}
|
|
8430
|
+
}
|
|
8431
|
+
var isOriginRelayHere = deepEqual(location, RELAY_LOCATION);
|
|
8432
|
+
var hasGlobalConsensus = hasJunction(location, 'GlobalConsensus');
|
|
8433
|
+
if (origin && isExternalChain(chain) && originRelay !== undefined && isOriginRelayHere && !hasGlobalConsensus) {
|
|
8434
|
+
return {
|
|
8435
|
+
parents: Parents.ONE,
|
|
8436
|
+
interior: {
|
|
8437
|
+
X1: [{
|
|
8438
|
+
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
8439
|
+
}]
|
|
8440
|
+
}
|
|
8441
|
+
};
|
|
8442
|
+
}
|
|
8443
|
+
if (isExternalChain(chain) && location.parents === Parents.TWO && RELAYCHAINS.some(function (relay) {
|
|
8444
|
+
return deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, relay.toLowerCase(), null));
|
|
8445
|
+
})) {
|
|
8446
|
+
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
8447
|
+
parents: Parents.ONE
|
|
8448
|
+
});
|
|
8449
|
+
}
|
|
8450
|
+
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus && originRelay !== undefined) {
|
|
8451
|
+
return {
|
|
8452
|
+
parents: Parents.TWO,
|
|
8453
|
+
interior: {
|
|
8454
|
+
X2: [{
|
|
8455
|
+
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
8456
|
+
}, {
|
|
8457
|
+
Parachain: resolveParaId(origin)
|
|
8458
|
+
}]
|
|
8459
|
+
}
|
|
8460
|
+
};
|
|
8461
|
+
}
|
|
8462
|
+
if (origin && ecosystemDiffers && newInterior !== 'Here' && !hasGlobalConsensus && originRelay !== undefined) {
|
|
8463
|
+
var _junctions = Object.values(newInterior).flat().filter(function (junction) {
|
|
8464
|
+
return _typeof(junction) === 'object' && junction !== null;
|
|
8465
|
+
});
|
|
8466
|
+
var updatedJunctions = [{
|
|
8467
|
+
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
8468
|
+
}].concat(_toConsumableArray(_junctions));
|
|
8469
|
+
return {
|
|
8470
|
+
parents: Parents.TWO,
|
|
8471
|
+
interior: _defineProperty({}, "X".concat(updatedJunctions.length), updatedJunctions)
|
|
8472
|
+
};
|
|
8473
|
+
}
|
|
8474
|
+
var shouldSetParentsToZero = parachainRemoved || newInterior === 'Here' && isRelayChain(chain) || isLocationOnTargetExternal;
|
|
8475
|
+
return {
|
|
8476
|
+
parents: shouldSetParentsToZero ? Parents.ZERO : location.parents,
|
|
8477
|
+
interior: newInterior
|
|
8478
|
+
};
|
|
8479
|
+
};
|
|
8480
|
+
var localizeLocation = function localizeLocation(chain, location, origin) {
|
|
8481
|
+
return localizeLocationInner(chain, location, origin, function (c) {
|
|
8482
|
+
return getRelayChainOf(c);
|
|
8483
|
+
}, function (c) {
|
|
8484
|
+
return getParaId(c);
|
|
8485
|
+
});
|
|
8486
|
+
};
|
|
8487
|
+
var localizeLocationImpl = function localizeLocationImpl(api, chain, location, origin) {
|
|
8488
|
+
return localizeLocationInner(chain, location, origin, function (c) {
|
|
8489
|
+
return getRelayChainOfImpl(api, c);
|
|
8490
|
+
}, function (c) {
|
|
8491
|
+
return getParaIdImpl(c, api._customCtx);
|
|
8492
|
+
});
|
|
8493
|
+
};
|
|
8494
|
+
|
|
8495
|
+
var reverseTransformLocation = function reverseTransformLocation(location) {
|
|
8496
|
+
var parachainJunction = {
|
|
8497
|
+
Parachain: 1000
|
|
8498
|
+
};
|
|
8499
|
+
var alreadyHasP1000 = location.interior !== 'Here' && Object.values(location.interior).flat().some(function (j) {
|
|
8500
|
+
return _typeof(j) === 'object' && j !== null && 'Parachain' in j && j.Parachain === 1000;
|
|
8501
|
+
});
|
|
8502
|
+
if (alreadyHasP1000) {
|
|
8503
|
+
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
8504
|
+
parents: Parents.ONE
|
|
8505
|
+
});
|
|
8506
|
+
}
|
|
8507
|
+
var existingJunctions = location.interior === 'Here' ? [] // no other junctions
|
|
8508
|
+
: Object.values(location.interior).flat();
|
|
8509
|
+
var allJunctions = [parachainJunction].concat(_toConsumableArray(existingJunctions));
|
|
8510
|
+
return _objectSpread2(_objectSpread2({}, location), {}, {
|
|
8511
|
+
parents: Parents.ONE,
|
|
8512
|
+
interior: _defineProperty({}, "X".concat(allJunctions.length), allJunctions)
|
|
8513
|
+
});
|
|
8514
|
+
};
|
|
8515
|
+
|
|
9437
8516
|
var resolveTransferType = function resolveTransferType(_ref) {
|
|
9438
8517
|
var origin = _ref.origin,
|
|
9439
8518
|
reserve = _ref.reserve,
|
|
@@ -9585,6 +8664,27 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
|
9585
8664
|
};
|
|
9586
8665
|
}();
|
|
9587
8666
|
|
|
8667
|
+
var generateMessageId = /*#__PURE__*/function () {
|
|
8668
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, senderAddress, sourceParaId, tokenAddress, recipient, amount) {
|
|
8669
|
+
var accountNextId, sourceAccountHex, entropy;
|
|
8670
|
+
return _regenerator().w(function (_context) {
|
|
8671
|
+
while (1) switch (_context.n) {
|
|
8672
|
+
case 0:
|
|
8673
|
+
_context.n = 1;
|
|
8674
|
+
return api.getFromRpc('system', 'accountNextIndex', senderAddress);
|
|
8675
|
+
case 1:
|
|
8676
|
+
accountNextId = _context.v;
|
|
8677
|
+
sourceAccountHex = api.accountToHex(senderAddress);
|
|
8678
|
+
entropy = new Uint8Array([].concat(_toConsumableArray(api.stringToUint8a(sourceParaId.toString())), _toConsumableArray(api.hexToUint8a(sourceAccountHex)), _toConsumableArray(api.stringToUint8a(accountNextId)), _toConsumableArray(api.hexToUint8a(tokenAddress)), _toConsumableArray(api.stringToUint8a(recipient)), _toConsumableArray(api.stringToUint8a(amount.toString()))));
|
|
8679
|
+
return _context.a(2, api.blake2AsHex(entropy));
|
|
8680
|
+
}
|
|
8681
|
+
}, _callee);
|
|
8682
|
+
}));
|
|
8683
|
+
return function generateMessageId(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
8684
|
+
return _ref.apply(this, arguments);
|
|
8685
|
+
};
|
|
8686
|
+
}();
|
|
8687
|
+
|
|
9588
8688
|
var resolveBuyExecutionAmount = function resolveBuyExecutionAmount(_ref, isForFeeCalc, _ref2, systemAssetAmount) {
|
|
9589
8689
|
var isRelayAsset = _ref.isRelayAsset,
|
|
9590
8690
|
assetInfo = _ref.assetInfo;
|
|
@@ -9606,7 +8706,7 @@ var resolveSnowbridgeMessageId = function resolveSnowbridgeMessageId(_ref3) {
|
|
|
9606
8706
|
recipient = _ref3$options.recipient;
|
|
9607
8707
|
if (!isSnowbridge) return Promise.resolve(null);
|
|
9608
8708
|
assertSender(sender);
|
|
9609
|
-
return generateMessageId(origin.api, sender, getParaId(origin.chain), JSON.stringify(assetInfo.location), JSON.stringify(recipient), assetInfo.amount);
|
|
8709
|
+
return generateMessageId(origin.api, sender, origin.api.getParaId(origin.chain), JSON.stringify(assetInfo.location), JSON.stringify(recipient), assetInfo.amount);
|
|
9610
8710
|
};
|
|
9611
8711
|
var createCustomXcm = /*#__PURE__*/function () {
|
|
9612
8712
|
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, assetCount, isForFeeCalc, systemAssetAmount) {
|
|
@@ -9626,7 +8726,6 @@ var createCustomXcm = /*#__PURE__*/function () {
|
|
|
9626
8726
|
sender,
|
|
9627
8727
|
ahAddress,
|
|
9628
8728
|
overriddenAsset,
|
|
9629
|
-
overriddenAssets,
|
|
9630
8729
|
buildRefundInstruction,
|
|
9631
8730
|
hopFees,
|
|
9632
8731
|
destFee,
|
|
@@ -9660,7 +8759,6 @@ var createCustomXcm = /*#__PURE__*/function () {
|
|
|
9660
8759
|
};
|
|
9661
8760
|
origin = context.origin, dest = context.dest, reserve = context.reserve, isSubBridge = context.isSubBridge, isRelayAsset = context.isRelayAsset, assetInfo = context.assetInfo, bridgeHopChain = context.bridgeHopChain, options = context.options;
|
|
9662
8761
|
destination = options.destination, version = options.version, recipient = options.recipient, paraIdTo = options.paraIdTo, sender = options.sender, ahAddress = options.ahAddress, overriddenAsset = options.overriddenAsset;
|
|
9663
|
-
overriddenAssets = Array.isArray(overriddenAsset) ? overriddenAsset : null;
|
|
9664
8762
|
buildRefundInstruction = function buildRefundInstruction() {
|
|
9665
8763
|
if (!sender || isSubBridge) return null;
|
|
9666
8764
|
var resolveRefundAddress = function resolveRefundAddress() {
|
|
@@ -9707,7 +8805,7 @@ var createCustomXcm = /*#__PURE__*/function () {
|
|
|
9707
8805
|
depositInstruction = {
|
|
9708
8806
|
DepositAsset: {
|
|
9709
8807
|
assets: {
|
|
9710
|
-
Wild: assetCount > 1 && !
|
|
8808
|
+
Wild: assetCount > 1 && !overriddenAsset ? allOfSelector : {
|
|
9711
8809
|
AllCounted: assetCount
|
|
9712
8810
|
}
|
|
9713
8811
|
},
|
|
@@ -9722,8 +8820,8 @@ var createCustomXcm = /*#__PURE__*/function () {
|
|
|
9722
8820
|
return createAsset(version, amount, normalizeLocation(origin.api.localizeLocation(reserve.chain, location), version));
|
|
9723
8821
|
};
|
|
9724
8822
|
assetsFilter = [];
|
|
9725
|
-
if (
|
|
9726
|
-
assetsFilter.push.apply(assetsFilter, _toConsumableArray(
|
|
8823
|
+
if (overriddenAsset) {
|
|
8824
|
+
assetsFilter.push.apply(assetsFilter, _toConsumableArray(overriddenAsset.map(function (asset) {
|
|
9727
8825
|
return localizeFilterAsset(asset.fun.Fungible, extractAssetLocation(asset));
|
|
9728
8826
|
})));
|
|
9729
8827
|
} else {
|
|
@@ -9825,8 +8923,7 @@ var buildAssets = function buildAssets(api, chain, asset, feeAmount, isRelayAsse
|
|
|
9825
8923
|
var version = _ref.version,
|
|
9826
8924
|
overriddenAsset = _ref.overriddenAsset;
|
|
9827
8925
|
if (overriddenAsset) {
|
|
9828
|
-
|
|
9829
|
-
return [createAsset(version, asset.amount, overriddenAsset)];
|
|
8926
|
+
return overriddenAsset;
|
|
9830
8927
|
}
|
|
9831
8928
|
var assets = [];
|
|
9832
8929
|
if (!isRelayAsset) {
|
|
@@ -9837,7 +8934,7 @@ var buildAssets = function buildAssets(api, chain, asset, feeAmount, isRelayAsse
|
|
|
9837
8934
|
};
|
|
9838
8935
|
var resolveAssetCount = function resolveAssetCount(overriddenAsset, isRelayAsset) {
|
|
9839
8936
|
if (overriddenAsset) {
|
|
9840
|
-
return
|
|
8937
|
+
return overriddenAsset.length;
|
|
9841
8938
|
}
|
|
9842
8939
|
return isRelayAsset ? 1 : 2;
|
|
9843
8940
|
};
|
|
@@ -9968,39 +9065,9 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
|
9968
9065
|
};
|
|
9969
9066
|
}();
|
|
9970
9067
|
|
|
9971
|
-
/**
|
|
9972
|
-
* Retrieves the chain instance for a given chain.
|
|
9973
|
-
*
|
|
9974
|
-
* @param chain - The chain identifier.
|
|
9975
|
-
* @returns The chain instance
|
|
9976
|
-
*/
|
|
9977
|
-
var getChain = function getChain(chain) {
|
|
9978
|
-
var map = chains();
|
|
9979
|
-
return map[chain];
|
|
9980
|
-
};
|
|
9981
|
-
|
|
9982
|
-
/**
|
|
9983
|
-
* Gets the relay chain (Polkadot, Kusama, Westend, or Paseo) of a given chain.
|
|
9984
|
-
*
|
|
9985
|
-
* @param chain - The chain to evaluate.
|
|
9986
|
-
* @returns The corresponding relay chain.
|
|
9987
|
-
*/
|
|
9988
|
-
var getRelayChainOf = function getRelayChainOf(chain) {
|
|
9989
|
-
return getChain(chain).ecosystem;
|
|
9990
|
-
};
|
|
9991
|
-
var getRelayChainOfImpl = function getRelayChainOfImpl(api, chain) {
|
|
9992
|
-
if (isCustomChain(chain)) {
|
|
9993
|
-
var _api$_customCtx$custo;
|
|
9994
|
-
var customEntry = (_api$_customCtx$custo = api._customCtx.customChains) === null || _api$_customCtx$custo === void 0 ? void 0 : _api$_customCtx$custo[chain];
|
|
9995
|
-
if (customEntry) return customEntry.ecosystem;
|
|
9996
|
-
throw new CustomChainInvalidError("Custom chain '".concat(chain, "' is not registered."));
|
|
9997
|
-
}
|
|
9998
|
-
return getChain(chain).ecosystem;
|
|
9999
|
-
};
|
|
10000
|
-
|
|
10001
9068
|
var createCallForReserve = /*#__PURE__*/function () {
|
|
10002
9069
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, reserveChain, options) {
|
|
10003
|
-
var api, destination, sender, recipient, currency, feeCurrency, version, serialized, tx, dryRunResult
|
|
9070
|
+
var api, destination, sender, recipient, currency, feeCurrency, version, serialized, tx, dryRunResult;
|
|
10004
9071
|
return _regenerator().w(function (_context) {
|
|
10005
9072
|
while (1) switch (_context.n) {
|
|
10006
9073
|
case 0:
|
|
@@ -10029,10 +9096,9 @@ var createCallForReserve = /*#__PURE__*/function () {
|
|
|
10029
9096
|
});
|
|
10030
9097
|
case 2:
|
|
10031
9098
|
dryRunResult = _context.v;
|
|
10032
|
-
success = !dryRunResult.failureReason;
|
|
10033
9099
|
return _context.a(2, {
|
|
10034
9100
|
call: serialized,
|
|
10035
|
-
success: success
|
|
9101
|
+
success: dryRunResult.success
|
|
10036
9102
|
});
|
|
10037
9103
|
}
|
|
10038
9104
|
}, _callee);
|
|
@@ -10124,7 +9190,6 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
10124
9190
|
}
|
|
10125
9191
|
throw new ScenarioNotSupportedError('Unable to verify the existential deposit for substrate bridge scenarios');
|
|
10126
9192
|
case 2:
|
|
10127
|
-
assertNotRawAssets(currency);
|
|
10128
9193
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
10129
9194
|
destApi = api.clone();
|
|
10130
9195
|
_context2.n = 3;
|
|
@@ -10176,23 +9241,29 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
10176
9241
|
_context2.n = 5;
|
|
10177
9242
|
break;
|
|
10178
9243
|
}
|
|
10179
|
-
throw new DryRunFailedError(dryRunError,
|
|
9244
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, dryRunError), {}, {
|
|
9245
|
+
chainKind: 'origin',
|
|
9246
|
+
chain: origin
|
|
9247
|
+
}));
|
|
10180
9248
|
case 5:
|
|
10181
9249
|
erroredHop = hops.find(function (hop) {
|
|
10182
9250
|
return hop.result.dryRunError;
|
|
10183
9251
|
});
|
|
10184
9252
|
hopError = erroredHop === null || erroredHop === void 0 ? void 0 : erroredHop.result.dryRunError;
|
|
10185
|
-
if (!hopError) {
|
|
9253
|
+
if (!(erroredHop && hopError)) {
|
|
10186
9254
|
_context2.n = 6;
|
|
10187
9255
|
break;
|
|
10188
9256
|
}
|
|
10189
|
-
throw new DryRunFailedError(hopError,
|
|
9257
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, hopError), {}, {
|
|
9258
|
+
chainKind: 'hop',
|
|
9259
|
+
chain: erroredHop.chain
|
|
9260
|
+
}));
|
|
10190
9261
|
case 6:
|
|
10191
9262
|
if (!destDryRunError) {
|
|
10192
9263
|
_context2.n = 7;
|
|
10193
9264
|
break;
|
|
10194
9265
|
}
|
|
10195
|
-
throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError));
|
|
9266
|
+
throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError.reason));
|
|
10196
9267
|
case 7:
|
|
10197
9268
|
isUnableToCompute = !isSymbolMatch(normalizeSymbol(feeElement.destAsset.symbol), normalizeSymbol(destFeeAsset.symbol)) && destFeeType === 'paymentInfo';
|
|
10198
9269
|
if (!isUnableToCompute) {
|
|
@@ -10317,7 +9388,7 @@ var transferPolkadotXcm = /*#__PURE__*/function () {
|
|
|
10317
9388
|
case 2:
|
|
10318
9389
|
resolvedMultiAssets = maybeOverrideAssets(version, asset.amount, [multiAsset], overriddenAsset);
|
|
10319
9390
|
destLocation = createDestination(api, version, chain, destination, paraIdTo);
|
|
10320
|
-
feeAssetIndex = overriddenAsset === undefined
|
|
9391
|
+
feeAssetIndex = overriddenAsset === undefined ? DEFAULT_FEE_ASSET : overriddenAsset.findIndex(function (asset) {
|
|
10321
9392
|
return asset.isFeeAsset;
|
|
10322
9393
|
});
|
|
10323
9394
|
call = {
|
|
@@ -10808,7 +9879,10 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10808
9879
|
_context.n = 4;
|
|
10809
9880
|
break;
|
|
10810
9881
|
}
|
|
10811
|
-
throw new DryRunFailedError(dryRunResult.
|
|
9882
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, dryRunResult.origin.dryRunError), {}, {
|
|
9883
|
+
chainKind: 'origin',
|
|
9884
|
+
chain: chain
|
|
9885
|
+
}));
|
|
10812
9886
|
case 4:
|
|
10813
9887
|
originFeeEstimate = dryRunResult.origin.fee;
|
|
10814
9888
|
originFee = padValueBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
@@ -10837,6 +9911,168 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10837
9911
|
};
|
|
10838
9912
|
}();
|
|
10839
9913
|
|
|
9914
|
+
var createMainInstruction = function createMainInstruction(api, origin, asset, ethAsset, recipient, messageId) {
|
|
9915
|
+
assertHasId(ethAsset);
|
|
9916
|
+
var interiorSb = ethAsset.symbol === 'ETH' ? {
|
|
9917
|
+
Here: null
|
|
9918
|
+
} : {
|
|
9919
|
+
X1: [{
|
|
9920
|
+
AccountKey20: {
|
|
9921
|
+
network: null,
|
|
9922
|
+
key: ethAsset.assetId
|
|
9923
|
+
}
|
|
9924
|
+
}]
|
|
9925
|
+
};
|
|
9926
|
+
var isAssetNativeToPolkadot = !deepEqual(getJunctionValue(asset.location, 'GlobalConsensus'), {
|
|
9927
|
+
Ethereum: {
|
|
9928
|
+
chainId: 1
|
|
9929
|
+
}
|
|
9930
|
+
// MYTH needs to use InitiateReserveWithdraw
|
|
9931
|
+
}) && origin !== 'Mythos';
|
|
9932
|
+
var beneficiary = {
|
|
9933
|
+
parents: Parents.ZERO,
|
|
9934
|
+
interior: {
|
|
9935
|
+
X1: [{
|
|
9936
|
+
AccountKey20: {
|
|
9937
|
+
network: null,
|
|
9938
|
+
key: recipient
|
|
9939
|
+
}
|
|
9940
|
+
}]
|
|
9941
|
+
}
|
|
9942
|
+
};
|
|
9943
|
+
var makeBuyExecution = function makeBuyExecution(feesId) {
|
|
9944
|
+
return {
|
|
9945
|
+
BuyExecution: {
|
|
9946
|
+
fees: {
|
|
9947
|
+
id: feesId,
|
|
9948
|
+
fun: {
|
|
9949
|
+
Fungible: 1n
|
|
9950
|
+
}
|
|
9951
|
+
},
|
|
9952
|
+
weight_limit: 'Unlimited'
|
|
9953
|
+
}
|
|
9954
|
+
};
|
|
9955
|
+
};
|
|
9956
|
+
var makeDepositAsset = function makeDepositAsset() {
|
|
9957
|
+
return {
|
|
9958
|
+
DepositAsset: {
|
|
9959
|
+
assets: {
|
|
9960
|
+
Wild: {
|
|
9961
|
+
AllCounted: 1
|
|
9962
|
+
}
|
|
9963
|
+
},
|
|
9964
|
+
beneficiary: beneficiary
|
|
9965
|
+
}
|
|
9966
|
+
};
|
|
9967
|
+
};
|
|
9968
|
+
var commonXcm = function commonXcm(feesId) {
|
|
9969
|
+
return [makeBuyExecution(feesId), makeDepositAsset(), {
|
|
9970
|
+
SetTopic: messageId
|
|
9971
|
+
}];
|
|
9972
|
+
};
|
|
9973
|
+
var ethJunction = getEthereumJunction(api, origin);
|
|
9974
|
+
if (isAssetNativeToPolkadot) {
|
|
9975
|
+
var assetEcosystem = RELAYCHAINS.find(function (chain) {
|
|
9976
|
+
return asset.symbol.includes(getNativeAssetSymbol(chain));
|
|
9977
|
+
});
|
|
9978
|
+
if (!assetEcosystem) throw new UnsupportedOperationError('Unsupported native polkadot asset');
|
|
9979
|
+
return {
|
|
9980
|
+
DepositReserveAsset: {
|
|
9981
|
+
assets: {
|
|
9982
|
+
Wild: {
|
|
9983
|
+
AllOf: {
|
|
9984
|
+
id: asset.location,
|
|
9985
|
+
fun: 'Fungible'
|
|
9986
|
+
}
|
|
9987
|
+
}
|
|
9988
|
+
},
|
|
9989
|
+
dest: {
|
|
9990
|
+
parents: Parents.TWO,
|
|
9991
|
+
interior: {
|
|
9992
|
+
X1: [ethJunction]
|
|
9993
|
+
}
|
|
9994
|
+
},
|
|
9995
|
+
xcm: commonXcm({
|
|
9996
|
+
parents: Parents.ONE,
|
|
9997
|
+
interior: {
|
|
9998
|
+
X1: [{
|
|
9999
|
+
GlobalConsensus: _defineProperty({}, assetEcosystem.toLowerCase(), null)
|
|
10000
|
+
}]
|
|
10001
|
+
}
|
|
10002
|
+
})
|
|
10003
|
+
}
|
|
10004
|
+
};
|
|
10005
|
+
}
|
|
10006
|
+
return {
|
|
10007
|
+
InitiateReserveWithdraw: {
|
|
10008
|
+
assets: {
|
|
10009
|
+
Wild: {
|
|
10010
|
+
AllOf: {
|
|
10011
|
+
id: ethAsset.location,
|
|
10012
|
+
fun: 'Fungible'
|
|
10013
|
+
}
|
|
10014
|
+
}
|
|
10015
|
+
},
|
|
10016
|
+
reserve: {
|
|
10017
|
+
parents: Parents.TWO,
|
|
10018
|
+
interior: {
|
|
10019
|
+
X1: [ethJunction]
|
|
10020
|
+
}
|
|
10021
|
+
},
|
|
10022
|
+
xcm: commonXcm({
|
|
10023
|
+
parents: Parents.ZERO,
|
|
10024
|
+
interior: interiorSb
|
|
10025
|
+
})
|
|
10026
|
+
}
|
|
10027
|
+
};
|
|
10028
|
+
};
|
|
10029
|
+
var createEthereumBridgeInstructions = function createEthereumBridgeInstructions(_ref, origin, messageId, ethAsset) {
|
|
10030
|
+
var api = _ref.api,
|
|
10031
|
+
sender = _ref.sender,
|
|
10032
|
+
recipient = _ref.recipient,
|
|
10033
|
+
assetInfo = _ref.assetInfo,
|
|
10034
|
+
ahAddress = _ref.ahAddress,
|
|
10035
|
+
version = _ref.version;
|
|
10036
|
+
assertSender(sender);
|
|
10037
|
+
if (isChainEvm(origin) && !ahAddress) {
|
|
10038
|
+
throw new MissingParameterError('ahAddress');
|
|
10039
|
+
}
|
|
10040
|
+
return [{
|
|
10041
|
+
SetAppendix: origin === 'Mythos' ? [] : [{
|
|
10042
|
+
DepositAsset: {
|
|
10043
|
+
assets: {
|
|
10044
|
+
Wild: 'All'
|
|
10045
|
+
},
|
|
10046
|
+
beneficiary: createBeneficiaryLocation({
|
|
10047
|
+
api: api,
|
|
10048
|
+
address: isChainEvm(origin) ? ahAddress : sender,
|
|
10049
|
+
version: version
|
|
10050
|
+
})
|
|
10051
|
+
}
|
|
10052
|
+
}]
|
|
10053
|
+
}, createMainInstruction(api, origin, assetInfo, ethAsset, recipient, messageId), {
|
|
10054
|
+
SetTopic: messageId
|
|
10055
|
+
}];
|
|
10056
|
+
};
|
|
10057
|
+
var createCustomXcmOnDest = function createCustomXcmOnDest(options, origin, messageId, ethAsset) {
|
|
10058
|
+
var api = options.api,
|
|
10059
|
+
sender = options.sender,
|
|
10060
|
+
recipient = options.recipient,
|
|
10061
|
+
assetInfo = options.assetInfo,
|
|
10062
|
+
ahAddress = options.ahAddress,
|
|
10063
|
+
version = options.version;
|
|
10064
|
+
assertSender(sender);
|
|
10065
|
+
var instructions = createEthereumBridgeInstructions({
|
|
10066
|
+
api: api,
|
|
10067
|
+
sender: sender,
|
|
10068
|
+
recipient: recipient,
|
|
10069
|
+
assetInfo: assetInfo,
|
|
10070
|
+
ahAddress: ahAddress,
|
|
10071
|
+
version: version
|
|
10072
|
+
}, origin, messageId, ethAsset);
|
|
10073
|
+
return _defineProperty({}, version, instructions);
|
|
10074
|
+
};
|
|
10075
|
+
|
|
10840
10076
|
var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo) {
|
|
10841
10077
|
var isAssetHub = exchangeChain.includes('AssetHub');
|
|
10842
10078
|
var nativeSymbol = getNativeAssetSymbol(exchangeChain);
|
|
@@ -11055,7 +10291,10 @@ var executeDryRun = /*#__PURE__*/function () {
|
|
|
11055
10291
|
_context.n = 2;
|
|
11056
10292
|
break;
|
|
11057
10293
|
}
|
|
11058
|
-
throw new DryRunFailedError(
|
|
10294
|
+
throw new DryRunFailedError(_objectSpread2({
|
|
10295
|
+
chainKind: 'origin',
|
|
10296
|
+
chain: params.origin
|
|
10297
|
+
}, result.origin.dryRunError));
|
|
11059
10298
|
case 2:
|
|
11060
10299
|
return _context.a(2, result);
|
|
11061
10300
|
}
|
|
@@ -11081,8 +10320,8 @@ var findExchangeHopIndex = function findExchangeHopIndex(chain, dryRunResult, ex
|
|
|
11081
10320
|
}
|
|
11082
10321
|
return index;
|
|
11083
10322
|
};
|
|
11084
|
-
var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult, exchangeHopIndex, destChain) {
|
|
11085
|
-
var requireHopsSuccess = arguments.length >
|
|
10323
|
+
var extractFeesFromDryRun = function extractFeesFromDryRun(chain, exchangeChain, dryRunResult, exchangeHopIndex, destChain) {
|
|
10324
|
+
var requireHopsSuccess = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
11086
10325
|
var fees = {
|
|
11087
10326
|
originFee: 0n,
|
|
11088
10327
|
originReserveFee: 0n,
|
|
@@ -11096,7 +10335,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11096
10335
|
if (!destChain) {
|
|
11097
10336
|
// Exchange fee comes from the final destination result
|
|
11098
10337
|
if (dryRunResult.destination && !dryRunResult.destination.success && requireHopsSuccess) {
|
|
11099
|
-
throw new DryRunFailedError(
|
|
10338
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, dryRunResult.destination.dryRunError), {}, {
|
|
10339
|
+
chainKind: 'destination',
|
|
10340
|
+
chain: exchangeChain
|
|
10341
|
+
}), 'Exchange (destination):');
|
|
11100
10342
|
}
|
|
11101
10343
|
if (dryRunResult.destination && dryRunResult.destination.success) {
|
|
11102
10344
|
fees.exchangeFee = padValueBy(dryRunResult.destination.fee, FEE_PADDING_PERCENTAGE);
|
|
@@ -11105,7 +10347,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11105
10347
|
// Normal case: exchange is an intermediate hop
|
|
11106
10348
|
var exchangeHop = hops[exchangeHopIndex];
|
|
11107
10349
|
if (requireHopsSuccess && !exchangeHop.result.success) {
|
|
11108
|
-
throw new DryRunFailedError(
|
|
10350
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, exchangeHop.result.dryRunError), {}, {
|
|
10351
|
+
chainKind: 'hop',
|
|
10352
|
+
chain: exchangeHop.chain
|
|
10353
|
+
}), 'Exchange hop:');
|
|
11109
10354
|
}
|
|
11110
10355
|
if (exchangeHop.result.success) {
|
|
11111
10356
|
fees.exchangeFee = padValueBy(exchangeHop.result.fee, FEE_PADDING_PERCENTAGE);
|
|
@@ -11113,7 +10358,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11113
10358
|
}
|
|
11114
10359
|
} else {
|
|
11115
10360
|
if (!dryRunResult.origin.success) {
|
|
11116
|
-
throw new DryRunFailedError(
|
|
10361
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, dryRunResult.origin.dryRunError), {}, {
|
|
10362
|
+
chainKind: 'origin',
|
|
10363
|
+
chain: exchangeChain
|
|
10364
|
+
}), 'Origin:');
|
|
11117
10365
|
}
|
|
11118
10366
|
// There is no exchange fee if origin is exchange, because jit_withdraw is used
|
|
11119
10367
|
fees.exchangeFee = 0n;
|
|
@@ -11122,7 +10370,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11122
10370
|
if (exchangeHopIndex > 0) {
|
|
11123
10371
|
var hopBeforeExchange = hops[exchangeHopIndex - 1];
|
|
11124
10372
|
if (requireHopsSuccess && !hopBeforeExchange.result.success) {
|
|
11125
|
-
throw new DryRunFailedError(
|
|
10373
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, hopBeforeExchange.result.dryRunError), {}, {
|
|
10374
|
+
chainKind: 'hop',
|
|
10375
|
+
chain: hopBeforeExchange.chain
|
|
10376
|
+
}), 'Hop before exchange:');
|
|
11126
10377
|
}
|
|
11127
10378
|
if (hopBeforeExchange.result.success) {
|
|
11128
10379
|
fees.originReserveFee = padValueBy(hopBeforeExchange.result.fee, FEE_PADDING_PERCENTAGE);
|
|
@@ -11132,7 +10383,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11132
10383
|
// the last hop is the origin reserve fee (before reaching exchange destination)
|
|
11133
10384
|
var lastHop = hops[hops.length - 1];
|
|
11134
10385
|
if (requireHopsSuccess && !lastHop.result.success) {
|
|
11135
|
-
throw new DryRunFailedError(
|
|
10386
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, lastHop.result.dryRunError), {}, {
|
|
10387
|
+
chainKind: 'hop',
|
|
10388
|
+
chain: lastHop.chain
|
|
10389
|
+
}), 'Origin reserve hop:');
|
|
11136
10390
|
}
|
|
11137
10391
|
if (lastHop.result.success) {
|
|
11138
10392
|
fees.originReserveFee = padValueBy(lastHop.result.fee, FEE_PADDING_PERCENTAGE);
|
|
@@ -11143,7 +10397,10 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
11143
10397
|
if (destChain && exchangeHopIndex < hops.length - 1) {
|
|
11144
10398
|
var hopAfterExchange = hops[exchangeHopIndex + 1];
|
|
11145
10399
|
if (requireHopsSuccess && !hopAfterExchange.result.success) {
|
|
11146
|
-
throw new DryRunFailedError(
|
|
10400
|
+
throw new DryRunFailedError(_objectSpread2(_objectSpread2({}, hopAfterExchange.result.dryRunError), {}, {
|
|
10401
|
+
chainKind: 'hop',
|
|
10402
|
+
chain: hopAfterExchange.chain
|
|
10403
|
+
}), 'Hop after exchange:');
|
|
11147
10404
|
}
|
|
11148
10405
|
if (hopAfterExchange.result.success) {
|
|
11149
10406
|
fees.destReserveFee = padValueBy(hopAfterExchange.result.fee, FEE_PADDING_PERCENTAGE);
|
|
@@ -11192,6 +10449,7 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
11192
10449
|
}();
|
|
11193
10450
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
11194
10451
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
10452
|
+
var _firstDryRunResult$dr;
|
|
11195
10453
|
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, feeAssetInfo, sender, recipient, calculateMinAmountOut, version, isEthereumDest, hasSeparateFeeAsset, internalOptions, dryRunParams, FEE_ASSET_AMOUNT, dummyOriginFee, fees, totalFeesPre, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, extractedFees, totalFees, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, finalCall;
|
|
11196
10454
|
return _regenerator().w(function (_context3) {
|
|
11197
10455
|
while (1) switch (_context3.n) {
|
|
@@ -11261,14 +10519,14 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
11261
10519
|
}));
|
|
11262
10520
|
case 3:
|
|
11263
10521
|
firstDryRunResult = _context3.v;
|
|
11264
|
-
if (!(firstDryRunResult.
|
|
10522
|
+
if (!(((_firstDryRunResult$dr = firstDryRunResult.dryRunError) === null || _firstDryRunResult$dr === void 0 ? void 0 : _firstDryRunResult$dr.reason) === 'NotHoldingFees')) {
|
|
11265
10523
|
_context3.n = 4;
|
|
11266
10524
|
break;
|
|
11267
10525
|
}
|
|
11268
10526
|
throw new AmountTooLowError("Asset amount is too low to cover the fees, please increase the amount.");
|
|
11269
10527
|
case 4:
|
|
11270
10528
|
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult, exchangeChain, destChain);
|
|
11271
|
-
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false); // Set originFee from dry run origin fee (padded), same as handleExecuteTransfer
|
|
10529
|
+
extractedFees = extractFeesFromDryRun(chain, exchangeChain, firstDryRunResult, exchangeHopIndex, destChain, false); // Set originFee from dry run origin fee (padded), same as handleExecuteTransfer
|
|
11272
10530
|
extractedFees.originFee = feeAssetInfo && firstDryRunResult.origin.success ? padValueBy(firstDryRunResult.origin.fee, FEE_PADDING_PERCENTAGE) : 0n;
|
|
11273
10531
|
if (extractedFees.exchangeFee === 0n) {
|
|
11274
10532
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
@@ -11401,7 +10659,7 @@ var throwUnsupportedCurrency = function throwUnsupportedCurrency(currency, chain
|
|
|
11401
10659
|
},
|
|
11402
10660
|
isDestination = _ref.isDestination;
|
|
11403
10661
|
if ('location' in currency) {
|
|
11404
|
-
throw new InvalidCurrencyError("\n Selected chain doesn't support location you provided.
|
|
10662
|
+
throw new InvalidCurrencyError("\n Selected chain doesn't support location you provided. If you meant a custom location, register it with the 'customAssets' Builder option instead.");
|
|
11405
10663
|
}
|
|
11406
10664
|
throw new InvalidCurrencyError("".concat(isDestination ? 'Destination' : 'Origin', " chain ").concat(chain, " does not support currency ").concat(JSON.stringify(currency, replaceBigInt), "."));
|
|
11407
10665
|
};
|
|
@@ -12190,13 +11448,12 @@ var getXTokensParams = function getXTokensParams(isMultiAssetTransfer, currencyS
|
|
|
12190
11448
|
dest_weight_limit: weightLimit
|
|
12191
11449
|
};
|
|
12192
11450
|
}
|
|
12193
|
-
var
|
|
12194
|
-
var
|
|
12195
|
-
var feeAssetIndex = isOverriddenMultiAssets ? overriddenAsset.findIndex(function (asset) {
|
|
11451
|
+
var assetKey = overriddenAsset ? 'assets' : 'asset';
|
|
11452
|
+
var feeAssetIndex = overriddenAsset ? overriddenAsset.findIndex(function (asset) {
|
|
12196
11453
|
return asset.isFeeAsset;
|
|
12197
11454
|
}) : undefined;
|
|
12198
11455
|
var feeIndexWithFallback = feeAssetIndex === -1 ? 0 : feeAssetIndex;
|
|
12199
|
-
return _objectSpread2(_objectSpread2(_defineProperty({}, assetKey, currencySelection),
|
|
11456
|
+
return _objectSpread2(_objectSpread2(_defineProperty({}, assetKey, currencySelection), overriddenAsset && {
|
|
12200
11457
|
fee_item: feeIndexWithFallback
|
|
12201
11458
|
}), {}, {
|
|
12202
11459
|
dest: versionedDestLocation,
|
|
@@ -12204,29 +11461,23 @@ var getXTokensParams = function getXTokensParams(isMultiAssetTransfer, currencyS
|
|
|
12204
11461
|
});
|
|
12205
11462
|
};
|
|
12206
11463
|
|
|
12207
|
-
var shouldUseMultiAssetTransfer = function shouldUseMultiAssetTransfer(_ref) {
|
|
12208
|
-
var overriddenAsset = _ref.overriddenAsset,
|
|
12209
|
-
useMultiAssetTransfer = _ref.useMultiAssetTransfer;
|
|
12210
|
-
var isOverriddenMultiAssets = overriddenAsset && !isTLocation(overriddenAsset);
|
|
12211
|
-
return useMultiAssetTransfer || !!isOverriddenMultiAssets;
|
|
12212
|
-
};
|
|
12213
11464
|
var getXTokensMethod = function getXTokensMethod(useMultiAsset, overriddenAsset) {
|
|
12214
11465
|
if (!useMultiAsset) return 'transfer';
|
|
12215
|
-
|
|
12216
|
-
return isOverriddenMultiAssets ? 'transfer_multiassets' : 'transfer_multiasset';
|
|
11466
|
+
return overriddenAsset ? 'transfer_multiassets' : 'transfer_multiasset';
|
|
12217
11467
|
};
|
|
12218
11468
|
var buildXTokensCall = function buildXTokensCall(input, currencySelection, fees) {
|
|
12219
11469
|
var api = input.api,
|
|
12220
11470
|
origin = input.origin,
|
|
12221
11471
|
destination = input.destination,
|
|
12222
11472
|
overriddenAsset = input.overriddenAsset,
|
|
11473
|
+
useMultiAssetTransfer = input.useMultiAssetTransfer,
|
|
12223
11474
|
recipient = input.recipient,
|
|
12224
11475
|
asset = input.asset,
|
|
12225
11476
|
pallet = input.pallet,
|
|
12226
11477
|
version = input.version,
|
|
12227
11478
|
paraIdTo = input.paraIdTo,
|
|
12228
11479
|
methodOverride = input.method;
|
|
12229
|
-
var useMultiAsset =
|
|
11480
|
+
var useMultiAsset = useMultiAssetTransfer || !!overriddenAsset;
|
|
12230
11481
|
var modifiedCurrencySelection = useMultiAsset ? getModifiedCurrencySelection(input) : currencySelection;
|
|
12231
11482
|
var method = getXTokensMethod(useMultiAsset, overriddenAsset);
|
|
12232
11483
|
var destLocation = createBeneficiaryLocXTokens({
|
|
@@ -13046,7 +12297,7 @@ var createTypeAndThenTransfer = /*#__PURE__*/function () {
|
|
|
13046
12297
|
assertAddressIsString(recipient);
|
|
13047
12298
|
assertSender(sender);
|
|
13048
12299
|
_context.n = 1;
|
|
13049
|
-
return generateMessageId(api, sender, getParaId(chain), ethAsset.assetId, recipient, asset.amount);
|
|
12300
|
+
return generateMessageId(api, sender, api.getParaId(chain), ethAsset.assetId, recipient, asset.amount);
|
|
13050
12301
|
case 1:
|
|
13051
12302
|
messageId = _context.v;
|
|
13052
12303
|
_context.n = 2;
|
|
@@ -13741,7 +12992,6 @@ var chains = function chains() {
|
|
|
13741
12992
|
|
|
13742
12993
|
var MIN_FEE = 1000n;
|
|
13743
12994
|
var DEFAULT_FEE_ASSET = 0;
|
|
13744
|
-
var RELAYCHAIN_PARA_ID = 0;
|
|
13745
12995
|
var ETH_MAINNET_PARA_ID = 1;
|
|
13746
12996
|
var ETH_MAINNET_CHAIN_ID = BigInt(ETH_MAINNET_PARA_ID);
|
|
13747
12997
|
var ETH_TESTNET_PARA_ID = 11155111;
|
|
@@ -13792,19 +13042,33 @@ var EVM_DEV_PRIVATE_KEYS = {
|
|
|
13792
13042
|
};
|
|
13793
13043
|
|
|
13794
13044
|
/**
|
|
13795
|
-
* Retrieves the chain
|
|
13045
|
+
* Retrieves the chain instance for a given chain.
|
|
13796
13046
|
*
|
|
13797
|
-
* @param
|
|
13798
|
-
* @returns The chain
|
|
13047
|
+
* @param chain - The chain identifier.
|
|
13048
|
+
* @returns The chain instance
|
|
13799
13049
|
*/
|
|
13800
|
-
var
|
|
13801
|
-
var
|
|
13802
|
-
|
|
13803
|
-
|
|
13804
|
-
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13050
|
+
var getChain = function getChain(chain) {
|
|
13051
|
+
var map = chains();
|
|
13052
|
+
return map[chain];
|
|
13053
|
+
};
|
|
13054
|
+
|
|
13055
|
+
/**
|
|
13056
|
+
* Gets the relay chain (Polkadot, Kusama, Westend, or Paseo) of a given chain.
|
|
13057
|
+
*
|
|
13058
|
+
* @param chain - The chain to evaluate.
|
|
13059
|
+
* @returns The corresponding relay chain.
|
|
13060
|
+
*/
|
|
13061
|
+
var getRelayChainOf = function getRelayChainOf(chain) {
|
|
13062
|
+
return getChain(chain).ecosystem;
|
|
13063
|
+
};
|
|
13064
|
+
var getRelayChainOfImpl = function getRelayChainOfImpl(api, chain) {
|
|
13065
|
+
if (isCustomChain(chain)) {
|
|
13066
|
+
var _api$_customCtx$custo;
|
|
13067
|
+
var customEntry = (_api$_customCtx$custo = api._customCtx.customChains) === null || _api$_customCtx$custo === void 0 ? void 0 : _api$_customCtx$custo[chain];
|
|
13068
|
+
if (customEntry) return customEntry.ecosystem;
|
|
13069
|
+
throw new CustomChainInvalidError("Custom chain '".concat(chain, "' is not registered."));
|
|
13070
|
+
}
|
|
13071
|
+
return getChain(chain).ecosystem;
|
|
13808
13072
|
};
|
|
13809
13073
|
|
|
13810
13074
|
var getAssetReserveChainInner = function getAssetReserveChainInner(chain, assetLocation, resolveExternalReserve, resolveRelay) {
|
|
@@ -14124,7 +13388,6 @@ var overrideTxAmount = /*#__PURE__*/function () {
|
|
|
14124
13388
|
while (1) switch (_context.n) {
|
|
14125
13389
|
case 0:
|
|
14126
13390
|
currency = options.currency;
|
|
14127
|
-
assertNotRawAssets(currency);
|
|
14128
13391
|
overrideAmount = function overrideAmount(item) {
|
|
14129
13392
|
return computeOverridenAmount(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
14130
13393
|
currency: item
|
|
@@ -14254,8 +13517,8 @@ var createChainClient = /*#__PURE__*/function () {
|
|
|
14254
13517
|
};
|
|
14255
13518
|
}();
|
|
14256
13519
|
|
|
14257
|
-
var
|
|
14258
|
-
if (
|
|
13520
|
+
var getErrorInstruction = function getErrorInstruction(message, index) {
|
|
13521
|
+
if (index === undefined || _typeof(message) !== 'object' || message === null) {
|
|
14259
13522
|
return undefined;
|
|
14260
13523
|
}
|
|
14261
13524
|
var instructions = message;
|
|
@@ -14263,9 +13526,14 @@ var getFailingInstruction = function getFailingInstruction(message, failureIndex
|
|
|
14263
13526
|
instructions = 'value' in message && Array.isArray(message.value) ? message.value : Object.values(message)[0];
|
|
14264
13527
|
}
|
|
14265
13528
|
if (!Array.isArray(instructions)) return undefined;
|
|
14266
|
-
var instruction = instructions[
|
|
13529
|
+
var instruction = instructions[index];
|
|
14267
13530
|
return _typeof(instruction) === 'object' && instruction !== null ? instruction : undefined;
|
|
14268
13531
|
};
|
|
13532
|
+
var buildDryRunError = function buildDryRunError(error, message) {
|
|
13533
|
+
return _objectSpread2(_objectSpread2({}, error), {}, {
|
|
13534
|
+
instruction: getErrorInstruction(message, error.instructionIndex)
|
|
13535
|
+
});
|
|
13536
|
+
};
|
|
14269
13537
|
|
|
14270
13538
|
var resolveModuleError = function resolveModuleError(chain, error) {
|
|
14271
13539
|
var palletDetails = getSupportedPalletsDetails(chain).find(function (p) {
|
|
@@ -14281,26 +13549,26 @@ var resolveModuleError = function resolveModuleError(chain, error) {
|
|
|
14281
13549
|
if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
|
|
14282
13550
|
throw new UnsupportedOperationError("Pallet ".concat(name, " is not supported"));
|
|
14283
13551
|
}
|
|
14284
|
-
var
|
|
14285
|
-
if (!
|
|
13552
|
+
var reason = name === 'XTokens' ? Object.values(XTokensError)[errorIndex] : Object.values(PolkadotXcmError)[errorIndex];
|
|
13553
|
+
if (!reason) {
|
|
14286
13554
|
throw new RoutingResolutionError("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
|
|
14287
13555
|
}
|
|
14288
|
-
if (
|
|
13556
|
+
if (reason === PolkadotXcmError.LocalExecutionIncompleteWithError) {
|
|
14289
13557
|
// Byte layout: [pallet error variant][instruction index][xcm sub-error]
|
|
14290
|
-
var
|
|
13558
|
+
var instructionIndex = Number("0x".concat(error.error.slice(4, 6)));
|
|
14291
13559
|
var subErrorIndex = Number("0x".concat(error.error.slice(6, 8)));
|
|
14292
|
-
var
|
|
14293
|
-
if (!
|
|
13560
|
+
var subReason = Object.values(PolkadotXcmExecutionError)[subErrorIndex];
|
|
13561
|
+
if (!subReason) {
|
|
14294
13562
|
throw new RoutingResolutionError("Sub-error index ".concat(subErrorIndex, " not found in PolkadotXcm pallet"));
|
|
14295
13563
|
}
|
|
14296
13564
|
return {
|
|
14297
|
-
|
|
14298
|
-
|
|
14299
|
-
|
|
13565
|
+
reason: reason,
|
|
13566
|
+
subReason: subReason,
|
|
13567
|
+
instructionIndex: instructionIndex
|
|
14300
13568
|
};
|
|
14301
13569
|
}
|
|
14302
13570
|
return {
|
|
14303
|
-
|
|
13571
|
+
reason: reason
|
|
14304
13572
|
};
|
|
14305
13573
|
};
|
|
14306
13574
|
|
|
@@ -15107,4 +14375,4 @@ var createClientCache = function createClientCache(maxSize, pingClient, onEvicti
|
|
|
15107
14375
|
};
|
|
15108
14376
|
};
|
|
15109
14377
|
|
|
15110
|
-
export { API_TYPES, AmountTooLowError, ApiNotInitializedError,
|
|
14378
|
+
export { API_TYPES, AmountTooLowError, ApiNotInitializedError, BaseAssetsPallet, BatchMode, BatchValidationError, BridgeHaltedError, Builder, CustomChainConflictError, CustomChainInvalidError, DEFAULT_TTL_MS, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETH_MAINNET_CHAIN_ID, ETH_TESTNET_CHAIN_ID, EXCHANGE_CHAINS, EXTENSION_MS, ExtensionNotInstalledError, FeatureTemporarilyDisabledError, GeneralBuilder, InvalidAddressError, MAX_CLIENTS, MissingChainApiError, MissingParameterError, NoXCMSupportImplementedError, NumberFormatError, OverrideConflictError, PolkadotApi, PolkadotXcmError, PolkadotXcmExecutionError, ProviderUnavailableError, RELAY_LOCATION, RoutingResolutionError, RuntimeApiError, RuntimeApiUnavailableError, ScenarioNotSupportedError, SubmitTransactionError, TRANSACT_ORIGINS, TX_CLIENT_TIMEOUT_MS, TypeAndThenUnavailableError, UnableToComputeError, UnsupportedOperationError, ValidationError, XTokensError, abstractDecimals, addEthereumBridgeFees, addXcmVersionHeader, aggregateHopFees, applyDecimalAbstraction, assertAddressIsString, assertCurrencyCore, assertEvmAddress, assertExtensionInstalled, assertHasId, assertNotEvmTransfer, assertSender, assertSenderSource, assertSubstrateOrigin, assertSwapSupport, assertToIsString, blake2b256, blake2b512, buildCustomChainAssetsInfo, buildCustomChainConfig, buildDestInfo, buildDryRunError, buildHopInfo, buildOriginInfo, calcPreviewMintAmount, compareAddresses, computeOverridenAmount, constructTypeAndThenCall, convertBuilderConfig, convertSs58, createAsset, createAssetId, createAssetsFilter, createBaseExecuteXcm, createBeneficiaryLocXTokens, createBeneficiaryLocation, createChainClient, createClientCache, createClientPoolHelpers, createCustomXcmOnDest, createDestination, createDirectExecuteXcm, createEthereumBridgeInstructions, createExecuteCall, createExecuteExchangeXcm, createSwapBuilder, createTransfer, createTransferOrSwap, createTransferOrSwapAll, createTxOverrideAmount, createTypeAndThenCall, createTypeThenAutoReserve, createVersionedAssets, createVersionedDestination, createX1Payload, deriveAccountId, dryRun, dryRunInternal, dryRunOrigin, encodeSs58, executeWithSwap, formatAssetIdToERC20, formatUnits, generateMessageId, getAssetBalanceInternal, getAssetReserveChain, getAssetReserveChainImpl, getBalance, getBalanceInternal, getBridgeStatus, getChain, getChainConfig, getChainConfigImpl, getChainLocation, getChainProviders, getChainProvidersImpl, getChainVersion, getDryRunError, getErrorInstruction, getEthErc20Balance, getEvmExtensionOrThrow, getEvmPrivateKeyHex, getEvmSnowbridgeExtensionOrThrow, getLocalTransferAmount, getMinTransferableAmount, getMinTransferableAmountInternal, getMoonbeamErc20Balance, getOriginXcmFee, getOriginXcmFeeInternal, getParaEthTransferFees, getParaId, getParaIdImpl, getRelayChainOf, getRelayChainOfImpl, getRelayChainSymbolOf, getSwapExtensionOrThrow, getTChain, getTSubstrateChain, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeInternal, getXcmFeeOnce, handleExecuteTransfer, handleSwapExecuteTransfer, handleToAhTeleport, isConfig, isExchange, isNativeAssetTeleport, isSenderSigner, isViemSigner, keyFromWs, localizeLocation, localizeLocationImpl, maybeOverrideAsset, maybeOverrideAssets, normalizeAmount, normalizeCustomChains, normalizeExchange, overrideTxAmount, padFee, padValueBy, parseUnits, pickCompatibleXcmVersion, pickOtherMintPallet, pickRouterCompatibleXcmVersion, registerEvmExtension, registerEvmSnowbridgeExtension, registerSwapExtension, resolveAssetCount, resolveDestChain, resolveModuleError, resolveParaId, resolveTransferParams, reverseTransformLocation, selectXcmVersion, sortAssets, throwUnsupportedCurrency, traverseXcmHops, validateAddress, validateAssetSpecifiers, validateCurrency, validateDestination, validateDestinationAddress, validateTransact, verifyEdOnDestination, wrapTxBypass };
|