@paraspell/sdk-core 10.6.0 → 10.7.1

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
@@ -3,7 +3,7 @@ import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol,
3
3
  export * from '@paraspell/assets';
4
4
  import { base58 } from '@scure/base';
5
5
  import { isAddress, createPublicClient, http, getContract } from 'viem';
6
- import { Parents, isTMultiLocation, Version, isRelayChain, replaceBigInt, NODE_NAMES_DOT_KSM, hasJunction, deepEqual, isDotKsmBridge } from '@paraspell/sdk-common';
6
+ import { Parents, isTMultiLocation, Version, isRelayChain, replaceBigInt, NODE_NAMES_DOT_KSM, hasJunction, deepEqual, isDotKsmBridge, getJunctionValue } from '@paraspell/sdk-common';
7
7
  export * from '@paraspell/sdk-common';
8
8
  import { getSupportedPalletsDetails, getDefaultPallet } from '@paraspell/pallets';
9
9
  export * from '@paraspell/pallets';
@@ -2114,6 +2114,42 @@ var createBeneficiaryMultiLocation = function createBeneficiaryMultiLocation(_re
2114
2114
  }
2115
2115
  };
2116
2116
 
2117
+ /**
2118
+ * This function localizes a multiLocation by removing the `Parachain` junction
2119
+ * if it exists. The `parents` field is set to `0` either if a `Parachain` was removed
2120
+ * or if the resulting interior is `'Here'` and the node is a relay chain.
2121
+ *
2122
+ * @param node - The current node
2123
+ * @param multiLocation - The multiLocation to localize
2124
+ * @returns The localized multiLocation
2125
+ */
2126
+ var localizeLocation = function localizeLocation(node, multiLocation) {
2127
+ var newInterior = multiLocation.interior;
2128
+ var parachainRemoved = false;
2129
+ if (multiLocation.interior !== 'Here') {
2130
+ var junctions = Object.values(multiLocation.interior).flat().filter(function (junction) {
2131
+ return _typeof(junction) === 'object' && junction !== null;
2132
+ });
2133
+ var filteredJunctions = junctions.filter(function (junction) {
2134
+ if ('Parachain' in junction) {
2135
+ parachainRemoved = true;
2136
+ return false;
2137
+ }
2138
+ return true;
2139
+ });
2140
+ if (filteredJunctions.length === 0) {
2141
+ newInterior = 'Here';
2142
+ } else {
2143
+ newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
2144
+ }
2145
+ }
2146
+ var shouldSetParentsToZero = parachainRemoved || newInterior === 'Here' && isRelayChain(node);
2147
+ return {
2148
+ parents: shouldSetParentsToZero ? Parents.ZERO : multiLocation.parents,
2149
+ interior: newInterior
2150
+ };
2151
+ };
2152
+
2117
2153
  var reverseTransformMultiLocation = function reverseTransformMultiLocation(multiLocation) {
2118
2154
  var parachainJunction = {
2119
2155
  Parachain: 1000
@@ -2136,36 +2172,6 @@ var reverseTransformMultiLocation = function reverseTransformMultiLocation(multi
2136
2172
  });
2137
2173
  };
2138
2174
 
2139
- /**
2140
- * This function transforms a multiLocation by removing the `Parachain` junction
2141
- * if it exists and setting the `parents` to `0`.
2142
- *
2143
- * @param multiLocation - The multiLocation to transform
2144
- * @returns The transformed multiLocation
2145
- */
2146
- var transformMultiLocation = function transformMultiLocation(multiLocation) {
2147
- var newInterior;
2148
- if (multiLocation.interior === 'Here') {
2149
- newInterior = 'Here';
2150
- } else {
2151
- var junctions = Object.values(multiLocation.interior).flat().filter(function (junction) {
2152
- return _typeof(junction) === 'object' && junction !== null;
2153
- });
2154
- var filteredJunctions = junctions.filter(function (junction) {
2155
- return !('Parachain' in junction);
2156
- });
2157
- if (filteredJunctions.length === 0) {
2158
- newInterior = 'Here';
2159
- } else {
2160
- newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
2161
- }
2162
- }
2163
- return _objectSpread2(_objectSpread2({}, multiLocation), {}, {
2164
- parents: Parents.ZERO,
2165
- interior: newInterior
2166
- });
2167
- };
2168
-
2169
2175
  var createBeneficiary = function createBeneficiary(options) {
2170
2176
  return createBeneficiaryMultiLocation(options);
2171
2177
  };
@@ -2402,15 +2408,6 @@ var resolveModuleError = function resolveModuleError(node, error) {
2402
2408
  return failureReason;
2403
2409
  };
2404
2410
 
2405
- var getFees = function getFees(scenario) {
2406
- if (scenario === 'ParaToRelay') {
2407
- return 4600000000;
2408
- } else if (scenario === 'ParaToPara') {
2409
- return 399600000000;
2410
- }
2411
- throw new InvalidParameterError("Fees for scenario ".concat(scenario, " are not defined."));
2412
- };
2413
-
2414
2411
  /**
2415
2412
  * Retrieves the node instance for a given node.
2416
2413
  *
@@ -2423,7 +2420,7 @@ var getNode = function getNode(node) {
2423
2420
  };
2424
2421
 
2425
2422
  var resolveParaId = function resolveParaId(paraId, destination) {
2426
- if (isTMultiLocation(destination) || isRelayChain(destination) || destination === 'Ethereum') {
2423
+ if (isTMultiLocation(destination)) {
2427
2424
  return undefined;
2428
2425
  }
2429
2426
  return paraId !== null && paraId !== void 0 ? paraId : getParaId(destination);
@@ -2561,14 +2558,14 @@ var getModifiedCurrencySelection = function getModifiedCurrencySelection(input)
2561
2558
  return createDefaultCurrencySelection(input);
2562
2559
  };
2563
2560
 
2564
- var getXTokensParameters = function getXTokensParameters(isMultiAssetTransfer, currencySelection, destLocation, amount, fees, version, overriddenAsset) {
2561
+ var getXTokensParameters = function getXTokensParameters(isMultiAssetTransfer, currencySelection, destLocation, amount, weightLimit, version, overriddenAsset) {
2565
2562
  var versionedDestLocation = addXcmVersionHeader(destLocation, version);
2566
2563
  if (!isMultiAssetTransfer) {
2567
2564
  return {
2568
2565
  currency_id: currencySelection,
2569
2566
  amount: BigInt(amount),
2570
2567
  dest: versionedDestLocation,
2571
- dest_weight_limit: fees
2568
+ dest_weight_limit: weightLimit
2572
2569
  };
2573
2570
  }
2574
2571
  var isOverriddenMultiAssets = overriddenAsset && !isTMultiLocation(overriddenAsset);
@@ -2581,7 +2578,7 @@ var getXTokensParameters = function getXTokensParameters(isMultiAssetTransfer, c
2581
2578
  fee_item: feeIndexWithFallback
2582
2579
  }), {}, {
2583
2580
  dest: versionedDestLocation,
2584
- dest_weight_limit: fees
2581
+ dest_weight_limit: weightLimit
2585
2582
  });
2586
2583
  };
2587
2584
 
@@ -4836,7 +4833,8 @@ var getDestXcmFee = /*#__PURE__*/function () {
4836
4833
  };
4837
4834
  }();
4838
4835
 
4839
- var getFailureInfo$1 = function getFailureInfo(results) {
4836
+ var getFailureInfo$1 = function getFailureInfo(results, hops) {
4837
+ // Check standard chains first for backwards compatibility
4840
4838
  for (var _i = 0, _arr = ['destination', 'assetHub', 'bridgeHub']; _i < _arr.length; _i++) {
4841
4839
  var chain = _arr[_i];
4842
4840
  var res = results[chain];
@@ -4847,17 +4845,34 @@ var getFailureInfo$1 = function getFailureInfo(results) {
4847
4845
  };
4848
4846
  }
4849
4847
  }
4848
+ var _iterator = _createForOfIteratorHelper(hops),
4849
+ _step;
4850
+ try {
4851
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
4852
+ var hop = _step.value;
4853
+ if (!hop.result.success && hop.result.failureReason) {
4854
+ return {
4855
+ failureReason: hop.result.failureReason,
4856
+ failureChain: hop.node
4857
+ };
4858
+ }
4859
+ }
4860
+ } catch (err) {
4861
+ _iterator.e(err);
4862
+ } finally {
4863
+ _iterator.f();
4864
+ }
4850
4865
  return {};
4851
4866
  };
4852
4867
  var dryRunInternal = /*#__PURE__*/function () {
4853
4868
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
4854
4869
  var _intermediateFees$bri, _intermediateFees$ass, _processedBridgeHubDa, _destinationDryRun;
4855
- var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, _getFailureInfo, failureReason, failureChain;
4870
+ var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, hops, destinationDryRun, nextChain, hopApi, hopDryRun, hopCurrency, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, _getFailureInfo, failureReason, failureChain;
4856
4871
  return _regenerator().w(function (_context) {
4857
4872
  while (1) switch (_context.n) {
4858
4873
  case 0:
4859
4874
  origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
4860
- resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4875
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4861
4876
  asset = findAssetForNodeOrThrow(origin, currency, destination);
4862
4877
  _context.n = 1;
4863
4878
  return api.getDryRunCall({
@@ -4876,7 +4891,8 @@ var dryRunInternal = /*#__PURE__*/function () {
4876
4891
  return _context.a(2, {
4877
4892
  failureReason: originDryRun.failureReason,
4878
4893
  failureChain: 'origin',
4879
- origin: originDryRun
4894
+ origin: originDryRun,
4895
+ hops: []
4880
4896
  });
4881
4897
  case 2:
4882
4898
  initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
@@ -4886,6 +4902,7 @@ var dryRunInternal = /*#__PURE__*/function () {
4886
4902
  forwardedXcms = initialForwardedXcms;
4887
4903
  nextParaId = initialDestParaId;
4888
4904
  intermediateFees = {};
4905
+ hops = [];
4889
4906
  case 3:
4890
4907
  if (!(Array.isArray(forwardedXcms) && forwardedXcms.length && forwardedXcms[1].length && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
4891
4908
  _context.n = 13;
@@ -4928,6 +4945,23 @@ var dryRunInternal = /*#__PURE__*/function () {
4928
4945
  });
4929
4946
  case 8:
4930
4947
  hopDryRun = _context.v;
4948
+ // Determine the currency for this hop
4949
+ hopCurrency = void 0;
4950
+ if (nextChain === destination) {
4951
+ hopCurrency = asset === null || asset === void 0 ? void 0 : asset.symbol;
4952
+ } else if (isRelayChain(nextChain) || nextChain === assetHubNode || nextChain === bridgeHubNode) {
4953
+ hopCurrency = resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(nextChain);
4954
+ }
4955
+ // Add to hops array (only if not the destination)
4956
+ if (nextChain !== destination) {
4957
+ hops.push({
4958
+ node: nextChain,
4959
+ result: hopDryRun.success && hopCurrency ? _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
4960
+ currency: hopCurrency
4961
+ }) : hopDryRun
4962
+ });
4963
+ }
4964
+ // Keep existing logic for backwards compatibility
4931
4965
  if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
4932
4966
  destinationDryRun = hopDryRun;
4933
4967
  } else if (nextChain === assetHubNode) {
@@ -4973,12 +5007,21 @@ var dryRunInternal = /*#__PURE__*/function () {
4973
5007
  processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
4974
5008
  fee: intermediateFees.bridgeHub.fee + bridgeFee
4975
5009
  });
5010
+ // Update the hop data if BridgeHub is in the hops array
5011
+ bridgeHubHopIndex = hops.findIndex(function (hop) {
5012
+ return hop.node === bridgeHubNode;
5013
+ });
5014
+ if (bridgeHubHopIndex !== -1 && hops[bridgeHubHopIndex].result.success) {
5015
+ hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, hops[bridgeHubHopIndex].result), {}, {
5016
+ fee: intermediateFees.bridgeHub.fee + bridgeFee
5017
+ });
5018
+ }
4976
5019
  case 16:
4977
5020
  _getFailureInfo = getFailureInfo$1({
4978
5021
  destination: destinationDryRun,
4979
5022
  assetHub: intermediateFees.assetHub,
4980
5023
  bridgeHub: intermediateFees.bridgeHub
4981
- }), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
5024
+ }, hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
4982
5025
  return _context.a(2, {
4983
5026
  failureReason: failureReason,
4984
5027
  failureChain: failureChain,
@@ -4986,14 +5029,15 @@ var dryRunInternal = /*#__PURE__*/function () {
4986
5029
  currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
4987
5030
  }) : originDryRun,
4988
5031
  assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
4989
- currency: getNativeAssetSymbol(assetHubNode)
5032
+ currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(assetHubNode)
4990
5033
  }) : intermediateFees.assetHub,
4991
5034
  bridgeHub: (_processedBridgeHubDa = processedBridgeHubData) !== null && _processedBridgeHubDa !== void 0 && _processedBridgeHubDa.success ? _objectSpread2(_objectSpread2({}, processedBridgeHubData), {}, {
4992
5035
  currency: getNativeAssetSymbol(bridgeHubNode)
4993
5036
  }) : processedBridgeHubData,
4994
5037
  destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
4995
5038
  currency: asset === null || asset === void 0 ? void 0 : asset.symbol
4996
- }) : destinationDryRun
5039
+ }) : destinationDryRun,
5040
+ hops: hops // Add the hops array to the return value
4997
5041
  });
4998
5042
  }
4999
5043
  }, _callee, null, [[5,, 10, 12]]);
@@ -5897,6 +5941,7 @@ var send = /*#__PURE__*/function () {
5897
5941
  asset: normalizedAsset,
5898
5942
  currency: currency,
5899
5943
  feeAsset: resolvedFeeAsset,
5944
+ feeCurrency: feeAsset,
5900
5945
  address: address,
5901
5946
  to: destination,
5902
5947
  paraIdTo: paraIdTo,
@@ -5963,11 +6008,11 @@ var ParachainNode = /*#__PURE__*/function () {
5963
6008
  key: "transfer",
5964
6009
  value: function () {
5965
6010
  var _transfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
5966
- var api, asset, currency, feeAsset, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, isRelayDestination, scenario, paraId, isLocalTransfer, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input, _options, isEthAsset, isAHPOrigin, isAHPDest, isEthDest;
6011
+ var api, asset, currency, feeAsset, feeCurrency, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, isRelayDestination, scenario, paraId, isLocalTransfer, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input, _options, isEthAsset, isAHPOrigin, isAHPDest, isEthDest;
5967
6012
  return _regenerator().w(function (_context) {
5968
6013
  while (1) switch (_context.n) {
5969
6014
  case 0:
5970
- api = options.api, asset = options.asset, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, overriddenAsset = options.overriddenAsset, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method;
6015
+ api = options.api, asset = options.asset, currency = options.currency, feeAsset = options.feeAsset, feeCurrency = options.feeCurrency, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, overriddenAsset = options.overriddenAsset, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method;
5971
6016
  isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5972
6017
  scenario = isRelayDestination ? 'ParaToRelay' : 'ParaToPara';
5973
6018
  paraId = resolveParaId(paraIdTo, destination);
@@ -6003,7 +6048,6 @@ var ParachainNode = /*#__PURE__*/function () {
6003
6048
  version: version,
6004
6049
  paraId: paraId
6005
6050
  }),
6006
- fees: getFees(scenario),
6007
6051
  origin: this.node,
6008
6052
  scenario: scenario,
6009
6053
  paraIdTo: paraId,
@@ -6059,6 +6103,7 @@ var ParachainNode = /*#__PURE__*/function () {
6059
6103
  asset: asset,
6060
6104
  currency: currency,
6061
6105
  feeAsset: feeAsset,
6106
+ feeCurrency: feeCurrency,
6062
6107
  scenario: scenario,
6063
6108
  destination: destination,
6064
6109
  paraIdTo: paraId,
@@ -6072,13 +6117,13 @@ var ParachainNode = /*#__PURE__*/function () {
6072
6117
  isAHPOrigin = this.node === 'AssetHubPolkadot' || this.node === 'AssetHubKusama';
6073
6118
  isAHPDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
6074
6119
  isEthDest = destination === 'Ethereum'; // Eth asset - Any origin to any dest via AH - DestinationReserve - multiple instructions
6075
- if (!(isEthAsset && !isAHPOrigin && !isAHPDest && !isEthDest)) {
6120
+ if (!(isEthAsset && !isAHPOrigin && !isAHPDest && !isEthDest && !feeAsset)) {
6076
6121
  _context.n = 6;
6077
6122
  break;
6078
6123
  }
6079
6124
  return _context.a(2, this.transferEthAssetViaAH(_options));
6080
6125
  case 6:
6081
- if (!(isEthAsset && isAHPDest && !isAHPOrigin && !isEthDest)) {
6126
+ if (!(isEthAsset && isAHPDest && !isAHPOrigin && !isEthDest && !feeAsset)) {
6082
6127
  _context.n = 7;
6083
6128
  break;
6084
6129
  }
@@ -6753,7 +6798,7 @@ var createExecuteExchangeXcm = function createExecuteExchangeXcm(input, weight,
6753
6798
  paraId: paraIdTo
6754
6799
  });
6755
6800
  assertHasLocation(asset);
6756
- var transformedMultiLocation = transformMultiLocation(asset.multiLocation);
6801
+ var transformedMultiLocation = localizeLocation('AssetHubPolkadot', asset.multiLocation);
6757
6802
  var call = {
6758
6803
  module: 'PolkadotXcm',
6759
6804
  method: 'execute',
@@ -6829,8 +6874,97 @@ var createExecuteExchangeXcm = function createExecuteExchangeXcm(input, weight,
6829
6874
  return api.callTxMethod(call);
6830
6875
  };
6831
6876
 
6832
- var createExecuteXcm = function createExecuteXcm(input, executionFee, version) {
6833
- var _feeAsset$multiLocati;
6877
+ var getReserveParaId = function getReserveParaId(assetLocation) {
6878
+ var hasParaJunction = hasJunction(assetLocation, 'Parachain');
6879
+ var hasGlobalConsensusJunction = hasJunction(assetLocation, 'GlobalConsensus');
6880
+ if (hasParaJunction) {
6881
+ return getJunctionValue(assetLocation, 'Parachain');
6882
+ }
6883
+ if (hasGlobalConsensusJunction) {
6884
+ return getParaId('AssetHubPolkadot');
6885
+ }
6886
+ if (deepEqual(assetLocation, {
6887
+ parents: Parents.ONE,
6888
+ interior: {
6889
+ Here: null
6890
+ }
6891
+ })) {
6892
+ return getParaId('Polkadot');
6893
+ }
6894
+ };
6895
+ var isOnReserveChain = function isOnReserveChain(node, reserveParaId) {
6896
+ if (reserveParaId === undefined) return false;
6897
+ var currentParaId = getParaId(node);
6898
+ return currentParaId === reserveParaId;
6899
+ };
6900
+ var getChainLocation = function getChainLocation(paraId) {
6901
+ var interior = paraId === getParaId('Polkadot') ? 'Here' : {
6902
+ X1: [{
6903
+ Parachain: paraId
6904
+ }]
6905
+ };
6906
+ return {
6907
+ parents: Parents.ONE,
6908
+ interior: interior
6909
+ };
6910
+ };
6911
+ var createAssetsFilter = function createAssetsFilter(asset, feeAsset) {
6912
+ return !feeAsset ?
6913
+ // For same fee asset, deposit only this one asset
6914
+ {
6915
+ Wild: {
6916
+ AllCounted: 1
6917
+ }
6918
+ } :
6919
+ // For different fee asset, specify which one to deposit by location and amount
6920
+ {
6921
+ Definite: [asset]
6922
+ };
6923
+ };
6924
+ var sortMultiAssets = function sortMultiAssets(assets) {
6925
+ return assets.sort(function (a, b) {
6926
+ var aLoc = extractMultiAssetLoc(a);
6927
+ var bLoc = extractMultiAssetLoc(b);
6928
+ var aIsHere = isHere(aLoc);
6929
+ var bIsHere = isHere(bLoc);
6930
+ var aHasGlobal = hasJunction(aLoc, 'GlobalConsensus');
6931
+ var bHasGlobal = hasJunction(bLoc, 'GlobalConsensus');
6932
+ var aGeneralIndex = getJunctionValue(aLoc, 'GeneralIndex');
6933
+ var bGeneralIndex = getJunctionValue(bLoc, 'GeneralIndex');
6934
+ var getPriority = function getPriority(isHere, hasGlobal) {
6935
+ if (isHere) return 0;
6936
+ if (hasGlobal) return 2;
6937
+ return 1;
6938
+ };
6939
+ var aPriority = getPriority(aIsHere, aHasGlobal);
6940
+ var bPriority = getPriority(bIsHere, bHasGlobal);
6941
+ if (aPriority !== bPriority) return aPriority - bPriority;
6942
+ if (aGeneralIndex === undefined && bGeneralIndex === undefined) return 0;
6943
+ if (aGeneralIndex === undefined) return 1;
6944
+ if (bGeneralIndex === undefined) return -1;
6945
+ return aGeneralIndex - bGeneralIndex;
6946
+ });
6947
+ };
6948
+ function isHere(loc) {
6949
+ var _loc$interior;
6950
+ return loc.interior === 'Here' || ((_loc$interior = loc.interior) === null || _loc$interior === void 0 ? void 0 : _loc$interior.Here) !== undefined;
6951
+ }
6952
+ var updateAsset = function updateAsset(asset, amount) {
6953
+ return _objectSpread2(_objectSpread2({}, asset), {}, {
6954
+ fun: {
6955
+ Fungible: amount
6956
+ }
6957
+ });
6958
+ };
6959
+ var createWithdrawAssets = function createWithdrawAssets(asset, feeAsset) {
6960
+ var assetsToWithdraw = [asset];
6961
+ if (feeAsset) {
6962
+ assetsToWithdraw.push(feeAsset);
6963
+ }
6964
+ return sortMultiAssets(assetsToWithdraw);
6965
+ };
6966
+ var createExecuteXcm = function createExecuteXcm(node, input, executionFee, hopExecutionFee, version) {
6967
+ var _ref;
6834
6968
  var api = input.api,
6835
6969
  asset = input.asset,
6836
6970
  scenario = input.scenario,
@@ -6838,6 +6972,7 @@ var createExecuteXcm = function createExecuteXcm(input, executionFee, version) {
6838
6972
  paraIdTo = input.paraIdTo,
6839
6973
  address = input.address,
6840
6974
  feeAsset = input.feeAsset;
6975
+ var amount = BigInt(asset.amount);
6841
6976
  var dest = createDestination(scenario, version, destination, paraIdTo);
6842
6977
  var beneficiary = createBeneficiary({
6843
6978
  api: api,
@@ -6847,78 +6982,36 @@ var createExecuteXcm = function createExecuteXcm(input, executionFee, version) {
6847
6982
  version: version,
6848
6983
  paraId: paraIdTo
6849
6984
  });
6850
- if (!isForeignAsset(asset) || !asset.multiLocation || !asset.assetId) {
6851
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is missing multiLocation or assetId"));
6852
- }
6853
- if (feeAsset && (!isForeignAsset(feeAsset) || !feeAsset.multiLocation || !feeAsset.assetId)) {
6854
- throw new InvalidCurrencyError("Fee asset ".concat(JSON.stringify(feeAsset), " is missing multiLocation or assetId"));
6855
- }
6856
- var assetML = transformMultiLocation(asset.multiLocation);
6857
- var feeML = transformMultiLocation((_feeAsset$multiLocati = feeAsset === null || feeAsset === void 0 ? void 0 : feeAsset.multiLocation) !== null && _feeAsset$multiLocati !== void 0 ? _feeAsset$multiLocati : asset.multiLocation);
6858
- var sameFeeAsset = feeAsset && isAssetEqual(asset, feeAsset);
6859
- var amountWithoutFee = BigInt(asset.amount) - executionFee;
6860
- var assetsToWithdraw = [{
6861
- assetId: asset.assetId,
6862
- multiasset: {
6863
- id: assetML,
6864
- fun: {
6865
- Fungible: BigInt(asset.amount)
6866
- }
6867
- }
6868
- }];
6869
- if (!sameFeeAsset && feeAsset !== null && feeAsset !== void 0 && feeAsset.multiLocation) {
6870
- assetsToWithdraw.push({
6871
- assetId: feeAsset.assetId,
6872
- multiasset: {
6873
- id: feeML,
6874
- fun: {
6875
- Fungible: executionFee
6876
- }
6877
- }
6878
- });
6879
- }
6880
- assetsToWithdraw.sort(function (a, b) {
6881
- return a.assetId > b.assetId ? 1 : -1;
6882
- });
6883
- var xcm = [{
6884
- WithdrawAsset: assetsToWithdraw.map(function (_ref) {
6885
- var multiasset = _ref.multiasset;
6886
- return multiasset;
6887
- })
6888
- }, {
6889
- BuyExecution: {
6890
- fees: {
6891
- id: feeML,
6892
- fun: {
6893
- Fungible: executionFee
6894
- }
6895
- },
6896
- weight_limit: {
6897
- Limited: {
6898
- ref_time: 150n,
6899
- proof_size: 0n
6900
- }
6901
- }
6985
+ assertHasLocation(asset);
6986
+ if (feeAsset) {
6987
+ assertHasLocation(feeAsset);
6988
+ }
6989
+ var reserveParaId = getReserveParaId(asset.multiLocation);
6990
+ var reserveChain = reserveParaId !== undefined ? getTNode(reserveParaId, determineRelayChain(node) === 'Polkadot' ? 'polkadot' : 'kusama') : undefined;
6991
+ var isReserveDest = reserveParaId === paraIdTo;
6992
+ var multiAsset = createMultiAsset(version, amount, asset.multiLocation);
6993
+ var multiAssetLocalized = createMultiAsset(version, amount, localizeLocation(node, asset.multiLocation));
6994
+ var multiAssetLocalizedToReserve = createMultiAsset(version, amount, localizeLocation(reserveChain !== null && reserveChain !== void 0 ? reserveChain : node, asset.multiLocation));
6995
+ var feeMultiAsset = feeAsset && !isAssetEqual(asset, feeAsset) ? createMultiAsset(version, executionFee, feeAsset.multiLocation) : undefined;
6996
+ var feeMultiAssetLocalized = feeAsset && !isAssetEqual(asset, feeAsset) ? createMultiAsset(version, executionFee, localizeLocation(node, feeAsset.multiLocation)) : undefined;
6997
+ var feeMultiAssetLocalizedToReserve = feeAsset && !isAssetEqual(asset, feeAsset) ? createMultiAsset(version, executionFee, localizeLocation(reserveChain !== null && reserveChain !== void 0 ? reserveChain : node, feeAsset.multiLocation)) : undefined;
6998
+ var withdrawAssets = createWithdrawAssets(node === 'AssetHubPolkadot' ? multiAssetLocalized : multiAsset, node === 'AssetHubPolkadot' ? feeMultiAssetLocalized : feeMultiAsset);
6999
+ var assetsFilter = createAssetsFilter(multiAsset, feeMultiAsset);
7000
+ if (node !== 'AssetHubPolkadot' && reserveParaId === undefined) {
7001
+ throw new InvalidParameterError('Sending local reserve assets with custom fee asset is not yet supported for this chain.');
7002
+ }
7003
+ var depositInstruction = isReserveDest ? {
7004
+ DepositAsset: {
7005
+ assets: createAssetsFilter(multiAssetLocalizedToReserve, feeMultiAssetLocalizedToReserve),
7006
+ beneficiary: beneficiary
6902
7007
  }
6903
- }, {
7008
+ } : {
6904
7009
  DepositReserveAsset: {
6905
- assets: {
6906
- Definite: [{
6907
- id: assetML,
6908
- fun: {
6909
- Fungible: sameFeeAsset ? amountWithoutFee : BigInt(asset.amount)
6910
- }
6911
- }]
6912
- },
7010
+ assets: createAssetsFilter(multiAssetLocalized, feeMultiAssetLocalized),
6913
7011
  dest: dest,
6914
7012
  xcm: [{
6915
7013
  BuyExecution: {
6916
- fees: {
6917
- id: asset.multiLocation,
6918
- fun: {
6919
- Fungible: sameFeeAsset ? amountWithoutFee - executionFee : BigInt(asset.amount)
6920
- }
6921
- },
7014
+ fees: updateAsset(multiAsset, amount - (feeMultiAsset ? hopExecutionFee : executionFee + hopExecutionFee)),
6922
7015
  weight_limit: 'Unlimited'
6923
7016
  }
6924
7017
  }, {
@@ -6932,10 +7025,149 @@ var createExecuteXcm = function createExecuteXcm(input, executionFee, version) {
6932
7025
  }
6933
7026
  }]
6934
7027
  }
6935
- }];
7028
+ };
7029
+ var needsIntermediaryReserve = reserveParaId !== undefined &&
7030
+ // Has a reserve
7031
+ !isOnReserveChain(node, reserveParaId); // Not on reserve
7032
+ var lastInstruction = needsIntermediaryReserve ? {
7033
+ InitiateReserveWithdraw: {
7034
+ assets: assetsFilter,
7035
+ reserve: getChainLocation(reserveParaId),
7036
+ xcm: [{
7037
+ BuyExecution: {
7038
+ fees:
7039
+ // Decrease amount by 2 units becuase for some reason polkadot withdraws 2 units less
7040
+ // than requested, so we need to account for that
7041
+ updateAsset(multiAssetLocalizedToReserve, amount - 2n),
7042
+ weight_limit: 'Unlimited'
7043
+ }
7044
+ }, depositInstruction]
7045
+ }
7046
+ } : depositInstruction;
7047
+ var xcm = [{
7048
+ WithdrawAsset: withdrawAssets
7049
+ }, {
7050
+ BuyExecution: {
7051
+ fees: (_ref = node === 'AssetHubPolkadot' ? feeMultiAssetLocalized : feeMultiAsset) !== null && _ref !== void 0 ? _ref : node === 'AssetHubPolkadot' ? multiAssetLocalized : multiAsset,
7052
+ weight_limit: {
7053
+ Limited: {
7054
+ ref_time: 450n,
7055
+ proof_size: 0n
7056
+ }
7057
+ }
7058
+ }
7059
+ }, lastInstruction];
6936
7060
  return addXcmVersionHeader(xcm, version);
6937
7061
  };
6938
7062
 
7063
+ var handleExecuteTransfer = /*#__PURE__*/function () {
7064
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(node, input) {
7065
+ var api, senderAddress, paraIdTo, asset, currency, feeCurrency, address, feeAsset, version, feeAssetBalance, checkAmount, MIN_FEE, call, destNode, dryRunResult, paddedFee, hopFee, paddedHopFee, xcm, weight, _t;
7066
+ return _regenerator().w(function (_context) {
7067
+ while (1) switch (_context.n) {
7068
+ case 0:
7069
+ api = input.api, senderAddress = input.senderAddress, paraIdTo = input.paraIdTo, asset = input.asset, currency = input.currency, feeCurrency = input.feeCurrency, address = input.address, feeAsset = input.feeAsset, version = input.version;
7070
+ if (senderAddress) {
7071
+ _context.n = 1;
7072
+ break;
7073
+ }
7074
+ throw new InvalidParameterError('Please provide senderAddress');
7075
+ case 1:
7076
+ assertAddressIsString(address);
7077
+ validateAddress(senderAddress, node, false);
7078
+ if (!(feeCurrency && feeAsset && !isAssetEqual(asset, feeAsset))) {
7079
+ _context.n = 3;
7080
+ break;
7081
+ }
7082
+ _context.n = 2;
7083
+ return getAssetBalanceInternal({
7084
+ api: api,
7085
+ address: senderAddress,
7086
+ node: node,
7087
+ currency: feeCurrency
7088
+ });
7089
+ case 2:
7090
+ _t = _context.v;
7091
+ _context.n = 4;
7092
+ break;
7093
+ case 3:
7094
+ _t = undefined;
7095
+ case 4:
7096
+ feeAssetBalance = _t;
7097
+ checkAmount = function checkAmount(fee) {
7098
+ if (BigInt(asset.amount) <= fee) {
7099
+ throw new InvalidParameterError("Asset amount is too low, please increase the amount or use a different fee asset.");
7100
+ }
7101
+ };
7102
+ MIN_FEE = 1000n;
7103
+ checkAmount(MIN_FEE);
7104
+ call = createExecuteCall(createExecuteXcm(node, input, feeAssetBalance && feeAssetBalance > 1n ? feeAssetBalance : MIN_FEE, MIN_FEE, version), MAX_WEIGHT);
7105
+ destNode = getTNode(paraIdTo, determineRelayChain(node) === 'Polkadot' ? 'polkadot' : 'kusama');
7106
+ _context.n = 5;
7107
+ return dryRunInternal({
7108
+ api: api,
7109
+ tx: api.callTxMethod(call),
7110
+ origin: node,
7111
+ destination: destNode,
7112
+ senderAddress: senderAddress,
7113
+ address: address,
7114
+ currency: currency,
7115
+ feeAsset: feeCurrency
7116
+ });
7117
+ case 5:
7118
+ dryRunResult = _context.v;
7119
+ if (dryRunResult.origin.success) {
7120
+ _context.n = 6;
7121
+ break;
7122
+ }
7123
+ throw new DryRunFailedError(dryRunResult.failureReason);
7124
+ case 6:
7125
+ if (!(dryRunResult.assetHub && !dryRunResult.assetHub.success)) {
7126
+ _context.n = 7;
7127
+ break;
7128
+ }
7129
+ throw new DryRunFailedError(dryRunResult.failureReason);
7130
+ case 7:
7131
+ if (!(!dryRunResult.assetHub && dryRunResult.hops)) {
7132
+ _context.n = 9;
7133
+ break;
7134
+ }
7135
+ if (!(dryRunResult.hops.length > 1)) {
7136
+ _context.n = 8;
7137
+ break;
7138
+ }
7139
+ throw new InvalidParameterError("Multiple intermediate hops detected (".concat(dryRunResult.hops.length, "). Only single hop transfers are supported."));
7140
+ case 8:
7141
+ if (!(dryRunResult.hops.length === 1 && !dryRunResult.hops[0].result.success)) {
7142
+ _context.n = 9;
7143
+ break;
7144
+ }
7145
+ throw new DryRunFailedError(dryRunResult.failureReason);
7146
+ case 9:
7147
+ paddedFee = padFeeBy(dryRunResult.origin.fee, 20);
7148
+ if (dryRunResult.assetHub) {
7149
+ hopFee = dryRunResult.assetHub.fee;
7150
+ } else if (dryRunResult.hops && dryRunResult.hops.length === 1 && dryRunResult.hops[0].result.success) {
7151
+ hopFee = dryRunResult.hops[0].result.fee;
7152
+ } else {
7153
+ hopFee = MIN_FEE;
7154
+ }
7155
+ paddedHopFee = padFeeBy(hopFee, 40);
7156
+ checkAmount(feeAsset && !isAssetEqual(asset, feeAsset) ? paddedHopFee : paddedFee + paddedHopFee);
7157
+ xcm = createExecuteXcm(node, input, paddedFee, paddedHopFee, version);
7158
+ _context.n = 10;
7159
+ return api.getXcmWeight(xcm);
7160
+ case 10:
7161
+ weight = _context.v;
7162
+ return _context.a(2, createExecuteCall(xcm, weight));
7163
+ }
7164
+ }, _callee);
7165
+ }));
7166
+ return function handleExecuteTransfer(_x, _x2) {
7167
+ return _ref.apply(this, arguments);
7168
+ };
7169
+ }();
7170
+
6939
7171
  var handleToAhTeleport = /*#__PURE__*/function () {
6940
7172
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(origin, input, defaultTx) {
6941
7173
  var _dryRunResult$destina, _feeResult$origin$wei;
@@ -7288,154 +7520,94 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
7288
7520
  if (destination === 'Polimec' || destination === 'Moonbeam') return 'transfer_assets';
7289
7521
  return scenario === 'ParaToPara' && !isSystemNode ? 'limited_reserve_transfer_assets' : 'limited_teleport_assets';
7290
7522
  }
7291
- }, {
7292
- key: "handleExecuteTransfer",
7293
- value: function () {
7294
- var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
7295
- var api, senderAddress, asset, feeAsset, version, decimals, multiplier, base, scaledMultiplier, MIN_FEE, checkAmount, call, dryRunResult, paddedFee, xcm, weight;
7296
- return _regenerator().w(function (_context3) {
7297
- while (1) switch (_context3.n) {
7298
- case 0:
7299
- api = input.api, senderAddress = input.senderAddress, asset = input.asset, feeAsset = input.feeAsset, version = input.version;
7300
- if (senderAddress) {
7301
- _context3.n = 1;
7302
- break;
7303
- }
7304
- throw new InvalidParameterError('Please provide senderAddress');
7305
- case 1:
7306
- validateAddress(senderAddress, this.node, false);
7307
- decimals = asset.decimals;
7308
- multiplier = decimals > 10 ? 0.4 : 0.15;
7309
- base = BigInt(Math.pow(10, decimals));
7310
- scaledMultiplier = BigInt(Math.floor(multiplier * Math.pow(10, decimals)));
7311
- MIN_FEE = base * scaledMultiplier / BigInt(Math.pow(10, decimals));
7312
- checkAmount = function checkAmount(fee) {
7313
- if (feeAsset && isAssetEqual(asset, feeAsset) && BigInt(asset.amount) <= fee * 2n) {
7314
- throw new InvalidParameterError("Asset amount ".concat(asset.amount, " is too low, please increase the amount or use a different fee asset."));
7315
- }
7316
- };
7317
- checkAmount(MIN_FEE);
7318
- call = createExecuteCall(createExecuteXcm(input, MIN_FEE, version), MAX_WEIGHT);
7319
- _context3.n = 2;
7320
- return api.getDryRunCall({
7321
- node: this.node,
7322
- tx: api.callTxMethod(call),
7323
- address: senderAddress,
7324
- asset: asset,
7325
- feeAsset: feeAsset
7326
- });
7327
- case 2:
7328
- dryRunResult = _context3.v;
7329
- if (dryRunResult.success) {
7330
- _context3.n = 3;
7331
- break;
7332
- }
7333
- throw new DryRunFailedError(dryRunResult.failureReason);
7334
- case 3:
7335
- paddedFee = dryRunResult.fee * 120n / 100n;
7336
- checkAmount(paddedFee);
7337
- xcm = createExecuteXcm(input, paddedFee, version);
7338
- _context3.n = 4;
7339
- return api.getXcmWeight(xcm);
7340
- case 4:
7341
- weight = _context3.v;
7342
- return _context3.a(2, createExecuteCall(createExecuteXcm(input, paddedFee, version), weight));
7343
- }
7344
- }, _callee3, this);
7345
- }));
7346
- function handleExecuteTransfer(_x3) {
7347
- return _handleExecuteTransfer.apply(this, arguments);
7348
- }
7349
- return handleExecuteTransfer;
7350
- }()
7351
7523
  }, {
7352
7524
  key: "transferPolkadotXCM",
7353
7525
  value: function () {
7354
- var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(input) {
7526
+ var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
7355
7527
  var api, scenario, asset, destination, feeAsset, overriddenAsset, isNativeAsset, isEthereumAsset, isSystemNode, method, modifiedInput, _t, _t2;
7356
- return _regenerator().w(function (_context4) {
7357
- while (1) switch (_context4.n) {
7528
+ return _regenerator().w(function (_context3) {
7529
+ while (1) switch (_context3.n) {
7358
7530
  case 0:
7359
7531
  api = input.api, scenario = input.scenario, asset = input.asset, destination = input.destination, feeAsset = input.feeAsset, overriddenAsset = input.overriddenAsset;
7360
7532
  if (!feeAsset) {
7361
- _context4.n = 4;
7533
+ _context3.n = 4;
7362
7534
  break;
7363
7535
  }
7364
7536
  if (!overriddenAsset) {
7365
- _context4.n = 1;
7537
+ _context3.n = 1;
7366
7538
  break;
7367
7539
  }
7368
7540
  throw new InvalidCurrencyError('Cannot use overridden multi-assets with XCM execute');
7369
7541
  case 1:
7370
- if (!(normalizeSymbol(asset.symbol) === normalizeSymbol('KSM'))) {
7371
- _context4.n = 2;
7542
+ if (!isSymbolMatch(asset.symbol, 'KSM')) {
7543
+ _context3.n = 2;
7372
7544
  break;
7373
7545
  }
7374
- return _context4.a(2, this.handleLocalReserveTransfer(input));
7546
+ return _context3.a(2, this.handleLocalReserveTransfer(input));
7375
7547
  case 2:
7376
- isNativeAsset = asset.symbol === this.getNativeAssetSymbol();
7548
+ isNativeAsset = isSymbolMatch(asset.symbol, this.getNativeAssetSymbol());
7377
7549
  if (isNativeAsset) {
7378
- _context4.n = 4;
7550
+ _context3.n = 4;
7379
7551
  break;
7380
7552
  }
7381
7553
  _t = api;
7382
- _context4.n = 3;
7383
- return this.handleExecuteTransfer(input);
7554
+ _context3.n = 3;
7555
+ return handleExecuteTransfer(this.node, input);
7384
7556
  case 3:
7385
- _t2 = _context4.v;
7386
- return _context4.a(2, _t.callTxMethod.call(_t, _t2));
7557
+ _t2 = _context3.v;
7558
+ return _context3.a(2, _t.callTxMethod.call(_t, _t2));
7387
7559
  case 4:
7388
7560
  if (!(destination === 'AssetHubKusama')) {
7389
- _context4.n = 5;
7561
+ _context3.n = 5;
7390
7562
  break;
7391
7563
  }
7392
- return _context4.a(2, this.handleBridgeTransfer(input, 'Kusama'));
7564
+ return _context3.a(2, this.handleBridgeTransfer(input, 'Kusama'));
7393
7565
  case 5:
7394
7566
  if (!(destination === 'Ethereum')) {
7395
- _context4.n = 6;
7567
+ _context3.n = 6;
7396
7568
  break;
7397
7569
  }
7398
- return _context4.a(2, this.handleEthBridgeTransfer(input));
7570
+ return _context3.a(2, this.handleEthBridgeTransfer(input));
7399
7571
  case 6:
7400
7572
  if (!(destination === 'Mythos')) {
7401
- _context4.n = 7;
7573
+ _context3.n = 7;
7402
7574
  break;
7403
7575
  }
7404
- return _context4.a(2, this.handleMythosTransfer(input));
7576
+ return _context3.a(2, this.handleMythosTransfer(input));
7405
7577
  case 7:
7406
7578
  isEthereumAsset = asset.multiLocation && findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
7407
7579
  if (!(destination === 'BifrostPolkadot' && isEthereumAsset)) {
7408
- _context4.n = 8;
7580
+ _context3.n = 8;
7409
7581
  break;
7410
7582
  }
7411
- return _context4.a(2, this.handleLocalReserveTransfer(input));
7583
+ return _context3.a(2, this.handleLocalReserveTransfer(input));
7412
7584
  case 8:
7413
7585
  if (!isEthereumAsset) {
7414
- _context4.n = 9;
7586
+ _context3.n = 9;
7415
7587
  break;
7416
7588
  }
7417
- return _context4.a(2, this.handleLocalReserveTransfer(input, true));
7589
+ return _context3.a(2, this.handleLocalReserveTransfer(input, true));
7418
7590
  case 9:
7419
7591
  isSystemNode = !isTMultiLocation(destination) && SYSTEM_NODES_POLKADOT.includes(destination);
7420
7592
  if (!(scenario === 'ParaToPara' && asset.symbol === 'DOT' && !isForeignAsset(asset) && destination !== 'Hydration' && destination !== 'Polimec' && destination !== 'Moonbeam' && destination !== 'BifrostPolkadot' && destination !== 'PeoplePolkadot' && destination !== 'Ajuna' && !isSystemNode)) {
7421
- _context4.n = 10;
7593
+ _context3.n = 10;
7422
7594
  break;
7423
7595
  }
7424
7596
  throw new ScenarioNotSupportedError(this.node, scenario, 'Some Parachains do not have a reserve for DOT on AssetHub. This can also include multihop transfers that have AssetHub as a hop chain and the call contains DOT. Chains that do not have a DOT reserve on AssetHub are not allowed to transfer DOT to it or through it because this transfer will result in asset loss.');
7425
7597
  case 10:
7426
7598
  if (!(scenario === 'ParaToPara' && asset.symbol === 'KSM' && !isForeignAsset(asset))) {
7427
- _context4.n = 11;
7599
+ _context3.n = 11;
7428
7600
  break;
7429
7601
  }
7430
7602
  throw new ScenarioNotSupportedError(this.node, scenario, 'Bridged KSM cannot currently be transfered from AssetHubPolkadot, if you are sending different KSM asset, please specify {id: <KSMID>}.');
7431
7603
  case 11:
7432
7604
  method = this.getMethod(scenario, destination);
7433
7605
  modifiedInput = this.patchInput(input);
7434
- return _context4.a(2, transferPolkadotXcm(modifiedInput, method, 'Unlimited'));
7606
+ return _context3.a(2, transferPolkadotXcm(modifiedInput, method, 'Unlimited'));
7435
7607
  }
7436
- }, _callee4, this);
7608
+ }, _callee3, this);
7437
7609
  }));
7438
- function transferPolkadotXCM(_x4) {
7610
+ function transferPolkadotXCM(_x3) {
7439
7611
  return _transferPolkadotXCM.apply(this, arguments);
7440
7612
  }
7441
7613
  return transferPolkadotXCM;
@@ -7461,7 +7633,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
7461
7633
  if (!multiLocation) {
7462
7634
  throw new InvalidCurrencyError('Asset does not have a multiLocation defined');
7463
7635
  }
7464
- var transformedMultiLocation = hasJunction(multiLocation, 'Parachain', 1000) ? transformMultiLocation(multiLocation) : multiLocation;
7636
+ var transformedMultiLocation = hasJunction(multiLocation, 'Parachain', getParaId(this.node)) ? localizeLocation(this.node, multiLocation) : multiLocation;
7465
7637
  return createMultiAsset(version, amount, transformedMultiLocation);
7466
7638
  } else {
7467
7639
  return _superPropGet(AssetHubPolkadot, "createCurrencySpec", this, 3)([amount, scenario, version, asset]);
@@ -8414,23 +8586,46 @@ var Hydration = /*#__PURE__*/function (_ParachainNode) {
8414
8586
  key: "transferPolkadotXCM",
8415
8587
  value: function () {
8416
8588
  var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
8417
- var destination;
8589
+ var api, destination, feeAsset, asset, overriddenAsset, isNativeAsset, isNativeFeeAsset, _t, _t2;
8418
8590
  return _regenerator().w(function (_context) {
8419
8591
  while (1) switch (_context.n) {
8420
8592
  case 0:
8421
- destination = input.destination;
8593
+ api = input.api, destination = input.destination, feeAsset = input.feeAsset, asset = input.asset, overriddenAsset = input.overriddenAsset;
8422
8594
  if (!(destination === 'Ethereum')) {
8423
8595
  _context.n = 1;
8424
8596
  break;
8425
8597
  }
8426
8598
  return _context.a(2, this.transferToEthereum(input));
8427
8599
  case 1:
8428
- if (!(destination === 'Polimec')) {
8600
+ if (!feeAsset) {
8601
+ _context.n = 4;
8602
+ break;
8603
+ }
8604
+ if (!overriddenAsset) {
8429
8605
  _context.n = 2;
8430
8606
  break;
8431
8607
  }
8432
- return _context.a(2, this.transferToPolimec(input));
8608
+ throw new InvalidCurrencyError('Cannot use overridden multi-assets with XCM execute');
8433
8609
  case 2:
8610
+ isNativeAsset = isSymbolMatch(asset.symbol, this.getNativeAssetSymbol());
8611
+ isNativeFeeAsset = isSymbolMatch(feeAsset.symbol, this.getNativeAssetSymbol());
8612
+ if (!(!isNativeAsset || !isNativeFeeAsset)) {
8613
+ _context.n = 4;
8614
+ break;
8615
+ }
8616
+ _t = api;
8617
+ _context.n = 3;
8618
+ return handleExecuteTransfer(this.node, input);
8619
+ case 3:
8620
+ _t2 = _context.v;
8621
+ return _context.a(2, _t.callTxMethod.call(_t, _t2));
8622
+ case 4:
8623
+ if (!(destination === 'Polimec')) {
8624
+ _context.n = 5;
8625
+ break;
8626
+ }
8627
+ return _context.a(2, this.transferToPolimec(input));
8628
+ case 5:
8434
8629
  return _context.a(2, this.transferToAssetHub(input));
8435
8630
  }
8436
8631
  }, _callee, this);
@@ -8456,9 +8651,10 @@ var Hydration = /*#__PURE__*/function (_ParachainNode) {
8456
8651
  key: "canUseXTokens",
8457
8652
  value: function canUseXTokens(_ref3) {
8458
8653
  var destination = _ref3.to,
8459
- asset = _ref3.asset;
8654
+ asset = _ref3.asset,
8655
+ feeAsset = _ref3.feeAsset;
8460
8656
  var isEthAsset = asset.multiLocation && findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
8461
- return destination !== 'Ethereum' && destination !== 'Polimec' && !(destination === 'AssetHubPolkadot' && asset.symbol === 'DOT') && !isEthAsset;
8657
+ return destination !== 'Ethereum' && destination !== 'Polimec' && !(destination === 'AssetHubPolkadot' && asset.symbol === 'DOT') && !isEthAsset && !feeAsset;
8462
8658
  }
8463
8659
  }, {
8464
8660
  key: "transferLocalNativeAsset",
@@ -10361,4 +10557,4 @@ var Builder = function Builder(api) {
10361
10557
  return new GeneralBuilder(api, new BatchTransactionManager());
10362
10558
  };
10363
10559
 
10364
- export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, XTokensError, addXcmVersionHeader, assertAddressIsString, assertHasLocation, assertToIsString, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiary, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
10560
+ export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, XTokensError, addXcmVersionHeader, assertAddressIsString, assertHasLocation, assertToIsString, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiary, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, localizeLocation, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, validateAddress, verifyEdOnDestination };