@paraspell/sdk 7.2.0 → 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.
@@ -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",
@@ -15976,8 +16001,14 @@ var getBalanceForeignXTokens = function getBalanceForeignXTokens(api, node, addr
15976
16001
  case 3:
15977
16002
  return _context.abrupt("return", api.getBalanceForeignAssetsAccount(address, BigInt(asset.assetId)));
15978
16003
  case 4:
16004
+ if (!(node === 'BifrostPolkadot' || node === 'BifrostKusama')) {
16005
+ _context.next = 6;
16006
+ break;
16007
+ }
16008
+ return _context.abrupt("return", api.getBalanceForeignBifrost(address, asset));
16009
+ case 6:
15979
16010
  return _context.abrupt("return", api.getBalanceForeignXTokens(address, asset));
15980
- case 5:
16011
+ case 7:
15981
16012
  case "end":
15982
16013
  return _context.stop();
15983
16014
  }
@@ -15985,14 +16016,14 @@ var getBalanceForeignXTokens = function getBalanceForeignXTokens(api, node, addr
15985
16016
  }));
15986
16017
  };
15987
16018
 
15988
- var getBalanceForeign$1 = function getBalanceForeign(_a) {
16019
+ var getBalanceForeignInternal = function getBalanceForeignInternal(_a) {
15989
16020
  return __awaiter(void 0, [_a], void 0, function (_ref) {
15990
16021
  var address = _ref.address,
15991
16022
  node = _ref.node,
15992
16023
  currency = _ref.currency,
15993
16024
  api = _ref.api;
15994
16025
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
15995
- var _b, asset;
16026
+ var _b, asset, defaultPallet;
15996
16027
  return _regeneratorRuntime().wrap(function _callee$(_context) {
15997
16028
  while (1) switch (_context.prev = _context.next) {
15998
16029
  case 0:
@@ -16006,26 +16037,27 @@ var getBalanceForeign$1 = function getBalanceForeign(_a) {
16006
16037
  }
16007
16038
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " not found on ").concat(node));
16008
16039
  case 5:
16009
- if (!(getDefaultPallet(node) === 'XTokens')) {
16010
- _context.next = 11;
16040
+ defaultPallet = getDefaultPallet(node);
16041
+ if (!(defaultPallet === 'XTokens')) {
16042
+ _context.next = 12;
16011
16043
  break;
16012
16044
  }
16013
- _context.next = 8;
16045
+ _context.next = 9;
16014
16046
  return getBalanceForeignXTokens(api, node, address, asset);
16015
- case 8:
16047
+ case 9:
16016
16048
  return _context.abrupt("return", _context.sent);
16017
- case 11:
16018
- if (!(getDefaultPallet(node) === 'PolkadotXcm')) {
16019
- _context.next = 15;
16049
+ case 12:
16050
+ if (!(defaultPallet === 'PolkadotXcm')) {
16051
+ _context.next = 16;
16020
16052
  break;
16021
16053
  }
16022
- _context.next = 14;
16054
+ _context.next = 15;
16023
16055
  return getBalanceForeignPolkadotXcm(api, node, address, asset);
16024
- case 14:
16025
- return _context.abrupt("return", _context.sent);
16026
16056
  case 15:
16027
- throw new Error('Unsupported pallet');
16057
+ return _context.abrupt("return", _context.sent);
16028
16058
  case 16:
16059
+ throw new Error('Unsupported pallet');
16060
+ case 17:
16029
16061
  case "end":
16030
16062
  return _context.stop();
16031
16063
  }
@@ -16033,8 +16065,33 @@ var getBalanceForeign$1 = function getBalanceForeign(_a) {
16033
16065
  })();
16034
16066
  });
16035
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
+ };
16036
16093
 
16037
- var getAssetBalance$1 = function getAssetBalance(_a) {
16094
+ var getAssetBalanceInternal = function getAssetBalanceInternal(_a) {
16038
16095
  return __awaiter(void 0, [_a], void 0, function (_ref) {
16039
16096
  var address = _ref.address,
16040
16097
  node = _ref.node,
@@ -16054,7 +16111,7 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16054
16111
  break;
16055
16112
  }
16056
16113
  _context.next = 6;
16057
- return getBalanceNative$1({
16114
+ return getBalanceNativeInternal({
16058
16115
  address: address,
16059
16116
  node: node,
16060
16117
  api: api
@@ -16065,7 +16122,7 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16065
16122
  break;
16066
16123
  case 9:
16067
16124
  _context.next = 11;
16068
- return getBalanceForeign$1({
16125
+ return getBalanceForeignInternal({
16069
16126
  address: address,
16070
16127
  node: node,
16071
16128
  api: api,
@@ -16101,6 +16158,31 @@ var getAssetBalance$1 = function getAssetBalance(_a) {
16101
16158
  })();
16102
16159
  });
16103
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
+ };
16104
16186
 
16105
16187
  var palletsMap = edsMapJson;
16106
16188
  var getExistentialDeposit = function getExistentialDeposit(node) {
@@ -16119,7 +16201,7 @@ var getMaxNativeTransferableAmount = function getMaxNativeTransferableAmount(api
16119
16201
  case 0:
16120
16202
  ed = getExistentialDeposit(node);
16121
16203
  _context.next = 3;
16122
- return getBalanceNative$1({
16204
+ return getBalanceNativeInternal({
16123
16205
  address: address,
16124
16206
  node: node,
16125
16207
  api: api
@@ -16555,6 +16637,10 @@ var ParaToRelayBuilder = /*#__PURE__*/function () {
16555
16637
  }]);
16556
16638
  }();
16557
16639
 
16640
+ var isPjsClient = function isPjsClient(api) {
16641
+ return _typeof(api) === 'object' && api !== null && 'disconnect' in api && typeof api.disconnect === 'function';
16642
+ };
16643
+
16558
16644
  var buildBeneficiaryInput = function buildBeneficiaryInput(api, address) {
16559
16645
  if (isTMultiLocation(address)) {
16560
16646
  return address;
@@ -16598,6 +16684,7 @@ var claimAssets$1 = function claimAssets(options) {
16598
16684
  _context.next = 3;
16599
16685
  return api.init(node);
16600
16686
  case 3:
16687
+ _context.prev = 3;
16601
16688
  args = buildClaimAssetsInput(options);
16602
16689
  module = isRelayChain(node) ? 'XcmPallet' : 'PolkadotXcm';
16603
16690
  call = {
@@ -16606,20 +16693,29 @@ var claimAssets$1 = function claimAssets(options) {
16606
16693
  parameters: args
16607
16694
  };
16608
16695
  if (!(serializedApiCallEnabled === true)) {
16609
- _context.next = 8;
16696
+ _context.next = 9;
16610
16697
  break;
16611
16698
  }
16612
16699
  return _context.abrupt("return", Object.assign(Object.assign({}, call), {
16613
- // Keep compatible with the old SerializedCall type
16614
16700
  parameters: Object.values(args)
16615
16701
  }));
16616
- case 8:
16617
- return _context.abrupt("return", api.callTxMethod(call));
16618
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:
16619
16715
  case "end":
16620
16716
  return _context.stop();
16621
16717
  }
16622
- }, _callee);
16718
+ }, _callee, null, [[3,, 10, 15]]);
16623
16719
  }));
16624
16720
  };
16625
16721
 
@@ -17206,7 +17302,7 @@ var EvmBuilder = function EvmBuilder(provider) {
17206
17302
  return new EvmBuilderClass(provider);
17207
17303
  };
17208
17304
 
17209
- var createTx$1 = function createTx(originApi, address, amount, currency, originNode, destNode) {
17305
+ var createTx$1 = function createTx(api, address, amount, currency, originNode, destNode) {
17210
17306
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17211
17307
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17212
17308
  while (1) switch (_context.prev = _context.next) {
@@ -17216,7 +17312,7 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17216
17312
  break;
17217
17313
  }
17218
17314
  _context.next = 3;
17219
- return Builder$1(originApi).to(destNode).amount(amount).address(address).build();
17315
+ return Builder$1(api).to(destNode).amount(amount).address(address).build();
17220
17316
  case 3:
17221
17317
  return _context.abrupt("return", _context.sent);
17222
17318
  case 6:
@@ -17225,12 +17321,12 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17225
17321
  break;
17226
17322
  }
17227
17323
  _context.next = 9;
17228
- return Builder$1(originApi).from(originNode).amount(amount).address(address).build();
17324
+ return Builder$1(api).from(originNode).amount(amount).address(address).build();
17229
17325
  case 9:
17230
17326
  return _context.abrupt("return", _context.sent);
17231
17327
  case 12:
17232
17328
  _context.next = 14;
17233
- 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();
17234
17330
  case 14:
17235
17331
  return _context.abrupt("return", _context.sent);
17236
17332
  case 15:
@@ -17240,7 +17336,7 @@ var createTx$1 = function createTx(originApi, address, amount, currency, originN
17240
17336
  }, _callee);
17241
17337
  }));
17242
17338
  };
17243
- var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17339
+ var getOriginFeeDetailsInternal = function getOriginFeeDetailsInternal(_a) {
17244
17340
  return __awaiter(void 0, [_a], void 0, function (_ref) {
17245
17341
  var api = _ref.api,
17246
17342
  account = _ref.account,
@@ -17252,34 +17348,37 @@ var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17252
17348
  _ref$feeMarginPercent = _ref.feeMarginPercentage,
17253
17349
  feeMarginPercentage = _ref$feeMarginPercent === void 0 ? 10 : _ref$feeMarginPercent;
17254
17350
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
17255
- var nativeBalance, minTransferableAmount, tx, xcmFee, xcmFeeWithMargin, sufficientForXCM;
17351
+ var tx, xcmFee, xcmFeeWithMargin, nativeBalance, minTransferableAmount, sufficientForXCM;
17256
17352
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
17257
17353
  while (1) switch (_context2.prev = _context2.next) {
17258
17354
  case 0:
17259
17355
  _context2.next = 2;
17260
- return getBalanceNative$1({
17261
- address: account,
17262
- node: origin,
17263
- api: api
17264
- });
17356
+ return api.init(origin);
17265
17357
  case 2:
17266
- nativeBalance = _context2.sent;
17267
- minTransferableAmount = getMinNativeTransferableAmount(origin);
17268
- _context2.next = 6;
17358
+ _context2.next = 4;
17269
17359
  return createTx$1(api, accountDestination, amount, currency, origin, destination);
17270
- case 6:
17360
+ case 4:
17271
17361
  tx = _context2.sent;
17272
- _context2.next = 9;
17362
+ _context2.next = 7;
17273
17363
  return api.calculateTransactionFee(tx, account);
17274
- case 9:
17364
+ case 7:
17275
17365
  xcmFee = _context2.sent;
17276
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);
17277
17376
  sufficientForXCM = nativeBalance - minTransferableAmount - xcmFeeWithMargin > 0;
17278
17377
  return _context2.abrupt("return", {
17279
17378
  sufficientForXCM: sufficientForXCM,
17280
17379
  xcmFee: xcmFee
17281
17380
  });
17282
- case 13:
17381
+ case 15:
17283
17382
  case "end":
17284
17383
  return _context2.stop();
17285
17384
  }
@@ -17287,6 +17386,33 @@ var getOriginFeeDetails$1 = function getOriginFeeDetails(_a) {
17287
17386
  })();
17288
17387
  });
17289
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
+ };
17290
17416
 
17291
17417
  var getTransferInfo$1 = function getTransferInfo(_a) {
17292
17418
  return __awaiter(void 0, [_a], void 0, function (_ref) {
@@ -17296,77 +17422,72 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17296
17422
  accountDestination = _ref.accountDestination,
17297
17423
  currency = _ref.currency,
17298
17424
  amount = _ref.amount,
17299
- originApi = _ref.api;
17425
+ api = _ref.api;
17300
17426
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17301
17427
  var _b, _c, _d, originBalance, xcmFeeDetails, expectedBalanceAfterXCMDelivery, asset;
17302
17428
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17303
17429
  while (1) switch (_context.prev = _context.next) {
17304
17430
  case 0:
17305
17431
  _context.next = 2;
17306
- return originApi.init(origin);
17432
+ return api.init(origin);
17307
17433
  case 2:
17308
- _context.next = 4;
17309
- return getBalanceNative$1({
17434
+ api.setDisconnectAllowed(false);
17435
+ _context.prev = 3;
17436
+ _context.next = 6;
17437
+ return getBalanceNativeInternal({
17310
17438
  address: accountOrigin,
17311
17439
  node: origin,
17312
- api: originApi
17440
+ api: api
17313
17441
  });
17314
- case 4:
17442
+ case 6:
17315
17443
  originBalance = _context.sent;
17316
- _context.next = 7;
17317
- return getOriginFeeDetails$1({
17444
+ _context.next = 9;
17445
+ return getOriginFeeDetailsInternal({
17318
17446
  origin: origin,
17319
17447
  destination: destination,
17320
17448
  currency: currency,
17321
17449
  amount: amount,
17322
17450
  account: accountOrigin,
17323
17451
  accountDestination: accountDestination,
17324
- api: originApi
17452
+ api: api
17325
17453
  });
17326
- case 7:
17454
+ case 9:
17327
17455
  xcmFeeDetails = _context.sent;
17328
17456
  expectedBalanceAfterXCMDelivery = originBalance - xcmFeeDetails.xcmFee;
17329
17457
  asset = (_b = getAssetBySymbolOrId(origin, currency, destination)) !== null && _b !== void 0 ? _b : origin === 'AssetHubPolkadot' ? getAssetBySymbolOrId('Ethereum', currency, null) : null;
17330
17458
  if (asset) {
17331
- _context.next = 12;
17459
+ _context.next = 14;
17332
17460
  break;
17333
17461
  }
17334
17462
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " not found on ").concat(origin));
17335
- case 12:
17463
+ case 14:
17336
17464
  _context.t0 = {
17337
17465
  origin: origin,
17338
17466
  destination: destination,
17339
17467
  ecosystem: determineRelayChainSymbol(origin)
17340
17468
  };
17341
- _context.next = 15;
17342
- return getAssetBalance$1({
17343
- api: originApi,
17469
+ _context.next = 17;
17470
+ return getAssetBalanceInternal({
17471
+ api: api,
17344
17472
  address: accountOrigin,
17345
17473
  node: origin,
17346
17474
  currency: currency
17347
17475
  });
17348
- case 15:
17476
+ case 17:
17349
17477
  _context.t1 = _context.sent;
17350
17478
  _context.t2 = (_c = asset === null || asset === void 0 ? void 0 : asset.symbol) !== null && _c !== void 0 ? _c : '';
17351
17479
  _context.t3 = {
17352
17480
  balance: _context.t1,
17353
17481
  currency: _context.t2
17354
17482
  };
17355
- _context.next = 20;
17356
- return getBalanceNative$1({
17357
- address: accountOrigin,
17358
- node: origin,
17359
- api: originApi
17360
- });
17361
- case 20:
17362
- _context.t4 = _context.sent;
17483
+ _context.t4 = originBalance;
17363
17484
  _context.t5 = expectedBalanceAfterXCMDelivery;
17364
17485
  _context.t6 = xcmFeeDetails;
17365
17486
  _context.t7 = BigInt((_d = getExistentialDeposit(origin)) !== null && _d !== void 0 ? _d : 0);
17366
17487
  _context.t8 = getNativeAssetSymbol(origin);
17367
17488
  _context.t9 = getMinNativeTransferableAmount(origin);
17368
17489
  _context.next = 28;
17369
- return getMaxNativeTransferableAmount(originApi, accountOrigin, origin);
17490
+ return getMaxNativeTransferableAmount(api, accountOrigin, origin);
17370
17491
  case 28:
17371
17492
  _context.t10 = _context.sent;
17372
17493
  _context.t11 = {
@@ -17379,10 +17500,10 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17379
17500
  maxNativeTransferableAmount: _context.t10
17380
17501
  };
17381
17502
  _context.next = 32;
17382
- return getBalanceNative$1({
17503
+ return getBalanceNativeInternal({
17383
17504
  address: accountDestination,
17384
17505
  node: destination,
17385
- api: originApi
17506
+ api: api
17386
17507
  });
17387
17508
  case 32:
17388
17509
  _context.t12 = _context.sent;
@@ -17400,10 +17521,17 @@ var getTransferInfo$1 = function getTransferInfo(_a) {
17400
17521
  destinationFeeBalance: _context.t15
17401
17522
  });
17402
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:
17403
17531
  case "end":
17404
17532
  return _context.stop();
17405
17533
  }
17406
- }, _callee);
17534
+ }, _callee, null, [[3,, 37, 42]]);
17407
17535
  })();
17408
17536
  });
17409
17537
  };
@@ -17538,7 +17666,7 @@ var checkKeepAlive = function checkKeepAlive(_a) {
17538
17666
  asset = _ref.asset,
17539
17667
  destNode = _ref.destNode;
17540
17668
  return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17541
- var balance, balanceOrigin, amountBN, ed, edOrigin, tx, xcmFee, increasedFee, amountBNWithoutFee, amountOriginBNWithoutFee;
17669
+ var balance, balanceOrigin, amountBN, ed, edOrigin, oldDisconnectAllowed, tx, xcmFee, increasedFee, amountBNWithoutFee, amountOriginBNWithoutFee;
17542
17670
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17543
17671
  while (1) switch (_context.prev = _context.next) {
17544
17672
  case 0:
@@ -17571,47 +17699,50 @@ var checkKeepAlive = function checkKeepAlive(_a) {
17571
17699
  amountBN = BigInt(amount);
17572
17700
  ed = getExistentialDeposit$1(destNode !== null && destNode !== void 0 ? destNode : determineRelayChain(originNode));
17573
17701
  edOrigin = getExistentialDeposit$1(originNode !== null && originNode !== void 0 ? originNode : determineRelayChain(destNode));
17574
- _context.next = 17;
17702
+ oldDisconnectAllowed = originApi.getDisconnectAllowed();
17703
+ originApi.setDisconnectAllowed(false);
17704
+ _context.next = 19;
17575
17705
  return createTx(originApi, destApi, address, amount, asset.symbol, originNode, destNode);
17576
- case 17:
17706
+ case 19:
17577
17707
  tx = _context.sent;
17708
+ originApi.setDisconnectAllowed(oldDisconnectAllowed);
17578
17709
  if (!(tx === null)) {
17579
- _context.next = 20;
17710
+ _context.next = 23;
17580
17711
  break;
17581
17712
  }
17582
17713
  throw new KeepAliveError('Transaction for XCM fee calculation could not be created.');
17583
- case 20:
17584
- _context.next = 22;
17714
+ case 23:
17715
+ _context.next = 25;
17585
17716
  return originApi.calculateTransactionFee(tx, address);
17586
- case 22:
17717
+ case 25:
17587
17718
  xcmFee = _context.sent;
17588
17719
  if (!(ed === null)) {
17589
- _context.next = 25;
17720
+ _context.next = 28;
17590
17721
  break;
17591
17722
  }
17592
17723
  throw new KeepAliveError('Existential deposit not found for destination parachain.');
17593
- case 25:
17724
+ case 28:
17594
17725
  if (!(edOrigin === null)) {
17595
- _context.next = 27;
17726
+ _context.next = 30;
17596
17727
  break;
17597
17728
  }
17598
17729
  throw new KeepAliveError('Existential deposit not found for origin parachain.');
17599
- case 27:
17730
+ case 30:
17600
17731
  increasedFee = xcmFee + xcmFee / BigInt(2);
17601
17732
  amountBNWithoutFee = amountBN - increasedFee;
17602
17733
  if (!(balance + amountBNWithoutFee < BigInt(ed))) {
17603
- _context.next = 31;
17734
+ _context.next = 34;
17604
17735
  break;
17605
17736
  }
17606
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."));
17607
- case 31:
17738
+ case 34:
17608
17739
  amountOriginBNWithoutFee = amountBN - (xcmFee + xcmFee / BigInt(2));
17609
17740
  if (!((asset.symbol === 'DOT' || asset.symbol === 'KSM') && balanceOrigin - amountOriginBNWithoutFee > BigInt(edOrigin))) {
17610
- _context.next = 34;
17741
+ _context.next = 37;
17611
17742
  break;
17612
17743
  }
17613
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."));
17614
- case 34:
17745
+ case 37:
17615
17746
  case "end":
17616
17747
  return _context.stop();
17617
17748
  }
@@ -17745,48 +17876,49 @@ var sendCommon = function sendCommon(options_1) {
17745
17876
  _context.next = 45;
17746
17877
  return api.init(origin);
17747
17878
  case 45:
17879
+ _context.prev = 45;
17748
17880
  amountStr = amount === null || amount === void 0 ? void 0 : amount.toString();
17749
17881
  if (!('multilocation' in currency || 'multiasset' in currency)) {
17750
- _context.next = 50;
17882
+ _context.next = 51;
17751
17883
  break;
17752
17884
  }
17753
17885
  console.warn('Keep alive check is not supported when using MultiLocation as currency.');
17754
- _context.next = 68;
17886
+ _context.next = 69;
17755
17887
  break;
17756
- case 50:
17888
+ case 51:
17757
17889
  if (!(_typeof(address) === 'object')) {
17758
- _context.next = 54;
17890
+ _context.next = 55;
17759
17891
  break;
17760
17892
  }
17761
17893
  console.warn('Keep alive check is not supported when using MultiLocation as address.');
17762
- _context.next = 68;
17894
+ _context.next = 69;
17763
17895
  break;
17764
- case 54:
17896
+ case 55:
17765
17897
  if (!(_typeof(destination) === 'object')) {
17766
- _context.next = 58;
17898
+ _context.next = 59;
17767
17899
  break;
17768
17900
  }
17769
17901
  console.warn('Keep alive check is not supported when using MultiLocation as destination.');
17770
- _context.next = 68;
17902
+ _context.next = 69;
17771
17903
  break;
17772
- case 58:
17904
+ case 59:
17773
17905
  if (!(destination === 'Ethereum')) {
17774
- _context.next = 62;
17906
+ _context.next = 63;
17775
17907
  break;
17776
17908
  }
17777
17909
  console.warn('Keep alive check is not supported when using Ethereum as origin or destination.');
17778
- _context.next = 68;
17910
+ _context.next = 69;
17779
17911
  break;
17780
- case 62:
17912
+ case 63:
17781
17913
  if (asset) {
17782
- _context.next = 66;
17914
+ _context.next = 67;
17783
17915
  break;
17784
17916
  }
17785
17917
  console.warn('Keep alive check is not supported when asset check is disabled.');
17786
- _context.next = 68;
17918
+ _context.next = 69;
17787
17919
  break;
17788
- case 66:
17789
- _context.next = 68;
17920
+ case 67:
17921
+ _context.next = 69;
17790
17922
  return checkKeepAlive({
17791
17923
  originApi: api,
17792
17924
  address: address,
@@ -17796,7 +17928,7 @@ var sendCommon = function sendCommon(options_1) {
17796
17928
  asset: asset,
17797
17929
  destNode: destination
17798
17930
  });
17799
- case 68:
17931
+ case 69:
17800
17932
  // In case asset check is disabled, we create asset object from currency symbol
17801
17933
  resolvedAsset = asset !== null && asset !== void 0 ? asset : {
17802
17934
  symbol: 'symbol' in currency ? currency.symbol : undefined
@@ -17815,11 +17947,21 @@ var sendCommon = function sendCommon(options_1) {
17815
17947
  serializedApiCallEnabled: serializedApiCallEnabled,
17816
17948
  ahAddress: ahAddress
17817
17949
  }));
17818
- 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:
17819
17961
  case "end":
17820
17962
  return _context.stop();
17821
17963
  }
17822
- }, _callee);
17964
+ }, _callee, null, [[45,, 71, 76]]);
17823
17965
  })();
17824
17966
  });
17825
17967
  };
@@ -17872,24 +18014,25 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17872
18014
  _context4.next = 7;
17873
18015
  return api.init(determineRelayChain(destination));
17874
18016
  case 7:
18017
+ _context4.prev = 7;
17875
18018
  amountStr = amount.toString();
17876
18019
  if (!isMultiLocationDestination) {
17877
- _context4.next = 12;
18020
+ _context4.next = 13;
17878
18021
  break;
17879
18022
  }
17880
18023
  console.warn('Keep alive check is not supported when using MultiLocation as destination.');
17881
- _context4.next = 18;
18024
+ _context4.next = 19;
17882
18025
  break;
17883
- case 12:
18026
+ case 13:
17884
18027
  if (!isAddressMultiLocation) {
17885
- _context4.next = 16;
18028
+ _context4.next = 17;
17886
18029
  break;
17887
18030
  }
17888
18031
  console.warn('Keep alive check is not supported when using MultiLocation as address.');
17889
- _context4.next = 18;
18032
+ _context4.next = 19;
17890
18033
  break;
17891
- case 16:
17892
- _context4.next = 18;
18034
+ case 17:
18035
+ _context4.next = 19;
17893
18036
  return checkKeepAlive({
17894
18037
  originApi: api,
17895
18038
  address: address,
@@ -17900,7 +18043,7 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17900
18043
  },
17901
18044
  destNode: destination
17902
18045
  });
17903
- case 18:
18046
+ case 19:
17904
18047
  serializedApiCall = getNode(isMultiLocationDestination ? resolveTNodeFromMultiLocation(destination) : destination).transferRelayToPara({
17905
18048
  api: api,
17906
18049
  destination: destination,
@@ -17911,19 +18054,29 @@ var transferRelayToParaCommon = function transferRelayToParaCommon(options_1) {
17911
18054
  version: version
17912
18055
  });
17913
18056
  if (!serializedApiCallEnabled) {
17914
- _context4.next = 21;
18057
+ _context4.next = 22;
17915
18058
  break;
17916
18059
  }
17917
18060
  return _context4.abrupt("return", Object.assign(Object.assign({}, serializedApiCall), {
17918
18061
  parameters: Object.values(serializedApiCall.parameters)
17919
18062
  }));
17920
- case 21:
17921
- return _context4.abrupt("return", api.callTxMethod(serializedApiCall));
17922
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:
17923
18076
  case "end":
17924
18077
  return _context4.stop();
17925
18078
  }
17926
- }, _callee4);
18079
+ }, _callee4, null, [[7,, 23, 28]]);
17927
18080
  })();
17928
18081
  });
17929
18082
  };
@@ -18158,6 +18311,8 @@ var unsupportedNodes = ['ComposableFinance', 'Interlay', 'Parallel', 'Pioneer',
18158
18311
  var PapiApi = /*#__PURE__*/function () {
18159
18312
  function PapiApi() {
18160
18313
  _classCallCheck(this, PapiApi);
18314
+ this.initialized = false;
18315
+ this.disconnectAllowed = true;
18161
18316
  }
18162
18317
  return _createClass(PapiApi, [{
18163
18318
  key: "setApi",
@@ -18177,38 +18332,46 @@ var PapiApi = /*#__PURE__*/function () {
18177
18332
  return _regeneratorRuntime().wrap(function _callee$(_context) {
18178
18333
  while (1) switch (_context.prev = _context.next) {
18179
18334
  case 0:
18180
- if (!unsupportedNodes.includes(node)) {
18335
+ if (!this.initialized) {
18181
18336
  _context.next = 2;
18182
18337
  break;
18183
18338
  }
18184
- throw new NodeNotSupportedError("The node ".concat(node, " is not yet supported by the Polkadot API."));
18339
+ return _context.abrupt("return");
18185
18340
  case 2:
18341
+ if (!unsupportedNodes.includes(node)) {
18342
+ _context.next = 4;
18343
+ break;
18344
+ }
18345
+ throw new NodeNotSupportedError("The node ".concat(node, " is not yet supported by the Polkadot API."));
18346
+ case 4:
18186
18347
  if (!(typeof this._api === 'string')) {
18187
- _context.next = 8;
18348
+ _context.next = 10;
18188
18349
  break;
18189
18350
  }
18190
- _context.next = 5;
18351
+ _context.next = 7;
18191
18352
  return this.createApiInstance(this._api);
18192
- case 5:
18353
+ case 7:
18193
18354
  this.api = _context.sent;
18194
- _context.next = 16;
18355
+ _context.next = 18;
18195
18356
  break;
18196
- case 8:
18357
+ case 10:
18197
18358
  if (!((_a = this._api) !== null && _a !== void 0)) {
18198
- _context.next = 12;
18359
+ _context.next = 14;
18199
18360
  break;
18200
18361
  }
18201
18362
  _context.t0 = _a;
18202
- _context.next = 15;
18363
+ _context.next = 17;
18203
18364
  break;
18204
- case 12:
18205
- _context.next = 14;
18206
- return createApiInstanceForNode$1(this, node);
18207
18365
  case 14:
18366
+ _context.next = 16;
18367
+ return createApiInstanceForNode$1(this, node);
18368
+ case 16:
18208
18369
  _context.t0 = _context.sent;
18209
- case 15:
18370
+ case 17:
18210
18371
  this.api = _context.t0;
18211
- case 16:
18372
+ case 18:
18373
+ this.initialized = true;
18374
+ case 19:
18212
18375
  case "end":
18213
18376
  return _context.stop();
18214
18377
  }
@@ -18259,9 +18422,7 @@ var PapiApi = /*#__PURE__*/function () {
18259
18422
  var module = _ref.module,
18260
18423
  section = _ref.section,
18261
18424
  parameters = _ref.parameters;
18262
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18263
18425
  var transformedParameters = _transform(parameters);
18264
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
18265
18426
  return this.api.getUnsafeApi().tx[module][section](transformedParameters);
18266
18427
  }
18267
18428
  }, {
@@ -18347,8 +18508,7 @@ var PapiApi = /*#__PURE__*/function () {
18347
18508
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
18348
18509
  while (1) switch (_context7.prev = _context7.next) {
18349
18510
  case 0:
18350
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18351
- transformedMultiLocation = _transform(multiLocation); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18511
+ transformedMultiLocation = _transform(multiLocation);
18352
18512
  _context7.next = 3;
18353
18513
  return this.api.getUnsafeApi().query.ForeignAssets.Account.getValue(transformedMultiLocation, address);
18354
18514
  case 3:
@@ -18382,70 +18542,92 @@ var PapiApi = /*#__PURE__*/function () {
18382
18542
  }));
18383
18543
  }
18384
18544
  }, {
18385
- key: "getBalanceForeignXTokens",
18386
- value: function getBalanceForeignXTokens(address, asset) {
18545
+ key: "getBalanceForeignBifrost",
18546
+ value: function getBalanceForeignBifrost(address, asset) {
18387
18547
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
18388
- var response, entry;
18548
+ var currencySelection, transformedParameters, response, accountData;
18389
18549
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
18390
18550
  while (1) switch (_context9.prev = _context9.next) {
18391
18551
  case 0:
18392
- _context9.next = 2;
18552
+ currencySelection = getNode('BifrostPolkadot').getCurrencySelection(asset);
18553
+ transformedParameters = _transform(currencySelection);
18554
+ _context9.next = 4;
18555
+ return this.api.getUnsafeApi().query.Tokens.Accounts.getValue(address, transformedParameters);
18556
+ case 4:
18557
+ response = _context9.sent;
18558
+ accountData = response ? response : null;
18559
+ return _context9.abrupt("return", accountData ? BigInt(accountData.free.toString()) : BigInt(0));
18560
+ case 7:
18561
+ case "end":
18562
+ return _context9.stop();
18563
+ }
18564
+ }, _callee9, this);
18565
+ }));
18566
+ }
18567
+ }, {
18568
+ key: "getBalanceForeignXTokens",
18569
+ value: function getBalanceForeignXTokens(address, asset) {
18570
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
18571
+ var response, entry;
18572
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
18573
+ while (1) switch (_context10.prev = _context10.next) {
18574
+ case 0:
18575
+ _context10.next = 2;
18393
18576
  return this.api.getUnsafeApi().query.Tokens.Accounts.getEntries(address);
18394
18577
  case 2:
18395
- response = _context9.sent;
18578
+ response = _context10.sent;
18396
18579
  entry = response.find(function (_ref2) {
18397
18580
  var keyArgs = _ref2.keyArgs;
18398
18581
  var _a, _b, _c, _d;
18399
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18400
18582
  var _keyArgs = _slicedToArray(keyArgs, 2);
18401
18583
  _keyArgs[0];
18402
18584
  var assetItem = _keyArgs[1];
18403
18585
  return assetItem.toString().toLowerCase() === ((_a = asset.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || isForeignAsset(asset) && assetItem.toString().toLowerCase() === ((_b = asset.assetId) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || _typeof(assetItem) === 'object' && 'value' in assetItem && assetItem.value.toString().toLowerCase() === ((_c = asset.symbol) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || _typeof(assetItem) === 'object' && 'value' in assetItem && isForeignAsset(asset) && assetItem.value.toString().toLowerCase() === ((_d = asset.assetId) === null || _d === void 0 ? void 0 : _d.toLowerCase());
18404
- }); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
18405
- return _context9.abrupt("return", (entry === null || entry === void 0 ? void 0 : entry.value) ? BigInt(entry.value.free.toString()) : BigInt(0));
18586
+ });
18587
+ return _context10.abrupt("return", (entry === null || entry === void 0 ? void 0 : entry.value) ? BigInt(entry.value.free.toString()) : BigInt(0));
18406
18588
  case 5:
18407
18589
  case "end":
18408
- return _context9.stop();
18590
+ return _context10.stop();
18409
18591
  }
18410
- }, _callee9, this);
18592
+ }, _callee10, this);
18411
18593
  }));
18412
18594
  }
18413
18595
  }, {
18414
18596
  key: "getBalanceForeignAssetsAccount",
18415
18597
  value: function getBalanceForeignAssetsAccount(address, assetId) {
18416
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
18598
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
18417
18599
  var response;
18418
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
18419
- while (1) switch (_context10.prev = _context10.next) {
18600
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
18601
+ while (1) switch (_context11.prev = _context11.next) {
18420
18602
  case 0:
18421
- _context10.next = 2;
18603
+ _context11.next = 2;
18422
18604
  return this.api.getUnsafeApi().query.Assets.Account.getValue(assetId, address);
18423
18605
  case 2:
18424
- response = _context10.sent;
18425
- return _context10.abrupt("return", BigInt(response === undefined ? 0 : response.balance));
18606
+ response = _context11.sent;
18607
+ return _context11.abrupt("return", BigInt(response === undefined ? 0 : response.balance));
18426
18608
  case 4:
18427
18609
  case "end":
18428
- return _context10.stop();
18610
+ return _context11.stop();
18429
18611
  }
18430
- }, _callee10, this);
18612
+ }, _callee11, this);
18431
18613
  }));
18432
18614
  }
18433
18615
  }, {
18434
18616
  key: "getFromStorage",
18435
18617
  value: function getFromStorage(key) {
18436
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
18437
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
18438
- while (1) switch (_context11.prev = _context11.next) {
18618
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
18619
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
18620
+ while (1) switch (_context12.prev = _context12.next) {
18439
18621
  case 0:
18440
- _context11.next = 2;
18622
+ _context12.next = 2;
18441
18623
  return this.api._request('state_getStorage', [key]);
18442
18624
  case 2:
18443
- return _context11.abrupt("return", _context11.sent);
18625
+ return _context12.abrupt("return", _context12.sent);
18444
18626
  case 3:
18445
18627
  case "end":
18446
- return _context11.stop();
18628
+ return _context12.stop();
18447
18629
  }
18448
- }, _callee11, this);
18630
+ }, _callee12, this);
18449
18631
  }));
18450
18632
  }
18451
18633
  }, {
@@ -18456,23 +18638,43 @@ var PapiApi = /*#__PURE__*/function () {
18456
18638
  }, {
18457
18639
  key: "createApiForNode",
18458
18640
  value: function createApiForNode(node) {
18459
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
18641
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
18460
18642
  var api;
18461
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
18462
- while (1) switch (_context12.prev = _context12.next) {
18643
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
18644
+ while (1) switch (_context13.prev = _context13.next) {
18463
18645
  case 0:
18464
18646
  api = new PapiApi();
18465
- _context12.next = 3;
18647
+ _context13.next = 3;
18466
18648
  return api.init(node);
18467
18649
  case 3:
18468
- return _context12.abrupt("return", api);
18650
+ return _context13.abrupt("return", api);
18469
18651
  case 4:
18470
18652
  case "end":
18471
- return _context12.stop();
18653
+ return _context13.stop();
18472
18654
  }
18473
- }, _callee12);
18655
+ }, _callee13);
18474
18656
  }));
18475
18657
  }
18658
+ }, {
18659
+ key: "setDisconnectAllowed",
18660
+ value: function setDisconnectAllowed(allowed) {
18661
+ this.disconnectAllowed = allowed;
18662
+ }
18663
+ }, {
18664
+ key: "getDisconnectAllowed",
18665
+ value: function getDisconnectAllowed() {
18666
+ return this.disconnectAllowed;
18667
+ }
18668
+ }, {
18669
+ key: "disconnect",
18670
+ value: function disconnect() {
18671
+ if (!this.disconnectAllowed) return Promise.resolve();
18672
+ // Disconnect api only if it was created automatically
18673
+ if (typeof this._api === 'string' || this._api === undefined) {
18674
+ this.api.destroy();
18675
+ }
18676
+ return Promise.resolve();
18677
+ }
18476
18678
  }]);
18477
18679
  }();
18478
18680