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