@paraspell/sdk-pjs 10.10.11 → 10.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -276,20 +276,16 @@ var snakeToCamel = function snakeToCamel(str) {
276
276
  });
277
277
  };
278
278
  var PolkadotJsApi = /*#__PURE__*/function () {
279
- function PolkadotJsApi() {
279
+ function PolkadotJsApi(config) {
280
280
  _classCallCheck(this, PolkadotJsApi);
281
281
  this.initialized = false;
282
282
  this.disconnectAllowed = true;
283
+ this._config = config;
283
284
  }
284
285
  return _createClass(PolkadotJsApi, [{
285
- key: "setApi",
286
- value: function setApi(api) {
287
- this._api = api;
288
- }
289
- }, {
290
- key: "getApiOrUrl",
291
- value: function getApiOrUrl() {
292
- return this._api;
286
+ key: "getConfig",
287
+ value: function getConfig() {
288
+ return this._config;
293
289
  }
294
290
  }, {
295
291
  key: "getApi",
@@ -299,45 +295,31 @@ var PolkadotJsApi = /*#__PURE__*/function () {
299
295
  }, {
300
296
  key: "init",
301
297
  value: function () {
302
- var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(node, _clientTtlMs) {
303
- var _this$_api, _t;
298
+ var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, _clientTtlMs) {
299
+ var apiConfig;
304
300
  return _regenerator().w(function (_context) {
305
301
  while (1) switch (_context.n) {
306
302
  case 0:
307
- if (!(this.initialized || node === 'Ethereum')) {
303
+ if (!(this.initialized || chain === 'Ethereum')) {
308
304
  _context.n = 1;
309
305
  break;
310
306
  }
311
307
  return _context.a(2);
312
308
  case 1:
313
- if (!(typeof this._api === 'string' || this._api instanceof Array)) {
314
- _context.n = 3;
309
+ this._node = chain;
310
+ apiConfig = this.getApiConfigForChain(chain);
311
+ if (!(sdkCore.isConfig(this._config) && this._config.development && !apiConfig)) {
312
+ _context.n = 2;
315
313
  break;
316
314
  }
317
- _context.n = 2;
318
- return this.createApiInstance(this._api);
315
+ throw new sdkCore.MissingChainApiError(chain);
319
316
  case 2:
320
- this.api = _context.v;
321
- _context.n = 7;
322
- break;
317
+ _context.n = 3;
318
+ return this.resolveApi(apiConfig, chain);
323
319
  case 3:
324
- if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
325
- _context.n = 4;
326
- break;
327
- }
328
- _t = _this$_api;
329
- _context.n = 6;
330
- break;
331
- case 4:
332
- _context.n = 5;
333
- return sdkCore.createApiInstanceForNode(this, node);
334
- case 5:
335
- _t = _context.v;
336
- case 6:
337
- this.api = _t;
338
- case 7:
320
+ this.api = _context.v;
339
321
  this.initialized = true;
340
- case 8:
322
+ case 4:
341
323
  return _context.a(2);
342
324
  }
343
325
  }, _callee, this);
@@ -348,21 +330,58 @@ var PolkadotJsApi = /*#__PURE__*/function () {
348
330
  return init;
349
331
  }()
350
332
  }, {
351
- key: "createApiInstance",
333
+ key: "getApiConfigForChain",
334
+ value: function getApiConfigForChain(chain) {
335
+ if (sdkCore.isConfig(this._config)) {
336
+ var _this$_config$apiOver;
337
+ return (_this$_config$apiOver = this._config.apiOverrides) === null || _this$_config$apiOver === void 0 ? void 0 : _this$_config$apiOver[chain];
338
+ }
339
+ return this._config;
340
+ }
341
+ }, {
342
+ key: "resolveApi",
352
343
  value: function () {
353
- var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(wsUrl) {
354
- var wsProvider;
344
+ var _resolveApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiConfig, chain) {
355
345
  return _regenerator().w(function (_context2) {
356
346
  while (1) switch (_context2.n) {
347
+ case 0:
348
+ if (apiConfig) {
349
+ _context2.n = 1;
350
+ break;
351
+ }
352
+ return _context2.a(2, sdkCore.createApiInstanceForNode(this, chain));
353
+ case 1:
354
+ if (!(typeof apiConfig === 'string' || apiConfig instanceof Array)) {
355
+ _context2.n = 2;
356
+ break;
357
+ }
358
+ return _context2.a(2, this.createApiInstance(apiConfig));
359
+ case 2:
360
+ return _context2.a(2, apiConfig);
361
+ }
362
+ }, _callee2, this);
363
+ }));
364
+ function resolveApi(_x3, _x4) {
365
+ return _resolveApi.apply(this, arguments);
366
+ }
367
+ return resolveApi;
368
+ }()
369
+ }, {
370
+ key: "createApiInstance",
371
+ value: function () {
372
+ var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(wsUrl) {
373
+ var wsProvider;
374
+ return _regenerator().w(function (_context3) {
375
+ while (1) switch (_context3.n) {
357
376
  case 0:
358
377
  wsProvider = new api.WsProvider(wsUrl);
359
- return _context2.a(2, api.ApiPromise.create({
378
+ return _context3.a(2, api.ApiPromise.create({
360
379
  provider: wsProvider
361
380
  }));
362
381
  }
363
- }, _callee2);
382
+ }, _callee3);
364
383
  }));
365
- function createApiInstance(_x3) {
384
+ function createApiInstance(_x5) {
366
385
  return _createApiInstance.apply(this, arguments);
367
386
  }
368
387
  return createApiInstance;
@@ -416,21 +435,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
416
435
  }, {
417
436
  key: "calculateTransactionFee",
418
437
  value: function () {
419
- var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(tx, address) {
438
+ var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(tx, address) {
420
439
  var _yield$tx$paymentInfo, partialFee;
421
- return _regenerator().w(function (_context3) {
422
- while (1) switch (_context3.n) {
440
+ return _regenerator().w(function (_context4) {
441
+ while (1) switch (_context4.n) {
423
442
  case 0:
424
- _context3.n = 1;
443
+ _context4.n = 1;
425
444
  return tx.paymentInfo(address);
426
445
  case 1:
427
- _yield$tx$paymentInfo = _context3.v;
446
+ _yield$tx$paymentInfo = _context4.v;
428
447
  partialFee = _yield$tx$paymentInfo.partialFee;
429
- return _context3.a(2, partialFee.toBigInt());
448
+ return _context4.a(2, partialFee.toBigInt());
430
449
  }
431
- }, _callee3);
450
+ }, _callee4);
432
451
  }));
433
- function calculateTransactionFee(_x4, _x5) {
452
+ function calculateTransactionFee(_x6, _x7) {
434
453
  return _calculateTransactionFee.apply(this, arguments);
435
454
  }
436
455
  return calculateTransactionFee;
@@ -438,23 +457,23 @@ var PolkadotJsApi = /*#__PURE__*/function () {
438
457
  }, {
439
458
  key: "quoteAhPrice",
440
459
  value: function () {
441
- var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(fromMl, toMl, amountIn) {
460
+ var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(fromMl, toMl, amountIn) {
442
461
  var includeFee,
443
462
  quoted,
444
- _args4 = arguments;
445
- return _regenerator().w(function (_context4) {
446
- while (1) switch (_context4.n) {
463
+ _args5 = arguments;
464
+ return _regenerator().w(function (_context5) {
465
+ while (1) switch (_context5.n) {
447
466
  case 0:
448
- includeFee = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : true;
449
- _context4.n = 1;
467
+ includeFee = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : true;
468
+ _context5.n = 1;
450
469
  return this.api.call.assetConversionApi.quotePriceExactTokensForTokens(fromMl, toMl, amountIn.toString(), includeFee);
451
470
  case 1:
452
- quoted = _context4.v;
453
- return _context4.a(2, quoted.toJSON() !== null ? BigInt(quoted.toString()) : undefined);
471
+ quoted = _context5.v;
472
+ return _context5.a(2, quoted.toJSON() !== null ? BigInt(quoted.toString()) : undefined);
454
473
  }
455
- }, _callee4, this);
474
+ }, _callee5, this);
456
475
  }));
457
- function quoteAhPrice(_x6, _x7, _x8) {
476
+ function quoteAhPrice(_x8, _x9, _x0) {
458
477
  return _quoteAhPrice.apply(this, arguments);
459
478
  }
460
479
  return quoteAhPrice;
@@ -462,20 +481,20 @@ var PolkadotJsApi = /*#__PURE__*/function () {
462
481
  }, {
463
482
  key: "getBalanceNative",
464
483
  value: function () {
465
- var _getBalanceNative = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(address) {
484
+ var _getBalanceNative = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(address) {
466
485
  var response;
467
- return _regenerator().w(function (_context5) {
468
- while (1) switch (_context5.n) {
486
+ return _regenerator().w(function (_context6) {
487
+ while (1) switch (_context6.n) {
469
488
  case 0:
470
- _context5.n = 1;
489
+ _context6.n = 1;
471
490
  return this.api.query.system.account(address);
472
491
  case 1:
473
- response = _context5.v;
474
- return _context5.a(2, response.data.free.toBigInt());
492
+ response = _context6.v;
493
+ return _context6.a(2, response.data.free.toBigInt());
475
494
  }
476
- }, _callee5, this);
495
+ }, _callee6, this);
477
496
  }));
478
- function getBalanceNative(_x9) {
497
+ function getBalanceNative(_x1) {
479
498
  return _getBalanceNative.apply(this, arguments);
480
499
  }
481
500
  return getBalanceNative;
@@ -483,22 +502,22 @@ var PolkadotJsApi = /*#__PURE__*/function () {
483
502
  }, {
484
503
  key: "getBalanceForeignPolkadotXcm",
485
504
  value: function () {
486
- var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(address, id) {
505
+ var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(address, id) {
487
506
  var parsedId, response, obj;
488
- return _regenerator().w(function (_context6) {
489
- while (1) switch (_context6.n) {
507
+ return _regenerator().w(function (_context7) {
508
+ while (1) switch (_context7.n) {
490
509
  case 0:
491
510
  parsedId = new types.u32(this.api.registry, id);
492
- _context6.n = 1;
511
+ _context7.n = 1;
493
512
  return this.api.query.assets.account(parsedId, address);
494
513
  case 1:
495
- response = _context6.v;
514
+ response = _context7.v;
496
515
  obj = response.toJSON();
497
- return _context6.a(2, obj.balance ? BigInt(obj.balance) : 0n);
516
+ return _context7.a(2, obj.balance ? BigInt(obj.balance) : 0n);
498
517
  }
499
- }, _callee6, this);
518
+ }, _callee7, this);
500
519
  }));
501
- function getBalanceForeignPolkadotXcm(_x0, _x1) {
520
+ function getBalanceForeignPolkadotXcm(_x10, _x11) {
502
521
  return _getBalanceForeignPolkadotXcm.apply(this, arguments);
503
522
  }
504
523
  return getBalanceForeignPolkadotXcm;
@@ -506,21 +525,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
506
525
  }, {
507
526
  key: "getMythosForeignBalance",
508
527
  value: function () {
509
- var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(address) {
528
+ var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(address) {
510
529
  var response, obj;
511
- return _regenerator().w(function (_context7) {
512
- while (1) switch (_context7.n) {
530
+ return _regenerator().w(function (_context8) {
531
+ while (1) switch (_context8.n) {
513
532
  case 0:
514
- _context7.n = 1;
533
+ _context8.n = 1;
515
534
  return this.api.query.balances.account(address);
516
535
  case 1:
517
- response = _context7.v;
536
+ response = _context8.v;
518
537
  obj = response.toJSON();
519
- return _context7.a(2, obj.free ? BigInt(obj.free) : 0n);
538
+ return _context8.a(2, obj.free ? BigInt(obj.free) : 0n);
520
539
  }
521
- }, _callee7, this);
540
+ }, _callee8, this);
522
541
  }));
523
- function getMythosForeignBalance(_x10) {
542
+ function getMythosForeignBalance(_x12) {
524
543
  return _getMythosForeignBalance.apply(this, arguments);
525
544
  }
526
545
  return getMythosForeignBalance;
@@ -528,21 +547,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
528
547
  }, {
529
548
  key: "getBalanceForeignAssetsPallet",
530
549
  value: function () {
531
- var _getBalanceForeignAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(address, multiLocation) {
550
+ var _getBalanceForeignAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(address, multiLocation) {
532
551
  var response, obj;
533
- return _regenerator().w(function (_context8) {
534
- while (1) switch (_context8.n) {
552
+ return _regenerator().w(function (_context9) {
553
+ while (1) switch (_context9.n) {
535
554
  case 0:
536
- _context8.n = 1;
555
+ _context9.n = 1;
537
556
  return this.api.query.foreignAssets.account(multiLocation, address);
538
557
  case 1:
539
- response = _context8.v;
558
+ response = _context9.v;
540
559
  obj = response.toJSON();
541
- return _context8.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
560
+ return _context9.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
542
561
  }
543
- }, _callee8, this);
562
+ }, _callee9, this);
544
563
  }));
545
- function getBalanceForeignAssetsPallet(_x11, _x12) {
564
+ function getBalanceForeignAssetsPallet(_x13, _x14) {
546
565
  return _getBalanceForeignAssetsPallet.apply(this, arguments);
547
566
  }
548
567
  return getBalanceForeignAssetsPallet;
@@ -550,21 +569,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
550
569
  }, {
551
570
  key: "getForeignAssetsByIdBalance",
552
571
  value: function () {
553
- var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(address, assetId) {
572
+ var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(address, assetId) {
554
573
  var response, obj;
555
- return _regenerator().w(function (_context9) {
556
- while (1) switch (_context9.n) {
574
+ return _regenerator().w(function (_context0) {
575
+ while (1) switch (_context0.n) {
557
576
  case 0:
558
- _context9.n = 1;
577
+ _context0.n = 1;
559
578
  return this.api.query.foreignAssets.account(assetId, address);
560
579
  case 1:
561
- response = _context9.v;
580
+ response = _context0.v;
562
581
  obj = response.toJSON();
563
- return _context9.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
582
+ return _context0.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
564
583
  }
565
- }, _callee9, this);
584
+ }, _callee0, this);
566
585
  }));
567
- function getForeignAssetsByIdBalance(_x13, _x14) {
586
+ function getForeignAssetsByIdBalance(_x15, _x16) {
568
587
  return _getForeignAssetsByIdBalance.apply(this, arguments);
569
588
  }
570
589
  return getForeignAssetsByIdBalance;
@@ -572,22 +591,22 @@ var PolkadotJsApi = /*#__PURE__*/function () {
572
591
  }, {
573
592
  key: "getBalanceForeignBifrost",
574
593
  value: function () {
575
- var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(address, asset) {
594
+ var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(address, asset) {
576
595
  var currencySelection, response, accountData;
577
- return _regenerator().w(function (_context0) {
578
- while (1) switch (_context0.n) {
596
+ return _regenerator().w(function (_context1) {
597
+ while (1) switch (_context1.n) {
579
598
  case 0:
580
599
  currencySelection = sdkCore.getNode('BifrostPolkadot').getCurrencySelection(asset);
581
- _context0.n = 1;
600
+ _context1.n = 1;
582
601
  return this.api.query.tokens.accounts(address, currencySelection);
583
602
  case 1:
584
- response = _context0.v;
603
+ response = _context1.v;
585
604
  accountData = response ? response : null;
586
- return _context0.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
605
+ return _context1.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
587
606
  }
588
- }, _callee0, this);
607
+ }, _callee1, this);
589
608
  }));
590
- function getBalanceForeignBifrost(_x15, _x16) {
609
+ function getBalanceForeignBifrost(_x17, _x18) {
591
610
  return _getBalanceForeignBifrost.apply(this, arguments);
592
611
  }
593
612
  return getBalanceForeignBifrost;
@@ -595,23 +614,23 @@ var PolkadotJsApi = /*#__PURE__*/function () {
595
614
  }, {
596
615
  key: "getBalanceNativeAcala",
597
616
  value: function () {
598
- var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(address, symbol) {
617
+ var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(address, symbol) {
599
618
  var response, accountData;
600
- return _regenerator().w(function (_context1) {
601
- while (1) switch (_context1.n) {
619
+ return _regenerator().w(function (_context10) {
620
+ while (1) switch (_context10.n) {
602
621
  case 0:
603
- _context1.n = 1;
622
+ _context10.n = 1;
604
623
  return this.api.query.tokens.accounts(address, {
605
624
  Token: symbol
606
625
  });
607
626
  case 1:
608
- response = _context1.v;
627
+ response = _context10.v;
609
628
  accountData = response ? response : null;
610
- return _context1.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
629
+ return _context10.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
611
630
  }
612
- }, _callee1, this);
631
+ }, _callee10, this);
613
632
  }));
614
- function getBalanceNativeAcala(_x17, _x18) {
633
+ function getBalanceNativeAcala(_x19, _x20) {
615
634
  return _getBalanceNativeAcala.apply(this, arguments);
616
635
  }
617
636
  return getBalanceNativeAcala;
@@ -619,19 +638,19 @@ var PolkadotJsApi = /*#__PURE__*/function () {
619
638
  }, {
620
639
  key: "getBalanceForeignXTokens",
621
640
  value: function () {
622
- var _getBalanceForeignXTokens = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(node, address, asset) {
641
+ var _getBalanceForeignXTokens = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(node, address, asset) {
623
642
  var pallet, response, entry, accountData;
624
- return _regenerator().w(function (_context10) {
625
- while (1) switch (_context10.n) {
643
+ return _regenerator().w(function (_context11) {
644
+ while (1) switch (_context11.n) {
626
645
  case 0:
627
646
  pallet = 'tokens';
628
647
  if (node === 'Centrifuge' || node === 'Altair') {
629
648
  pallet = 'ormlTokens';
630
649
  }
631
- _context10.n = 1;
650
+ _context11.n = 1;
632
651
  return this.api.query[pallet].accounts.entries(address);
633
652
  case 1:
634
- response = _context10.v;
653
+ response = _context11.v;
635
654
  entry = response.find(function (_ref2) {
636
655
  var _asset$symbol, _asset$assetId, _assetItem$toHuman, _asset$symbol2, _assetItem$toHuman2, _asset$assetId2;
637
656
  var _ref3 = _slicedToArray(_ref2, 2),
@@ -643,11 +662,11 @@ var PolkadotJsApi = /*#__PURE__*/function () {
643
662
  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());
644
663
  });
645
664
  accountData = entry ? entry[1] : null;
646
- return _context10.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
665
+ return _context11.a(2, accountData ? BigInt(accountData.free.toString()) : 0n);
647
666
  }
648
- }, _callee10, this);
667
+ }, _callee11, this);
649
668
  }));
650
- function getBalanceForeignXTokens(_x19, _x20, _x21) {
669
+ function getBalanceForeignXTokens(_x21, _x22, _x23) {
651
670
  return _getBalanceForeignXTokens.apply(this, arguments);
652
671
  }
653
672
  return getBalanceForeignXTokens;
@@ -655,21 +674,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
655
674
  }, {
656
675
  key: "getBalanceAssetsPallet",
657
676
  value: function () {
658
- var _getBalanceAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(address, assetId) {
677
+ var _getBalanceAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(address, assetId) {
659
678
  var response, obj;
660
- return _regenerator().w(function (_context11) {
661
- while (1) switch (_context11.n) {
679
+ return _regenerator().w(function (_context12) {
680
+ while (1) switch (_context12.n) {
662
681
  case 0:
663
- _context11.n = 1;
682
+ _context12.n = 1;
664
683
  return this.api.query.assets.account(assetId, address);
665
684
  case 1:
666
- response = _context11.v;
685
+ response = _context12.v;
667
686
  obj = response.toJSON();
668
- return _context11.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
687
+ return _context12.a(2, BigInt(obj === null || !obj.balance ? 0 : obj.balance));
669
688
  }
670
- }, _callee11, this);
689
+ }, _callee12, this);
671
690
  }));
672
- function getBalanceAssetsPallet(_x22, _x23) {
691
+ function getBalanceAssetsPallet(_x24, _x25) {
673
692
  return _getBalanceAssetsPallet.apply(this, arguments);
674
693
  }
675
694
  return getBalanceAssetsPallet;
@@ -682,27 +701,27 @@ var PolkadotJsApi = /*#__PURE__*/function () {
682
701
  }, {
683
702
  key: "getFromRpc",
684
703
  value: function () {
685
- var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(module, method, key) {
704
+ var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(module, method, key) {
686
705
  var rpcModule, response;
687
- return _regenerator().w(function (_context12) {
688
- while (1) switch (_context12.n) {
706
+ return _regenerator().w(function (_context13) {
707
+ while (1) switch (_context13.n) {
689
708
  case 0:
690
709
  rpcModule = this.api.rpc[module];
691
710
  if (!(!rpcModule || !rpcModule[method])) {
692
- _context12.n = 1;
711
+ _context13.n = 1;
693
712
  break;
694
713
  }
695
714
  throw new sdkCore.InvalidParameterError("RPC method ".concat(module, ".").concat(method, " not available"));
696
715
  case 1:
697
- _context12.n = 2;
716
+ _context13.n = 2;
698
717
  return rpcModule[method](key);
699
718
  case 2:
700
- response = _context12.v;
701
- return _context12.a(2, response.toHex());
719
+ response = _context13.v;
720
+ return _context13.a(2, response.toHex());
702
721
  }
703
- }, _callee12, this);
722
+ }, _callee13, this);
704
723
  }));
705
- function getFromRpc(_x24, _x25, _x26) {
724
+ function getFromRpc(_x26, _x27, _x28) {
706
725
  return _getFromRpc.apply(this, arguments);
707
726
  }
708
727
  return getFromRpc;
@@ -715,25 +734,25 @@ var PolkadotJsApi = /*#__PURE__*/function () {
715
734
  }, {
716
735
  key: "clone",
717
736
  value: function clone() {
718
- return new PolkadotJsApi();
737
+ return new PolkadotJsApi(sdkCore.isConfig(this._config) ? this._config : undefined);
719
738
  }
720
739
  }, {
721
740
  key: "createApiForNode",
722
741
  value: function () {
723
- var _createApiForNode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(node) {
742
+ var _createApiForNode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(node) {
724
743
  var api;
725
- return _regenerator().w(function (_context13) {
726
- while (1) switch (_context13.n) {
744
+ return _regenerator().w(function (_context14) {
745
+ while (1) switch (_context14.n) {
727
746
  case 0:
728
747
  api = new PolkadotJsApi();
729
- _context13.n = 1;
748
+ _context14.n = 1;
730
749
  return api.init(node);
731
750
  case 1:
732
- return _context13.a(2, api);
751
+ return _context14.a(2, api);
733
752
  }
734
- }, _callee13);
753
+ }, _callee14);
735
754
  }));
736
- function createApiForNode(_x27) {
755
+ function createApiForNode(_x29) {
737
756
  return _createApiForNode.apply(this, arguments);
738
757
  }
739
758
  return createApiForNode;
@@ -741,16 +760,16 @@ var PolkadotJsApi = /*#__PURE__*/function () {
741
760
  }, {
742
761
  key: "getDryRunCall",
743
762
  value: function () {
744
- var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(_ref4) {
763
+ var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(_ref4) {
745
764
  var _this$api$call$dryRun;
746
765
  var tx, address, node, supportsDryRunApi, nodesRequiringVersionParam, needsVersionParam, DEFAULT_XCM_VERSION, response, result, resultJson, isSuccess, moduleError, failureReason, executionFee, fee, actualWeight, weight, forwardedXcms, destParaId;
747
- return _regenerator().w(function (_context14) {
748
- while (1) switch (_context14.n) {
766
+ return _regenerator().w(function (_context15) {
767
+ while (1) switch (_context15.n) {
749
768
  case 0:
750
769
  tx = _ref4.tx, address = _ref4.address, node = _ref4.node;
751
770
  supportsDryRunApi = sdkCore.getAssetsObject(node).supportsDryRunApi;
752
771
  if (supportsDryRunApi) {
753
- _context14.n = 1;
772
+ _context15.n = 1;
754
773
  break;
755
774
  }
756
775
  throw new sdkCore.NodeNotSupportedError("DryRunApi is not available on node ".concat(node));
@@ -758,32 +777,32 @@ var PolkadotJsApi = /*#__PURE__*/function () {
758
777
  nodesRequiringVersionParam = ['BifrostPolkadot', 'BifrostKusama', 'AssetHubKusama', 'AssetHubPolkadot', 'Kusama', 'Polkadot', 'Polimec', 'Astar'];
759
778
  needsVersionParam = nodesRequiringVersionParam.includes(node);
760
779
  DEFAULT_XCM_VERSION = 3;
761
- _context14.n = 2;
780
+ _context15.n = 2;
762
781
  return (_this$api$call$dryRun = this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [{
763
782
  system: {
764
783
  Signed: address
765
784
  }
766
785
  }, tx].concat(_toConsumableArray(needsVersionParam ? [DEFAULT_XCM_VERSION] : [])));
767
786
  case 2:
768
- response = _context14.v;
787
+ response = _context15.v;
769
788
  result = response.toHuman();
770
789
  resultJson = response.toJSON();
771
790
  isSuccess = result.Ok && result.Ok.executionResult.Ok;
772
791
  if (isSuccess) {
773
- _context14.n = 3;
792
+ _context15.n = 3;
774
793
  break;
775
794
  }
776
795
  moduleError = result.Ok.executionResult.Err.error.Module;
777
796
  failureReason = sdkCore.resolveModuleError(node, moduleError);
778
- return _context14.a(2, {
797
+ return _context15.a(2, {
779
798
  success: false,
780
799
  failureReason: failureReason
781
800
  });
782
801
  case 3:
783
- _context14.n = 4;
802
+ _context15.n = 4;
784
803
  return this.calculateTransactionFee(tx, address);
785
804
  case 4:
786
- executionFee = _context14.v;
805
+ executionFee = _context15.v;
787
806
  fee = sdkCore.computeFeeFromDryRunPjs(result, node, executionFee);
788
807
  actualWeight = resultJson.ok.executionResult.ok.actualWeight;
789
808
  weight = actualWeight ? {
@@ -794,7 +813,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
794
813
  destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref5) {
795
814
  return i.here === null ? 0 : (_ref5 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref5 === void 0 ? void 0 : _ref5.parachain;
796
815
  }(Object.values(forwardedXcms[0])[0].interior);
797
- return _context14.a(2, {
816
+ return _context15.a(2, {
798
817
  success: true,
799
818
  fee: fee,
800
819
  weight: weight,
@@ -802,9 +821,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
802
821
  destParaId: destParaId
803
822
  });
804
823
  }
805
- }, _callee14, this);
824
+ }, _callee15, this);
806
825
  }));
807
- function getDryRunCall(_x28) {
826
+ function getDryRunCall(_x30) {
808
827
  return _getDryRunCall.apply(this, arguments);
809
828
  }
810
829
  return getDryRunCall;
@@ -812,21 +831,21 @@ var PolkadotJsApi = /*#__PURE__*/function () {
812
831
  }, {
813
832
  key: "getXcmWeight",
814
833
  value: function () {
815
- var _getXcmWeight = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(xcm) {
834
+ var _getXcmWeight = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(xcm) {
816
835
  var result, resultJson;
817
- return _regenerator().w(function (_context15) {
818
- while (1) switch (_context15.n) {
836
+ return _regenerator().w(function (_context16) {
837
+ while (1) switch (_context16.n) {
819
838
  case 0:
820
- _context15.n = 1;
839
+ _context16.n = 1;
821
840
  return this.api.call.xcmPaymentApi.queryXcmWeight(xcm);
822
841
  case 1:
823
- result = _context15.v;
842
+ result = _context16.v;
824
843
  resultJson = result.toJSON();
825
- return _context15.a(2, resultJson.ok);
844
+ return _context16.a(2, resultJson.ok);
826
845
  }
827
- }, _callee15, this);
846
+ }, _callee16, this);
828
847
  }));
829
- function getXcmWeight(_x29) {
848
+ function getXcmWeight(_x31) {
830
849
  return _getXcmWeight.apply(this, arguments);
831
850
  }
832
851
  return getXcmWeight;
@@ -834,33 +853,33 @@ var PolkadotJsApi = /*#__PURE__*/function () {
834
853
  }, {
835
854
  key: "getDryRunXcm",
836
855
  value: function () {
837
- var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(_ref6) {
856
+ var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(_ref6) {
838
857
  var _ref7, _ref8, _ref9;
839
858
  var originLocation, xcm, node, origin, supportsDryRunApi, response, result, resultJson, isSuccess, failureReason, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee, actualWeight, weight, forwardedXcms, destParaId;
840
- return _regenerator().w(function (_context16) {
841
- while (1) switch (_context16.n) {
859
+ return _regenerator().w(function (_context17) {
860
+ while (1) switch (_context17.n) {
842
861
  case 0:
843
862
  originLocation = _ref6.originLocation, xcm = _ref6.xcm, node = _ref6.node, origin = _ref6.origin;
844
863
  supportsDryRunApi = sdkCore.getAssetsObject(node).supportsDryRunApi;
845
864
  if (supportsDryRunApi) {
846
- _context16.n = 1;
865
+ _context17.n = 1;
847
866
  break;
848
867
  }
849
868
  throw new sdkCore.NodeNotSupportedError("DryRunApi is not available on node ".concat(node));
850
869
  case 1:
851
- _context16.n = 2;
870
+ _context17.n = 2;
852
871
  return this.api.call.dryRunApi.dryRunXcm(originLocation, xcm);
853
872
  case 2:
854
- response = _context16.v;
873
+ response = _context17.v;
855
874
  result = response.toHuman();
856
875
  resultJson = response.toJSON();
857
876
  isSuccess = result.Ok && result.Ok.executionResult.Complete;
858
877
  if (isSuccess) {
859
- _context16.n = 3;
878
+ _context17.n = 3;
860
879
  break;
861
880
  }
862
881
  failureReason = result.Ok.executionResult.Incomplete.error;
863
- return _context16.a(2, {
882
+ return _context17.a(2, {
864
883
  success: false,
865
884
  failureReason: failureReason
866
885
  });
@@ -882,10 +901,10 @@ var PolkadotJsApi = /*#__PURE__*/function () {
882
901
  return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
883
902
  });
884
903
  if (feeEvent) {
885
- _context16.n = 4;
904
+ _context17.n = 4;
886
905
  break;
887
906
  }
888
- return _context16.a(2, Promise.resolve({
907
+ return _context17.a(2, Promise.resolve({
889
908
  success: false,
890
909
  failureReason: 'Cannot determine destination fee. No Issued event found'
891
910
  }));
@@ -901,7 +920,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
901
920
  destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref0) {
902
921
  return i.Here ? 0 : (_ref0 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref0 === void 0 ? void 0 : _ref0.parachain;
903
922
  }(Object.values(forwardedXcms[0])[0].interior);
904
- return _context16.a(2, {
923
+ return _context17.a(2, {
905
924
  success: true,
906
925
  fee: fee,
907
926
  weight: weight,
@@ -909,9 +928,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
909
928
  destParaId: destParaId
910
929
  });
911
930
  }
912
- }, _callee16, this);
931
+ }, _callee17, this);
913
932
  }));
914
- function getDryRunXcm(_x30) {
933
+ function getDryRunXcm(_x32) {
915
934
  return _getDryRunXcm.apply(this, arguments);
916
935
  }
917
936
  return getDryRunXcm;
@@ -919,18 +938,18 @@ var PolkadotJsApi = /*#__PURE__*/function () {
919
938
  }, {
920
939
  key: "getBridgeStatus",
921
940
  value: function () {
922
- var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
941
+ var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
923
942
  var outboundOperatingMode;
924
- return _regenerator().w(function (_context17) {
925
- while (1) switch (_context17.n) {
943
+ return _regenerator().w(function (_context18) {
944
+ while (1) switch (_context18.n) {
926
945
  case 0:
927
- _context17.n = 1;
946
+ _context18.n = 1;
928
947
  return this.api.query.ethereumOutboundQueue.operatingMode();
929
948
  case 1:
930
- outboundOperatingMode = _context17.v;
931
- return _context17.a(2, outboundOperatingMode.toPrimitive());
949
+ outboundOperatingMode = _context18.v;
950
+ return _context18.a(2, outboundOperatingMode.toPrimitive());
932
951
  }
933
- }, _callee17, this);
952
+ }, _callee18, this);
934
953
  }));
935
954
  function getBridgeStatus() {
936
955
  return _getBridgeStatus.apply(this, arguments);
@@ -950,35 +969,38 @@ var PolkadotJsApi = /*#__PURE__*/function () {
950
969
  }, {
951
970
  key: "disconnect",
952
971
  value: function () {
953
- var _disconnect = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
972
+ var _disconnect = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
973
+ var _this$_config$apiOver2;
954
974
  var force,
955
- _args18 = arguments;
956
- return _regenerator().w(function (_context18) {
957
- while (1) switch (_context18.n) {
975
+ api,
976
+ _args19 = arguments;
977
+ return _regenerator().w(function (_context19) {
978
+ while (1) switch (_context19.n) {
958
979
  case 0:
959
- force = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : false;
980
+ force = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : false;
960
981
  if (this.initialized) {
961
- _context18.n = 1;
982
+ _context19.n = 1;
962
983
  break;
963
984
  }
964
- return _context18.a(2, Promise.resolve());
985
+ return _context19.a(2, Promise.resolve());
965
986
  case 1:
966
987
  if (!(!force && !this.disconnectAllowed)) {
967
- _context18.n = 2;
988
+ _context19.n = 2;
968
989
  break;
969
990
  }
970
- return _context18.a(2);
991
+ return _context19.a(2);
971
992
  case 2:
972
- if (!(force || typeof this._api === 'string' || this._api === undefined)) {
973
- _context18.n = 3;
993
+ api = sdkCore.isConfig(this._config) ? (_this$_config$apiOver2 = this._config.apiOverrides) === null || _this$_config$apiOver2 === void 0 ? void 0 : _this$_config$apiOver2[this._node] : this._config; // Disconnect api only if it was created automatically
994
+ if (!(force || typeof api === 'string' || api === undefined)) {
995
+ _context19.n = 3;
974
996
  break;
975
997
  }
976
- _context18.n = 3;
998
+ _context19.n = 3;
977
999
  return this.api.disconnect();
978
1000
  case 3:
979
- return _context18.a(2);
1001
+ return _context19.a(2);
980
1002
  }
981
- }, _callee18, this);
1003
+ }, _callee19, this);
982
1004
  }));
983
1005
  function disconnect() {
984
1006
  return _disconnect.apply(this, arguments);
@@ -999,8 +1021,7 @@ var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
999
1021
  return _regenerator().w(function (_context) {
1000
1022
  while (1) switch (_context.n) {
1001
1023
  case 0:
1002
- pjsApi = new PolkadotJsApi();
1003
- pjsApi.setApi(options.api);
1024
+ pjsApi = new PolkadotJsApi(options.api);
1004
1025
  optionsWithApi = _objectSpread2(_objectSpread2({}, options), {}, {
1005
1026
  api: pjsApi
1006
1027
  });
@@ -1543,6 +1564,8 @@ var EvmBuilderCore = /*#__PURE__*/function () {
1543
1564
  _yield$transferEthToP = _context.v;
1544
1565
  response = _yield$transferEthToP.response;
1545
1566
  return _context.a(2, response.hash);
1567
+ case 6:
1568
+ return _context.a(2);
1546
1569
  }
1547
1570
  }, _callee, this);
1548
1571
  }));
@@ -1573,8 +1596,7 @@ var EvmBuilder$1 = function EvmBuilder(api, provider) {
1573
1596
  * @returns A new Builder instance.
1574
1597
  */
1575
1598
  var Builder = function Builder(api) {
1576
- var pjsApi = new PolkadotJsApi();
1577
- pjsApi.setApi(api);
1599
+ var pjsApi = new PolkadotJsApi(api);
1578
1600
  return sdkCore.Builder(pjsApi);
1579
1601
  };
1580
1602
  var EvmBuilder = function EvmBuilder(provider) {
@@ -1601,8 +1623,7 @@ var getParaEthTransferFees = /*#__PURE__*/function () {
1601
1623
  return _regenerator().w(function (_context) {
1602
1624
  while (1) switch (_context.n) {
1603
1625
  case 0:
1604
- pjsApi = new PolkadotJsApi();
1605
- pjsApi.setApi(api);
1626
+ pjsApi = new PolkadotJsApi(api);
1606
1627
  _context.n = 1;
1607
1628
  return pjsApi.init('AssetHubPolkadot', sdkCore.DRY_RUN_CLIENT_TIMEOUT_MS);
1608
1629
  case 1:
@@ -1623,8 +1644,7 @@ var getBridgeStatus = /*#__PURE__*/function () {
1623
1644
  return _regenerator().w(function (_context2) {
1624
1645
  while (1) switch (_context2.n) {
1625
1646
  case 0:
1626
- pjsApi = new PolkadotJsApi();
1627
- pjsApi.setApi(api);
1647
+ pjsApi = new PolkadotJsApi(api);
1628
1648
  return _context2.a(2, sdkCore.getBridgeStatus(pjsApi));
1629
1649
  }
1630
1650
  }, _callee2);