@paraspell/swap 13.10.1 → 14.0.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.d.ts CHANGED
@@ -314,7 +314,7 @@ declare class SwapBuilderCore<TApi, TRes, TSigner, T extends Partial<TTransferBa
314
314
  }, TCustomChain>;
315
315
  getXcmFees<TDisableFallback extends boolean = false>(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>, options?: TGetXcmFeeBuilderOptions & {
316
316
  disableFallback: TDisableFallback;
317
- }): Promise<TGetXcmFeeResult<TDisableFallback>>;
317
+ }): Promise<TGetXcmFeeResult<TDisableFallback, TCustomChain>>;
318
318
  getOriginXcmFee<TDisableFallback extends boolean = false>(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>, options?: TGetXcmFeeBuilderOptions & {
319
319
  disableFallback: TDisableFallback;
320
320
  }): Promise<TXcmFeeDetailWithForwardedXcm<TDisableFallback>>;
@@ -323,14 +323,14 @@ declare class SwapBuilderCore<TApi, TRes, TSigner, T extends Partial<TTransferBa
323
323
  getMinTransferableAmount(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<bigint>;
324
324
  signAndSubmit(this: SwapBuilderCore<TApi, TRes, TSigner, TTransferBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<string[]>;
325
325
  build(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<TTransactionContext<TApi, TRes>[]>;
326
- dryRun(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<TDryRunResult>;
327
- dryRunPreview(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>, previewOptions?: TDryRunPreviewOptions): Promise<TDryRunResult>;
326
+ dryRun(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<TDryRunResult<TCustomChain>>;
327
+ dryRunPreview(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>, TCustomChain>, previewOptions?: TDryRunPreviewOptions): Promise<TDryRunResult<TCustomChain>>;
328
328
  getBestAmountOut(this: SwapBuilderCore<TApi, TRes, TSigner, TGetBestAmountOutBaseOptions<TApi, TRes, TSigner>, TCustomChain>): Promise<{
329
329
  exchange: TExchangeChain;
330
330
  amountOut: bigint;
331
331
  }>;
332
332
  }
333
- declare const SwapBuilder: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>) => TSwapBuilder<TApi, TRes, TSigner>;
333
+ declare const SwapBuilder: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>) => TSwapBuilder<TApi, TRes, TSigner, TCustomChain>;
334
334
 
335
335
  declare const FEE_BUFFER_PCT = 10;
336
336
  declare const DEST_FEE_BUFFER_PCT = -1;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createChainClient as createChainClient$1, registerSwapExtension } from '@paraspell/sdk';
2
- import { UnsupportedOperationError, assertCurrencyCore, dryRun, getFailureInfo, DryRunFailedError, isConfig, getNativeAssets, RoutingResolutionError, findAssetInfoById, getOtherAssets, getChainProviders, parseUnits, getNativeAssetSymbol, padValueBy, formatUnits as formatUnits$1, AmountTooLowError, getBalance, localizeLocation, getAssets, Parents, isSymbolMatch, getParaId, UnableToComputeError, getAssetDecimals, findNativeAssetInfoOrThrow, InvalidCurrencyError, findAssetInfoOrThrow, isOverrideLocationSpecifier, findAssetInfoByLoc, isSymbolSpecifier, findBestMatches, findAssetInfoBySymbol, deepEqual, normalizeExchange, EXCHANGE_CHAINS, reverseTransformLocation, getAssetsImpl, isAssetEqual, isExternalChain, isSystemAsset, ScenarioNotSupportedError, applyDecimalAbstraction, findAssetInfo, getRelayChainOf, hasSupportForAsset, Builder, isChainEvm, convertBuilderConfig, handleSwapExecuteTransfer, getXcmFee, getOriginXcmFee as getOriginXcmFee$1, InvalidAddressError, MissingParameterError, BatchMode, createChainClient as createChainClient$2, getExistentialDepositOrThrow, buildHopInfo, getRelayChainSymbol, aggregateHopFees, buildDestInfo, buildOriginInfo } from '@paraspell/sdk-core';
2
+ import { UnsupportedOperationError, assertCurrencyCore, dryRun, getDryRunError, DryRunFailedError, isConfig, getNativeAssets, RoutingResolutionError, findAssetInfoById, getOtherAssets, getChainProviders, parseUnits, getNativeAssetSymbol, padValueBy, formatUnits as formatUnits$1, AmountTooLowError, getBalance, localizeLocation, getAssets, Parents, isSymbolMatch, getParaId, UnableToComputeError, findNativeAssetInfoOrThrow, InvalidCurrencyError, findAssetInfoOrThrow, findAssetInfoByLoc, isSymbolSpecifier, findBestMatches, findAssetInfoBySymbol, deepEqual, normalizeExchange, EXCHANGE_CHAINS, reverseTransformLocation, getAssetsImpl, isAssetEqual, isExternalChain, isSystemAsset, ScenarioNotSupportedError, applyDecimalAbstraction, findAssetInfo, getRelayChainOf, Builder, isChainEvm, convertBuilderConfig, handleSwapExecuteTransfer, getXcmFee, getOriginXcmFee as getOriginXcmFee$1, InvalidAddressError, MissingParameterError, BatchMode, createChainClient as createChainClient$2, getExistentialDepositOrThrow, buildHopInfo, getRelayChainSymbol, aggregateHopFees, buildDestInfo, buildOriginInfo } from '@paraspell/sdk-core';
3
3
  import { toHex } from 'polkadot-api/utils';
4
4
  import 'polkadot-api';
5
5
  import { Wallet } from '@acala-network/sdk';
@@ -9,7 +9,7 @@ import { firstValueFrom } from 'rxjs';
9
9
  import { createChainClient, formatUnits } from '@paraspell/sdk-pjs';
10
10
  import { options } from '@acala-network/api';
11
11
  import { WsProvider, ApiPromise } from '@polkadot/api';
12
- import { snakeToCamel } from '@paraspell/sdk-common';
12
+ import { lowercaseFirstLetter, snakeToCamel } from '@paraspell/sdk-common';
13
13
  import { Amount, Token, getCurrencyCombinations } from '@crypto-dex-sdk/currency';
14
14
  import { Percent } from '@crypto-dex-sdk/math';
15
15
  import { PAIR_ADDRESSES, isNativeCurrency, addressToNodeCurrency, SwapRouter } from '@crypto-dex-sdk/parachains-bifrost';
@@ -592,7 +592,8 @@ var dryRunTransaction = /*#__PURE__*/function () {
592
592
  };
593
593
  }();
594
594
  var mergeDryRunResults = function mergeDryRunResults(options, originResult, exchangeResult) {
595
- var exchange = options.exchange,
595
+ var origin = options.origin,
596
+ exchange = options.exchange,
596
597
  destination = options.destination;
597
598
  var result = {
598
599
  origin: originResult.origin,
@@ -602,12 +603,26 @@ var mergeDryRunResults = function mergeDryRunResults(options, originResult, exch
602
603
  result: exchangeResult.origin
603
604
  }] : []), _toConsumableArray(exchangeResult.hops))
604
605
  };
605
- return _objectSpread2(_objectSpread2({}, getFailureInfo(result)), result);
606
+ var dryRunError = getDryRunError({
607
+ origin: {
608
+ chain: origin ? origin.chain : exchange.chain,
609
+ result: result.origin
610
+ },
611
+ destination: result.destination ? {
612
+ chain: destination ? destination.chain : exchange.chain,
613
+ result: result.destination
614
+ } : undefined,
615
+ hops: result.hops
616
+ });
617
+ return _objectSpread2({
618
+ success: !dryRunError,
619
+ dryRunError: dryRunError
620
+ }, result);
606
621
  };
607
622
  var dryRun2Transactions = /*#__PURE__*/function () {
608
623
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, transactions, originBypass, exchangeBypass) {
609
624
  var _originBypass$mintFee;
610
- var exchange, _transactions, firstTx, secondTx, firstRes, _getFailureInfo, failureReason, exchangeBypassOptions, secondRes;
625
+ var exchange, _transactions, firstTx, secondTx, firstRes, exchangeBypassOptions, secondRes;
611
626
  return _regenerator().w(function (_context2) {
612
627
  while (1) switch (_context2.n) {
613
628
  case 0:
@@ -617,8 +632,7 @@ var dryRun2Transactions = /*#__PURE__*/function () {
617
632
  return dryRunTransaction(options, firstTx, exchange.chain, originBypass);
618
633
  case 1:
619
634
  firstRes = _context2.v;
620
- _getFailureInfo = getFailureInfo(firstRes), failureReason = _getFailureInfo.failureReason;
621
- exchangeBypassOptions = exchangeBypass !== null && exchangeBypass !== void 0 ? exchangeBypass : !failureReason ? {
635
+ exchangeBypassOptions = exchangeBypass !== null && exchangeBypass !== void 0 ? exchangeBypass : firstRes.success ? {
622
636
  sentAssetMintMode: 'preview',
623
637
  mintFeeAssets: (_originBypass$mintFee = originBypass === null || originBypass === void 0 ? void 0 : originBypass.mintFeeAssets) !== null && _originBypass$mintFee !== void 0 ? _originBypass$mintFee : false
624
638
  } : undefined;
@@ -702,11 +716,11 @@ var maybePerformXcmFormatCheck = /*#__PURE__*/function () {
702
716
  return dryRunTransactions(routerPlan, options, BYPASS, BYPASS);
703
717
  case 2:
704
718
  result = _context.v;
705
- if (!result.failureReason) {
719
+ if (!result.dryRunError) {
706
720
  _context.n = 3;
707
721
  break;
708
722
  }
709
- throw new DryRunFailedError(result.failureReason, result.failureChain, 'XCM format check failed.');
723
+ throw new DryRunFailedError(result.dryRunError, 'XCM format check failed.');
710
724
  case 3:
711
725
  return _context.a(2);
712
726
  }
@@ -1771,6 +1785,22 @@ var Hydration = {
1771
1785
  ]
1772
1786
  }
1773
1787
  },
1788
+ {
1789
+ parents: 1,
1790
+ interior: {
1791
+ X2: [
1792
+ {
1793
+ Parachain: 2034
1794
+ },
1795
+ {
1796
+ AccountKey20: {
1797
+ network: null,
1798
+ key: "0x6b9ac524ec8f08c49ec80176b138d16eb461c3d8"
1799
+ }
1800
+ }
1801
+ ]
1802
+ }
1803
+ },
1774
1804
  {
1775
1805
  parents: 1,
1776
1806
  interior: {
@@ -6096,40 +6126,6 @@ var Acala = {
6096
6126
  }
6097
6127
  }
6098
6128
  ],
6099
- [
6100
- {
6101
- parents: 1,
6102
- interior: {
6103
- X2: [
6104
- {
6105
- Parachain: 2000
6106
- },
6107
- {
6108
- GeneralKey: {
6109
- length: 2,
6110
- data: "0x0000000000000000000000000000000000000000000000000000000000000000"
6111
- }
6112
- }
6113
- ]
6114
- }
6115
- },
6116
- {
6117
- parents: 1,
6118
- interior: {
6119
- X2: [
6120
- {
6121
- Parachain: 2032
6122
- },
6123
- {
6124
- GeneralKey: {
6125
- length: 2,
6126
- data: "0x0001000000000000000000000000000000000000000000000000000000000000"
6127
- }
6128
- }
6129
- ]
6130
- }
6131
- }
6132
- ],
6133
6129
  [
6134
6130
  {
6135
6131
  parents: 1,
@@ -6614,40 +6610,6 @@ var Acala = {
6614
6610
  }
6615
6611
  }
6616
6612
  ],
6617
- [
6618
- {
6619
- parents: 1,
6620
- interior: {
6621
- X3: [
6622
- {
6623
- Parachain: 1000
6624
- },
6625
- {
6626
- PalletInstance: 50
6627
- },
6628
- {
6629
- GeneralIndex: 22222012
6630
- }
6631
- ]
6632
- }
6633
- },
6634
- {
6635
- parents: 1,
6636
- interior: {
6637
- X2: [
6638
- {
6639
- Parachain: 2032
6640
- },
6641
- {
6642
- GeneralKey: {
6643
- length: 2,
6644
- data: "0x0001000000000000000000000000000000000000000000000000000000000000"
6645
- }
6646
- }
6647
- ]
6648
- }
6649
- }
6650
- ],
6651
6613
  [
6652
6614
  {
6653
6615
  parents: 1,
@@ -8450,46 +8412,51 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
8450
8412
  }]);
8451
8413
  }(ExchangeChain);
8452
8414
 
8453
- // NetworkId enum variants that polkadot.js `.toJSON()` lowercases when the
8454
- // variant carries no data (e.g. `Kusama` -> `kusama`). Struct/tuple variants
8455
- // like `Ethereum { chain_id }` keep their PascalCase.
8456
- var LOWERCASED_PLAIN_VARIANTS = new Set(['Polkadot', 'Kusama', 'Westend', 'Rococo', 'Wococo', 'BitcoinCore', 'BitcoinCash', 'PolkadotBulletin']);
8457
8415
  var isBinary = function isBinary(v) {
8458
8416
  return _typeof(v) === 'object' && v !== null && 'asHex' in v && typeof v.asHex === 'function';
8459
8417
  };
8460
8418
  var JUNCTIONS_VARIANT = /^X[1-8]$/;
8461
- // Recursively convert polkadot-api's `{ type, value }` enum encoding into the
8462
- // flat `{ VariantName: value }` shape used by stored asset locations (which
8463
- // originate from polkadot.js's `.toJSON()`).
8464
- //
8465
- // Reproduces three pjs `.toJSON()` quirks so output is byte-identical:
8466
- // - plain NetworkId variants lowercased (`Kusama` -> `kusama`)
8467
- // - struct field names snake_case -> camelCase (`chain_id` -> `chainId`)
8468
- // - `Binary` byte values rendered as `0x...` hex strings
8469
- var _papiLocationToJson = function papiLocationToJson(value) {
8470
- if (value === undefined) return null;
8419
+ var MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
8420
+ var _toJson = function toJson(value, depth) {
8421
+ if (value === undefined || value === null) return null;
8422
+ if (typeof value === 'bigint') return value <= MAX_SAFE ? Number(value) : '0x' + value.toString(16).padStart(32, '0');
8471
8423
  if (isBinary(value)) return value.asHex();
8472
- if (_typeof(value) !== 'object' || value === null) return value;
8473
- if (Array.isArray(value)) return value.map(_papiLocationToJson);
8424
+ if (value instanceof Uint8Array) return toHex(value);
8425
+ if (_typeof(value) !== 'object') return value;
8426
+ if (Array.isArray(value)) return value.map(function (v) {
8427
+ return _toJson(v, depth);
8428
+ });
8474
8429
  var obj = value;
8475
8430
  if (Object.keys(obj).length === 2 && typeof obj.type === 'string' && Object.prototype.hasOwnProperty.call(obj, 'value')) {
8476
- // v3 Junctions encode X1 as a single Junction (not an array). pjs
8477
- // normalizes X1..X8 to array form, so we do the same.
8478
- if (JUNCTIONS_VARIANT.test(obj.type) && !Array.isArray(obj.value)) {
8479
- return _defineProperty({}, obj.type, [_papiLocationToJson(obj.value)]);
8431
+ if (/^V\d+$/.test(obj.type)) return _toJson(obj.value, depth);
8432
+ var inner = _toJson(obj.value, depth + 1);
8433
+ if (obj.type === 'GeneralKey' && typeof inner === 'string') {
8434
+ return {
8435
+ GeneralKey: {
8436
+ length: (inner.length - 2) / 2,
8437
+ data: '0x' + inner.slice(2).padEnd(64, '0')
8438
+ }
8439
+ };
8480
8440
  }
8481
- var variant = obj.value === undefined && LOWERCASED_PLAIN_VARIANTS.has(obj.type) ? obj.type[0].toLowerCase() + obj.type.slice(1) : obj.type;
8482
- return _defineProperty({}, variant, _papiLocationToJson(obj.value));
8441
+ if (JUNCTIONS_VARIANT.test(obj.type)) {
8442
+ return _defineProperty({}, obj.type, Array.isArray(obj.value) ? inner : [inner]);
8443
+ }
8444
+ var isObjectPayload = obj.value !== null && _typeof(obj.value) === 'object';
8445
+ var key = depth <= 2 || isObjectPayload ? obj.type : lowercaseFirstLetter(obj.type);
8446
+ return _defineProperty({}, key, inner);
8483
8447
  }
8484
8448
  var out = {};
8485
8449
  for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
8486
8450
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
8487
8451
  k = _Object$entries$_i[0],
8488
8452
  v = _Object$entries$_i[1];
8489
- out[snakeToCamel(k)] = _papiLocationToJson(v);
8453
+ out[snakeToCamel(k)] = _toJson(v, depth + 1);
8490
8454
  }
8491
8455
  return out;
8492
8456
  };
8457
+ var papiLocationToJson = function papiLocationToJson(loc) {
8458
+ return loc === null || loc === undefined ? undefined : _toJson(loc, 0);
8459
+ };
8493
8460
 
8494
8461
  var getDexConfig$1 = /*#__PURE__*/function () {
8495
8462
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, chain) {
@@ -8508,8 +8475,8 @@ var getDexConfig$1 = /*#__PURE__*/function () {
8508
8475
  _ref2$keyArgs$ = _slicedToArray(_ref2$keyArgs[0], 2),
8509
8476
  ml1 = _ref2$keyArgs$[0],
8510
8477
  ml2 = _ref2$keyArgs$[1];
8511
- poolLocations.add(JSON.stringify(_papiLocationToJson(ml1), replaceBigIntNumeric));
8512
- poolLocations.add(JSON.stringify(_papiLocationToJson(ml2), replaceBigIntNumeric));
8478
+ poolLocations.add(JSON.stringify(papiLocationToJson(ml1), replaceBigIntNumeric));
8479
+ poolLocations.add(JSON.stringify(papiLocationToJson(ml2), replaceBigIntNumeric));
8513
8480
  });
8514
8481
  filteredAssets = assets.filter(function (asset) {
8515
8482
  return poolLocations.has(JSON.stringify(asset.location, replaceBigIntNumeric)) || poolLocations.has(JSON.stringify(localizeLocation('AssetHubPolkadot', asset.location), replaceBigIntNumeric));
@@ -9332,32 +9299,9 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
9332
9299
  }]);
9333
9300
  }(ExchangeChain);
9334
9301
 
9335
- var getAssetInfo = /*#__PURE__*/function () {
9336
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(assetClient, asset) {
9337
- var assets;
9338
- return _regenerator().w(function (_context) {
9339
- while (1) switch (_context.n) {
9340
- case 0:
9341
- _context.n = 1;
9342
- return assetClient.getSupported();
9343
- case 1:
9344
- assets = _context.v;
9345
- return _context.a(2, asset.assetId ? assets.find(function (a) {
9346
- return a.id.toString() === asset.assetId;
9347
- }) : assets.find(function (a) {
9348
- return a.symbol === asset.symbol;
9349
- }));
9350
- }
9351
- }, _callee);
9352
- }));
9353
- return function getAssetInfo(_x, _x2) {
9354
- return _ref.apply(this, arguments);
9355
- };
9356
- }();
9357
-
9358
9302
  var calculateFee = /*#__PURE__*/function () {
9359
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, tradeRouter, txBuilderFactory, assetClient, currencyFromInfo, currencyToInfo, currencyFromDecimals, chain, toDestTransactionFee) {
9360
- var amount, slippagePct, feeCalcAddress, sender, trade, nativeCurrencyInfo, nativeCurrencyDecimals, substrateTx, tx, _yield$tx$getPaymentI, swapFee, feeNative, currencyFromPriceInfo, currencyFromPrice, feeInCurrencyFrom, finalFee;
9303
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, tradeRouter, txBuilderFactory, currencyFromInfo, currencyToInfo, currencyFromDecimals, chain, toDestTransactionFee) {
9304
+ var amount, slippagePct, feeCalcAddress, sender, trade, nativeAsset, substrateTx, tx, _yield$tx$getPaymentI, swapFee, feeNative, currencyFromPriceInfo, currencyFromPrice, feeInCurrencyFrom, finalFee;
9361
9305
  return _regenerator().w(function (_context) {
9362
9306
  while (1) switch (_context.n) {
9363
9307
  case 0:
@@ -9366,58 +9310,40 @@ var calculateFee = /*#__PURE__*/function () {
9366
9310
  return tradeRouter.getBestSell(currencyFromInfo.id, currencyToInfo.id, amount.toString());
9367
9311
  case 1:
9368
9312
  trade = _context.v;
9313
+ nativeAsset = findNativeAssetInfoOrThrow(chain);
9369
9314
  _context.n = 2;
9370
- return getAssetInfo(assetClient, {
9371
- symbol: getNativeAssetSymbol(chain)
9372
- });
9373
- case 2:
9374
- nativeCurrencyInfo = _context.v;
9375
- if (!(nativeCurrencyInfo === undefined)) {
9376
- _context.n = 3;
9377
- break;
9378
- }
9379
- throw new UnableToComputeError('Native currency not found');
9380
- case 3:
9381
- nativeCurrencyDecimals = getAssetDecimals(chain, nativeCurrencyInfo.symbol);
9382
- if (!(nativeCurrencyDecimals === null)) {
9383
- _context.n = 4;
9384
- break;
9385
- }
9386
- throw new UnableToComputeError('Native currency decimals not found');
9387
- case 4:
9388
- _context.n = 5;
9389
9315
  return txBuilderFactory.trade(trade).withSlippage(Number(slippagePct)).withBeneficiary(sender).build();
9390
- case 5:
9316
+ case 2:
9391
9317
  substrateTx = _context.v;
9392
9318
  tx = substrateTx.get();
9393
- _context.n = 6;
9319
+ _context.n = 3;
9394
9320
  return tx.getPaymentInfo(feeCalcAddress);
9395
- case 6:
9321
+ case 3:
9396
9322
  _yield$tx$getPaymentI = _context.v;
9397
9323
  swapFee = _yield$tx$getPaymentI.partial_fee;
9398
9324
  feeNative = swapFee + toDestTransactionFee + toDestTransactionFee;
9399
- Logger.log('XCM to exch. fee:', toDestTransactionFee, nativeCurrencyInfo.symbol);
9400
- Logger.log('XCM to dest. fee:', toDestTransactionFee, nativeCurrencyInfo.symbol);
9401
- Logger.log('Swap fee:', swapFee, nativeCurrencyInfo.symbol);
9402
- Logger.log('Total fee:', feeNative, nativeCurrencyInfo.symbol);
9403
- if (!(currencyFromInfo.symbol === nativeCurrencyInfo.symbol)) {
9404
- _context.n = 7;
9325
+ Logger.log('XCM to exch. fee:', toDestTransactionFee, nativeAsset.symbol);
9326
+ Logger.log('XCM to dest. fee:', toDestTransactionFee, nativeAsset.symbol);
9327
+ Logger.log('Swap fee:', swapFee, nativeAsset.symbol);
9328
+ Logger.log('Total fee:', feeNative, nativeAsset.symbol);
9329
+ if (!(currencyFromInfo.symbol === nativeAsset.symbol)) {
9330
+ _context.n = 4;
9405
9331
  break;
9406
9332
  }
9407
9333
  return _context.a(2, feeNative);
9408
- case 7:
9409
- _context.n = 8;
9410
- return tradeRouter.getSpotPrice(currencyFromInfo.id, nativeCurrencyInfo.id);
9411
- case 8:
9334
+ case 4:
9335
+ _context.n = 5;
9336
+ return tradeRouter.getSpotPrice(currencyFromInfo.id, Number(nativeAsset.assetId));
9337
+ case 5:
9412
9338
  currencyFromPriceInfo = _context.v;
9413
9339
  if (!(currencyFromPriceInfo === undefined)) {
9414
- _context.n = 9;
9340
+ _context.n = 6;
9415
9341
  break;
9416
9342
  }
9417
9343
  throw new UnableToComputeError('Price not found');
9418
- case 9:
9344
+ case 6:
9419
9345
  currencyFromPrice = currencyFromPriceInfo.amount;
9420
- feeInCurrencyFrom = feeNative * pow10n(currencyFromPriceInfo.decimals + currencyFromDecimals) / (currencyFromPrice * pow10n(nativeCurrencyDecimals));
9346
+ feeInCurrencyFrom = feeNative * pow10n(currencyFromPriceInfo.decimals + currencyFromDecimals) / (currencyFromPrice * pow10n(nativeAsset.decimals));
9421
9347
  Logger.log('Total fee in currency from:', feeInCurrencyFrom, currencyFromInfo.symbol);
9422
9348
  finalFee = padValueBy(feeInCurrencyFrom, FEE_BUFFER_PCT);
9423
9349
  Logger.log("Total fee in currency from with buffer ".concat(FEE_BUFFER_PCT, "%:"), finalFee, currencyFromInfo.symbol);
@@ -9425,11 +9351,34 @@ var calculateFee = /*#__PURE__*/function () {
9425
9351
  }
9426
9352
  }, _callee);
9427
9353
  }));
9428
- return function calculateFee(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9) {
9354
+ return function calculateFee(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
9429
9355
  return _ref2.apply(this, arguments);
9430
9356
  };
9431
9357
  }();
9432
9358
 
9359
+ var getAssetInfo = /*#__PURE__*/function () {
9360
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(assetClient, asset) {
9361
+ var assets;
9362
+ return _regenerator().w(function (_context) {
9363
+ while (1) switch (_context.n) {
9364
+ case 0:
9365
+ _context.n = 1;
9366
+ return assetClient.getSupported();
9367
+ case 1:
9368
+ assets = _context.v;
9369
+ return _context.a(2, asset.assetId ? assets.find(function (a) {
9370
+ return a.id.toString() === asset.assetId;
9371
+ }) : assets.find(function (a) {
9372
+ return a.symbol === asset.symbol;
9373
+ }));
9374
+ }
9375
+ }, _callee);
9376
+ }));
9377
+ return function getAssetInfo(_x, _x2) {
9378
+ return _ref.apply(this, arguments);
9379
+ };
9380
+ }();
9381
+
9433
9382
  var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
9434
9383
  function HydrationExchange() {
9435
9384
  var _this;
@@ -9476,7 +9425,7 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
9476
9425
  throw new InvalidCurrencyError("Currency to doesn't exist");
9477
9426
  case 5:
9478
9427
  _context.n = 6;
9479
- return calculateFee(options, tradeRouter, txBuilderFactory, assetClient, currencyFromInfo, currencyToInfo, currencyFromInfo.decimals, this.chain, toDestTransactionFee);
9428
+ return calculateFee(options, tradeRouter, txBuilderFactory, currencyFromInfo, currencyToInfo, currencyFromInfo.decimals, this.chain, toDestTransactionFee);
9480
9429
  case 6:
9481
9430
  tradeFee = _context.v;
9482
9431
  amountWithoutFee = origin ? amount - tradeFee : amount;
@@ -9698,8 +9647,8 @@ var getExchangeAssets = function getExchangeAssets(exchange) {
9698
9647
 
9699
9648
  var getExchangeAsset = function getExchangeAsset(exchange, currency) {
9700
9649
  var throwOnDuplicateSymbol = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
9701
- if ('location' in currency && isOverrideLocationSpecifier(currency.location) || Array.isArray(currency)) {
9702
- throw new UnsupportedOperationError('XCM Router does not support location override or multi-asset currencies yet.');
9650
+ if (Array.isArray(currency)) {
9651
+ throw new UnsupportedOperationError('XCM Router does not support multi-asset currencies yet.');
9703
9652
  }
9704
9653
  var assets = getExchangeAssets(exchange);
9705
9654
  var nativeAssets = assets.filter(function (asset) {
@@ -9709,7 +9658,7 @@ var getExchangeAsset = function getExchangeAsset(exchange, currency) {
9709
9658
  return !asset.isNative;
9710
9659
  });
9711
9660
  var asset;
9712
- if ('location' in currency && !isOverrideLocationSpecifier(currency.location)) {
9661
+ if ('location' in currency) {
9713
9662
  asset = findAssetInfoByLoc(assets, currency.location);
9714
9663
  } else if ('symbol' in currency) {
9715
9664
  if (!isSymbolSpecifier(currency.symbol)) {
@@ -10029,7 +9978,9 @@ var selectBestExchangeCommon = /*#__PURE__*/function () {
10029
9978
  }
10030
9979
  return _context.a(3, 14);
10031
9980
  case 6:
10032
- if (!(destinationSpecified && !hasSupportForAsset(to, assetTo.symbol))) {
9981
+ if (!(destinationSpecified && !findAssetInfo(to, {
9982
+ location: assetTo.location
9983
+ }))) {
10033
9984
  _context.n = 7;
10034
9985
  break;
10035
9986
  }
@@ -10268,7 +10219,9 @@ var resolveAssets = function resolveAssets(dex, _ref) {
10268
10219
  if (!assetTo) {
10269
10220
  throw new RoutingResolutionError("Currency to ".concat(JSON.stringify(currencyTo), " not found in ").concat(dex.chain, "."));
10270
10221
  }
10271
- if (destinationSpecified && !hasSupportForAsset(to, assetTo.symbol)) {
10222
+ if (destinationSpecified && !findAssetInfo(to, {
10223
+ location: assetTo.location
10224
+ })) {
10272
10225
  throw new RoutingResolutionError("Currency to ".concat(JSON.stringify(currencyTo), " not supported by ").concat(to, "."));
10273
10226
  }
10274
10227
  var feeAssetFromOrigin = feeAsset && originSpecified ? (_findAssetInfo = findAssetInfo(from, feeAsset, dex.chain)) !== null && _findAssetInfo !== void 0 ? _findAssetInfo : undefined : undefined;
@@ -10537,11 +10490,11 @@ var canUseExecuteTransfer = function canUseExecuteTransfer(dex, options) {
10537
10490
  return Boolean(options.origin || options.destination) && (dex.chain.includes('AssetHub') || dex.chain === 'Hydration');
10538
10491
  };
10539
10492
  var isFilteredError = function isFilteredError(error) {
10540
- return error instanceof DryRunFailedError && error.dryRunType === 'origin' && error.reason === 'Filtered';
10493
+ return error instanceof DryRunFailedError && error.dryRunError.chainKind === 'origin' && error.dryRunError.reason === 'Filtered';
10541
10494
  };
10542
10495
  var getSwapExecuteXcmFee = /*#__PURE__*/function () {
10543
10496
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(dex, options, disableFallback) {
10544
- var _origin$chain, _destination$chain;
10497
+ var _origin$chain, _destination$chain, _result$dryRunError;
10545
10498
  var api, origin, exchange, currencyFrom, currencyTo, feeAsset, destination, amount, sender, recipient, evmSenderAddress, buildTx, amountOut, result;
10546
10499
  return _regenerator().w(function (_context3) {
10547
10500
  while (1) switch (_context3.n) {
@@ -10574,7 +10527,7 @@ var getSwapExecuteXcmFee = /*#__PURE__*/function () {
10574
10527
  });
10575
10528
  case 2:
10576
10529
  result = _context3.v;
10577
- if (!(result.failureReason === 'NoDeal' && exchange.chain === 'Hydration')) {
10530
+ if (!(((_result$dryRunError = result.dryRunError) === null || _result$dryRunError === void 0 ? void 0 : _result$dryRunError.reason) === 'NoDeal' && exchange.chain === 'Hydration')) {
10578
10531
  _context3.n = 3;
10579
10532
  break;
10580
10533
  }
@@ -11077,8 +11030,8 @@ var getSwapFee = /*#__PURE__*/function () {
11077
11030
 
11078
11031
  var getRouterFees = /*#__PURE__*/function () {
11079
11032
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dex, options, disableFallback) {
11080
- var _sendingChain$hops, _receivingChain$origi, _receivingChain$hops, _sendingChain$origin, _receivingChain$desti, _sendingChain$failure, _sendingChain$failure2;
11081
- var api, origin, exchange, destination, sender, _yield$getSwapExecute, result, transformedHops, sendingChain, _yield$getSwapFee, swapChain, amountOut, receivingChain, mergedHops, finalOrigin, finalDestination, _t, _t2, _t3;
11033
+ var _sendingChain$hops, _receivingChain$origi, _receivingChain$hops, _sendingChain$origin, _receivingChain$desti, _sendingChain$dryRunE;
11034
+ var api, origin, exchange, destination, sender, _yield$getSwapExecute, result, transformedHops, sendingChain, _yield$getSwapFee, swapChain, amountOut, receivingChain, mergedHops, finalOrigin, finalDestination, dryRunError, _t, _t2, _t3;
11082
11035
  return _regenerator().w(function (_context) {
11083
11036
  while (1) switch (_context.p = _context.n) {
11084
11037
  case 0:
@@ -11176,9 +11129,10 @@ var getRouterFees = /*#__PURE__*/function () {
11176
11129
  }), !origin && !destination && {
11177
11130
  fee: 0n
11178
11131
  });
11132
+ dryRunError = (_sendingChain$dryRunE = sendingChain === null || sendingChain === void 0 ? void 0 : sendingChain.dryRunError) !== null && _sendingChain$dryRunE !== void 0 ? _sendingChain$dryRunE : receivingChain === null || receivingChain === void 0 ? void 0 : receivingChain.dryRunError;
11179
11133
  return _context.a(2, {
11180
- failureReason: (_sendingChain$failure = sendingChain === null || sendingChain === void 0 ? void 0 : sendingChain.failureReason) !== null && _sendingChain$failure !== void 0 ? _sendingChain$failure : receivingChain === null || receivingChain === void 0 ? void 0 : receivingChain.failureReason,
11181
- failureChain: (_sendingChain$failure2 = sendingChain === null || sendingChain === void 0 ? void 0 : sendingChain.failureChain) !== null && _sendingChain$failure2 !== void 0 ? _sendingChain$failure2 : receivingChain === null || receivingChain === void 0 ? void 0 : receivingChain.failureChain,
11134
+ success: !dryRunError,
11135
+ dryRunError: dryRunError,
11182
11136
  origin: finalOrigin,
11183
11137
  destination: finalDestination,
11184
11138
  hops: mergedHops
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/swap",
3
- "version": "13.10.1",
3
+ "version": "14.0.0",
4
4
  "description": "Tool for XCM cross-chain asset exchanging across Polkadot and Kusama ecosystems",
5
5
  "type": "module",
6
6
  "exports": {
@@ -50,10 +50,10 @@
50
50
  "postcss": "^8.5.16",
51
51
  "react": "^19.2.7",
52
52
  "rxjs": "^7.8.2",
53
- "@paraspell/sdk": "13.10.1",
54
- "@paraspell/sdk-common": "13.10.1",
55
- "@paraspell/sdk-core": "13.10.1",
56
- "@paraspell/sdk-pjs": "13.10.1"
53
+ "@paraspell/sdk": "14.0.0",
54
+ "@paraspell/sdk-common": "14.0.0",
55
+ "@paraspell/sdk-core": "14.0.0",
56
+ "@paraspell/sdk-pjs": "14.0.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@babel/plugin-syntax-import-attributes": "^7.29.7",