@paraspell/sdk 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -338,6 +338,15 @@ function _toPropertyKey(t) {
338
338
  var i = _toPrimitive(t, "string");
339
339
  return "symbol" == typeof i ? i : i + "";
340
340
  }
341
+ function _typeof(o) {
342
+ "@babel/helpers - typeof";
343
+
344
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
345
+ return typeof o;
346
+ } : function (o) {
347
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
348
+ }, _typeof(o);
349
+ }
341
350
  function _classCallCheck(instance, Constructor) {
342
351
  if (!(instance instanceof Constructor)) {
343
352
  throw new TypeError("Cannot call a class as a function");
@@ -498,6 +507,57 @@ function _arrayLikeToArray(arr, len) {
498
507
  function _nonIterableSpread() {
499
508
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
500
509
  }
510
+ function _createForOfIteratorHelper(o, allowArrayLike) {
511
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
512
+ if (!it) {
513
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
514
+ if (it) o = it;
515
+ var i = 0;
516
+ var F = function () {};
517
+ return {
518
+ s: F,
519
+ n: function () {
520
+ if (i >= o.length) return {
521
+ done: true
522
+ };
523
+ return {
524
+ done: false,
525
+ value: o[i++]
526
+ };
527
+ },
528
+ e: function (e) {
529
+ throw e;
530
+ },
531
+ f: F
532
+ };
533
+ }
534
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
535
+ }
536
+ var normalCompletion = true,
537
+ didErr = false,
538
+ err;
539
+ return {
540
+ s: function () {
541
+ it = it.call(o);
542
+ },
543
+ n: function () {
544
+ var step = it.next();
545
+ normalCompletion = step.done;
546
+ return step;
547
+ },
548
+ e: function (e) {
549
+ didErr = true;
550
+ err = e;
551
+ },
552
+ f: function () {
553
+ try {
554
+ if (!normalCompletion && it.return != null) it.return();
555
+ } finally {
556
+ if (didErr) throw err;
557
+ }
558
+ }
559
+ };
560
+ }
501
561
 
502
562
  /******************************************************************************
503
563
  Copyright (c) Microsoft Corporation.
@@ -5599,18 +5659,18 @@ var constructRelayToParaParameters = function constructRelayToParaParameters(_re
5599
5659
  amount = _ref.amount,
5600
5660
  paraIdTo = _ref.paraIdTo;
5601
5661
  var includeFee = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5602
- var paraId = paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination);
5603
- var parameters = [createPolkadotXcmHeader('RelayToPara', version, paraId), generateAddressPayload(api, 'RelayToPara', null, address, version, paraId), createCurrencySpec(amount, version, exports.Parents.ZERO), 0];
5662
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5663
+ var parameters = [createPolkadotXcmHeader('RelayToPara', version, destination, paraId), generateAddressPayload(api, 'RelayToPara', null, address, version, paraId), createCurrencySpec(amount, version, exports.Parents.ZERO), 0];
5604
5664
  if (includeFee) {
5605
5665
  parameters.push('Unlimited');
5606
5666
  }
5607
5667
  return parameters;
5608
5668
  };
5609
- var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5610
- var interior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Here';
5669
+ var createCurrencySpec = function createCurrencySpec(amount, version, parents, overridedMultiLocation) {
5670
+ var interior = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'Here';
5611
5671
  return _defineProperty({}, version, [{
5612
5672
  id: {
5613
- Concrete: {
5673
+ Concrete: overridedMultiLocation !== null && overridedMultiLocation !== void 0 ? overridedMultiLocation : {
5614
5674
  parents: parents,
5615
5675
  interior: interior
5616
5676
  }
@@ -5620,14 +5680,15 @@ var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5620
5680
  }
5621
5681
  }]);
5622
5682
  };
5623
- var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, nodeId) {
5683
+ var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, destination, nodeId) {
5624
5684
  var parents = scenario === 'RelayToPara' ? exports.Parents.ZERO : exports.Parents.ONE;
5625
5685
  var interior = scenario === 'ParaToRelay' ? 'Here' : {
5626
5686
  X1: {
5627
5687
  Parachain: nodeId
5628
5688
  }
5629
5689
  };
5630
- return _defineProperty({}, scenario === 'RelayToPara' ? exports.Version.V3 : version, {
5690
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5691
+ return _defineProperty({}, scenario === 'RelayToPara' ? exports.Version.V3 : version, isMultiLocationDestination ? destination : {
5631
5692
  parents: parents,
5632
5693
  interior: interior
5633
5694
  });
@@ -5651,6 +5712,42 @@ var calculateTransactionFee = function calculateTransactionFee(tx, address) {
5651
5712
  }, _callee);
5652
5713
  }));
5653
5714
  };
5715
+ var findParachainJunction = function findParachainJunction(multilocation) {
5716
+ var interior = multilocation.interior;
5717
+ for (var key in interior) {
5718
+ var junctions = interior[key];
5719
+ if (Array.isArray(junctions)) {
5720
+ var _iterator = _createForOfIteratorHelper(junctions),
5721
+ _step;
5722
+ try {
5723
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5724
+ var junction = _step.value;
5725
+ if ('Parachain' in junction) {
5726
+ return Number(junction.Parachain);
5727
+ }
5728
+ }
5729
+ } catch (err) {
5730
+ _iterator.e(err);
5731
+ } finally {
5732
+ _iterator.f();
5733
+ }
5734
+ } else if (junctions !== undefined && 'Parachain' in junctions) {
5735
+ return Number(junctions.Parachain);
5736
+ }
5737
+ }
5738
+ return null;
5739
+ };
5740
+ var resolveTNodeFromMultiLocation = function resolveTNodeFromMultiLocation(multiLocation) {
5741
+ var parachainId = findParachainJunction(multiLocation);
5742
+ if (parachainId === null) {
5743
+ throw new Error('Parachain ID not found in destination multi location.');
5744
+ }
5745
+ var node = getTNode(parachainId);
5746
+ if (node === null) {
5747
+ throw new Error('Node with specified paraId not found in destination multi location.');
5748
+ }
5749
+ return node;
5750
+ };
5654
5751
 
5655
5752
  var supportsXTokens = function supportsXTokens(obj) {
5656
5753
  return 'transferXTokens' in obj;
@@ -5705,10 +5802,11 @@ var ParachainNode = /*#__PURE__*/function () {
5705
5802
  address = options.address,
5706
5803
  destination = options.destination,
5707
5804
  paraIdTo = options.paraIdTo,
5805
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
5708
5806
  _options$serializedAp = options.serializedApiCallEnabled,
5709
5807
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
5710
5808
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
5711
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5809
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5712
5810
  if (supportsXTokens(this)) {
5713
5811
  return this.transferXTokens({
5714
5812
  api: api,
@@ -5721,6 +5819,7 @@ var ParachainNode = /*#__PURE__*/function () {
5721
5819
  scenario: scenario,
5722
5820
  paraIdTo: paraId,
5723
5821
  destination: destination,
5822
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5724
5823
  serializedApiCallEnabled: serializedApiCallEnabled
5725
5824
  });
5726
5825
  } else if (supportsXTransfer(this)) {
@@ -5733,14 +5832,15 @@ var ParachainNode = /*#__PURE__*/function () {
5733
5832
  paraId: paraId,
5734
5833
  origin: this.node,
5735
5834
  destination: destination,
5835
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5736
5836
  serializedApiCallEnabled: serializedApiCallEnabled
5737
5837
  });
5738
5838
  } else if (supportsPolkadotXCM(this)) {
5739
5839
  return this.transferPolkadotXCM({
5740
5840
  api: api,
5741
- header: this.createPolkadotXcmHeader(scenario, paraId),
5841
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
5742
5842
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
5743
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
5843
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
5744
5844
  scenario: scenario,
5745
5845
  currencySymbol: currencySymbol,
5746
5846
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -5783,13 +5883,13 @@ var ParachainNode = /*#__PURE__*/function () {
5783
5883
  }
5784
5884
  }, {
5785
5885
  key: "createCurrencySpec",
5786
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
5787
- return createCurrencySpec(amount, version, scenario === 'ParaToRelay' ? exports.Parents.ONE : exports.Parents.ZERO);
5886
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
5887
+ return createCurrencySpec(amount, version, scenario === 'ParaToRelay' ? exports.Parents.ONE : exports.Parents.ZERO, overridedMultiLocation);
5788
5888
  }
5789
5889
  }, {
5790
5890
  key: "createPolkadotXcmHeader",
5791
- value: function createPolkadotXcmHeader$1(scenario, paraId) {
5792
- return createPolkadotXcmHeader(scenario, this.version, paraId);
5891
+ value: function createPolkadotXcmHeader$1(scenario, destination, paraId) {
5892
+ return createPolkadotXcmHeader(scenario, this.version, destination, paraId);
5793
5893
  }
5794
5894
  }]);
5795
5895
  }();
@@ -5815,6 +5915,20 @@ var getModifiedCurrencySelection = function getModifiedCurrencySelection(version
5815
5915
  }
5816
5916
  });
5817
5917
  };
5918
+ var getCurrencySelection = function getCurrencySelection(_ref2, isAssetHub, currencySelection) {
5919
+ var origin = _ref2.origin,
5920
+ amount = _ref2.amount,
5921
+ currencyID = _ref2.currencyID,
5922
+ paraIdTo = _ref2.paraIdTo,
5923
+ overridedCurrencyMultiLocation = _ref2.overridedCurrencyMultiLocation;
5924
+ var _getNode = getNode(origin),
5925
+ version = _getNode.version;
5926
+ if (overridedCurrencyMultiLocation !== undefined) return _defineProperty({}, version, overridedCurrencyMultiLocation);
5927
+ if (isAssetHub) {
5928
+ return getModifiedCurrencySelection(version, amount, currencyID, paraIdTo);
5929
+ }
5930
+ return currencySelection;
5931
+ };
5818
5932
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
5819
5933
  var XTokensTransferImpl = /*#__PURE__*/function () {
5820
5934
  function XTokensTransferImpl() {
@@ -5822,30 +5936,30 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
5822
5936
  }
5823
5937
  return _createClass(XTokensTransferImpl, null, [{
5824
5938
  key: "transferXTokens",
5825
- value: function transferXTokens(_ref2, currencySelection) {
5826
- var api = _ref2.api,
5827
- amount = _ref2.amount,
5828
- currencyID = _ref2.currencyID,
5829
- addressSelection = _ref2.addressSelection,
5830
- origin = _ref2.origin,
5831
- destination = _ref2.destination,
5832
- paraIdTo = _ref2.paraIdTo,
5833
- serializedApiCallEnabled = _ref2.serializedApiCallEnabled;
5939
+ value: function transferXTokens(input, currencySelection) {
5834
5940
  var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Unlimited';
5835
5941
  var pallet = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'XTokens';
5942
+ var api = input.api,
5943
+ amount = input.amount,
5944
+ addressSelection = input.addressSelection,
5945
+ destination = input.destination,
5946
+ serializedApiCallEnabled = input.serializedApiCallEnabled;
5947
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5948
+ if (isMultiLocationDestination) {
5949
+ throw new Error('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
5950
+ }
5836
5951
  var module = lowercaseFirstLetter(pallet.toString());
5837
5952
  var isAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5838
- var node = getNode(origin);
5839
- var modifiedCurrencySelection = isAssetHub ? getModifiedCurrencySelection(node.version, amount, currencyID, paraIdTo) : currencySelection;
5953
+ var modifiedCurrencySelection = getCurrencySelection(input, isAssetHub, currencySelection);
5840
5954
  var section = isAssetHub ? 'transferMultiasset' : 'transfer';
5841
5955
  if (serializedApiCallEnabled === true) {
5842
5956
  return {
5843
5957
  module: module,
5844
5958
  section: section,
5845
- parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [currencySelection, amount, addressSelection, fees]
5959
+ parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [modifiedCurrencySelection, amount, addressSelection, fees]
5846
5960
  };
5847
5961
  }
5848
- return isAssetHub ? api.tx[module][section](modifiedCurrencySelection, addressSelection, fees) : api.tx[module][section](currencySelection, amount, addressSelection, fees);
5962
+ return isAssetHub ? api.tx[module][section](modifiedCurrencySelection, addressSelection, fees) : api.tx[module][section](modifiedCurrencySelection, amount, addressSelection, fees);
5849
5963
  }
5850
5964
  }]);
5851
5965
  }();
@@ -6560,7 +6674,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6560
6674
  }
6561
6675
  }, {
6562
6676
  key: "createCurrencySpec",
6563
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6677
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6564
6678
  if (scenario === 'ParaToPara') {
6565
6679
  var interior = {
6566
6680
  X2: [{
@@ -6569,7 +6683,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6569
6683
  GeneralIndex: currencyId
6570
6684
  }]
6571
6685
  };
6572
- return createCurrencySpec(amount, version, exports.Parents.ZERO, interior);
6686
+ return createCurrencySpec(amount, version, exports.Parents.ZERO, overridedMultiLocation, interior);
6573
6687
  } else {
6574
6688
  return _get(_getPrototypeOf(AssetHubPolkadot.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6575
6689
  }
@@ -6719,10 +6833,11 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6719
6833
  address = options.address,
6720
6834
  destination = options.destination,
6721
6835
  paraIdTo = options.paraIdTo,
6836
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6722
6837
  _options$serializedAp = options.serializedApiCallEnabled,
6723
6838
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6724
6839
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6725
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6840
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6726
6841
  var node = this.node;
6727
6842
  if (supportsXTokens(this) && currencySymbol !== 'ASTR') {
6728
6843
  return this.transferXTokens({
@@ -6736,14 +6851,15 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6736
6851
  scenario: scenario,
6737
6852
  paraIdTo: paraId,
6738
6853
  destination: destination,
6854
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6739
6855
  serializedApiCallEnabled: serializedApiCallEnabled
6740
6856
  });
6741
6857
  } else if (supportsPolkadotXCM(this)) {
6742
6858
  return this.transferPolkadotXCM({
6743
6859
  api: api,
6744
- header: this.createPolkadotXcmHeader(scenario, paraId),
6860
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6745
6861
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6746
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
6862
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6747
6863
  scenario: scenario,
6748
6864
  currencySymbol: currencySymbol,
6749
6865
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -6774,14 +6890,14 @@ var Darwinia$2 = /*#__PURE__*/function (_ParachainNode) {
6774
6890
  }
6775
6891
  }, {
6776
6892
  key: "createCurrencySpec",
6777
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6893
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6778
6894
  if (scenario === 'ParaToPara') {
6779
6895
  var interior = {
6780
6896
  X1: {
6781
6897
  PalletInstance: 5
6782
6898
  }
6783
6899
  };
6784
- return createCurrencySpec(amount, version, exports.Parents.ZERO, interior);
6900
+ return createCurrencySpec(amount, version, exports.Parents.ZERO, overridedMultiLocation, interior);
6785
6901
  } else {
6786
6902
  return _get(_getPrototypeOf(Darwinia.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6787
6903
  }
@@ -6866,10 +6982,11 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6866
6982
  address = options.address,
6867
6983
  destination = options.destination,
6868
6984
  paraIdTo = options.paraIdTo,
6985
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6869
6986
  _options$serializedAp = options.serializedApiCallEnabled,
6870
6987
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6871
6988
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6872
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6989
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6873
6990
  var node = this.node;
6874
6991
  if (supportsXTokens(this) && currencySymbol !== 'SDN') {
6875
6992
  return this.transferXTokens({
@@ -6879,18 +6996,19 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6879
6996
  amount: amount,
6880
6997
  addressSelection: generateAddressPayload(api, scenario, 'XTokens', address, this.version, paraId),
6881
6998
  fees: getFees(scenario),
6999
+ origin: this.node,
6882
7000
  scenario: scenario,
6883
7001
  paraIdTo: paraId,
6884
- origin: this.node,
6885
7002
  destination: destination,
7003
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6886
7004
  serializedApiCallEnabled: serializedApiCallEnabled
6887
7005
  });
6888
7006
  } else if (supportsPolkadotXCM(this)) {
6889
7007
  return this.transferPolkadotXCM({
6890
7008
  api: api,
6891
- header: this.createPolkadotXcmHeader(scenario, paraId),
7009
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6892
7010
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6893
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
7011
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6894
7012
  scenario: scenario,
6895
7013
  currencySymbol: currencySymbol,
6896
7014
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -7070,6 +7188,28 @@ var determineDestWeight = function determineDestWeight(destNode) {
7070
7188
  }
7071
7189
  throw new NodeNotSupportedError("Node ".concat(destNode, " is not supported"));
7072
7190
  };
7191
+ var getDestination = function getDestination(_ref) {
7192
+ var recipientAddress = _ref.recipientAddress,
7193
+ paraId = _ref.paraId,
7194
+ api = _ref.api;
7195
+ var isMultiLocation = _typeof(recipientAddress) === 'object';
7196
+ if (isMultiLocation) {
7197
+ return recipientAddress;
7198
+ }
7199
+ var isEthAddress = ethers.ethers.utils.isAddress(recipientAddress);
7200
+ return {
7201
+ parents: 1,
7202
+ interior: {
7203
+ X2: [{
7204
+ Parachain: paraId
7205
+ }, _defineProperty({}, isEthAddress ? 'AccountKey20' : 'AccountId32', Object.assign({}, isEthAddress ? {
7206
+ key: recipientAddress
7207
+ } : {
7208
+ id: createAccID(api, recipientAddress)
7209
+ }))]
7210
+ }
7211
+ };
7212
+ };
7073
7213
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
7074
7214
  var XTransferTransferImpl = /*#__PURE__*/function () {
7075
7215
  function XTransferTransferImpl() {
@@ -7077,28 +7217,19 @@ var XTransferTransferImpl = /*#__PURE__*/function () {
7077
7217
  }
7078
7218
  return _createClass(XTransferTransferImpl, null, [{
7079
7219
  key: "transferXTransfer",
7080
- value: function transferXTransfer(_ref) {
7081
- var api = _ref.api,
7082
- amount = _ref.amount,
7083
- origin = _ref.origin,
7084
- recipientAddress = _ref.recipientAddress,
7085
- destination = _ref.destination,
7086
- paraId = _ref.paraId,
7087
- serializedApiCallEnabled = _ref.serializedApiCallEnabled;
7088
- var currencySpec = createCurrencySpec(amount, exports.Version.V1, exports.Parents.ZERO)[exports.Version.V1][0];
7089
- var isEthAddress = ethers.ethers.utils.isAddress(recipientAddress);
7090
- var dest = {
7091
- parents: 1,
7092
- interior: {
7093
- X2: [{
7094
- Parachain: paraId
7095
- }, _defineProperty({}, isEthAddress ? 'AccountKey20' : 'AccountId32', Object.assign({}, isEthAddress ? {
7096
- key: recipientAddress
7097
- } : {
7098
- id: createAccID(api, recipientAddress)
7099
- }))]
7100
- }
7101
- };
7220
+ value: function transferXTransfer(input) {
7221
+ var api = input.api,
7222
+ amount = input.amount,
7223
+ origin = input.origin,
7224
+ destination = input.destination,
7225
+ serializedApiCallEnabled = input.serializedApiCallEnabled,
7226
+ overridedCurrencyMultiLocation = input.overridedCurrencyMultiLocation;
7227
+ var isMultiLocationDestination = _typeof(destination) === 'object';
7228
+ if (isMultiLocationDestination) {
7229
+ throw new Error('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
7230
+ }
7231
+ var currencySpec = createCurrencySpec(amount, exports.Version.V1, exports.Parents.ZERO, overridedCurrencyMultiLocation)[exports.Version.V1][0];
7232
+ var dest = getDestination(input);
7102
7233
  if (serializedApiCallEnabled === true) {
7103
7234
  return {
7104
7235
  module: 'xTransfer',
@@ -7229,6 +7360,10 @@ var getFees = function getFees(scenario) {
7229
7360
  throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
7230
7361
  };
7231
7362
  var generateAddressPayload = function generateAddressPayload(api, scenario, pallet, recipientAddress, version, nodeId) {
7363
+ var isMultiLocation = _typeof(recipientAddress) === 'object';
7364
+ if (isMultiLocation) {
7365
+ return _defineProperty({}, version, recipientAddress);
7366
+ }
7232
7367
  var isEthAddress = ethers.ethers.utils.isAddress(recipientAddress);
7233
7368
  if (scenario === 'ParaToRelay') {
7234
7369
  return _defineProperty({}, version, {
@@ -7294,8 +7429,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7294
7429
  var _getNode = getNode(node),
7295
7430
  type = _getNode.type,
7296
7431
  name = _getNode.name;
7297
- var _ref5 = type === 'polkadot' ? endpoints.prodRelayPolkadot : endpoints.prodRelayKusama,
7298
- linked = _ref5.linked;
7432
+ var _ref6 = type === 'polkadot' ? endpoints.prodRelayPolkadot : endpoints.prodRelayKusama,
7433
+ linked = _ref6.linked;
7299
7434
  if (linked === undefined) return undefined;
7300
7435
  var preferredOption = linked.find(function (o) {
7301
7436
  return o.info === name && Object.values(o.providers).length > 0;
@@ -7306,8 +7441,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7306
7441
  };
7307
7442
  var getAllNodeProviders = function getAllNodeProviders(node) {
7308
7443
  var _a;
7309
- var _ref6 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7310
- providers = _ref6.providers;
7444
+ var _ref7 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7445
+ providers = _ref7.providers;
7311
7446
  if (providers.length < 1) {
7312
7447
  throw new Error("Node ".concat(node, " does not have any providers."));
7313
7448
  }
@@ -7367,18 +7502,22 @@ var createApiInstanceForNode = function createApiInstanceForNode(node) {
7367
7502
  var lowercaseFirstLetter = function lowercaseFirstLetter(str) {
7368
7503
  return str.charAt(0).toLowerCase() + str.slice(1);
7369
7504
  };
7370
- var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref7) {
7505
+ var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref8) {
7371
7506
  var _api$tx$module;
7372
- var module = _ref7.module,
7373
- section = _ref7.section,
7374
- parameters = _ref7.parameters;
7507
+ var module = _ref8.module,
7508
+ section = _ref8.section,
7509
+ parameters = _ref8.parameters;
7375
7510
  return (_api$tx$module = api.tx[module])[section].apply(_api$tx$module, _toConsumableArray(parameters));
7376
7511
  };
7377
7512
  var determineRelayChain = function determineRelayChain(node) {
7378
7513
  return getRelayChainSymbol(node) === 'KSM' ? 'Kusama' : 'Polkadot';
7379
7514
  };
7380
7515
 
7381
- var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7516
+ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, currency) {
7517
+ if (_typeof(currency) === 'object') {
7518
+ return null;
7519
+ }
7520
+ var currencyString = currency.toString();
7382
7521
  var _getAssetsObject = getAssetsObject(node),
7383
7522
  otherAssets = _getAssetsObject.otherAssets,
7384
7523
  nativeAssets = _getAssetsObject.nativeAssets,
@@ -7386,7 +7525,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7386
7525
  var asset = [].concat(_toConsumableArray(otherAssets), _toConsumableArray(nativeAssets)).find(function (_ref) {
7387
7526
  var symbol = _ref.symbol,
7388
7527
  assetId = _ref.assetId;
7389
- return symbol === symbolOrId || assetId === symbolOrId;
7528
+ return symbol === currencyString || assetId === currencyString;
7390
7529
  });
7391
7530
  if (asset !== undefined) {
7392
7531
  var symbol = asset.symbol,
@@ -7396,7 +7535,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7396
7535
  assetId: assetId
7397
7536
  };
7398
7537
  }
7399
- if (relayChainAssetSymbol === symbolOrId) return {
7538
+ if (relayChainAssetSymbol === currencyString) return {
7400
7539
  symbol: relayChainAssetSymbol
7401
7540
  };
7402
7541
  return null;
@@ -7724,6 +7863,9 @@ var OpenChannelBuilder = /*#__PURE__*/function () {
7724
7863
  }, {
7725
7864
  key: "buildOptions",
7726
7865
  value: function buildOptions() {
7866
+ if (_typeof(this.to) === 'object') {
7867
+ throw new Error('Channels do not support multi-location destinations');
7868
+ }
7727
7869
  return {
7728
7870
  api: this.api,
7729
7871
  origin: this.from,
@@ -8236,71 +8378,98 @@ var checkKeepAlive = function checkKeepAlive(_ref) {
8236
8378
 
8237
8379
  var sendCommon = function sendCommon(options) {
8238
8380
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
8239
- var _a, api, origin, currencySymbolOrId, amount, address, destination, paraIdTo, destApiForKeepAlive, _options$serializedAp, serializedApiCallEnabled, asset, originRelayChainSymbol, destinationRelayChainSymbol, originNode, assetCheckEnabled, apiWithFallback, amountStr, currencyId;
8381
+ var _a, api, origin, currency, amount, address, destination, paraIdTo, destApiForKeepAlive, _options$serializedAp, serializedApiCallEnabled, asset, isMultiLocationDestination, isMultiLocationCurrency, originRelayChainSymbol, destinationRelayChainSymbol, originNode, assetCheckEnabled, apiWithFallback, amountStr, currencyStr, currencyId;
8240
8382
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8241
8383
  while (1) switch (_context.prev = _context.next) {
8242
8384
  case 0:
8243
- api = options.api, origin = options.origin, currencySymbolOrId = options.currency, amount = options.amount, address = options.address, destination = options.destination, paraIdTo = options.paraIdTo, destApiForKeepAlive = options.destApiForKeepAlive, _options$serializedAp = options.serializedApiCallEnabled, serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
8244
- if (!(typeof currencySymbolOrId === 'number' && currencySymbolOrId > Number.MAX_SAFE_INTEGER)) {
8385
+ api = options.api, origin = options.origin, currency = options.currency, amount = options.amount, address = options.address, destination = options.destination, paraIdTo = options.paraIdTo, destApiForKeepAlive = options.destApiForKeepAlive, _options$serializedAp = options.serializedApiCallEnabled, serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
8386
+ if (!(typeof currency === 'number' && currency > Number.MAX_SAFE_INTEGER)) {
8245
8387
  _context.next = 3;
8246
8388
  break;
8247
8389
  }
8248
8390
  throw new InvalidCurrencyError('The provided asset ID is larger than the maximum safe integer value. Please provide it as a string.');
8249
8391
  case 3:
8250
- asset = getAssetBySymbolOrId(origin, currencySymbolOrId.toString());
8251
- if (!(destination !== undefined)) {
8252
- _context.next = 9;
8392
+ asset = getAssetBySymbolOrId(origin, currency);
8393
+ isMultiLocationDestination = _typeof(destination) === 'object';
8394
+ isMultiLocationCurrency = _typeof(currency) === 'object';
8395
+ if (!(destination !== undefined && !isMultiLocationDestination)) {
8396
+ _context.next = 11;
8253
8397
  break;
8254
8398
  }
8255
8399
  originRelayChainSymbol = getRelayChainSymbol(origin);
8256
8400
  destinationRelayChainSymbol = getRelayChainSymbol(destination);
8257
8401
  if (!(originRelayChainSymbol !== destinationRelayChainSymbol)) {
8258
- _context.next = 9;
8402
+ _context.next = 11;
8259
8403
  break;
8260
8404
  }
8261
8405
  throw new IncompatibleNodesError();
8262
- case 9:
8406
+ case 11:
8263
8407
  originNode = getNode(origin);
8264
- assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' ? false : originNode.assetCheckEnabled;
8408
+ assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' || isMultiLocationCurrency ? false : originNode.assetCheckEnabled;
8265
8409
  if (!(asset === null && assetCheckEnabled)) {
8266
- _context.next = 13;
8267
- break;
8268
- }
8269
- throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency or currencyId ").concat(currencySymbolOrId, "."));
8270
- case 13:
8271
- if (!(destination !== undefined && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !hasSupportForAsset(destination, asset.symbol))) {
8272
8410
  _context.next = 15;
8273
8411
  break;
8274
8412
  }
8275
- throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency or currencyId ").concat(currencySymbolOrId, "."));
8413
+ throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency or currencyId ").concat(JSON.stringify(currency), "."));
8276
8414
  case 15:
8415
+ if (!(destination !== undefined && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !hasSupportForAsset(destination, asset.symbol))) {
8416
+ _context.next = 17;
8417
+ break;
8418
+ }
8419
+ throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency or currencyId ").concat(JSON.stringify(currency), "."));
8420
+ case 17:
8277
8421
  if (!(api !== null && api !== void 0)) {
8278
- _context.next = 19;
8422
+ _context.next = 21;
8279
8423
  break;
8280
8424
  }
8281
8425
  _context.t0 = api;
8282
- _context.next = 22;
8426
+ _context.next = 24;
8283
8427
  break;
8284
- case 19:
8285
- _context.next = 21;
8286
- return createApiInstanceForNode(origin);
8287
8428
  case 21:
8429
+ _context.next = 23;
8430
+ return createApiInstanceForNode(origin);
8431
+ case 23:
8288
8432
  _context.t0 = _context.sent;
8289
- case 22:
8433
+ case 24:
8290
8434
  apiWithFallback = _context.t0;
8291
8435
  amountStr = amount.toString();
8292
- _context.next = 26;
8436
+ if (!(_typeof(currency) === 'object')) {
8437
+ _context.next = 30;
8438
+ break;
8439
+ }
8440
+ console.warn('Keep alive check is not supported when using MultiLocation as currency.');
8441
+ _context.next = 40;
8442
+ break;
8443
+ case 30:
8444
+ if (!(_typeof(address) === 'object')) {
8445
+ _context.next = 34;
8446
+ break;
8447
+ }
8448
+ console.warn('Keep alive check is not supported when using MultiLocation as address.');
8449
+ _context.next = 40;
8450
+ break;
8451
+ case 34:
8452
+ if (!(_typeof(destination) === 'object')) {
8453
+ _context.next = 38;
8454
+ break;
8455
+ }
8456
+ console.warn('Keep alive check is not supported when using MultiLocation as destination.');
8457
+ _context.next = 40;
8458
+ break;
8459
+ case 38:
8460
+ _context.next = 40;
8293
8461
  return checkKeepAlive({
8294
8462
  originApi: apiWithFallback,
8295
8463
  address: address,
8296
8464
  amount: amountStr,
8297
8465
  originNode: origin,
8298
8466
  destApi: destApiForKeepAlive,
8299
- currencySymbol: (_a = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _a !== void 0 ? _a : currencySymbolOrId.toString(),
8467
+ currencySymbol: (_a = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _a !== void 0 ? _a : currency.toString(),
8300
8468
  destNode: destination
8301
8469
  });
8302
- case 26:
8303
- currencyId = assetCheckEnabled ? asset === null || asset === void 0 ? void 0 : asset.assetId : currencySymbolOrId.toString();
8470
+ case 40:
8471
+ currencyStr = _typeof(currency) === 'object' ? undefined : currency.toString();
8472
+ currencyId = assetCheckEnabled ? asset === null || asset === void 0 ? void 0 : asset.assetId : currencyStr;
8304
8473
  return _context.abrupt("return", originNode.transfer({
8305
8474
  api: apiWithFallback,
8306
8475
  currencySymbol: asset === null || asset === void 0 ? void 0 : asset.symbol,
@@ -8309,9 +8478,10 @@ var sendCommon = function sendCommon(options) {
8309
8478
  address: address,
8310
8479
  destination: destination,
8311
8480
  paraIdTo: paraIdTo,
8481
+ overridedCurrencyMultiLocation: _typeof(currency) === 'object' ? currency : undefined,
8312
8482
  serializedApiCallEnabled: serializedApiCallEnabled
8313
8483
  }));
8314
- case 28:
8484
+ case 43:
8315
8485
  case "end":
8316
8486
  return _context.stop();
8317
8487
  }
@@ -8354,39 +8524,61 @@ var send = function send(options) {
8354
8524
  };
8355
8525
  var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8356
8526
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
8357
- var api, destination, amount, address, paraIdTo, destApiForKeepAlive, _options$serializedAp2, serializedApiCallEnabled, currencySymbol, relayNode, apiWithFallback, amountStr, serializedApiCall;
8527
+ var api, destination, amount, address, paraIdTo, destApiForKeepAlive, _options$serializedAp2, serializedApiCallEnabled, isMultiLocationDestination, isAddressMultiLocation, apiWithFallback, amountStr, serializedApiCall;
8358
8528
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
8359
8529
  while (1) switch (_context4.prev = _context4.next) {
8360
8530
  case 0:
8361
8531
  api = options.api, destination = options.destination, amount = options.amount, address = options.address, paraIdTo = options.paraIdTo, destApiForKeepAlive = options.destApiForKeepAlive, _options$serializedAp2 = options.serializedApiCallEnabled, serializedApiCallEnabled = _options$serializedAp2 === void 0 ? false : _options$serializedAp2;
8362
- currencySymbol = getRelayChainSymbol(destination);
8363
- relayNode = determineRelayChain(destination);
8532
+ isMultiLocationDestination = _typeof(destination) === 'object';
8533
+ isAddressMultiLocation = _typeof(address) === 'object';
8534
+ if (!(api === undefined && isMultiLocationDestination)) {
8535
+ _context4.next = 5;
8536
+ break;
8537
+ }
8538
+ throw new Error('API is required when using MultiLocation as destination.');
8539
+ case 5:
8364
8540
  if (!(api !== null && api !== void 0)) {
8365
- _context4.next = 7;
8541
+ _context4.next = 9;
8366
8542
  break;
8367
8543
  }
8368
8544
  _context4.t0 = api;
8369
- _context4.next = 10;
8545
+ _context4.next = 12;
8370
8546
  break;
8371
- case 7:
8372
- _context4.next = 9;
8373
- return createApiInstanceForNode(relayNode);
8374
8547
  case 9:
8548
+ _context4.next = 11;
8549
+ return createApiInstanceForNode(determineRelayChain(destination));
8550
+ case 11:
8375
8551
  _context4.t0 = _context4.sent;
8376
- case 10:
8552
+ case 12:
8377
8553
  apiWithFallback = _context4.t0;
8378
8554
  amountStr = amount.toString();
8379
- _context4.next = 14;
8555
+ if (!isMultiLocationDestination) {
8556
+ _context4.next = 18;
8557
+ break;
8558
+ }
8559
+ console.warn('Keep alive check is not supported when using MultiLocation as destination.');
8560
+ _context4.next = 24;
8561
+ break;
8562
+ case 18:
8563
+ if (!isAddressMultiLocation) {
8564
+ _context4.next = 22;
8565
+ break;
8566
+ }
8567
+ console.warn('Keep alive check is not supported when using MultiLocation as address.');
8568
+ _context4.next = 24;
8569
+ break;
8570
+ case 22:
8571
+ _context4.next = 24;
8380
8572
  return checkKeepAlive({
8381
8573
  originApi: apiWithFallback,
8382
8574
  address: address,
8383
8575
  amount: amountStr,
8384
8576
  destApi: destApiForKeepAlive,
8385
- currencySymbol: currencySymbol,
8577
+ currencySymbol: getRelayChainSymbol(destination),
8386
8578
  destNode: destination
8387
8579
  });
8388
- case 14:
8389
- serializedApiCall = getNode(destination).transferRelayToPara({
8580
+ case 24:
8581
+ serializedApiCall = getNode(isMultiLocationDestination ? resolveTNodeFromMultiLocation(destination) : destination).transferRelayToPara({
8390
8582
  api: apiWithFallback,
8391
8583
  destination: destination,
8392
8584
  address: address,
@@ -8395,13 +8587,13 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8395
8587
  destApiForKeepAlive: destApiForKeepAlive
8396
8588
  });
8397
8589
  if (!serializedApiCallEnabled) {
8398
- _context4.next = 17;
8590
+ _context4.next = 27;
8399
8591
  break;
8400
8592
  }
8401
8593
  return _context4.abrupt("return", serializedApiCall);
8402
- case 17:
8594
+ case 27:
8403
8595
  return _context4.abrupt("return", callPolkadotJsTxFunction(apiWithFallback, serializedApiCall));
8404
- case 18:
8596
+ case 28:
8405
8597
  case "end":
8406
8598
  return _context4.stop();
8407
8599
  }