@paraspell/assets 12.0.5 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -192,6 +192,8 @@ declare const isAssetEqual: (asset1: TAssetInfo, asset2: TAssetInfo) => boolean;
192
192
 
193
193
  declare const isAssetXcEqual: (asset1: TAssetInfo, asset2: TAssetInfo) => boolean;
194
194
 
195
+ declare const isStableCoinAsset: (asset: TAssetInfo, assetId?: number) => boolean;
196
+
195
197
  declare const isSymbolMatch: (symbolA: string, symbolB: string) => boolean;
196
198
 
197
199
  /**
@@ -215,7 +217,7 @@ declare const normalizeSymbol: (symbol?: string) => string;
215
217
 
216
218
  declare const findAssetInfo: (chain: TChain, currency: TCurrencyInput, destination: TChain | null) => TAssetInfo | null;
217
219
 
218
- declare const findAssetInfoById: (assets: TAssetInfo[], assetId: TCurrency) => TAssetInfo | undefined;
220
+ declare const findAssetInfoById: (assets: TAssetInfo[], assetId: TCurrency) => TAssetInfo;
219
221
 
220
222
  declare const findAssetInfoByLoc: (foreignAssets: TAssetInfo[], location: string | TLocation) => TAssetInfo | undefined;
221
223
 
@@ -279,5 +281,5 @@ declare const extractAssetLocation: <T = bigint>(asset: TAsset<T>) => TLocation;
279
281
 
280
282
  declare const getAssetLocation: (chain: TChain, currency: TCurrencyInput) => TLocation | null;
281
283
 
282
- export { DuplicateAssetError, DuplicateAssetIdError, Foreign, ForeignAbstract, InvalidCurrencyError, Native, Override, assertEdDefined, compareLocations, extractAssetLocation, findAssetInfo, findAssetInfoById, findAssetInfoByLoc, findAssetInfoBySymbol, findAssetInfoOnDest, findAssetInfoOrThrow, findAssetOnDestOrThrow, findBestMatches, findNativeAssetInfo, findNativeAssetInfoOrThrow, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssetLocation, getAssets, getAssetsObject, getEdFromAssetOrThrow, getExistentialDeposit, getExistentialDepositOrThrow, getFeeAssets, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getSupportedDestinations, hasDryRunSupport, hasSupportForAsset, hasXcmPaymentApiSupport, isAssetEqual, isAssetXcEqual, isChainEvm, isOverrideLocationSpecifier, isSymbolMatch, isSymbolSpecifier, isTAsset, normalizeLocation, normalizeSymbol };
284
+ export { DuplicateAssetError, DuplicateAssetIdError, Foreign, ForeignAbstract, InvalidCurrencyError, Native, Override, assertEdDefined, compareLocations, extractAssetLocation, findAssetInfo, findAssetInfoById, findAssetInfoByLoc, findAssetInfoBySymbol, findAssetInfoOnDest, findAssetInfoOrThrow, findAssetOnDestOrThrow, findBestMatches, findNativeAssetInfo, findNativeAssetInfoOrThrow, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssetLocation, getAssets, getAssetsObject, getEdFromAssetOrThrow, getExistentialDeposit, getExistentialDepositOrThrow, getFeeAssets, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getSupportedDestinations, hasDryRunSupport, hasSupportForAsset, hasXcmPaymentApiSupport, isAssetEqual, isAssetXcEqual, isChainEvm, isOverrideLocationSpecifier, isStableCoinAsset, isSymbolMatch, isSymbolSpecifier, isTAsset, normalizeLocation, normalizeSymbol };
283
285
  export type { TAmount, TAsset, TAssetInfo, TAssetInfoWithId, TAssetJsonMap, TAssetV3, TAssetV4, TAssetWithFee, TAssetWithLocation, TChainAssetsInfo, TCurrency, TCurrencyCore, TCurrencyInput, TCurrencyInputWithAmount, TCurrencySymbol, TCurrencySymbolValue, TLocationValue, TLocationValueWithOverride, TOverrideLocationSpecifier, TSymbolSpecifier, WithAmount, WithComplexAmount };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Version, deepEqual, getJunctionValue, replaceBigInt, isSubstrateBridge, CHAINS } from '@paraspell/sdk-common';
1
+ import { Version, deepEqual, getJunctionValue, hasJunction, replaceBigInt, isSubstrateBridge, CHAINS } from '@paraspell/sdk-common';
2
2
 
3
3
  var Polkadot = {
4
4
  relaychainSymbol: "DOT",
@@ -2949,6 +2949,7 @@ var Hydration = {
2949
2949
  isNative: true,
2950
2950
  decimals: 12,
2951
2951
  existentialDeposit: "1000000000000",
2952
+ assetId: "0",
2952
2953
  location: {
2953
2954
  parents: 1,
2954
2955
  interior: {
@@ -20436,6 +20437,14 @@ var isSymbolMatch = function isSymbolMatch(symbolA, symbolB) {
20436
20437
  return normalizeSymbol(symbolA) === normalizeSymbol(symbolB);
20437
20438
  };
20438
20439
 
20440
+ function _arrayLikeToArray(r, a) {
20441
+ (null == a || a > r.length) && (a = r.length);
20442
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
20443
+ return n;
20444
+ }
20445
+ function _arrayWithoutHoles(r) {
20446
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
20447
+ }
20439
20448
  function _assertThisInitialized(e) {
20440
20449
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20441
20450
  return e;
@@ -20490,6 +20499,12 @@ function _isNativeReflectConstruct() {
20490
20499
  return !!t;
20491
20500
  })();
20492
20501
  }
20502
+ function _iterableToArray(r) {
20503
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
20504
+ }
20505
+ function _nonIterableSpread() {
20506
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
20507
+ }
20493
20508
  function _objectWithoutProperties(e, t) {
20494
20509
  if (null == e) return {};
20495
20510
  var o,
@@ -20520,6 +20535,9 @@ function _setPrototypeOf(t, e) {
20520
20535
  return t.__proto__ = e, t;
20521
20536
  }, _setPrototypeOf(t, e);
20522
20537
  }
20538
+ function _toConsumableArray(r) {
20539
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
20540
+ }
20523
20541
  function _typeof(o) {
20524
20542
  "@babel/helpers - typeof";
20525
20543
 
@@ -20529,6 +20547,13 @@ function _typeof(o) {
20529
20547
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
20530
20548
  }, _typeof(o);
20531
20549
  }
20550
+ function _unsupportedIterableToArray(r, a) {
20551
+ if (r) {
20552
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
20553
+ var t = {}.toString.call(r).slice(8, -1);
20554
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
20555
+ }
20556
+ }
20532
20557
  function _wrapNativeSuper(t) {
20533
20558
  var r = "function" == typeof Map ? new Map() : void 0;
20534
20559
  return _wrapNativeSuper = function (t) {
@@ -20625,17 +20650,14 @@ var InvalidCurrencyError = /*#__PURE__*/function (_Error) {
20625
20650
  }(/*#__PURE__*/_wrapNativeSuper(Error));
20626
20651
 
20627
20652
  var findAssetInfoById = function findAssetInfoById(assets, assetId) {
20628
- var otherAssetsMatches = assets.filter(function (_ref) {
20629
- var currentAssetId = _ref.assetId;
20630
- return currentAssetId === assetId.toString();
20653
+ var id = assetId.toString();
20654
+ var matches = assets.filter(function (a) {
20655
+ return a.assetId === id;
20631
20656
  });
20632
- if (otherAssetsMatches.length > 1) {
20633
- throw new DuplicateAssetIdError(assetId.toString());
20657
+ if (matches.length > 1) {
20658
+ throw new DuplicateAssetIdError(id);
20634
20659
  }
20635
- return assets.find(function (_ref2) {
20636
- var currentAssetId = _ref2.assetId;
20637
- return currentAssetId === assetId.toString();
20638
- });
20660
+ return matches[0];
20639
20661
  };
20640
20662
 
20641
20663
  var sanitizeLocation = function sanitizeLocation(location) {
@@ -20902,6 +20924,7 @@ var findAssetInfo = function findAssetInfo(chain, currency, destination) {
20902
20924
  }
20903
20925
  var otherAssets = getOtherAssets(chain);
20904
20926
  var nativeAssets = getNativeAssets(chain);
20927
+ var assets = [].concat(_toConsumableArray(nativeAssets), _toConsumableArray(otherAssets));
20905
20928
  var asset;
20906
20929
  if ('symbol' in currency) {
20907
20930
  asset = findAssetInfoBySymbol(destination, otherAssets, nativeAssets, currency.symbol);
@@ -20909,7 +20932,7 @@ var findAssetInfo = function findAssetInfo(chain, currency, destination) {
20909
20932
  var _findAssetInfoByLoc;
20910
20933
  asset = (_findAssetInfoByLoc = findAssetInfoByLoc(otherAssets, currency.location)) !== null && _findAssetInfoByLoc !== void 0 ? _findAssetInfoByLoc : findAssetInfoByLoc(nativeAssets, currency.location);
20911
20934
  } else if ('id' in currency) {
20912
- asset = findAssetInfoById(otherAssets, currency.id);
20935
+ asset = findAssetInfoById(assets, currency.id);
20913
20936
  }
20914
20937
  return asset !== null && asset !== void 0 ? asset : null;
20915
20938
  };
@@ -20939,6 +20962,20 @@ var Override = function Override(location) {
20939
20962
  };
20940
20963
  };
20941
20964
 
20965
+ var STABLECOIN_IDS = [1984, 1337];
20966
+
20967
+ var hasStablecoinIndex = function hasStablecoinIndex(location, assetId) {
20968
+ return assetId !== undefined ? hasJunction(location, 'GeneralIndex', assetId) : STABLECOIN_IDS.some(function (id) {
20969
+ return hasJunction(location, 'GeneralIndex', id);
20970
+ });
20971
+ };
20972
+ var isStablecoinLocation = function isStablecoinLocation(location, assetId) {
20973
+ return !!location && hasJunction(location, 'PalletInstance', 50) && hasStablecoinIndex(location, assetId);
20974
+ };
20975
+ var isStableCoinAsset = function isStableCoinAsset(asset, assetId) {
20976
+ return isStablecoinLocation(asset.location, assetId);
20977
+ };
20978
+
20942
20979
  var findAssetInfoOrThrow = function findAssetInfoOrThrow(chain, currency, destination) {
20943
20980
  var asset = findAssetInfo(chain, currency, destination);
20944
20981
  if (!asset) {
@@ -20947,6 +20984,19 @@ var findAssetInfoOrThrow = function findAssetInfoOrThrow(chain, currency, destin
20947
20984
  return asset;
20948
20985
  };
20949
20986
 
20987
+ var findStablecoinAssets = function findStablecoinAssets(chain) {
20988
+ var assets = getOtherAssets(chain);
20989
+ return STABLECOIN_IDS.map(function (id) {
20990
+ var matches = assets.filter(function (asset) {
20991
+ return isStableCoinAsset(asset, id);
20992
+ });
20993
+ var consensusMatch = matches.find(function (asset) {
20994
+ return asset.location && hasJunction(asset.location, 'GlobalConsensus');
20995
+ });
20996
+ return consensusMatch !== null && consensusMatch !== void 0 ? consensusMatch : matches[0];
20997
+ });
20998
+ };
20999
+
20950
21000
  var findAssetInfoOnDest = function findAssetInfoOnDest(origin, destination, currency, originAsset) {
20951
21001
  var isBridge = isSubstrateBridge(origin, destination);
20952
21002
  var resolvedOriginAsset = originAsset !== null && originAsset !== void 0 ? originAsset : findAssetInfoOrThrow(origin, currency, destination);
@@ -20956,6 +21006,14 @@ var findAssetInfoOnDest = function findAssetInfoOnDest(origin, destination, curr
20956
21006
  symbol: Native(resolvedOriginAsset.symbol)
20957
21007
  }, null);
20958
21008
  if (nativeMatch) return nativeMatch;
21009
+ var isStablecoin = isStableCoinAsset(resolvedOriginAsset);
21010
+ if (isStablecoin) {
21011
+ var stablecoins = findStablecoinAssets(destination);
21012
+ var match = stablecoins.find(function (asset) {
21013
+ return asset.symbol === resolvedOriginAsset.symbol;
21014
+ });
21015
+ if (match) return match;
21016
+ }
20959
21017
  // Then try foreign
20960
21018
  var foreignMatch = findAssetInfo(destination, {
20961
21019
  symbol: Foreign(resolvedOriginAsset.symbol)
@@ -21223,9 +21281,11 @@ var getSupportedAssets = function getSupportedAssets(origin, destination) {
21223
21281
  var destinationAssets = getAssets(destination);
21224
21282
  var isSubBridge = isSubstrateBridge(origin, destination);
21225
21283
  if (isSubBridge) {
21226
- return originAssets.filter(function (asset) {
21227
- return asset.symbol === 'KSM' || asset.symbol === 'DOT';
21284
+ var systemAssets = originAssets.filter(function (asset) {
21285
+ return ['DOT', 'KSM'].includes(asset.symbol);
21228
21286
  });
21287
+ var stablecoinAssets = findStablecoinAssets(origin);
21288
+ return [].concat(_toConsumableArray(systemAssets), _toConsumableArray(stablecoinAssets));
21229
21289
  }
21230
21290
  var supportedAssets = originAssets.filter(function (asset) {
21231
21291
  return destinationAssets.some(function (a) {
@@ -21270,4 +21330,4 @@ var isAssetEqual = function isAssetEqual(asset1, asset2) {
21270
21330
  return isSymbolMatch(asset1.symbol, asset2.symbol);
21271
21331
  };
21272
21332
 
21273
- export { DuplicateAssetError, DuplicateAssetIdError, Foreign, ForeignAbstract, InvalidCurrencyError, Native, Override, assertEdDefined, compareLocations, extractAssetLocation, findAssetInfo, findAssetInfoById, findAssetInfoByLoc, findAssetInfoBySymbol, findAssetInfoOnDest, findAssetInfoOrThrow, findAssetOnDestOrThrow, findBestMatches, findNativeAssetInfo, findNativeAssetInfoOrThrow, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssetLocation, getAssets, getAssetsObject, getEdFromAssetOrThrow, getExistentialDeposit, getExistentialDepositOrThrow, getFeeAssets, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getSupportedDestinations, hasDryRunSupport, hasSupportForAsset, hasXcmPaymentApiSupport, isAssetEqual, isAssetXcEqual, isChainEvm, isOverrideLocationSpecifier, isSymbolMatch, isSymbolSpecifier, isTAsset, normalizeLocation, normalizeSymbol };
21333
+ export { DuplicateAssetError, DuplicateAssetIdError, Foreign, ForeignAbstract, InvalidCurrencyError, Native, Override, assertEdDefined, compareLocations, extractAssetLocation, findAssetInfo, findAssetInfoById, findAssetInfoByLoc, findAssetInfoBySymbol, findAssetInfoOnDest, findAssetInfoOrThrow, findAssetOnDestOrThrow, findBestMatches, findNativeAssetInfo, findNativeAssetInfoOrThrow, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssetLocation, getAssets, getAssetsObject, getEdFromAssetOrThrow, getExistentialDeposit, getExistentialDepositOrThrow, getFeeAssets, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getSupportedDestinations, hasDryRunSupport, hasSupportForAsset, hasXcmPaymentApiSupport, isAssetEqual, isAssetXcEqual, isChainEvm, isOverrideLocationSpecifier, isStableCoinAsset, isSymbolMatch, isSymbolSpecifier, isTAsset, normalizeLocation, normalizeSymbol };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/assets",
3
- "version": "12.0.5",
3
+ "version": "12.1.0",
4
4
  "description": "Assets for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@paraspell/sdk-common": "12.0.5"
26
+ "@paraspell/sdk-common": "12.1.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@babel/plugin-syntax-import-attributes": "^7.27.1",