@paraspell/sdk-core 8.15.0 → 8.15.1

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.cjs CHANGED
@@ -3234,6 +3234,18 @@ var getParaEthTransferFees = /*#__PURE__*/function () {
3234
3234
  };
3235
3235
  }();
3236
3236
 
3237
+ // Inspired by Moonbeam XCM-SDK
3238
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3239
+ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3240
+ if (id.startsWith('0x')) {
3241
+ return id;
3242
+ }
3243
+ if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3244
+ throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3245
+ }
3246
+ return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3247
+ };
3248
+
3237
3249
  var isEthersSigner = function isEthersSigner(signer) {
3238
3250
  return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
3239
3251
  };
@@ -3338,18 +3350,6 @@ var abi$1 = [
3338
3350
  }
3339
3351
  ];
3340
3352
 
3341
- // Inspired by Moonbeam XCM-SDK
3342
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3343
- var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3344
- if (id.startsWith('0x')) {
3345
- return id;
3346
- }
3347
- if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3348
- throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3349
- }
3350
- return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3351
- };
3352
-
3353
3353
  // Partially inspired by Moonbeam XCM-SDK
3354
3354
  // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts#L126
3355
3355
  var getDestinationMultilocation = function getDestinationMultilocation(api, address, destination) {
@@ -8705,6 +8705,43 @@ var Builder = function Builder(api) {
8705
8705
  return new GeneralBuilder(api, new BatchTransactionManager());
8706
8706
  };
8707
8707
 
8708
+ var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
8709
+ var MOONBEAM_ID = 1284;
8710
+ var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
8711
+ var MOONRIVER_ID = 1285;
8712
+ var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
8713
+ function getMoonbeamErc20Balance(_x, _x2, _x3) {
8714
+ return _getMoonbeamErc20Balance.apply(this, arguments);
8715
+ }
8716
+ function _getMoonbeamErc20Balance() {
8717
+ _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
8718
+ var _ref, rpc, id, provider, addr, token;
8719
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8720
+ while (1) switch (_context.prev = _context.next) {
8721
+ case 0:
8722
+ _ref = node === 'Moonbeam' ? {
8723
+ rpc: MOONBEAM_RPC,
8724
+ id: MOONBEAM_ID
8725
+ } : {
8726
+ rpc: MOONRIVER_RPC,
8727
+ id: MOONRIVER_ID
8728
+ }, rpc = _ref.rpc, id = _ref.id;
8729
+ provider = new ethers.ethers.JsonRpcProvider(rpc, id);
8730
+ addr = formatAssetIdToERC20(assetId);
8731
+ token = new ethers.ethers.Contract(addr, ERC20_ABI, provider);
8732
+ _context.next = 6;
8733
+ return token.balanceOf(address);
8734
+ case 6:
8735
+ return _context.abrupt("return", _context.sent);
8736
+ case 7:
8737
+ case "end":
8738
+ return _context.stop();
8739
+ }
8740
+ }, _callee);
8741
+ }));
8742
+ return _getMoonbeamErc20Balance.apply(this, arguments);
8743
+ }
8744
+
8708
8745
  var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8709
8746
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
8710
8747
  var ASSETS_PALLET_ID, hasRequiredJunctions;
@@ -8712,7 +8749,7 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8712
8749
  while (1) switch (_context.prev = _context.next) {
8713
8750
  case 0:
8714
8751
  if (!(node === 'Moonbeam' || node === 'Moonriver')) {
8715
- _context.next = 4;
8752
+ _context.next = 6;
8716
8753
  break;
8717
8754
  }
8718
8755
  if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
@@ -8721,48 +8758,54 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8721
8758
  }
8722
8759
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
8723
8760
  case 3:
8761
+ if (!(asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
8762
+ _context.next = 5;
8763
+ break;
8764
+ }
8765
+ return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
8766
+ case 5:
8724
8767
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
8725
- case 4:
8768
+ case 6:
8726
8769
  if (!(node === 'Mythos')) {
8727
- _context.next = 6;
8770
+ _context.next = 8;
8728
8771
  break;
8729
8772
  }
8730
8773
  return _context.abrupt("return", api.getMythosForeignBalance(address));
8731
- case 6:
8774
+ case 8:
8732
8775
  if (assets.isForeignAsset(asset)) {
8733
- _context.next = 8;
8776
+ _context.next = 10;
8734
8777
  break;
8735
8778
  }
8736
8779
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
8737
- case 8:
8780
+ case 10:
8738
8781
  if (!(node === 'Polimec')) {
8739
- _context.next = 12;
8782
+ _context.next = 14;
8740
8783
  break;
8741
8784
  }
8742
8785
  if (!(asset.multiLocation === undefined)) {
8743
- _context.next = 11;
8786
+ _context.next = 13;
8744
8787
  break;
8745
8788
  }
8746
8789
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
8747
- case 11:
8790
+ case 13:
8748
8791
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8749
- case 12:
8792
+ case 14:
8750
8793
  if (!(node === 'AssetHubPolkadot')) {
8751
- _context.next = 18;
8794
+ _context.next = 20;
8752
8795
  break;
8753
8796
  }
8754
8797
  ASSETS_PALLET_ID = 50;
8755
8798
  hasRequiredJunctions = asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && sdkCommon.hasJunction(asset.multiLocation, 'GeneralIndex');
8756
8799
  if (!(!asset.multiLocation || hasRequiredJunctions)) {
8757
- _context.next = 17;
8800
+ _context.next = 19;
8758
8801
  break;
8759
8802
  }
8760
8803
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
8761
- case 17:
8804
+ case 19:
8762
8805
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8763
- case 18:
8806
+ case 20:
8764
8807
  return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
8765
- case 19:
8808
+ case 21:
8766
8809
  case "end":
8767
8810
  return _context.stop();
8768
8811
  }
package/dist/index.mjs CHANGED
@@ -3235,6 +3235,18 @@ var getParaEthTransferFees = /*#__PURE__*/function () {
3235
3235
  };
3236
3236
  }();
3237
3237
 
3238
+ // Inspired by Moonbeam XCM-SDK
3239
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3240
+ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3241
+ if (id.startsWith('0x')) {
3242
+ return id;
3243
+ }
3244
+ if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3245
+ throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3246
+ }
3247
+ return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3248
+ };
3249
+
3238
3250
  var isEthersSigner = function isEthersSigner(signer) {
3239
3251
  return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
3240
3252
  };
@@ -3339,18 +3351,6 @@ var abi$1 = [
3339
3351
  }
3340
3352
  ];
3341
3353
 
3342
- // Inspired by Moonbeam XCM-SDK
3343
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3344
- var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3345
- if (id.startsWith('0x')) {
3346
- return id;
3347
- }
3348
- if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3349
- throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3350
- }
3351
- return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3352
- };
3353
-
3354
3354
  // Partially inspired by Moonbeam XCM-SDK
3355
3355
  // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts#L126
3356
3356
  var getDestinationMultilocation = function getDestinationMultilocation(api, address, destination) {
@@ -8706,6 +8706,43 @@ var Builder = function Builder(api) {
8706
8706
  return new GeneralBuilder(api, new BatchTransactionManager());
8707
8707
  };
8708
8708
 
8709
+ var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
8710
+ var MOONBEAM_ID = 1284;
8711
+ var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
8712
+ var MOONRIVER_ID = 1285;
8713
+ var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
8714
+ function getMoonbeamErc20Balance(_x, _x2, _x3) {
8715
+ return _getMoonbeamErc20Balance.apply(this, arguments);
8716
+ }
8717
+ function _getMoonbeamErc20Balance() {
8718
+ _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
8719
+ var _ref, rpc, id, provider, addr, token;
8720
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8721
+ while (1) switch (_context.prev = _context.next) {
8722
+ case 0:
8723
+ _ref = node === 'Moonbeam' ? {
8724
+ rpc: MOONBEAM_RPC,
8725
+ id: MOONBEAM_ID
8726
+ } : {
8727
+ rpc: MOONRIVER_RPC,
8728
+ id: MOONRIVER_ID
8729
+ }, rpc = _ref.rpc, id = _ref.id;
8730
+ provider = new ethers.JsonRpcProvider(rpc, id);
8731
+ addr = formatAssetIdToERC20(assetId);
8732
+ token = new ethers.Contract(addr, ERC20_ABI, provider);
8733
+ _context.next = 6;
8734
+ return token.balanceOf(address);
8735
+ case 6:
8736
+ return _context.abrupt("return", _context.sent);
8737
+ case 7:
8738
+ case "end":
8739
+ return _context.stop();
8740
+ }
8741
+ }, _callee);
8742
+ }));
8743
+ return _getMoonbeamErc20Balance.apply(this, arguments);
8744
+ }
8745
+
8709
8746
  var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8710
8747
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
8711
8748
  var ASSETS_PALLET_ID, hasRequiredJunctions;
@@ -8713,7 +8750,7 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8713
8750
  while (1) switch (_context.prev = _context.next) {
8714
8751
  case 0:
8715
8752
  if (!(node === 'Moonbeam' || node === 'Moonriver')) {
8716
- _context.next = 4;
8753
+ _context.next = 6;
8717
8754
  break;
8718
8755
  }
8719
8756
  if (!(!isForeignAsset(asset) || !asset.assetId)) {
@@ -8722,48 +8759,54 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8722
8759
  }
8723
8760
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
8724
8761
  case 3:
8762
+ if (!(asset.multiLocation && hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
8763
+ _context.next = 5;
8764
+ break;
8765
+ }
8766
+ return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
8767
+ case 5:
8725
8768
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
8726
- case 4:
8769
+ case 6:
8727
8770
  if (!(node === 'Mythos')) {
8728
- _context.next = 6;
8771
+ _context.next = 8;
8729
8772
  break;
8730
8773
  }
8731
8774
  return _context.abrupt("return", api.getMythosForeignBalance(address));
8732
- case 6:
8775
+ case 8:
8733
8776
  if (isForeignAsset(asset)) {
8734
- _context.next = 8;
8777
+ _context.next = 10;
8735
8778
  break;
8736
8779
  }
8737
8780
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
8738
- case 8:
8781
+ case 10:
8739
8782
  if (!(node === 'Polimec')) {
8740
- _context.next = 12;
8783
+ _context.next = 14;
8741
8784
  break;
8742
8785
  }
8743
8786
  if (!(asset.multiLocation === undefined)) {
8744
- _context.next = 11;
8787
+ _context.next = 13;
8745
8788
  break;
8746
8789
  }
8747
8790
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
8748
- case 11:
8791
+ case 13:
8749
8792
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8750
- case 12:
8793
+ case 14:
8751
8794
  if (!(node === 'AssetHubPolkadot')) {
8752
- _context.next = 18;
8795
+ _context.next = 20;
8753
8796
  break;
8754
8797
  }
8755
8798
  ASSETS_PALLET_ID = 50;
8756
8799
  hasRequiredJunctions = asset.multiLocation && hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && hasJunction(asset.multiLocation, 'GeneralIndex');
8757
8800
  if (!(!asset.multiLocation || hasRequiredJunctions)) {
8758
- _context.next = 17;
8801
+ _context.next = 19;
8759
8802
  break;
8760
8803
  }
8761
8804
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
8762
- case 17:
8805
+ case 19:
8763
8806
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8764
- case 18:
8807
+ case 20:
8765
8808
  return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
8766
- case 19:
8809
+ case 21:
8767
8810
  case "end":
8768
8811
  return _context.stop();
8769
8812
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "8.15.0",
3
+ "version": "8.15.1",
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
  "dependencies": {
26
26
  "ethers": "^6.13.7",
27
27
  "viem": "^2.28.1",
28
- "@paraspell/sdk-common": "8.15.0",
29
- "@paraspell/pallets": "8.15.0",
30
- "@paraspell/assets": "8.15.0"
28
+ "@paraspell/pallets": "8.15.1",
29
+ "@paraspell/sdk-common": "8.15.1",
30
+ "@paraspell/assets": "8.15.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-import-attributes": "^7.27.1",