@paraspell/sdk-core 8.9.7 → 8.9.9

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
@@ -2838,6 +2838,26 @@ var resolveParaId = function resolveParaId(paraId, destination) {
2838
2838
  return paraId !== null && paraId !== void 0 ? paraId : getParaId(destination);
2839
2839
  };
2840
2840
 
2841
+ /**
2842
+ * Error thrown when the Ethereum bridge is halted.
2843
+ */
2844
+ var BridgeHaltedError = /*#__PURE__*/function (_Error) {
2845
+ /**
2846
+ * Constructs a new BridgeHaltedError.
2847
+ *
2848
+ * @param message - Optional custom error message.
2849
+ */
2850
+ function BridgeHaltedError() {
2851
+ var _this;
2852
+ _classCallCheck(this, BridgeHaltedError);
2853
+ _this = _callSuper(this, BridgeHaltedError, ['Bridge operations have been paused by onchain governance.']);
2854
+ _this.name = 'BridgeHaltedError';
2855
+ return _this;
2856
+ }
2857
+ _inherits(BridgeHaltedError, _Error);
2858
+ return _createClass(BridgeHaltedError);
2859
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
2860
+
2841
2861
  /**
2842
2862
  * Error thrown when nodes from different relay chains are incompatible.
2843
2863
  */
@@ -3099,6 +3119,36 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
3099
3119
  }]);
3100
3120
  }();
3101
3121
 
3122
+ var getBridgeStatus = /*#__PURE__*/function () {
3123
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
3124
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3125
+ while (1) switch (_context.prev = _context.next) {
3126
+ case 0:
3127
+ _context.next = 2;
3128
+ return api.init('BridgeHubPolkadot');
3129
+ case 2:
3130
+ _context.prev = 2;
3131
+ _context.next = 5;
3132
+ return api.getBridgeStatus();
3133
+ case 5:
3134
+ return _context.abrupt("return", _context.sent);
3135
+ case 6:
3136
+ _context.prev = 6;
3137
+ _context.next = 9;
3138
+ return api.disconnect();
3139
+ case 9:
3140
+ return _context.finish(6);
3141
+ case 10:
3142
+ case "end":
3143
+ return _context.stop();
3144
+ }
3145
+ }, _callee, null, [[2,, 6, 10]]);
3146
+ }));
3147
+ return function getBridgeStatus(_x) {
3148
+ return _ref.apply(this, arguments);
3149
+ };
3150
+ }();
3151
+
3102
3152
  var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, version, messageId) {
3103
3153
  var api = _ref.api,
3104
3154
  address = _ref.address,
@@ -3431,38 +3481,48 @@ var ParachainNode = /*#__PURE__*/function () {
3431
3481
  key: "transferToEthereum",
3432
3482
  value: function () {
3433
3483
  var _transferToEthereum = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3434
- var api, asset, scenario, version, destination, address, senderAddress, versionOrDefault, ethMultiAsset, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, fee, ethAsset, messageId, call;
3484
+ var api, asset, scenario, version, destination, address, senderAddress, bridgeStatus, versionOrDefault, ethMultiAsset, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, fee, ethAsset, messageId, call;
3435
3485
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3436
3486
  while (1) switch (_context2.prev = _context2.next) {
3437
3487
  case 0:
3438
3488
  api = input.api, asset = input.asset, scenario = input.scenario, version = input.version, destination = input.destination, address = input.address, senderAddress = input.senderAddress;
3489
+ _context2.next = 3;
3490
+ return getBridgeStatus(api.clone());
3491
+ case 3:
3492
+ bridgeStatus = _context2.sent;
3493
+ if (!(bridgeStatus !== 'Normal')) {
3494
+ _context2.next = 6;
3495
+ break;
3496
+ }
3497
+ throw new BridgeHaltedError();
3498
+ case 6:
3439
3499
  if (assets.isForeignAsset(asset)) {
3440
- _context2.next = 3;
3500
+ _context2.next = 8;
3441
3501
  break;
3442
3502
  }
3443
3503
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3444
- case 3:
3504
+ case 8:
3445
3505
  if (!(senderAddress === undefined)) {
3446
- _context2.next = 5;
3506
+ _context2.next = 10;
3447
3507
  break;
3448
3508
  }
3449
3509
  throw new Error('Sender address is required for transfers to Ethereum');
3450
- case 5:
3510
+ case 10:
3451
3511
  if (!sdkCommon.isTMultiLocation(address)) {
3452
- _context2.next = 7;
3512
+ _context2.next = 12;
3453
3513
  break;
3454
3514
  }
3455
3515
  throw new Error('Multi-location address is not supported for Ethereum transfers');
3456
- case 7:
3516
+ case 12:
3457
3517
  versionOrDefault = version !== null && version !== void 0 ? version : exports.Version.V4;
3458
3518
  ethMultiAsset = createMultiAsset(versionOrDefault, asset.amount, asset.multiLocation);
3459
- _context2.next = 11;
3519
+ _context2.next = 16;
3460
3520
  return api.createApiForNode('AssetHubPolkadot');
3461
- case 11:
3521
+ case 16:
3462
3522
  ahApi = _context2.sent;
3463
- _context2.next = 14;
3523
+ _context2.next = 19;
3464
3524
  return getParaEthTransferFees(ahApi);
3465
- case 14:
3525
+ case 19:
3466
3526
  _yield$getParaEthTran = _context2.sent;
3467
3527
  _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
3468
3528
  bridgeFee = _yield$getParaEthTran2[0];
@@ -3470,14 +3530,14 @@ var ParachainNode = /*#__PURE__*/function () {
3470
3530
  fee = (bridgeFee + executionFee).toString();
3471
3531
  ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
3472
3532
  if (!(!ethAsset || !ethAsset.assetId)) {
3473
- _context2.next = 22;
3533
+ _context2.next = 27;
3474
3534
  break;
3475
3535
  }
3476
3536
  throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3477
- case 22:
3478
- _context2.next = 24;
3537
+ case 27:
3538
+ _context2.next = 29;
3479
3539
  return generateMessageId(api, senderAddress, getParaId(this.node), ethAsset.assetId, address, asset.amount);
3480
- case 24:
3540
+ case 29:
3481
3541
  messageId = _context2.sent;
3482
3542
  call = {
3483
3543
  module: 'PolkadotXcm',
@@ -3496,7 +3556,7 @@ var ParachainNode = /*#__PURE__*/function () {
3496
3556
  }
3497
3557
  };
3498
3558
  return _context2.abrupt("return", api.callTxMethod(call));
3499
- case 27:
3559
+ case 32:
3500
3560
  case "end":
3501
3561
  return _context2.stop();
3502
3562
  }
@@ -3850,36 +3910,65 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3850
3910
  }
3851
3911
  }, {
3852
3912
  key: "handleEthBridgeTransfer",
3853
- value: function handleEthBridgeTransfer(input) {
3854
- var api = input.api,
3855
- scenario = input.scenario,
3856
- destination = input.destination,
3857
- paraIdTo = input.paraIdTo,
3858
- address = input.address,
3859
- asset = input.asset;
3860
- if (!ethers.ethers.isAddress(address)) {
3861
- throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
3862
- }
3863
- if (!assets.isForeignAsset(asset)) {
3864
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3865
- }
3866
- if (!asset.multiLocation) {
3867
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3913
+ value: function () {
3914
+ var _handleEthBridgeTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
3915
+ var api, scenario, destination, paraIdTo, address, asset, bridgeStatus, modifiedInput;
3916
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3917
+ while (1) switch (_context.prev = _context.next) {
3918
+ case 0:
3919
+ api = input.api, scenario = input.scenario, destination = input.destination, paraIdTo = input.paraIdTo, address = input.address, asset = input.asset;
3920
+ _context.next = 3;
3921
+ return getBridgeStatus(api.clone());
3922
+ case 3:
3923
+ bridgeStatus = _context.sent;
3924
+ if (!(bridgeStatus !== 'Normal')) {
3925
+ _context.next = 6;
3926
+ break;
3927
+ }
3928
+ throw new BridgeHaltedError();
3929
+ case 6:
3930
+ if (ethers.ethers.isAddress(address)) {
3931
+ _context.next = 8;
3932
+ break;
3933
+ }
3934
+ throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
3935
+ case 8:
3936
+ if (assets.isForeignAsset(asset)) {
3937
+ _context.next = 10;
3938
+ break;
3939
+ }
3940
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3941
+ case 10:
3942
+ if (asset.multiLocation) {
3943
+ _context.next = 12;
3944
+ break;
3945
+ }
3946
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3947
+ case 12:
3948
+ modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
3949
+ header: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, sdkCommon.Parents.TWO),
3950
+ addressSelection: createVersionedBeneficiary({
3951
+ api: api,
3952
+ scenario: scenario,
3953
+ pallet: 'PolkadotXcm',
3954
+ recipientAddress: address,
3955
+ version: this.version,
3956
+ paraId: paraIdTo
3957
+ }),
3958
+ currencySelection: createVersionedMultiAssets(exports.Version.V3, asset.amount, asset.multiLocation)
3959
+ });
3960
+ return _context.abrupt("return", PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited'));
3961
+ case 14:
3962
+ case "end":
3963
+ return _context.stop();
3964
+ }
3965
+ }, _callee, this);
3966
+ }));
3967
+ function handleEthBridgeTransfer(_x) {
3968
+ return _handleEthBridgeTransfer.apply(this, arguments);
3868
3969
  }
3869
- var modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
3870
- header: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, sdkCommon.Parents.TWO),
3871
- addressSelection: createVersionedBeneficiary({
3872
- api: api,
3873
- scenario: scenario,
3874
- pallet: 'PolkadotXcm',
3875
- recipientAddress: address,
3876
- version: this.version,
3877
- paraId: paraIdTo
3878
- }),
3879
- currencySelection: createVersionedMultiAssets(exports.Version.V3, asset.amount, asset.multiLocation)
3880
- });
3881
- return PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited');
3882
- }
3970
+ return handleEthBridgeTransfer;
3971
+ }()
3883
3972
  }, {
3884
3973
  key: "handleMythosTransfer",
3885
3974
  value: function handleMythosTransfer(input) {
@@ -3958,14 +4047,14 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3958
4047
  }, {
3959
4048
  key: "handleExecuteTransfer",
3960
4049
  value: function () {
3961
- var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
4050
+ var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3962
4051
  var api, senderAddress, asset, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
3963
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3964
- while (1) switch (_context.prev = _context.next) {
4052
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4053
+ while (1) switch (_context2.prev = _context2.next) {
3965
4054
  case 0:
3966
4055
  api = input.api, senderAddress = input.senderAddress, asset = input.asset;
3967
4056
  if (senderAddress) {
3968
- _context.next = 3;
4057
+ _context2.next = 3;
3969
4058
  break;
3970
4059
  }
3971
4060
  throw new Error('Please provide senderAddress');
@@ -3977,53 +4066,53 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3977
4066
  refTime: maxU64,
3978
4067
  proofSize: maxU64
3979
4068
  }, MIN_FEE);
3980
- _context.next = 9;
4069
+ _context2.next = 9;
3981
4070
  return api.getDryRun({
3982
4071
  node: this.node,
3983
4072
  tx: dummyTx,
3984
4073
  address: senderAddress
3985
4074
  });
3986
4075
  case 9:
3987
- dryRunResult = _context.sent;
4076
+ dryRunResult = _context2.sent;
3988
4077
  if (dryRunResult.success) {
3989
- _context.next = 12;
4078
+ _context2.next = 12;
3990
4079
  break;
3991
4080
  }
3992
4081
  throw new Error("Dry run failed: ".concat(dryRunResult.failureReason));
3993
4082
  case 12:
3994
4083
  if (dryRunResult.weight) {
3995
- _context.next = 14;
4084
+ _context2.next = 14;
3996
4085
  break;
3997
4086
  }
3998
4087
  throw new Error('Dry run failed: weight not found');
3999
4088
  case 14:
4000
4089
  feeDotShifted = dryRunResult.fee / 10n;
4001
4090
  toMl = transformMultiLocation(asset.multiLocation);
4002
- _context.next = 18;
4091
+ _context2.next = 18;
4003
4092
  return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
4004
4093
  case 18:
4005
- feeConverted = _context.sent;
4094
+ feeConverted = _context2.sent;
4006
4095
  if (feeConverted) {
4007
- _context.next = 21;
4096
+ _context2.next = 21;
4008
4097
  break;
4009
4098
  }
4010
4099
  throw new Error("Pool DOT -> ".concat(asset.symbol, " not found."));
4011
4100
  case 21:
4012
4101
  if (!(BigInt(asset.amount) - feeConverted < 0)) {
4013
- _context.next = 23;
4102
+ _context2.next = 23;
4014
4103
  break;
4015
4104
  }
4016
4105
  throw new Error("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
4017
4106
  case 23:
4018
4107
  feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
4019
- return _context.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4108
+ return _context2.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4020
4109
  case 25:
4021
4110
  case "end":
4022
- return _context.stop();
4111
+ return _context2.stop();
4023
4112
  }
4024
- }, _callee, this);
4113
+ }, _callee2, this);
4025
4114
  }));
4026
- function handleExecuteTransfer(_x) {
4115
+ function handleExecuteTransfer(_x2) {
4027
4116
  return _handleExecuteTransfer.apply(this, arguments);
4028
4117
  }
4029
4118
  return handleExecuteTransfer;
@@ -5870,7 +5959,7 @@ var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
5870
5959
  var transferMoonbeamToEth = /*#__PURE__*/function () {
5871
5960
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
5872
5961
  var _signer$account;
5873
- var api, from, to, signer, address, ahAddress, currency, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
5962
+ var api, from, to, signer, address, ahAddress, currency, bridgeStatus, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
5874
5963
  return _regeneratorRuntime().wrap(function _callee$(_context) {
5875
5964
  while (1) switch (_context.prev = _context.next) {
5876
5965
  case 0:
@@ -5881,38 +5970,48 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5881
5970
  }
5882
5971
  throw new Error('AssetHub address is required');
5883
5972
  case 3:
5973
+ _context.next = 5;
5974
+ return getBridgeStatus(api.clone());
5975
+ case 5:
5976
+ bridgeStatus = _context.sent;
5977
+ if (!(bridgeStatus !== 'Normal')) {
5978
+ _context.next = 8;
5979
+ break;
5980
+ }
5981
+ throw new BridgeHaltedError();
5982
+ case 8:
5884
5983
  if (!('multiasset' in currency)) {
5885
- _context.next = 5;
5984
+ _context.next = 10;
5886
5985
  break;
5887
5986
  }
5888
5987
  throw new Error('Multiassets syntax is not supported for Evm transfers');
5889
- case 5:
5988
+ case 10:
5890
5989
  if (!('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation))) {
5891
- _context.next = 7;
5990
+ _context.next = 12;
5892
5991
  break;
5893
5992
  }
5894
5993
  throw new Error('Override multilocation is not supported for Evm transfers');
5895
- case 7:
5994
+ case 12:
5896
5995
  foundAsset = assets.findAsset(from, currency, to);
5897
5996
  if (!(foundAsset === null)) {
5898
- _context.next = 10;
5997
+ _context.next = 15;
5899
5998
  break;
5900
5999
  }
5901
6000
  throw new assets.InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
5902
- case 10:
6001
+ case 15:
5903
6002
  if (!(!assets.isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
5904
- _context.next = 12;
6003
+ _context.next = 17;
5905
6004
  break;
5906
6005
  }
5907
6006
  throw new assets.InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
5908
- case 12:
6007
+ case 17:
5909
6008
  ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), foundAsset.multiLocation);
5910
6009
  if (!(!ethAsset || !ethAsset.assetId)) {
5911
- _context.next = 15;
6010
+ _context.next = 20;
5912
6011
  break;
5913
6012
  }
5914
6013
  throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
5915
- case 15:
6014
+ case 20:
5916
6015
  contract = isEthersSigner(signer) ? new ethers.Contract(xcmInterfacePrecompile, abi, signer) : viem.getContract({
5917
6016
  abi: abi,
5918
6017
  address: xcmInterfacePrecompile,
@@ -5925,31 +6024,31 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5925
6024
  }
5926
6025
  });
5927
6026
  if (!isEthersSigner(signer)) {
5928
- _context.next = 22;
6027
+ _context.next = 27;
5929
6028
  break;
5930
6029
  }
5931
- _context.next = 19;
6030
+ _context.next = 24;
5932
6031
  return signer.getAddress();
5933
- case 19:
6032
+ case 24:
5934
6033
  _context.t0 = _context.sent;
5935
- _context.next = 23;
6034
+ _context.next = 28;
5936
6035
  break;
5937
- case 22:
6036
+ case 27:
5938
6037
  _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
5939
- case 23:
6038
+ case 28:
5940
6039
  senderAddress = _context.t0;
5941
6040
  if (senderAddress) {
5942
- _context.next = 26;
6041
+ _context.next = 31;
5943
6042
  break;
5944
6043
  }
5945
6044
  throw new Error('Unable to get sender address');
5946
- case 26:
5947
- _context.next = 28;
6045
+ case 31:
6046
+ _context.next = 33;
5948
6047
  return api.init(from);
5949
- case 28:
5950
- _context.next = 30;
6048
+ case 33:
6049
+ _context.next = 35;
5951
6050
  return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
5952
- case 30:
6051
+ case 35:
5953
6052
  messageId = _context.sent;
5954
6053
  customXcm = createCustomXcmOnDest({
5955
6054
  api: api,
@@ -5959,17 +6058,17 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5959
6058
  asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
5960
6059
  amount: currency.amount
5961
6060
  })}, exports.Version.V4, messageId);
5962
- _context.next = 34;
6061
+ _context.next = 39;
5963
6062
  return api.objectToHex(customXcm, 'XcmVersionedXcm');
5964
- case 34:
6063
+ case 39:
5965
6064
  customXcmOnDest = _context.sent;
5966
- _context.next = 37;
6065
+ _context.next = 42;
5967
6066
  return api.createApiForNode('AssetHubPolkadot');
5968
- case 37:
6067
+ case 42:
5969
6068
  assetHubApi = _context.sent;
5970
- _context.next = 40;
6069
+ _context.next = 45;
5971
6070
  return getParaEthTransferFees(assetHubApi);
5972
- case 40:
6071
+ case 45:
5973
6072
  _yield$getParaEthTran = _context.sent;
5974
6073
  _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
5975
6074
  bridgeFee = _yield$getParaEthTran2[0];
@@ -5987,7 +6086,7 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5987
6086
  throw new Error('Input must be a valid number');
5988
6087
  }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
5989
6088
  }; // Execute the custom XCM message with the precompile
5990
- _context.next = 49;
6089
+ _context.next = 54;
5991
6090
  return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
5992
6091
  // This represents (1,X1(Parachain(1000)))
5993
6092
  [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
@@ -5999,10 +6098,10 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5999
6098
  0,
6000
6099
  // The TransferType corresponding to fee asset
6001
6100
  2, customXcmOnDest]);
6002
- case 49:
6101
+ case 54:
6003
6102
  tx = _context.sent;
6004
6103
  return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
6005
- case 51:
6104
+ case 56:
6006
6105
  case "end":
6007
6106
  return _context.stop();
6008
6107
  }
@@ -7444,6 +7543,7 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
7444
7543
  }();
7445
7544
 
7446
7545
  exports.AssetClaimBuilder = AssetClaimBuilder;
7546
+ exports.BridgeHaltedError = BridgeHaltedError;
7447
7547
  exports.Builder = Builder;
7448
7548
  exports.ETHEREUM_JUNCTION = ETHEREUM_JUNCTION;
7449
7549
  exports.ETH_CHAIN_ID = ETH_CHAIN_ID;
@@ -7468,6 +7568,7 @@ exports.getBalanceForeign = getBalanceForeign;
7468
7568
  exports.getBalanceForeignInternal = getBalanceForeignInternal;
7469
7569
  exports.getBalanceNative = getBalanceNative;
7470
7570
  exports.getBalanceNativeInternal = getBalanceNativeInternal;
7571
+ exports.getBridgeStatus = getBridgeStatus;
7471
7572
  exports.getDryRun = getDryRun;
7472
7573
  exports.getFees = getFees;
7473
7574
  exports.getMaxForeignTransferableAmount = getMaxForeignTransferableAmount;
package/dist/index.d.ts CHANGED
@@ -250,6 +250,7 @@ type TCreateBeneficiaryOptions<TApi, TRes> = {
250
250
  version: Version;
251
251
  paraId?: number;
252
252
  };
253
+ type TBridgeStatus = 'Normal' | 'Halted';
253
254
 
254
255
  type TAssetClaimOptionsBase = {
255
256
  node: TNodeWithRelayChains;
@@ -625,6 +626,7 @@ interface IPolkadotApi<TApi, TRes> {
625
626
  clone(): IPolkadotApi<TApi, TRes>;
626
627
  createApiForNode(node: TNodeWithRelayChains): Promise<IPolkadotApi<TApi, TRes>>;
627
628
  getDryRun(options: TDryRunBaseOptions<TRes>): Promise<TDryRunResult>;
629
+ getBridgeStatus(): Promise<TBridgeStatus>;
628
630
  setDisconnectAllowed(allowed: boolean): void;
629
631
  getDisconnectAllowed(): boolean;
630
632
  disconnect(force?: boolean): Promise<void>;
@@ -887,7 +889,7 @@ declare class AssetHubKusama<TApi, TRes> extends ParachainNode<TApi, TRes> imple
887
889
  declare class AssetHubPolkadot<TApi, TRes> extends ParachainNode<TApi, TRes> implements IPolkadotXCMTransfer {
888
890
  constructor();
889
891
  handleBridgeTransfer<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>, targetChain: 'Polkadot' | 'Kusama'): TRes;
890
- handleEthBridgeTransfer<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): TRes;
892
+ handleEthBridgeTransfer<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): Promise<TRes>;
891
893
  handleMythosTransfer<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): TRes;
892
894
  handleBifrostEthTransfer: <TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi_1, TRes_1>) => TRes_1;
893
895
  patchInput<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): TPolkadotXCMTransferOptions<TApi, TRes>;
@@ -1309,6 +1311,18 @@ declare const nodes: <TApi, TRes>() => {
1309
1311
  Polimec: Polimec<TApi, TRes>;
1310
1312
  };
1311
1313
 
1314
+ /**
1315
+ * Error thrown when the Ethereum bridge is halted.
1316
+ */
1317
+ declare class BridgeHaltedError extends Error {
1318
+ /**
1319
+ * Constructs a new BridgeHaltedError.
1320
+ *
1321
+ * @param message - Optional custom error message.
1322
+ */
1323
+ constructor();
1324
+ }
1325
+
1312
1326
  /**
1313
1327
  * Error thrown when nodes from different relay chains are incompatible.
1314
1328
  */
@@ -1422,6 +1436,8 @@ declare const transferMoonbeamToEth: <TApi, TRes>({ api, from, to, signer, addre
1422
1436
  declare const isEthersSigner: (signer: Signer | WalletClient) => signer is Signer;
1423
1437
  declare const isEthersContract: (contract: Contract | GetContractReturnType<Abi | readonly unknown[]>) => contract is Contract;
1424
1438
 
1439
+ declare const getBridgeStatus: <TApi, TRes>(api: IPolkadotApi<TApi, TRes>) => Promise<TBridgeStatus>;
1440
+
1425
1441
  declare const getDryRun: <TApi, TRes>(options: TDryRunOptions<TApi, TRes>) => Promise<TDryRunResult>;
1426
1442
 
1427
1443
  declare const send: <TApi, TRes>(options: TSendOptions<TApi, TRes>) => Promise<TRes>;
@@ -1475,5 +1491,5 @@ declare const validateAddress: (address: TAddress, node: TNodeWithRelayChains, i
1475
1491
  */
1476
1492
  declare const determineRelayChain: (node: TNodeWithRelayChains) => TRelaychain;
1477
1493
 
1478
- export { AssetClaimBuilder, BatchMode, Builder, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, Version, XTokensError, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, determineRelayChain, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getDryRun, getFees, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
1479
- export type { IPolkadotApi, IPolkadotXCMTransfer, IXTokensTransfer, IXTransferTransfer, OneKey, TAddress, TApiOrUrl, TAssetClaimOptions, TAssetClaimOptionsBase, TBalanceResponse, TBatchOptions, TBifrostToken, TCreateBeneficiaryOptions, TDestWeight, TDestination, TDryRunBaseOptions, TDryRunOptions, TDryRunResult, TEdJsonMap, TEvmBuilderOptions, TEvmBuilderOptionsBase, TEvmNodeFrom, TForeignAssetId, TForeignOrNativeAsset, TForeignOrTokenAsset, TGetAssetBalanceOptions, TGetAssetBalanceOptionsBase, TGetBalanceForeignOptions, TGetBalanceForeignOptionsBase, TGetBalanceNativeOptions, TGetBalanceNativeOptionsBase, TGetMaxForeignTransferableAmountOptions, TGetMaxForeignTransferableAmountOptionsBase, TGetMaxNativeTransferableAmountOptions, TGetMaxNativeTransferableAmountOptionsBase, TGetOriginFeeDetailsOptions, TGetOriginFeeDetailsOptionsBase, TGetTransferInfoOptions, TGetTransferInfoOptionsBase, TGetTransferableAmountOptions, TGetTransferableAmountOptionsBase, TMantaAsset, TModuleError, TNativeTokenAsset, TNodeConfig, TNodeConfigMap, TNodleAsset, TOriginFeeDetails, TOtherReserveAsset, TPolkadotXCMTransferOptions, TPolkadotXcmSection, TProviderEntry, TRelayToParaDestination, TRelayToParaOptions, TRelayToParaOverrides, TRelaychain, TReserveAsset, TScenario, TSelfReserveAsset, TSendBaseOptions, TSendInternalOptions, TSendOptions, TSerializeEthTransferOptions, TSerializedApiCall, TSerializedEthTransfer, TTransferInfo, TVerifyEdOnDestinationOptions, TVerifyEdOnDestinationOptionsBase, TVersionClaimAssets, TWeight, TXTokensCurrencySelection, TXTokensSection, TXTokensTransferOptions, TXTransferSection, TXTransferTransferOptions, TXcmAsset, TXcmForeignAsset, TXcmPalletSection, TXcmVersioned, TZeitgeistAsset, WithApi };
1494
+ export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, Version, XTokensError, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, determineRelayChain, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getDryRun, getFees, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
1495
+ export type { IPolkadotApi, IPolkadotXCMTransfer, IXTokensTransfer, IXTransferTransfer, OneKey, TAddress, TApiOrUrl, TAssetClaimOptions, TAssetClaimOptionsBase, TBalanceResponse, TBatchOptions, TBifrostToken, TBridgeStatus, TCreateBeneficiaryOptions, TDestWeight, TDestination, TDryRunBaseOptions, TDryRunOptions, TDryRunResult, TEdJsonMap, TEvmBuilderOptions, TEvmBuilderOptionsBase, TEvmNodeFrom, TForeignAssetId, TForeignOrNativeAsset, TForeignOrTokenAsset, TGetAssetBalanceOptions, TGetAssetBalanceOptionsBase, TGetBalanceForeignOptions, TGetBalanceForeignOptionsBase, TGetBalanceNativeOptions, TGetBalanceNativeOptionsBase, TGetMaxForeignTransferableAmountOptions, TGetMaxForeignTransferableAmountOptionsBase, TGetMaxNativeTransferableAmountOptions, TGetMaxNativeTransferableAmountOptionsBase, TGetOriginFeeDetailsOptions, TGetOriginFeeDetailsOptionsBase, TGetTransferInfoOptions, TGetTransferInfoOptionsBase, TGetTransferableAmountOptions, TGetTransferableAmountOptionsBase, TMantaAsset, TModuleError, TNativeTokenAsset, TNodeConfig, TNodeConfigMap, TNodleAsset, TOriginFeeDetails, TOtherReserveAsset, TPolkadotXCMTransferOptions, TPolkadotXcmSection, TProviderEntry, TRelayToParaDestination, TRelayToParaOptions, TRelayToParaOverrides, TRelaychain, TReserveAsset, TScenario, TSelfReserveAsset, TSendBaseOptions, TSendInternalOptions, TSendOptions, TSerializeEthTransferOptions, TSerializedApiCall, TSerializedEthTransfer, TTransferInfo, TVerifyEdOnDestinationOptions, TVerifyEdOnDestinationOptionsBase, TVersionClaimAssets, TWeight, TXTokensCurrencySelection, TXTokensSection, TXTokensTransferOptions, TXTransferSection, TXTransferTransferOptions, TXcmAsset, TXcmForeignAsset, TXcmPalletSection, TXcmVersioned, TZeitgeistAsset, WithApi };
package/dist/index.mjs CHANGED
@@ -2839,6 +2839,26 @@ var resolveParaId = function resolveParaId(paraId, destination) {
2839
2839
  return paraId !== null && paraId !== void 0 ? paraId : getParaId(destination);
2840
2840
  };
2841
2841
 
2842
+ /**
2843
+ * Error thrown when the Ethereum bridge is halted.
2844
+ */
2845
+ var BridgeHaltedError = /*#__PURE__*/function (_Error) {
2846
+ /**
2847
+ * Constructs a new BridgeHaltedError.
2848
+ *
2849
+ * @param message - Optional custom error message.
2850
+ */
2851
+ function BridgeHaltedError() {
2852
+ var _this;
2853
+ _classCallCheck(this, BridgeHaltedError);
2854
+ _this = _callSuper(this, BridgeHaltedError, ['Bridge operations have been paused by onchain governance.']);
2855
+ _this.name = 'BridgeHaltedError';
2856
+ return _this;
2857
+ }
2858
+ _inherits(BridgeHaltedError, _Error);
2859
+ return _createClass(BridgeHaltedError);
2860
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
2861
+
2842
2862
  /**
2843
2863
  * Error thrown when nodes from different relay chains are incompatible.
2844
2864
  */
@@ -3100,6 +3120,36 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
3100
3120
  }]);
3101
3121
  }();
3102
3122
 
3123
+ var getBridgeStatus = /*#__PURE__*/function () {
3124
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
3125
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3126
+ while (1) switch (_context.prev = _context.next) {
3127
+ case 0:
3128
+ _context.next = 2;
3129
+ return api.init('BridgeHubPolkadot');
3130
+ case 2:
3131
+ _context.prev = 2;
3132
+ _context.next = 5;
3133
+ return api.getBridgeStatus();
3134
+ case 5:
3135
+ return _context.abrupt("return", _context.sent);
3136
+ case 6:
3137
+ _context.prev = 6;
3138
+ _context.next = 9;
3139
+ return api.disconnect();
3140
+ case 9:
3141
+ return _context.finish(6);
3142
+ case 10:
3143
+ case "end":
3144
+ return _context.stop();
3145
+ }
3146
+ }, _callee, null, [[2,, 6, 10]]);
3147
+ }));
3148
+ return function getBridgeStatus(_x) {
3149
+ return _ref.apply(this, arguments);
3150
+ };
3151
+ }();
3152
+
3103
3153
  var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, version, messageId) {
3104
3154
  var api = _ref.api,
3105
3155
  address = _ref.address,
@@ -3432,38 +3482,48 @@ var ParachainNode = /*#__PURE__*/function () {
3432
3482
  key: "transferToEthereum",
3433
3483
  value: function () {
3434
3484
  var _transferToEthereum = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3435
- var api, asset, scenario, version, destination, address, senderAddress, versionOrDefault, ethMultiAsset, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, fee, ethAsset, messageId, call;
3485
+ var api, asset, scenario, version, destination, address, senderAddress, bridgeStatus, versionOrDefault, ethMultiAsset, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, fee, ethAsset, messageId, call;
3436
3486
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3437
3487
  while (1) switch (_context2.prev = _context2.next) {
3438
3488
  case 0:
3439
3489
  api = input.api, asset = input.asset, scenario = input.scenario, version = input.version, destination = input.destination, address = input.address, senderAddress = input.senderAddress;
3490
+ _context2.next = 3;
3491
+ return getBridgeStatus(api.clone());
3492
+ case 3:
3493
+ bridgeStatus = _context2.sent;
3494
+ if (!(bridgeStatus !== 'Normal')) {
3495
+ _context2.next = 6;
3496
+ break;
3497
+ }
3498
+ throw new BridgeHaltedError();
3499
+ case 6:
3440
3500
  if (isForeignAsset(asset)) {
3441
- _context2.next = 3;
3501
+ _context2.next = 8;
3442
3502
  break;
3443
3503
  }
3444
3504
  throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3445
- case 3:
3505
+ case 8:
3446
3506
  if (!(senderAddress === undefined)) {
3447
- _context2.next = 5;
3507
+ _context2.next = 10;
3448
3508
  break;
3449
3509
  }
3450
3510
  throw new Error('Sender address is required for transfers to Ethereum');
3451
- case 5:
3511
+ case 10:
3452
3512
  if (!isTMultiLocation(address)) {
3453
- _context2.next = 7;
3513
+ _context2.next = 12;
3454
3514
  break;
3455
3515
  }
3456
3516
  throw new Error('Multi-location address is not supported for Ethereum transfers');
3457
- case 7:
3517
+ case 12:
3458
3518
  versionOrDefault = version !== null && version !== void 0 ? version : Version.V4;
3459
3519
  ethMultiAsset = createMultiAsset(versionOrDefault, asset.amount, asset.multiLocation);
3460
- _context2.next = 11;
3520
+ _context2.next = 16;
3461
3521
  return api.createApiForNode('AssetHubPolkadot');
3462
- case 11:
3522
+ case 16:
3463
3523
  ahApi = _context2.sent;
3464
- _context2.next = 14;
3524
+ _context2.next = 19;
3465
3525
  return getParaEthTransferFees(ahApi);
3466
- case 14:
3526
+ case 19:
3467
3527
  _yield$getParaEthTran = _context2.sent;
3468
3528
  _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
3469
3529
  bridgeFee = _yield$getParaEthTran2[0];
@@ -3471,14 +3531,14 @@ var ParachainNode = /*#__PURE__*/function () {
3471
3531
  fee = (bridgeFee + executionFee).toString();
3472
3532
  ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
3473
3533
  if (!(!ethAsset || !ethAsset.assetId)) {
3474
- _context2.next = 22;
3534
+ _context2.next = 27;
3475
3535
  break;
3476
3536
  }
3477
3537
  throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3478
- case 22:
3479
- _context2.next = 24;
3538
+ case 27:
3539
+ _context2.next = 29;
3480
3540
  return generateMessageId(api, senderAddress, getParaId(this.node), ethAsset.assetId, address, asset.amount);
3481
- case 24:
3541
+ case 29:
3482
3542
  messageId = _context2.sent;
3483
3543
  call = {
3484
3544
  module: 'PolkadotXcm',
@@ -3497,7 +3557,7 @@ var ParachainNode = /*#__PURE__*/function () {
3497
3557
  }
3498
3558
  };
3499
3559
  return _context2.abrupt("return", api.callTxMethod(call));
3500
- case 27:
3560
+ case 32:
3501
3561
  case "end":
3502
3562
  return _context2.stop();
3503
3563
  }
@@ -3851,36 +3911,65 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3851
3911
  }
3852
3912
  }, {
3853
3913
  key: "handleEthBridgeTransfer",
3854
- value: function handleEthBridgeTransfer(input) {
3855
- var api = input.api,
3856
- scenario = input.scenario,
3857
- destination = input.destination,
3858
- paraIdTo = input.paraIdTo,
3859
- address = input.address,
3860
- asset = input.asset;
3861
- if (!ethers.isAddress(address)) {
3862
- throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
3863
- }
3864
- if (!isForeignAsset(asset)) {
3865
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3866
- }
3867
- if (!asset.multiLocation) {
3868
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3914
+ value: function () {
3915
+ var _handleEthBridgeTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
3916
+ var api, scenario, destination, paraIdTo, address, asset, bridgeStatus, modifiedInput;
3917
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3918
+ while (1) switch (_context.prev = _context.next) {
3919
+ case 0:
3920
+ api = input.api, scenario = input.scenario, destination = input.destination, paraIdTo = input.paraIdTo, address = input.address, asset = input.asset;
3921
+ _context.next = 3;
3922
+ return getBridgeStatus(api.clone());
3923
+ case 3:
3924
+ bridgeStatus = _context.sent;
3925
+ if (!(bridgeStatus !== 'Normal')) {
3926
+ _context.next = 6;
3927
+ break;
3928
+ }
3929
+ throw new BridgeHaltedError();
3930
+ case 6:
3931
+ if (ethers.isAddress(address)) {
3932
+ _context.next = 8;
3933
+ break;
3934
+ }
3935
+ throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
3936
+ case 8:
3937
+ if (isForeignAsset(asset)) {
3938
+ _context.next = 10;
3939
+ break;
3940
+ }
3941
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3942
+ case 10:
3943
+ if (asset.multiLocation) {
3944
+ _context.next = 12;
3945
+ break;
3946
+ }
3947
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3948
+ case 12:
3949
+ modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
3950
+ header: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, Parents.TWO),
3951
+ addressSelection: createVersionedBeneficiary({
3952
+ api: api,
3953
+ scenario: scenario,
3954
+ pallet: 'PolkadotXcm',
3955
+ recipientAddress: address,
3956
+ version: this.version,
3957
+ paraId: paraIdTo
3958
+ }),
3959
+ currencySelection: createVersionedMultiAssets(Version.V3, asset.amount, asset.multiLocation)
3960
+ });
3961
+ return _context.abrupt("return", PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited'));
3962
+ case 14:
3963
+ case "end":
3964
+ return _context.stop();
3965
+ }
3966
+ }, _callee, this);
3967
+ }));
3968
+ function handleEthBridgeTransfer(_x) {
3969
+ return _handleEthBridgeTransfer.apply(this, arguments);
3869
3970
  }
3870
- var modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
3871
- header: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, Parents.TWO),
3872
- addressSelection: createVersionedBeneficiary({
3873
- api: api,
3874
- scenario: scenario,
3875
- pallet: 'PolkadotXcm',
3876
- recipientAddress: address,
3877
- version: this.version,
3878
- paraId: paraIdTo
3879
- }),
3880
- currencySelection: createVersionedMultiAssets(Version.V3, asset.amount, asset.multiLocation)
3881
- });
3882
- return PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited');
3883
- }
3971
+ return handleEthBridgeTransfer;
3972
+ }()
3884
3973
  }, {
3885
3974
  key: "handleMythosTransfer",
3886
3975
  value: function handleMythosTransfer(input) {
@@ -3959,14 +4048,14 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3959
4048
  }, {
3960
4049
  key: "handleExecuteTransfer",
3961
4050
  value: function () {
3962
- var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
4051
+ var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3963
4052
  var api, senderAddress, asset, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
3964
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3965
- while (1) switch (_context.prev = _context.next) {
4053
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4054
+ while (1) switch (_context2.prev = _context2.next) {
3966
4055
  case 0:
3967
4056
  api = input.api, senderAddress = input.senderAddress, asset = input.asset;
3968
4057
  if (senderAddress) {
3969
- _context.next = 3;
4058
+ _context2.next = 3;
3970
4059
  break;
3971
4060
  }
3972
4061
  throw new Error('Please provide senderAddress');
@@ -3978,53 +4067,53 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3978
4067
  refTime: maxU64,
3979
4068
  proofSize: maxU64
3980
4069
  }, MIN_FEE);
3981
- _context.next = 9;
4070
+ _context2.next = 9;
3982
4071
  return api.getDryRun({
3983
4072
  node: this.node,
3984
4073
  tx: dummyTx,
3985
4074
  address: senderAddress
3986
4075
  });
3987
4076
  case 9:
3988
- dryRunResult = _context.sent;
4077
+ dryRunResult = _context2.sent;
3989
4078
  if (dryRunResult.success) {
3990
- _context.next = 12;
4079
+ _context2.next = 12;
3991
4080
  break;
3992
4081
  }
3993
4082
  throw new Error("Dry run failed: ".concat(dryRunResult.failureReason));
3994
4083
  case 12:
3995
4084
  if (dryRunResult.weight) {
3996
- _context.next = 14;
4085
+ _context2.next = 14;
3997
4086
  break;
3998
4087
  }
3999
4088
  throw new Error('Dry run failed: weight not found');
4000
4089
  case 14:
4001
4090
  feeDotShifted = dryRunResult.fee / 10n;
4002
4091
  toMl = transformMultiLocation(asset.multiLocation);
4003
- _context.next = 18;
4092
+ _context2.next = 18;
4004
4093
  return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
4005
4094
  case 18:
4006
- feeConverted = _context.sent;
4095
+ feeConverted = _context2.sent;
4007
4096
  if (feeConverted) {
4008
- _context.next = 21;
4097
+ _context2.next = 21;
4009
4098
  break;
4010
4099
  }
4011
4100
  throw new Error("Pool DOT -> ".concat(asset.symbol, " not found."));
4012
4101
  case 21:
4013
4102
  if (!(BigInt(asset.amount) - feeConverted < 0)) {
4014
- _context.next = 23;
4103
+ _context2.next = 23;
4015
4104
  break;
4016
4105
  }
4017
4106
  throw new Error("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
4018
4107
  case 23:
4019
4108
  feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
4020
- return _context.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4109
+ return _context2.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4021
4110
  case 25:
4022
4111
  case "end":
4023
- return _context.stop();
4112
+ return _context2.stop();
4024
4113
  }
4025
- }, _callee, this);
4114
+ }, _callee2, this);
4026
4115
  }));
4027
- function handleExecuteTransfer(_x) {
4116
+ function handleExecuteTransfer(_x2) {
4028
4117
  return _handleExecuteTransfer.apply(this, arguments);
4029
4118
  }
4030
4119
  return handleExecuteTransfer;
@@ -5871,7 +5960,7 @@ var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
5871
5960
  var transferMoonbeamToEth = /*#__PURE__*/function () {
5872
5961
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
5873
5962
  var _signer$account;
5874
- var api, from, to, signer, address, ahAddress, currency, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
5963
+ var api, from, to, signer, address, ahAddress, currency, bridgeStatus, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
5875
5964
  return _regeneratorRuntime().wrap(function _callee$(_context) {
5876
5965
  while (1) switch (_context.prev = _context.next) {
5877
5966
  case 0:
@@ -5882,38 +5971,48 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5882
5971
  }
5883
5972
  throw new Error('AssetHub address is required');
5884
5973
  case 3:
5974
+ _context.next = 5;
5975
+ return getBridgeStatus(api.clone());
5976
+ case 5:
5977
+ bridgeStatus = _context.sent;
5978
+ if (!(bridgeStatus !== 'Normal')) {
5979
+ _context.next = 8;
5980
+ break;
5981
+ }
5982
+ throw new BridgeHaltedError();
5983
+ case 8:
5885
5984
  if (!('multiasset' in currency)) {
5886
- _context.next = 5;
5985
+ _context.next = 10;
5887
5986
  break;
5888
5987
  }
5889
5988
  throw new Error('Multiassets syntax is not supported for Evm transfers');
5890
- case 5:
5989
+ case 10:
5891
5990
  if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
5892
- _context.next = 7;
5991
+ _context.next = 12;
5893
5992
  break;
5894
5993
  }
5895
5994
  throw new Error('Override multilocation is not supported for Evm transfers');
5896
- case 7:
5995
+ case 12:
5897
5996
  foundAsset = findAsset(from, currency, to);
5898
5997
  if (!(foundAsset === null)) {
5899
- _context.next = 10;
5998
+ _context.next = 15;
5900
5999
  break;
5901
6000
  }
5902
6001
  throw new InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
5903
- case 10:
6002
+ case 15:
5904
6003
  if (!(!isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
5905
- _context.next = 12;
6004
+ _context.next = 17;
5906
6005
  break;
5907
6006
  }
5908
6007
  throw new InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
5909
- case 12:
6008
+ case 17:
5910
6009
  ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), foundAsset.multiLocation);
5911
6010
  if (!(!ethAsset || !ethAsset.assetId)) {
5912
- _context.next = 15;
6011
+ _context.next = 20;
5913
6012
  break;
5914
6013
  }
5915
6014
  throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
5916
- case 15:
6015
+ case 20:
5917
6016
  contract = isEthersSigner(signer) ? new Contract(xcmInterfacePrecompile, abi, signer) : getContract({
5918
6017
  abi: abi,
5919
6018
  address: xcmInterfacePrecompile,
@@ -5926,31 +6025,31 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5926
6025
  }
5927
6026
  });
5928
6027
  if (!isEthersSigner(signer)) {
5929
- _context.next = 22;
6028
+ _context.next = 27;
5930
6029
  break;
5931
6030
  }
5932
- _context.next = 19;
6031
+ _context.next = 24;
5933
6032
  return signer.getAddress();
5934
- case 19:
6033
+ case 24:
5935
6034
  _context.t0 = _context.sent;
5936
- _context.next = 23;
6035
+ _context.next = 28;
5937
6036
  break;
5938
- case 22:
6037
+ case 27:
5939
6038
  _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
5940
- case 23:
6039
+ case 28:
5941
6040
  senderAddress = _context.t0;
5942
6041
  if (senderAddress) {
5943
- _context.next = 26;
6042
+ _context.next = 31;
5944
6043
  break;
5945
6044
  }
5946
6045
  throw new Error('Unable to get sender address');
5947
- case 26:
5948
- _context.next = 28;
6046
+ case 31:
6047
+ _context.next = 33;
5949
6048
  return api.init(from);
5950
- case 28:
5951
- _context.next = 30;
6049
+ case 33:
6050
+ _context.next = 35;
5952
6051
  return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
5953
- case 30:
6052
+ case 35:
5954
6053
  messageId = _context.sent;
5955
6054
  customXcm = createCustomXcmOnDest({
5956
6055
  api: api,
@@ -5960,17 +6059,17 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5960
6059
  asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
5961
6060
  amount: currency.amount
5962
6061
  })}, Version.V4, messageId);
5963
- _context.next = 34;
6062
+ _context.next = 39;
5964
6063
  return api.objectToHex(customXcm, 'XcmVersionedXcm');
5965
- case 34:
6064
+ case 39:
5966
6065
  customXcmOnDest = _context.sent;
5967
- _context.next = 37;
6066
+ _context.next = 42;
5968
6067
  return api.createApiForNode('AssetHubPolkadot');
5969
- case 37:
6068
+ case 42:
5970
6069
  assetHubApi = _context.sent;
5971
- _context.next = 40;
6070
+ _context.next = 45;
5972
6071
  return getParaEthTransferFees(assetHubApi);
5973
- case 40:
6072
+ case 45:
5974
6073
  _yield$getParaEthTran = _context.sent;
5975
6074
  _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
5976
6075
  bridgeFee = _yield$getParaEthTran2[0];
@@ -5988,7 +6087,7 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
5988
6087
  throw new Error('Input must be a valid number');
5989
6088
  }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
5990
6089
  }; // Execute the custom XCM message with the precompile
5991
- _context.next = 49;
6090
+ _context.next = 54;
5992
6091
  return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
5993
6092
  // This represents (1,X1(Parachain(1000)))
5994
6093
  [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
@@ -6000,10 +6099,10 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
6000
6099
  0,
6001
6100
  // The TransferType corresponding to fee asset
6002
6101
  2, customXcmOnDest]);
6003
- case 49:
6102
+ case 54:
6004
6103
  tx = _context.sent;
6005
6104
  return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
6006
- case 51:
6105
+ case 56:
6007
6106
  case "end":
6008
6107
  return _context.stop();
6009
6108
  }
@@ -7444,4 +7543,4 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
7444
7543
  };
7445
7544
  }();
7446
7545
 
7447
- export { AssetClaimBuilder, BatchMode, Builder, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, Version, XTokensError, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, determineRelayChain, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getDryRun, getFees, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
7546
+ export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, Version, XTokensError, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, determineRelayChain, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getDryRun, getFees, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "8.9.7",
3
+ "version": "8.9.9",
4
4
  "description": "SDK core for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,9 +25,9 @@
25
25
  "dependencies": {
26
26
  "ethers": "^6.13.5",
27
27
  "viem": "^2.23.15",
28
- "@paraspell/assets": "8.9.7",
29
- "@paraspell/sdk-common": "8.9.7",
30
- "@paraspell/pallets": "8.9.7"
28
+ "@paraspell/assets": "8.9.9",
29
+ "@paraspell/pallets": "8.9.9",
30
+ "@paraspell/sdk-common": "8.9.9"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-import-attributes": "^7.26.0",