@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.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.
@@ -5126,31 +5186,57 @@ var Polkadex$3 = {
5126
5186
  ],
5127
5187
  otherAssets: [
5128
5188
  {
5129
- assetId: "226557799181424065994173367616174607641"
5189
+ assetId: "226557799181424065994173367616174607641",
5190
+ symbol: "IBTC",
5191
+ decimals: 12
5130
5192
  },
5131
5193
  {
5132
- assetId: "193492391581201937291053139015355410612"
5194
+ assetId: "193492391581201937291053139015355410612",
5195
+ symbol: "PHA",
5196
+ decimals: 12
5133
5197
  },
5134
5198
  {
5135
5199
  assetId: "14826654563114266286226336203450732505"
5136
5200
  },
5137
5201
  {
5138
- assetId: "222121451965151777636299756141619631150"
5202
+ assetId: "222121451965151777636299756141619631150",
5203
+ symbol: "ASTR",
5204
+ decimals: 12
5205
+ },
5206
+ {
5207
+ assetId: "95930534000017180603917534864279132680",
5208
+ symbol: "DOT",
5209
+ decimals: 12
5210
+ },
5211
+ {
5212
+ assetId: "339306133874233608313826294843504252047",
5213
+ symbol: "PINK",
5214
+ decimals: 12
5139
5215
  },
5140
5216
  {
5141
- assetId: "95930534000017180603917534864279132680"
5217
+ assetId: "119367686984583275840673742485354142551",
5218
+ symbol: "DED",
5219
+ decimals: 12
5142
5220
  },
5143
5221
  {
5144
- assetId: "339306133874233608313826294843504252047"
5222
+ assetId: "3496813586714279103986568049643838918",
5223
+ symbol: "USDT",
5224
+ decimals: 12
5145
5225
  },
5146
5226
  {
5147
- assetId: "3496813586714279103986568049643838918"
5227
+ assetId: "32595388462891559990827225517299393930",
5228
+ symbol: "UNQ",
5229
+ decimals: 12
5148
5230
  },
5149
5231
  {
5150
- assetId: "32595388462891559990827225517299393930"
5232
+ assetId: "182269558229932594457975666948556356791",
5233
+ symbol: "GLMR",
5234
+ decimals: 12
5151
5235
  },
5152
5236
  {
5153
- assetId: "182269558229932594457975666948556356791"
5237
+ assetId: "304494718746685751324769169435167367843",
5238
+ symbol: "USDC",
5239
+ decimals: 12
5154
5240
  },
5155
5241
  {
5156
5242
  assetId: "240851462719321838889739625279903325250"
@@ -5573,18 +5659,18 @@ var constructRelayToParaParameters = function constructRelayToParaParameters(_re
5573
5659
  amount = _ref.amount,
5574
5660
  paraIdTo = _ref.paraIdTo;
5575
5661
  var includeFee = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5576
- var paraId = paraIdTo !== null && paraIdTo !== void 0 ? paraIdTo : getParaId(destination);
5577
- 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];
5578
5664
  if (includeFee) {
5579
5665
  parameters.push('Unlimited');
5580
5666
  }
5581
5667
  return parameters;
5582
5668
  };
5583
- var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5584
- 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';
5585
5671
  return _defineProperty({}, version, [{
5586
5672
  id: {
5587
- Concrete: {
5673
+ Concrete: overridedMultiLocation !== null && overridedMultiLocation !== void 0 ? overridedMultiLocation : {
5588
5674
  parents: parents,
5589
5675
  interior: interior
5590
5676
  }
@@ -5594,14 +5680,15 @@ var createCurrencySpec = function createCurrencySpec(amount, version, parents) {
5594
5680
  }
5595
5681
  }]);
5596
5682
  };
5597
- var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, nodeId) {
5683
+ var createPolkadotXcmHeader = function createPolkadotXcmHeader(scenario, version, destination, nodeId) {
5598
5684
  var parents = scenario === 'RelayToPara' ? exports.Parents.ZERO : exports.Parents.ONE;
5599
5685
  var interior = scenario === 'ParaToRelay' ? 'Here' : {
5600
5686
  X1: {
5601
5687
  Parachain: nodeId
5602
5688
  }
5603
5689
  };
5604
- 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 : {
5605
5692
  parents: parents,
5606
5693
  interior: interior
5607
5694
  });
@@ -5625,6 +5712,42 @@ var calculateTransactionFee = function calculateTransactionFee(tx, address) {
5625
5712
  }, _callee);
5626
5713
  }));
5627
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
+ };
5628
5751
 
5629
5752
  var supportsXTokens = function supportsXTokens(obj) {
5630
5753
  return 'transferXTokens' in obj;
@@ -5679,10 +5802,11 @@ var ParachainNode = /*#__PURE__*/function () {
5679
5802
  address = options.address,
5680
5803
  destination = options.destination,
5681
5804
  paraIdTo = options.paraIdTo,
5805
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
5682
5806
  _options$serializedAp = options.serializedApiCallEnabled,
5683
5807
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
5684
5808
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
5685
- 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;
5686
5810
  if (supportsXTokens(this)) {
5687
5811
  return this.transferXTokens({
5688
5812
  api: api,
@@ -5695,6 +5819,7 @@ var ParachainNode = /*#__PURE__*/function () {
5695
5819
  scenario: scenario,
5696
5820
  paraIdTo: paraId,
5697
5821
  destination: destination,
5822
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5698
5823
  serializedApiCallEnabled: serializedApiCallEnabled
5699
5824
  });
5700
5825
  } else if (supportsXTransfer(this)) {
@@ -5707,14 +5832,15 @@ var ParachainNode = /*#__PURE__*/function () {
5707
5832
  paraId: paraId,
5708
5833
  origin: this.node,
5709
5834
  destination: destination,
5835
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
5710
5836
  serializedApiCallEnabled: serializedApiCallEnabled
5711
5837
  });
5712
5838
  } else if (supportsPolkadotXCM(this)) {
5713
5839
  return this.transferPolkadotXCM({
5714
5840
  api: api,
5715
- header: this.createPolkadotXcmHeader(scenario, paraId),
5841
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
5716
5842
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
5717
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
5843
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
5718
5844
  scenario: scenario,
5719
5845
  currencySymbol: currencySymbol,
5720
5846
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -5757,13 +5883,13 @@ var ParachainNode = /*#__PURE__*/function () {
5757
5883
  }
5758
5884
  }, {
5759
5885
  key: "createCurrencySpec",
5760
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
5761
- 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);
5762
5888
  }
5763
5889
  }, {
5764
5890
  key: "createPolkadotXcmHeader",
5765
- value: function createPolkadotXcmHeader$1(scenario, paraId) {
5766
- return createPolkadotXcmHeader(scenario, this.version, paraId);
5891
+ value: function createPolkadotXcmHeader$1(scenario, destination, paraId) {
5892
+ return createPolkadotXcmHeader(scenario, this.version, destination, paraId);
5767
5893
  }
5768
5894
  }]);
5769
5895
  }();
@@ -5789,6 +5915,20 @@ var getModifiedCurrencySelection = function getModifiedCurrencySelection(version
5789
5915
  }
5790
5916
  });
5791
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
+ };
5792
5932
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
5793
5933
  var XTokensTransferImpl = /*#__PURE__*/function () {
5794
5934
  function XTokensTransferImpl() {
@@ -5796,30 +5936,30 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
5796
5936
  }
5797
5937
  return _createClass(XTokensTransferImpl, null, [{
5798
5938
  key: "transferXTokens",
5799
- value: function transferXTokens(_ref2, currencySelection) {
5800
- var api = _ref2.api,
5801
- amount = _ref2.amount,
5802
- currencyID = _ref2.currencyID,
5803
- addressSelection = _ref2.addressSelection,
5804
- origin = _ref2.origin,
5805
- destination = _ref2.destination,
5806
- paraIdTo = _ref2.paraIdTo,
5807
- serializedApiCallEnabled = _ref2.serializedApiCallEnabled;
5939
+ value: function transferXTokens(input, currencySelection) {
5808
5940
  var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Unlimited';
5809
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
+ }
5810
5951
  var module = lowercaseFirstLetter(pallet.toString());
5811
5952
  var isAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5812
- var node = getNode(origin);
5813
- var modifiedCurrencySelection = isAssetHub ? getModifiedCurrencySelection(node.version, amount, currencyID, paraIdTo) : currencySelection;
5953
+ var modifiedCurrencySelection = getCurrencySelection(input, isAssetHub, currencySelection);
5814
5954
  var section = isAssetHub ? 'transferMultiasset' : 'transfer';
5815
5955
  if (serializedApiCallEnabled === true) {
5816
5956
  return {
5817
5957
  module: module,
5818
5958
  section: section,
5819
- parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [currencySelection, amount, addressSelection, fees]
5959
+ parameters: isAssetHub ? [modifiedCurrencySelection, addressSelection, fees] : [modifiedCurrencySelection, amount, addressSelection, fees]
5820
5960
  };
5821
5961
  }
5822
- 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);
5823
5963
  }
5824
5964
  }]);
5825
5965
  }();
@@ -6534,7 +6674,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6534
6674
  }
6535
6675
  }, {
6536
6676
  key: "createCurrencySpec",
6537
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6677
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6538
6678
  if (scenario === 'ParaToPara') {
6539
6679
  var interior = {
6540
6680
  X2: [{
@@ -6543,7 +6683,7 @@ var AssetHubPolkadot$2 = /*#__PURE__*/function (_ParachainNode) {
6543
6683
  GeneralIndex: currencyId
6544
6684
  }]
6545
6685
  };
6546
- return createCurrencySpec(amount, version, exports.Parents.ZERO, interior);
6686
+ return createCurrencySpec(amount, version, exports.Parents.ZERO, overridedMultiLocation, interior);
6547
6687
  } else {
6548
6688
  return _get(_getPrototypeOf(AssetHubPolkadot.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6549
6689
  }
@@ -6693,10 +6833,11 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6693
6833
  address = options.address,
6694
6834
  destination = options.destination,
6695
6835
  paraIdTo = options.paraIdTo,
6836
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6696
6837
  _options$serializedAp = options.serializedApiCallEnabled,
6697
6838
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6698
6839
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6699
- 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;
6700
6841
  var node = this.node;
6701
6842
  if (supportsXTokens(this) && currencySymbol !== 'ASTR') {
6702
6843
  return this.transferXTokens({
@@ -6710,14 +6851,15 @@ var Astar$2 = /*#__PURE__*/function (_ParachainNode) {
6710
6851
  scenario: scenario,
6711
6852
  paraIdTo: paraId,
6712
6853
  destination: destination,
6854
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6713
6855
  serializedApiCallEnabled: serializedApiCallEnabled
6714
6856
  });
6715
6857
  } else if (supportsPolkadotXCM(this)) {
6716
6858
  return this.transferPolkadotXCM({
6717
6859
  api: api,
6718
- header: this.createPolkadotXcmHeader(scenario, paraId),
6860
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6719
6861
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6720
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
6862
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6721
6863
  scenario: scenario,
6722
6864
  currencySymbol: currencySymbol,
6723
6865
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -6748,14 +6890,14 @@ var Darwinia$2 = /*#__PURE__*/function (_ParachainNode) {
6748
6890
  }
6749
6891
  }, {
6750
6892
  key: "createCurrencySpec",
6751
- value: function createCurrencySpec$1(amount, scenario, version, currencyId) {
6893
+ value: function createCurrencySpec$1(amount, scenario, version, currencyId, overridedMultiLocation) {
6752
6894
  if (scenario === 'ParaToPara') {
6753
6895
  var interior = {
6754
6896
  X1: {
6755
6897
  PalletInstance: 5
6756
6898
  }
6757
6899
  };
6758
- return createCurrencySpec(amount, version, exports.Parents.ZERO, interior);
6900
+ return createCurrencySpec(amount, version, exports.Parents.ZERO, overridedMultiLocation, interior);
6759
6901
  } else {
6760
6902
  return _get(_getPrototypeOf(Darwinia.prototype), "createCurrencySpec", this).call(this, amount, scenario, version, currencyId);
6761
6903
  }
@@ -6840,10 +6982,11 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6840
6982
  address = options.address,
6841
6983
  destination = options.destination,
6842
6984
  paraIdTo = options.paraIdTo,
6985
+ overridedCurrencyMultiLocation = options.overridedCurrencyMultiLocation,
6843
6986
  _options$serializedAp = options.serializedApiCallEnabled,
6844
6987
  serializedApiCallEnabled = _options$serializedAp === void 0 ? false : _options$serializedAp;
6845
6988
  var scenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay';
6846
- 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;
6847
6990
  var node = this.node;
6848
6991
  if (supportsXTokens(this) && currencySymbol !== 'SDN') {
6849
6992
  return this.transferXTokens({
@@ -6853,18 +6996,19 @@ var Shiden$2 = /*#__PURE__*/function (_ParachainNode) {
6853
6996
  amount: amount,
6854
6997
  addressSelection: generateAddressPayload(api, scenario, 'XTokens', address, this.version, paraId),
6855
6998
  fees: getFees(scenario),
6999
+ origin: this.node,
6856
7000
  scenario: scenario,
6857
7001
  paraIdTo: paraId,
6858
- origin: this.node,
6859
7002
  destination: destination,
7003
+ overridedCurrencyMultiLocation: overridedCurrencyMultiLocation,
6860
7004
  serializedApiCallEnabled: serializedApiCallEnabled
6861
7005
  });
6862
7006
  } else if (supportsPolkadotXCM(this)) {
6863
7007
  return this.transferPolkadotXCM({
6864
7008
  api: api,
6865
- header: this.createPolkadotXcmHeader(scenario, paraId),
7009
+ header: this.createPolkadotXcmHeader(scenario, destination, paraId),
6866
7010
  addressSelection: generateAddressPayload(api, scenario, 'PolkadotXcm', address, this.version, paraId),
6867
- currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId),
7011
+ currencySelection: this.createCurrencySpec(amount, scenario, this.version, currencyId, overridedCurrencyMultiLocation),
6868
7012
  scenario: scenario,
6869
7013
  currencySymbol: currencySymbol,
6870
7014
  serializedApiCallEnabled: serializedApiCallEnabled
@@ -7044,6 +7188,28 @@ var determineDestWeight = function determineDestWeight(destNode) {
7044
7188
  }
7045
7189
  throw new NodeNotSupportedError("Node ".concat(destNode, " is not supported"));
7046
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
+ };
7047
7213
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
7048
7214
  var XTransferTransferImpl = /*#__PURE__*/function () {
7049
7215
  function XTransferTransferImpl() {
@@ -7051,28 +7217,19 @@ var XTransferTransferImpl = /*#__PURE__*/function () {
7051
7217
  }
7052
7218
  return _createClass(XTransferTransferImpl, null, [{
7053
7219
  key: "transferXTransfer",
7054
- value: function transferXTransfer(_ref) {
7055
- var api = _ref.api,
7056
- amount = _ref.amount,
7057
- origin = _ref.origin,
7058
- recipientAddress = _ref.recipientAddress,
7059
- destination = _ref.destination,
7060
- paraId = _ref.paraId,
7061
- serializedApiCallEnabled = _ref.serializedApiCallEnabled;
7062
- var currencySpec = createCurrencySpec(amount, exports.Version.V1, exports.Parents.ZERO)[exports.Version.V1][0];
7063
- var isEthAddress = ethers.ethers.utils.isAddress(recipientAddress);
7064
- var dest = {
7065
- parents: 1,
7066
- interior: {
7067
- X2: [{
7068
- Parachain: paraId
7069
- }, _defineProperty({}, isEthAddress ? 'AccountKey20' : 'AccountId32', Object.assign({}, isEthAddress ? {
7070
- key: recipientAddress
7071
- } : {
7072
- id: createAccID(api, recipientAddress)
7073
- }))]
7074
- }
7075
- };
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);
7076
7233
  if (serializedApiCallEnabled === true) {
7077
7234
  return {
7078
7235
  module: 'xTransfer',
@@ -7203,6 +7360,10 @@ var getFees = function getFees(scenario) {
7203
7360
  throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
7204
7361
  };
7205
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
+ }
7206
7367
  var isEthAddress = ethers.ethers.utils.isAddress(recipientAddress);
7207
7368
  if (scenario === 'ParaToRelay') {
7208
7369
  return _defineProperty({}, version, {
@@ -7268,8 +7429,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7268
7429
  var _getNode = getNode(node),
7269
7430
  type = _getNode.type,
7270
7431
  name = _getNode.name;
7271
- var _ref5 = type === 'polkadot' ? endpoints.prodRelayPolkadot : endpoints.prodRelayKusama,
7272
- linked = _ref5.linked;
7432
+ var _ref6 = type === 'polkadot' ? endpoints.prodRelayPolkadot : endpoints.prodRelayKusama,
7433
+ linked = _ref6.linked;
7273
7434
  if (linked === undefined) return undefined;
7274
7435
  var preferredOption = linked.find(function (o) {
7275
7436
  return o.info === name && Object.values(o.providers).length > 0;
@@ -7280,8 +7441,8 @@ var getNodeEndpointOption = function getNodeEndpointOption(node) {
7280
7441
  };
7281
7442
  var getAllNodeProviders = function getAllNodeProviders(node) {
7282
7443
  var _a;
7283
- var _ref6 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7284
- providers = _ref6.providers;
7444
+ var _ref7 = (_a = getNodeEndpointOption(node)) !== null && _a !== void 0 ? _a : {},
7445
+ providers = _ref7.providers;
7285
7446
  if (providers.length < 1) {
7286
7447
  throw new Error("Node ".concat(node, " does not have any providers."));
7287
7448
  }
@@ -7341,18 +7502,22 @@ var createApiInstanceForNode = function createApiInstanceForNode(node) {
7341
7502
  var lowercaseFirstLetter = function lowercaseFirstLetter(str) {
7342
7503
  return str.charAt(0).toLowerCase() + str.slice(1);
7343
7504
  };
7344
- var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref7) {
7505
+ var callPolkadotJsTxFunction = function callPolkadotJsTxFunction(api, _ref8) {
7345
7506
  var _api$tx$module;
7346
- var module = _ref7.module,
7347
- section = _ref7.section,
7348
- parameters = _ref7.parameters;
7507
+ var module = _ref8.module,
7508
+ section = _ref8.section,
7509
+ parameters = _ref8.parameters;
7349
7510
  return (_api$tx$module = api.tx[module])[section].apply(_api$tx$module, _toConsumableArray(parameters));
7350
7511
  };
7351
7512
  var determineRelayChain = function determineRelayChain(node) {
7352
7513
  return getRelayChainSymbol(node) === 'KSM' ? 'Kusama' : 'Polkadot';
7353
7514
  };
7354
7515
 
7355
- 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();
7356
7521
  var _getAssetsObject = getAssetsObject(node),
7357
7522
  otherAssets = _getAssetsObject.otherAssets,
7358
7523
  nativeAssets = _getAssetsObject.nativeAssets,
@@ -7360,7 +7525,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7360
7525
  var asset = [].concat(_toConsumableArray(otherAssets), _toConsumableArray(nativeAssets)).find(function (_ref) {
7361
7526
  var symbol = _ref.symbol,
7362
7527
  assetId = _ref.assetId;
7363
- return symbol === symbolOrId || assetId === symbolOrId;
7528
+ return symbol === currencyString || assetId === currencyString;
7364
7529
  });
7365
7530
  if (asset !== undefined) {
7366
7531
  var symbol = asset.symbol,
@@ -7370,7 +7535,7 @@ var getAssetBySymbolOrId = function getAssetBySymbolOrId(node, symbolOrId) {
7370
7535
  assetId: assetId
7371
7536
  };
7372
7537
  }
7373
- if (relayChainAssetSymbol === symbolOrId) return {
7538
+ if (relayChainAssetSymbol === currencyString) return {
7374
7539
  symbol: relayChainAssetSymbol
7375
7540
  };
7376
7541
  return null;
@@ -7698,6 +7863,9 @@ var OpenChannelBuilder = /*#__PURE__*/function () {
7698
7863
  }, {
7699
7864
  key: "buildOptions",
7700
7865
  value: function buildOptions() {
7866
+ if (_typeof(this.to) === 'object') {
7867
+ throw new Error('Channels do not support multi-location destinations');
7868
+ }
7701
7869
  return {
7702
7870
  api: this.api,
7703
7871
  origin: this.from,
@@ -8210,71 +8378,98 @@ var checkKeepAlive = function checkKeepAlive(_ref) {
8210
8378
 
8211
8379
  var sendCommon = function sendCommon(options) {
8212
8380
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
8213
- 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;
8214
8382
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8215
8383
  while (1) switch (_context.prev = _context.next) {
8216
8384
  case 0:
8217
- 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;
8218
- 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)) {
8219
8387
  _context.next = 3;
8220
8388
  break;
8221
8389
  }
8222
8390
  throw new InvalidCurrencyError('The provided asset ID is larger than the maximum safe integer value. Please provide it as a string.');
8223
8391
  case 3:
8224
- asset = getAssetBySymbolOrId(origin, currencySymbolOrId.toString());
8225
- if (!(destination !== undefined)) {
8226
- _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;
8227
8397
  break;
8228
8398
  }
8229
8399
  originRelayChainSymbol = getRelayChainSymbol(origin);
8230
8400
  destinationRelayChainSymbol = getRelayChainSymbol(destination);
8231
8401
  if (!(originRelayChainSymbol !== destinationRelayChainSymbol)) {
8232
- _context.next = 9;
8402
+ _context.next = 11;
8233
8403
  break;
8234
8404
  }
8235
8405
  throw new IncompatibleNodesError();
8236
- case 9:
8406
+ case 11:
8237
8407
  originNode = getNode(origin);
8238
- assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' ? false : originNode.assetCheckEnabled;
8408
+ assetCheckEnabled = destination === 'AssetHubKusama' || destination === 'AssetHubPolkadot' || isMultiLocationCurrency ? false : originNode.assetCheckEnabled;
8239
8409
  if (!(asset === null && assetCheckEnabled)) {
8240
- _context.next = 13;
8241
- break;
8242
- }
8243
- throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency or currencyId ").concat(currencySymbolOrId, "."));
8244
- case 13:
8245
- if (!(destination !== undefined && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !hasSupportForAsset(destination, asset.symbol))) {
8246
8410
  _context.next = 15;
8247
8411
  break;
8248
8412
  }
8249
- 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), "."));
8250
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:
8251
8421
  if (!(api !== null && api !== void 0)) {
8252
- _context.next = 19;
8422
+ _context.next = 21;
8253
8423
  break;
8254
8424
  }
8255
8425
  _context.t0 = api;
8256
- _context.next = 22;
8426
+ _context.next = 24;
8257
8427
  break;
8258
- case 19:
8259
- _context.next = 21;
8260
- return createApiInstanceForNode(origin);
8261
8428
  case 21:
8429
+ _context.next = 23;
8430
+ return createApiInstanceForNode(origin);
8431
+ case 23:
8262
8432
  _context.t0 = _context.sent;
8263
- case 22:
8433
+ case 24:
8264
8434
  apiWithFallback = _context.t0;
8265
8435
  amountStr = amount.toString();
8266
- _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;
8267
8461
  return checkKeepAlive({
8268
8462
  originApi: apiWithFallback,
8269
8463
  address: address,
8270
8464
  amount: amountStr,
8271
8465
  originNode: origin,
8272
8466
  destApi: destApiForKeepAlive,
8273
- 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(),
8274
8468
  destNode: destination
8275
8469
  });
8276
- case 26:
8277
- 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;
8278
8473
  return _context.abrupt("return", originNode.transfer({
8279
8474
  api: apiWithFallback,
8280
8475
  currencySymbol: asset === null || asset === void 0 ? void 0 : asset.symbol,
@@ -8283,9 +8478,10 @@ var sendCommon = function sendCommon(options) {
8283
8478
  address: address,
8284
8479
  destination: destination,
8285
8480
  paraIdTo: paraIdTo,
8481
+ overridedCurrencyMultiLocation: _typeof(currency) === 'object' ? currency : undefined,
8286
8482
  serializedApiCallEnabled: serializedApiCallEnabled
8287
8483
  }));
8288
- case 28:
8484
+ case 43:
8289
8485
  case "end":
8290
8486
  return _context.stop();
8291
8487
  }
@@ -8328,39 +8524,61 @@ var send = function send(options) {
8328
8524
  };
8329
8525
  var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8330
8526
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
8331
- 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;
8332
8528
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
8333
8529
  while (1) switch (_context4.prev = _context4.next) {
8334
8530
  case 0:
8335
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;
8336
- currencySymbol = getRelayChainSymbol(destination);
8337
- 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:
8338
8540
  if (!(api !== null && api !== void 0)) {
8339
- _context4.next = 7;
8541
+ _context4.next = 9;
8340
8542
  break;
8341
8543
  }
8342
8544
  _context4.t0 = api;
8343
- _context4.next = 10;
8545
+ _context4.next = 12;
8344
8546
  break;
8345
- case 7:
8346
- _context4.next = 9;
8347
- return createApiInstanceForNode(relayNode);
8348
8547
  case 9:
8548
+ _context4.next = 11;
8549
+ return createApiInstanceForNode(determineRelayChain(destination));
8550
+ case 11:
8349
8551
  _context4.t0 = _context4.sent;
8350
- case 10:
8552
+ case 12:
8351
8553
  apiWithFallback = _context4.t0;
8352
8554
  amountStr = amount.toString();
8353
- _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;
8354
8572
  return checkKeepAlive({
8355
8573
  originApi: apiWithFallback,
8356
8574
  address: address,
8357
8575
  amount: amountStr,
8358
8576
  destApi: destApiForKeepAlive,
8359
- currencySymbol: currencySymbol,
8577
+ currencySymbol: getRelayChainSymbol(destination),
8360
8578
  destNode: destination
8361
8579
  });
8362
- case 14:
8363
- serializedApiCall = getNode(destination).transferRelayToPara({
8580
+ case 24:
8581
+ serializedApiCall = getNode(isMultiLocationDestination ? resolveTNodeFromMultiLocation(destination) : destination).transferRelayToPara({
8364
8582
  api: apiWithFallback,
8365
8583
  destination: destination,
8366
8584
  address: address,
@@ -8369,13 +8587,13 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options) {
8369
8587
  destApiForKeepAlive: destApiForKeepAlive
8370
8588
  });
8371
8589
  if (!serializedApiCallEnabled) {
8372
- _context4.next = 17;
8590
+ _context4.next = 27;
8373
8591
  break;
8374
8592
  }
8375
8593
  return _context4.abrupt("return", serializedApiCall);
8376
- case 17:
8594
+ case 27:
8377
8595
  return _context4.abrupt("return", callPolkadotJsTxFunction(apiWithFallback, serializedApiCall));
8378
- case 18:
8596
+ case 28:
8379
8597
  case "end":
8380
8598
  return _context4.stop();
8381
8599
  }