@paraspell/sdk-core 11.12.2 → 11.12.4

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/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  import { blake2b } from '@noble/hashes/blake2';
2
- import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, findAssetInfoOrThrow, getNativeAssetSymbol, getOtherAssets, isAssetEqual, findNativeAssetInfoOrThrow, findAssetInfo, isTAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, isOverrideLocationSpecifier, findAssetInfoByLoc, findAssetOnDestOrThrow, findAssetInfoOnDest, Native, hasXcmPaymentApiSupport, getExistentialDeposit, getRelayChainSymbol, findNativeAssetInfo, isAssetXcEqual, hasSupportForAsset, isSymbolSpecifier, normalizeLocation, getEdFromAssetOrThrow, normalizeSymbol } from '@paraspell/assets';
2
+ import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, findAssetInfoOrThrow, getNativeAssetSymbol, getOtherAssets, isAssetEqual, findNativeAssetInfoOrThrow, findAssetInfo, isTAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, findAssetOnDestOrThrow, findAssetInfoOnDest, hasSupportForAsset, isOverrideLocationSpecifier, getRelayChainSymbol, isSymbolSpecifier, findAssetInfoByLoc, Native, hasXcmPaymentApiSupport, getExistentialDeposit, findNativeAssetInfo, isAssetXcEqual, normalizeLocation, getEdFromAssetOrThrow, normalizeSymbol } from '@paraspell/assets';
3
3
  export * from '@paraspell/assets';
4
4
  import { base58 } from '@scure/base';
5
5
  import { isAddress, parseUnits as parseUnits$1, formatUnits as formatUnits$1, createPublicClient, http, getContract, pad, toHex, getAddress, concat, keccak256 } from 'viem';
6
6
  import { getSupportedPalletsDetails, getDefaultPallet, getSupportedPallets, getNativeAssetsPallet, getOtherAssetsPallets } from '@paraspell/pallets';
7
7
  export * from '@paraspell/pallets';
8
- import { replaceBigInt, isTLocation, Version, hasJunction, getJunctionValue, isRelayChain, Parents, PARACHAINS, deepEqual, isTrustedChain, isExternalChain, isDotKsmBridge, isSystemChain } from '@paraspell/sdk-common';
8
+ import { replaceBigInt, isTLocation, Version, hasJunction, getJunctionValue, isRelayChain, Parents, isExternalChain, deepEqual, PARACHAINS, isSubstrateBridge, isTrustedChain, isSystemChain } from '@paraspell/sdk-common';
9
9
  export * from '@paraspell/sdk-common';
10
10
  import { moonbeam, moonriver, mainnet } from 'viem/chains';
11
11
 
@@ -3091,7 +3091,13 @@ var getChainLocation = function getChainLocation(chain, destChain) {
3091
3091
  * @param location - The location to localize
3092
3092
  * @returns The localized location
3093
3093
  */
3094
- var localizeLocation = function localizeLocation(chain, location) {
3094
+ var localizeLocation = function localizeLocation(chain, location, origin) {
3095
+ var targetRelay = isExternalChain(chain) ? undefined : getRelayChainOf(chain).toLowerCase();
3096
+ var originRelay = origin && !isExternalChain(origin) ? getRelayChainOf(origin).toLowerCase() : undefined;
3097
+ var ecosystemDiffers = originRelay !== targetRelay;
3098
+ if (origin && ecosystemDiffers && location.parents === Parents.TWO && originRelay !== undefined && targetRelay !== undefined && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null))) {
3099
+ return RELAY_LOCATION;
3100
+ }
3095
3101
  var newInterior = location.interior;
3096
3102
  var parachainRemoved = false;
3097
3103
  if (location.interior !== 'Here') {
@@ -3115,6 +3121,20 @@ var localizeLocation = function localizeLocation(chain, location) {
3115
3121
  newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
3116
3122
  }
3117
3123
  }
3124
+ var isOriginRelayHere = deepEqual(location, RELAY_LOCATION);
3125
+ var hasGlobalConsensus = hasJunction(location, 'GlobalConsensus');
3126
+ if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus && originRelay !== undefined) {
3127
+ return {
3128
+ parents: Parents.TWO,
3129
+ interior: {
3130
+ X2: [{
3131
+ GlobalConsensus: _defineProperty({}, originRelay, null)
3132
+ }, {
3133
+ Parachain: getParaId(origin)
3134
+ }]
3135
+ }
3136
+ };
3137
+ }
3118
3138
  var shouldSetParentsToZero = parachainRemoved || newInterior === 'Here' && isRelayChain(chain);
3119
3139
  return {
3120
3140
  parents: shouldSetParentsToZero ? Parents.ZERO : location.parents,
@@ -3243,13 +3263,26 @@ var constructRelayToParaParameters = function constructRelayToParaParameters(_re
3243
3263
  };
3244
3264
 
3245
3265
  var createDestination = function createDestination(version, origin, destination, chainId, junction, parents) {
3266
+ var isLocDestination = isTLocation(destination);
3267
+ var isSubBridge = !isLocDestination && !isExternalChain(destination) && isSubstrateBridge(origin, destination);
3268
+ if (isSubBridge) {
3269
+ return {
3270
+ parents: Parents.TWO,
3271
+ interior: {
3272
+ X2: [{
3273
+ GlobalConsensus: getRelayChainOf(destination)
3274
+ }, {
3275
+ Parachain: chainId
3276
+ }]
3277
+ }
3278
+ };
3279
+ }
3246
3280
  var scenario = resolveScenario(origin, destination);
3247
3281
  var parentsResolved = parents !== null && parents !== void 0 ? parents : scenario === 'RelayToPara' ? Parents.ZERO : Parents.ONE;
3248
3282
  var interior = scenario === 'ParaToRelay' ? 'Here' : createX1Payload(version, junction !== null && junction !== void 0 ? junction : {
3249
3283
  Parachain: chainId
3250
3284
  });
3251
- var isLocationDestination = isTLocation(destination);
3252
- return isLocationDestination ? destination : {
3285
+ return isLocDestination ? destination : {
3253
3286
  parents: parentsResolved,
3254
3287
  interior: interior
3255
3288
  };
@@ -3258,19 +3291,6 @@ var createVersionedDestination = function createVersionedDestination(version, or
3258
3291
  var plainDestination = createDestination(version, origin, destination, chainId, junction, parents);
3259
3292
  return addXcmVersionHeader(plainDestination, version);
3260
3293
  };
3261
- var createBridgeDestination = function createBridgeDestination(ecosystem, destination, chainId) {
3262
- var location = {
3263
- parents: Parents.TWO,
3264
- interior: {
3265
- X2: [{
3266
- GlobalConsensus: ecosystem
3267
- }, {
3268
- Parachain: chainId
3269
- }]
3270
- }
3271
- };
3272
- return isTLocation(destination) ? destination : location;
3273
- };
3274
3294
  var resolveTChainFromLocation = function resolveTChainFromLocation(relaychain, location) {
3275
3295
  var _PARACHAINS$find;
3276
3296
  var parachainId = getJunctionValue(location, 'Parachain');
@@ -4499,6 +4519,204 @@ var getDestXcmFee = /*#__PURE__*/function () {
4499
4519
  };
4500
4520
  }();
4501
4521
 
4522
+ var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
4523
+ return assetCheckEnabled ? findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null) : null;
4524
+ };
4525
+
4526
+ var resolveHopAsset = function resolveHopAsset(_ref) {
4527
+ var _asset$location, _findAssetInfoOnDest;
4528
+ var originChain = _ref.originChain,
4529
+ currentChain = _ref.currentChain,
4530
+ swapConfig = _ref.swapConfig,
4531
+ asset = _ref.asset,
4532
+ hasPassedExchange = _ref.hasPassedExchange,
4533
+ currency = _ref.currency;
4534
+ var isExternalAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO;
4535
+ if (isExternalAsset) {
4536
+ return findNativeAssetInfoOrThrow(getRelayChainOf(currentChain));
4537
+ }
4538
+ if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
4539
+ return findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo);
4540
+ }
4541
+ return (_findAssetInfoOnDest = findAssetInfoOnDest(originChain, currentChain, currency)) !== null && _findAssetInfoOnDest !== void 0 ? _findAssetInfoOnDest : asset;
4542
+ };
4543
+
4544
+ var validateBridgeAsset = function validateBridgeAsset(origin, destination, asset, currency, isBridge) {
4545
+ var _asset$location;
4546
+ if (!asset || isTLocation(destination) || isExternalChain(destination) || !isBridge) {
4547
+ return;
4548
+ }
4549
+ var nativeAsset = findNativeAssetInfoOrThrow(origin);
4550
+ var isNativeAsset = isAssetEqual(asset, nativeAsset);
4551
+ var ecosystem = getRelayChainOf(destination).toLowerCase();
4552
+ var isBridgedAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO && deepEqual(getJunctionValue(asset.location, 'GlobalConsensus'), _defineProperty({}, ecosystem, null));
4553
+ if (!(isNativeAsset || isBridgedAsset)) {
4554
+ throw new InvalidCurrencyError("Substrate bridge does not support currency ".concat(JSON.stringify(currency, replaceBigInt), "."));
4555
+ }
4556
+ };
4557
+ var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
4558
+ var origin = _ref.from,
4559
+ destination = _ref.to,
4560
+ currency = _ref.currency;
4561
+ var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
4562
+ var isLocationDestination = _typeof(destination) === 'object';
4563
+ if (!isBridge && !isRelayDestination && !isLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
4564
+ throw new InvalidCurrencyError("Destination chain ".concat(destination, " does not support currency ").concat(JSON.stringify(currency, replaceBigInt), "."));
4565
+ }
4566
+ if (asset === null && assetCheckEnabled) {
4567
+ throwUnsupportedCurrency(currency, origin);
4568
+ }
4569
+ validateBridgeAsset(origin, destination, asset, currency, isBridge);
4570
+ };
4571
+
4572
+ var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
4573
+ var api = options.api,
4574
+ currency = options.currency,
4575
+ feeAsset = options.feeAsset,
4576
+ origin = options.from,
4577
+ destination = options.to;
4578
+ if ('location' in currency && isOverrideLocationSpecifier(currency.location)) {
4579
+ return currency.location.value;
4580
+ }
4581
+ if (Array.isArray(currency)) {
4582
+ if (!feeAsset) {
4583
+ throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
4584
+ }
4585
+ if ('location' in feeAsset && isOverrideLocationSpecifier(feeAsset.location)) {
4586
+ throw new InvalidCurrencyError('Fee asset cannot be an overridden location specifier');
4587
+ }
4588
+ if (currency.every(function (asset) {
4589
+ return isTAsset(asset);
4590
+ })) {
4591
+ if (!feeAsset) {
4592
+ throw new InvalidCurrencyError('Fee asset not provided');
4593
+ }
4594
+ if (!('location' in feeAsset)) {
4595
+ throw new InvalidCurrencyError('Fee asset must be specified by location when using raw overridden multi assets');
4596
+ }
4597
+ return currency.map(function (asset) {
4598
+ var ml = extractAssetLocation(asset);
4599
+ return _objectSpread2(_objectSpread2({}, asset), {}, {
4600
+ fun: {
4601
+ Fungible: BigInt(asset.fun.Fungible)
4602
+ },
4603
+ isFeeAsset: deepEqual(ml, feeAsset.location)
4604
+ });
4605
+ });
4606
+ }
4607
+ // MultiAsset is an array of TCurrencyCore, search for assets
4608
+ var assets = currency.map(function (currency) {
4609
+ if (currency.amount === AMOUNT_ALL) {
4610
+ throw new InvalidCurrencyError('Multi assets cannot use amount all. Please specify amount.');
4611
+ }
4612
+ var asset = findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null);
4613
+ if (!asset) {
4614
+ throw new InvalidCurrencyError("Origin chain ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
4615
+ }
4616
+ assertHasLocation(asset);
4617
+ if (!resolvedFeeAsset) {
4618
+ throw new InvalidCurrencyError('Fee asset not found');
4619
+ }
4620
+ validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
4621
+ var version = getChainVersion(origin);
4622
+ var abstractedAmount = abstractDecimals(currency.amount, asset.decimals, api);
4623
+ return _objectSpread2({
4624
+ isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
4625
+ }, createAsset(version, abstractedAmount, asset.location));
4626
+ });
4627
+ if (assets.filter(function (asset) {
4628
+ return asset.isFeeAsset;
4629
+ }).length > 1) {
4630
+ throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
4631
+ }
4632
+ if (assets.filter(function (asset) {
4633
+ return asset.isFeeAsset;
4634
+ }).length === 0) {
4635
+ throw new InvalidCurrencyError("Fee asset not found in multiassets");
4636
+ }
4637
+ return assets;
4638
+ }
4639
+ return undefined;
4640
+ };
4641
+
4642
+ var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
4643
+ if (forcedVersion) return forcedVersion;
4644
+ var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
4645
+ return destVersion < originVersion ? destVersion : originVersion;
4646
+ };
4647
+
4648
+ var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
4649
+ if (isRelayChain(origin)) return true;
4650
+ var isMultipleAssets = Array.isArray(currency);
4651
+ var hasOverriddenLocation = 'location' in currency && isOverrideLocationSpecifier(currency.location);
4652
+ return !(isMultipleAssets || hasOverriddenLocation);
4653
+ };
4654
+
4655
+ var validateAddress = function validateAddress(address, chain) {
4656
+ var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
4657
+ if (isTLocation(address)) return;
4658
+ var isEvm = isChainEvm(chain);
4659
+ var isEthereumAddress = isAddress(address);
4660
+ if (isEvm) {
4661
+ if (!isEthereumAddress) {
4662
+ throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
4663
+ }
4664
+ } else {
4665
+ if (isEthereumAddress) {
4666
+ throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
4667
+ }
4668
+ }
4669
+ };
4670
+
4671
+ var validateDestinationAddress = function validateDestinationAddress(address, destination) {
4672
+ if (typeof address === 'string' && !isTLocation(destination)) {
4673
+ validateAddress(address, destination);
4674
+ }
4675
+ };
4676
+
4677
+ var validateCurrency = function validateCurrency(currency, feeAsset) {
4678
+ if (Array.isArray(currency)) {
4679
+ if (currency.length === 0) {
4680
+ throw new InvalidCurrencyError('Overridden assets cannot be empty');
4681
+ }
4682
+ if (currency.length === 1) {
4683
+ throw new InvalidCurrencyError('Please provide more than one asset');
4684
+ }
4685
+ if (currency.length > 1 && !currency.every(function (asset) {
4686
+ return isTAsset(asset);
4687
+ }) && !feeAsset) {
4688
+ throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
4689
+ }
4690
+ }
4691
+ };
4692
+ var validateDestination = function validateDestination(origin, destination) {
4693
+ if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
4694
+ throw new IncompatibleChainsError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
4695
+ }
4696
+ var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam', 'Mythos'];
4697
+ if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
4698
+ throw new IncompatibleChainsError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
4699
+ }
4700
+ var isLocationDestination = _typeof(destination) === 'object';
4701
+ var isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
4702
+ var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
4703
+ if (!isRelayDestination && !isLocationDestination) {
4704
+ var originRelayChainSymbol = getRelayChainSymbol(origin);
4705
+ var destinationRelayChainSymbol = getRelayChainSymbol(destination);
4706
+ if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
4707
+ throw new IncompatibleChainsError();
4708
+ }
4709
+ }
4710
+ };
4711
+ var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
4712
+ if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
4713
+ throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
4714
+ }
4715
+ if (!assetCheckEnabled && 'id' in currency) {
4716
+ throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
4717
+ }
4718
+ };
4719
+
4502
4720
  var getFailureInfo$1 = function getFailureInfo(result) {
4503
4721
  var orderedChecks = [{
4504
4722
  chain: 'origin',
@@ -5331,19 +5549,19 @@ var dryRunInternal = /*#__PURE__*/function () {
5331
5549
  initialForwardedXcms = originDryModified.forwardedXcms, initialDestParaId = originDryModified.destParaId;
5332
5550
  processHop = /*#__PURE__*/function () {
5333
5551
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
5334
- var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, _findAssetInfoOnDest, hopDryRun;
5552
+ var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, hopDryRun;
5335
5553
  return _regenerator().w(function (_context) {
5336
5554
  while (1) switch (_context.n) {
5337
5555
  case 0:
5338
5556
  hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange;
5339
- if (asset.location && asset.location.parents === Parents.TWO) {
5340
- hopAsset = findNativeAssetInfoOrThrow(getRelayChainOf(currentChain));
5341
- } else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
5342
- hopAsset = findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo);
5343
- } else {
5344
- hopAsset = asset;
5345
- hopAsset = (_findAssetInfoOnDest = findAssetInfoOnDest(origin, currentChain, currency)) !== null && _findAssetInfoOnDest !== void 0 ? _findAssetInfoOnDest : asset;
5346
- }
5557
+ hopAsset = resolveHopAsset({
5558
+ originChain: origin,
5559
+ currentChain: currentChain,
5560
+ asset: currentAsset,
5561
+ currency: currency,
5562
+ swapConfig: swapConfig,
5563
+ hasPassedExchange: hasPassedExchange
5564
+ });
5347
5565
  if (hasDryRunSupport(currentChain)) {
5348
5566
  _context.n = 1;
5349
5567
  break;
@@ -5907,22 +6125,6 @@ var handleToAhTeleport = /*#__PURE__*/function () {
5907
6125
  };
5908
6126
  }();
5909
6127
 
5910
- var validateAddress = function validateAddress(address, chain) {
5911
- var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
5912
- if (isTLocation(address)) return;
5913
- var isEvm = isChainEvm(chain);
5914
- var isEthereumAddress = isAddress(address);
5915
- if (isEvm) {
5916
- if (!isEthereumAddress) {
5917
- throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
5918
- }
5919
- } else {
5920
- if (isEthereumAddress) {
5921
- throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
5922
- }
5923
- }
5924
- };
5925
-
5926
6128
  var resolveLocationFromDest = function resolveLocationFromDest(destination, asset) {
5927
6129
  if (_typeof(destination) === 'object') return destination;
5928
6130
  if (isRelayChain(destination)) return DOT_LOCATION;
@@ -6229,15 +6431,16 @@ var Parachain = /*#__PURE__*/function () {
6229
6431
  }, {
6230
6432
  key: "canUseXTokens",
6231
6433
  value: function canUseXTokens(options) {
6434
+ var _asset$location;
6232
6435
  var asset = options.assetInfo;
6233
- var isExternalAsset = asset.location && asset.location.parents === Parents.TWO;
6436
+ var isExternalAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO;
6234
6437
  return !isExternalAsset && !this.shouldUseNativeAssetTeleport(options);
6235
6438
  }
6236
6439
  }, {
6237
6440
  key: "transfer",
6238
6441
  value: function () {
6239
6442
  var _transfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(sendOptions) {
6240
- var api, asset, currency, feeAsset, feeCurrency, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, scenario, paraId, destChain, isLocalTransfer, isRelayAsset, supportsTypeThen, useTypeAndThen, isBifrostOrigin, isJamtonOrigin, isAssetHubDest, useMultiAssets, input, options, shouldUseTeleport, isAhToOtherPara, isOtherParaToAh, isAllowedAhTransfer, isAHPOrigin, isAHPDest, isExternalAsset, isEthDest, isExternalAssetViaAh, isExternalAssetToAh, call, _t;
6443
+ var api, asset, currency, feeAsset, feeCurrency, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, scenario, paraId, destChain, isLocalTransfer, isRelayAsset, supportsTypeThen, isSubBridge, useTypeAndThen, isBifrostOrigin, isJamtonOrigin, isAssetHubDest, useMultiAssets, input, _asset$location2, options, shouldUseTeleport, isAhToOtherPara, isOtherParaToAh, isAllowedAhTransfer, isAHOrigin, isAHDest, isExternalAsset, isEthDest, isExternalAssetViaAh, isExternalAssetToAh, call, _t;
6241
6444
  return _regenerator().w(function (_context) {
6242
6445
  while (1) switch (_context.n) {
6243
6446
  case 0:
@@ -6271,7 +6474,8 @@ var Parachain = /*#__PURE__*/function () {
6271
6474
  }
6272
6475
  throw new InvalidParameterError('Relaychain assets can only be transferred using the type-and-then method which is not supported by this chain');
6273
6476
  case 4:
6274
- useTypeAndThen = isRelayAsset && supportsTypeThen && destChain && !feeAsset && (!isTrustedChain(this.chain) || !isTrustedChain(destChain));
6477
+ isSubBridge = !isTLocation(destination) && isSubstrateBridge(this.chain, destination);
6478
+ useTypeAndThen = isRelayAsset && supportsTypeThen && destChain && !feeAsset && (!isTrustedChain(this.chain) || !isTrustedChain(destChain)) || isSubBridge;
6275
6479
  if (!(supportsXTokens(this) && this.canUseXTokens(sendOptions) && !useTypeAndThen)) {
6276
6480
  _context.n = 6;
6277
6481
  break;
@@ -6364,17 +6568,17 @@ var Parachain = /*#__PURE__*/function () {
6364
6568
  }
6365
6569
  throw new InvalidParameterError('Astar system asset transfers are temporarily disabled');
6366
6570
  case 9:
6367
- isAHPOrigin = this.chain.includes('AssetHub');
6368
- isAHPDest = !isTLocation(destination) && destination.includes('AssetHub'); // Handle common cases
6369
- isExternalAsset = asset.location && asset.location.parents === Parents.TWO;
6571
+ isAHOrigin = this.chain.includes('AssetHub');
6572
+ isAHDest = !isTLocation(destination) && destination.includes('AssetHub'); // Handle common cases
6573
+ isExternalAsset = ((_asset$location2 = asset.location) === null || _asset$location2 === void 0 ? void 0 : _asset$location2.parents) === Parents.TWO;
6370
6574
  isEthDest = destination === 'Ethereum'; // External asset - Any origin to any dest via AH - DestinationReserve - multiple instructions
6371
- isExternalAssetViaAh = isExternalAsset && !isAHPOrigin && !isAHPDest && !isEthDest && !feeAsset; // External asset - Any origin to AHP - DestinationReserve - one DepositAsset instruction
6372
- isExternalAssetToAh = isExternalAsset && isAHPDest && !isAHPOrigin && !isEthDest && !feeAsset;
6575
+ isExternalAssetViaAh = isExternalAsset && !isAHOrigin && !isAHDest && !isEthDest && !feeAsset; // External asset - Any origin to AHP - DestinationReserve - one DepositAsset instruction
6576
+ isExternalAssetToAh = isExternalAsset && isAHDest && !isAHOrigin && !isEthDest && !feeAsset;
6373
6577
  if (!(isExternalAssetViaAh || isExternalAssetToAh || useTypeAndThen)) {
6374
6578
  _context.n = 15;
6375
6579
  break;
6376
6580
  }
6377
- if (!(useTypeAndThen && supportsPolkadotXCM(this))) {
6581
+ if (!(useTypeAndThen && supportsPolkadotXCM(this) && !isSubBridge)) {
6378
6582
  _context.n = 10;
6379
6583
  break;
6380
6584
  }
@@ -6461,7 +6665,7 @@ var Parachain = /*#__PURE__*/function () {
6461
6665
  value: function shouldUseNativeAssetTeleport(_ref) {
6462
6666
  var asset = _ref.assetInfo,
6463
6667
  to = _ref.to;
6464
- if (isTLocation(to) || isDotKsmBridge(this.chain, to) || to === 'Ethereum') return false;
6668
+ if (isTLocation(to) || isSubstrateBridge(this.chain, to) || to === 'Ethereum') return false;
6465
6669
  var isAHPOrigin = this.chain.includes('AssetHub');
6466
6670
  var isAHPDest = !isTLocation(to) && to.includes('AssetHub');
6467
6671
  var isNativeAsset = !isTLocation(to) && (isAHPOrigin && isForeignAsset(asset) && isSymbolMatch(asset.symbol, getNativeAssetSymbol(to)) || isAHPDest && !isForeignAsset(asset) && isSymbolMatch(asset.symbol, getNativeAssetSymbol(this.chain)));
@@ -6557,51 +6761,57 @@ var Parachain = /*#__PURE__*/function () {
6557
6761
  key: "transferLocal",
6558
6762
  value: function () {
6559
6763
  var _transferLocal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
6560
- var api, asset, address, senderAddress, currency, isAmountAll, validatedOptions, isNativeAsset, balance, localOptions;
6764
+ var api, asset, feeAsset, address, senderAddress, currency, isAmountAll, validatedOptions, isNativeAsset, balance, localOptions;
6561
6765
  return _regenerator().w(function (_context3) {
6562
6766
  while (1) switch (_context3.n) {
6563
6767
  case 0:
6564
- api = options.api, asset = options.assetInfo, address = options.address, senderAddress = options.senderAddress, currency = options.currency, isAmountAll = options.isAmountAll;
6768
+ api = options.api, asset = options.assetInfo, feeAsset = options.feeAsset, address = options.address, senderAddress = options.senderAddress, currency = options.currency, isAmountAll = options.isAmountAll;
6565
6769
  if (!isTLocation(address)) {
6566
6770
  _context3.n = 1;
6567
6771
  break;
6568
6772
  }
6569
6773
  throw new InvalidAddressError('Location address is not supported for local transfers');
6570
6774
  case 1:
6775
+ if (!feeAsset) {
6776
+ _context3.n = 2;
6777
+ break;
6778
+ }
6779
+ throw new InvalidParameterError('Fee asset is not supported for local transfers');
6780
+ case 2:
6571
6781
  validatedOptions = _objectSpread2(_objectSpread2({}, options), {}, {
6572
6782
  address: address
6573
6783
  });
6574
6784
  isNativeAsset = asset.symbol === this.getNativeAssetSymbol() && !isForeignAsset(asset);
6575
6785
  if (!isAmountAll) {
6576
- _context3.n = 3;
6786
+ _context3.n = 4;
6577
6787
  break;
6578
6788
  }
6579
6789
  assertSenderAddress(senderAddress);
6580
- _context3.n = 2;
6790
+ _context3.n = 3;
6581
6791
  return getAssetBalanceInternal({
6582
6792
  api: api,
6583
6793
  chain: this.chain,
6584
6794
  address: senderAddress,
6585
6795
  currency: currency
6586
6796
  });
6587
- case 2:
6797
+ case 3:
6588
6798
  balance = _context3.v;
6589
- _context3.n = 4;
6799
+ _context3.n = 5;
6590
6800
  break;
6591
- case 3:
6592
- balance = MIN_AMOUNT;
6593
6801
  case 4:
6802
+ balance = MIN_AMOUNT;
6803
+ case 5:
6594
6804
  localOptions = _objectSpread2(_objectSpread2({}, validatedOptions), {}, {
6595
6805
  balance: balance
6596
6806
  });
6597
6807
  if (!isNativeAsset) {
6598
- _context3.n = 5;
6808
+ _context3.n = 6;
6599
6809
  break;
6600
6810
  }
6601
6811
  return _context3.a(2, this.transferLocalNativeAsset(localOptions));
6602
- case 5:
6603
- return _context3.a(2, this.transferLocalNonNativeAsset(localOptions));
6604
6812
  case 6:
6813
+ return _context3.a(2, this.transferLocalNonNativeAsset(localOptions));
6814
+ case 7:
6605
6815
  return _context3.a(2);
6606
6816
  }
6607
6817
  }, _callee3, this);
@@ -7102,9 +7312,6 @@ var AssetHubKusama = /*#__PURE__*/function (_Parachain) {
7102
7312
  scenario = input.scenario;
7103
7313
  // TESTED https://kusama.subscan.io/xcm_message/kusama-ddc2a48f0d8e0337832d7aae26f6c3053e1f4ffd
7104
7314
  // TESTED https://kusama.subscan.io/xcm_message/kusama-8e423130a4d8b61679af95dbea18a55124f99672
7105
- if (destination === 'AssetHubPolkadot') {
7106
- return getChain('AssetHubPolkadot').handleBridgeTransfer(input, 'Polkadot');
7107
- }
7108
7315
  if (scenario === 'ParaToPara' && asset.symbol === 'DOT' && !isForeignAsset(asset)) {
7109
7316
  throw new ScenarioNotSupportedError(this.chain, scenario, 'Bridged DOT cannot currently be transfered from AssetHubKusama, if you are sending different DOT asset, please specify {id: <DOTID>}.');
7110
7317
  }
@@ -7150,36 +7357,6 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7150
7357
  }
7151
7358
  _inherits(AssetHubPolkadot, _Parachain);
7152
7359
  return _createClass(AssetHubPolkadot, [{
7153
- key: "handleBridgeTransfer",
7154
- value: function handleBridgeTransfer(input, targetChain) {
7155
- var _asset$symbol, _asset$symbol2, _asset$symbol3;
7156
- var api = input.api,
7157
- asset = input.assetInfo,
7158
- destination = input.destination,
7159
- address = input.address,
7160
- version = input.version,
7161
- paraIdTo = input.paraIdTo;
7162
- if (targetChain === 'Kusama' && ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toUpperCase()) === 'KSM' || targetChain === 'Polkadot' && ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toUpperCase()) === 'DOT') {
7163
- var modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
7164
- destLocation: createBridgeDestination(targetChain, destination, paraIdTo),
7165
- beneficiaryLocation: createBeneficiaryLocation({
7166
- api: api,
7167
- address: address,
7168
- version: version
7169
- }),
7170
- asset: createAsset(version, asset.amount, asset.location)
7171
- });
7172
- return transferPolkadotXcm(modifiedInput, 'transfer_assets', 'Unlimited');
7173
- } else if (targetChain === 'Polkadot' && ((_asset$symbol3 = asset.symbol) === null || _asset$symbol3 === void 0 ? void 0 : _asset$symbol3.toUpperCase()) === 'KSM' || targetChain === 'Kusama' && 'DOT') {
7174
- var _modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
7175
- destLocation: createBridgeDestination(targetChain, destination, paraIdTo),
7176
- asset: createAsset(version, asset.amount, DOT_LOCATION)
7177
- });
7178
- return transferPolkadotXcm(_modifiedInput, 'limited_reserve_transfer_assets', 'Unlimited');
7179
- }
7180
- throw new InvalidCurrencyError("Polkadot <-> Kusama bridge does not support currency ".concat(asset.symbol));
7181
- }
7182
- }, {
7183
7360
  key: "handleEthBridgeNativeTransfer",
7184
7361
  value: function () {
7185
7362
  var _handleEthBridgeNativeTransfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
@@ -7384,52 +7561,46 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7384
7561
  case 4:
7385
7562
  return _context3.a(2, _t.callTxMethod.call(_t, _context3.v));
7386
7563
  case 5:
7387
- if (!(destination === 'AssetHubKusama')) {
7388
- _context3.n = 6;
7389
- break;
7390
- }
7391
- return _context3.a(2, this.handleBridgeTransfer(options, 'Kusama'));
7392
- case 6:
7393
7564
  if (!(destination === 'Ethereum')) {
7394
- _context3.n = 7;
7565
+ _context3.n = 6;
7395
7566
  break;
7396
7567
  }
7397
7568
  return _context3.a(2, this.handleEthBridgeTransfer(options));
7398
- case 7:
7569
+ case 6:
7399
7570
  if (!(destination === 'Mythos')) {
7400
- _context3.n = 8;
7571
+ _context3.n = 7;
7401
7572
  break;
7402
7573
  }
7403
7574
  return _context3.a(2, this.handleMythosTransfer(options));
7404
- case 8:
7575
+ case 7:
7405
7576
  isExternalAsset = assetInfo.location && assetInfo.location.parents === Parents.TWO;
7406
7577
  if (!isExternalAsset) {
7407
- _context3.n = 10;
7578
+ _context3.n = 9;
7408
7579
  break;
7409
7580
  }
7410
- _context3.n = 9;
7581
+ _context3.n = 8;
7411
7582
  return createTypeAndThenCall(this.chain, options);
7412
- case 9:
7583
+ case 8:
7413
7584
  _call = _context3.v;
7414
7585
  return _context3.a(2, api.callTxMethod(_call));
7415
- case 10:
7586
+ case 9:
7416
7587
  if (!(scenario === 'ParaToPara' && assetInfo.symbol === 'KSM' && !isForeignAsset(assetInfo))) {
7417
- _context3.n = 11;
7588
+ _context3.n = 10;
7418
7589
  break;
7419
7590
  }
7420
7591
  throw new ScenarioNotSupportedError(this.chain, scenario, 'Bridged KSM cannot currently be transfered from AssetHubPolkadot, if you are sending different KSM asset, please specify {id: <KSMID>}.');
7421
- case 11:
7592
+ case 10:
7422
7593
  method = this.getMethod(scenario, destination); // Patch transfer_assets to use type_and_then transfer
7423
7594
  if (!(method === 'transfer_assets' && isSymbolMatch(assetInfo.symbol, getRelayChainSymbol(this.chain)))) {
7424
- _context3.n = 13;
7595
+ _context3.n = 12;
7425
7596
  break;
7426
7597
  }
7427
7598
  _t2 = api;
7428
- _context3.n = 12;
7599
+ _context3.n = 11;
7429
7600
  return createTypeAndThenCall(this.chain, options);
7430
- case 12:
7601
+ case 11:
7431
7602
  return _context3.a(2, _t2.callTxMethod.call(_t2, _context3.v));
7432
- case 13:
7603
+ case 12:
7433
7604
  modifiedInput = this.patchInput(options);
7434
7605
  return _context3.a(2, transferPolkadotXcm(modifiedInput, method, 'Unlimited'));
7435
7606
  }
@@ -11127,156 +11298,6 @@ var getOriginXcmFee = /*#__PURE__*/function () {
11127
11298
  };
11128
11299
  }();
11129
11300
 
11130
- var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
11131
- return assetCheckEnabled ? findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null) : null;
11132
- };
11133
-
11134
- var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
11135
- var origin = _ref.from,
11136
- destination = _ref.to,
11137
- currency = _ref.currency;
11138
- var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
11139
- var isLocationDestination = _typeof(destination) === 'object';
11140
- if (!isBridge && !isRelayDestination && !isLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
11141
- throw new InvalidCurrencyError("Destination chain ".concat(destination, " does not support currency ").concat(JSON.stringify(currency, replaceBigInt), "."));
11142
- }
11143
- if (!isBridge && asset === null && assetCheckEnabled) {
11144
- throwUnsupportedCurrency(currency, origin);
11145
- }
11146
- };
11147
-
11148
- var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
11149
- var api = options.api,
11150
- currency = options.currency,
11151
- feeAsset = options.feeAsset,
11152
- origin = options.from,
11153
- destination = options.to;
11154
- if ('location' in currency && isOverrideLocationSpecifier(currency.location)) {
11155
- return currency.location.value;
11156
- }
11157
- if (Array.isArray(currency)) {
11158
- if (!feeAsset) {
11159
- throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
11160
- }
11161
- if ('location' in feeAsset && isOverrideLocationSpecifier(feeAsset.location)) {
11162
- throw new InvalidCurrencyError('Fee asset cannot be an overridden location specifier');
11163
- }
11164
- if (currency.every(function (asset) {
11165
- return isTAsset(asset);
11166
- })) {
11167
- if (!feeAsset) {
11168
- throw new InvalidCurrencyError('Fee asset not provided');
11169
- }
11170
- if (!('location' in feeAsset)) {
11171
- throw new InvalidCurrencyError('Fee asset must be specified by location when using raw overridden multi assets');
11172
- }
11173
- return currency.map(function (asset) {
11174
- var ml = extractAssetLocation(asset);
11175
- return _objectSpread2(_objectSpread2({}, asset), {}, {
11176
- fun: {
11177
- Fungible: BigInt(asset.fun.Fungible)
11178
- },
11179
- isFeeAsset: deepEqual(ml, feeAsset.location)
11180
- });
11181
- });
11182
- }
11183
- // MultiAsset is an array of TCurrencyCore, search for assets
11184
- var assets = currency.map(function (currency) {
11185
- if (currency.amount === AMOUNT_ALL) {
11186
- throw new InvalidCurrencyError('Multi assets cannot use amount all. Please specify amount.');
11187
- }
11188
- var asset = findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null);
11189
- if (!asset) {
11190
- throw new InvalidCurrencyError("Origin chain ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
11191
- }
11192
- assertHasLocation(asset);
11193
- if (!resolvedFeeAsset) {
11194
- throw new InvalidCurrencyError('Fee asset not found');
11195
- }
11196
- validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
11197
- var version = getChainVersion(origin);
11198
- var abstractedAmount = abstractDecimals(currency.amount, asset.decimals, api);
11199
- return _objectSpread2({
11200
- isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
11201
- }, createAsset(version, abstractedAmount, asset.location));
11202
- });
11203
- if (assets.filter(function (asset) {
11204
- return asset.isFeeAsset;
11205
- }).length > 1) {
11206
- throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
11207
- }
11208
- if (assets.filter(function (asset) {
11209
- return asset.isFeeAsset;
11210
- }).length === 0) {
11211
- throw new InvalidCurrencyError("Fee asset not found in multiassets");
11212
- }
11213
- return assets;
11214
- }
11215
- return undefined;
11216
- };
11217
-
11218
- var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
11219
- if (forcedVersion) return forcedVersion;
11220
- var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
11221
- return destVersion < originVersion ? destVersion : originVersion;
11222
- };
11223
-
11224
- var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
11225
- if (isRelayChain(origin)) return true;
11226
- var isMultipleAssets = Array.isArray(currency);
11227
- var hasOverriddenLocation = 'location' in currency && isOverrideLocationSpecifier(currency.location);
11228
- return !(isMultipleAssets || hasOverriddenLocation);
11229
- };
11230
-
11231
- var validateDestinationAddress = function validateDestinationAddress(address, destination) {
11232
- if (typeof address === 'string' && !isTLocation(destination)) {
11233
- validateAddress(address, destination);
11234
- }
11235
- };
11236
-
11237
- var validateCurrency = function validateCurrency(currency, feeAsset) {
11238
- if (Array.isArray(currency)) {
11239
- if (currency.length === 0) {
11240
- throw new InvalidCurrencyError('Overridden assets cannot be empty');
11241
- }
11242
- if (currency.length === 1) {
11243
- throw new InvalidCurrencyError('Please provide more than one asset');
11244
- }
11245
- if (currency.length > 1 && !currency.every(function (asset) {
11246
- return isTAsset(asset);
11247
- }) && !feeAsset) {
11248
- throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
11249
- }
11250
- }
11251
- };
11252
- var validateDestination = function validateDestination(origin, destination) {
11253
- if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
11254
- throw new IncompatibleChainsError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
11255
- }
11256
- var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam', 'Mythos'];
11257
- if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
11258
- throw new IncompatibleChainsError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
11259
- }
11260
- var isLocationDestination = _typeof(destination) === 'object';
11261
- var isBridge = !isTLocation(destination) && isDotKsmBridge(origin, destination);
11262
- var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
11263
- if (!isRelayDestination && !isLocationDestination) {
11264
- var originRelayChainSymbol = getRelayChainSymbol(origin);
11265
- var destinationRelayChainSymbol = getRelayChainSymbol(destination);
11266
- if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
11267
- throw new IncompatibleChainsError();
11268
- }
11269
- }
11270
- };
11271
- var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
11272
- if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
11273
- throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
11274
- }
11275
- if (!assetCheckEnabled && 'id' in currency) {
11276
- throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
11277
- }
11278
- };
11279
-
11280
11301
  var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
11281
11302
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
11282
11303
  var api, tx, origin, destination, currency, senderAddress, feeAsset, originAsset, amount, rawOriginFee, originFee, resolvedFeeAsset, sufficient, asset;
@@ -11476,20 +11497,19 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11476
11497
  case 10:
11477
11498
  processHop = /*#__PURE__*/function () {
11478
11499
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
11479
- var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, _findAssetInfoOnDest, hopResult;
11500
+ var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, hopResult;
11480
11501
  return _regenerator().w(function (_context) {
11481
11502
  while (1) switch (_context.n) {
11482
11503
  case 0:
11483
11504
  hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange;
11484
- if (!(currentAsset.location && currentAsset.location.parents === Parents.TWO)) {
11485
- if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
11486
- hopAsset = findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo);
11487
- } else {
11488
- hopAsset = (_findAssetInfoOnDest = findAssetInfoOnDest(origin, currentChain, currency)) !== null && _findAssetInfoOnDest !== void 0 ? _findAssetInfoOnDest : currentAsset;
11489
- }
11490
- } else {
11491
- hopAsset = findNativeAssetInfoOrThrow(getRelayChainOf(currentChain));
11492
- }
11505
+ hopAsset = resolveHopAsset({
11506
+ originChain: origin,
11507
+ currentChain: currentChain,
11508
+ asset: currentAsset,
11509
+ currency: currency,
11510
+ swapConfig: swapConfig,
11511
+ hasPassedExchange: hasPassedExchange
11512
+ });
11493
11513
  _context.n = 1;
11494
11514
  return getDestXcmFee({
11495
11515
  api: hopApi,
@@ -11834,7 +11854,7 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
11834
11854
  case 3:
11835
11855
  originSufficient = _context.v;
11836
11856
  _context.n = 4;
11837
- return isSufficientDestination(destApi, destination, address, currency.amount, originAsset, fixedDestinationFee);
11857
+ return isSufficientDestination(destApi, destination, address, amount, originAsset, fixedDestinationFee);
11838
11858
  case 4:
11839
11859
  _destinationSufficient = _context.v;
11840
11860
  return _context.a(2, {
@@ -11943,7 +11963,7 @@ var send = /*#__PURE__*/function () {
11943
11963
  validateDestination(origin, destination);
11944
11964
  validateDestinationAddress(address, destination);
11945
11965
  if (senderAddress) validateAddress(senderAddress, origin, false);
11946
- isBridge = !isTLocation(destination) && isDotKsmBridge(origin, destination);
11966
+ isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
11947
11967
  assetCheckEnabled = shouldPerformAssetCheck(origin, currency);
11948
11968
  validateAssetSpecifiers(assetCheckEnabled, currency);
11949
11969
  asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
@@ -12717,18 +12737,19 @@ var computeInstructionFee = /*#__PURE__*/function () {
12717
12737
  }();
12718
12738
  var computeAllFees = /*#__PURE__*/function () {
12719
12739
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3, customXcm, isDotAsset, refundInstruction) {
12720
- var _customXcm$DepositRes;
12721
12740
  var reserve, dest, version, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0;
12722
12741
  return _regenerator().w(function (_context2) {
12723
12742
  while (1) switch (_context2.n) {
12724
12743
  case 0:
12725
12744
  reserve = _ref3.reserve, dest = _ref3.dest, version = _ref3.options.version;
12726
- if (!('DepositReserveAsset' in customXcm || 'InitiateTeleport' in customXcm)) {
12745
+ if (!customXcm.some(function (x) {
12746
+ return 'DepositReserveAsset' in x || 'InitiateTeleport' in x;
12747
+ })) {
12727
12748
  _context2.n = 6;
12728
12749
  break;
12729
12750
  }
12730
12751
  _context2.n = 1;
12731
- return computeInstructionFee(reserve, version, [customXcm]);
12752
+ return computeInstructionFee(reserve, version, customXcm);
12732
12753
  case 1:
12733
12754
  _t3 = _context2.v;
12734
12755
  if (!refundInstruction) {
@@ -12746,7 +12767,12 @@ var computeAllFees = /*#__PURE__*/function () {
12746
12767
  case 4:
12747
12768
  _t5 = _t4;
12748
12769
  _context2.n = 5;
12749
- return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, ((_customXcm$DepositRes = customXcm === null || customXcm === void 0 ? void 0 : customXcm.DepositReserveAsset) !== null && _customXcm$DepositRes !== void 0 ? _customXcm$DepositRes : customXcm.InitiateTeleport).xcm);
12770
+ return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, function () {
12771
+ var instr = customXcm.find(function (j) {
12772
+ return 'DepositReserveAsset' in j || 'InitiateTeleport' in j;
12773
+ });
12774
+ return instr ? 'DepositReserveAsset' in instr ? instr.DepositReserveAsset.xcm : instr.InitiateTeleport.xcm : undefined;
12775
+ }());
12750
12776
  case 5:
12751
12777
  _t6 = _context2.v;
12752
12778
  _t2 = {
@@ -12762,7 +12788,7 @@ var computeAllFees = /*#__PURE__*/function () {
12762
12788
  break;
12763
12789
  }
12764
12790
  _context2.n = 7;
12765
- return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, [customXcm]);
12791
+ return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm);
12766
12792
  case 7:
12767
12793
  _t7 = _context2.v;
12768
12794
  _context2.n = 9;
@@ -12800,28 +12826,49 @@ var computeAllFees = /*#__PURE__*/function () {
12800
12826
  };
12801
12827
  }();
12802
12828
 
12829
+ var getSubBridgeReserve = function getSubBridgeReserve(chain, destination, location) {
12830
+ if (deepEqual(location, RELAY_LOCATION)) return chain;
12831
+ return destination;
12832
+ };
12833
+ var resolveReserveChain = function resolveReserveChain(chain, destination, assetLocation, isSubBridge, overrideReserve) {
12834
+ if (isSubBridge) {
12835
+ return getSubBridgeReserve(chain, destination, assetLocation);
12836
+ }
12837
+ if (overrideReserve !== undefined) {
12838
+ return overrideReserve;
12839
+ }
12840
+ var relayChain = getRelayChainOf(chain);
12841
+ if (relayChain === 'Paseo' || relayChain === 'Kusama') {
12842
+ // Paseo and Kusama ecosystems migrate reserves to AssetHub
12843
+ return getAssetReserveChain(chain, chain, assetLocation);
12844
+ }
12845
+ if (isRelayChain(destination)) {
12846
+ return destination;
12847
+ }
12848
+ return getAssetReserveChain(chain, chain, assetLocation);
12849
+ };
12803
12850
  var createTypeAndThenCallContext = /*#__PURE__*/function () {
12804
12851
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
12805
- var api, destChain, assetInfo, reserveChain, destApi, reserveApi;
12852
+ var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, destApi, reserveApi;
12806
12853
  return _regenerator().w(function (_context) {
12807
12854
  while (1) switch (_context.n) {
12808
12855
  case 0:
12809
- api = options.api, destChain = options.destChain, assetInfo = options.assetInfo;
12856
+ api = options.api, destination = options.destination, assetInfo = options.assetInfo;
12810
12857
  assertHasLocation(assetInfo);
12811
- if (destChain) {
12858
+ if (!isTLocation(destination)) {
12812
12859
  _context.n = 1;
12813
12860
  break;
12814
12861
  }
12815
12862
  throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
12816
12863
  case 1:
12817
- reserveChain = overrideReserve !== undefined ? overrideReserve :
12818
- // Paseo ecosystem migrated reserves to AssetHub
12819
- getRelayChainOf(chain) === 'Paseo' ? getAssetReserveChain(chain, chain, assetInfo.location) : isRelayChain(destChain) ? destChain : getAssetReserveChain(chain, chain, assetInfo.location);
12864
+ destinationChain = destination;
12865
+ isSubBridge = isSubstrateBridge(chain, destinationChain);
12866
+ reserveChain = resolveReserveChain(chain, destinationChain, assetInfo.location, isSubBridge, overrideReserve);
12820
12867
  destApi = api.clone();
12821
12868
  _context.n = 2;
12822
- return destApi.init(destChain);
12869
+ return destApi.init(destinationChain);
12823
12870
  case 2:
12824
- reserveApi = reserveChain === chain ? api : reserveChain === destChain ? destApi : api.clone();
12871
+ reserveApi = reserveChain === chain ? api : reserveChain === destinationChain ? destApi : api.clone();
12825
12872
  _context.n = 3;
12826
12873
  return reserveApi.init(reserveChain);
12827
12874
  case 3:
@@ -12832,12 +12879,13 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
12832
12879
  },
12833
12880
  dest: {
12834
12881
  api: destApi,
12835
- chain: destChain
12882
+ chain: destinationChain
12836
12883
  },
12837
12884
  reserve: {
12838
12885
  api: reserveApi,
12839
12886
  chain: reserveChain
12840
12887
  },
12888
+ isSubBridge: isSubBridge,
12841
12889
  assetInfo: assetInfo,
12842
12890
  options: options
12843
12891
  });
@@ -12849,16 +12897,17 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
12849
12897
  };
12850
12898
  }();
12851
12899
 
12852
- var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
12900
+ var createCustomXcm = function createCustomXcm(_ref, isDotAsset, assetCount, isForFeeCalc) {
12853
12901
  var origin = _ref.origin,
12854
12902
  dest = _ref.dest,
12855
12903
  reserve = _ref.reserve,
12904
+ isSubBridge = _ref.isSubBridge,
12856
12905
  assetInfo = _ref.assetInfo,
12857
12906
  options = _ref.options;
12858
- var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
12859
- reserveFee: MIN_FEE,
12907
+ var fees = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
12908
+ reserveFee: 0n,
12860
12909
  refundFee: 0n,
12861
- destFee: MIN_FEE
12910
+ destFee: 0n
12862
12911
  };
12863
12912
  var destination = options.destination,
12864
12913
  version = options.version,
@@ -12868,20 +12917,22 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
12868
12917
  refundFee = fees.refundFee,
12869
12918
  destFee = fees.destFee;
12870
12919
  var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
12871
- var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation);
12872
- var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location));
12920
+ var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation, origin.chain);
12921
+ var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location, origin.chain));
12873
12922
  var depositInstruction = {
12874
12923
  DepositAsset: {
12875
12924
  assets: {
12876
- Wild: {
12925
+ Wild: assetCount > 1 ? {
12877
12926
  AllOf: {
12878
12927
  id: asset.id,
12879
12928
  fun: 'Fungible'
12880
12929
  }
12930
+ } : {
12931
+ AllCounted: 1
12881
12932
  }
12882
12933
  },
12883
12934
  beneficiary: createBeneficiaryLocation({
12884
- api: origin.api,
12935
+ api: isSubBridge ? dest.api : origin.api,
12885
12936
  address: address,
12886
12937
  version: version
12887
12938
  })
@@ -12890,10 +12941,10 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
12890
12941
  var assetsFilter = [];
12891
12942
  if (!isDotAsset) assetsFilter.push(createAsset(version, reserveFee + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
12892
12943
  assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
12893
- if (origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
12944
+ if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
12894
12945
  var buyExecutionAmount = !isDotAsset ? destFee : assetInfo.amount - reserveFee - refundFee;
12895
- if (buyExecutionAmount < 0n) throw new AmountTooLowError();
12896
- var filter = fees.destFee === MIN_FEE ? {
12946
+ if (buyExecutionAmount < 0n && !isForFeeCalc) throw new AmountTooLowError();
12947
+ var filter = isForFeeCalc ? {
12897
12948
  Wild: 'All'
12898
12949
  } : {
12899
12950
  Definite: assetsFilter
@@ -12904,26 +12955,29 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
12904
12955
  weight_limit: 'Unlimited'
12905
12956
  }
12906
12957
  };
12958
+ if (isSubBridge) {
12959
+ return [buyExecution, depositInstruction];
12960
+ }
12907
12961
  var destLoc = createDestination(version, origin.chain, destination, paraIdTo);
12908
12962
  // If destination is a system chain, use teleport instead of reserve deposit
12909
12963
  if (isSystemChain(dest.chain)) {
12910
- return {
12964
+ return [{
12911
12965
  InitiateTeleport: {
12912
12966
  assets: filter,
12913
12967
  dest: destLoc,
12914
12968
  xcm: [buyExecution, depositInstruction]
12915
12969
  }
12916
- };
12970
+ }];
12917
12971
  }
12918
- return {
12972
+ return [{
12919
12973
  DepositReserveAsset: {
12920
12974
  assets: filter,
12921
12975
  dest: destLoc,
12922
12976
  xcm: [buyExecution, depositInstruction]
12923
12977
  }
12924
- };
12978
+ }];
12925
12979
  }
12926
- return depositInstruction;
12980
+ return [depositInstruction];
12927
12981
  };
12928
12982
 
12929
12983
  var createRefundInstruction = function createRefundInstruction(api, senderAddress, version, assetCount) {
@@ -12958,7 +13012,7 @@ var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, vers
12958
13012
  */
12959
13013
  var createTypeAndThenCall = /*#__PURE__*/function () {
12960
13014
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
12961
- var api, senderAddress, version, context, assetInfo, isDotAsset, customXcm, assetCount, refundInstruction, fees, finalCustomXcm, totalFee, assets;
13015
+ var api, senderAddress, version, context, assetInfo, isSubBridge, LOCATIONS, isRelayAsset, assetCount, customXcm, refundInstruction, fees, finalCustomXcm, totalFee, assets;
12962
13016
  return _regenerator().w(function (_context) {
12963
13017
  while (1) switch (_context.n) {
12964
13018
  case 0:
@@ -12967,8 +13021,8 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
12967
13021
  return createTypeAndThenCallContext(chain, options, overrideReserve);
12968
13022
  case 1:
12969
13023
  context = _context.v;
12970
- assetInfo = context.assetInfo;
12971
- isDotAsset = deepEqual(assetInfo.location, RELAY_LOCATION) || deepEqual(assetInfo.location, {
13024
+ assetInfo = context.assetInfo, isSubBridge = context.isSubBridge;
13025
+ LOCATIONS = [RELAY_LOCATION, {
12972
13026
  parents: 2,
12973
13027
  interior: {
12974
13028
  X1: [{
@@ -12977,20 +13031,32 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
12977
13031
  }
12978
13032
  }]
12979
13033
  }
13034
+ }, {
13035
+ parents: 2,
13036
+ interior: {
13037
+ X1: [{
13038
+ GlobalConsensus: {
13039
+ Polkadot: null
13040
+ }
13041
+ }]
13042
+ }
13043
+ }];
13044
+ isRelayAsset = LOCATIONS.some(function (loc) {
13045
+ return deepEqual(assetInfo.location, loc);
12980
13046
  });
12981
- customXcm = createCustomXcm(context, isDotAsset);
12982
- assetCount = isDotAsset ? 1 : 2;
13047
+ assetCount = isRelayAsset ? 1 : 2;
13048
+ customXcm = createCustomXcm(context, isRelayAsset, assetCount, true);
12983
13049
  refundInstruction = senderAddress ? createRefundInstruction(api, senderAddress, version, assetCount) : null;
12984
13050
  _context.n = 2;
12985
- return computeAllFees(context, customXcm, isDotAsset, refundInstruction);
13051
+ return computeAllFees(context, customXcm, isRelayAsset, refundInstruction);
12986
13052
  case 2:
12987
13053
  fees = _context.v;
12988
13054
  finalCustomXcm = [];
12989
- if (refundInstruction) finalCustomXcm.push(refundInstruction);
12990
- finalCustomXcm.push(createCustomXcm(context, isDotAsset, fees));
13055
+ if (refundInstruction && !isSubBridge) finalCustomXcm.push(refundInstruction);
13056
+ finalCustomXcm.push.apply(finalCustomXcm, _toConsumableArray(createCustomXcm(context, isRelayAsset, assetCount, false, fees)));
12991
13057
  totalFee = fees.reserveFee + fees.destFee + fees.refundFee;
12992
- assets = buildAssets(chain, assetInfo, totalFee, isDotAsset, version);
12993
- return _context.a(2, buildTypeAndThenCall(context, isDotAsset, finalCustomXcm, assets));
13058
+ assets = buildAssets(chain, assetInfo, totalFee, isRelayAsset, version);
13059
+ return _context.a(2, buildTypeAndThenCall(context, isRelayAsset, finalCustomXcm, assets));
12994
13060
  }
12995
13061
  }, _callee);
12996
13062
  }));
@@ -13817,9 +13883,6 @@ var GeneralBuilder = /*#__PURE__*/function () {
13817
13883
  value: function () {
13818
13884
  var _buildCommon = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
13819
13885
  var isCalledInternally,
13820
- _this$_options,
13821
- from,
13822
- to,
13823
13886
  _yield$this$prepareNo,
13824
13887
  normalizedOptions,
13825
13888
  tx,
@@ -13834,25 +13897,18 @@ var GeneralBuilder = /*#__PURE__*/function () {
13834
13897
  }
13835
13898
  throw new InvalidParameterError('Transaction manager contains batched items. Use buildBatch() to process them.');
13836
13899
  case 1:
13837
- _this$_options = this._options, from = _this$_options.from, to = _this$_options.to;
13838
- if (!(!isTLocation(to) && isRelayChain(from) && isRelayChain(to) && from !== to)) {
13839
- _context4.n = 2;
13840
- break;
13841
- }
13842
- throw new InvalidParameterError('Transfers between relay chains are not yet supported.');
13843
- case 2:
13844
- _context4.n = 3;
13900
+ _context4.n = 2;
13845
13901
  return this.prepareNormalizedOptions(this._options);
13846
- case 3:
13902
+ case 2:
13847
13903
  _yield$this$prepareNo = _context4.v;
13848
13904
  normalizedOptions = _yield$this$prepareNo.normalizedOptions;
13849
- _context4.n = 4;
13905
+ _context4.n = 3;
13850
13906
  return send(normalizedOptions);
13851
- case 4:
13907
+ case 3:
13852
13908
  tx = _context4.v;
13853
- _context4.n = 5;
13909
+ _context4.n = 4;
13854
13910
  return this.maybePerformXcmFormatCheck(tx, normalizedOptions, isCalledInternally);
13855
- case 5:
13911
+ case 4:
13856
13912
  return _context4.a(2, {
13857
13913
  tx: tx,
13858
13914
  options: normalizedOptions