@paraspell/sdk 5.0.0 → 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.mjs CHANGED
@@ -336,6 +336,15 @@ function _toPropertyKey(t) {
336
336
  var i = _toPrimitive(t, "string");
337
337
  return "symbol" == typeof i ? i : i + "";
338
338
  }
339
+ function _typeof(o) {
340
+ "@babel/helpers - typeof";
341
+
342
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
343
+ return typeof o;
344
+ } : function (o) {
345
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
346
+ }, _typeof(o);
347
+ }
339
348
  function _classCallCheck(instance, Constructor) {
340
349
  if (!(instance instanceof Constructor)) {
341
350
  throw new TypeError("Cannot call a class as a function");
@@ -496,6 +505,57 @@ function _arrayLikeToArray(arr, len) {
496
505
  function _nonIterableSpread() {
497
506
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
498
507
  }
508
+ function _createForOfIteratorHelper(o, allowArrayLike) {
509
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
510
+ if (!it) {
511
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
512
+ if (it) o = it;
513
+ var i = 0;
514
+ var F = function () {};
515
+ return {
516
+ s: F,
517
+ n: function () {
518
+ if (i >= o.length) return {
519
+ done: true
520
+ };
521
+ return {
522
+ done: false,
523
+ value: o[i++]
524
+ };
525
+ },
526
+ e: function (e) {
527
+ throw e;
528
+ },
529
+ f: F
530
+ };
531
+ }
532
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
533
+ }
534
+ var normalCompletion = true,
535
+ didErr = false,
536
+ err;
537
+ return {
538
+ s: function () {
539
+ it = it.call(o);
540
+ },
541
+ n: function () {
542
+ var step = it.next();
543
+ normalCompletion = step.done;
544
+ return step;
545
+ },
546
+ e: function (e) {
547
+ didErr = true;
548
+ err = e;
549
+ },
550
+ f: function () {
551
+ try {
552
+ if (!normalCompletion && it.return != null) it.return();
553
+ } finally {
554
+ if (didErr) throw err;
555
+ }
556
+ }
557
+ };
558
+ }
499
559
 
500
560
  /******************************************************************************
501
561
  Copyright (c) Microsoft Corporation.
@@ -5124,31 +5184,57 @@ var Polkadex$3 = {
5124
5184
  ],
5125
5185
  otherAssets: [
5126
5186
  {
5127
- assetId: "226557799181424065994173367616174607641"
5187
+ assetId: "226557799181424065994173367616174607641",
5188
+ symbol: "IBTC",
5189
+ decimals: 12
5128
5190
  },
5129
5191
  {
5130
- assetId: "193492391581201937291053139015355410612"
5192
+ assetId: "193492391581201937291053139015355410612",
5193
+ symbol: "PHA",
5194
+ decimals: 12
5131
5195
  },
5132
5196
  {
5133
5197
  assetId: "14826654563114266286226336203450732505"
5134
5198
  },
5135
5199
  {
5136
- assetId: "222121451965151777636299756141619631150"
5200
+ assetId: "222121451965151777636299756141619631150",
5201
+ symbol: "ASTR",
5202
+ decimals: 12
5203
+ },
5204
+ {
5205
+ assetId: "95930534000017180603917534864279132680",
5206
+ symbol: "DOT",
5207
+ decimals: 12
5208
+ },
5209
+ {
5210
+ assetId: "339306133874233608313826294843504252047",
5211
+ symbol: "PINK",
5212
+ decimals: 12
5137
5213
  },
5138
5214
  {
5139
- assetId: "95930534000017180603917534864279132680"
5215
+ assetId: "119367686984583275840673742485354142551",
5216
+ symbol: "DED",
5217
+ decimals: 12
5140
5218
  },
5141
5219
  {
5142
- assetId: "339306133874233608313826294843504252047"
5220
+ assetId: "3496813586714279103986568049643838918",
5221
+ symbol: "USDT",
5222
+ decimals: 12
5143
5223
  },
5144
5224
  {
5145
- assetId: "3496813586714279103986568049643838918"
5225
+ assetId: "32595388462891559990827225517299393930",
5226
+ symbol: "UNQ",
5227
+ decimals: 12
5146
5228
  },
5147
5229
  {
5148
- assetId: "32595388462891559990827225517299393930"
5230
+ assetId: "182269558229932594457975666948556356791",
5231
+ symbol: "GLMR",
5232
+ decimals: 12
5149
5233
  },
5150
5234
  {
5151
- assetId: "182269558229932594457975666948556356791"
5235
+ assetId: "304494718746685751324769169435167367843",
5236
+ symbol: "USDC",
5237
+ decimals: 12
5152
5238
  },
5153
5239
  {
5154
5240
  assetId: "240851462719321838889739625279903325250"
@@ -5571,18 +5657,18 @@ var constructRelayToParaParameters = function constructRelayToParaParameters(_re
5571
5657
  amount = _ref.amount,
5572
5658
  paraIdTo = _ref.paraIdTo;
5573
5659
  var includeFee = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5574
- var paraId = paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination);
5575
- var parameters = [createPolkadotXcmHeader('RelayToPara', version, paraId), generateAddressPayload(api, 'RelayToPara', null, address, version, paraId), createCurrencySpec(amount, version, Parents.ZERO), 0];
5660
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5661
+ var parameters = [createPolkadotXcmHeader('RelayToPara', version, destination, paraId), generateAddressPayload(api, 'RelayToPara', null, address, version, paraId), createCurrencySpec(amount, version, Parents.ZERO), 0];
5576
5662
  if (includeFee) {
5577
5663
  parameters.push('Unlimited');
5578
5664
  }
5579
5665
  return parameters;
5580
5666
  };
5581
- var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5582
- var interior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Here';
5667
+ var createCurrencySpec = function createCurrencySpec(amount, version, parents, overridedMultiLocation) {
5668
+ var interior = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'Here';
5583
5669
  return _defineProperty({}, version, [{
5584
5670
  id: {
5585
- Concrete: {
5671
+ Concrete: overridedMultiLocation !== null && overridedMultiLocation !== void 0 ? overridedMultiLocation : {
5586
5672
  parents: parents,
5587
5673
  interior: interior
5588
5674
  }
@@ -5592,14 +5678,15 @@ var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5592
5678
  }
5593
5679
  }]);
5594
5680
  };
5595
- var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, nodeId) {
5681
+ var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, destination, nodeId) {
5596
5682
  var parents = scenario === 'RelayToPara' ? Parents.ZERO : Parents.ONE;
5597
5683
  var interior = scenario === 'ParaToRelay' ? 'Here' : {
5598
5684
  X1: {
5599
5685
  Parachain: nodeId
5600
5686
  }
5601
5687
  };
5602
- return _defineProperty({}, scenario === 'RelayToPara' ? Version.V3 : version, {
5688
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5689
+ return _defineProperty({}, scenario === 'RelayToPara' ? Version.V3 : version, isMultiLocationDestination ? destination : {
5603
5690
  parents: parents,
5604
5691
  interior: interior
5605
5692
  });
@@ -5623,6 +5710,42 @@ var calculateTransactionFee = function calculateTransactionFee(tx, address) {
5623
5710
  }, _callee);
5624
5711
  }));
5625
5712
  };
5713
+ var findParachainJunction = function findParachainJunction(multilocation) {
5714
+ var interior = multilocation.interior;
5715
+ for (var key in interior) {
5716
+ var junctions = interior[key];
5717
+ if (Array.isArray(junctions)) {
5718
+ var _iterator = _createForOfIteratorHelper(junctions),
5719
+ _step;
5720
+ try {
5721
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5722
+ var junction = _step.value;
5723
+ if ('Parachain' in junction) {
5724
+ return Number(junction.Parachain);
5725
+ }
5726
+ }
5727
+ } catch (err) {
5728
+ _iterator.e(err);
5729
+ } finally {
5730
+ _iterator.f();
5731
+ }
5732
+ } else if (junctions !== undefined && 'Parachain' in junctions) {
5733
+ return Number(junctions.Parachain);
5734
+ }
5735
+ }
5736
+ return null;
5737
+ };
5738
+ var resolveTNodeFromMultiLocation = function resolveTNodeFromMultiLocation(multiLocation) {
5739
+ var parachainId = findParachainJunction(multiLocation);
5740
+ if (parachainId === null) {
5741
+ throw new Error('Parachain ID not found in destination multi location.');
5742
+ }
5743
+ var node = getTNode(parachainId);
5744
+ if (node === null) {
5745
+ throw new Error('Node with specified paraId not found in destination multi location.');
5746
+ }
5747
+ return node;
5748
+ };
5626
5749
 
5627
5750
  var supportsXTokens = function supportsXTokens(obj) {
5628
5751
  return 'transferXTokens' in obj;
@@ -5677,10 +5800,11 @@ var ParachainNode = /*#__PURE__*/function () {
5677
5800
  address = options.address,
5678
5801
  destination = options.destination,
5679
5802
  paraIdTo = options.paraIdTo,
5803
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
5680
5804
  _options$serializedAp = options.serializedApiCallEnabled,
5681
5805
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
5682
5806
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
5683
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5807
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
5684
5808
  if (supportsXTokens(this)) {
5685
5809
  return this.transferXTokens({
5686
5810
  api: api,
@@ -5693,6 +5817,7 @@ var ParachainNode = /*#__PURE__*/function () {
5693
5817
  scenario: scenario,
5694
5818
  paraIdTo: paraId,
5695
5819
  destination: destination,
5820
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5696
5821
  serializedApiCallEnabled: serializedApiCallEnabled
5697
5822
  });
5698
5823
  } else if (supportsXTransfer(this)) {
@@ -5705,14 +5830,15 @@ var ParachainNode = /*#__PURE__*/function () {
5705
5830
  paraId: paraId,
5706
5831
  origin: this.node,
5707
5832
  destination: destination,
5833
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5708
5834
  serializedApiCallEnabled: serializedApiCallEnabled
5709
5835
  });
5710
5836
  } else if (supportsPolkadotXCM(this)) {
5711
5837
  return this.transferPolkadotXCM({
5712
5838
  api: api,
5713
- header: this.createPolkadotXcmHeader(scenario, paraId),
5839
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
5714
5840
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
5715
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
5841
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
5716
5842
  scenario: scenario,
5717
5843
  currencySymbol: currencySymbol,
5718
5844
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -5755,13 +5881,13 @@ var ParachainNode = /*#__PURE__*/function () {
5755
5881
  }
5756
5882
  }, {
5757
5883
  key: "createCurrencySpec",
5758
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
5759
- return createCurrencySpec(amount, version, scenario === 'ParaToRelay' ? Parents.ONE : Parents.ZERO);
5884
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
5885
+ return createCurrencySpec(amount, version, scenario === 'ParaToRelay' ? Parents.ONE : Parents.ZERO, overridedMultiLocation);
5760
5886
  }
5761
5887
  }, {
5762
5888
  key: "createPolkadotXcmHeader",
5763
- value: function createPolkadotXcmHeader$1(scenario, paraId) {
5764
- return createPolkadotXcmHeader(scenario, this.version, paraId);
5889
+ value: function createPolkadotXcmHeader$1(scenario, destination, paraId) {
5890
+ return createPolkadotXcmHeader(scenario, this.version, destination, paraId);
5765
5891
  }
5766
5892
  }]);
5767
5893
  }();
@@ -5787,6 +5913,20 @@ var getModifiedCurrencySelection = function getModifiedCurrencySelection(version
5787
5913
  }
5788
5914
  });
5789
5915
  };
5916
+ var getCurrencySelection = function getCurrencySelection(_ref2, isAssetHub, currencySelection) {
5917
+ var origin = _ref2.origin,
5918
+ amount = _ref2.amount,
5919
+ currencyID = _ref2.currencyID,
5920
+ paraIdTo = _ref2.paraIdTo,
5921
+ overridedCurrencyMultiLocation = _ref2.overridedCurrencyMultiLocation;
5922
+ var _getNode = getNode(origin),
5923
+ version = _getNode.version;
5924
+ if (overridedCurrencyMultiLocation !== undefined) return _defineProperty({}, version, overridedCurrencyMultiLocation);
5925
+ if (isAssetHub) {
5926
+ return getModifiedCurrencySelection(version, amount, currencyID, paraIdTo);
5927
+ }
5928
+ return currencySelection;
5929
+ };
5790
5930
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
5791
5931
  var XTokensTransferImpl = /*#__PURE__*/function () {
5792
5932
  function XTokensTransferImpl() {
@@ -5794,30 +5934,30 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
5794
5934
  }
5795
5935
  return _createClass(XTokensTransferImpl, null, [{
5796
5936
  key: "transferXTokens",
5797
- value: function transferXTokens(_ref2, currencySelection) {
5798
- var api = _ref2.api,
5799
- amount = _ref2.amount,
5800
- currencyID = _ref2.currencyID,
5801
- addressSelection = _ref2.addressSelection,
5802
- origin = _ref2.origin,
5803
- destination = _ref2.destination,
5804
- paraIdTo = _ref2.paraIdTo,
5805
- serializedApiCallEnabled = _ref2.serializedApiCallEnabled;
5937
+ value: function transferXTokens(input, currencySelection) {
5806
5938
  var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Unlimited';
5807
5939
  var pallet = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'XTokens';
5940
+ var api = input.api,
5941
+ amount = input.amount,
5942
+ addressSelection = input.addressSelection,
5943
+ destination = input.destination,
5944
+ serializedApiCallEnabled = input.serializedApiCallEnabled;
5945
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5946
+ if (isMultiLocationDestination) {
5947
+ 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.');
5948
+ }
5808
5949
  var module = lowercaseFirstLetter(pallet.toString());
5809
5950
  var isAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5810
- var node = getNode(origin);
5811
- var modifiedCurrencySelection = isAssetHub ? getModifiedCurrencySelection(node.version, amount, currencyID, paraIdTo) : currencySelection;
5951
+ var modifiedCurrencySelection = getCurrencySelection(input, isAssetHub, currencySelection);
5812
5952
  var section = isAssetHub ? 'transferMultiasset' : 'transfer';
5813
5953
  if (serializedApiCallEnabled === true) {
5814
5954
  return {
5815
5955
  module: module,
5816
5956
  section: section,
5817
- parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [currencySelection, amount, addressSelection, fees]
5957
+ parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [modifiedCurrencySelection, amount, addressSelection, fees]
5818
5958
  };
5819
5959
  }
5820
- return isAssetHub ? api.tx[module][section](modifiedCurrencySelection, addressSelection, fees) : api.tx[module][section](currencySelection, amount, addressSelection, fees);
5960
+ return isAssetHub ? api.tx[module][section](modifiedCurrencySelection, addressSelection, fees) : api.tx[module][section](modifiedCurrencySelection, amount, addressSelection, fees);
5821
5961
  }
5822
5962
  }]);
5823
5963
  }();
@@ -6532,7 +6672,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6532
6672
  }
6533
6673
  }, {
6534
6674
  key: "createCurrencySpec",
6535
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6675
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6536
6676
  if (scenario === 'ParaToPara') {
6537
6677
  var interior = {
6538
6678
  X2: [{
@@ -6541,7 +6681,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6541
6681
  GeneralIndex: currencyId
6542
6682
  }]
6543
6683
  };
6544
- return createCurrencySpec(amount, version, Parents.ZERO, interior);
6684
+ return createCurrencySpec(amount, version, Parents.ZERO, overridedMultiLocation, interior);
6545
6685
  } else {
6546
6686
  return _get(_getPrototypeOf(AssetHubPolkadot.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6547
6687
  }
@@ -6691,10 +6831,11 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6691
6831
  address = options.address,
6692
6832
  destination = options.destination,
6693
6833
  paraIdTo = options.paraIdTo,
6834
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6694
6835
  _options$serializedAp = options.serializedApiCallEnabled,
6695
6836
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6696
6837
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6697
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6838
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6698
6839
  var node = this.node;
6699
6840
  if (supportsXTokens(this) && currencySymbol !== 'ASTR') {
6700
6841
  return this.transferXTokens({
@@ -6708,14 +6849,15 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6708
6849
  scenario: scenario,
6709
6850
  paraIdTo: paraId,
6710
6851
  destination: destination,
6852
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6711
6853
  serializedApiCallEnabled: serializedApiCallEnabled
6712
6854
  });
6713
6855
  } else if (supportsPolkadotXCM(this)) {
6714
6856
  return this.transferPolkadotXCM({
6715
6857
  api: api,
6716
- header: this.createPolkadotXcmHeader(scenario, paraId),
6858
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6717
6859
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6718
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
6860
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6719
6861
  scenario: scenario,
6720
6862
  currencySymbol: currencySymbol,
6721
6863
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -6746,14 +6888,14 @@ var Darwinia$2 = /*#__PURE__*/function (_ParachainNode) {
6746
6888
  }
6747
6889
  }, {
6748
6890
  key: "createCurrencySpec",
6749
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6891
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6750
6892
  if (scenario === 'ParaToPara') {
6751
6893
  var interior = {
6752
6894
  X1: {
6753
6895
  PalletInstance: 5
6754
6896
  }
6755
6897
  };
6756
- return createCurrencySpec(amount, version, Parents.ZERO, interior);
6898
+ return createCurrencySpec(amount, version, Parents.ZERO, overridedMultiLocation, interior);
6757
6899
  } else {
6758
6900
  return _get(_getPrototypeOf(Darwinia.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6759
6901
  }
@@ -6838,10 +6980,11 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6838
6980
  address = options.address,
6839
6981
  destination = options.destination,
6840
6982
  paraIdTo = options.paraIdTo,
6983
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6841
6984
  _options$serializedAp = options.serializedApiCallEnabled,
6842
6985
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6843
6986
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6844
- var paraId = destination !== undefined ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6987
+ var paraId = destination !== undefined && _typeof(destination) !== 'object' ? paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination) : undefined;
6845
6988
  var node = this.node;
6846
6989
  if (supportsXTokens(this) && currencySymbol !== 'SDN') {
6847
6990
  return this.transferXTokens({
@@ -6851,18 +6994,19 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6851
6994
  amount: amount,
6852
6995
  addressSelection: generateAddressPayload(api, scenario, 'XTokens', address, this.version, paraId),
6853
6996
  fees: getFees(scenario),
6997
+ origin: this.node,
6854
6998
  scenario: scenario,
6855
6999
  paraIdTo: paraId,
6856
- origin: this.node,
6857
7000
  destination: destination,
7001
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6858
7002
  serializedApiCallEnabled: serializedApiCallEnabled
6859
7003
  });
6860
7004
  } else if (supportsPolkadotXCM(this)) {
6861
7005
  return this.transferPolkadotXCM({
6862
7006
  api: api,
6863
- header: this.createPolkadotXcmHeader(scenario, paraId),
7007
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6864
7008
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6865
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
7009
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6866
7010
  scenario: scenario,
6867
7011
  currencySymbol: currencySymbol,
6868
7012
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -7042,6 +7186,28 @@ var determineDestWeight = function determineDestWeight(destNode) {
7042
7186
  }
7043
7187
  throw new NodeNotSupportedError("Node ".concat(destNode, " is not supported"));
7044
7188
  };
7189
+ var getDestination = function getDestination(_ref) {
7190
+ var recipientAddress = _ref.recipientAddress,
7191
+ paraId = _ref.paraId,
7192
+ api = _ref.api;
7193
+ var isMultiLocation = _typeof(recipientAddress) === 'object';
7194
+ if (isMultiLocation) {
7195
+ return recipientAddress;
7196
+ }
7197
+ var isEthAddress = ethers.utils.isAddress(recipientAddress);
7198
+ return {
7199
+ parents: 1,
7200
+ interior: {
7201
+ X2: [{
7202
+ Parachain: paraId
7203
+ }, _defineProperty({}, isEthAddress ? 'AccountKey20' : 'AccountId32', Object.assign({}, isEthAddress ? {
7204
+ key: recipientAddress
7205
+ } : {
7206
+ id: createAccID(api, recipientAddress)
7207
+ }))]
7208
+ }
7209
+ };
7210
+ };
7045
7211
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
7046
7212
  var XTransferTransferImpl = /*#__PURE__*/function () {
7047
7213
  function XTransferTransferImpl() {
@@ -7049,28 +7215,19 @@ var XTransferTransferImpl = /*#__PURE__*/function () {
7049
7215
  }
7050
7216
  return _createClass(XTransferTransferImpl, null, [{
7051
7217
  key: "transferXTransfer",
7052
- value: function transferXTransfer(_ref) {
7053
- var api = _ref.api,
7054
- amount = _ref.amount,
7055
- origin = _ref.origin,
7056
- recipientAddress = _ref.recipientAddress,
7057
- destination = _ref.destination,
7058
- paraId = _ref.paraId,
7059
- serializedApiCallEnabled = _ref.serializedApiCallEnabled;
7060
- var currencySpec = createCurrencySpec(amount, Version.V1, Parents.ZERO)[Version.V1][0];
7061
- var isEthAddress = ethers.utils.isAddress(recipientAddress);
7062
- var dest = {
7063
- parents: 1,
7064
- interior: {
7065
- X2: [{
7066
- Parachain: paraId
7067
- }, _defineProperty({}, isEthAddress ? 'AccountKey20' : 'AccountId32', Object.assign({}, isEthAddress ? {
7068
- key: recipientAddress
7069
- } : {
7070
- id: createAccID(api, recipientAddress)
7071
- }))]
7072
- }
7073
- };
7218
+ value: function transferXTransfer(input) {
7219
+ var api = input.api,
7220
+ amount = input.amount,
7221
+ origin = input.origin,
7222
+ destination = input.destination,
7223
+ serializedApiCallEnabled = input.serializedApiCallEnabled,
7224
+ overridedCurrencyMultiLocation = input.overridedCurrencyMultiLocation;
7225
+ var isMultiLocationDestination = _typeof(destination) === 'object';
7226
+ if (isMultiLocationDestination) {
7227
+ 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.');
7228
+ }
7229
+ var currencySpec = createCurrencySpec(amount, Version.V1, Parents.ZERO, overridedCurrencyMultiLocation)[Version.V1][0];
7230
+ var dest = getDestination(input);
7074
7231
  if (serializedApiCallEnabled === true) {
7075
7232
  return {
7076
7233
  module: 'xTransfer',
@@ -7201,6 +7358,10 @@ var getFees = function getFees(scenario) {
7201
7358
  throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
7202
7359
  };
7203
7360
  var generateAddressPayload = function generateAddressPayload(api, scenario, pallet, recipientAddress, version, nodeId) {
7361
+ var isMultiLocation = _typeof(recipientAddress) === 'object';
7362
+ if (isMultiLocation) {
7363
+ return _defineProperty({}, version, recipientAddress);
7364
+ }
7204
7365
  var isEthAddress = ethers.utils.isAddress(recipientAddress);
7205
7366
  if (scenario === 'ParaToRelay') {
7206
7367
  return _defineProperty({}, version, {
@@ -7266,8 +7427,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7266
7427
  var _getNode = getNode(node),
7267
7428
  type = _getNode.type,
7268
7429
  name = _getNode.name;
7269
- var _ref5 = type === 'polkadot' ? prodRelayPolkadot : prodRelayKusama,
7270
- linked = _ref5.linked;
7430
+ var _ref6 = type === 'polkadot' ? prodRelayPolkadot : prodRelayKusama,
7431
+ linked = _ref6.linked;
7271
7432
  if (linked === undefined) return undefined;
7272
7433
  var preferredOption = linked.find(function (o) {
7273
7434
  return o.info === name && Object.values(o.providers).length > 0;
@@ -7278,8 +7439,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7278
7439
  };
7279
7440
  var getAllNodeProviders = function getAllNodeProviders(node) {
7280
7441
  var _a;
7281
- var _ref6 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7282
- providers = _ref6.providers;
7442
+ var _ref7 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7443
+ providers = _ref7.providers;
7283
7444
  if (providers.length < 1) {
7284
7445
  throw new Error("Node ".concat(node, " does not have any providers."));
7285
7446
  }
@@ -7339,18 +7500,22 @@ var createApiInstanceForNode = function createApiInstanceForNode(node) {
7339
7500
  var lowercaseFirstLetter = function lowercaseFirstLetter(str) {
7340
7501
  return str.charAt(0).toLowerCase() + str.slice(1);
7341
7502
  };
7342
- var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref7) {
7503
+ var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref8) {
7343
7504
  var _api$tx$module;
7344
- var module = _ref7.module,
7345
- section = _ref7.section,
7346
- parameters = _ref7.parameters;
7505
+ var module = _ref8.module,
7506
+ section = _ref8.section,
7507
+ parameters = _ref8.parameters;
7347
7508
  return (_api$tx$module = api.tx[module])[section].apply(_api$tx$module, _toConsumableArray(parameters));
7348
7509
  };
7349
7510
  var determineRelayChain = function determineRelayChain(node) {
7350
7511
  return getRelayChainSymbol(node) === 'KSM' ? 'Kusama' : 'Polkadot';
7351
7512
  };
7352
7513
 
7353
- var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7514
+ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, currency) {
7515
+ if (_typeof(currency) === 'object') {
7516
+ return null;
7517
+ }
7518
+ var currencyString = currency.toString();
7354
7519
  var _getAssetsObject = getAssetsObject(node),
7355
7520
  otherAssets = _getAssetsObject.otherAssets,
7356
7521
  nativeAssets = _getAssetsObject.nativeAssets,
@@ -7358,7 +7523,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7358
7523
  var asset = [].concat(_toConsumableArray(otherAssets), _toConsumableArray(nativeAssets)).find(function (_ref) {
7359
7524
  var symbol = _ref.symbol,
7360
7525
  assetId = _ref.assetId;
7361
- return symbol === symbolOrId || assetId === symbolOrId;
7526
+ return symbol === currencyString || assetId === currencyString;
7362
7527
  });
7363
7528
  if (asset !== undefined) {
7364
7529
  var symbol = asset.symbol,
@@ -7368,7 +7533,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7368
7533
  assetId: assetId
7369
7534
  };
7370
7535
  }
7371
- if (relayChainAssetSymbol === symbolOrId) return {
7536
+ if (relayChainAssetSymbol === currencyString) return {
7372
7537
  symbol: relayChainAssetSymbol
7373
7538
  };
7374
7539
  return null;
@@ -7696,6 +7861,9 @@ var OpenChannelBuilder = /*#__PURE__*/function () {
7696
7861
  }, {
7697
7862
  key: "buildOptions",
7698
7863
  value: function buildOptions() {
7864
+ if (_typeof(this.to) === 'object') {
7865
+ throw new Error('Channels do not support multi-location destinations');
7866
+ }
7699
7867
  return {
7700
7868
  api: this.api,
7701
7869
  origin: this.from,
@@ -8208,71 +8376,98 @@ var checkKeepAlive = function checkKeepAlive(_ref) {
8208
8376
 
8209
8377
  var sendCommon = function sendCommon(options) {
8210
8378
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
8211
- var _a, api, origin, currencySymbolOrId, amount, address, destination, paraIdTo, destApiForKeepAlive, _options$serializedAp, serializedApiCallEnabled, asset, originRelayChainSymbol, destinationRelayChainSymbol, originNode, assetCheckEnabled, apiWithFallback, amountStr, currencyId;
8379
+ var _a, api, origin, currency, amount, address, destination, paraIdTo, destApiForKeepAlive, _options$serializedAp, serializedApiCallEnabled, asset, isMultiLocationDestination, isMultiLocationCurrency, originRelayChainSymbol, destinationRelayChainSymbol, originNode, assetCheckEnabled, apiWithFallback, amountStr, currencyStr, currencyId;
8212
8380
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8213
8381
  while (1) switch (_context.prev = _context.next) {
8214
8382
  case 0:
8215
- 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;
8216
- if (!(typeof currencySymbolOrId === 'number' && currencySymbolOrId > Number.MAX_SAFE_INTEGER)) {
8383
+ 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;
8384
+ if (!(typeof currency === 'number' && currency > Number.MAX_SAFE_INTEGER)) {
8217
8385
  _context.next = 3;
8218
8386
  break;
8219
8387
  }
8220
8388
  throw new InvalidCurrencyError('The provided asset ID is larger than the maximum safe integer value. Please provide it as a string.');
8221
8389
  case 3:
8222
- asset = getAssetBySymbolOrId(origin, currencySymbolOrId.toString());
8223
- if (!(destination !== undefined)) {
8224
- _context.next = 9;
8390
+ asset = getAssetBySymbolOrId(origin, currency);
8391
+ isMultiLocationDestination = _typeof(destination) === 'object';
8392
+ isMultiLocationCurrency = _typeof(currency) === 'object';
8393
+ if (!(destination !== undefined && !isMultiLocationDestination)) {
8394
+ _context.next = 11;
8225
8395
  break;
8226
8396
  }
8227
8397
  originRelayChainSymbol = getRelayChainSymbol(origin);
8228
8398
  destinationRelayChainSymbol = getRelayChainSymbol(destination);
8229
8399
  if (!(originRelayChainSymbol !== destinationRelayChainSymbol)) {
8230
- _context.next = 9;
8400
+ _context.next = 11;
8231
8401
  break;
8232
8402
  }
8233
8403
  throw new IncompatibleNodesError();
8234
- case 9:
8404
+ case 11:
8235
8405
  originNode = getNode(origin);
8236
- assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' ? false : originNode.assetCheckEnabled;
8406
+ assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' || isMultiLocationCurrency ? false : originNode.assetCheckEnabled;
8237
8407
  if (!(asset === null && assetCheckEnabled)) {
8238
- _context.next = 13;
8239
- break;
8240
- }
8241
- throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency or currencyId ").concat(currencySymbolOrId, "."));
8242
- case 13:
8243
- if (!(destination !== undefined && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !hasSupportForAsset(destination, asset.symbol))) {
8244
8408
  _context.next = 15;
8245
8409
  break;
8246
8410
  }
8247
- throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency or currencyId ").concat(currencySymbolOrId, "."));
8411
+ throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency or currencyId ").concat(JSON.stringify(currency), "."));
8248
8412
  case 15:
8413
+ if (!(destination !== undefined && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !hasSupportForAsset(destination, asset.symbol))) {
8414
+ _context.next = 17;
8415
+ break;
8416
+ }
8417
+ throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency or currencyId ").concat(JSON.stringify(currency), "."));
8418
+ case 17:
8249
8419
  if (!(api !== null && api !== void 0)) {
8250
- _context.next = 19;
8420
+ _context.next = 21;
8251
8421
  break;
8252
8422
  }
8253
8423
  _context.t0 = api;
8254
- _context.next = 22;
8424
+ _context.next = 24;
8255
8425
  break;
8256
- case 19:
8257
- _context.next = 21;
8258
- return createApiInstanceForNode(origin);
8259
8426
  case 21:
8427
+ _context.next = 23;
8428
+ return createApiInstanceForNode(origin);
8429
+ case 23:
8260
8430
  _context.t0 = _context.sent;
8261
- case 22:
8431
+ case 24:
8262
8432
  apiWithFallback = _context.t0;
8263
8433
  amountStr = amount.toString();
8264
- _context.next = 26;
8434
+ if (!(_typeof(currency) === 'object')) {
8435
+ _context.next = 30;
8436
+ break;
8437
+ }
8438
+ console.warn('Keep alive check is not supported when using MultiLocation as currency.');
8439
+ _context.next = 40;
8440
+ break;
8441
+ case 30:
8442
+ if (!(_typeof(address) === 'object')) {
8443
+ _context.next = 34;
8444
+ break;
8445
+ }
8446
+ console.warn('Keep alive check is not supported when using MultiLocation as address.');
8447
+ _context.next = 40;
8448
+ break;
8449
+ case 34:
8450
+ if (!(_typeof(destination) === 'object')) {
8451
+ _context.next = 38;
8452
+ break;
8453
+ }
8454
+ console.warn('Keep alive check is not supported when using MultiLocation as destination.');
8455
+ _context.next = 40;
8456
+ break;
8457
+ case 38:
8458
+ _context.next = 40;
8265
8459
  return checkKeepAlive({
8266
8460
  originApi: apiWithFallback,
8267
8461
  address: address,
8268
8462
  amount: amountStr,
8269
8463
  originNode: origin,
8270
8464
  destApi: destApiForKeepAlive,
8271
- currencySymbol: (_a = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _a !== void 0 ? _a : currencySymbolOrId.toString(),
8465
+ currencySymbol: (_a = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _a !== void 0 ? _a : currency.toString(),
8272
8466
  destNode: destination
8273
8467
  });
8274
- case 26:
8275
- currencyId = assetCheckEnabled ? asset === null || asset === void 0 ? void 0 : asset.assetId : currencySymbolOrId.toString();
8468
+ case 40:
8469
+ currencyStr = _typeof(currency) === 'object' ? undefined : currency.toString();
8470
+ currencyId = assetCheckEnabled ? asset === null || asset === void 0 ? void 0 : asset.assetId : currencyStr;
8276
8471
  return _context.abrupt("return", originNode.transfer({
8277
8472
  api: apiWithFallback,
8278
8473
  currencySymbol: asset === null || asset === void 0 ? void 0 : asset.symbol,
@@ -8281,9 +8476,10 @@ var sendCommon = function sendCommon(options) {
8281
8476
  address: address,
8282
8477
  destination: destination,
8283
8478
  paraIdTo: paraIdTo,
8479
+ overridedCurrencyMultiLocation: _typeof(currency) === 'object' ? currency : undefined,
8284
8480
  serializedApiCallEnabled: serializedApiCallEnabled
8285
8481
  }));
8286
- case 28:
8482
+ case 43:
8287
8483
  case "end":
8288
8484
  return _context.stop();
8289
8485
  }
@@ -8326,39 +8522,61 @@ var send = function send(options) {
8326
8522
  };
8327
8523
  var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8328
8524
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
8329
- var api, destination, amount, address, paraIdTo, destApiForKeepAlive, _options$serializedAp2, serializedApiCallEnabled, currencySymbol, relayNode, apiWithFallback, amountStr, serializedApiCall;
8525
+ var api, destination, amount, address, paraIdTo, destApiForKeepAlive, _options$serializedAp2, serializedApiCallEnabled, isMultiLocationDestination, isAddressMultiLocation, apiWithFallback, amountStr, serializedApiCall;
8330
8526
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
8331
8527
  while (1) switch (_context4.prev = _context4.next) {
8332
8528
  case 0:
8333
8529
  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;
8334
- currencySymbol = getRelayChainSymbol(destination);
8335
- relayNode = determineRelayChain(destination);
8530
+ isMultiLocationDestination = _typeof(destination) === 'object';
8531
+ isAddressMultiLocation = _typeof(address) === 'object';
8532
+ if (!(api === undefined && isMultiLocationDestination)) {
8533
+ _context4.next = 5;
8534
+ break;
8535
+ }
8536
+ throw new Error('API is required when using MultiLocation as destination.');
8537
+ case 5:
8336
8538
  if (!(api !== null && api !== void 0)) {
8337
- _context4.next = 7;
8539
+ _context4.next = 9;
8338
8540
  break;
8339
8541
  }
8340
8542
  _context4.t0 = api;
8341
- _context4.next = 10;
8543
+ _context4.next = 12;
8342
8544
  break;
8343
- case 7:
8344
- _context4.next = 9;
8345
- return createApiInstanceForNode(relayNode);
8346
8545
  case 9:
8546
+ _context4.next = 11;
8547
+ return createApiInstanceForNode(determineRelayChain(destination));
8548
+ case 11:
8347
8549
  _context4.t0 = _context4.sent;
8348
- case 10:
8550
+ case 12:
8349
8551
  apiWithFallback = _context4.t0;
8350
8552
  amountStr = amount.toString();
8351
- _context4.next = 14;
8553
+ if (!isMultiLocationDestination) {
8554
+ _context4.next = 18;
8555
+ break;
8556
+ }
8557
+ console.warn('Keep alive check is not supported when using MultiLocation as destination.');
8558
+ _context4.next = 24;
8559
+ break;
8560
+ case 18:
8561
+ if (!isAddressMultiLocation) {
8562
+ _context4.next = 22;
8563
+ break;
8564
+ }
8565
+ console.warn('Keep alive check is not supported when using MultiLocation as address.');
8566
+ _context4.next = 24;
8567
+ break;
8568
+ case 22:
8569
+ _context4.next = 24;
8352
8570
  return checkKeepAlive({
8353
8571
  originApi: apiWithFallback,
8354
8572
  address: address,
8355
8573
  amount: amountStr,
8356
8574
  destApi: destApiForKeepAlive,
8357
- currencySymbol: currencySymbol,
8575
+ currencySymbol: getRelayChainSymbol(destination),
8358
8576
  destNode: destination
8359
8577
  });
8360
- case 14:
8361
- serializedApiCall = getNode(destination).transferRelayToPara({
8578
+ case 24:
8579
+ serializedApiCall = getNode(isMultiLocationDestination ? resolveTNodeFromMultiLocation(destination) : destination).transferRelayToPara({
8362
8580
  api: apiWithFallback,
8363
8581
  destination: destination,
8364
8582
  address: address,
@@ -8367,13 +8585,13 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8367
8585
  destApiForKeepAlive: destApiForKeepAlive
8368
8586
  });
8369
8587
  if (!serializedApiCallEnabled) {
8370
- _context4.next = 17;
8588
+ _context4.next = 27;
8371
8589
  break;
8372
8590
  }
8373
8591
  return _context4.abrupt("return", serializedApiCall);
8374
- case 17:
8592
+ case 27:
8375
8593
  return _context4.abrupt("return", callPolkadotJsTxFunction(apiWithFallback, serializedApiCall));
8376
- case 18:
8594
+ case 28:
8377
8595
  case "end":
8378
8596
  return _context4.stop();
8379
8597
  }