@paraspell/sdk-core 13.7.1 → 13.7.2

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
@@ -3,7 +3,7 @@ import { isChainEvm, getAssetsObject, isChainEvmImpl, InvalidCurrencyError, isOv
3
3
  export * from '@paraspell/assets';
4
4
  import { base58 } from '@scure/base';
5
5
  import { isAddress, pad, toHex, getAddress, concat, keccak256, isHex, createPublicClient, http, getContract, formatUnits as formatUnits$1, parseUnits as parseUnits$1 } from 'viem';
6
- import { isTLocation, replaceBigInt, isExternalChain, Version, isRelayChain, Parents, isSubstrateBridge, isSnowbridge, isCustomChain, getJunctionValue, deepEqual, hasJunction, RELAYCHAINS, PARACHAINS, isTrustedChain, ETHEREUM_BRIDGE_ORIGINS, isBridge, DEFAULT_SS58_PREFIX, CHAINS } from '@paraspell/sdk-common';
6
+ import { isTLocation, replaceBigInt, isExternalChain, Version, isCustomChain, isRelayChain, Parents, isSubstrateBridge, isSnowbridge, getJunctionValue, deepEqual, hasJunction, RELAYCHAINS, PARACHAINS, isTrustedChain, ETHEREUM_BRIDGE_ORIGINS, isBridge, DEFAULT_SS58_PREFIX, CHAINS } from '@paraspell/sdk-common';
7
7
  export * from '@paraspell/sdk-common';
8
8
  import { getXcmPallet, getSupportedPallets, hasPalletImpl, getOtherAssetsPallets, getNativeAssetsPallet, getXcmPalletImpl, getSupportedPalletsDetails, ASSETS_PALLETS, NATIVE_ASSETS_PALLET_PRIORITY, OTHER_ASSETS_PALLET_PRIORITY } from '@paraspell/pallets';
9
9
  export * from '@paraspell/pallets';
@@ -1791,9 +1791,9 @@ var SystemPallet = /*#__PURE__*/function (_BaseAssetsPallet) {
1791
1791
  }, {
1792
1792
  key: "getBalance",
1793
1793
  value: function () {
1794
- var _getBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, address) {
1795
- var _balance$data;
1796
- var balance, value;
1794
+ var _getBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, address, asset) {
1795
+ var _asset$existentialDep;
1796
+ var account, free, reserved, frozen, ed, frozenUntouchable, untouchable, spendable;
1797
1797
  return _regenerator().w(function (_context2) {
1798
1798
  while (1) switch (_context2.n) {
1799
1799
  case 0:
@@ -1804,13 +1804,25 @@ var SystemPallet = /*#__PURE__*/function (_BaseAssetsPallet) {
1804
1804
  params: [address]
1805
1805
  });
1806
1806
  case 1:
1807
- balance = _context2.v;
1808
- value = balance === null || balance === void 0 || (_balance$data = balance.data) === null || _balance$data === void 0 ? void 0 : _balance$data.free;
1809
- return _context2.a(2, value !== undefined ? BigInt(value) : 0n);
1807
+ account = _context2.v;
1808
+ if (!((account === null || account === void 0 ? void 0 : account.data) === undefined)) {
1809
+ _context2.n = 2;
1810
+ break;
1811
+ }
1812
+ return _context2.a(2, 0n);
1813
+ case 2:
1814
+ free = BigInt(account.data.free);
1815
+ reserved = BigInt(account.data.reserved);
1816
+ frozen = BigInt(account.data.frozen);
1817
+ ed = BigInt((_asset$existentialDep = asset.existentialDeposit) !== null && _asset$existentialDep !== void 0 ? _asset$existentialDep : 0);
1818
+ frozenUntouchable = frozen - reserved;
1819
+ untouchable = frozenUntouchable > ed ? frozenUntouchable : ed;
1820
+ spendable = free - untouchable;
1821
+ return _context2.a(2, spendable > 0n ? spendable : 0n);
1810
1822
  }
1811
1823
  }, _callee2, this);
1812
1824
  }));
1813
- function getBalance(_x6, _x7) {
1825
+ function getBalance(_x6, _x7, _x8) {
1814
1826
  return _getBalance.apply(this, arguments);
1815
1827
  }
1816
1828
  return getBalance;
@@ -1819,7 +1831,7 @@ var SystemPallet = /*#__PURE__*/function (_BaseAssetsPallet) {
1819
1831
  }(BaseAssetsPallet);
1820
1832
 
1821
1833
  var resolveId = function resolveId(api, asset, chain) {
1822
- if (chain === 'BifrostPolkadot' || chain === 'BifrostKusama' || chain === 'BifrostPaseo') {
1834
+ if (!isCustomChain(chain) && (chain === 'BifrostPolkadot' || chain === 'BifrostKusama' || chain === 'BifrostPaseo')) {
1823
1835
  var _asset$assetId;
1824
1836
  var isEthAsset = !asset.isNative && ((_asset$assetId = asset.assetId) === null || _asset$assetId === void 0 ? void 0 : _asset$assetId.startsWith('0x'));
1825
1837
  var resolvedAsset = isEthAsset ? api.findAssetInfoOrThrow(chain, {
@@ -2120,7 +2132,7 @@ var createDestination = function createDestination(api, version, origin, destina
2120
2132
  parents: Parents.TWO,
2121
2133
  interior: {
2122
2134
  X2: [{
2123
- GlobalConsensus: getRelayChainOf(destination)
2135
+ GlobalConsensus: getRelayChainOfImpl(api, destination)
2124
2136
  }, {
2125
2137
  Parachain: chainId
2126
2138
  }]
@@ -3485,13 +3497,13 @@ var getParaId = function getParaId(chain) {
3485
3497
  return getParaIdImpl(chain);
3486
3498
  };
3487
3499
 
3488
- var getChainLocation = function getChainLocation(chain, destChain) {
3500
+ var getChainLocation = function getChainLocation(chain, destChain, customCtx) {
3489
3501
  var fromRelay = isRelayChain(chain);
3490
3502
  var toRelay = isRelayChain(destChain);
3491
3503
  var parents = fromRelay ? Parents.ZERO : Parents.ONE;
3492
3504
  var interior = toRelay ? 'Here' : {
3493
3505
  X1: [{
3494
- Parachain: getParaId(destChain)
3506
+ Parachain: getParaIdImpl(destChain, customCtx)
3495
3507
  }]
3496
3508
  };
3497
3509
  return {
@@ -3668,7 +3680,6 @@ var Chain = /*#__PURE__*/function () {
3668
3680
  get: function get() {
3669
3681
  return this._ecosystem;
3670
3682
  }
3671
- // TODO: Fix this type cast in a subsequent refactor
3672
3683
  }, {
3673
3684
  key: "chain",
3674
3685
  get: function get() {
@@ -6570,12 +6581,12 @@ var isSufficientDestination = /*#__PURE__*/function () {
6570
6581
  };
6571
6582
  }();
6572
6583
 
6573
- var createOriginLocation = function createOriginLocation(origin, destination, version) {
6584
+ var createOriginLocation = function createOriginLocation(origin, destination, version, customCtx) {
6574
6585
  if (isRelayChain(origin)) return DOT_LOCATION;
6575
6586
  return {
6576
6587
  parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
6577
6588
  interior: createX1Payload(version, {
6578
- Parachain: getParaId(origin)
6589
+ Parachain: getParaIdImpl(origin, customCtx)
6579
6590
  })
6580
6591
  };
6581
6592
  };
@@ -7509,7 +7520,7 @@ var traverseXcmHops = /*#__PURE__*/function () {
7509
7520
  _context.n = 10;
7510
7521
  break;
7511
7522
  }
7512
- nextChain = getTChain(nextParaId, getRelayChainOf(origin));
7523
+ nextChain = getTChain(nextParaId, getRelayChainOfImpl(api, origin));
7513
7524
  if (nextChain) {
7514
7525
  _context.n = 2;
7515
7526
  break;
@@ -7714,7 +7725,7 @@ var dryRunInternal = /*#__PURE__*/function () {
7714
7725
  case 1:
7715
7726
  _context.n = 2;
7716
7727
  return hopApi.getDryRunXcm({
7717
- originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain, resolvedVersion), resolvedVersion),
7728
+ originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain, resolvedVersion, api._customCtx), resolvedVersion),
7718
7729
  tx: tx,
7719
7730
  xcm: forwardedXcms[1][0],
7720
7731
  chain: currentChain,
@@ -7760,8 +7771,8 @@ var dryRunInternal = /*#__PURE__*/function () {
7760
7771
  case 6:
7761
7772
  traversalResult = _context2.v;
7762
7773
  // Process Ethereum bridge fees
7763
- bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
7764
- assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
7774
+ bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
7775
+ assetHubChain = "AssetHub".concat(getRelayChainOfImpl(api, origin));
7765
7776
  bridgeHubHop = traversalResult.hops.find(function (hop) {
7766
7777
  return hop.chain === bridgeHubChain;
7767
7778
  }); // For Mythos → Ethereum, we skip additional Ethereum bridge fees (aligns with getXcmFeeInternal)
@@ -7882,7 +7893,9 @@ var parseUnits = parseUnits$1;
7882
7893
  var formatUnits = formatUnits$1;
7883
7894
 
7884
7895
  var resolveBypassMintAmount = function resolveBypassMintAmount(chain) {
7885
- return HIGH_BYPASS_MINT_CHAINS.includes(chain) ? HIGH_BYPASS_MINT_AMOUNT : BYPASS_MINT_AMOUNT;
7896
+ return HIGH_BYPASS_MINT_CHAINS.some(function (c) {
7897
+ return c === chain;
7898
+ }) ? HIGH_BYPASS_MINT_AMOUNT : BYPASS_MINT_AMOUNT;
7886
7899
  };
7887
7900
  var pickOtherPallet = function pickOtherPallet(asset, pallets) {
7888
7901
  if (!asset.isNative && (!asset.assetId || asset.assetId.startsWith('0x'))) {
@@ -8743,8 +8756,8 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
8743
8756
  destAsset = api.findNativeAssetInfoOrThrow(destination);
8744
8757
  case 16:
8745
8758
  // Process Ethereum bridge fees
8746
- bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
8747
- assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
8759
+ bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
8760
+ assetHubChain = "AssetHub".concat(getRelayChainOfImpl(api, origin));
8748
8761
  bridgeHubHop = traversalResult.hops.find(function (hop) {
8749
8762
  return hop.chain === bridgeHubChain;
8750
8763
  });
@@ -8764,7 +8777,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
8764
8777
  processedBridgeHub = _t4;
8765
8778
  // Update bridge hub fee in hops if needed
8766
8779
  if (processedBridgeHub && bridgeHubHop && processedBridgeHub.fee !== bridgeHubHop.result.fee) {
8767
- _bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
8780
+ _bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
8768
8781
  bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
8769
8782
  return hop.chain === _bridgeHubChain;
8770
8783
  });
@@ -10499,22 +10512,23 @@ var createAssetsFilter = function createAssetsFilter(asset, version) {
10499
10512
  };
10500
10513
 
10501
10514
  var prepareExecuteContext = function prepareExecuteContext(_ref) {
10502
- var chain = _ref.chain,
10515
+ var api = _ref.api,
10516
+ chain = _ref.chain,
10503
10517
  destChain = _ref.destChain,
10504
10518
  assetInfo = _ref.assetInfo,
10505
10519
  feeAssetInfo = _ref.feeAssetInfo,
10506
10520
  originFee = _ref.fees.originFee,
10507
10521
  version = _ref.version;
10508
10522
  var amount = assetInfo.amount;
10509
- var reserveChain = getAssetReserveChain(chain, assetInfo.location);
10523
+ var reserveChain = getAssetReserveChainImpl(api, chain, assetInfo.location);
10510
10524
  var asset = createAsset(version, amount, assetInfo.location);
10511
- var assetLocalized = createAsset(version, amount, localizeLocation(chain, assetInfo.location));
10525
+ var assetLocalized = createAsset(version, amount, localizeLocationImpl(api, chain, assetInfo.location));
10512
10526
  var assetLocalizedToDest = createAsset(version, amount, localizeLocation(destChain, assetInfo.location));
10513
- var assetLocalizedToReserve = createAsset(version, amount, localizeLocation(reserveChain !== null && reserveChain !== void 0 ? reserveChain : chain, assetInfo.location));
10527
+ var assetLocalizedToReserve = createAsset(version, amount, localizeLocationImpl(api, reserveChain !== null && reserveChain !== void 0 ? reserveChain : chain, assetInfo.location));
10514
10528
  var feeAsset = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, feeAssetInfo.location) : undefined;
10515
- var feeAssetLocalized = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocation(chain, feeAssetInfo.location)) : undefined;
10529
+ var feeAssetLocalized = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocationImpl(api, chain, feeAssetInfo.location)) : undefined;
10516
10530
  var feeAssetLocalizedToDest = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocation(destChain, feeAssetInfo.location)) : undefined;
10517
- var feeAssetLocalizedToReserve = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocation(reserveChain !== null && reserveChain !== void 0 ? reserveChain : chain, feeAssetInfo.location)) : undefined;
10531
+ var feeAssetLocalizedToReserve = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocationImpl(api, reserveChain !== null && reserveChain !== void 0 ? reserveChain : chain, feeAssetInfo.location)) : undefined;
10518
10532
  return {
10519
10533
  amount: amount,
10520
10534
  asset: asset,
@@ -10641,7 +10655,7 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
10641
10655
  mainInstructions = [{
10642
10656
  InitiateTeleport: {
10643
10657
  assets: routingAssetsFilter,
10644
- dest: getChainLocation(chain, reserveChain),
10658
+ dest: getChainLocation(chain, reserveChain, api._customCtx),
10645
10659
  xcm: [].concat(_toConsumableArray(createPayFees(version, hopFeeAssetToReserve !== null && hopFeeAssetToReserve !== void 0 ? hopFeeAssetToReserve : updateAsset(assetLocalizedToReserve, amount - originFeeDeduction), undefined, true, forceBuyExecution)), _toConsumableArray(resolvedDepositInstruction))
10646
10660
  }
10647
10661
  }];
@@ -10651,7 +10665,7 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
10651
10665
  mainInstructions = [{
10652
10666
  InitiateReserveWithdraw: {
10653
10667
  assets: routingAssetsFilter,
10654
- reserve: getChainLocation(chain, reserveChain),
10668
+ reserve: getChainLocation(chain, reserveChain, api._customCtx),
10655
10669
  xcm: [].concat(_toConsumableArray(createPayFees(version, // Decrease amount by 2 units because for some reason polkadot withdraws 2 units less
10656
10670
  // than requested, so we need to account for that
10657
10671
  hopFeeAssetToReserve !== null && hopFeeAssetToReserve !== void 0 ? hopFeeAssetToReserve : updateAsset(assetLocalizedToReserve, amount - 2n), undefined, true, forceBuyExecution)), _toConsumableArray(resolvedDepositInstruction))
@@ -13750,12 +13764,17 @@ var getAssetReserveChainImpl = function getAssetReserveChainImpl(api, chain, ass
13750
13764
  };
13751
13765
 
13752
13766
  var getChainVersion = function getChainVersion(api, chain) {
13753
- var _api$_customCtx$custo;
13754
13767
  if (isRelayChain(chain) || isExternalChain(chain)) {
13755
13768
  return Version.V5;
13756
13769
  }
13757
- var customEntry = (_api$_customCtx$custo = api._customCtx.customChains) === null || _api$_customCtx$custo === void 0 ? void 0 : _api$_customCtx$custo[chain];
13758
- if (customEntry) return customEntry.xcmVersion;
13770
+ if (isCustomChain(chain)) {
13771
+ var _api$_customCtx$custo;
13772
+ var entry = (_api$_customCtx$custo = api._customCtx.customChains) === null || _api$_customCtx$custo === void 0 ? void 0 : _api$_customCtx$custo[chain];
13773
+ if (!entry) {
13774
+ throw new CustomChainInvalidError("Custom chain '".concat(chain, "' is not registered."));
13775
+ }
13776
+ return entry.xcmVersion;
13777
+ }
13759
13778
  return getChain(chain).version;
13760
13779
  };
13761
13780
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "13.7.1",
3
+ "version": "13.7.2",
4
4
  "description": "SDK core for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,9 +25,9 @@
25
25
  "@noble/hashes": "^2.2.0",
26
26
  "@scure/base": "^2.2.0",
27
27
  "viem": "^2.51.3",
28
- "@paraspell/assets": "13.7.1",
29
- "@paraspell/sdk-common": "13.7.1",
30
- "@paraspell/pallets": "13.7.1"
28
+ "@paraspell/assets": "13.7.2",
29
+ "@paraspell/pallets": "13.7.2",
30
+ "@paraspell/sdk-common": "13.7.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-import-attributes": "^7.29.7",