@paraspell/sdk 7.2.1 → 7.2.2

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
@@ -15051,7 +15051,7 @@ var getExistentialDeposit$1 = function getExistentialDeposit(node) {
15051
15051
  return edMap[node];
15052
15052
  };
15053
15053
 
15054
- var getBalanceNative$1 = function getBalanceNative(_a) {
15054
+ var getBalanceNativeInternal = function getBalanceNativeInternal(_a) {
15055
15055
  return __awaiter(void 0, [_a], void 0, function (_ref) {
15056
15056
  var address = _ref.address,
15057
15057
  node = _ref.node,
@@ -15075,6 +15075,31 @@ var getBalanceNative$1 = function getBalanceNative(_a) {
15075
15075
  })();
15076
15076
  });
15077
15077
  };
15078
+ var getBalanceNative$1 = function getBalanceNative(options) {
15079
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
15080
+ var api;
15081
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
15082
+ while (1) switch (_context2.prev = _context2.next) {
15083
+ case 0:
15084
+ api = options.api;
15085
+ _context2.prev = 1;
15086
+ _context2.next = 4;
15087
+ return getBalanceNativeInternal(options);
15088
+ case 4:
15089
+ return _context2.abrupt("return", _context2.sent);
15090
+ case 5:
15091
+ _context2.prev = 5;
15092
+ _context2.next = 8;
15093
+ return api.disconnect();
15094
+ case 8:
15095
+ return _context2.finish(5);
15096
+ case 9:
15097
+ case "end":
15098
+ return _context2.stop();
15099
+ }
15100
+ }, _callee2, null, [[1,, 5, 9]]);
15101
+ }));
15102
+ };
15078
15103
 
15079
15104
  var AssetHubPolkadot = {
15080
15105
  defaultPallet: "PolkadotXcm",
@@ -15991,14 +16016,14 @@ var getBalanceForeignXTokens = function getBalanceForeignXTokens(api, node, addr
15991
16016
  }));
15992
16017
  };
15993
16018
 
15994
- var getBalanceForeign$1 = function getBalanceForeign(_a) {
16019
+ var getBalanceForeignInternal = function getBalanceForeignInternal(_a) {
15995
16020
  return __awaiter(void 0, [_a], void 0, function (_ref) {
15996
16021
  var address = _ref.address,
15997
16022
  node = _ref.node,
15998
16023
  currency = _ref.currency,
15999
16024
  api = _ref.api;
16000
16025
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
16001
- var _b, asset;
16026
+ var _b, asset, defaultPallet;
16002
16027
  return _regeneratorRuntime().wrap(function _callee$(_context) {
16003
16028
  while (1) switch (_context.prev = _context.next) {
16004
16029
  case 0:
@@ -16012,26 +16037,27 @@ var getBalanceForeign$1 = function getBalanceForeign(_a) {
16012
16037
  }
16013
16038
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " not found on ").concat(node));
16014
16039
  case 5:
16015
- if (!(getDefaultPallet(node) === 'XTokens')) {
16016
- _context.next = 11;
16040
+ defaultPallet = getDefaultPallet(node);
16041
+ if (!(defaultPallet === 'XTokens')) {
16042
+ _context.next = 12;
16017
16043
  break;
16018
16044
  }
16019
- _context.next = 8;
16045
+ _context.next = 9;
16020
16046
  return getBalanceForeignXTokens(api, node, address, asset);
16021
- case 8:
16047
+ case 9:
16022
16048
  return _context.abrupt("return", _context.sent);
16023
- case 11:
16024
- if (!(getDefaultPallet(node) === 'PolkadotXcm')) {
16025
- _context.next = 15;
16049
+ case 12:
16050
+ if (!(defaultPallet === 'PolkadotXcm')) {
16051
+ _context.next = 16;
16026
16052
  break;
16027
16053
  }
16028
- _context.next = 14;
16054
+ _context.next = 15;
16029
16055
  return getBalanceForeignPolkadotXcm(api, node, address, asset);
16030
- case 14:
16031
- return _context.abrupt("return", _context.sent);
16032
16056
  case 15:
16033
- throw new Error('Unsupported pallet');
16057
+ return _context.abrupt("return", _context.sent);
16034
16058
  case 16:
16059
+ throw new Error('Unsupported pallet');
16060
+ case 17:
16035
16061
  case "end":
16036
16062
  return _context.stop();
16037
16063
  }
@@ -16039,8 +16065,33 @@ var getBalanceForeign$1 = function getBalanceForeign(_a) {
16039
16065
  })();
16040
16066
  });
16041
16067
  };
16068
+ var getBalanceForeign$1 = function getBalanceForeign(options) {
16069
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
16070
+ var api;
16071
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
16072
+ while (1) switch (_context2.prev = _context2.next) {
16073
+ case 0:
16074
+ api = options.api;
16075
+ _context2.prev = 1;
16076
+ _context2.next = 4;
16077
+ return getBalanceForeignInternal(options);
16078
+ case 4:
16079
+ return _context2.abrupt("return", _context2.sent);
16080
+ case 5:
16081
+ _context2.prev = 5;
16082
+ _context2.next = 8;
16083
+ return api.disconnect();
16084
+ case 8:
16085
+ return _context2.finish(5);
16086
+ case 9:
16087
+ case "end":
16088
+ return _context2.stop();
16089
+ }
16090
+ }, _callee2, null, [[1,, 5, 9]]);
16091
+ }));
16092
+ };
16042
16093
 
16043
- var getAssetBalance$1 = function getAssetBalance(_a) {
16094
+ var getAssetBalanceInternal = function getAssetBalanceInternal(_a) {
16044
16095
  return __awaiter(void 0, [_a], void 0, function (_ref) {
16045
16096
  var address = _ref.address,
16046
16097
  node = _ref.node,
@@ -16060,7 +16111,7 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16060
16111
  break;
16061
16112
  }
16062
16113
  _context.next = 6;
16063
- return getBalanceNative$1({
16114
+ return getBalanceNativeInternal({
16064
16115
  address: address,
16065
16116
  node: node,
16066
16117
  api: api
@@ -16071,7 +16122,7 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16071
16122
  break;
16072
16123
  case 9:
16073
16124
  _context.next = 11;
16074
- return getBalanceForeign$1({
16125
+ return getBalanceForeignInternal({
16075
16126
  address: address,
16076
16127
  node: node,
16077
16128
  api: api,
@@ -16107,6 +16158,31 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16107
16158
  })();
16108
16159
  });
16109
16160
  };
16161
+ var getAssetBalance$1 = function getAssetBalance(options) {
16162
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
16163
+ var api;
16164
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
16165
+ while (1) switch (_context2.prev = _context2.next) {
16166
+ case 0:
16167
+ api = options.api;
16168
+ _context2.prev = 1;
16169
+ _context2.next = 4;
16170
+ return getAssetBalanceInternal(options);
16171
+ case 4:
16172
+ return _context2.abrupt("return", _context2.sent);
16173
+ case 5:
16174
+ _context2.prev = 5;
16175
+ _context2.next = 8;
16176
+ return api.disconnect();
16177
+ case 8:
16178
+ return _context2.finish(5);
16179
+ case 9:
16180
+ case "end":
16181
+ return _context2.stop();
16182
+ }
16183
+ }, _callee2, null, [[1,, 5, 9]]);
16184
+ }));
16185
+ };
16110
16186
 
16111
16187
  var palletsMap = edsMapJson;
16112
16188
  var getExistentialDeposit = function getExistentialDeposit(node) {
@@ -16125,7 +16201,7 @@ var getMaxNativeTransferableAmount = function getMaxNativeTransferableAmount(api
16125
16201
  case 0:
16126
16202
  ed = getExistentialDeposit(node);
16127
16203
  _context.next = 3;
16128
- return getBalanceNative$1({
16204
+ return getBalanceNativeInternal({
16129
16205
  address: address,
16130
16206
  node: node,
16131
16207
  api: api
@@ -16561,6 +16637,10 @@ var ParaToRelayBuilder = /*#__PURE__*/function () {
16561
16637
  }]);
16562
16638
  }();
16563
16639
 
16640
+ var isPjsClient = function isPjsClient(api) {
16641
+ return _typeof(api) === 'object' && api !== null && 'disconnect' in api && typeof api.disconnect === 'function';
16642
+ };
16643
+
16564
16644
  var buildBeneficiaryInput = function buildBeneficiaryInput(api, address) {
16565
16645
  if (isTMultiLocation(address)) {
16566
16646
  return address;
@@ -16604,6 +16684,7 @@ var claimAssets$1 = function claimAssets(options) {
16604
16684
  _context.next = 3;
16605
16685
  return api.init(node);
16606
16686
  case 3:
16687
+ _context.prev = 3;
16607
16688
  args = buildClaimAssetsInput(options);
16608
16689
  module = isRelayChain(node) ? 'XcmPallet' : 'PolkadotXcm';
16609
16690
  call = {
@@ -16612,20 +16693,29 @@ var claimAssets$1 = function claimAssets(options) {
16612
16693
  parameters: args
16613
16694
  };
16614
16695
  if (!(serializedApiCallEnabled === true)) {
16615
- _context.next = 8;
16696
+ _context.next = 9;
16616
16697
  break;
16617
16698
  }
16618
16699
  return _context.abrupt("return", Object.assign(Object.assign({}, call), {
16619
- // Keep compatible with the old SerializedCall type
16620
16700
  parameters: Object.values(args)
16621
16701
  }));
16622
- case 8:
16623
- return _context.abrupt("return", api.callTxMethod(call));
16624
16702
  case 9:
16703
+ return _context.abrupt("return", api.callTxMethod(call));
16704
+ case 10:
16705
+ _context.prev = 10;
16706
+ if (!isPjsClient(api)) {
16707
+ _context.next = 14;
16708
+ break;
16709
+ }
16710
+ _context.next = 14;
16711
+ return api.disconnect();
16712
+ case 14:
16713
+ return _context.finish(10);
16714
+ case 15:
16625
16715
  case "end":
16626
16716
  return _context.stop();
16627
16717
  }
16628
- }, _callee);
16718
+ }, _callee, null, [[3,, 10, 15]]);
16629
16719
  }));
16630
16720
  };
16631
16721
 
@@ -17212,7 +17302,7 @@ var EvmBuilder = function EvmBuilder(provider) {
17212
17302
  return new EvmBuilderClass(provider);
17213
17303
  };
17214
17304
 
17215
- var createTx$1 = function createTx(originApi, address, amount, currency, originNode, destNode) {
17305
+ var createTx$1 = function createTx(api, address, amount, currency, originNode, destNode) {
17216
17306
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17217
17307
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17218
17308
  while (1) switch (_context.prev = _context.next) {
@@ -17222,7 +17312,7 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17222
17312
  break;
17223
17313
  }
17224
17314
  _context.next = 3;
17225
- return Builder$1(originApi).to(destNode).amount(amount).address(address).build();
17315
+ return Builder$1(api).to(destNode).amount(amount).address(address).build();
17226
17316
  case 3:
17227
17317
  return _context.abrupt("return", _context.sent);
17228
17318
  case 6:
@@ -17231,12 +17321,12 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17231
17321
  break;
17232
17322
  }
17233
17323
  _context.next = 9;
17234
- return Builder$1(originApi).from(originNode).amount(amount).address(address).build();
17324
+ return Builder$1(api).from(originNode).amount(amount).address(address).build();
17235
17325
  case 9:
17236
17326
  return _context.abrupt("return", _context.sent);
17237
17327
  case 12:
17238
17328
  _context.next = 14;
17239
- return Builder$1(originApi).from(originNode).to(destNode).currency(currency).amount(amount).address(address).build();
17329
+ return Builder$1(api).from(originNode).to(destNode).currency(currency).amount(amount).address(address).build();
17240
17330
  case 14:
17241
17331
  return _context.abrupt("return", _context.sent);
17242
17332
  case 15:
@@ -17246,7 +17336,7 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17246
17336
  }, _callee);
17247
17337
  }));
17248
17338
  };
17249
- var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17339
+ var getOriginFeeDetailsInternal = function getOriginFeeDetailsInternal(_a) {
17250
17340
  return __awaiter(void 0, [_a], void 0, function (_ref) {
17251
17341
  var api = _ref.api,
17252
17342
  account = _ref.account,
@@ -17258,34 +17348,37 @@ var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17258
17348
  _ref$feeMarginPercent = _ref.feeMarginPercentage,
17259
17349
  feeMarginPercentage = _ref$feeMarginPercent === void 0 ? 10 : _ref$feeMarginPercent;
17260
17350
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
17261
- var nativeBalance, minTransferableAmount, tx, xcmFee, xcmFeeWithMargin, sufficientForXCM;
17351
+ var tx, xcmFee, xcmFeeWithMargin, nativeBalance, minTransferableAmount, sufficientForXCM;
17262
17352
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
17263
17353
  while (1) switch (_context2.prev = _context2.next) {
17264
17354
  case 0:
17265
17355
  _context2.next = 2;
17266
- return getBalanceNative$1({
17267
- address: account,
17268
- node: origin,
17269
- api: api
17270
- });
17356
+ return api.init(origin);
17271
17357
  case 2:
17272
- nativeBalance = _context2.sent;
17273
- minTransferableAmount = getMinNativeTransferableAmount(origin);
17274
- _context2.next = 6;
17358
+ _context2.next = 4;
17275
17359
  return createTx$1(api, accountDestination, amount, currency, origin, destination);
17276
- case 6:
17360
+ case 4:
17277
17361
  tx = _context2.sent;
17278
- _context2.next = 9;
17362
+ _context2.next = 7;
17279
17363
  return api.calculateTransactionFee(tx, account);
17280
- case 9:
17364
+ case 7:
17281
17365
  xcmFee = _context2.sent;
17282
17366
  xcmFeeWithMargin = xcmFee + xcmFee / BigInt(feeMarginPercentage);
17367
+ _context2.next = 11;
17368
+ return getBalanceNativeInternal({
17369
+ address: account,
17370
+ node: origin,
17371
+ api: api
17372
+ });
17373
+ case 11:
17374
+ nativeBalance = _context2.sent;
17375
+ minTransferableAmount = getMinNativeTransferableAmount(origin);
17283
17376
  sufficientForXCM = nativeBalance - minTransferableAmount - xcmFeeWithMargin > 0;
17284
17377
  return _context2.abrupt("return", {
17285
17378
  sufficientForXCM: sufficientForXCM,
17286
17379
  xcmFee: xcmFee
17287
17380
  });
17288
- case 13:
17381
+ case 15:
17289
17382
  case "end":
17290
17383
  return _context2.stop();
17291
17384
  }
@@ -17293,6 +17386,33 @@ var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17293
17386
  })();
17294
17387
  });
17295
17388
  };
17389
+ var getOriginFeeDetails$1 = function getOriginFeeDetails(options) {
17390
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
17391
+ var api;
17392
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
17393
+ while (1) switch (_context3.prev = _context3.next) {
17394
+ case 0:
17395
+ api = options.api;
17396
+ api.setDisconnectAllowed(false);
17397
+ _context3.prev = 2;
17398
+ _context3.next = 5;
17399
+ return getOriginFeeDetailsInternal(options);
17400
+ case 5:
17401
+ return _context3.abrupt("return", _context3.sent);
17402
+ case 6:
17403
+ _context3.prev = 6;
17404
+ api.setDisconnectAllowed(true);
17405
+ _context3.next = 10;
17406
+ return api.disconnect();
17407
+ case 10:
17408
+ return _context3.finish(6);
17409
+ case 11:
17410
+ case "end":
17411
+ return _context3.stop();
17412
+ }
17413
+ }, _callee3, null, [[2,, 6, 11]]);
17414
+ }));
17415
+ };
17296
17416
 
17297
17417
  var getTransferInfo$1 = function getTransferInfo(_a) {
17298
17418
  return __awaiter(void 0, [_a], void 0, function (_ref) {
@@ -17302,77 +17422,72 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17302
17422
  accountDestination = _ref.accountDestination,
17303
17423
  currency = _ref.currency,
17304
17424
  amount = _ref.amount,
17305
- originApi = _ref.api;
17425
+ api = _ref.api;
17306
17426
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17307
17427
  var _b, _c, _d, originBalance, xcmFeeDetails, expectedBalanceAfterXCMDelivery, asset;
17308
17428
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17309
17429
  while (1) switch (_context.prev = _context.next) {
17310
17430
  case 0:
17311
17431
  _context.next = 2;
17312
- return originApi.init(origin);
17432
+ return api.init(origin);
17313
17433
  case 2:
17314
- _context.next = 4;
17315
- return getBalanceNative$1({
17434
+ api.setDisconnectAllowed(false);
17435
+ _context.prev = 3;
17436
+ _context.next = 6;
17437
+ return getBalanceNativeInternal({
17316
17438
  address: accountOrigin,
17317
17439
  node: origin,
17318
- api: originApi
17440
+ api: api
17319
17441
  });
17320
- case 4:
17442
+ case 6:
17321
17443
  originBalance = _context.sent;
17322
- _context.next = 7;
17323
- return getOriginFeeDetails$1({
17444
+ _context.next = 9;
17445
+ return getOriginFeeDetailsInternal({
17324
17446
  origin: origin,
17325
17447
  destination: destination,
17326
17448
  currency: currency,
17327
17449
  amount: amount,
17328
17450
  account: accountOrigin,
17329
17451
  accountDestination: accountDestination,
17330
- api: originApi
17452
+ api: api
17331
17453
  });
17332
- case 7:
17454
+ case 9:
17333
17455
  xcmFeeDetails = _context.sent;
17334
17456
  expectedBalanceAfterXCMDelivery = originBalance - xcmFeeDetails.xcmFee;
17335
17457
  asset = (_b = getAssetBySymbolOrId(origin, currency, destination)) !== null && _b !== void 0 ? _b : origin === 'AssetHubPolkadot' ? getAssetBySymbolOrId('Ethereum', currency, null) : null;
17336
17458
  if (asset) {
17337
- _context.next = 12;
17459
+ _context.next = 14;
17338
17460
  break;
17339
17461
  }
17340
17462
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " not found on ").concat(origin));
17341
- case 12:
17463
+ case 14:
17342
17464
  _context.t0 = {
17343
17465
  origin: origin,
17344
17466
  destination: destination,
17345
17467
  ecosystem: determineRelayChainSymbol(origin)
17346
17468
  };
17347
- _context.next = 15;
17348
- return getAssetBalance$1({
17349
- api: originApi,
17469
+ _context.next = 17;
17470
+ return getAssetBalanceInternal({
17471
+ api: api,
17350
17472
  address: accountOrigin,
17351
17473
  node: origin,
17352
17474
  currency: currency
17353
17475
  });
17354
- case 15:
17476
+ case 17:
17355
17477
  _context.t1 = _context.sent;
17356
17478
  _context.t2 = (_c = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _c !== void 0 ? _c : '';
17357
17479
  _context.t3 = {
17358
17480
  balance: _context.t1,
17359
17481
  currency: _context.t2
17360
17482
  };
17361
- _context.next = 20;
17362
- return getBalanceNative$1({
17363
- address: accountOrigin,
17364
- node: origin,
17365
- api: originApi
17366
- });
17367
- case 20:
17368
- _context.t4 = _context.sent;
17483
+ _context.t4 = originBalance;
17369
17484
  _context.t5 = expectedBalanceAfterXCMDelivery;
17370
17485
  _context.t6 = xcmFeeDetails;
17371
17486
  _context.t7 = BigInt((_d = getExistentialDeposit(origin)) !== null && _d !== void 0 ? _d : 0);
17372
17487
  _context.t8 = getNativeAssetSymbol(origin);
17373
17488
  _context.t9 = getMinNativeTransferableAmount(origin);
17374
17489
  _context.next = 28;
17375
- return getMaxNativeTransferableAmount(originApi, accountOrigin, origin);
17490
+ return getMaxNativeTransferableAmount(api, accountOrigin, origin);
17376
17491
  case 28:
17377
17492
  _context.t10 = _context.sent;
17378
17493
  _context.t11 = {
@@ -17385,10 +17500,10 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17385
17500
  maxNativeTransferableAmount: _context.t10
17386
17501
  };
17387
17502
  _context.next = 32;
17388
- return getBalanceNative$1({
17503
+ return getBalanceNativeInternal({
17389
17504
  address: accountDestination,
17390
17505
  node: destination,
17391
- api: originApi
17506
+ api: api
17392
17507
  });
17393
17508
  case 32:
17394
17509
  _context.t12 = _context.sent;
@@ -17406,10 +17521,17 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17406
17521
  destinationFeeBalance: _context.t15
17407
17522
  });
17408
17523
  case 37:
17524
+ _context.prev = 37;
17525
+ api.setDisconnectAllowed(true);
17526
+ _context.next = 41;
17527
+ return api.disconnect();
17528
+ case 41:
17529
+ return _context.finish(37);
17530
+ case 42:
17409
17531
  case "end":
17410
17532
  return _context.stop();
17411
17533
  }
17412
- }, _callee);
17534
+ }, _callee, null, [[3,, 37, 42]]);
17413
17535
  })();
17414
17536
  });
17415
17537
  };
@@ -17544,7 +17666,7 @@ var checkKeepAlive = function checkKeepAlive(_a) {
17544
17666
  asset = _ref.asset,
17545
17667
  destNode = _ref.destNode;
17546
17668
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17547
- var balance, balanceOrigin, amountBN, ed, edOrigin, tx, xcmFee, increasedFee, amountBNWithoutFee, amountOriginBNWithoutFee;
17669
+ var balance, balanceOrigin, amountBN, ed, edOrigin, oldDisconnectAllowed, tx, xcmFee, increasedFee, amountBNWithoutFee, amountOriginBNWithoutFee;
17548
17670
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17549
17671
  while (1) switch (_context.prev = _context.next) {
17550
17672
  case 0:
@@ -17577,47 +17699,50 @@ var checkKeepAlive = function checkKeepAlive(_a) {
17577
17699
  amountBN = BigInt(amount);
17578
17700
  ed = getExistentialDeposit$1(destNode !== null && destNode !== void 0 ? destNode : determineRelayChain(originNode));
17579
17701
  edOrigin = getExistentialDeposit$1(originNode !== null && originNode !== void 0 ? originNode : determineRelayChain(destNode));
17580
- _context.next = 17;
17702
+ oldDisconnectAllowed = originApi.getDisconnectAllowed();
17703
+ originApi.setDisconnectAllowed(false);
17704
+ _context.next = 19;
17581
17705
  return createTx(originApi, destApi, address, amount, asset.symbol, originNode, destNode);
17582
- case 17:
17706
+ case 19:
17583
17707
  tx = _context.sent;
17708
+ originApi.setDisconnectAllowed(oldDisconnectAllowed);
17584
17709
  if (!(tx === null)) {
17585
- _context.next = 20;
17710
+ _context.next = 23;
17586
17711
  break;
17587
17712
  }
17588
17713
  throw new KeepAliveError('Transaction for XCM fee calculation could not be created.');
17589
- case 20:
17590
- _context.next = 22;
17714
+ case 23:
17715
+ _context.next = 25;
17591
17716
  return originApi.calculateTransactionFee(tx, address);
17592
- case 22:
17717
+ case 25:
17593
17718
  xcmFee = _context.sent;
17594
17719
  if (!(ed === null)) {
17595
- _context.next = 25;
17720
+ _context.next = 28;
17596
17721
  break;
17597
17722
  }
17598
17723
  throw new KeepAliveError('Existential deposit not found for destination parachain.');
17599
- case 25:
17724
+ case 28:
17600
17725
  if (!(edOrigin === null)) {
17601
- _context.next = 27;
17726
+ _context.next = 30;
17602
17727
  break;
17603
17728
  }
17604
17729
  throw new KeepAliveError('Existential deposit not found for origin parachain.');
17605
- case 27:
17730
+ case 30:
17606
17731
  increasedFee = xcmFee + xcmFee / BigInt(2);
17607
17732
  amountBNWithoutFee = amountBN - increasedFee;
17608
17733
  if (!(balance + amountBNWithoutFee < BigInt(ed))) {
17609
- _context.next = 31;
17734
+ _context.next = 34;
17610
17735
  break;
17611
17736
  }
17612
17737
  throw new KeepAliveError("Keep alive check failed: Sending ".concat(amount, " ").concat(asset.symbol, " to ").concat(destNode, " would result in an account balance below the required existential deposit.\n Please increase the amount to meet the minimum balance requirement of the destination chain."));
17613
- case 31:
17738
+ case 34:
17614
17739
  amountOriginBNWithoutFee = amountBN - (xcmFee + xcmFee / BigInt(2));
17615
17740
  if (!((asset.symbol === 'DOT' || asset.symbol === 'KSM') && balanceOrigin - amountOriginBNWithoutFee > BigInt(edOrigin))) {
17616
- _context.next = 34;
17741
+ _context.next = 37;
17617
17742
  break;
17618
17743
  }
17619
17744
  throw new KeepAliveError("Keep alive check failed: Sending ".concat(amount, " ").concat(asset.symbol, " to ").concat(destNode, " would result in an account balance below the required existential deposit on origin.\n Please decrease the amount to meet the minimum balance requirement of the origin chain."));
17620
- case 34:
17745
+ case 37:
17621
17746
  case "end":
17622
17747
  return _context.stop();
17623
17748
  }
@@ -17751,48 +17876,49 @@ var sendCommon = function sendCommon(options_1) {
17751
17876
  _context.next = 45;
17752
17877
  return api.init(origin);
17753
17878
  case 45:
17879
+ _context.prev = 45;
17754
17880
  amountStr = amount === null || amount === void 0 ? void 0 : amount.toString();
17755
17881
  if (!('multilocation' in currency || 'multiasset' in currency)) {
17756
- _context.next = 50;
17882
+ _context.next = 51;
17757
17883
  break;
17758
17884
  }
17759
17885
  console.warn('Keep alive check is not supported when using MultiLocation as currency.');
17760
- _context.next = 68;
17886
+ _context.next = 69;
17761
17887
  break;
17762
- case 50:
17888
+ case 51:
17763
17889
  if (!(_typeof(address) === 'object')) {
17764
- _context.next = 54;
17890
+ _context.next = 55;
17765
17891
  break;
17766
17892
  }
17767
17893
  console.warn('Keep alive check is not supported when using MultiLocation as address.');
17768
- _context.next = 68;
17894
+ _context.next = 69;
17769
17895
  break;
17770
- case 54:
17896
+ case 55:
17771
17897
  if (!(_typeof(destination) === 'object')) {
17772
- _context.next = 58;
17898
+ _context.next = 59;
17773
17899
  break;
17774
17900
  }
17775
17901
  console.warn('Keep alive check is not supported when using MultiLocation as destination.');
17776
- _context.next = 68;
17902
+ _context.next = 69;
17777
17903
  break;
17778
- case 58:
17904
+ case 59:
17779
17905
  if (!(destination === 'Ethereum')) {
17780
- _context.next = 62;
17906
+ _context.next = 63;
17781
17907
  break;
17782
17908
  }
17783
17909
  console.warn('Keep alive check is not supported when using Ethereum as origin or destination.');
17784
- _context.next = 68;
17910
+ _context.next = 69;
17785
17911
  break;
17786
- case 62:
17912
+ case 63:
17787
17913
  if (asset) {
17788
- _context.next = 66;
17914
+ _context.next = 67;
17789
17915
  break;
17790
17916
  }
17791
17917
  console.warn('Keep alive check is not supported when asset check is disabled.');
17792
- _context.next = 68;
17918
+ _context.next = 69;
17793
17919
  break;
17794
- case 66:
17795
- _context.next = 68;
17920
+ case 67:
17921
+ _context.next = 69;
17796
17922
  return checkKeepAlive({
17797
17923
  originApi: api,
17798
17924
  address: address,
@@ -17802,7 +17928,7 @@ var sendCommon = function sendCommon(options_1) {
17802
17928
  asset: asset,
17803
17929
  destNode: destination
17804
17930
  });
17805
- case 68:
17931
+ case 69:
17806
17932
  // In case asset check is disabled, we create asset object from currency symbol
17807
17933
  resolvedAsset = asset !== null && asset !== void 0 ? asset : {
17808
17934
  symbol: 'symbol' in currency ? currency.symbol : undefined
@@ -17821,11 +17947,21 @@ var sendCommon = function sendCommon(options_1) {
17821
17947
  serializedApiCallEnabled: serializedApiCallEnabled,
17822
17948
  ahAddress: ahAddress
17823
17949
  }));
17824
- case 70:
17950
+ case 71:
17951
+ _context.prev = 71;
17952
+ if (!isPjsClient(api)) {
17953
+ _context.next = 75;
17954
+ break;
17955
+ }
17956
+ _context.next = 75;
17957
+ return api.disconnect();
17958
+ case 75:
17959
+ return _context.finish(71);
17960
+ case 76:
17825
17961
  case "end":
17826
17962
  return _context.stop();
17827
17963
  }
17828
- }, _callee);
17964
+ }, _callee, null, [[45,, 71, 76]]);
17829
17965
  })();
17830
17966
  });
17831
17967
  };
@@ -17878,24 +18014,25 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17878
18014
  _context4.next = 7;
17879
18015
  return api.init(determineRelayChain(destination));
17880
18016
  case 7:
18017
+ _context4.prev = 7;
17881
18018
  amountStr = amount.toString();
17882
18019
  if (!isMultiLocationDestination) {
17883
- _context4.next = 12;
18020
+ _context4.next = 13;
17884
18021
  break;
17885
18022
  }
17886
18023
  console.warn('Keep alive check is not supported when using MultiLocation as destination.');
17887
- _context4.next = 18;
18024
+ _context4.next = 19;
17888
18025
  break;
17889
- case 12:
18026
+ case 13:
17890
18027
  if (!isAddressMultiLocation) {
17891
- _context4.next = 16;
18028
+ _context4.next = 17;
17892
18029
  break;
17893
18030
  }
17894
18031
  console.warn('Keep alive check is not supported when using MultiLocation as address.');
17895
- _context4.next = 18;
18032
+ _context4.next = 19;
17896
18033
  break;
17897
- case 16:
17898
- _context4.next = 18;
18034
+ case 17:
18035
+ _context4.next = 19;
17899
18036
  return checkKeepAlive({
17900
18037
  originApi: api,
17901
18038
  address: address,
@@ -17906,7 +18043,7 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17906
18043
  },
17907
18044
  destNode: destination
17908
18045
  });
17909
- case 18:
18046
+ case 19:
17910
18047
  serializedApiCall = getNode(isMultiLocationDestination ? resolveTNodeFromMultiLocation(destination) : destination).transferRelayToPara({
17911
18048
  api: api,
17912
18049
  destination: destination,
@@ -17917,19 +18054,29 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17917
18054
  version: version
17918
18055
  });
17919
18056
  if (!serializedApiCallEnabled) {
17920
- _context4.next = 21;
18057
+ _context4.next = 22;
17921
18058
  break;
17922
18059
  }
17923
18060
  return _context4.abrupt("return", Object.assign(Object.assign({}, serializedApiCall), {
17924
18061
  parameters: Object.values(serializedApiCall.parameters)
17925
18062
  }));
17926
- case 21:
17927
- return _context4.abrupt("return", api.callTxMethod(serializedApiCall));
17928
18063
  case 22:
18064
+ return _context4.abrupt("return", api.callTxMethod(serializedApiCall));
18065
+ case 23:
18066
+ _context4.prev = 23;
18067
+ if (!isPjsClient(api)) {
18068
+ _context4.next = 27;
18069
+ break;
18070
+ }
18071
+ _context4.next = 27;
18072
+ return api.disconnect();
18073
+ case 27:
18074
+ return _context4.finish(23);
18075
+ case 28:
17929
18076
  case "end":
17930
18077
  return _context4.stop();
17931
18078
  }
17932
- }, _callee4);
18079
+ }, _callee4, null, [[7,, 23, 28]]);
17933
18080
  })();
17934
18081
  });
17935
18082
  };
@@ -17971,6 +18118,8 @@ var snakeToCamel = function snakeToCamel(str) {
17971
18118
  var PolkadotJsApi = /*#__PURE__*/function () {
17972
18119
  function PolkadotJsApi() {
17973
18120
  _classCallCheck(this, PolkadotJsApi);
18121
+ this.initialized = false;
18122
+ this.disconnectAllowed = true;
17974
18123
  }
17975
18124
  return _createClass(PolkadotJsApi, [{
17976
18125
  key: "setApi",
@@ -17990,32 +18139,40 @@ var PolkadotJsApi = /*#__PURE__*/function () {
17990
18139
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17991
18140
  while (1) switch (_context.prev = _context.next) {
17992
18141
  case 0:
18142
+ if (!this.initialized) {
18143
+ _context.next = 2;
18144
+ break;
18145
+ }
18146
+ return _context.abrupt("return");
18147
+ case 2:
17993
18148
  if (!(typeof this._api === 'string')) {
17994
- _context.next = 6;
18149
+ _context.next = 8;
17995
18150
  break;
17996
18151
  }
17997
- _context.next = 3;
18152
+ _context.next = 5;
17998
18153
  return this.createApiInstance(this._api);
17999
- case 3:
18154
+ case 5:
18000
18155
  this.api = _context.sent;
18001
- _context.next = 14;
18156
+ _context.next = 16;
18002
18157
  break;
18003
- case 6:
18158
+ case 8:
18004
18159
  if (!((_a = this._api) !== null && _a !== void 0)) {
18005
- _context.next = 10;
18160
+ _context.next = 12;
18006
18161
  break;
18007
18162
  }
18008
18163
  _context.t0 = _a;
18009
- _context.next = 13;
18164
+ _context.next = 15;
18010
18165
  break;
18011
- case 10:
18012
- _context.next = 12;
18013
- return createApiInstanceForNode$1(this, node);
18014
18166
  case 12:
18167
+ _context.next = 14;
18168
+ return createApiInstanceForNode$1(this, node);
18169
+ case 14:
18015
18170
  _context.t0 = _context.sent;
18016
- case 13:
18171
+ case 15:
18017
18172
  this.api = _context.t0;
18018
- case 14:
18173
+ case 16:
18174
+ this.initialized = true;
18175
+ case 17:
18019
18176
  case "end":
18020
18177
  return _context.stop();
18021
18178
  }
@@ -18307,6 +18464,42 @@ var PolkadotJsApi = /*#__PURE__*/function () {
18307
18464
  }, _callee13);
18308
18465
  }));
18309
18466
  }
18467
+ }, {
18468
+ key: "setDisconnectAllowed",
18469
+ value: function setDisconnectAllowed(allowed) {
18470
+ this.disconnectAllowed = allowed;
18471
+ }
18472
+ }, {
18473
+ key: "getDisconnectAllowed",
18474
+ value: function getDisconnectAllowed() {
18475
+ return this.disconnectAllowed;
18476
+ }
18477
+ }, {
18478
+ key: "disconnect",
18479
+ value: function disconnect() {
18480
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
18481
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
18482
+ while (1) switch (_context14.prev = _context14.next) {
18483
+ case 0:
18484
+ if (this.disconnectAllowed) {
18485
+ _context14.next = 2;
18486
+ break;
18487
+ }
18488
+ return _context14.abrupt("return");
18489
+ case 2:
18490
+ if (!(typeof this._api === 'string' || this._api === undefined)) {
18491
+ _context14.next = 5;
18492
+ break;
18493
+ }
18494
+ _context14.next = 5;
18495
+ return this.api.disconnect();
18496
+ case 5:
18497
+ case "end":
18498
+ return _context14.stop();
18499
+ }
18500
+ }, _callee14, this);
18501
+ }));
18502
+ }
18310
18503
  }]);
18311
18504
  }();
18312
18505