@paraspell/sdk-core 10.4.6 → 10.4.7

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
@@ -4580,25 +4580,31 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
4580
4580
  }();
4581
4581
 
4582
4582
  var isSufficientOrigin = /*#__PURE__*/function () {
4583
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, node, senderAddress, fee) {
4583
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, node, senderAddress, fee, feeAsset) {
4584
4584
  var existentialDeposit, nativeBalance;
4585
4585
  return _regenerator().w(function (_context) {
4586
4586
  while (1) switch (_context.n) {
4587
4587
  case 0:
4588
+ if (!feeAsset) {
4589
+ _context.n = 1;
4590
+ break;
4591
+ }
4592
+ return _context.a(2, undefined);
4593
+ case 1:
4588
4594
  existentialDeposit = assets.getExistentialDepositOrThrow(node);
4589
- _context.n = 1;
4595
+ _context.n = 2;
4590
4596
  return getBalanceNativeInternal({
4591
4597
  api: api,
4592
4598
  node: node,
4593
4599
  address: senderAddress
4594
4600
  });
4595
- case 1:
4601
+ case 2:
4596
4602
  nativeBalance = _context.v;
4597
4603
  return _context.a(2, nativeBalance - existentialDeposit - fee > 0n);
4598
4604
  }
4599
4605
  }, _callee);
4600
4606
  }));
4601
- return function isSufficientOrigin(_x, _x2, _x3, _x4) {
4607
+ return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5) {
4602
4608
  return _ref.apply(this, arguments);
4603
4609
  };
4604
4610
  }();
@@ -4627,7 +4633,7 @@ var isSufficientDestination = /*#__PURE__*/function () {
4627
4633
  }
4628
4634
  }, _callee2);
4629
4635
  }));
4630
- return function isSufficientDestination(_x5, _x6, _x7, _x8, _x9) {
4636
+ return function isSufficientDestination(_x6, _x7, _x8, _x9, _x0) {
4631
4637
  return _ref2.apply(this, arguments);
4632
4638
  };
4633
4639
  }();
@@ -4781,6 +4787,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
4781
4787
  return _context2.a(2, {
4782
4788
  fee: fee,
4783
4789
  feeType: 'dryRun',
4790
+ sufficient: true,
4784
4791
  forwardedXcms: newForwardedXcms,
4785
4792
  destParaId: destParaId
4786
4793
  });
@@ -5033,7 +5040,7 @@ var dryRunOrigin = /*#__PURE__*/function () {
5033
5040
 
5034
5041
  var getOriginXcmFee = /*#__PURE__*/function () {
5035
5042
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
5036
- var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, currencySymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee, _sufficient, fee, forwardedXcms, destParaId, weight;
5043
+ var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, nativeAssetSymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee, _sufficient, fee, forwardedXcms, destParaId, weight, currencySymbol;
5037
5044
  return _regenerator().w(function (_context) {
5038
5045
  while (1) switch (_context.n) {
5039
5046
  case 0:
@@ -5042,7 +5049,7 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5042
5049
  _context.n = 1;
5043
5050
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
5044
5051
  case 1:
5045
- currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin);
5052
+ nativeAssetSymbol = assets.getNativeAssetSymbol(origin);
5046
5053
  if (assets.hasDryRunSupport(origin)) {
5047
5054
  _context.n = 4;
5048
5055
  break;
@@ -5053,12 +5060,12 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5053
5060
  rawFee = _context.v;
5054
5061
  paddedFee = padFee(rawFee, origin, destination, 'origin');
5055
5062
  _context.n = 3;
5056
- return isSufficientOrigin(api, origin, senderAddress, paddedFee);
5063
+ return isSufficientOrigin(api, origin, senderAddress, paddedFee, resolvedFeeAsset);
5057
5064
  case 3:
5058
5065
  sufficient = _context.v;
5059
5066
  return _context.a(2, {
5060
5067
  fee: paddedFee,
5061
- currency: currencySymbol,
5068
+ currency: nativeAssetSymbol,
5062
5069
  feeType: 'paymentInfo',
5063
5070
  sufficient: sufficient
5064
5071
  });
@@ -5090,21 +5097,23 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5090
5097
  _rawFee = _context.v;
5091
5098
  _paddedFee = padFee(_rawFee, origin, destination, 'origin');
5092
5099
  _context.n = 8;
5093
- return isSufficientOrigin(api, origin, senderAddress, _paddedFee);
5100
+ return isSufficientOrigin(api, origin, senderAddress, _paddedFee, resolvedFeeAsset);
5094
5101
  case 8:
5095
5102
  _sufficient = _context.v;
5096
5103
  return _context.a(2, {
5097
5104
  fee: _paddedFee,
5098
- currency: currencySymbol,
5105
+ currency: nativeAssetSymbol,
5099
5106
  feeType: 'paymentInfo',
5100
5107
  dryRunError: dryRunResult.failureReason,
5101
5108
  sufficient: _sufficient
5102
5109
  });
5103
5110
  case 9:
5104
5111
  fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId, weight = dryRunResult.weight;
5112
+ currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : nativeAssetSymbol;
5105
5113
  return _context.a(2, {
5106
5114
  fee: fee,
5107
5115
  feeType: 'dryRun',
5116
+ sufficient: true,
5108
5117
  currency: currencySymbol,
5109
5118
  forwardedXcms: forwardedXcms,
5110
5119
  destParaId: destParaId,
@@ -5118,20 +5127,176 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5118
5127
  };
5119
5128
  }();
5120
5129
 
5130
+ var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
5131
+ return assetCheckEnabled ? assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null) : null;
5132
+ };
5133
+
5134
+ var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
5135
+ var origin = _ref.from,
5136
+ destination = _ref.to,
5137
+ currency = _ref.currency;
5138
+ var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5139
+ var allowedChainsToAh = ['AssetHubPolkadot', 'BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
5140
+ if (!sdkCommon.isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
5141
+ throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
5142
+ }
5143
+ var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
5144
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5145
+ if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !assets.hasSupportForAsset(destination, asset.symbol)) {
5146
+ throw new assets.InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
5147
+ }
5148
+ if (!isBridge && asset === null && assetCheckEnabled) {
5149
+ throwUnsupportedCurrency(currency, origin);
5150
+ }
5151
+ };
5152
+
5153
+ var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
5154
+ var currency = options.currency,
5155
+ feeAsset = options.feeAsset,
5156
+ origin = options.from,
5157
+ destination = options.to;
5158
+ if ('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation)) {
5159
+ return currency.multilocation.value;
5160
+ }
5161
+ if ('multiasset' in currency) {
5162
+ if (!feeAsset) {
5163
+ throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5164
+ }
5165
+ if ('multilocation' in feeAsset && assets.isOverrideMultiLocationSpecifier(feeAsset.multilocation)) {
5166
+ throw new assets.InvalidCurrencyError('Fee asset cannot be an overridden multi location specifier');
5167
+ }
5168
+ if (currency.multiasset.every(function (asset) {
5169
+ return assets.isTMultiAsset(asset);
5170
+ })) {
5171
+ if (!feeAsset) {
5172
+ throw new assets.InvalidCurrencyError('Fee asset not provided');
5173
+ }
5174
+ if (!('multilocation' in feeAsset)) {
5175
+ throw new assets.InvalidCurrencyError('Fee asset must be specified by multilocation when using raw overridden multi assets');
5176
+ }
5177
+ return currency.multiasset.map(function (multiAsset) {
5178
+ var ml = assets.extractMultiAssetLoc(multiAsset);
5179
+ return _objectSpread2(_objectSpread2({}, multiAsset), {}, {
5180
+ isFeeAsset: sdkCommon.deepEqual(ml, feeAsset.multilocation)
5181
+ });
5182
+ });
5183
+ }
5184
+ // MultiAsset is an array of TCurrencyCore, search for assets
5185
+ var assets$1 = currency.multiasset.map(function (currency) {
5186
+ var asset = assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null);
5187
+ if (asset && !asset.multiLocation) {
5188
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " does not have a multiLocation"));
5189
+ }
5190
+ if (!asset) {
5191
+ throw new assets.InvalidCurrencyError("Origin node ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
5192
+ }
5193
+ if (!resolvedFeeAsset) {
5194
+ throw new assets.InvalidCurrencyError('Fee asset not found');
5195
+ }
5196
+ validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
5197
+ var originTyped = origin;
5198
+ var originNode = getNode(originTyped);
5199
+ return _objectSpread2({
5200
+ isFeeAsset: assets.isAssetEqual(resolvedFeeAsset, asset)
5201
+ }, createMultiAsset(originNode.version, currency.amount, asset.multiLocation));
5202
+ });
5203
+ if (assets$1.filter(function (asset) {
5204
+ return asset.isFeeAsset;
5205
+ }).length > 1) {
5206
+ throw new assets.InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
5207
+ }
5208
+ if (assets$1.filter(function (asset) {
5209
+ return asset.isFeeAsset;
5210
+ }).length === 0) {
5211
+ throw new assets.InvalidCurrencyError("Fee asset not found in multiassets");
5212
+ }
5213
+ return assets$1;
5214
+ }
5215
+ return undefined;
5216
+ };
5217
+
5218
+ var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
5219
+ if (forcedVersion) {
5220
+ return forcedVersion;
5221
+ }
5222
+ var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
5223
+ if (originVersion === sdkCommon.Version.V4 && destVersion === sdkCommon.Version.V3) {
5224
+ return sdkCommon.Version.V3;
5225
+ }
5226
+ return originVersion;
5227
+ };
5228
+
5229
+ var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
5230
+ if (sdkCommon.isRelayChain(origin)) return true;
5231
+ var hasMultiAsset = 'multiasset' in currency;
5232
+ var hasOverriddenMultilocation = 'multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation);
5233
+ return !(hasMultiAsset || hasOverriddenMultilocation);
5234
+ };
5235
+
5236
+ var validateDestinationAddress = function validateDestinationAddress(address, destination) {
5237
+ if (typeof address === 'string' && !sdkCommon.isTMultiLocation(destination)) {
5238
+ validateAddress(address, destination);
5239
+ }
5240
+ };
5241
+
5242
+ var validateCurrency = function validateCurrency(currency, feeAsset) {
5243
+ if ('multiasset' in currency) {
5244
+ if (currency.multiasset.length === 0) {
5245
+ throw new assets.InvalidCurrencyError('Overridden multi assets cannot be empty');
5246
+ }
5247
+ if (currency.multiasset.length === 1) {
5248
+ throw new assets.InvalidCurrencyError('Please provide more than one multi asset');
5249
+ }
5250
+ if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
5251
+ return assets.isTMultiAsset(asset);
5252
+ }) && !feeAsset) {
5253
+ throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5254
+ }
5255
+ }
5256
+ };
5257
+ var validateDestination = function validateDestination(origin, destination) {
5258
+ if (sdkCommon.isRelayChain(origin) && !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination) && origin !== destination) {
5259
+ throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
5260
+ }
5261
+ var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
5262
+ if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
5263
+ throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5264
+ }
5265
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5266
+ var isBridge = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isDotKsmBridge(origin, destination);
5267
+ var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
5268
+ if (!isRelayDestination && !isMultiLocationDestination) {
5269
+ var originRelayChainSymbol = assets.getRelayChainSymbol(origin);
5270
+ var destinationRelayChainSymbol = assets.getRelayChainSymbol(destination);
5271
+ if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
5272
+ throw new IncompatibleNodesError();
5273
+ }
5274
+ }
5275
+ };
5276
+ var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
5277
+ if (!assetCheckEnabled && 'symbol' in currency && assets.isSymbolSpecifier(currency.symbol)) {
5278
+ throw new assets.InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
5279
+ }
5280
+ if (!assetCheckEnabled && 'id' in currency) {
5281
+ throw new assets.InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
5282
+ }
5283
+ };
5284
+
5121
5285
  var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
5122
5286
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
5123
- var api, tx, origin, destination, senderAddress, rawOriginFee, originFee, sufficient;
5287
+ var api, tx, origin, destination, currency, senderAddress, feeAsset, rawOriginFee, originFee, resolvedFeeAsset, sufficient;
5124
5288
  return _regenerator().w(function (_context) {
5125
5289
  while (1) switch (_context.n) {
5126
5290
  case 0:
5127
- api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress;
5291
+ api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, currency = _ref.currency, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset;
5128
5292
  _context.n = 1;
5129
5293
  return api.calculateTransactionFee(tx, senderAddress);
5130
5294
  case 1:
5131
5295
  rawOriginFee = _context.v;
5132
5296
  originFee = padFee(rawOriginFee, origin, destination, 'origin');
5297
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
5133
5298
  _context.n = 2;
5134
- return isSufficientOrigin(api, origin, senderAddress, originFee);
5299
+ return isSufficientOrigin(api, origin, senderAddress, originFee, resolvedFeeAsset);
5135
5300
  case 2:
5136
5301
  sufficient = _context.v;
5137
5302
  return _context.a(2, {
@@ -5468,12 +5633,13 @@ var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
5468
5633
  var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
5469
5634
  var getXcmFeeEstimate = /*#__PURE__*/function () {
5470
5635
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
5471
- var api, origin, destination, currency, address, senderAddress, originAsset, destApi, _ref2, _ref3, fixedOriginFee, fixedDestinationFee, originSufficient, _destinationSufficient, originFeeDetails, currencyInput, destinationFee, destinationSufficient, destFeeDetails, _t;
5636
+ var api, origin, destination, currency, feeAsset, address, senderAddress, originAsset, resolvedFeeAsset, destApi, _ref2, _ref3, fixedOriginFee, fixedDestinationFee, originSufficient, _destinationSufficient, originFeeDetails, currencyInput, destinationFee, destinationSufficient, destFeeDetails, _t;
5472
5637
  return _regenerator().w(function (_context) {
5473
5638
  while (1) switch (_context.n) {
5474
5639
  case 0:
5475
- api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, address = options.address, senderAddress = options.senderAddress;
5640
+ api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, feeAsset = options.feeAsset, address = options.address, senderAddress = options.senderAddress;
5476
5641
  originAsset = assets.findAssetForNodeOrThrow(origin, currency, destination);
5642
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
5477
5643
  _context.n = 1;
5478
5644
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
5479
5645
  case 1:
@@ -5487,7 +5653,7 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
5487
5653
  }
5488
5654
  _ref2 = origin === 'AssetHubPolkadot' ? [BRIDGE_FEE_DOT, BRIDGE_FEE_KSM] : [BRIDGE_FEE_KSM, BRIDGE_FEE_DOT], _ref3 = _slicedToArray(_ref2, 2), fixedOriginFee = _ref3[0], fixedDestinationFee = _ref3[1];
5489
5655
  _context.n = 3;
5490
- return isSufficientOrigin(api, origin, senderAddress, fixedOriginFee);
5656
+ return isSufficientOrigin(api, origin, senderAddress, fixedOriginFee, resolvedFeeAsset);
5491
5657
  case 3:
5492
5658
  originSufficient = _context.v;
5493
5659
  _context.n = 4;
@@ -5591,161 +5757,6 @@ var transferRelayToPara = /*#__PURE__*/function () {
5591
5757
  };
5592
5758
  }();
5593
5759
 
5594
- var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
5595
- return assetCheckEnabled ? assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null) : null;
5596
- };
5597
-
5598
- var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
5599
- var origin = _ref.from,
5600
- destination = _ref.to,
5601
- currency = _ref.currency;
5602
- var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5603
- var allowedChainsToAh = ['AssetHubPolkadot', 'BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
5604
- if (!sdkCommon.isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
5605
- throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
5606
- }
5607
- var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
5608
- var isMultiLocationDestination = _typeof(destination) === 'object';
5609
- if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !assets.hasSupportForAsset(destination, asset.symbol)) {
5610
- throw new assets.InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
5611
- }
5612
- if (!isBridge && asset === null && assetCheckEnabled) {
5613
- throwUnsupportedCurrency(currency, origin);
5614
- }
5615
- };
5616
-
5617
- var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
5618
- var currency = options.currency,
5619
- feeAsset = options.feeAsset,
5620
- origin = options.from,
5621
- destination = options.to;
5622
- if ('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation)) {
5623
- return currency.multilocation.value;
5624
- }
5625
- if ('multiasset' in currency) {
5626
- if (!feeAsset) {
5627
- throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5628
- }
5629
- if ('multilocation' in feeAsset && assets.isOverrideMultiLocationSpecifier(feeAsset.multilocation)) {
5630
- throw new assets.InvalidCurrencyError('Fee asset cannot be an overridden multi location specifier');
5631
- }
5632
- if (currency.multiasset.every(function (asset) {
5633
- return assets.isTMultiAsset(asset);
5634
- })) {
5635
- if (!feeAsset) {
5636
- throw new assets.InvalidCurrencyError('Fee asset not provided');
5637
- }
5638
- if (!('multilocation' in feeAsset)) {
5639
- throw new assets.InvalidCurrencyError('Fee asset must be specified by multilocation when using raw overridden multi assets');
5640
- }
5641
- return currency.multiasset.map(function (multiAsset) {
5642
- var ml = assets.extractMultiAssetLoc(multiAsset);
5643
- return _objectSpread2(_objectSpread2({}, multiAsset), {}, {
5644
- isFeeAsset: sdkCommon.deepEqual(ml, feeAsset.multilocation)
5645
- });
5646
- });
5647
- }
5648
- // MultiAsset is an array of TCurrencyCore, search for assets
5649
- var assets$1 = currency.multiasset.map(function (currency) {
5650
- var asset = assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null);
5651
- if (asset && !asset.multiLocation) {
5652
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " does not have a multiLocation"));
5653
- }
5654
- if (!asset) {
5655
- throw new assets.InvalidCurrencyError("Origin node ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
5656
- }
5657
- if (!resolvedFeeAsset) {
5658
- throw new assets.InvalidCurrencyError('Fee asset not found');
5659
- }
5660
- validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
5661
- var originTyped = origin;
5662
- var originNode = getNode(originTyped);
5663
- return _objectSpread2({
5664
- isFeeAsset: assets.isAssetEqual(resolvedFeeAsset, asset)
5665
- }, createMultiAsset(originNode.version, currency.amount, asset.multiLocation));
5666
- });
5667
- if (assets$1.filter(function (asset) {
5668
- return asset.isFeeAsset;
5669
- }).length > 1) {
5670
- throw new assets.InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
5671
- }
5672
- if (assets$1.filter(function (asset) {
5673
- return asset.isFeeAsset;
5674
- }).length === 0) {
5675
- throw new assets.InvalidCurrencyError("Fee asset not found in multiassets");
5676
- }
5677
- return assets$1;
5678
- }
5679
- return undefined;
5680
- };
5681
-
5682
- var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
5683
- if (forcedVersion) {
5684
- return forcedVersion;
5685
- }
5686
- var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
5687
- if (originVersion === sdkCommon.Version.V4 && destVersion === sdkCommon.Version.V3) {
5688
- return sdkCommon.Version.V3;
5689
- }
5690
- return originVersion;
5691
- };
5692
-
5693
- var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
5694
- if (sdkCommon.isRelayChain(origin)) return true;
5695
- var hasMultiAsset = 'multiasset' in currency;
5696
- var hasOverriddenMultilocation = 'multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation);
5697
- return !(hasMultiAsset || hasOverriddenMultilocation);
5698
- };
5699
-
5700
- var validateDestinationAddress = function validateDestinationAddress(address, destination) {
5701
- if (typeof address === 'string' && !sdkCommon.isTMultiLocation(destination)) {
5702
- validateAddress(address, destination);
5703
- }
5704
- };
5705
-
5706
- var validateCurrency = function validateCurrency(currency, feeAsset) {
5707
- if ('multiasset' in currency) {
5708
- if (currency.multiasset.length === 0) {
5709
- throw new assets.InvalidCurrencyError('Overridden multi assets cannot be empty');
5710
- }
5711
- if (currency.multiasset.length === 1) {
5712
- throw new assets.InvalidCurrencyError('Please provide more than one multi asset');
5713
- }
5714
- if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
5715
- return assets.isTMultiAsset(asset);
5716
- }) && !feeAsset) {
5717
- throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5718
- }
5719
- }
5720
- };
5721
- var validateDestination = function validateDestination(origin, destination) {
5722
- if (sdkCommon.isRelayChain(origin) && !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination) && origin !== destination) {
5723
- throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
5724
- }
5725
- var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
5726
- if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
5727
- throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5728
- }
5729
- var isMultiLocationDestination = _typeof(destination) === 'object';
5730
- var isBridge = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isDotKsmBridge(origin, destination);
5731
- var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
5732
- if (!isRelayDestination && !isMultiLocationDestination) {
5733
- var originRelayChainSymbol = assets.getRelayChainSymbol(origin);
5734
- var destinationRelayChainSymbol = assets.getRelayChainSymbol(destination);
5735
- if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
5736
- throw new IncompatibleNodesError();
5737
- }
5738
- }
5739
- };
5740
- var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
5741
- if (!assetCheckEnabled && 'symbol' in currency && assets.isSymbolSpecifier(currency.symbol)) {
5742
- throw new assets.InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
5743
- }
5744
- if (!assetCheckEnabled && 'id' in currency) {
5745
- throw new assets.InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
5746
- }
5747
- };
5748
-
5749
5760
  var send = /*#__PURE__*/function () {
5750
5761
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
5751
5762
  var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, originVersion, destVersion, resolvedVersion, isLocalTransfer, overriddenAsset, resolvedAsset, finalAsset, finalVersion, normalizedAsset;
@@ -10098,11 +10109,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
10098
10109
  key: "getOriginXcmFeeEstimate",
10099
10110
  value: (function () {
10100
10111
  var _getOriginXcmFeeEstimate2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
10101
- var _this$_options6, from, to, senderAddress, tx;
10112
+ var _this$_options6, from, to, senderAddress, currency, tx;
10102
10113
  return _regenerator().w(function (_context7) {
10103
10114
  while (1) switch (_context7.n) {
10104
10115
  case 0:
10105
- _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress;
10116
+ _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress, currency = _this$_options6.currency;
10106
10117
  assertToIsString(to);
10107
10118
  _context7.n = 1;
10108
10119
  return this.build();
@@ -10115,6 +10126,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
10115
10126
  tx: tx,
10116
10127
  origin: from,
10117
10128
  destination: to,
10129
+ currency: currency,
10118
10130
  senderAddress: senderAddress
10119
10131
  });
10120
10132
  case 3:
package/dist/index.d.ts CHANGED
@@ -844,7 +844,7 @@ type TGetXcmFeeBaseOptions<TRes> = {
844
844
  };
845
845
  type TGetXcmFeeOptions<TApi, TRes> = WithApi<TGetXcmFeeBaseOptions<TRes>, TApi, TRes>;
846
846
  type TGetXcmFeeEstimateOptions<TApi, TRes> = Omit<TGetXcmFeeOptions<TApi, TRes>, 'disableFallback'>;
847
- type TGetOriginXcmFeeEstimateOptions<TApi, TRes> = Omit<TGetXcmFeeOptions<TApi, TRes>, 'disableFallback' | 'address' | 'currency'>;
847
+ type TGetOriginXcmFeeEstimateOptions<TApi, TRes> = Omit<TGetXcmFeeOptions<TApi, TRes>, 'disableFallback' | 'address'>;
848
848
  type TGetXcmFeeBuilderOptions = {
849
849
  disableFallback: boolean;
850
850
  };
@@ -1768,7 +1768,7 @@ declare const getOriginXcmFee: <TApi, TRes>({ api, tx, origin, destination, send
1768
1768
  destParaId?: number;
1769
1769
  }>;
1770
1770
 
1771
- declare const getOriginXcmFeeEstimate: <TApi, TRes>({ api, tx, origin, destination, senderAddress }: TGetOriginXcmFeeEstimateOptions<TApi, TRes>) => Promise<TGetXcmFeeEstimateDetail>;
1771
+ declare const getOriginXcmFeeEstimate: <TApi, TRes>({ api, tx, origin, destination, currency, senderAddress, feeAsset }: TGetOriginXcmFeeEstimateOptions<TApi, TRes>) => Promise<TGetXcmFeeEstimateDetail>;
1772
1772
 
1773
1773
  declare const getXcmFee: <TApi, TRes>({ api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback }: TGetXcmFeeOptions<TApi, TRes>) => Promise<TGetXcmFeeResult>;
1774
1774
 
package/dist/index.mjs CHANGED
@@ -4581,25 +4581,31 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
4581
4581
  }();
4582
4582
 
4583
4583
  var isSufficientOrigin = /*#__PURE__*/function () {
4584
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, node, senderAddress, fee) {
4584
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, node, senderAddress, fee, feeAsset) {
4585
4585
  var existentialDeposit, nativeBalance;
4586
4586
  return _regenerator().w(function (_context) {
4587
4587
  while (1) switch (_context.n) {
4588
4588
  case 0:
4589
+ if (!feeAsset) {
4590
+ _context.n = 1;
4591
+ break;
4592
+ }
4593
+ return _context.a(2, undefined);
4594
+ case 1:
4589
4595
  existentialDeposit = getExistentialDepositOrThrow(node);
4590
- _context.n = 1;
4596
+ _context.n = 2;
4591
4597
  return getBalanceNativeInternal({
4592
4598
  api: api,
4593
4599
  node: node,
4594
4600
  address: senderAddress
4595
4601
  });
4596
- case 1:
4602
+ case 2:
4597
4603
  nativeBalance = _context.v;
4598
4604
  return _context.a(2, nativeBalance - existentialDeposit - fee > 0n);
4599
4605
  }
4600
4606
  }, _callee);
4601
4607
  }));
4602
- return function isSufficientOrigin(_x, _x2, _x3, _x4) {
4608
+ return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5) {
4603
4609
  return _ref.apply(this, arguments);
4604
4610
  };
4605
4611
  }();
@@ -4628,7 +4634,7 @@ var isSufficientDestination = /*#__PURE__*/function () {
4628
4634
  }
4629
4635
  }, _callee2);
4630
4636
  }));
4631
- return function isSufficientDestination(_x5, _x6, _x7, _x8, _x9) {
4637
+ return function isSufficientDestination(_x6, _x7, _x8, _x9, _x0) {
4632
4638
  return _ref2.apply(this, arguments);
4633
4639
  };
4634
4640
  }();
@@ -4782,6 +4788,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
4782
4788
  return _context2.a(2, {
4783
4789
  fee: fee,
4784
4790
  feeType: 'dryRun',
4791
+ sufficient: true,
4785
4792
  forwardedXcms: newForwardedXcms,
4786
4793
  destParaId: destParaId
4787
4794
  });
@@ -5034,7 +5041,7 @@ var dryRunOrigin = /*#__PURE__*/function () {
5034
5041
 
5035
5042
  var getOriginXcmFee = /*#__PURE__*/function () {
5036
5043
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
5037
- var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, currencySymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee, _sufficient, fee, forwardedXcms, destParaId, weight;
5044
+ var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, nativeAssetSymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee, _sufficient, fee, forwardedXcms, destParaId, weight, currencySymbol;
5038
5045
  return _regenerator().w(function (_context) {
5039
5046
  while (1) switch (_context.n) {
5040
5047
  case 0:
@@ -5043,7 +5050,7 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5043
5050
  _context.n = 1;
5044
5051
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
5045
5052
  case 1:
5046
- currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin);
5053
+ nativeAssetSymbol = getNativeAssetSymbol(origin);
5047
5054
  if (hasDryRunSupport(origin)) {
5048
5055
  _context.n = 4;
5049
5056
  break;
@@ -5054,12 +5061,12 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5054
5061
  rawFee = _context.v;
5055
5062
  paddedFee = padFee(rawFee, origin, destination, 'origin');
5056
5063
  _context.n = 3;
5057
- return isSufficientOrigin(api, origin, senderAddress, paddedFee);
5064
+ return isSufficientOrigin(api, origin, senderAddress, paddedFee, resolvedFeeAsset);
5058
5065
  case 3:
5059
5066
  sufficient = _context.v;
5060
5067
  return _context.a(2, {
5061
5068
  fee: paddedFee,
5062
- currency: currencySymbol,
5069
+ currency: nativeAssetSymbol,
5063
5070
  feeType: 'paymentInfo',
5064
5071
  sufficient: sufficient
5065
5072
  });
@@ -5091,21 +5098,23 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5091
5098
  _rawFee = _context.v;
5092
5099
  _paddedFee = padFee(_rawFee, origin, destination, 'origin');
5093
5100
  _context.n = 8;
5094
- return isSufficientOrigin(api, origin, senderAddress, _paddedFee);
5101
+ return isSufficientOrigin(api, origin, senderAddress, _paddedFee, resolvedFeeAsset);
5095
5102
  case 8:
5096
5103
  _sufficient = _context.v;
5097
5104
  return _context.a(2, {
5098
5105
  fee: _paddedFee,
5099
- currency: currencySymbol,
5106
+ currency: nativeAssetSymbol,
5100
5107
  feeType: 'paymentInfo',
5101
5108
  dryRunError: dryRunResult.failureReason,
5102
5109
  sufficient: _sufficient
5103
5110
  });
5104
5111
  case 9:
5105
5112
  fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId, weight = dryRunResult.weight;
5113
+ currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : nativeAssetSymbol;
5106
5114
  return _context.a(2, {
5107
5115
  fee: fee,
5108
5116
  feeType: 'dryRun',
5117
+ sufficient: true,
5109
5118
  currency: currencySymbol,
5110
5119
  forwardedXcms: forwardedXcms,
5111
5120
  destParaId: destParaId,
@@ -5119,20 +5128,176 @@ var getOriginXcmFee = /*#__PURE__*/function () {
5119
5128
  };
5120
5129
  }();
5121
5130
 
5131
+ var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
5132
+ return assetCheckEnabled ? findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null) : null;
5133
+ };
5134
+
5135
+ var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
5136
+ var origin = _ref.from,
5137
+ destination = _ref.to,
5138
+ currency = _ref.currency;
5139
+ var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5140
+ var allowedChainsToAh = ['AssetHubPolkadot', 'BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
5141
+ if (!isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
5142
+ throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
5143
+ }
5144
+ var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5145
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5146
+ if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
5147
+ throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
5148
+ }
5149
+ if (!isBridge && asset === null && assetCheckEnabled) {
5150
+ throwUnsupportedCurrency(currency, origin);
5151
+ }
5152
+ };
5153
+
5154
+ var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
5155
+ var currency = options.currency,
5156
+ feeAsset = options.feeAsset,
5157
+ origin = options.from,
5158
+ destination = options.to;
5159
+ if ('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation)) {
5160
+ return currency.multilocation.value;
5161
+ }
5162
+ if ('multiasset' in currency) {
5163
+ if (!feeAsset) {
5164
+ throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5165
+ }
5166
+ if ('multilocation' in feeAsset && isOverrideMultiLocationSpecifier(feeAsset.multilocation)) {
5167
+ throw new InvalidCurrencyError('Fee asset cannot be an overridden multi location specifier');
5168
+ }
5169
+ if (currency.multiasset.every(function (asset) {
5170
+ return isTMultiAsset(asset);
5171
+ })) {
5172
+ if (!feeAsset) {
5173
+ throw new InvalidCurrencyError('Fee asset not provided');
5174
+ }
5175
+ if (!('multilocation' in feeAsset)) {
5176
+ throw new InvalidCurrencyError('Fee asset must be specified by multilocation when using raw overridden multi assets');
5177
+ }
5178
+ return currency.multiasset.map(function (multiAsset) {
5179
+ var ml = extractMultiAssetLoc(multiAsset);
5180
+ return _objectSpread2(_objectSpread2({}, multiAsset), {}, {
5181
+ isFeeAsset: deepEqual(ml, feeAsset.multilocation)
5182
+ });
5183
+ });
5184
+ }
5185
+ // MultiAsset is an array of TCurrencyCore, search for assets
5186
+ var assets = currency.multiasset.map(function (currency) {
5187
+ var asset = findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null);
5188
+ if (asset && !asset.multiLocation) {
5189
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " does not have a multiLocation"));
5190
+ }
5191
+ if (!asset) {
5192
+ throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
5193
+ }
5194
+ if (!resolvedFeeAsset) {
5195
+ throw new InvalidCurrencyError('Fee asset not found');
5196
+ }
5197
+ validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
5198
+ var originTyped = origin;
5199
+ var originNode = getNode(originTyped);
5200
+ return _objectSpread2({
5201
+ isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
5202
+ }, createMultiAsset(originNode.version, currency.amount, asset.multiLocation));
5203
+ });
5204
+ if (assets.filter(function (asset) {
5205
+ return asset.isFeeAsset;
5206
+ }).length > 1) {
5207
+ throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
5208
+ }
5209
+ if (assets.filter(function (asset) {
5210
+ return asset.isFeeAsset;
5211
+ }).length === 0) {
5212
+ throw new InvalidCurrencyError("Fee asset not found in multiassets");
5213
+ }
5214
+ return assets;
5215
+ }
5216
+ return undefined;
5217
+ };
5218
+
5219
+ var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
5220
+ if (forcedVersion) {
5221
+ return forcedVersion;
5222
+ }
5223
+ var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
5224
+ if (originVersion === Version.V4 && destVersion === Version.V3) {
5225
+ return Version.V3;
5226
+ }
5227
+ return originVersion;
5228
+ };
5229
+
5230
+ var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
5231
+ if (isRelayChain(origin)) return true;
5232
+ var hasMultiAsset = 'multiasset' in currency;
5233
+ var hasOverriddenMultilocation = 'multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation);
5234
+ return !(hasMultiAsset || hasOverriddenMultilocation);
5235
+ };
5236
+
5237
+ var validateDestinationAddress = function validateDestinationAddress(address, destination) {
5238
+ if (typeof address === 'string' && !isTMultiLocation(destination)) {
5239
+ validateAddress(address, destination);
5240
+ }
5241
+ };
5242
+
5243
+ var validateCurrency = function validateCurrency(currency, feeAsset) {
5244
+ if ('multiasset' in currency) {
5245
+ if (currency.multiasset.length === 0) {
5246
+ throw new InvalidCurrencyError('Overridden multi assets cannot be empty');
5247
+ }
5248
+ if (currency.multiasset.length === 1) {
5249
+ throw new InvalidCurrencyError('Please provide more than one multi asset');
5250
+ }
5251
+ if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
5252
+ return isTMultiAsset(asset);
5253
+ }) && !feeAsset) {
5254
+ throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5255
+ }
5256
+ }
5257
+ };
5258
+ var validateDestination = function validateDestination(origin, destination) {
5259
+ if (isRelayChain(origin) && !isTMultiLocation(destination) && isRelayChain(destination) && origin !== destination) {
5260
+ throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
5261
+ }
5262
+ var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
5263
+ if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
5264
+ throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5265
+ }
5266
+ var isMultiLocationDestination = _typeof(destination) === 'object';
5267
+ var isBridge = !isTMultiLocation(destination) && isDotKsmBridge(origin, destination);
5268
+ var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5269
+ if (!isRelayDestination && !isMultiLocationDestination) {
5270
+ var originRelayChainSymbol = getRelayChainSymbol(origin);
5271
+ var destinationRelayChainSymbol = getRelayChainSymbol(destination);
5272
+ if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
5273
+ throw new IncompatibleNodesError();
5274
+ }
5275
+ }
5276
+ };
5277
+ var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
5278
+ if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
5279
+ throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
5280
+ }
5281
+ if (!assetCheckEnabled && 'id' in currency) {
5282
+ throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
5283
+ }
5284
+ };
5285
+
5122
5286
  var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
5123
5287
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
5124
- var api, tx, origin, destination, senderAddress, rawOriginFee, originFee, sufficient;
5288
+ var api, tx, origin, destination, currency, senderAddress, feeAsset, rawOriginFee, originFee, resolvedFeeAsset, sufficient;
5125
5289
  return _regenerator().w(function (_context) {
5126
5290
  while (1) switch (_context.n) {
5127
5291
  case 0:
5128
- api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress;
5292
+ api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, currency = _ref.currency, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset;
5129
5293
  _context.n = 1;
5130
5294
  return api.calculateTransactionFee(tx, senderAddress);
5131
5295
  case 1:
5132
5296
  rawOriginFee = _context.v;
5133
5297
  originFee = padFee(rawOriginFee, origin, destination, 'origin');
5298
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
5134
5299
  _context.n = 2;
5135
- return isSufficientOrigin(api, origin, senderAddress, originFee);
5300
+ return isSufficientOrigin(api, origin, senderAddress, originFee, resolvedFeeAsset);
5136
5301
  case 2:
5137
5302
  sufficient = _context.v;
5138
5303
  return _context.a(2, {
@@ -5469,12 +5634,13 @@ var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
5469
5634
  var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
5470
5635
  var getXcmFeeEstimate = /*#__PURE__*/function () {
5471
5636
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
5472
- var api, origin, destination, currency, address, senderAddress, originAsset, destApi, _ref2, _ref3, fixedOriginFee, fixedDestinationFee, originSufficient, _destinationSufficient, originFeeDetails, currencyInput, destinationFee, destinationSufficient, destFeeDetails, _t;
5637
+ var api, origin, destination, currency, feeAsset, address, senderAddress, originAsset, resolvedFeeAsset, destApi, _ref2, _ref3, fixedOriginFee, fixedDestinationFee, originSufficient, _destinationSufficient, originFeeDetails, currencyInput, destinationFee, destinationSufficient, destFeeDetails, _t;
5473
5638
  return _regenerator().w(function (_context) {
5474
5639
  while (1) switch (_context.n) {
5475
5640
  case 0:
5476
- api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, address = options.address, senderAddress = options.senderAddress;
5641
+ api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, feeAsset = options.feeAsset, address = options.address, senderAddress = options.senderAddress;
5477
5642
  originAsset = findAssetForNodeOrThrow(origin, currency, destination);
5643
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
5478
5644
  _context.n = 1;
5479
5645
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
5480
5646
  case 1:
@@ -5488,7 +5654,7 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
5488
5654
  }
5489
5655
  _ref2 = origin === 'AssetHubPolkadot' ? [BRIDGE_FEE_DOT, BRIDGE_FEE_KSM] : [BRIDGE_FEE_KSM, BRIDGE_FEE_DOT], _ref3 = _slicedToArray(_ref2, 2), fixedOriginFee = _ref3[0], fixedDestinationFee = _ref3[1];
5490
5656
  _context.n = 3;
5491
- return isSufficientOrigin(api, origin, senderAddress, fixedOriginFee);
5657
+ return isSufficientOrigin(api, origin, senderAddress, fixedOriginFee, resolvedFeeAsset);
5492
5658
  case 3:
5493
5659
  originSufficient = _context.v;
5494
5660
  _context.n = 4;
@@ -5592,161 +5758,6 @@ var transferRelayToPara = /*#__PURE__*/function () {
5592
5758
  };
5593
5759
  }();
5594
5760
 
5595
- var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
5596
- return assetCheckEnabled ? findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null) : null;
5597
- };
5598
-
5599
- var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
5600
- var origin = _ref.from,
5601
- destination = _ref.to,
5602
- currency = _ref.currency;
5603
- var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
5604
- var allowedChainsToAh = ['AssetHubPolkadot', 'BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
5605
- if (!isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
5606
- throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
5607
- }
5608
- var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5609
- var isMultiLocationDestination = _typeof(destination) === 'object';
5610
- if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
5611
- throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
5612
- }
5613
- if (!isBridge && asset === null && assetCheckEnabled) {
5614
- throwUnsupportedCurrency(currency, origin);
5615
- }
5616
- };
5617
-
5618
- var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
5619
- var currency = options.currency,
5620
- feeAsset = options.feeAsset,
5621
- origin = options.from,
5622
- destination = options.to;
5623
- if ('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation)) {
5624
- return currency.multilocation.value;
5625
- }
5626
- if ('multiasset' in currency) {
5627
- if (!feeAsset) {
5628
- throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5629
- }
5630
- if ('multilocation' in feeAsset && isOverrideMultiLocationSpecifier(feeAsset.multilocation)) {
5631
- throw new InvalidCurrencyError('Fee asset cannot be an overridden multi location specifier');
5632
- }
5633
- if (currency.multiasset.every(function (asset) {
5634
- return isTMultiAsset(asset);
5635
- })) {
5636
- if (!feeAsset) {
5637
- throw new InvalidCurrencyError('Fee asset not provided');
5638
- }
5639
- if (!('multilocation' in feeAsset)) {
5640
- throw new InvalidCurrencyError('Fee asset must be specified by multilocation when using raw overridden multi assets');
5641
- }
5642
- return currency.multiasset.map(function (multiAsset) {
5643
- var ml = extractMultiAssetLoc(multiAsset);
5644
- return _objectSpread2(_objectSpread2({}, multiAsset), {}, {
5645
- isFeeAsset: deepEqual(ml, feeAsset.multilocation)
5646
- });
5647
- });
5648
- }
5649
- // MultiAsset is an array of TCurrencyCore, search for assets
5650
- var assets = currency.multiasset.map(function (currency) {
5651
- var asset = findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null);
5652
- if (asset && !asset.multiLocation) {
5653
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " does not have a multiLocation"));
5654
- }
5655
- if (!asset) {
5656
- throw new InvalidCurrencyError("Origin node ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
5657
- }
5658
- if (!resolvedFeeAsset) {
5659
- throw new InvalidCurrencyError('Fee asset not found');
5660
- }
5661
- validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
5662
- var originTyped = origin;
5663
- var originNode = getNode(originTyped);
5664
- return _objectSpread2({
5665
- isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
5666
- }, createMultiAsset(originNode.version, currency.amount, asset.multiLocation));
5667
- });
5668
- if (assets.filter(function (asset) {
5669
- return asset.isFeeAsset;
5670
- }).length > 1) {
5671
- throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
5672
- }
5673
- if (assets.filter(function (asset) {
5674
- return asset.isFeeAsset;
5675
- }).length === 0) {
5676
- throw new InvalidCurrencyError("Fee asset not found in multiassets");
5677
- }
5678
- return assets;
5679
- }
5680
- return undefined;
5681
- };
5682
-
5683
- var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
5684
- if (forcedVersion) {
5685
- return forcedVersion;
5686
- }
5687
- var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
5688
- if (originVersion === Version.V4 && destVersion === Version.V3) {
5689
- return Version.V3;
5690
- }
5691
- return originVersion;
5692
- };
5693
-
5694
- var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
5695
- if (isRelayChain(origin)) return true;
5696
- var hasMultiAsset = 'multiasset' in currency;
5697
- var hasOverriddenMultilocation = 'multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation);
5698
- return !(hasMultiAsset || hasOverriddenMultilocation);
5699
- };
5700
-
5701
- var validateDestinationAddress = function validateDestinationAddress(address, destination) {
5702
- if (typeof address === 'string' && !isTMultiLocation(destination)) {
5703
- validateAddress(address, destination);
5704
- }
5705
- };
5706
-
5707
- var validateCurrency = function validateCurrency(currency, feeAsset) {
5708
- if ('multiasset' in currency) {
5709
- if (currency.multiasset.length === 0) {
5710
- throw new InvalidCurrencyError('Overridden multi assets cannot be empty');
5711
- }
5712
- if (currency.multiasset.length === 1) {
5713
- throw new InvalidCurrencyError('Please provide more than one multi asset');
5714
- }
5715
- if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
5716
- return isTMultiAsset(asset);
5717
- }) && !feeAsset) {
5718
- throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
5719
- }
5720
- }
5721
- };
5722
- var validateDestination = function validateDestination(origin, destination) {
5723
- if (isRelayChain(origin) && !isTMultiLocation(destination) && isRelayChain(destination) && origin !== destination) {
5724
- throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
5725
- }
5726
- var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
5727
- if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
5728
- throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5729
- }
5730
- var isMultiLocationDestination = _typeof(destination) === 'object';
5731
- var isBridge = !isTMultiLocation(destination) && isDotKsmBridge(origin, destination);
5732
- var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5733
- if (!isRelayDestination && !isMultiLocationDestination) {
5734
- var originRelayChainSymbol = getRelayChainSymbol(origin);
5735
- var destinationRelayChainSymbol = getRelayChainSymbol(destination);
5736
- if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
5737
- throw new IncompatibleNodesError();
5738
- }
5739
- }
5740
- };
5741
- var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
5742
- if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
5743
- throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
5744
- }
5745
- if (!assetCheckEnabled && 'id' in currency) {
5746
- throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
5747
- }
5748
- };
5749
-
5750
5761
  var send = /*#__PURE__*/function () {
5751
5762
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
5752
5763
  var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, originVersion, destVersion, resolvedVersion, isLocalTransfer, overriddenAsset, resolvedAsset, finalAsset, finalVersion, normalizedAsset;
@@ -10099,11 +10110,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
10099
10110
  key: "getOriginXcmFeeEstimate",
10100
10111
  value: (function () {
10101
10112
  var _getOriginXcmFeeEstimate2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
10102
- var _this$_options6, from, to, senderAddress, tx;
10113
+ var _this$_options6, from, to, senderAddress, currency, tx;
10103
10114
  return _regenerator().w(function (_context7) {
10104
10115
  while (1) switch (_context7.n) {
10105
10116
  case 0:
10106
- _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress;
10117
+ _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress, currency = _this$_options6.currency;
10107
10118
  assertToIsString(to);
10108
10119
  _context7.n = 1;
10109
10120
  return this.build();
@@ -10116,6 +10127,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
10116
10127
  tx: tx,
10117
10128
  origin: from,
10118
10129
  destination: to,
10130
+ currency: currency,
10119
10131
  senderAddress: senderAddress
10120
10132
  });
10121
10133
  case 3:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "10.4.6",
3
+ "version": "10.4.7",
4
4
  "description": "SDK core for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "@noble/hashes": "^1.8.0",
27
27
  "@scure/base": "^1.2.6",
28
28
  "viem": "^2.30.5",
29
- "@paraspell/assets": "10.4.6",
30
- "@paraspell/sdk-common": "10.4.6",
31
- "@paraspell/pallets": "10.4.6"
29
+ "@paraspell/assets": "10.4.7",
30
+ "@paraspell/pallets": "10.4.7",
31
+ "@paraspell/sdk-common": "10.4.7"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/plugin-syntax-import-attributes": "^7.27.1",