@paraspell/sdk-pjs 12.8.9 → 12.9.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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/dist/index.mjs +171 -91
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -28,20 +28,20 @@
28
28
 
29
29
  ### Install dependencies
30
30
 
31
- ParaSpell XCM SDK is the 🥇 in the ecosystem to support both **PolkadotJS** and **PolkadotAPI**.
31
+ ParaSpell XCM SDK is the 🥇 in the ecosystem to support **PolkadotJS**, **Dedot** and **PolkadotAPI**.
32
32
 
33
- **This version of SDK uses PolkadotJS** if you wish to use **PolkadotAPI** version please reffer to [following package](https://github.com/paraspell/xcm-tools/tree/main/packages/sdk).
33
+ **This version of SDK uses PolkadotJS** if you wish to use **PolkadotAPI** version please reffer to [following package](https://github.com/paraspell/xcm-tools/tree/main/packages/sdk) or or **Dedot** please reffer to [following package](https://github.com/paraspell/xcm-tools/tree/main/packages/sdk-dedot)..
34
34
 
35
35
 
36
36
  ```bash
37
37
  #PolkadotJS peer dependencies
38
- pnpm | npm install || yarn add @polkadot/api @polkadot/types @polkadot/api-base @polkadot/util @polkadot/util-crypto
38
+ npm install | pnpm add | yarn add @polkadot/api @polkadot/types @polkadot/api-base @polkadot/util @polkadot/util-crypto
39
39
  ```
40
40
 
41
41
  ### Install SDK
42
42
 
43
43
  ```bash
44
- pnpm | npm install || yarn add @paraspell/sdk-pjs
44
+ npm install | pnpm add | yarn add @paraspell/sdk-pjs
45
45
  ```
46
46
 
47
47
  ### Importing package to your project
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { getEvmPrivateKeyHex, createClientCache, createClientPoolHelpers, isConfig, getChainProviders, BatchMode, findNativeAssetInfoOrThrow, isSenderSigner, MissingChainApiError, isExternalChain, UnsupportedOperationError, findAssetInfoOrThrow, computeFeeFromDryRunPjs, hasXcmPaymentApiSupport, resolveModuleError, getAssetsObject, RuntimeApiUnavailableError, wrapTxBypass, localizeLocation, addXcmVersionHeader, isAssetXcEqual, RELAY_LOCATION, getRelayChainOf, createChainClient as createChainClient$1, getBalance as getBalance$1, claimAssets as claimAssets$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, assertHasId, getParaId, RoutingResolutionError, abstractDecimals, MissingParameterError, isOverrideLocationSpecifier, transferMoonbeamEvm, transferMoonbeamToEth, validateAddress as validateAddress$1, Builder as Builder$1, getBridgeStatus as getBridgeStatus$1, getParaEthTransferFees as getParaEthTransferFees$1, DRY_RUN_CLIENT_TIMEOUT_MS, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
1
+ import { getNativeAssetSymbol, getOtherAssets, hasJunction, getJunctionValue, getEvmPrivateKeyHex, createClientCache, MAX_CLIENTS, EXTENSION_MS, createClientPoolHelpers, BatchMode, isConfig, findNativeAssetInfoOrThrow, getChainProviders, isSenderSigner, DEFAULT_TTL_MS, resolveChainApi, isExternalChain, UnsupportedOperationError, findAssetInfoOrThrow, hasXcmPaymentApiSupport, resolveModuleError, getAssetsObject, RuntimeApiUnavailableError, wrapTxBypass, localizeLocation, addXcmVersionHeader, isAssetXcEqual, RELAY_LOCATION, getRelayChainOf, createChainClient as createChainClient$1, getBalance as getBalance$1, claimAssets as claimAssets$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, assertHasId, getParaId, RoutingResolutionError, abstractDecimals, MissingParameterError, isOverrideLocationSpecifier, transferMoonbeamEvm, transferMoonbeamToEth, validateAddress as validateAddress$1, Builder as Builder$1, getBridgeStatus as getBridgeStatus$1, getParaEthTransferFees as getParaEthTransferFees$1, DRY_RUN_CLIENT_TIMEOUT_MS, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
2
2
  export * from '@paraspell/sdk-core';
3
3
  import { Keyring, WsProvider, ApiPromise } from '@polkadot/api';
4
4
  import { isHex, u8aToHex, hexToU8a, stringToU8a } from '@polkadot/util';
@@ -7,23 +7,6 @@ import { WETH9__factory } from '@snowbridge/contract-types';
7
7
  import { bridgeInfoFor } from '@snowbridge/registry';
8
8
  import { Context, toPolkadotV2 } from '@snowbridge/api';
9
9
 
10
- var createKeyringPair = function createKeyringPair(path) {
11
- var evmPrivateKey = getEvmPrivateKeyHex(path);
12
- var keyring = evmPrivateKey ? new Keyring() : new Keyring({
13
- type: 'sr25519'
14
- });
15
- return evmPrivateKey ? keyring.createFromUri(evmPrivateKey, undefined, 'ethereum') : keyring.addFromUri(path);
16
- };
17
-
18
- var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
19
- return value.charAt(0).toLowerCase() + value.slice(1);
20
- };
21
- var snakeToCamel = function snakeToCamel(str) {
22
- return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
23
- return group.toUpperCase().replace('-', '').replace('_', '');
24
- });
25
- };
26
-
27
10
  function _arrayLikeToArray(r, a) {
28
11
  (null == a || a > r.length) && (a = r.length);
29
12
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -71,6 +54,54 @@ function _createClass(e, r, t) {
71
54
  writable: false
72
55
  }), e;
73
56
  }
57
+ function _createForOfIteratorHelper(r, e) {
58
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
59
+ if (!t) {
60
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
61
+ t && (r = t);
62
+ var n = 0,
63
+ F = function () {};
64
+ return {
65
+ s: F,
66
+ n: function () {
67
+ return n >= r.length ? {
68
+ done: true
69
+ } : {
70
+ done: false,
71
+ value: r[n++]
72
+ };
73
+ },
74
+ e: function (r) {
75
+ throw r;
76
+ },
77
+ f: F
78
+ };
79
+ }
80
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
+ }
82
+ var o,
83
+ a = true,
84
+ u = false;
85
+ return {
86
+ s: function () {
87
+ t = t.call(r);
88
+ },
89
+ n: function () {
90
+ var r = t.next();
91
+ return a = r.done, r;
92
+ },
93
+ e: function (r) {
94
+ u = true, o = r;
95
+ },
96
+ f: function () {
97
+ try {
98
+ a || null == t.return || t.return();
99
+ } finally {
100
+ if (u) throw o;
101
+ }
102
+ }
103
+ };
104
+ }
74
105
  function _defineProperty(e, r, t) {
75
106
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
76
107
  value: t,
@@ -248,10 +279,85 @@ function _unsupportedIterableToArray(r, a) {
248
279
  }
249
280
  }
250
281
 
251
- // Cache settings
252
- var DEFAULT_TTL_MS = 60000; // 1 minute
253
- var MAX_CLIENTS = 100;
254
- var EXTENSION_MS = 5 * 60000; // 5 minutes
282
+ var getLocationTokenId = function getLocationTokenId(location, chain) {
283
+ if (location.interior === 'Here') {
284
+ // native token
285
+ return getNativeAssetSymbol(chain);
286
+ }
287
+ var foreignAssets = getOtherAssets(chain);
288
+ if (location.interior.X2 && hasJunction(location, 'PalletInstance', '50') && hasJunction(location, 'GeneralIndex')) {
289
+ var _foreignAssets$find$s, _foreignAssets$find;
290
+ var assetId = getJunctionValue(location, 'GeneralIndex');
291
+ return (_foreignAssets$find$s = (_foreignAssets$find = foreignAssets.find(function (asset) {
292
+ return asset.assetId === String(assetId);
293
+ })) === null || _foreignAssets$find === void 0 ? void 0 : _foreignAssets$find.symbol) !== null && _foreignAssets$find$s !== void 0 ? _foreignAssets$find$s : null;
294
+ }
295
+ return null;
296
+ };
297
+
298
+ var computeOriginFee = function computeOriginFee(dryRun, chain, executionFee) {
299
+ // Extract delivery fees from emitted events
300
+ var deliveryFees = [];
301
+ var _iterator = _createForOfIteratorHelper(dryRun.Ok.emittedEvents),
302
+ _step;
303
+ try {
304
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
305
+ var e = _step.value;
306
+ var isXcmEvent = e.section === 'xcmPallet' || e.section === 'polkadotXcm' || e.section === 'cumulusXcm';
307
+ var isFeesPaid = e.method === 'FeesPaid';
308
+ if (isXcmEvent && isFeesPaid && e.data.fees) {
309
+ var _iterator2 = _createForOfIteratorHelper(e.data.fees),
310
+ _step2;
311
+ try {
312
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
313
+ var feeItem = _step2.value;
314
+ if (feeItem.fun.NonFungible) continue;
315
+ var plancks = BigInt(feeItem.fun.Fungible.replace(/,/g, ''));
316
+ var tokenSymbol = getLocationTokenId(feeItem.id, chain);
317
+ if (!tokenSymbol || !plancks) continue;
318
+ deliveryFees.push({
319
+ plancks: plancks,
320
+ tokenSymbol: tokenSymbol
321
+ });
322
+ }
323
+ } catch (err) {
324
+ _iterator2.e(err);
325
+ } finally {
326
+ _iterator2.f();
327
+ }
328
+ }
329
+ }
330
+ } catch (err) {
331
+ _iterator.e(err);
332
+ } finally {
333
+ _iterator.f();
334
+ }
335
+ var nativeAssetSymbol = getNativeAssetSymbol(chain);
336
+ // Sum the fees that match the feeToken
337
+ var totalDeliveryFees = deliveryFees.filter(function (df) {
338
+ return df.tokenSymbol === nativeAssetSymbol;
339
+ }).reduce(function (acc, df) {
340
+ return acc + df.plancks;
341
+ }, 0n);
342
+ return totalDeliveryFees + executionFee;
343
+ };
344
+
345
+ var createKeyringPair = function createKeyringPair(path) {
346
+ var evmPrivateKey = getEvmPrivateKeyHex(path);
347
+ var keyring = evmPrivateKey ? new Keyring() : new Keyring({
348
+ type: 'sr25519'
349
+ });
350
+ return evmPrivateKey ? keyring.createFromUri(evmPrivateKey, undefined, 'ethereum') : keyring.addFromUri(path);
351
+ };
352
+
353
+ var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
354
+ return value.charAt(0).toLowerCase() + value.slice(1);
355
+ };
356
+ var snakeToCamel = function snakeToCamel(str) {
357
+ return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
358
+ return group.toUpperCase().replace('-', '').replace('_', '');
359
+ });
360
+ };
255
361
 
256
362
  var clientPool = createClientCache(MAX_CLIENTS, /*#__PURE__*/function () {
257
363
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(client) {
@@ -318,8 +424,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
318
424
  key: "init",
319
425
  value: function () {
320
426
  var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(chain) {
427
+ var _this = this;
321
428
  var clientTtlMs,
322
- apiConfig,
323
429
  _args = arguments;
324
430
  return _regenerator().w(function (_context3) {
325
431
  while (1) switch (_context3.n) {
@@ -333,19 +439,14 @@ var PolkadotJsApi = /*#__PURE__*/function () {
333
439
  case 1:
334
440
  this._ttlMs = clientTtlMs;
335
441
  this._chain = chain;
336
- apiConfig = this.getApiConfigForChain(chain);
337
- if (!(isConfig(this._config) && this._config.development && !apiConfig)) {
338
- _context3.n = 2;
339
- break;
340
- }
341
- throw new MissingChainApiError(chain);
442
+ _context3.n = 2;
443
+ return resolveChainApi(this._config, chain, function (wsUrl, c) {
444
+ return _this.createApiInstance(wsUrl, c);
445
+ });
342
446
  case 2:
343
- _context3.n = 3;
344
- return this.resolveApi(apiConfig, chain);
345
- case 3:
346
447
  this.api = _context3.v;
347
448
  this.initialized = true;
348
- case 4:
449
+ case 3:
349
450
  return _context3.a(2);
350
451
  }
351
452
  }, _callee3, this);
@@ -355,27 +456,6 @@ var PolkadotJsApi = /*#__PURE__*/function () {
355
456
  }
356
457
  return init;
357
458
  }()
358
- }, {
359
- key: "getApiConfigForChain",
360
- value: function getApiConfigForChain(chain) {
361
- if (isConfig(this._config)) {
362
- var _this$_config$apiOver;
363
- return (_this$_config$apiOver = this._config.apiOverrides) === null || _this$_config$apiOver === void 0 ? void 0 : _this$_config$apiOver[chain];
364
- }
365
- return this._config;
366
- }
367
- }, {
368
- key: "resolveApi",
369
- value: function resolveApi(apiConfig, chain) {
370
- if (!apiConfig) {
371
- var wsUrl = getChainProviders(chain);
372
- return this.createApiInstance(wsUrl, chain);
373
- }
374
- if (typeof apiConfig === 'string' || apiConfig instanceof Array) {
375
- return this.createApiInstance(apiConfig, chain);
376
- }
377
- return Promise.resolve(apiConfig);
378
- }
379
459
  }, {
380
460
  key: "createApiInstance",
381
461
  value: function createApiInstance(wsUrl, _chain) {
@@ -681,7 +761,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
681
761
  key: "getDryRunCall",
682
762
  value: function () {
683
763
  var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(options) {
684
- var _this = this;
764
+ var _this2 = this;
685
765
  var tx, address, feeAsset, chain, destination, version, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, basePayload, resolvedTx, resolvedFeeAsset, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureErr, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, destParaId, overriddenWeight, xcmFee, _yield$this$getPaymen, executionFee, fee, _t, _t2, _t3, _t4;
686
766
  return _regenerator().w(function (_context1) {
687
767
  while (1) switch (_context1.p = _context1.n) {
@@ -725,13 +805,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
725
805
  resolvedFeeAsset = _context1.v;
726
806
  performDryRunCall = /*#__PURE__*/function () {
727
807
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(includeVersion) {
728
- var _this$api$call$dryRun;
808
+ var _this2$api$call$dryRu;
729
809
  var versionNum;
730
810
  return _regenerator().w(function (_context0) {
731
811
  while (1) switch (_context0.n) {
732
812
  case 0:
733
813
  versionNum = Number(version.charAt(1));
734
- return _context0.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [basePayload, resolvedTx].concat(_toConsumableArray(includeVersion ? [versionNum] : []))));
814
+ return _context0.a(2, (_this2$api$call$dryRu = _this2.api.call.dryRunApi).dryRunCall.apply(_this2$api$call$dryRu, [basePayload, resolvedTx].concat(_toConsumableArray(includeVersion ? [versionNum] : []))));
735
815
  }
736
816
  }, _callee0);
737
817
  }));
@@ -907,7 +987,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
907
987
  case 22:
908
988
  _yield$this$getPaymen = _context1.v;
909
989
  executionFee = _yield$this$getPaymen.partialFee;
910
- fee = computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
990
+ fee = computeOriginFee(resultHuman, chain, executionFee);
911
991
  return _context1.a(2, {
912
992
  success: true,
913
993
  fee: fee,
@@ -1272,11 +1352,11 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1272
1352
  }, {
1273
1353
  key: "disconnect",
1274
1354
  value: function disconnect() {
1275
- var _this$_config$apiOver2;
1355
+ var _this$_config$apiOver;
1276
1356
  var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1277
1357
  if (!this.initialized) return Promise.resolve();
1278
1358
  if (!force && !this.disconnectAllowed) return Promise.resolve();
1279
- var api = isConfig(this._config) ? (_this$_config$apiOver2 = this._config.apiOverrides) === null || _this$_config$apiOver2 === void 0 ? void 0 : _this$_config$apiOver2[this._chain] : this._config;
1359
+ var api = isConfig(this._config) ? (_this$_config$apiOver = this._config.apiOverrides) === null || _this$_config$apiOver === void 0 ? void 0 : _this$_config$apiOver[this._chain] : this._config;
1280
1360
  // Own client provided, destroy only if force true
1281
1361
  if (force && _typeof(api) === 'object') {
1282
1362
  void this.api.disconnect();
@@ -1391,28 +1471,28 @@ var getBalance = createPolkadotJsApiCall(getBalance$1);
1391
1471
  var claimAssets = createPolkadotJsApiCall(claimAssets$1);
1392
1472
 
1393
1473
  var assets = /*#__PURE__*/Object.freeze({
1394
- __proto__: null,
1395
- Foreign: Foreign,
1396
- ForeignAbstract: ForeignAbstract,
1397
- Native: Native,
1398
- Override: Override,
1399
- claimAssets: claimAssets,
1400
- findAssetInfo: findAssetInfo,
1401
- getAllAssetsSymbols: getAllAssetsSymbols,
1402
- getAssetDecimals: getAssetDecimals,
1403
- getAssetId: getAssetId,
1404
- getAssets: getAssets,
1405
- getAssetsObject: getAssetsObject,
1406
- getBalance: getBalance,
1407
- getExistentialDeposit: getExistentialDeposit,
1408
- getNativeAssetSymbol: getNativeAssetSymbol,
1409
- getNativeAssets: getNativeAssets,
1410
- getOtherAssets: getOtherAssets,
1411
- getRelayChainSymbol: getRelayChainSymbol,
1412
- getSupportedAssets: getSupportedAssets,
1413
- getTChain: getTChain,
1414
- hasSupportForAsset: hasSupportForAsset,
1415
- isChainEvm: isChainEvm
1474
+ __proto__: null,
1475
+ Foreign: Foreign,
1476
+ ForeignAbstract: ForeignAbstract,
1477
+ Native: Native,
1478
+ Override: Override,
1479
+ claimAssets: claimAssets,
1480
+ findAssetInfo: findAssetInfo,
1481
+ getAllAssetsSymbols: getAllAssetsSymbols,
1482
+ getAssetDecimals: getAssetDecimals,
1483
+ getAssetId: getAssetId,
1484
+ getAssets: getAssets,
1485
+ getAssetsObject: getAssetsObject,
1486
+ getBalance: getBalance,
1487
+ getExistentialDeposit: getExistentialDeposit,
1488
+ getNativeAssetSymbol: getNativeAssetSymbol,
1489
+ getNativeAssets: getNativeAssets,
1490
+ getOtherAssets: getOtherAssets,
1491
+ getRelayChainSymbol: getRelayChainSymbol,
1492
+ getSupportedAssets: getSupportedAssets,
1493
+ getTChain: getTChain,
1494
+ hasSupportForAsset: hasSupportForAsset,
1495
+ isChainEvm: isChainEvm
1416
1496
  });
1417
1497
 
1418
1498
  var convertSs58 = function convertSs58(address, chain) {
@@ -1902,15 +1982,15 @@ var getBridgeStatus = /*#__PURE__*/function () {
1902
1982
  }();
1903
1983
 
1904
1984
  var transfer = /*#__PURE__*/Object.freeze({
1905
- __proto__: null,
1906
- approveToken: approveToken,
1907
- depositToken: depositToken,
1908
- dryRun: dryRun,
1909
- dryRunOrigin: dryRunOrigin,
1910
- getBridgeStatus: getBridgeStatus,
1911
- getParaEthTransferFees: getParaEthTransferFees,
1912
- getTokenBalance: getTokenBalance,
1913
- transferEthToPolkadot: transferEthToPolkadot
1985
+ __proto__: null,
1986
+ approveToken: approveToken,
1987
+ depositToken: depositToken,
1988
+ dryRun: dryRun,
1989
+ dryRunOrigin: dryRunOrigin,
1990
+ getBridgeStatus: getBridgeStatus,
1991
+ getParaEthTransferFees: getParaEthTransferFees,
1992
+ getTokenBalance: getTokenBalance,
1993
+ transferEthToPolkadot: transferEthToPolkadot
1914
1994
  });
1915
1995
 
1916
1996
  export { Builder, EvmBuilder, approveToken, assets, claimAssets, convertSs58, createChainClient, depositToken, dryRun, dryRunOrigin, getBalance, getBridgeStatus, getParaEthTransferFees, getTokenBalance, transferEthToPolkadot, transfer as xcmPallet };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-pjs",
3
- "version": "12.8.9",
3
+ "version": "12.9.1",
4
4
  "description": "Polkadot.js based SDK for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "@snowbridge/registry": "^0.4.4",
30
30
  "ethers": "^6.16.0",
31
31
  "viem": "^2.47.1",
32
- "@paraspell/sdk-core": "12.8.9"
32
+ "@paraspell/sdk-core": "12.9.1"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@polkadot/api": ">= 16.0 < 17",