@paraspell/sdk-pjs 8.5.2 → 8.6.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/README.md CHANGED
@@ -223,6 +223,11 @@ const result = await Builder(API /*optional*/)
223
223
 
224
224
  //Function pattern
225
225
  await getDryRun({api /*optional*/, node, address /*sender address*/, tx /* Extrinsic object */})
226
+
227
+ //Check Parachain for DryRun support - returns true/false
228
+ import { hasDryRunSupport } from "@paraspell/sdk-pjs";
229
+
230
+ const result = hasDryRunSupport(node)
226
231
  ```
227
232
 
228
233
  ### Asset claim:
@@ -333,6 +338,9 @@ await getTransferInfo({from, to, address, destinationAddress, currency /*- {id:
333
338
 
334
339
  //Get bridge and execution fee for transfer from Parachain to Ethereum. Returns as an object of 2 values - [bridgeFee, executionFee]
335
340
  await getParaEthTransferFees(/*api - optional (Can also be WS port string or array o WS ports. Must be AssetHubPolkadot WS!)*/)
341
+
342
+ //Verify whether XCM message you wish to send will reach above existential deposit on destination chain.
343
+ await verifyEdOnDestination(node, currency: {symbol: || id: || multilocation: .. ,amount: 100000n}, address)
336
344
  ```
337
345
 
338
346
  ## 💻 Tests
package/dist/index.cjs CHANGED
@@ -7,8 +7,6 @@ var api$1 = require('@polkadot/api');
7
7
  var types = require('@polkadot/types');
8
8
  var utilCrypto = require('@polkadot/util-crypto');
9
9
  var util = require('@polkadot/util');
10
- var ethers = require('ethers');
11
- var viem = require('viem');
12
10
 
13
11
  function _arrayLikeToArray(r, a) {
14
12
  (null == a || a > r.length) && (a = r.length);
@@ -18,9 +16,6 @@ function _arrayLikeToArray(r, a) {
18
16
  function _arrayWithHoles(r) {
19
17
  if (Array.isArray(r)) return r;
20
18
  }
21
- function _arrayWithoutHoles(r) {
22
- if (Array.isArray(r)) return _arrayLikeToArray(r);
23
- }
24
19
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
25
20
  try {
26
21
  var i = n[a](c),
@@ -42,7 +37,7 @@ function _asyncToGenerator(n) {
42
37
  function _throw(n) {
43
38
  asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
44
39
  }
45
- _next(undefined);
40
+ _next(void 0);
46
41
  });
47
42
  };
48
43
  }
@@ -68,9 +63,6 @@ function _defineProperty(e, r, t) {
68
63
  writable: true
69
64
  }) : e[r] = t, e;
70
65
  }
71
- function _iterableToArray(r) {
72
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
73
- }
74
66
  function _iterableToArrayLimit(r, l) {
75
67
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
76
68
  if (null != t) {
@@ -98,9 +90,6 @@ function _iterableToArrayLimit(r, l) {
98
90
  function _nonIterableRest() {
99
91
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
100
92
  }
101
- function _nonIterableSpread() {
102
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
103
- }
104
93
  function ownKeys(e, r) {
105
94
  var t = Object.keys(e);
106
95
  if (Object.getOwnPropertySymbols) {
@@ -322,7 +311,7 @@ function _regeneratorRuntime() {
322
311
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
323
312
  return this;
324
313
  }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
325
- undefined === i && (i = Promise);
314
+ void 0 === i && (i = Promise);
326
315
  var a = new AsyncIterator(wrap(t, r, n, o), i);
327
316
  return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
328
317
  return t.done ? t.value : a.next();
@@ -426,14 +415,11 @@ function _regeneratorRuntime() {
426
415
  function _slicedToArray(r, e) {
427
416
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
428
417
  }
429
- function _toConsumableArray(r) {
430
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
431
- }
432
418
  function _toPrimitive(t, r) {
433
419
  if ("object" != typeof t || !t) return t;
434
420
  var e = t[Symbol.toPrimitive];
435
- if (undefined !== e) {
436
- var i = e.call(t, r || "default");
421
+ if (void 0 !== e) {
422
+ var i = e.call(t, r);
437
423
  if ("object" != typeof i) return i;
438
424
  throw new TypeError("@@toPrimitive must return a primitive value.");
439
425
  }
@@ -443,20 +429,11 @@ function _toPropertyKey(t) {
443
429
  var i = _toPrimitive(t, "string");
444
430
  return "symbol" == typeof i ? i : i + "";
445
431
  }
446
- function _typeof(o) {
447
- "@babel/helpers - typeof";
448
-
449
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
450
- return typeof o;
451
- } : function (o) {
452
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
453
- }, _typeof(o);
454
- }
455
432
  function _unsupportedIterableToArray(r, a) {
456
433
  if (r) {
457
434
  if ("string" == typeof r) return _arrayLikeToArray(r, a);
458
435
  var t = {}.toString.call(r).slice(8, -1);
459
- 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) : undefined;
436
+ 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;
460
437
  }
461
438
  }
462
439
 
@@ -479,13 +456,6 @@ var createContext = function createContext(executionUrl, config) {
479
456
  });
480
457
  };
481
458
 
482
- var isEthersSigner = function isEthersSigner(signer) {
483
- return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
484
- };
485
- var isEthersContract = function isEthersContract(contract) {
486
- return !('abi' in contract);
487
- };
488
-
489
459
  /**
490
460
  * Transfers an Ethereum asset to a Polkadot account.
491
461
  *
@@ -521,7 +491,7 @@ var transferEthToPolkadot$1 = /*#__PURE__*/function () {
521
491
  }
522
492
  throw new Error('provider parameter is required for Snowbridge transfers.');
523
493
  case 7:
524
- if (isEthersSigner(signer)) {
494
+ if (sdkCore.isEthersSigner(signer)) {
525
495
  _context.next = 9;
526
496
  break;
527
497
  }
@@ -846,7 +816,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
846
816
  _context.next = 16;
847
817
  break;
848
818
  case 8:
849
- if (!((_this$_api = this._api) !== null && _this$_api !== undefined)) {
819
+ if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
850
820
  _context.next = 12;
851
821
  break;
852
822
  }
@@ -922,6 +892,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
922
892
  var section = mode === sdkCore.BatchMode.BATCH_ALL ? 'batchAll' : 'batch';
923
893
  return this.api.tx.utility[section](calls);
924
894
  }
895
+ }, {
896
+ key: "objectToHex",
897
+ value: function objectToHex(obj, typeName) {
898
+ return Promise.resolve(this.api.createType(typeName, obj).toHex());
899
+ }
900
+ }, {
901
+ key: "hexToUint8a",
902
+ value: function hexToUint8a(hex) {
903
+ return util.hexToU8a(hex);
904
+ }
905
+ }, {
906
+ key: "stringToUint8a",
907
+ value: function stringToUint8a(str) {
908
+ return util.stringToU8a(str);
909
+ }
925
910
  }, {
926
911
  key: "calculateTransactionFee",
927
912
  value: function () {
@@ -1149,7 +1134,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1149
1134
  var assetItem = _ref3$0$args[1];
1150
1135
  _ref3[1];
1151
1136
  var assetSymbol = assetItem.toString().toLowerCase();
1152
- return assetSymbol === ((_asset$symbol = asset.symbol) === null || _asset$symbol === undefined ? undefined : _asset$symbol.toLowerCase()) || sdkCore.isForeignAsset(asset) && assetSymbol === ((_asset$assetId = asset.assetId) === null || _asset$assetId === undefined ? undefined : _asset$assetId.toLowerCase()) || Object.values((_assetItem$toHuman = assetItem.toHuman()) !== null && _assetItem$toHuman !== undefined ? _assetItem$toHuman : {}).toString().toLowerCase() === ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === undefined ? undefined : _asset$symbol2.toLowerCase()) || sdkCore.isForeignAsset(asset) && Object.values((_assetItem$toHuman2 = assetItem.toHuman()) !== null && _assetItem$toHuman2 !== undefined ? _assetItem$toHuman2 : {}).toString().toLowerCase() === ((_asset$assetId2 = asset.assetId) === null || _asset$assetId2 === undefined ? undefined : _asset$assetId2.toLowerCase());
1137
+ return assetSymbol === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase()) || sdkCore.isForeignAsset(asset) && assetSymbol === ((_asset$assetId = asset.assetId) === null || _asset$assetId === void 0 ? void 0 : _asset$assetId.toLowerCase()) || Object.values((_assetItem$toHuman = assetItem.toHuman()) !== null && _assetItem$toHuman !== void 0 ? _assetItem$toHuman : {}).toString().toLowerCase() === ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toLowerCase()) || sdkCore.isForeignAsset(asset) && Object.values((_assetItem$toHuman2 = assetItem.toHuman()) !== null && _assetItem$toHuman2 !== void 0 ? _assetItem$toHuman2 : {}).toString().toLowerCase() === ((_asset$assetId2 = asset.assetId) === null || _asset$assetId2 === void 0 ? void 0 : _asset$assetId2.toLowerCase());
1153
1138
  });
1154
1139
  accountData = entry ? entry[1] : null;
1155
1140
  return _context11.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
@@ -1190,29 +1175,41 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1190
1175
  return getBalanceForeignAssetsAccount;
1191
1176
  }()
1192
1177
  }, {
1193
- key: "getFromStorage",
1178
+ key: "getFromRpc",
1194
1179
  value: function () {
1195
- var _getFromStorage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(key) {
1196
- var response;
1180
+ var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(module, method, key) {
1181
+ var rpcModule, response;
1197
1182
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1198
1183
  while (1) switch (_context13.prev = _context13.next) {
1199
1184
  case 0:
1200
- _context13.next = 2;
1201
- return this.api.rpc.state.getStorage(key);
1202
- case 2:
1185
+ rpcModule = this.api.rpc[module];
1186
+ if (!(!rpcModule || !rpcModule[method])) {
1187
+ _context13.next = 3;
1188
+ break;
1189
+ }
1190
+ throw new Error("RPC method ".concat(module, ".").concat(method, " not available"));
1191
+ case 3:
1192
+ _context13.next = 5;
1193
+ return rpcModule[method](key);
1194
+ case 5:
1203
1195
  response = _context13.sent;
1204
1196
  return _context13.abrupt("return", response.toHex());
1205
- case 4:
1197
+ case 7:
1206
1198
  case "end":
1207
1199
  return _context13.stop();
1208
1200
  }
1209
1201
  }, _callee13, this);
1210
1202
  }));
1211
- function getFromStorage(_x22) {
1212
- return _getFromStorage.apply(this, arguments);
1203
+ function getFromRpc(_x22, _x23, _x24) {
1204
+ return _getFromRpc.apply(this, arguments);
1213
1205
  }
1214
- return getFromStorage;
1206
+ return getFromRpc;
1215
1207
  }()
1208
+ }, {
1209
+ key: "blake2AsHex",
1210
+ value: function blake2AsHex(data) {
1211
+ return utilCrypto.blake2AsHex(data);
1212
+ }
1216
1213
  }, {
1217
1214
  key: "clone",
1218
1215
  value: function clone() {
@@ -1237,7 +1234,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1237
1234
  }
1238
1235
  }, _callee14);
1239
1236
  }));
1240
- function createApiForNode(_x23) {
1237
+ function createApiForNode(_x25) {
1241
1238
  return _createApiForNode.apply(this, arguments);
1242
1239
  }
1243
1240
  return createApiForNode;
@@ -1293,7 +1290,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1293
1290
  }
1294
1291
  }, _callee15, this);
1295
1292
  }));
1296
- function getDryRun(_x24) {
1293
+ function getDryRun(_x26) {
1297
1294
  return _getDryRun.apply(this, arguments);
1298
1295
  }
1299
1296
  return getDryRun;
@@ -1459,6 +1456,7 @@ var getOriginFeeDetails = createPolkadotJsApiCall(sdkCore.getOriginFeeDetails);
1459
1456
  var getMaxNativeTransferableAmount = createPolkadotJsApiCall(sdkCore.getMaxNativeTransferableAmount);
1460
1457
  var getMaxForeignTransferableAmount = createPolkadotJsApiCall(sdkCore.getMaxForeignTransferableAmount);
1461
1458
  var getTransferableAmount = createPolkadotJsApiCall(sdkCore.getTransferableAmount);
1459
+ var verifyEdOnDestination = createPolkadotJsApiCall(sdkCore.verifyEdOnDestination);
1462
1460
 
1463
1461
  var assets = /*#__PURE__*/Object.freeze({
1464
1462
  __proto__: null,
@@ -1489,324 +1487,10 @@ var assets = /*#__PURE__*/Object.freeze({
1489
1487
  getTransferInfo: getTransferInfo,
1490
1488
  getTransferableAmount: getTransferableAmount,
1491
1489
  hasSupportForAsset: sdkCore.hasSupportForAsset,
1492
- isNodeEvm: sdkCore.isNodeEvm
1490
+ isNodeEvm: sdkCore.isNodeEvm,
1491
+ verifyEdOnDestination: verifyEdOnDestination
1493
1492
  });
1494
1493
 
1495
- var abi = [
1496
- {
1497
- inputs: [
1498
- {
1499
- components: [
1500
- {
1501
- internalType: "uint8",
1502
- name: "parents",
1503
- type: "uint8"
1504
- },
1505
- {
1506
- internalType: "bytes[]",
1507
- name: "interior",
1508
- type: "bytes[]"
1509
- }
1510
- ],
1511
- internalType: "struct XCM.Location",
1512
- name: "dest",
1513
- type: "tuple"
1514
- },
1515
- {
1516
- components: [
1517
- {
1518
- internalType: "address",
1519
- name: "asset",
1520
- type: "address"
1521
- },
1522
- {
1523
- internalType: "uint256",
1524
- name: "amount",
1525
- type: "uint256"
1526
- }
1527
- ],
1528
- internalType: "struct XCM.AssetAddressInfo[]",
1529
- name: "assets",
1530
- type: "tuple[]"
1531
- },
1532
- {
1533
- internalType: "enum XCM.TransferType",
1534
- name: "assetsTransferType",
1535
- type: "uint8"
1536
- },
1537
- {
1538
- internalType: "uint8",
1539
- name: "remoteFeesIdIndex",
1540
- type: "uint8"
1541
- },
1542
- {
1543
- internalType: "enum XCM.TransferType",
1544
- name: "feesTransferType",
1545
- type: "uint8"
1546
- },
1547
- {
1548
- internalType: "bytes",
1549
- name: "customXcmOnDest",
1550
- type: "bytes"
1551
- }
1552
- ],
1553
- name: "transferAssetsUsingTypeAndThenAddress",
1554
- outputs: [
1555
- ],
1556
- stateMutability: "nonpayable",
1557
- type: "function"
1558
- }
1559
- ];
1560
-
1561
- // https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
1562
- var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
1563
- var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
1564
- var transferMoonbeamToEth = /*#__PURE__*/function () {
1565
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1566
- var _signer$account;
1567
- var api, from, to, signer, address, ahAddress, currency, foundAsset, ethAsset, contract, BRIDGE_LOCATION, ERC20_TOKEN_LOCATION, ERC20_TOKEN_LOCATION_REANCHORED, customXcm, apiPjs, assetHubApi, assetHubApiPjs, xcmHash, sender, _yield$Promise$all, _yield$Promise$all2, parachainId, accountNextId, entropy, messageId, xcmOnDest, customXcmOnDest, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, tx;
1568
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1569
- while (1) switch (_context.prev = _context.next) {
1570
- case 0:
1571
- api = _ref.api, from = _ref.from, to = _ref.to, signer = _ref.signer, address = _ref.address, ahAddress = _ref.ahAddress, currency = _ref.currency;
1572
- if (!('multiasset' in currency)) {
1573
- _context.next = 3;
1574
- break;
1575
- }
1576
- throw new Error('Multiassets syntax is not supported for Evm transfers');
1577
- case 3:
1578
- if (!('multilocation' in currency && sdkCore.isOverrideMultiLocationSpecifier(currency.multilocation))) {
1579
- _context.next = 5;
1580
- break;
1581
- }
1582
- throw new Error('Override multilocation is not supported for Evm transfers');
1583
- case 5:
1584
- foundAsset = sdkCore.getAssetBySymbolOrId(from, currency, to);
1585
- if (!(foundAsset === null)) {
1586
- _context.next = 8;
1587
- break;
1588
- }
1589
- throw new sdkCore.InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
1590
- case 8:
1591
- if (!(!sdkCore.isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
1592
- _context.next = 10;
1593
- break;
1594
- }
1595
- throw new sdkCore.InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
1596
- case 10:
1597
- ethAsset = sdkCore.findAssetByMultiLocation(sdkCore.getOtherAssets('Ethereum'), foundAsset.multiLocation);
1598
- if (ethAsset) {
1599
- _context.next = 13;
1600
- break;
1601
- }
1602
- throw new sdkCore.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
1603
- case 13:
1604
- contract = isEthersSigner(signer) ? new ethers.Contract(xcmInterfacePrecompile, abi, signer) : viem.getContract({
1605
- abi: abi,
1606
- address: xcmInterfacePrecompile,
1607
- client: {
1608
- "public": viem.createPublicClient({
1609
- chain: signer.chain,
1610
- transport: viem.http()
1611
- }),
1612
- wallet: signer
1613
- }
1614
- });
1615
- BRIDGE_LOCATION = {
1616
- parents: 2,
1617
- interior: {
1618
- X1: [sdkCore.ETHEREUM_JUNCTION]
1619
- }
1620
- };
1621
- ERC20_TOKEN_LOCATION = {
1622
- parents: 2,
1623
- interior: {
1624
- X2: [{
1625
- GlobalConsensus: {
1626
- Ethereum: {
1627
- chain_id: sdkCore.ETH_CHAIN_ID
1628
- }
1629
- }
1630
- }, {
1631
- AccountKey20: {
1632
- key: foundAsset.assetId
1633
- }
1634
- }]
1635
- }
1636
- };
1637
- ERC20_TOKEN_LOCATION_REANCHORED = {
1638
- parents: 0,
1639
- interior: {
1640
- X1: [{
1641
- AccountKey20: {
1642
- key: foundAsset.assetId
1643
- }
1644
- }]
1645
- }
1646
- };
1647
- customXcm = [{
1648
- setAppendix: [{
1649
- depositAsset: {
1650
- assets: {
1651
- Wild: 'All'
1652
- },
1653
- beneficiary: {
1654
- parents: 0,
1655
- interior: {
1656
- x1: [{
1657
- AccountId32: {
1658
- id: util.u8aToHex(utilCrypto.decodeAddress(ahAddress))
1659
- }
1660
- }]
1661
- }
1662
- }
1663
- }
1664
- }]
1665
- }, {
1666
- initiateReserveWithdraw: {
1667
- assets: {
1668
- Wild: {
1669
- AllOf: {
1670
- id: ERC20_TOKEN_LOCATION,
1671
- fun: 'Fungible'
1672
- }
1673
- }
1674
- },
1675
- reserve: BRIDGE_LOCATION,
1676
- xcm: [{
1677
- buyExecution: {
1678
- fees: {
1679
- id: ERC20_TOKEN_LOCATION_REANCHORED,
1680
- // CAUTION: Must use reanchored locations.
1681
- fun: {
1682
- Fungible: '1' // Offering 1 unit as fee, but it is returned to the destination address.
1683
- }
1684
- },
1685
- weight_limit: 'Unlimited'
1686
- }
1687
- }, {
1688
- depositAsset: {
1689
- assets: {
1690
- Wild: {
1691
- AllCounted: 1
1692
- }
1693
- },
1694
- beneficiary: {
1695
- parents: 0,
1696
- interior: {
1697
- x1: [{
1698
- AccountKey20: {
1699
- key: address
1700
- }
1701
- }]
1702
- }
1703
- }
1704
- }
1705
- }, {
1706
- setTopic: '0x0000000000000000000000000000000000000000000000000000000000000000'
1707
- }]
1708
- }
1709
- }, {
1710
- setTopic: '0x0000000000000000000000000000000000000000000000000000000000000000'
1711
- }];
1712
- _context.next = 20;
1713
- return api.init(from);
1714
- case 20:
1715
- apiPjs = api.getApi();
1716
- _context.next = 23;
1717
- return api.createApiForNode('AssetHubPolkadot');
1718
- case 23:
1719
- assetHubApi = _context.sent;
1720
- assetHubApiPjs = assetHubApi.getApi(); // Generate an unique messageId and set into `setTopic` for remote track
1721
- xcmHash = assetHubApiPjs.createType('Xcm', customXcm);
1722
- if (!isEthersSigner(signer)) {
1723
- _context.next = 32;
1724
- break;
1725
- }
1726
- _context.next = 29;
1727
- return signer.getAddress();
1728
- case 29:
1729
- _context.t0 = _context.sent;
1730
- _context.next = 33;
1731
- break;
1732
- case 32:
1733
- _context.t0 = (_signer$account = signer.account) === null || _signer$account === undefined ? undefined : _signer$account.address;
1734
- case 33:
1735
- sender = _context.t0;
1736
- _context.next = 36;
1737
- return Promise.all([apiPjs.query.parachainInfo.parachainId(), apiPjs.rpc.system.accountNextIndex(sender)]);
1738
- case 36:
1739
- _yield$Promise$all = _context.sent;
1740
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
1741
- parachainId = _yield$Promise$all2[0];
1742
- accountNextId = _yield$Promise$all2[1];
1743
- entropy = new Uint8Array([].concat(_toConsumableArray(parachainId.toU8a()), _toConsumableArray(accountNextId.toU8a()), _toConsumableArray(xcmHash.toU8a())));
1744
- messageId = utilCrypto.blake2AsHex(entropy);
1745
- if (!(customXcm.length == 2)) {
1746
- _context.next = 47;
1747
- break;
1748
- }
1749
- customXcm[0].initiateReserveWithdraw.xcm[2].setTopic = messageId;
1750
- customXcm[1].setTopic = messageId;
1751
- _context.next = 53;
1752
- break;
1753
- case 47:
1754
- if (!(customXcm.length == 3)) {
1755
- _context.next = 52;
1756
- break;
1757
- }
1758
- customXcm[1].initiateReserveWithdraw.xcm[2].setTopic = messageId;
1759
- customXcm[2].setTopic = messageId;
1760
- _context.next = 53;
1761
- break;
1762
- case 52:
1763
- throw new Error('invalid xcm');
1764
- case 53:
1765
- xcmOnDest = assetHubApiPjs.createType('XcmVersionedXcm', {
1766
- V4: customXcm
1767
- });
1768
- customXcmOnDest = xcmOnDest.toHex();
1769
- _context.next = 57;
1770
- return sdkCore.getParaEthTransferFees(assetHubApi);
1771
- case 57:
1772
- _yield$getParaEthTran = _context.sent;
1773
- _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
1774
- bridgeFee = _yield$getParaEthTran2[0];
1775
- executionFee = _yield$getParaEthTran2[1];
1776
- transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
1777
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
1778
- createTx = function createTx(func, args) {
1779
- if (isEthersContract(contract)) {
1780
- return contract[func].apply(contract, _toConsumableArray(args));
1781
- }
1782
- return contract.write[func](args);
1783
- }; // Execute the custom XCM message with the precompile
1784
- _context.next = 65;
1785
- return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
1786
- // This represents (1,X1(Parachain(1000)))
1787
- [1, ['0x00' + util.numberToHex(sdkCore.getParaId('AssetHubPolkadot'), 32).slice(2)]],
1788
- // Assets including fee and the ERC20 asset, with fee be the first
1789
- [[XCDOT, transferFee], [ethAsset.assetId, currency.amount]],
1790
- // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
1791
- 2,
1792
- // index for the fee
1793
- 0,
1794
- // The TransferType corresponding to fee asset
1795
- 2, customXcmOnDest]);
1796
- case 65:
1797
- tx = _context.sent;
1798
- return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
1799
- case 67:
1800
- case "end":
1801
- return _context.stop();
1802
- }
1803
- }, _callee);
1804
- }));
1805
- return function transferMoonbeamToEth(_x) {
1806
- return _ref2.apply(this, arguments);
1807
- };
1808
- }();
1809
-
1810
1494
  /**
1811
1495
  * Builder class for constructing transfers from Ethereum to Polkadot.
1812
1496
  */
@@ -1908,9 +1592,9 @@ var EvmBuilderClass = /*#__PURE__*/function () {
1908
1592
  _context.next = 12;
1909
1593
  break;
1910
1594
  }
1911
- return _context.abrupt("return", transferMoonbeamToEth(this._options));
1595
+ return _context.abrupt("return", sdkCore.transferMoonbeamToEth(this._options));
1912
1596
  case 12:
1913
- if (!(this._options.from === 'Moonbeam' || this._options.from === 'Moonriver')) {
1597
+ if (!(this._options.from === 'Moonbeam' || this._options.from === 'Moonriver' || this._options.from === 'Darwinia')) {
1914
1598
  _context.next = 16;
1915
1599
  break;
1916
1600
  }
@@ -1992,6 +1676,7 @@ exports.getTransferInfo = getTransferInfo;
1992
1676
  exports.getTransferableAmount = getTransferableAmount;
1993
1677
  exports.send = send;
1994
1678
  exports.transferEthToPolkadot = transferEthToPolkadot;
1679
+ exports.verifyEdOnDestination = verifyEdOnDestination;
1995
1680
  exports.xcmPallet = transfer;
1996
1681
  Object.keys(sdkCore).forEach(function (k) {
1997
1682
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
package/dist/index.d.ts CHANGED
@@ -113,6 +113,9 @@ declare const getMaxForeignTransferableAmount: (options: _paraspell_sdk_core.TGe
113
113
  declare const getTransferableAmount: (options: _paraspell_sdk_core.TGetTransferableAmountOptionsBase & {
114
114
  api?: TPjsApiOrUrl;
115
115
  }) => Promise<bigint>;
116
+ declare const verifyEdOnDestination: (options: _paraspell_sdk_core.TVerifyEdOnDestinationOptionsBase & {
117
+ api?: TPjsApiOrUrl;
118
+ }) => Promise<boolean>;
116
119
 
117
120
  declare const assets_Foreign: typeof Foreign;
118
121
  declare const assets_ForeignAbstract: typeof ForeignAbstract;
@@ -142,8 +145,9 @@ declare const assets_getTransferInfo: typeof getTransferInfo;
142
145
  declare const assets_getTransferableAmount: typeof getTransferableAmount;
143
146
  declare const assets_hasSupportForAsset: typeof hasSupportForAsset;
144
147
  declare const assets_isNodeEvm: typeof isNodeEvm;
148
+ declare const assets_verifyEdOnDestination: typeof verifyEdOnDestination;
145
149
  declare namespace assets {
146
- export { assets_Foreign as Foreign, assets_ForeignAbstract as ForeignAbstract, assets_Native as Native, assets_Override as Override, assets_claimAssets as claimAssets, assets_getAllAssetsSymbols as getAllAssetsSymbols, assets_getAssetBalance as getAssetBalance, assets_getAssetBySymbolOrId as getAssetBySymbolOrId, assets_getAssetDecimals as getAssetDecimals, assets_getAssetId as getAssetId, assets_getAssets as getAssets, assets_getAssetsObject as getAssetsObject, assets_getBalanceForeign as getBalanceForeign, assets_getBalanceNative as getBalanceNative, assets_getExistentialDeposit as getExistentialDeposit, assets_getMaxForeignTransferableAmount as getMaxForeignTransferableAmount, assets_getMaxNativeTransferableAmount as getMaxNativeTransferableAmount, assets_getNativeAssetSymbol as getNativeAssetSymbol, assets_getNativeAssets as getNativeAssets, assets_getOriginFeeDetails as getOriginFeeDetails, assets_getOtherAssets as getOtherAssets, assets_getRelayChainSymbol as getRelayChainSymbol, assets_getSupportedAssets as getSupportedAssets, assets_getTNode as getTNode, assets_getTransferInfo as getTransferInfo, assets_getTransferableAmount as getTransferableAmount, assets_hasSupportForAsset as hasSupportForAsset, assets_isNodeEvm as isNodeEvm };
150
+ export { assets_Foreign as Foreign, assets_ForeignAbstract as ForeignAbstract, assets_Native as Native, assets_Override as Override, assets_claimAssets as claimAssets, assets_getAllAssetsSymbols as getAllAssetsSymbols, assets_getAssetBalance as getAssetBalance, assets_getAssetBySymbolOrId as getAssetBySymbolOrId, assets_getAssetDecimals as getAssetDecimals, assets_getAssetId as getAssetId, assets_getAssets as getAssets, assets_getAssetsObject as getAssetsObject, assets_getBalanceForeign as getBalanceForeign, assets_getBalanceNative as getBalanceNative, assets_getExistentialDeposit as getExistentialDeposit, assets_getMaxForeignTransferableAmount as getMaxForeignTransferableAmount, assets_getMaxNativeTransferableAmount as getMaxNativeTransferableAmount, assets_getNativeAssetSymbol as getNativeAssetSymbol, assets_getNativeAssets as getNativeAssets, assets_getOriginFeeDetails as getOriginFeeDetails, assets_getOtherAssets as getOtherAssets, assets_getRelayChainSymbol as getRelayChainSymbol, assets_getSupportedAssets as getSupportedAssets, assets_getTNode as getTNode, assets_getTransferInfo as getTransferInfo, assets_getTransferableAmount as getTransferableAmount, assets_hasSupportForAsset as hasSupportForAsset, assets_isNodeEvm as isNodeEvm, assets_verifyEdOnDestination as verifyEdOnDestination };
147
151
  }
148
152
 
149
153
  /**
@@ -152,7 +156,7 @@ declare namespace assets {
152
156
  declare class EvmBuilderClass<TApi, TRes> {
153
157
  _options: TOptionalEvmBuilderOptions<TApi, TRes>;
154
158
  constructor(api: IPolkadotApi<TApi, TRes>, provider?: AbstractProvider);
155
- from(node: 'Ethereum' | 'Moonbeam' | 'Moonriver'): this;
159
+ from(node: 'Ethereum' | 'Moonbeam' | 'Moonriver' | 'Darwinia'): this;
156
160
  /**
157
161
  * Specifies the destination node on Polkadot.
158
162
  *
@@ -210,4 +214,4 @@ type IFinalBuilderWithOptions = IFinalBuilderWithOptions$1<TPjsApi, Extrinsic>;
210
214
 
211
215
  declare const createApiInstanceForNode: (node: TNodeDotKsmWithRelayChains) => Promise<_polkadot_api.ApiPromise>;
212
216
 
213
- export { Builder, EvmBuilder, type Extrinsic, GeneralBuilder, type IFinalBuilderWithOptions, type TPjsApi, type TPjsApiOrUrl, approveToken, assets, claimAssets, createApiInstanceForNode, depositToken, getAssetBalance, getBalanceForeign, getBalanceNative, getDryRun, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, getTransferInfo, getTransferableAmount, send, transferEthToPolkadot, transfer as xcmPallet };
217
+ export { Builder, EvmBuilder, type Extrinsic, GeneralBuilder, type IFinalBuilderWithOptions, type TPjsApi, type TPjsApiOrUrl, approveToken, assets, claimAssets, createApiInstanceForNode, depositToken, getAssetBalance, getBalanceForeign, getBalanceNative, getDryRun, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, getTransferInfo, getTransferableAmount, send, transferEthToPolkadot, verifyEdOnDestination, transfer as xcmPallet };
package/dist/index.mjs CHANGED
@@ -1,13 +1,11 @@
1
- import { getParaId, isForeignAsset, InvalidCurrencyError, getAssetBySymbolOrId, isOverrideMultiLocationSpecifier, BatchMode, createApiInstanceForNode as createApiInstanceForNode$1, getNode, computeFeeFromDryRunPjs, resolveModuleError, getAssetsObject, send as send$1, getDryRun as getDryRun$1, getParaEthTransferFees as getParaEthTransferFees$1, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getTransferInfo as getTransferInfo$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, getMaxNativeTransferableAmount as getMaxNativeTransferableAmount$1, getMaxForeignTransferableAmount as getMaxForeignTransferableAmount$1, getTransferableAmount as getTransferableAmount$1, Foreign, ForeignAbstract, Native, Override, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTNode, hasSupportForAsset, isNodeEvm, ETH_CHAIN_ID, findAssetByMultiLocation, ETHEREUM_JUNCTION, transferMoonbeamEvm, validateAddress, Builder as Builder$1, GeneralBuilder as GeneralBuilder$1 } from '@paraspell/sdk-core';
1
+ import { getParaId, isForeignAsset, InvalidCurrencyError, getAssetBySymbolOrId, isEthersSigner, isOverrideMultiLocationSpecifier, BatchMode, createApiInstanceForNode as createApiInstanceForNode$1, getNode, computeFeeFromDryRunPjs, resolveModuleError, getAssetsObject, getParaEthTransferFees as getParaEthTransferFees$1, send as send$1, getDryRun as getDryRun$1, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getTransferInfo as getTransferInfo$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, getMaxNativeTransferableAmount as getMaxNativeTransferableAmount$1, getMaxForeignTransferableAmount as getMaxForeignTransferableAmount$1, getTransferableAmount as getTransferableAmount$1, verifyEdOnDestination as verifyEdOnDestination$1, Foreign, ForeignAbstract, Native, Override, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTNode, hasSupportForAsset, isNodeEvm, transferMoonbeamEvm, validateAddress, transferMoonbeamToEth, GeneralBuilder as GeneralBuilder$1, Builder as Builder$1 } from '@paraspell/sdk-core';
2
2
  export * from '@paraspell/sdk-core';
3
3
  import { Context, toPolkadotV2, assetsV2, environment } from '@snowbridge/api';
4
4
  import { WETH9__factory } from '@snowbridge/contract-types';
5
5
  import { WsProvider, ApiPromise } from '@polkadot/api';
6
6
  import { u32 } from '@polkadot/types';
7
7
  import { decodeAddress, blake2AsHex } from '@polkadot/util-crypto';
8
- import { isHex, u8aToHex, numberToHex } from '@polkadot/util';
9
- import { Contract } from 'ethers';
10
- import { getContract, createPublicClient, http } from 'viem';
8
+ import { isHex, u8aToHex, hexToU8a, stringToU8a } from '@polkadot/util';
11
9
 
12
10
  function _arrayLikeToArray(r, a) {
13
11
  (null == a || a > r.length) && (a = r.length);
@@ -17,9 +15,6 @@ function _arrayLikeToArray(r, a) {
17
15
  function _arrayWithHoles(r) {
18
16
  if (Array.isArray(r)) return r;
19
17
  }
20
- function _arrayWithoutHoles(r) {
21
- if (Array.isArray(r)) return _arrayLikeToArray(r);
22
- }
23
18
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
24
19
  try {
25
20
  var i = n[a](c),
@@ -41,7 +36,7 @@ function _asyncToGenerator(n) {
41
36
  function _throw(n) {
42
37
  asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
43
38
  }
44
- _next(undefined);
39
+ _next(void 0);
45
40
  });
46
41
  };
47
42
  }
@@ -67,9 +62,6 @@ function _defineProperty(e, r, t) {
67
62
  writable: true
68
63
  }) : e[r] = t, e;
69
64
  }
70
- function _iterableToArray(r) {
71
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
72
- }
73
65
  function _iterableToArrayLimit(r, l) {
74
66
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
75
67
  if (null != t) {
@@ -97,9 +89,6 @@ function _iterableToArrayLimit(r, l) {
97
89
  function _nonIterableRest() {
98
90
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
91
  }
100
- function _nonIterableSpread() {
101
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
- }
103
92
  function ownKeys(e, r) {
104
93
  var t = Object.keys(e);
105
94
  if (Object.getOwnPropertySymbols) {
@@ -321,7 +310,7 @@ function _regeneratorRuntime() {
321
310
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
322
311
  return this;
323
312
  }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
324
- undefined === i && (i = Promise);
313
+ void 0 === i && (i = Promise);
325
314
  var a = new AsyncIterator(wrap(t, r, n, o), i);
326
315
  return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
327
316
  return t.done ? t.value : a.next();
@@ -425,14 +414,11 @@ function _regeneratorRuntime() {
425
414
  function _slicedToArray(r, e) {
426
415
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
427
416
  }
428
- function _toConsumableArray(r) {
429
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
430
- }
431
417
  function _toPrimitive(t, r) {
432
418
  if ("object" != typeof t || !t) return t;
433
419
  var e = t[Symbol.toPrimitive];
434
- if (undefined !== e) {
435
- var i = e.call(t, r || "default");
420
+ if (void 0 !== e) {
421
+ var i = e.call(t, r);
436
422
  if ("object" != typeof i) return i;
437
423
  throw new TypeError("@@toPrimitive must return a primitive value.");
438
424
  }
@@ -442,20 +428,11 @@ function _toPropertyKey(t) {
442
428
  var i = _toPrimitive(t, "string");
443
429
  return "symbol" == typeof i ? i : i + "";
444
430
  }
445
- function _typeof(o) {
446
- "@babel/helpers - typeof";
447
-
448
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
449
- return typeof o;
450
- } : function (o) {
451
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
452
- }, _typeof(o);
453
- }
454
431
  function _unsupportedIterableToArray(r, a) {
455
432
  if (r) {
456
433
  if ("string" == typeof r) return _arrayLikeToArray(r, a);
457
434
  var t = {}.toString.call(r).slice(8, -1);
458
- 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) : undefined;
435
+ 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;
459
436
  }
460
437
  }
461
438
 
@@ -478,13 +455,6 @@ var createContext = function createContext(executionUrl, config) {
478
455
  });
479
456
  };
480
457
 
481
- var isEthersSigner = function isEthersSigner(signer) {
482
- return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
483
- };
484
- var isEthersContract = function isEthersContract(contract) {
485
- return !('abi' in contract);
486
- };
487
-
488
458
  /**
489
459
  * Transfers an Ethereum asset to a Polkadot account.
490
460
  *
@@ -845,7 +815,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
845
815
  _context.next = 16;
846
816
  break;
847
817
  case 8:
848
- if (!((_this$_api = this._api) !== null && _this$_api !== undefined)) {
818
+ if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
849
819
  _context.next = 12;
850
820
  break;
851
821
  }
@@ -921,6 +891,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
921
891
  var section = mode === BatchMode.BATCH_ALL ? 'batchAll' : 'batch';
922
892
  return this.api.tx.utility[section](calls);
923
893
  }
894
+ }, {
895
+ key: "objectToHex",
896
+ value: function objectToHex(obj, typeName) {
897
+ return Promise.resolve(this.api.createType(typeName, obj).toHex());
898
+ }
899
+ }, {
900
+ key: "hexToUint8a",
901
+ value: function hexToUint8a(hex) {
902
+ return hexToU8a(hex);
903
+ }
904
+ }, {
905
+ key: "stringToUint8a",
906
+ value: function stringToUint8a(str) {
907
+ return stringToU8a(str);
908
+ }
924
909
  }, {
925
910
  key: "calculateTransactionFee",
926
911
  value: function () {
@@ -1148,7 +1133,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1148
1133
  var assetItem = _ref3$0$args[1];
1149
1134
  _ref3[1];
1150
1135
  var assetSymbol = assetItem.toString().toLowerCase();
1151
- return assetSymbol === ((_asset$symbol = asset.symbol) === null || _asset$symbol === undefined ? undefined : _asset$symbol.toLowerCase()) || isForeignAsset(asset) && assetSymbol === ((_asset$assetId = asset.assetId) === null || _asset$assetId === undefined ? undefined : _asset$assetId.toLowerCase()) || Object.values((_assetItem$toHuman = assetItem.toHuman()) !== null && _assetItem$toHuman !== undefined ? _assetItem$toHuman : {}).toString().toLowerCase() === ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === undefined ? undefined : _asset$symbol2.toLowerCase()) || isForeignAsset(asset) && Object.values((_assetItem$toHuman2 = assetItem.toHuman()) !== null && _assetItem$toHuman2 !== undefined ? _assetItem$toHuman2 : {}).toString().toLowerCase() === ((_asset$assetId2 = asset.assetId) === null || _asset$assetId2 === undefined ? undefined : _asset$assetId2.toLowerCase());
1136
+ return assetSymbol === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase()) || isForeignAsset(asset) && assetSymbol === ((_asset$assetId = asset.assetId) === null || _asset$assetId === void 0 ? void 0 : _asset$assetId.toLowerCase()) || Object.values((_assetItem$toHuman = assetItem.toHuman()) !== null && _assetItem$toHuman !== void 0 ? _assetItem$toHuman : {}).toString().toLowerCase() === ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toLowerCase()) || isForeignAsset(asset) && Object.values((_assetItem$toHuman2 = assetItem.toHuman()) !== null && _assetItem$toHuman2 !== void 0 ? _assetItem$toHuman2 : {}).toString().toLowerCase() === ((_asset$assetId2 = asset.assetId) === null || _asset$assetId2 === void 0 ? void 0 : _asset$assetId2.toLowerCase());
1152
1137
  });
1153
1138
  accountData = entry ? entry[1] : null;
1154
1139
  return _context11.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
@@ -1189,29 +1174,41 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1189
1174
  return getBalanceForeignAssetsAccount;
1190
1175
  }()
1191
1176
  }, {
1192
- key: "getFromStorage",
1177
+ key: "getFromRpc",
1193
1178
  value: function () {
1194
- var _getFromStorage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(key) {
1195
- var response;
1179
+ var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(module, method, key) {
1180
+ var rpcModule, response;
1196
1181
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1197
1182
  while (1) switch (_context13.prev = _context13.next) {
1198
1183
  case 0:
1199
- _context13.next = 2;
1200
- return this.api.rpc.state.getStorage(key);
1201
- case 2:
1184
+ rpcModule = this.api.rpc[module];
1185
+ if (!(!rpcModule || !rpcModule[method])) {
1186
+ _context13.next = 3;
1187
+ break;
1188
+ }
1189
+ throw new Error("RPC method ".concat(module, ".").concat(method, " not available"));
1190
+ case 3:
1191
+ _context13.next = 5;
1192
+ return rpcModule[method](key);
1193
+ case 5:
1202
1194
  response = _context13.sent;
1203
1195
  return _context13.abrupt("return", response.toHex());
1204
- case 4:
1196
+ case 7:
1205
1197
  case "end":
1206
1198
  return _context13.stop();
1207
1199
  }
1208
1200
  }, _callee13, this);
1209
1201
  }));
1210
- function getFromStorage(_x22) {
1211
- return _getFromStorage.apply(this, arguments);
1202
+ function getFromRpc(_x22, _x23, _x24) {
1203
+ return _getFromRpc.apply(this, arguments);
1212
1204
  }
1213
- return getFromStorage;
1205
+ return getFromRpc;
1214
1206
  }()
1207
+ }, {
1208
+ key: "blake2AsHex",
1209
+ value: function blake2AsHex$1(data) {
1210
+ return blake2AsHex(data);
1211
+ }
1215
1212
  }, {
1216
1213
  key: "clone",
1217
1214
  value: function clone() {
@@ -1236,7 +1233,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1236
1233
  }
1237
1234
  }, _callee14);
1238
1235
  }));
1239
- function createApiForNode(_x23) {
1236
+ function createApiForNode(_x25) {
1240
1237
  return _createApiForNode.apply(this, arguments);
1241
1238
  }
1242
1239
  return createApiForNode;
@@ -1292,7 +1289,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1292
1289
  }
1293
1290
  }, _callee15, this);
1294
1291
  }));
1295
- function getDryRun(_x24) {
1292
+ function getDryRun(_x26) {
1296
1293
  return _getDryRun.apply(this, arguments);
1297
1294
  }
1298
1295
  return getDryRun;
@@ -1458,6 +1455,7 @@ var getOriginFeeDetails = createPolkadotJsApiCall(getOriginFeeDetails$1);
1458
1455
  var getMaxNativeTransferableAmount = createPolkadotJsApiCall(getMaxNativeTransferableAmount$1);
1459
1456
  var getMaxForeignTransferableAmount = createPolkadotJsApiCall(getMaxForeignTransferableAmount$1);
1460
1457
  var getTransferableAmount = createPolkadotJsApiCall(getTransferableAmount$1);
1458
+ var verifyEdOnDestination = createPolkadotJsApiCall(verifyEdOnDestination$1);
1461
1459
 
1462
1460
  var assets = /*#__PURE__*/Object.freeze({
1463
1461
  __proto__: null,
@@ -1488,324 +1486,10 @@ var assets = /*#__PURE__*/Object.freeze({
1488
1486
  getTransferInfo: getTransferInfo,
1489
1487
  getTransferableAmount: getTransferableAmount,
1490
1488
  hasSupportForAsset: hasSupportForAsset,
1491
- isNodeEvm: isNodeEvm
1489
+ isNodeEvm: isNodeEvm,
1490
+ verifyEdOnDestination: verifyEdOnDestination
1492
1491
  });
1493
1492
 
1494
- var abi = [
1495
- {
1496
- inputs: [
1497
- {
1498
- components: [
1499
- {
1500
- internalType: "uint8",
1501
- name: "parents",
1502
- type: "uint8"
1503
- },
1504
- {
1505
- internalType: "bytes[]",
1506
- name: "interior",
1507
- type: "bytes[]"
1508
- }
1509
- ],
1510
- internalType: "struct XCM.Location",
1511
- name: "dest",
1512
- type: "tuple"
1513
- },
1514
- {
1515
- components: [
1516
- {
1517
- internalType: "address",
1518
- name: "asset",
1519
- type: "address"
1520
- },
1521
- {
1522
- internalType: "uint256",
1523
- name: "amount",
1524
- type: "uint256"
1525
- }
1526
- ],
1527
- internalType: "struct XCM.AssetAddressInfo[]",
1528
- name: "assets",
1529
- type: "tuple[]"
1530
- },
1531
- {
1532
- internalType: "enum XCM.TransferType",
1533
- name: "assetsTransferType",
1534
- type: "uint8"
1535
- },
1536
- {
1537
- internalType: "uint8",
1538
- name: "remoteFeesIdIndex",
1539
- type: "uint8"
1540
- },
1541
- {
1542
- internalType: "enum XCM.TransferType",
1543
- name: "feesTransferType",
1544
- type: "uint8"
1545
- },
1546
- {
1547
- internalType: "bytes",
1548
- name: "customXcmOnDest",
1549
- type: "bytes"
1550
- }
1551
- ],
1552
- name: "transferAssetsUsingTypeAndThenAddress",
1553
- outputs: [
1554
- ],
1555
- stateMutability: "nonpayable",
1556
- type: "function"
1557
- }
1558
- ];
1559
-
1560
- // https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
1561
- var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
1562
- var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
1563
- var transferMoonbeamToEth = /*#__PURE__*/function () {
1564
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1565
- var _signer$account;
1566
- var api, from, to, signer, address, ahAddress, currency, foundAsset, ethAsset, contract, BRIDGE_LOCATION, ERC20_TOKEN_LOCATION, ERC20_TOKEN_LOCATION_REANCHORED, customXcm, apiPjs, assetHubApi, assetHubApiPjs, xcmHash, sender, _yield$Promise$all, _yield$Promise$all2, parachainId, accountNextId, entropy, messageId, xcmOnDest, customXcmOnDest, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, tx;
1567
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1568
- while (1) switch (_context.prev = _context.next) {
1569
- case 0:
1570
- api = _ref.api, from = _ref.from, to = _ref.to, signer = _ref.signer, address = _ref.address, ahAddress = _ref.ahAddress, currency = _ref.currency;
1571
- if (!('multiasset' in currency)) {
1572
- _context.next = 3;
1573
- break;
1574
- }
1575
- throw new Error('Multiassets syntax is not supported for Evm transfers');
1576
- case 3:
1577
- if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
1578
- _context.next = 5;
1579
- break;
1580
- }
1581
- throw new Error('Override multilocation is not supported for Evm transfers');
1582
- case 5:
1583
- foundAsset = getAssetBySymbolOrId(from, currency, to);
1584
- if (!(foundAsset === null)) {
1585
- _context.next = 8;
1586
- break;
1587
- }
1588
- throw new InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
1589
- case 8:
1590
- if (!(!isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
1591
- _context.next = 10;
1592
- break;
1593
- }
1594
- throw new InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
1595
- case 10:
1596
- ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), foundAsset.multiLocation);
1597
- if (ethAsset) {
1598
- _context.next = 13;
1599
- break;
1600
- }
1601
- throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
1602
- case 13:
1603
- contract = isEthersSigner(signer) ? new Contract(xcmInterfacePrecompile, abi, signer) : getContract({
1604
- abi: abi,
1605
- address: xcmInterfacePrecompile,
1606
- client: {
1607
- "public": createPublicClient({
1608
- chain: signer.chain,
1609
- transport: http()
1610
- }),
1611
- wallet: signer
1612
- }
1613
- });
1614
- BRIDGE_LOCATION = {
1615
- parents: 2,
1616
- interior: {
1617
- X1: [ETHEREUM_JUNCTION]
1618
- }
1619
- };
1620
- ERC20_TOKEN_LOCATION = {
1621
- parents: 2,
1622
- interior: {
1623
- X2: [{
1624
- GlobalConsensus: {
1625
- Ethereum: {
1626
- chain_id: ETH_CHAIN_ID
1627
- }
1628
- }
1629
- }, {
1630
- AccountKey20: {
1631
- key: foundAsset.assetId
1632
- }
1633
- }]
1634
- }
1635
- };
1636
- ERC20_TOKEN_LOCATION_REANCHORED = {
1637
- parents: 0,
1638
- interior: {
1639
- X1: [{
1640
- AccountKey20: {
1641
- key: foundAsset.assetId
1642
- }
1643
- }]
1644
- }
1645
- };
1646
- customXcm = [{
1647
- setAppendix: [{
1648
- depositAsset: {
1649
- assets: {
1650
- Wild: 'All'
1651
- },
1652
- beneficiary: {
1653
- parents: 0,
1654
- interior: {
1655
- x1: [{
1656
- AccountId32: {
1657
- id: u8aToHex(decodeAddress(ahAddress))
1658
- }
1659
- }]
1660
- }
1661
- }
1662
- }
1663
- }]
1664
- }, {
1665
- initiateReserveWithdraw: {
1666
- assets: {
1667
- Wild: {
1668
- AllOf: {
1669
- id: ERC20_TOKEN_LOCATION,
1670
- fun: 'Fungible'
1671
- }
1672
- }
1673
- },
1674
- reserve: BRIDGE_LOCATION,
1675
- xcm: [{
1676
- buyExecution: {
1677
- fees: {
1678
- id: ERC20_TOKEN_LOCATION_REANCHORED,
1679
- // CAUTION: Must use reanchored locations.
1680
- fun: {
1681
- Fungible: '1' // Offering 1 unit as fee, but it is returned to the destination address.
1682
- }
1683
- },
1684
- weight_limit: 'Unlimited'
1685
- }
1686
- }, {
1687
- depositAsset: {
1688
- assets: {
1689
- Wild: {
1690
- AllCounted: 1
1691
- }
1692
- },
1693
- beneficiary: {
1694
- parents: 0,
1695
- interior: {
1696
- x1: [{
1697
- AccountKey20: {
1698
- key: address
1699
- }
1700
- }]
1701
- }
1702
- }
1703
- }
1704
- }, {
1705
- setTopic: '0x0000000000000000000000000000000000000000000000000000000000000000'
1706
- }]
1707
- }
1708
- }, {
1709
- setTopic: '0x0000000000000000000000000000000000000000000000000000000000000000'
1710
- }];
1711
- _context.next = 20;
1712
- return api.init(from);
1713
- case 20:
1714
- apiPjs = api.getApi();
1715
- _context.next = 23;
1716
- return api.createApiForNode('AssetHubPolkadot');
1717
- case 23:
1718
- assetHubApi = _context.sent;
1719
- assetHubApiPjs = assetHubApi.getApi(); // Generate an unique messageId and set into `setTopic` for remote track
1720
- xcmHash = assetHubApiPjs.createType('Xcm', customXcm);
1721
- if (!isEthersSigner(signer)) {
1722
- _context.next = 32;
1723
- break;
1724
- }
1725
- _context.next = 29;
1726
- return signer.getAddress();
1727
- case 29:
1728
- _context.t0 = _context.sent;
1729
- _context.next = 33;
1730
- break;
1731
- case 32:
1732
- _context.t0 = (_signer$account = signer.account) === null || _signer$account === undefined ? undefined : _signer$account.address;
1733
- case 33:
1734
- sender = _context.t0;
1735
- _context.next = 36;
1736
- return Promise.all([apiPjs.query.parachainInfo.parachainId(), apiPjs.rpc.system.accountNextIndex(sender)]);
1737
- case 36:
1738
- _yield$Promise$all = _context.sent;
1739
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
1740
- parachainId = _yield$Promise$all2[0];
1741
- accountNextId = _yield$Promise$all2[1];
1742
- entropy = new Uint8Array([].concat(_toConsumableArray(parachainId.toU8a()), _toConsumableArray(accountNextId.toU8a()), _toConsumableArray(xcmHash.toU8a())));
1743
- messageId = blake2AsHex(entropy);
1744
- if (!(customXcm.length == 2)) {
1745
- _context.next = 47;
1746
- break;
1747
- }
1748
- customXcm[0].initiateReserveWithdraw.xcm[2].setTopic = messageId;
1749
- customXcm[1].setTopic = messageId;
1750
- _context.next = 53;
1751
- break;
1752
- case 47:
1753
- if (!(customXcm.length == 3)) {
1754
- _context.next = 52;
1755
- break;
1756
- }
1757
- customXcm[1].initiateReserveWithdraw.xcm[2].setTopic = messageId;
1758
- customXcm[2].setTopic = messageId;
1759
- _context.next = 53;
1760
- break;
1761
- case 52:
1762
- throw new Error('invalid xcm');
1763
- case 53:
1764
- xcmOnDest = assetHubApiPjs.createType('XcmVersionedXcm', {
1765
- V4: customXcm
1766
- });
1767
- customXcmOnDest = xcmOnDest.toHex();
1768
- _context.next = 57;
1769
- return getParaEthTransferFees$1(assetHubApi);
1770
- case 57:
1771
- _yield$getParaEthTran = _context.sent;
1772
- _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
1773
- bridgeFee = _yield$getParaEthTran2[0];
1774
- executionFee = _yield$getParaEthTran2[1];
1775
- transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
1776
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
1777
- createTx = function createTx(func, args) {
1778
- if (isEthersContract(contract)) {
1779
- return contract[func].apply(contract, _toConsumableArray(args));
1780
- }
1781
- return contract.write[func](args);
1782
- }; // Execute the custom XCM message with the precompile
1783
- _context.next = 65;
1784
- return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
1785
- // This represents (1,X1(Parachain(1000)))
1786
- [1, ['0x00' + numberToHex(getParaId('AssetHubPolkadot'), 32).slice(2)]],
1787
- // Assets including fee and the ERC20 asset, with fee be the first
1788
- [[XCDOT, transferFee], [ethAsset.assetId, currency.amount]],
1789
- // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
1790
- 2,
1791
- // index for the fee
1792
- 0,
1793
- // The TransferType corresponding to fee asset
1794
- 2, customXcmOnDest]);
1795
- case 65:
1796
- tx = _context.sent;
1797
- return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
1798
- case 67:
1799
- case "end":
1800
- return _context.stop();
1801
- }
1802
- }, _callee);
1803
- }));
1804
- return function transferMoonbeamToEth(_x) {
1805
- return _ref2.apply(this, arguments);
1806
- };
1807
- }();
1808
-
1809
1493
  /**
1810
1494
  * Builder class for constructing transfers from Ethereum to Polkadot.
1811
1495
  */
@@ -1909,7 +1593,7 @@ var EvmBuilderClass = /*#__PURE__*/function () {
1909
1593
  }
1910
1594
  return _context.abrupt("return", transferMoonbeamToEth(this._options));
1911
1595
  case 12:
1912
- if (!(this._options.from === 'Moonbeam' || this._options.from === 'Moonriver')) {
1596
+ if (!(this._options.from === 'Moonbeam' || this._options.from === 'Moonriver' || this._options.from === 'Darwinia')) {
1913
1597
  _context.next = 16;
1914
1598
  break;
1915
1599
  }
@@ -1970,4 +1654,4 @@ var EvmBuilder = function EvmBuilder(provider) {
1970
1654
  return EvmBuilder$1(pjsApi, provider);
1971
1655
  };
1972
1656
 
1973
- export { Builder, EvmBuilder, GeneralBuilder, approveToken, assets, claimAssets, createApiInstanceForNode, depositToken, getAssetBalance, getBalanceForeign, getBalanceNative, getDryRun, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, getTransferInfo, getTransferableAmount, send, transferEthToPolkadot, transfer as xcmPallet };
1657
+ export { Builder, EvmBuilder, GeneralBuilder, approveToken, assets, claimAssets, createApiInstanceForNode, depositToken, getAssetBalance, getBalanceForeign, getBalanceNative, getDryRun, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, getTransferInfo, getTransferableAmount, send, transferEthToPolkadot, verifyEdOnDestination, transfer as xcmPallet };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-pjs",
3
- "version": "8.5.2",
3
+ "version": "8.6.0",
4
4
  "description": "Polkadot.js based SDK for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,11 +23,11 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@snowbridge/api": "^0.1.32",
27
- "@snowbridge/contract-types": "^0.1.32",
26
+ "@snowbridge/api": "0.1.32",
27
+ "@snowbridge/contract-types": "0.1.32",
28
28
  "ethers": "^6.13.5",
29
- "viem": "^2.22.22",
30
- "@paraspell/sdk-core": "8.5.2"
29
+ "viem": "^2.23.5",
30
+ "@paraspell/sdk-core": "8.6.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@polkadot/api": ">= 15.0 < 16",
@@ -38,16 +38,16 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@babel/plugin-syntax-import-attributes": "^7.26.0",
41
- "@babel/preset-env": "^7.26.7",
42
- "@codecov/rollup-plugin": "^1.8.0",
41
+ "@babel/preset-env": "^7.26.9",
42
+ "@codecov/rollup-plugin": "^1.9.0",
43
43
  "@rollup/plugin-babel": "^6.0.4",
44
44
  "@rollup/plugin-json": "^6.1.0",
45
45
  "@rollup/plugin-typescript": "^12.1.2",
46
- "@vitest/coverage-v8": "^3.0.4",
47
- "axios": "^1.7.9",
46
+ "@vitest/coverage-v8": "^3.0.7",
47
+ "axios": "^1.8.1",
48
48
  "dotenv": "^16.4.7",
49
- "prettier": "^3.4.2",
50
- "rollup": "^4.32.0",
49
+ "prettier": "^3.5.2",
50
+ "rollup": "^4.34.8",
51
51
  "rollup-plugin-dts": "^6.1.1",
52
52
  "tslib": "^2.8.1"
53
53
  },