@paraspell/sdk-core 8.14.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) {
@@ -8064,14 +8064,15 @@ var buildClaimAssetsInput = function buildClaimAssetsInput(_ref) {
8064
8064
 
8065
8065
  var claimAssets = /*#__PURE__*/function () {
8066
8066
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
8067
- var api, node, args, module, call;
8067
+ var api, node, address, args, module, call;
8068
8068
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8069
8069
  while (1) switch (_context.prev = _context.next) {
8070
8070
  case 0:
8071
- api = options.api, node = options.node;
8072
- _context.next = 3;
8071
+ api = options.api, node = options.node, address = options.address;
8072
+ validateAddress(address, node);
8073
+ _context.next = 4;
8073
8074
  return api.init(node, TX_CLIENT_TIMEOUT_MS);
8074
- case 3:
8075
+ case 4:
8075
8076
  args = buildClaimAssetsInput(options);
8076
8077
  module = sdkCommon.isRelayChain(node) ? 'XcmPallet' : 'PolkadotXcm';
8077
8078
  call = {
@@ -8080,7 +8081,7 @@ var claimAssets = /*#__PURE__*/function () {
8080
8081
  parameters: args
8081
8082
  };
8082
8083
  return _context.abrupt("return", api.callTxMethod(call));
8083
- case 7:
8084
+ case 8:
8084
8085
  case "end":
8085
8086
  return _context.stop();
8086
8087
  }
@@ -8704,6 +8705,43 @@ var Builder = function Builder(api) {
8704
8705
  return new GeneralBuilder(api, new BatchTransactionManager());
8705
8706
  };
8706
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
+
8707
8745
  var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8708
8746
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
8709
8747
  var ASSETS_PALLET_ID, hasRequiredJunctions;
@@ -8711,7 +8749,7 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8711
8749
  while (1) switch (_context.prev = _context.next) {
8712
8750
  case 0:
8713
8751
  if (!(node === 'Moonbeam' || node === 'Moonriver')) {
8714
- _context.next = 4;
8752
+ _context.next = 6;
8715
8753
  break;
8716
8754
  }
8717
8755
  if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
@@ -8720,48 +8758,54 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8720
8758
  }
8721
8759
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
8722
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:
8723
8767
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
8724
- case 4:
8768
+ case 6:
8725
8769
  if (!(node === 'Mythos')) {
8726
- _context.next = 6;
8770
+ _context.next = 8;
8727
8771
  break;
8728
8772
  }
8729
8773
  return _context.abrupt("return", api.getMythosForeignBalance(address));
8730
- case 6:
8774
+ case 8:
8731
8775
  if (assets.isForeignAsset(asset)) {
8732
- _context.next = 8;
8776
+ _context.next = 10;
8733
8777
  break;
8734
8778
  }
8735
8779
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
8736
- case 8:
8780
+ case 10:
8737
8781
  if (!(node === 'Polimec')) {
8738
- _context.next = 12;
8782
+ _context.next = 14;
8739
8783
  break;
8740
8784
  }
8741
8785
  if (!(asset.multiLocation === undefined)) {
8742
- _context.next = 11;
8786
+ _context.next = 13;
8743
8787
  break;
8744
8788
  }
8745
8789
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
8746
- case 11:
8790
+ case 13:
8747
8791
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8748
- case 12:
8792
+ case 14:
8749
8793
  if (!(node === 'AssetHubPolkadot')) {
8750
- _context.next = 18;
8794
+ _context.next = 20;
8751
8795
  break;
8752
8796
  }
8753
8797
  ASSETS_PALLET_ID = 50;
8754
8798
  hasRequiredJunctions = asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && sdkCommon.hasJunction(asset.multiLocation, 'GeneralIndex');
8755
8799
  if (!(!asset.multiLocation || hasRequiredJunctions)) {
8756
- _context.next = 17;
8800
+ _context.next = 19;
8757
8801
  break;
8758
8802
  }
8759
8803
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
8760
- case 17:
8804
+ case 19:
8761
8805
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8762
- case 18:
8806
+ case 20:
8763
8807
  return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
8764
- case 19:
8808
+ case 21:
8765
8809
  case "end":
8766
8810
  return _context.stop();
8767
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) {
@@ -8065,14 +8065,15 @@ var buildClaimAssetsInput = function buildClaimAssetsInput(_ref) {
8065
8065
 
8066
8066
  var claimAssets = /*#__PURE__*/function () {
8067
8067
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
8068
- var api, node, args, module, call;
8068
+ var api, node, address, args, module, call;
8069
8069
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8070
8070
  while (1) switch (_context.prev = _context.next) {
8071
8071
  case 0:
8072
- api = options.api, node = options.node;
8073
- _context.next = 3;
8072
+ api = options.api, node = options.node, address = options.address;
8073
+ validateAddress(address, node);
8074
+ _context.next = 4;
8074
8075
  return api.init(node, TX_CLIENT_TIMEOUT_MS);
8075
- case 3:
8076
+ case 4:
8076
8077
  args = buildClaimAssetsInput(options);
8077
8078
  module = isRelayChain(node) ? 'XcmPallet' : 'PolkadotXcm';
8078
8079
  call = {
@@ -8081,7 +8082,7 @@ var claimAssets = /*#__PURE__*/function () {
8081
8082
  parameters: args
8082
8083
  };
8083
8084
  return _context.abrupt("return", api.callTxMethod(call));
8084
- case 7:
8085
+ case 8:
8085
8086
  case "end":
8086
8087
  return _context.stop();
8087
8088
  }
@@ -8705,6 +8706,43 @@ var Builder = function Builder(api) {
8705
8706
  return new GeneralBuilder(api, new BatchTransactionManager());
8706
8707
  };
8707
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
+
8708
8746
  var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8709
8747
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
8710
8748
  var ASSETS_PALLET_ID, hasRequiredJunctions;
@@ -8712,7 +8750,7 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8712
8750
  while (1) switch (_context.prev = _context.next) {
8713
8751
  case 0:
8714
8752
  if (!(node === 'Moonbeam' || node === 'Moonriver')) {
8715
- _context.next = 4;
8753
+ _context.next = 6;
8716
8754
  break;
8717
8755
  }
8718
8756
  if (!(!isForeignAsset(asset) || !asset.assetId)) {
@@ -8721,48 +8759,54 @@ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
8721
8759
  }
8722
8760
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
8723
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:
8724
8768
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
8725
- case 4:
8769
+ case 6:
8726
8770
  if (!(node === 'Mythos')) {
8727
- _context.next = 6;
8771
+ _context.next = 8;
8728
8772
  break;
8729
8773
  }
8730
8774
  return _context.abrupt("return", api.getMythosForeignBalance(address));
8731
- case 6:
8775
+ case 8:
8732
8776
  if (isForeignAsset(asset)) {
8733
- _context.next = 8;
8777
+ _context.next = 10;
8734
8778
  break;
8735
8779
  }
8736
8780
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
8737
- case 8:
8781
+ case 10:
8738
8782
  if (!(node === 'Polimec')) {
8739
- _context.next = 12;
8783
+ _context.next = 14;
8740
8784
  break;
8741
8785
  }
8742
8786
  if (!(asset.multiLocation === undefined)) {
8743
- _context.next = 11;
8787
+ _context.next = 13;
8744
8788
  break;
8745
8789
  }
8746
8790
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
8747
- case 11:
8791
+ case 13:
8748
8792
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8749
- case 12:
8793
+ case 14:
8750
8794
  if (!(node === 'AssetHubPolkadot')) {
8751
- _context.next = 18;
8795
+ _context.next = 20;
8752
8796
  break;
8753
8797
  }
8754
8798
  ASSETS_PALLET_ID = 50;
8755
8799
  hasRequiredJunctions = asset.multiLocation && hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && hasJunction(asset.multiLocation, 'GeneralIndex');
8756
8800
  if (!(!asset.multiLocation || hasRequiredJunctions)) {
8757
- _context.next = 17;
8801
+ _context.next = 19;
8758
8802
  break;
8759
8803
  }
8760
8804
  return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
8761
- case 17:
8805
+ case 19:
8762
8806
  return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
8763
- case 18:
8807
+ case 20:
8764
8808
  return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
8765
- case 19:
8809
+ case 21:
8766
8810
  case "end":
8767
8811
  return _context.stop();
8768
8812
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "8.14.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/pallets": "8.14.0",
29
- "@paraspell/assets": "8.14.0",
30
- "@paraspell/sdk-common": "8.14.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",