@paraspell/swap 13.2.2 → 13.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { createChainClient as createChainClient$1, getBalance, transform, registerSwapExtension } from '@paraspell/sdk';
2
- import { getNativeAssets, RoutingResolutionError, findAssetInfoById, getOtherAssets, getChainProviders, parseUnits, getNativeAssetSymbol, padValueBy, formatUnits as formatUnits$1, AmountTooLowError, localizeLocation, getAssets, Parents, isSymbolMatch, getParaId, UnableToComputeError, getAssetDecimals, InvalidCurrencyError, findAssetInfoOrThrow, isOverrideLocationSpecifier, UnsupportedOperationError, isSymbolSpecifier, findBestMatches, findAssetInfoBySymbol, findAssetInfoByLoc, deepEqual, normalizeExchange, EXCHANGE_CHAINS, reverseTransformLocation, isAssetEqual, isExternalChain, isSystemAsset, TransferToAhNotSupported, ScenarioNotSupportedError, applyDecimalAbstraction, isConfig, findAssetInfo, getRelayChainOf, hasSupportForAsset, Builder, isChainEvm, convertBuilderConfig, InvalidAddressError, MissingParameterError, DryRunFailedError, handleSwapExecuteTransfer, BatchMode, dryRun, getFailureInfo, getOriginXcmFee, getXcmFee, createChainClient as createChainClient$2, getExistentialDepositOrThrow, getBalance as getBalance$1 } from '@paraspell/sdk-core';
3
- import { toHex } from 'polkadot-api/utils';
1
+ import { createChainClient as createChainClient$1, registerSwapExtension } from '@paraspell/sdk';
2
+ import { getNativeAssets, RoutingResolutionError, findAssetInfoById, getOtherAssets, getChainProviders, parseUnits, getNativeAssetSymbol, padValueBy, formatUnits as formatUnits$1, AmountTooLowError, getBalance, localizeLocation, getAssets, Parents, isSymbolMatch, getParaId, UnableToComputeError, getAssetDecimals, InvalidCurrencyError, findAssetInfoOrThrow, isOverrideLocationSpecifier, UnsupportedOperationError, isSymbolSpecifier, findBestMatches, findAssetInfoBySymbol, findAssetInfoByLoc, deepEqual, normalizeExchange, EXCHANGE_CHAINS, reverseTransformLocation, isAssetEqual, isExternalChain, isSystemAsset, TransferToAhNotSupported, ScenarioNotSupportedError, applyDecimalAbstraction, isConfig, findAssetInfo, getRelayChainOf, hasSupportForAsset, Builder, isChainEvm, convertBuilderConfig, InvalidAddressError, MissingParameterError, DryRunFailedError, handleSwapExecuteTransfer, BatchMode, dryRun, getFailureInfo, getOriginXcmFee, getXcmFee, createChainClient as createChainClient$2, getExistentialDepositOrThrow } from '@paraspell/sdk-core';
4
3
  import 'polkadot-api';
5
4
  import { Wallet } from '@acala-network/sdk';
6
5
  import { FixedPointNumber } from '@acala-network/sdk-core';
@@ -405,7 +404,7 @@ var stripHeaderBytes = function stripHeaderBytes(hex, byteCount) {
405
404
  };
406
405
  var convertTxToTarget = /*#__PURE__*/function () {
407
406
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(tx, api) {
408
- var isPjsTx, hex, hex2, hex3, _t, _t2;
407
+ var isPjsTx, hex, hex2, hex3, _t;
409
408
  return _regenerator().w(function (_context) {
410
409
  while (1) switch (_context.p = _context.n) {
411
410
  case 0:
@@ -418,11 +417,10 @@ var convertTxToTarget = /*#__PURE__*/function () {
418
417
  _context.n = 3;
419
418
  break;
420
419
  case 1:
421
- _t2 = toHex;
422
420
  _context.n = 2;
423
- return tx.getEncodedData();
421
+ return api.txToHex(tx);
424
422
  case 2:
425
- _t = _t2(_context.v);
423
+ _t = _context.v;
426
424
  case 3:
427
425
  hex = _t;
428
426
  if (!(isPjsTx && api.type === 'PAPI')) {
@@ -1745,6 +1743,54 @@ var Hydration = {
1745
1743
  ]
1746
1744
  }
1747
1745
  },
1746
+ {
1747
+ parents: 1,
1748
+ interior: {
1749
+ X2: [
1750
+ {
1751
+ Parachain: 2034
1752
+ },
1753
+ {
1754
+ AccountKey20: {
1755
+ network: null,
1756
+ key: "0xca30f9ff99394c55deda293df223e3740635c72e"
1757
+ }
1758
+ }
1759
+ ]
1760
+ }
1761
+ },
1762
+ {
1763
+ parents: 1,
1764
+ interior: {
1765
+ X2: [
1766
+ {
1767
+ Parachain: 2034
1768
+ },
1769
+ {
1770
+ AccountKey20: {
1771
+ network: null,
1772
+ key: "0x49f925bf72718f4abbc57adef1b705931f928a2a"
1773
+ }
1774
+ }
1775
+ ]
1776
+ }
1777
+ },
1778
+ {
1779
+ parents: 1,
1780
+ interior: {
1781
+ X2: [
1782
+ {
1783
+ Parachain: 2034
1784
+ },
1785
+ {
1786
+ AccountKey20: {
1787
+ network: null,
1788
+ key: "0x987ddc8b236fb23e1e48882b206396ca9b42648b"
1789
+ }
1790
+ }
1791
+ ]
1792
+ }
1793
+ },
1748
1794
  {
1749
1795
  parents: 1,
1750
1796
  interior: {
@@ -7205,13 +7251,13 @@ var ExchangeChain = /*#__PURE__*/function () {
7205
7251
  }, {
7206
7252
  key: "handleMultiSwap",
7207
7253
  value: function () {
7208
- var _handleMultiSwap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, options, toDestTransactionFee) {
7254
+ var _handleMultiSwap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, toDestTransactionFee) {
7209
7255
  var singleSwapResult;
7210
7256
  return _regenerator().w(function (_context) {
7211
7257
  while (1) switch (_context.n) {
7212
7258
  case 0:
7213
7259
  _context.n = 1;
7214
- return this.swapCurrency(api, options, toDestTransactionFee);
7260
+ return this.swapCurrency(options, toDestTransactionFee);
7215
7261
  case 1:
7216
7262
  singleSwapResult = _context.v;
7217
7263
  return _context.a(2, {
@@ -7221,7 +7267,7 @@ var ExchangeChain = /*#__PURE__*/function () {
7221
7267
  }
7222
7268
  }, _callee, this);
7223
7269
  }));
7224
- function handleMultiSwap(_x, _x2, _x3) {
7270
+ function handleMultiSwap(_x, _x2) {
7225
7271
  return _handleMultiSwap.apply(this, arguments);
7226
7272
  }
7227
7273
  return handleMultiSwap;
@@ -7237,7 +7283,7 @@ var ExchangeChain = /*#__PURE__*/function () {
7237
7283
  }
7238
7284
  }, _callee2, this);
7239
7285
  }));
7240
- function createApiInstance(_x4) {
7286
+ function createApiInstance(_x3) {
7241
7287
  return _createApiInstance.apply(this, arguments);
7242
7288
  }
7243
7289
  return createApiInstance;
@@ -7253,7 +7299,7 @@ var ExchangeChain = /*#__PURE__*/function () {
7253
7299
  }
7254
7300
  }, _callee3, this);
7255
7301
  }));
7256
- function createApiInstancePapi(_x5) {
7302
+ function createApiInstancePapi(_x4) {
7257
7303
  return _createApiInstancePapi.apply(this, arguments);
7258
7304
  }
7259
7305
  return createApiInstancePapi;
@@ -7456,24 +7502,24 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7456
7502
  return _createClass(AcalaExchange, [{
7457
7503
  key: "swapCurrency",
7458
7504
  value: function () {
7459
- var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, options, toDestTransactionFee) {
7460
- var papiApi, assetFrom, assetTo, amount, sender, origin, isForFeeEstimation, wallet, fromToken, toToken, acalaDex, dex, swapFee, totalNativeCurrencyFee, balance, pctDestFee, amountWithoutFee, tradeResult, tx, amountOutRes, amountOut, nativeAssetSymbol, amountOutWithFee;
7505
+ var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, toDestTransactionFee) {
7506
+ var api, apiPjs, assetFrom, assetTo, amount, sender, origin, isForFeeEstimation, wallet, fromToken, toToken, acalaDex, dex, swapFee, totalNativeCurrencyFee, balance, pctDestFee, amountWithoutFee, tradeResult, tx, amountOutRes, amountOut, nativeAssetSymbol, amountOutWithFee;
7461
7507
  return _regenerator().w(function (_context) {
7462
7508
  while (1) switch (_context.n) {
7463
7509
  case 0:
7464
- papiApi = options.papiApi, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, origin = options.origin, isForFeeEstimation = options.isForFeeEstimation;
7465
- wallet = new Wallet(api);
7510
+ api = options.api, apiPjs = options.apiPjs, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, origin = options.origin, isForFeeEstimation = options.isForFeeEstimation;
7511
+ wallet = new Wallet(apiPjs);
7466
7512
  _context.n = 1;
7467
7513
  return wallet.isReady;
7468
7514
  case 1:
7469
7515
  fromToken = wallet.getToken(assetFrom.symbol);
7470
7516
  toToken = wallet.getToken(assetTo.symbol);
7471
7517
  acalaDex = new AcalaDex({
7472
- api: api,
7518
+ api: apiPjs,
7473
7519
  wallet: wallet
7474
7520
  });
7475
7521
  dex = new AggregateDex({
7476
- api: api,
7522
+ api: apiPjs,
7477
7523
  wallet: wallet,
7478
7524
  providers: [acalaDex]
7479
7525
  });
@@ -7485,7 +7531,7 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7485
7531
  Logger.log('Total fee native:', totalNativeCurrencyFee);
7486
7532
  _context.n = 3;
7487
7533
  return getBalance({
7488
- api: papiApi,
7534
+ api: api,
7489
7535
  address: sender,
7490
7536
  chain: this.chain
7491
7537
  });
@@ -7542,7 +7588,7 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7542
7588
  }
7543
7589
  }, _callee, this);
7544
7590
  }));
7545
- function swapCurrency(_x, _x2, _x3) {
7591
+ function swapCurrency(_x, _x2) {
7546
7592
  return _swapCurrency.apply(this, arguments);
7547
7593
  }
7548
7594
  return swapCurrency;
@@ -7550,24 +7596,24 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7550
7596
  }, {
7551
7597
  key: "getAmountOut",
7552
7598
  value: function () {
7553
- var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, options) {
7554
- var assetFrom, assetTo, amount, origin, wallet, fromToken, toToken, acalaDex, dex, pctDestFee, amountWithoutFee, tradeResult, amountOutRes;
7599
+ var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
7600
+ var apiPjs, assetFrom, assetTo, amount, origin, wallet, fromToken, toToken, acalaDex, dex, pctDestFee, amountWithoutFee, tradeResult, amountOutRes;
7555
7601
  return _regenerator().w(function (_context2) {
7556
7602
  while (1) switch (_context2.n) {
7557
7603
  case 0:
7558
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin;
7559
- wallet = new Wallet(api);
7604
+ apiPjs = options.apiPjs, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin;
7605
+ wallet = new Wallet(apiPjs);
7560
7606
  _context2.n = 1;
7561
7607
  return wallet.isReady;
7562
7608
  case 1:
7563
7609
  fromToken = wallet.getToken(assetFrom.symbol);
7564
7610
  toToken = wallet.getToken(assetTo.symbol);
7565
7611
  acalaDex = new AcalaDex({
7566
- api: api,
7612
+ api: apiPjs,
7567
7613
  wallet: wallet
7568
7614
  });
7569
7615
  dex = new AggregateDex({
7570
- api: api,
7616
+ api: apiPjs,
7571
7617
  wallet: wallet,
7572
7618
  providers: [acalaDex]
7573
7619
  });
@@ -7587,7 +7633,7 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7587
7633
  }
7588
7634
  }, _callee2);
7589
7635
  }));
7590
- function getAmountOut(_x4, _x5) {
7636
+ function getAmountOut(_x3) {
7591
7637
  return _getAmountOut.apply(this, arguments);
7592
7638
  }
7593
7639
  return getAmountOut;
@@ -7619,7 +7665,7 @@ var AcalaExchange = /*#__PURE__*/function (_ExchangeChain) {
7619
7665
  }
7620
7666
  }, _callee4, this);
7621
7667
  }));
7622
- function getDexConfig(_x6) {
7668
+ function getDexConfig(_x4) {
7623
7669
  return _getDexConfig2.apply(this, arguments);
7624
7670
  }
7625
7671
  return getDexConfig;
@@ -7728,54 +7774,6 @@ var getDexConfig$1 = /*#__PURE__*/function () {
7728
7774
  };
7729
7775
  }();
7730
7776
 
7731
- var getQuotedAmount = /*#__PURE__*/function () {
7732
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, chain, assetFromML, assetToML, amountIn) {
7733
- var includeFee,
7734
- localizedFrom,
7735
- localizedTo,
7736
- quoted,
7737
- _args = arguments,
7738
- _t;
7739
- return _regenerator().w(function (_context) {
7740
- while (1) switch (_context.p = _context.n) {
7741
- case 0:
7742
- includeFee = _args.length > 5 && _args[5] !== undefined ? _args[5] : true;
7743
- _context.p = 1;
7744
- localizedFrom = localizeLocation(chain, assetFromML);
7745
- localizedTo = localizeLocation(chain, assetToML);
7746
- _context.n = 2;
7747
- return api.getUnsafeApi().apis.AssetConversionApi.quote_price_exact_tokens_for_tokens(transform(localizedFrom), transform(localizedTo), amountIn, includeFee);
7748
- case 2:
7749
- quoted = _context.v;
7750
- if (!(quoted !== undefined)) {
7751
- _context.n = 3;
7752
- break;
7753
- }
7754
- return _context.a(2, {
7755
- amountOut: BigInt(quoted.toString()),
7756
- usedFromML: localizedFrom,
7757
- usedToML: localizedTo
7758
- });
7759
- case 3:
7760
- _context.n = 5;
7761
- break;
7762
- case 4:
7763
- _context.p = 4;
7764
- _t = _context.v;
7765
- // eslint-disable-next-line no-console
7766
- console.error('Error (localized):', _t);
7767
- case 5:
7768
- throw new RoutingResolutionError('Swap failed: Pool not found');
7769
- case 6:
7770
- return _context.a(2);
7771
- }
7772
- }, _callee, null, [[1, 4]]);
7773
- }));
7774
- return function getQuotedAmount(_x, _x2, _x3, _x4, _x5) {
7775
- return _ref.apply(this, arguments);
7776
- };
7777
- }();
7778
-
7779
7777
  var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7780
7778
  function AssetHubExchange() {
7781
7779
  _classCallCheck(this, AssetHubExchange);
@@ -7783,68 +7781,115 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7783
7781
  }
7784
7782
  _inherits(AssetHubExchange, _ExchangeChain);
7785
7783
  return _createClass(AssetHubExchange, [{
7786
- key: "swapCurrency",
7784
+ key: "quoteOrThrow",
7787
7785
  value: function () {
7788
- var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_api, options, toDestTxFee) {
7789
- var assetFrom, assetTo, amount, sender, slippagePct, origin, papiApi, pctDestFee, amountWithoutFee, _yield$getQuotedAmoun, amountOut, usedFromML, usedToML, slippageMultiplier, minAmountOut, tx, toDestFeeCurrencyTo, finalAmountOut, _t;
7786
+ var _quoteOrThrow = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, fromLocation, toLocation, amount) {
7787
+ var includeFee,
7788
+ quoted,
7789
+ cause,
7790
+ message,
7791
+ _args = arguments,
7792
+ _t;
7790
7793
  return _regenerator().w(function (_context) {
7791
- while (1) switch (_context.n) {
7794
+ while (1) switch (_context.p = _context.n) {
7795
+ case 0:
7796
+ includeFee = _args.length > 4 && _args[4] !== undefined ? _args[4] : true;
7797
+ _context.p = 1;
7798
+ _context.n = 2;
7799
+ return api.queryRuntimeApi({
7800
+ module: 'AssetConversionApi',
7801
+ method: 'quote_price_exact_tokens_for_tokens',
7802
+ params: [fromLocation, toLocation, amount, includeFee]
7803
+ });
7804
+ case 2:
7805
+ quoted = _context.v;
7806
+ _context.n = 4;
7807
+ break;
7808
+ case 3:
7809
+ _context.p = 3;
7810
+ _t = _context.v;
7811
+ cause = _t;
7812
+ case 4:
7813
+ if (!(quoted == null)) {
7814
+ _context.n = 5;
7815
+ break;
7816
+ }
7817
+ message = cause instanceof Error ? " (".concat(cause.message, ")") : '';
7818
+ throw new RoutingResolutionError("Swap failed: Pool not found".concat(message));
7819
+ case 5:
7820
+ return _context.a(2, BigInt(quoted));
7821
+ }
7822
+ }, _callee, null, [[1, 3]]);
7823
+ }));
7824
+ function quoteOrThrow(_x, _x2, _x3, _x4) {
7825
+ return _quoteOrThrow.apply(this, arguments);
7826
+ }
7827
+ return quoteOrThrow;
7828
+ }()
7829
+ }, {
7830
+ key: "swapCurrency",
7831
+ value: function () {
7832
+ var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, toDestTxFee) {
7833
+ var api, assetFrom, assetTo, amount, sender, slippagePct, origin, localizedFrom, localizedTo, pctDestFee, amountWithoutFee, amountOut, slippageMultiplier, minAmountOut, tx, toDestFeeCurrencyTo, finalAmountOut, _t2;
7834
+ return _regenerator().w(function (_context2) {
7835
+ while (1) switch (_context2.n) {
7792
7836
  case 0:
7793
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, slippagePct = options.slippagePct, origin = options.origin, papiApi = options.papiApi;
7837
+ api = options.api, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, slippagePct = options.slippagePct, origin = options.origin;
7838
+ localizedFrom = localizeLocation(this.chain, assetFrom.location);
7839
+ localizedTo = localizeLocation(this.chain, assetTo.location);
7794
7840
  pctDestFee = origin ? DEST_FEE_BUFFER_PCT : 0;
7795
7841
  amountWithoutFee = padValueBy(amount, pctDestFee);
7796
- _context.n = 1;
7797
- return getQuotedAmount(papiApi, this.chain, assetFrom.location, assetTo.location, amountWithoutFee);
7842
+ _context2.n = 1;
7843
+ return this.quoteOrThrow(api, localizedFrom, localizedTo, amountWithoutFee);
7798
7844
  case 1:
7799
- _yield$getQuotedAmoun = _context.v;
7800
- amountOut = _yield$getQuotedAmoun.amountOut;
7801
- usedFromML = _yield$getQuotedAmoun.usedFromML;
7802
- usedToML = _yield$getQuotedAmoun.usedToML;
7845
+ amountOut = _context2.v;
7803
7846
  slippageMultiplier = Number(slippagePct);
7804
7847
  minAmountOut = padValueBy(amountOut, -slippageMultiplier);
7805
- tx = papiApi.getUnsafeApi().tx.AssetConversion.swap_exact_tokens_for_tokens({
7806
- path: [transform(usedFromML), transform(usedToML)],
7807
- amount_in: amountWithoutFee,
7808
- amount_out_min: minAmountOut,
7809
- send_to: sender,
7810
- keep_alive: !!assetFrom.isNative
7848
+ tx = api.deserializeExtrinsics({
7849
+ module: 'AssetConversion',
7850
+ method: 'swap_exact_tokens_for_tokens',
7851
+ params: {
7852
+ path: [localizedFrom, localizedTo],
7853
+ amount_in: amountWithoutFee,
7854
+ amount_out_min: minAmountOut,
7855
+ send_to: sender,
7856
+ keep_alive: !!assetFrom.isNative
7857
+ }
7811
7858
  });
7812
7859
  if (!(assetTo.symbol == getNativeAssetSymbol(this.chain))) {
7813
- _context.n = 2;
7860
+ _context2.n = 2;
7814
7861
  break;
7815
7862
  }
7816
- _t = toDestTxFee;
7817
- _context.n = 4;
7863
+ _t2 = toDestTxFee;
7864
+ _context2.n = 4;
7818
7865
  break;
7819
7866
  case 2:
7820
- _context.n = 3;
7821
- return getQuotedAmount(papiApi, this.chain, {
7867
+ _context2.n = 3;
7868
+ return this.quoteOrThrow(api, {
7822
7869
  parents: Parents.ONE,
7823
7870
  interior: {
7824
7871
  Here: null
7825
7872
  }
7826
- }, assetTo.location, toDestTxFee, true).then(function (res) {
7827
- return res.amountOut;
7828
- });
7873
+ }, localizedTo, toDestTxFee, true);
7829
7874
  case 3:
7830
- _t = _context.v;
7875
+ _t2 = _context2.v;
7831
7876
  case 4:
7832
- toDestFeeCurrencyTo = _t;
7877
+ toDestFeeCurrencyTo = _t2;
7833
7878
  finalAmountOut = amountOut - padValueBy(toDestFeeCurrencyTo, FEE_BUFFER_PCT);
7834
7879
  if (!(finalAmountOut <= 0n)) {
7835
- _context.n = 5;
7880
+ _context2.n = 5;
7836
7881
  break;
7837
7882
  }
7838
7883
  throw new AmountTooLowError();
7839
7884
  case 5:
7840
- return _context.a(2, {
7885
+ return _context2.a(2, {
7841
7886
  tx: tx,
7842
7887
  amountOut: finalAmountOut
7843
7888
  });
7844
7889
  }
7845
- }, _callee, this);
7890
+ }, _callee2, this);
7846
7891
  }));
7847
- function swapCurrency(_x, _x2, _x3) {
7892
+ function swapCurrency(_x5, _x6) {
7848
7893
  return _swapCurrency.apply(this, arguments);
7849
7894
  }
7850
7895
  return swapCurrency;
@@ -7852,17 +7897,17 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7852
7897
  }, {
7853
7898
  key: "handleMultiSwap",
7854
7899
  value: function () {
7855
- var _handleMultiSwap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, options, toDestTransactionFee) {
7900
+ var _handleMultiSwap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options, toDestTransactionFee) {
7856
7901
  var assetFrom, assetTo, nativeAsset, isAssetFromNative, isAssetToNative, singleSwapResult, optionsHop1, resultHop1, hop1Received, assumedInputForHop2, optionsHop2, resultHop2;
7857
- return _regenerator().w(function (_context2) {
7858
- while (1) switch (_context2.n) {
7902
+ return _regenerator().w(function (_context3) {
7903
+ while (1) switch (_context3.n) {
7859
7904
  case 0:
7860
7905
  assetFrom = options.assetFrom, assetTo = options.assetTo;
7861
7906
  nativeAsset = getExchangeAsset(this.chain, {
7862
7907
  symbol: getNativeAssetSymbol(this.chain)
7863
7908
  });
7864
7909
  if (nativeAsset) {
7865
- _context2.n = 1;
7910
+ _context3.n = 1;
7866
7911
  break;
7867
7912
  }
7868
7913
  throw new RoutingResolutionError('Native asset not found for this exchange chain.');
@@ -7870,20 +7915,20 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7870
7915
  isAssetFromNative = assetFrom.symbol === nativeAsset.symbol;
7871
7916
  isAssetToNative = assetTo.symbol === nativeAsset.symbol;
7872
7917
  if (!(isAssetFromNative && isAssetToNative)) {
7873
- _context2.n = 2;
7918
+ _context3.n = 2;
7874
7919
  break;
7875
7920
  }
7876
7921
  throw new RoutingResolutionError('Cannot swap native asset to itself.');
7877
7922
  case 2:
7878
7923
  if (!(isAssetFromNative || isAssetToNative)) {
7879
- _context2.n = 4;
7924
+ _context3.n = 4;
7880
7925
  break;
7881
7926
  }
7882
- _context2.n = 3;
7883
- return this.swapCurrency(api, _objectSpread2({}, options), toDestTransactionFee);
7927
+ _context3.n = 3;
7928
+ return this.swapCurrency(options, toDestTransactionFee);
7884
7929
  case 3:
7885
- singleSwapResult = _context2.v;
7886
- return _context2.a(2, {
7930
+ singleSwapResult = _context3.v;
7931
+ return _context3.a(2, {
7887
7932
  txs: [singleSwapResult.tx],
7888
7933
  amountOut: singleSwapResult.amountOut
7889
7934
  });
@@ -7892,12 +7937,12 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7892
7937
  optionsHop1 = _objectSpread2(_objectSpread2({}, options), {}, {
7893
7938
  assetTo: nativeAsset
7894
7939
  });
7895
- _context2.n = 5;
7896
- return this.swapCurrency(api, optionsHop1, 0n);
7940
+ _context3.n = 5;
7941
+ return this.swapCurrency(optionsHop1, 0n);
7897
7942
  case 5:
7898
- resultHop1 = _context2.v;
7943
+ resultHop1 = _context3.v;
7899
7944
  if (!(resultHop1.amountOut <= 0n)) {
7900
- _context2.n = 6;
7945
+ _context3.n = 6;
7901
7946
  break;
7902
7947
  }
7903
7948
  throw new AmountTooLowError("First hop (".concat(assetFrom.symbol, " -> ").concat(nativeAsset.symbol, ") resulted in zero or negative output."));
@@ -7905,7 +7950,8 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7905
7950
  hop1Received = resultHop1.amountOut;
7906
7951
  assumedInputForHop2 = padValueBy(hop1Received, -2);
7907
7952
  optionsHop2 = {
7908
- papiApi: options.papiApi,
7953
+ apiPjs: options.apiPjs,
7954
+ api: options.api,
7909
7955
  slippagePct: options.slippagePct,
7910
7956
  sender: options.sender,
7911
7957
  origin: undefined,
@@ -7914,26 +7960,26 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7914
7960
  amount: assumedInputForHop2,
7915
7961
  feeCalcAddress: options.feeCalcAddress
7916
7962
  };
7917
- _context2.n = 7;
7918
- return this.swapCurrency(api, optionsHop2, toDestTransactionFee);
7963
+ _context3.n = 7;
7964
+ return this.swapCurrency(optionsHop2, toDestTransactionFee);
7919
7965
  case 7:
7920
- resultHop2 = _context2.v;
7966
+ resultHop2 = _context3.v;
7921
7967
  if (!(resultHop2.amountOut <= 0n)) {
7922
- _context2.n = 8;
7968
+ _context3.n = 8;
7923
7969
  break;
7924
7970
  }
7925
7971
  throw new AmountTooLowError("Second hop (".concat(nativeAsset.symbol, " -> ").concat(assetTo.symbol, ") resulted in zero or negative output."));
7926
7972
  case 8:
7927
- return _context2.a(2, {
7973
+ return _context3.a(2, {
7928
7974
  txs: [resultHop1.tx, resultHop2.tx],
7929
7975
  amountOut: resultHop2.amountOut
7930
7976
  });
7931
7977
  case 9:
7932
- return _context2.a(2);
7978
+ return _context3.a(2);
7933
7979
  }
7934
- }, _callee2, this);
7980
+ }, _callee3, this);
7935
7981
  }));
7936
- function handleMultiSwap(_x4, _x5, _x6) {
7982
+ function handleMultiSwap(_x7, _x8) {
7937
7983
  return _handleMultiSwap.apply(this, arguments);
7938
7984
  }
7939
7985
  return handleMultiSwap;
@@ -7941,17 +7987,17 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7941
7987
  }, {
7942
7988
  key: "getAmountOut",
7943
7989
  value: function () {
7944
- var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_api, options) {
7945
- var assetFrom, assetTo, amount, origin, papiApi, nativeAsset, isAssetFromNative, isAssetToNative, pctDestFee, amountWithoutFee, _yield$getQuotedAmoun2, amountOut, _yield$getQuotedAmoun3, hop1AmountOut, assumedInputForHop2, _yield$getQuotedAmoun4, finalAmountOut;
7946
- return _regenerator().w(function (_context3) {
7947
- while (1) switch (_context3.n) {
7990
+ var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(options) {
7991
+ var api, assetFrom, assetTo, amount, origin, nativeAsset, isAssetFromNative, isAssetToNative, pctDestFee, amountWithoutFee, hop1AmountOut, assumedInputForHop2, finalAmountOut;
7992
+ return _regenerator().w(function (_context4) {
7993
+ while (1) switch (_context4.n) {
7948
7994
  case 0:
7949
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin, papiApi = options.papiApi;
7995
+ api = options.api, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin;
7950
7996
  nativeAsset = getExchangeAsset(this.chain, {
7951
7997
  symbol: getNativeAssetSymbol(this.chain)
7952
7998
  });
7953
7999
  if (nativeAsset) {
7954
- _context3.n = 1;
8000
+ _context4.n = 1;
7955
8001
  break;
7956
8002
  }
7957
8003
  throw new RoutingResolutionError('Native asset not found for this exchange chain.');
@@ -7959,7 +8005,7 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7959
8005
  isAssetFromNative = assetFrom.symbol === nativeAsset.symbol;
7960
8006
  isAssetToNative = assetTo.symbol === nativeAsset.symbol;
7961
8007
  if (!(isAssetFromNative && isAssetToNative)) {
7962
- _context3.n = 2;
8008
+ _context4.n = 2;
7963
8009
  break;
7964
8010
  }
7965
8011
  throw new RoutingResolutionError('Cannot swap native asset to itself.');
@@ -7967,46 +8013,39 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
7967
8013
  pctDestFee = origin ? DEST_FEE_BUFFER_PCT : 0;
7968
8014
  amountWithoutFee = padValueBy(amount, pctDestFee);
7969
8015
  if (!(isAssetFromNative || isAssetToNative)) {
7970
- _context3.n = 4;
8016
+ _context4.n = 3;
7971
8017
  break;
7972
8018
  }
7973
- _context3.n = 3;
7974
- return getQuotedAmount(papiApi, this.chain, assetFrom.location, assetTo.location, amountWithoutFee);
8019
+ return _context4.a(2, this.quoteOrThrow(api, localizeLocation(this.chain, assetFrom.location), localizeLocation(this.chain, assetTo.location), amountWithoutFee));
7975
8020
  case 3:
7976
- _yield$getQuotedAmoun2 = _context3.v;
7977
- amountOut = _yield$getQuotedAmoun2.amountOut;
7978
- return _context3.a(2, amountOut);
8021
+ _context4.n = 4;
8022
+ return this.quoteOrThrow(api, localizeLocation(this.chain, assetFrom.location), localizeLocation(this.chain, nativeAsset.location), amountWithoutFee);
7979
8023
  case 4:
7980
- _context3.n = 5;
7981
- return getQuotedAmount(papiApi, this.chain, assetFrom.location, nativeAsset.location, amountWithoutFee);
7982
- case 5:
7983
- _yield$getQuotedAmoun3 = _context3.v;
7984
- hop1AmountOut = _yield$getQuotedAmoun3.amountOut;
8024
+ hop1AmountOut = _context4.v;
7985
8025
  if (!(hop1AmountOut <= 0n)) {
7986
- _context3.n = 6;
8026
+ _context4.n = 5;
7987
8027
  break;
7988
8028
  }
7989
8029
  throw new AmountTooLowError("First hop (".concat(assetFrom.symbol, " -> ").concat(nativeAsset.symbol, ") resulted in zero or negative output."));
7990
- case 6:
8030
+ case 5:
7991
8031
  assumedInputForHop2 = padValueBy(hop1AmountOut, -2);
7992
- _context3.n = 7;
7993
- return getQuotedAmount(papiApi, this.chain, nativeAsset.location, assetTo.location, assumedInputForHop2);
7994
- case 7:
7995
- _yield$getQuotedAmoun4 = _context3.v;
7996
- finalAmountOut = _yield$getQuotedAmoun4.amountOut;
8032
+ _context4.n = 6;
8033
+ return this.quoteOrThrow(api, localizeLocation(this.chain, nativeAsset.location), localizeLocation(this.chain, assetTo.location), assumedInputForHop2);
8034
+ case 6:
8035
+ finalAmountOut = _context4.v;
7997
8036
  if (!(finalAmountOut <= 0n)) {
7998
- _context3.n = 8;
8037
+ _context4.n = 7;
7999
8038
  break;
8000
8039
  }
8001
8040
  throw new AmountTooLowError("Second hop (".concat(nativeAsset.symbol, " -> ").concat(assetTo.symbol, ") resulted in zero or negative output."));
8041
+ case 7:
8042
+ return _context4.a(2, finalAmountOut);
8002
8043
  case 8:
8003
- return _context3.a(2, finalAmountOut);
8004
- case 9:
8005
- return _context3.a(2);
8044
+ return _context4.a(2);
8006
8045
  }
8007
- }, _callee3, this);
8046
+ }, _callee4, this);
8008
8047
  }));
8009
- function getAmountOut(_x7, _x8) {
8048
+ function getAmountOut(_x9) {
8010
8049
  return _getAmountOut.apply(this, arguments);
8011
8050
  }
8012
8051
  return getAmountOut;
@@ -8014,15 +8053,15 @@ var AssetHubExchange = /*#__PURE__*/function (_ExchangeChain) {
8014
8053
  }, {
8015
8054
  key: "getDexConfig",
8016
8055
  value: function () {
8017
- var _getDexConfig2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(api) {
8018
- return _regenerator().w(function (_context4) {
8019
- while (1) switch (_context4.n) {
8056
+ var _getDexConfig2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(api) {
8057
+ return _regenerator().w(function (_context5) {
8058
+ while (1) switch (_context5.n) {
8020
8059
  case 0:
8021
- return _context4.a(2, getDexConfig$1(api, this.chain));
8060
+ return _context5.a(2, getDexConfig$1(api, this.chain));
8022
8061
  }
8023
- }, _callee4, this);
8062
+ }, _callee5, this);
8024
8063
  }));
8025
- function getDexConfig(_x9) {
8064
+ function getDexConfig(_x0) {
8026
8065
  return _getDexConfig2.apply(this, arguments);
8027
8066
  }
8028
8067
  return getDexConfig;
@@ -8376,12 +8415,12 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8376
8415
  return _createClass(BifrostExchange, [{
8377
8416
  key: "swapCurrency",
8378
8417
  value: function () {
8379
- var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, options, toDestTxFee) {
8380
- var assetFrom, assetTo, amount, sender, slippagePct, origin, chainId, tokenMap, tokenWrappedFrom, tokenWrappedTo, tokenFrom, tokenTo, currencyCombinations, pairs, pctDestFee, amountWithoutFee, amountInFinal, trade, allowedSlippage, blockNumber, deadline, _SwapRouter$swapCallP, extrinsic, amountOut, nativeSymbol, amountOutWithFee;
8418
+ var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, toDestTxFee) {
8419
+ var apiPjs, assetFrom, assetTo, amount, sender, slippagePct, origin, chainId, tokenMap, tokenWrappedFrom, tokenWrappedTo, tokenFrom, tokenTo, currencyCombinations, pairs, pctDestFee, amountWithoutFee, amountInFinal, trade, allowedSlippage, blockNumber, deadline, _SwapRouter$swapCallP, extrinsic, amountOut, nativeSymbol, amountOutWithFee;
8381
8420
  return _regenerator().w(function (_context) {
8382
8421
  while (1) switch (_context.n) {
8383
8422
  case 0:
8384
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, slippagePct = options.slippagePct, origin = options.origin;
8423
+ apiPjs = options.apiPjs, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, sender = options.sender, slippagePct = options.slippagePct, origin = options.origin;
8385
8424
  chainId = getParaId(this.chain);
8386
8425
  tokenMap = getTokenMap(this.chain, chainId);
8387
8426
  tokenWrappedFrom = findToken(tokenMap, assetFrom.symbol);
@@ -8402,7 +8441,7 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8402
8441
  tokenTo = new Token(tokenWrappedTo.wrapped);
8403
8442
  currencyCombinations = getCurrencyCombinations(chainId, tokenFrom, tokenTo);
8404
8443
  _context.n = 3;
8405
- return getFilteredPairs(api, chainId, currencyCombinations);
8444
+ return getFilteredPairs(apiPjs, chainId, currencyCombinations);
8406
8445
  case 3:
8407
8446
  pairs = _context.v;
8408
8447
  Logger.log('To dest tx fee in native currency:', toDestTxFee);
@@ -8420,12 +8459,12 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8420
8459
  trade = getBestTrade(chainId, pairs, amountInFinal, tokenTo);
8421
8460
  allowedSlippage = new Percent(Number(slippagePct) * 100, 10000);
8422
8461
  _context.n = 5;
8423
- return api.derive.chain.bestNumber();
8462
+ return apiPjs.derive.chain.bestNumber();
8424
8463
  case 5:
8425
8464
  blockNumber = _context.v;
8426
8465
  deadline = blockNumber.toNumber() + 20;
8427
8466
  _SwapRouter$swapCallP = SwapRouter.swapCallParameters(trade, {
8428
- api: api,
8467
+ api: apiPjs,
8429
8468
  allowedSlippage: allowedSlippage,
8430
8469
  recipient: sender,
8431
8470
  deadline: deadline
@@ -8463,7 +8502,7 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8463
8502
  }
8464
8503
  }, _callee, this);
8465
8504
  }));
8466
- function swapCurrency(_x, _x2, _x3) {
8505
+ function swapCurrency(_x, _x2) {
8467
8506
  return _swapCurrency.apply(this, arguments);
8468
8507
  }
8469
8508
  return swapCurrency;
@@ -8471,12 +8510,12 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8471
8510
  }, {
8472
8511
  key: "getAmountOut",
8473
8512
  value: function () {
8474
- var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, options) {
8475
- var assetFrom, assetTo, amount, origin, chainId, tokenMap, tokenWrappedFrom, tokenWrappedTo, tokenFrom, tokenTo, currencyCombinations, pairs, pctDestFee, amountWithoutFee, amountIn, trade;
8513
+ var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
8514
+ var apiPjs, assetFrom, assetTo, amount, origin, chainId, tokenMap, tokenWrappedFrom, tokenWrappedTo, tokenFrom, tokenTo, currencyCombinations, pairs, pctDestFee, amountWithoutFee, amountIn, trade;
8476
8515
  return _regenerator().w(function (_context2) {
8477
8516
  while (1) switch (_context2.n) {
8478
8517
  case 0:
8479
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin;
8518
+ apiPjs = options.apiPjs, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin;
8480
8519
  chainId = getParaId(this.chain);
8481
8520
  tokenMap = getTokenMap(this.chain, chainId);
8482
8521
  tokenWrappedFrom = findToken(tokenMap, assetFrom.symbol);
@@ -8497,7 +8536,7 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8497
8536
  tokenTo = new Token(tokenWrappedTo.wrapped);
8498
8537
  currencyCombinations = getCurrencyCombinations(chainId, tokenFrom, tokenTo);
8499
8538
  _context2.n = 3;
8500
- return getFilteredPairs(api, chainId, currencyCombinations);
8539
+ return getFilteredPairs(apiPjs, chainId, currencyCombinations);
8501
8540
  case 3:
8502
8541
  pairs = _context2.v;
8503
8542
  pctDestFee = origin ? DEST_FEE_BUFFER_PCT : 0;
@@ -8508,7 +8547,7 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8508
8547
  }
8509
8548
  }, _callee2, this);
8510
8549
  }));
8511
- function getAmountOut(_x4, _x5) {
8550
+ function getAmountOut(_x3) {
8512
8551
  return _getAmountOut.apply(this, arguments);
8513
8552
  }
8514
8553
  return getAmountOut;
@@ -8524,7 +8563,7 @@ var BifrostExchange = /*#__PURE__*/function (_ExchangeChain) {
8524
8563
  }
8525
8564
  }, _callee3, this);
8526
8565
  }));
8527
- function getDexConfig$1(_x6) {
8566
+ function getDexConfig$1(_x4) {
8528
8567
  return _getDexConfig2.apply(this, arguments);
8529
8568
  }
8530
8569
  return getDexConfig$1;
@@ -8638,13 +8677,13 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
8638
8677
  return _createClass(HydrationExchange, [{
8639
8678
  key: "swapCurrency",
8640
8679
  value: function () {
8641
- var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, options, toDestTransactionFee) {
8642
- var origin, assetFrom, assetTo, sender, slippagePct, amount, _createSdkContext, tradeRouter, txBuilderFactory, currencyFromInfo, currencyToInfo, tradeFee, amountWithoutFee, amountNormalized, trade, substrateTx, tx, amountOut, nativeCurrencyInfo, nativeCurrencyDecimals, priceInfo, currencyToPrice, feeInCurrencyTo, amountOutModified;
8680
+ var _swapCurrency = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, toDestTransactionFee) {
8681
+ var apiPjs, origin, assetFrom, assetTo, sender, slippagePct, amount, _createSdkContext, tradeRouter, txBuilderFactory, currencyFromInfo, currencyToInfo, tradeFee, amountWithoutFee, amountNormalized, trade, substrateTx, tx, amountOut, nativeCurrencyInfo, nativeCurrencyDecimals, priceInfo, currencyToPrice, feeInCurrencyTo, amountOutModified;
8643
8682
  return _regenerator().w(function (_context) {
8644
8683
  while (1) switch (_context.n) {
8645
8684
  case 0:
8646
- origin = options.origin, assetFrom = options.assetFrom, assetTo = options.assetTo, sender = options.sender, slippagePct = options.slippagePct, amount = options.amount;
8647
- _createSdkContext = createSdkContext(api), tradeRouter = _createSdkContext.api.router, txBuilderFactory = _createSdkContext.tx;
8685
+ apiPjs = options.apiPjs, origin = options.origin, assetFrom = options.assetFrom, assetTo = options.assetTo, sender = options.sender, slippagePct = options.slippagePct, amount = options.amount;
8686
+ _createSdkContext = createSdkContext(apiPjs), tradeRouter = _createSdkContext.api.router, txBuilderFactory = _createSdkContext.tx;
8648
8687
  _context.n = 1;
8649
8688
  return getAssetInfo(tradeRouter, assetFrom);
8650
8689
  case 1:
@@ -8743,7 +8782,7 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
8743
8782
  }
8744
8783
  }, _callee, this);
8745
8784
  }));
8746
- function swapCurrency(_x, _x2, _x3) {
8785
+ function swapCurrency(_x, _x2) {
8747
8786
  return _swapCurrency.apply(this, arguments);
8748
8787
  }
8749
8788
  return swapCurrency;
@@ -8751,13 +8790,13 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
8751
8790
  }, {
8752
8791
  key: "getAmountOut",
8753
8792
  value: function () {
8754
- var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, options) {
8755
- var assetFrom, assetTo, amount, origin, _options$slippagePct, slippagePct, _createSdkContext2, tradeRouter, currencyFromInfo, currencyToInfo, pctDestFee, amountWithoutFee, amountNormalized, trade, amountOut, slippageMultiplier;
8793
+ var _getAmountOut = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
8794
+ var apiPjs, assetFrom, assetTo, amount, origin, _options$slippagePct, slippagePct, _createSdkContext2, tradeRouter, currencyFromInfo, currencyToInfo, pctDestFee, amountWithoutFee, amountNormalized, trade, amountOut, slippageMultiplier;
8756
8795
  return _regenerator().w(function (_context2) {
8757
8796
  while (1) switch (_context2.n) {
8758
8797
  case 0:
8759
- assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin, _options$slippagePct = options.slippagePct, slippagePct = _options$slippagePct === void 0 ? '0' : _options$slippagePct;
8760
- _createSdkContext2 = createSdkContext(api), tradeRouter = _createSdkContext2.api.router;
8798
+ apiPjs = options.apiPjs, assetFrom = options.assetFrom, assetTo = options.assetTo, amount = options.amount, origin = options.origin, _options$slippagePct = options.slippagePct, slippagePct = _options$slippagePct === void 0 ? '0' : _options$slippagePct;
8799
+ _createSdkContext2 = createSdkContext(apiPjs), tradeRouter = _createSdkContext2.api.router;
8761
8800
  _context2.n = 1;
8762
8801
  return getAssetInfo(tradeRouter, assetFrom);
8763
8802
  case 1:
@@ -8791,7 +8830,7 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
8791
8830
  }
8792
8831
  }, _callee2);
8793
8832
  }));
8794
- function getAmountOut(_x4, _x5) {
8833
+ function getAmountOut(_x3) {
8795
8834
  return _getAmountOut.apply(this, arguments);
8796
8835
  }
8797
8836
  return getAmountOut;
@@ -8834,7 +8873,7 @@ var HydrationExchange = /*#__PURE__*/function (_ExchangeChain) {
8834
8873
  }
8835
8874
  }, _callee3, this);
8836
8875
  }));
8837
- function getDexConfig(_x6) {
8876
+ function getDexConfig(_x4) {
8838
8877
  return _getDexConfig.apply(this, arguments);
8839
8878
  }
8840
8879
  return getDexConfig;
@@ -9339,8 +9378,9 @@ var selectBestExchange = /*#__PURE__*/function () {
9339
9378
  case 4:
9340
9379
  toDestTxFee = _context.v;
9341
9380
  _context.n = 5;
9342
- return dex.handleMultiSwap(modifiedOptions.exchange.apiPjs, _objectSpread2(_objectSpread2({}, modifiedOptions), {}, {
9343
- papiApi: modifiedOptions.exchange.apiPapi,
9381
+ return dex.handleMultiSwap(_objectSpread2(_objectSpread2({}, modifiedOptions), {}, {
9382
+ api: modifiedOptions.exchange.api,
9383
+ apiPjs: modifiedOptions.exchange.apiPjs,
9344
9384
  assetFrom: modifiedOptions.exchange.assetFrom,
9345
9385
  assetTo: modifiedOptions.exchange.assetTo,
9346
9386
  isForFeeEstimation: isForFeeEstimation
@@ -9709,8 +9749,9 @@ var createSwapTx = /*#__PURE__*/function () {
9709
9749
  case 1:
9710
9750
  toDestTxFee = _context2.v;
9711
9751
  _context2.n = 2;
9712
- return exchange.handleMultiSwap(options.exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
9713
- papiApi: options.exchange.apiPapi,
9752
+ return exchange.handleMultiSwap(_objectSpread2(_objectSpread2({}, options), {}, {
9753
+ api: options.exchange.api,
9754
+ apiPjs: options.exchange.apiPjs,
9714
9755
  assetFrom: options.exchange.assetFrom,
9715
9756
  assetTo: options.exchange.assetTo,
9716
9757
  isForFeeEstimation: isForFeeEstimation
@@ -9748,8 +9789,9 @@ var prepareExtrinsics = /*#__PURE__*/function () {
9748
9789
  }
9749
9790
  _context.p = 1;
9750
9791
  _context.n = 2;
9751
- return dex.getAmountOut(exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
9752
- papiApi: exchange.apiPapi,
9792
+ return dex.getAmountOut(_objectSpread2(_objectSpread2({}, options), {}, {
9793
+ api: exchange.api,
9794
+ apiPjs: exchange.apiPjs,
9753
9795
  assetFrom: exchange.assetFrom,
9754
9796
  assetTo: exchange.assetTo
9755
9797
  }));
@@ -9772,9 +9814,10 @@ var prepareExtrinsics = /*#__PURE__*/function () {
9772
9814
  currencyTo: currencyTo,
9773
9815
  feeAssetInfo: (_origin$feeAssetInfo = origin === null || origin === void 0 ? void 0 : origin.feeAssetInfo) !== null && _origin$feeAssetInfo !== void 0 ? _origin$feeAssetInfo : exchange.feeAssetInfo,
9774
9816
  calculateMinAmountOut: function calculateMinAmountOut(amountIn, assetTo) {
9775
- return dex.getAmountOut(exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
9817
+ return dex.getAmountOut(_objectSpread2(_objectSpread2({}, options), {}, {
9776
9818
  amount: amountIn,
9777
- papiApi: options.exchange.apiPapi,
9819
+ api: options.exchange.api,
9820
+ apiPjs: options.exchange.apiPjs,
9778
9821
  assetFrom: options.exchange.assetFrom,
9779
9822
  assetTo: assetTo !== null && assetTo !== void 0 ? assetTo : options.exchange.assetTo
9780
9823
  }));
@@ -10177,9 +10220,10 @@ var getRouterFees = /*#__PURE__*/function () {
10177
10220
  case 0:
10178
10221
  amt = overrideAmount !== undefined ? applyDecimalAbstraction(overrideAmount, exchange.assetFrom.decimals, true) : amount;
10179
10222
  _context.n = 1;
10180
- return dex.getAmountOut(exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
10223
+ return dex.getAmountOut(_objectSpread2(_objectSpread2({}, options), {}, {
10181
10224
  amount: amt,
10182
- papiApi: exchange.apiPapi,
10225
+ api: exchange.api,
10226
+ apiPjs: exchange.apiPjs,
10183
10227
  assetFrom: exchange.assetFrom,
10184
10228
  assetTo: exchange.assetTo
10185
10229
  }));
@@ -10202,9 +10246,10 @@ var getRouterFees = /*#__PURE__*/function () {
10202
10246
  sender: evmSenderAddress !== null && evmSenderAddress !== void 0 ? evmSenderAddress : sender,
10203
10247
  recipient: recipient !== null && recipient !== void 0 ? recipient : sender,
10204
10248
  calculateMinAmountOut: function calculateMinAmountOut(amountIn, assetTo) {
10205
- return dex.getAmountOut(exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
10249
+ return dex.getAmountOut(_objectSpread2(_objectSpread2({}, options), {}, {
10206
10250
  amount: amountIn,
10207
- papiApi: options.exchange.apiPapi,
10251
+ apiPjs: options.exchange.apiPjs,
10252
+ api: options.exchange.api,
10208
10253
  assetFrom: options.exchange.assetFrom,
10209
10254
  assetTo: assetTo !== null && assetTo !== void 0 ? assetTo : options.exchange.assetTo,
10210
10255
  slippagePct: '1'
@@ -10222,9 +10267,10 @@ var getRouterFees = /*#__PURE__*/function () {
10222
10267
  };
10223
10268
  }();
10224
10269
  _context2.n = 2;
10225
- return dex.getAmountOut(exchange.apiPjs, _objectSpread2(_objectSpread2({}, options), {}, {
10270
+ return dex.getAmountOut(_objectSpread2(_objectSpread2({}, options), {}, {
10226
10271
  amount: amount,
10227
- papiApi: exchange.apiPapi,
10272
+ api: exchange.api,
10273
+ apiPjs: exchange.apiPjs,
10228
10274
  assetFrom: exchange.assetFrom,
10229
10275
  assetTo: exchange.assetTo
10230
10276
  }));
@@ -10387,20 +10433,21 @@ var selectBestExchangeAmountOut = /*#__PURE__*/function () {
10387
10433
  case 0:
10388
10434
  return _context2.a(2, selectBestExchangeCommon(options, originApi, /*#__PURE__*/function () {
10389
10435
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dex, assetFromExchange, assetTo, _options, parsedAmount) {
10390
- var pjsApi, papiApi;
10436
+ var exchangeApi, exchangePjsApi;
10391
10437
  return _regenerator().w(function (_context) {
10392
10438
  while (1) switch (_context.n) {
10393
10439
  case 0:
10394
10440
  _context.n = 1;
10395
- return dex.createApiInstance();
10441
+ return options.api.createApiForChain(dex.chain);
10396
10442
  case 1:
10397
- pjsApi = _context.v;
10443
+ exchangeApi = _context.v;
10398
10444
  _context.n = 2;
10399
- return dex.createApiInstancePapi();
10445
+ return dex.createApiInstance();
10400
10446
  case 2:
10401
- papiApi = _context.v;
10402
- return _context.a(2, dex.getAmountOut(pjsApi, {
10403
- papiApi: papiApi,
10447
+ exchangePjsApi = _context.v;
10448
+ return _context.a(2, dex.getAmountOut({
10449
+ api: exchangeApi,
10450
+ apiPjs: exchangePjsApi,
10404
10451
  assetFrom: assetFromExchange,
10405
10452
  assetTo: assetTo,
10406
10453
  amount: BigInt(parsedAmount)
@@ -10423,7 +10470,7 @@ var selectBestExchangeAmountOut = /*#__PURE__*/function () {
10423
10470
  var getBestAmountOut = /*#__PURE__*/function () {
10424
10471
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
10425
10472
  var _assetFromOrigin$deci;
10426
- var api, exchange, amount, from, originApi, isExchangeAutoSelect, dex, _resolveAssets, assetFromOrigin, assetFrom, assetTo, res, config, exchangeConfig, pjsApi, papiApi, _t, _t2, _t3, _t4;
10473
+ var api, exchange, amount, from, originApi, isExchangeAutoSelect, dex, _resolveAssets, assetFromOrigin, assetFrom, assetTo, res, config, exchangeConfig, pjsApi, exchangeApi, _t, _t2, _t3, _t4;
10427
10474
  return _regenerator().w(function (_context) {
10428
10475
  while (1) switch (_context.n) {
10429
10476
  case 0:
@@ -10479,13 +10526,14 @@ var getBestAmountOut = /*#__PURE__*/function () {
10479
10526
  case 9:
10480
10527
  pjsApi = _context.v;
10481
10528
  _context.n = 10;
10482
- return dex.createApiInstancePapi(exchangeConfig);
10529
+ return api.createApiForChain(dex.chain);
10483
10530
  case 10:
10484
- papiApi = _context.v;
10531
+ exchangeApi = _context.v;
10485
10532
  _t3 = dex.chain;
10486
10533
  _context.n = 11;
10487
- return dex.getAmountOut(pjsApi, {
10488
- papiApi: papiApi,
10534
+ return dex.getAmountOut({
10535
+ api: exchangeApi,
10536
+ apiPjs: pjsApi,
10489
10537
  assetFrom: assetFrom,
10490
10538
  assetTo: assetTo,
10491
10539
  amount: applyDecimalAbstraction(amount, (_assetFromOrigin$deci = assetFromOrigin === null || assetFromOrigin === void 0 ? void 0 : assetFromOrigin.decimals) !== null && _assetFromOrigin$deci !== void 0 ? _assetFromOrigin$deci : assetFrom.decimals, (exchangeConfig === null || exchangeConfig === void 0 ? void 0 : exchangeConfig.abstractDecimals) !== false)
@@ -10585,7 +10633,7 @@ var computeLocalTransferableAmount = /*#__PURE__*/function () {
10585
10633
  location: exchange.assetFrom.location
10586
10634
  };
10587
10635
  _context.n = 1;
10588
- return getBalance$1({
10636
+ return getBalance({
10589
10637
  api: exchange.api,
10590
10638
  chain: exchange.chain,
10591
10639
  address: sender,
@@ -10782,202 +10830,113 @@ var transfer = /*#__PURE__*/function () {
10782
10830
  };
10783
10831
  }();
10784
10832
 
10785
- var RouterBuilderCore = /*#__PURE__*/function () {
10786
- function RouterBuilderCore(api, options) {
10787
- _classCallCheck(this, RouterBuilderCore);
10833
+ var SwapBuilderCore = /*#__PURE__*/function () {
10834
+ function SwapBuilderCore(api, options) {
10835
+ _classCallCheck(this, SwapBuilderCore);
10788
10836
  this._api = api;
10789
10837
  this._options = options !== null && options !== void 0 ? options : {};
10790
10838
  }
10791
- /**
10792
- * Specifies the origin chain of the transfer.
10793
- *
10794
- * @param chain - The origin chain.
10795
- * @returns The current builder instance.
10796
- */
10797
- return _createClass(RouterBuilderCore, [{
10839
+ return _createClass(SwapBuilderCore, [{
10798
10840
  key: "from",
10799
10841
  value: function from(chain) {
10800
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10842
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10801
10843
  from: chain
10802
10844
  }));
10803
10845
  }
10804
- /**
10805
- * Specifies the exchange chain to use.
10806
- *
10807
- * @param chain - The exchange chain, or `undefined` to auto-select.
10808
- * @returns The current builder instance.
10809
- */
10810
10846
  }, {
10811
10847
  key: "exchange",
10812
10848
  value: function exchange(chain) {
10813
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10849
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10814
10850
  exchange: normalizeExchange(chain)
10815
10851
  }));
10816
10852
  }
10817
- /**
10818
- * Specifies the destination chain of the transfer.
10819
- *
10820
- * @param chain - The destination chain.
10821
- * @returns The current builder instance.
10822
- */
10823
10853
  }, {
10824
10854
  key: "to",
10825
10855
  value: function to(chain) {
10826
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10856
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10827
10857
  to: chain
10828
10858
  }));
10829
10859
  }
10830
- /**
10831
- * Specifies the currency to send from the origin chain.
10832
- *
10833
- * @param currencyFrom - The currency to send.
10834
- * @returns The current builder instance.
10835
- */
10836
10860
  }, {
10837
10861
  key: "currencyFrom",
10838
10862
  value: function currencyFrom(currency) {
10839
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10863
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10840
10864
  currencyFrom: currency
10841
10865
  }));
10842
10866
  }
10843
- /**
10844
- * Specifies the currency that the origin currency will be exchanged to and received on the destination chain.
10845
- *
10846
- * @param currencyTo - The currency to receive.
10847
- * @returns The current builder instance.
10848
- */
10849
10867
  }, {
10850
10868
  key: "currencyTo",
10851
10869
  value: function currencyTo(currency) {
10852
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10870
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10853
10871
  currencyTo: currency
10854
10872
  }));
10855
10873
  }
10856
- /**
10857
- * Specifies the asset used to pay XCM fees.
10858
- *
10859
- * @param currency - The fee asset currency, or `undefined` to use the default.
10860
- * @returns The current builder instance.
10861
- */
10862
10874
  }, {
10863
10875
  key: "feeAsset",
10864
10876
  value: function feeAsset(currency) {
10865
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10877
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10866
10878
  feeAsset: currency
10867
10879
  }));
10868
10880
  }
10869
- /**
10870
- * Specifies the amount to transfer.
10871
- *
10872
- * @param amount - The amount to transfer.
10873
- * @returns The current builder instance.
10874
- */
10875
10881
  }, {
10876
10882
  key: "amount",
10877
10883
  value: function amount(_amount) {
10878
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10884
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10879
10885
  amount: _amount.toString()
10880
10886
  }));
10881
10887
  }
10882
- /**
10883
- * Specifies the recipient address on the destination chain.
10884
- *
10885
- * @param recipient - The recipient address.
10886
- * @returns The current builder instance.
10887
- */
10888
10888
  }, {
10889
10889
  key: "recipient",
10890
10890
  value: function recipient(address) {
10891
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10891
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10892
10892
  recipient: address
10893
10893
  }));
10894
10894
  }
10895
- /**
10896
- * Specifies the sender address initiating the transfer.
10897
- *
10898
- * @param senderAddress - The sender address.
10899
- * @returns The current builder instance.
10900
- */
10901
10895
  }, {
10902
10896
  key: "sender",
10903
10897
  value: function sender(address) {
10904
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10898
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10905
10899
  sender: address
10906
10900
  }));
10907
10901
  }
10908
- /**
10909
- * Specifies the signer for the transaction.
10910
- *
10911
- * @param signer - The signer instance.
10912
- * @returns The current builder instance.
10913
- */
10914
10902
  }, {
10915
10903
  key: "signer",
10916
10904
  value: function signer(_signer) {
10917
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10905
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10918
10906
  signer: _signer
10919
10907
  }));
10920
10908
  }
10921
- /**
10922
- * Specifies the EVM sender address, required if `evmSigner` is provided. Used when dealing with EVM chains.
10923
- *
10924
- * @param evmSenderAddress - The EVM sender address.
10925
- * @returns The current builder instance.
10926
- */
10927
10909
  }, {
10928
10910
  key: "evmSenderAddress",
10929
10911
  value: function evmSenderAddress(address) {
10930
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10912
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10931
10913
  evmSenderAddress: address
10932
10914
  }));
10933
10915
  }
10934
- /**
10935
- * Specifies the EVM signer, required if `evmSenderAddress` is provided.
10936
- *
10937
- * @param evmSigner - The EVM signer.
10938
- * @returns The current builder instance.
10939
- */
10940
10916
  }, {
10941
10917
  key: "evmSigner",
10942
10918
  value: function evmSigner(signer) {
10943
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10919
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10944
10920
  evmSigner: signer
10945
10921
  }));
10946
10922
  }
10947
- /**
10948
- * Specifies the maximum slippage percentage for swaps.
10949
- *
10950
- * @param slippagePct - The slippage percentage.
10951
- * @returns The current builder instance.
10952
- */
10953
10923
  }, {
10954
10924
  key: "slippagePct",
10955
10925
  value: function slippagePct(pct) {
10956
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10926
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10957
10927
  slippagePct: pct
10958
10928
  }));
10959
10929
  }
10960
- /**
10961
- * Sets a callback to receive status updates during the transfer.
10962
- *
10963
- * @param callback - The status change callback.
10964
- * @returns The current builder instance.
10965
- */
10966
10930
  }, {
10967
10931
  key: "onStatusChange",
10968
10932
  value: function onStatusChange(callback) {
10969
- return new RouterBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10933
+ return new SwapBuilderCore(this._api, _objectSpread2(_objectSpread2({}, this._options), {}, {
10970
10934
  onStatusChange: callback
10971
10935
  }));
10972
10936
  }
10973
- /**
10974
- * Returns the XCM fee for origin, exchange, and destination.
10975
- *
10976
- * @returns The XCM fee result.
10977
- */
10978
10937
  }, {
10979
10938
  key: "getXcmFees",
10980
- value: (function () {
10939
+ value: function () {
10981
10940
  var _getXcmFees2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
10982
10941
  var _options$disableFallb;
10983
10942
  var disableFallback;
@@ -10995,7 +10954,7 @@ var RouterBuilderCore = /*#__PURE__*/function () {
10995
10954
  return _getXcmFees2.apply(this, arguments);
10996
10955
  }
10997
10956
  return getXcmFees$1;
10998
- }())
10957
+ }()
10999
10958
  }, {
11000
10959
  key: "getTransferableAmount",
11001
10960
  value: function () {
@@ -11032,12 +10991,6 @@ var RouterBuilderCore = /*#__PURE__*/function () {
11032
10991
  }
11033
10992
  return getMinTransferableAmount$1;
11034
10993
  }()
11035
- /**
11036
- * Executes the transfer with the provided parameters.
11037
- *
11038
- * @returns An array of finalized transaction hashes (hex) in execution order.
11039
- * @throws Error if required parameters are missing.
11040
- */
11041
10994
  }, {
11042
10995
  key: "signAndSubmit",
11043
10996
  value: function signAndSubmit() {
@@ -11045,9 +10998,6 @@ var RouterBuilderCore = /*#__PURE__*/function () {
11045
10998
  api: this._api
11046
10999
  }));
11047
11000
  }
11048
- /**
11049
- * Builds the transactions for the transfer with the provided parameters.
11050
- */
11051
11001
  }, {
11052
11002
  key: "build",
11053
11003
  value: function build() {
@@ -11071,12 +11021,12 @@ var RouterBuilderCore = /*#__PURE__*/function () {
11071
11021
  }
11072
11022
  }]);
11073
11023
  }();
11074
- var RouterBuilder = function RouterBuilder(api) {
11075
- return new RouterBuilderCore(api);
11024
+ var SwapBuilder = function SwapBuilder(api) {
11025
+ return new SwapBuilderCore(api);
11076
11026
  };
11077
11027
 
11078
11028
  registerSwapExtension({
11079
- RouterBuilder: RouterBuilder
11029
+ SwapBuilder: SwapBuilder
11080
11030
  });
11081
11031
 
11082
- export { DEST_FEE_BUFFER_PCT, FALLBACK_FEE_CALC_ADDRESS, FALLBACK_FEE_CALC_EVM_ADDRESS, FEE_BUFFER_PCT, RouterBuilder, RouterBuilderCore, getExchangeAssets, getExchangeConfig, getExchangePairs, getSupportedAssetsFrom, getSupportedAssetsTo, getSupportedFeeAssets };
11032
+ export { DEST_FEE_BUFFER_PCT, FALLBACK_FEE_CALC_ADDRESS, FALLBACK_FEE_CALC_EVM_ADDRESS, FEE_BUFFER_PCT, SwapBuilder, SwapBuilderCore, getExchangeAssets, getExchangeConfig, getExchangePairs, getSupportedAssetsFrom, getSupportedAssetsTo, getSupportedFeeAssets };