@paraspell/sdk-core 13.7.0 → 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() {
@@ -4382,8 +4393,7 @@ var validateDestination = function validateDestination(origin, destination, api)
4382
4393
  }
4383
4394
  var isLocationDestination = _typeof(destination) === 'object';
4384
4395
  var isBridgeTransfer = !isTLocation(destination) && isBridge(origin, destination);
4385
- var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
4386
- if (!isRelayDestination && !isLocationDestination) {
4396
+ if (!isLocationDestination) {
4387
4397
  var originRelayChainSymbol = getRelayChainSymbolImpl(origin, api._customCtx);
4388
4398
  var destinationRelayChainSymbol = getRelayChainSymbolImpl(destination, api._customCtx);
4389
4399
  if (!isBridgeTransfer && originRelayChainSymbol !== destinationRelayChainSymbol) {
@@ -6571,12 +6581,12 @@ var isSufficientDestination = /*#__PURE__*/function () {
6571
6581
  };
6572
6582
  }();
6573
6583
 
6574
- var createOriginLocation = function createOriginLocation(origin, destination, version) {
6584
+ var createOriginLocation = function createOriginLocation(origin, destination, version, customCtx) {
6575
6585
  if (isRelayChain(origin)) return DOT_LOCATION;
6576
6586
  return {
6577
6587
  parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
6578
6588
  interior: createX1Payload(version, {
6579
- Parachain: getParaId(origin)
6589
+ Parachain: getParaIdImpl(origin, customCtx)
6580
6590
  })
6581
6591
  };
6582
6592
  };
@@ -7510,7 +7520,7 @@ var traverseXcmHops = /*#__PURE__*/function () {
7510
7520
  _context.n = 10;
7511
7521
  break;
7512
7522
  }
7513
- nextChain = getTChain(nextParaId, getRelayChainOf(origin));
7523
+ nextChain = getTChain(nextParaId, getRelayChainOfImpl(api, origin));
7514
7524
  if (nextChain) {
7515
7525
  _context.n = 2;
7516
7526
  break;
@@ -7715,7 +7725,7 @@ var dryRunInternal = /*#__PURE__*/function () {
7715
7725
  case 1:
7716
7726
  _context.n = 2;
7717
7727
  return hopApi.getDryRunXcm({
7718
- originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain, resolvedVersion), resolvedVersion),
7728
+ originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain, resolvedVersion, api._customCtx), resolvedVersion),
7719
7729
  tx: tx,
7720
7730
  xcm: forwardedXcms[1][0],
7721
7731
  chain: currentChain,
@@ -7761,8 +7771,8 @@ var dryRunInternal = /*#__PURE__*/function () {
7761
7771
  case 6:
7762
7772
  traversalResult = _context2.v;
7763
7773
  // Process Ethereum bridge fees
7764
- bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
7765
- assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
7774
+ bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
7775
+ assetHubChain = "AssetHub".concat(getRelayChainOfImpl(api, origin));
7766
7776
  bridgeHubHop = traversalResult.hops.find(function (hop) {
7767
7777
  return hop.chain === bridgeHubChain;
7768
7778
  }); // For Mythos → Ethereum, we skip additional Ethereum bridge fees (aligns with getXcmFeeInternal)
@@ -7883,7 +7893,9 @@ var parseUnits = parseUnits$1;
7883
7893
  var formatUnits = formatUnits$1;
7884
7894
 
7885
7895
  var resolveBypassMintAmount = function resolveBypassMintAmount(chain) {
7886
- 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;
7887
7899
  };
7888
7900
  var pickOtherPallet = function pickOtherPallet(asset, pallets) {
7889
7901
  if (!asset.isNative && (!asset.assetId || asset.assetId.startsWith('0x'))) {
@@ -8744,8 +8756,8 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
8744
8756
  destAsset = api.findNativeAssetInfoOrThrow(destination);
8745
8757
  case 16:
8746
8758
  // Process Ethereum bridge fees
8747
- bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
8748
- assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
8759
+ bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
8760
+ assetHubChain = "AssetHub".concat(getRelayChainOfImpl(api, origin));
8749
8761
  bridgeHubHop = traversalResult.hops.find(function (hop) {
8750
8762
  return hop.chain === bridgeHubChain;
8751
8763
  });
@@ -8765,7 +8777,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
8765
8777
  processedBridgeHub = _t4;
8766
8778
  // Update bridge hub fee in hops if needed
8767
8779
  if (processedBridgeHub && bridgeHubHop && processedBridgeHub.fee !== bridgeHubHop.result.fee) {
8768
- _bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
8780
+ _bridgeHubChain = "BridgeHub".concat(getRelayChainOfImpl(api, origin));
8769
8781
  bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
8770
8782
  return hop.chain === _bridgeHubChain;
8771
8783
  });
@@ -10500,22 +10512,23 @@ var createAssetsFilter = function createAssetsFilter(asset, version) {
10500
10512
  };
10501
10513
 
10502
10514
  var prepareExecuteContext = function prepareExecuteContext(_ref) {
10503
- var chain = _ref.chain,
10515
+ var api = _ref.api,
10516
+ chain = _ref.chain,
10504
10517
  destChain = _ref.destChain,
10505
10518
  assetInfo = _ref.assetInfo,
10506
10519
  feeAssetInfo = _ref.feeAssetInfo,
10507
10520
  originFee = _ref.fees.originFee,
10508
10521
  version = _ref.version;
10509
10522
  var amount = assetInfo.amount;
10510
- var reserveChain = getAssetReserveChain(chain, assetInfo.location);
10523
+ var reserveChain = getAssetReserveChainImpl(api, chain, assetInfo.location);
10511
10524
  var asset = createAsset(version, amount, assetInfo.location);
10512
- var assetLocalized = createAsset(version, amount, localizeLocation(chain, assetInfo.location));
10525
+ var assetLocalized = createAsset(version, amount, localizeLocationImpl(api, chain, assetInfo.location));
10513
10526
  var assetLocalizedToDest = createAsset(version, amount, localizeLocation(destChain, assetInfo.location));
10514
- 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));
10515
10528
  var feeAsset = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, feeAssetInfo.location) : undefined;
10516
- 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;
10517
10530
  var feeAssetLocalizedToDest = feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo) ? createAsset(version, originFee, localizeLocation(destChain, feeAssetInfo.location)) : undefined;
10518
- 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;
10519
10532
  return {
10520
10533
  amount: amount,
10521
10534
  asset: asset,
@@ -10642,7 +10655,7 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
10642
10655
  mainInstructions = [{
10643
10656
  InitiateTeleport: {
10644
10657
  assets: routingAssetsFilter,
10645
- dest: getChainLocation(chain, reserveChain),
10658
+ dest: getChainLocation(chain, reserveChain, api._customCtx),
10646
10659
  xcm: [].concat(_toConsumableArray(createPayFees(version, hopFeeAssetToReserve !== null && hopFeeAssetToReserve !== void 0 ? hopFeeAssetToReserve : updateAsset(assetLocalizedToReserve, amount - originFeeDeduction), undefined, true, forceBuyExecution)), _toConsumableArray(resolvedDepositInstruction))
10647
10660
  }
10648
10661
  }];
@@ -10652,7 +10665,7 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
10652
10665
  mainInstructions = [{
10653
10666
  InitiateReserveWithdraw: {
10654
10667
  assets: routingAssetsFilter,
10655
- reserve: getChainLocation(chain, reserveChain),
10668
+ reserve: getChainLocation(chain, reserveChain, api._customCtx),
10656
10669
  xcm: [].concat(_toConsumableArray(createPayFees(version, // Decrease amount by 2 units because for some reason polkadot withdraws 2 units less
10657
10670
  // than requested, so we need to account for that
10658
10671
  hopFeeAssetToReserve !== null && hopFeeAssetToReserve !== void 0 ? hopFeeAssetToReserve : updateAsset(assetLocalizedToReserve, amount - 2n), undefined, true, forceBuyExecution)), _toConsumableArray(resolvedDepositInstruction))
@@ -13751,12 +13764,17 @@ var getAssetReserveChainImpl = function getAssetReserveChainImpl(api, chain, ass
13751
13764
  };
13752
13765
 
13753
13766
  var getChainVersion = function getChainVersion(api, chain) {
13754
- var _api$_customCtx$custo;
13755
13767
  if (isRelayChain(chain) || isExternalChain(chain)) {
13756
13768
  return Version.V5;
13757
13769
  }
13758
- var customEntry = (_api$_customCtx$custo = api._customCtx.customChains) === null || _api$_customCtx$custo === void 0 ? void 0 : _api$_customCtx$custo[chain];
13759
- 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
+ }
13760
13778
  return getChain(chain).version;
13761
13779
  };
13762
13780
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "13.7.0",
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.0",
29
- "@paraspell/pallets": "13.7.0",
30
- "@paraspell/sdk-common": "13.7.0"
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",