@paraspell/sdk-core 8.9.10 → 8.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3,8 +3,8 @@
3
3
  var sdkCommon = require('@paraspell/sdk-common');
4
4
  var ethers = require('ethers');
5
5
  var assets = require('@paraspell/assets');
6
- var viem = require('viem');
7
6
  var pallets = require('@paraspell/pallets');
7
+ var viem = require('viem');
8
8
 
9
9
  function _arrayLikeToArray(r, a) {
10
10
  (null == a || a > r.length) && (a = r.length);
@@ -824,156 +824,23 @@ var AssetClaimBuilder = /*#__PURE__*/function () {
824
824
  }]);
825
825
  }();
826
826
 
827
- var getParaEthTransferFees = /*#__PURE__*/function () {
828
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
829
- var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, transferAssethubExecutionFee, finalBridgeFee, finalAssethubExecutionFee;
830
- return _regeneratorRuntime().wrap(function _callee$(_context) {
831
- while (1) switch (_context.prev = _context.next) {
832
- case 0:
833
- DEFAULT_FEE = 2750872500000n;
834
- _context.next = 3;
835
- return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
836
- case 3:
837
- feeStorageItem = _context.sent;
838
- leFeeHex = feeStorageItem.replace('0x', '');
839
- _context.next = 7;
840
- return ahApi.disconnect();
841
- case 7:
842
- bytes = leFeeHex.match(/.{1,2}/g) || [];
843
- reversedHex = bytes.reverse().join('');
844
- validReversedHex = reversedHex === '' ? '0' : reversedHex;
845
- leFee = BigInt('0x' + validReversedHex);
846
- transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
847
- transferAssethubExecutionFee = 2200000000n;
848
- finalBridgeFee = transferBridgeFee * 110n / 100n;
849
- finalAssethubExecutionFee = transferAssethubExecutionFee * 110n / 100n;
850
- return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
851
- case 16:
852
- case "end":
853
- return _context.stop();
854
- }
855
- }, _callee);
856
- }));
857
- return function getParaEthTransferFees(_x) {
858
- return _ref.apply(this, arguments);
859
- };
860
- }();
861
-
862
- var isEthersSigner = function isEthersSigner(signer) {
863
- return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
864
- };
865
- var isEthersContract = function isEthersContract(contract) {
866
- return !('abi' in contract);
867
- };
868
-
869
- var abi$1 = [
870
- {
871
- inputs: [
872
- {
873
- internalType: "address",
874
- name: "currencyAddress",
875
- type: "address"
876
- },
877
- {
878
- internalType: "uint256",
879
- name: "amount",
880
- type: "uint256"
881
- },
882
- {
883
- components: [
884
- {
885
- internalType: "uint8",
886
- name: "parents",
887
- type: "uint8"
888
- },
889
- {
890
- internalType: "bytes[]",
891
- name: "interior",
892
- type: "bytes[]"
893
- }
894
- ],
895
- internalType: "struct Xtokens.Multilocation",
896
- name: "destination",
897
- type: "tuple"
898
- },
899
- {
900
- internalType: "uint64",
901
- name: "weight",
902
- type: "uint64"
903
- }
904
- ],
905
- name: "transfer",
906
- outputs: [
907
- ],
908
- stateMutability: "nonpayable",
909
- type: "function"
910
- },
911
- {
912
- inputs: [
913
- {
914
- components: [
915
- {
916
- internalType: "address",
917
- name: "currencyAddress",
918
- type: "address"
919
- },
920
- {
921
- internalType: "uint256",
922
- name: "amount",
923
- type: "uint256"
924
- }
925
- ],
926
- internalType: "struct Xtokens.Currency[]",
927
- name: "currencies",
928
- type: "tuple[]"
929
- },
930
- {
931
- internalType: "uint32",
932
- name: "feeItem",
933
- type: "uint32"
934
- },
935
- {
936
- components: [
937
- {
938
- internalType: "uint8",
939
- name: "parents",
940
- type: "uint8"
941
- },
942
- {
943
- internalType: "bytes[]",
944
- name: "interior",
945
- type: "bytes[]"
946
- }
947
- ],
948
- internalType: "struct Xtokens.Multilocation",
949
- name: "destination",
950
- type: "tuple"
951
- },
952
- {
953
- internalType: "uint64",
954
- name: "weight",
955
- type: "uint64"
956
- }
957
- ],
958
- name: "transferMultiCurrencies",
959
- outputs: [
960
- ],
961
- stateMutability: "nonpayable",
962
- type: "function"
963
- }
964
- ];
965
-
966
- // Inspired by Moonbeam XCM-SDK
967
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
968
- var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
969
- if (id.startsWith('0x')) {
970
- return id;
971
- }
972
- if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
973
- throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
827
+ var DEFAULT_FEE_ASSET = 0;
828
+ var ETH_PARA_ID = 1;
829
+ var ETH_CHAIN_ID = BigInt(ETH_PARA_ID);
830
+ var ETHEREUM_JUNCTION = {
831
+ GlobalConsensus: {
832
+ Ethereum: {
833
+ chainId: ETH_CHAIN_ID
834
+ }
974
835
  }
975
- return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
976
836
  };
837
+ var DOT_MULTILOCATION = {
838
+ parents: sdkCommon.Parents.ONE,
839
+ interior: 'Here'
840
+ };
841
+ var SYSTEM_NODES_POLKADOT = ['PeoplePolkadot', 'CoretimePolkadot', 'Collectives'];
842
+ var SYSTEM_NODES_KUSAMA = ['PeopleKusama', 'CoretimeKusama'];
843
+ var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
977
844
 
978
845
  var AssetHubPolkadot$1 = {
979
846
  name: "AssetHub",
@@ -2322,22 +2189,18 @@ var getNodeProviders = function getNodeProviders(node) {
2322
2189
  });
2323
2190
  };
2324
2191
 
2325
- var DEFAULT_FEE_ASSET = 0;
2326
- var ETH_PARA_ID = 1;
2327
- var ETH_CHAIN_ID = BigInt(ETH_PARA_ID);
2328
- var ETHEREUM_JUNCTION = {
2329
- GlobalConsensus: {
2330
- Ethereum: {
2331
- chainId: ETH_CHAIN_ID
2332
- }
2192
+ /**
2193
+ * Retrieves the parachain ID for a specified node.
2194
+ *
2195
+ * @param node - The node for which to get the paraId.
2196
+ * @returns The parachain ID of the node.
2197
+ */
2198
+ var getParaId = function getParaId(node) {
2199
+ if (node === 'Ethereum') {
2200
+ return ETH_PARA_ID;
2333
2201
  }
2202
+ return getNodeConfig(node).paraId;
2334
2203
  };
2335
- var DOT_MULTILOCATION = {
2336
- parents: sdkCommon.Parents.ONE,
2337
- interior: 'Here'
2338
- };
2339
- var SYSTEM_NODES_POLKADOT = ['PeoplePolkadot', 'CoretimePolkadot', 'Collectives'];
2340
- var SYSTEM_NODES_KUSAMA = ['PeopleKusama', 'CoretimeKusama'];
2341
2204
 
2342
2205
  var shuffleArray = function shuffleArray(array) {
2343
2206
  var copy = _toConsumableArray(array);
@@ -2858,6 +2721,26 @@ var BridgeHaltedError = /*#__PURE__*/function (_Error) {
2858
2721
  return _createClass(BridgeHaltedError);
2859
2722
  }(/*#__PURE__*/_wrapNativeSuper(Error));
2860
2723
 
2724
+ /**
2725
+ * Error thrown when the Dry Run fails.
2726
+ */
2727
+ var DryRunFailedError = /*#__PURE__*/function (_Error) {
2728
+ /**
2729
+ * Constructs a new DryRunFailedError.
2730
+ *
2731
+ * @param message - Optional custom error message.
2732
+ */
2733
+ function DryRunFailedError(reason) {
2734
+ var _this;
2735
+ _classCallCheck(this, DryRunFailedError);
2736
+ _this = _callSuper(this, DryRunFailedError, ["Dry run failed: ".concat(reason)]);
2737
+ _this.name = 'DryRunFailedError';
2738
+ return _this;
2739
+ }
2740
+ _inherits(DryRunFailedError, _Error);
2741
+ return _createClass(DryRunFailedError);
2742
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
2743
+
2861
2744
  /**
2862
2745
  * Error thrown when nodes from different relay chains are incompatible.
2863
2746
  */
@@ -3168,7 +3051,7 @@ var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, version, messag
3168
3051
  if (!ethAsset) {
3169
3052
  throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3170
3053
  }
3171
- var interior_sb = ethAsset.symbol === 'ETH' ? {
3054
+ var interiorSb = ethAsset.symbol === 'ETH' ? {
3172
3055
  Here: null
3173
3056
  } : {
3174
3057
  X1: [{
@@ -3214,7 +3097,7 @@ var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, version, messag
3214
3097
  fees: {
3215
3098
  id: {
3216
3099
  parents: sdkCommon.Parents.ZERO,
3217
- interior: interior_sb
3100
+ interior: interiorSb
3218
3101
  },
3219
3102
  fun: {
3220
3103
  Fungible: 1n
@@ -3319,14 +3202,16 @@ var ParachainNode = /*#__PURE__*/function () {
3319
3202
  }
3320
3203
  }, {
3321
3204
  key: "canUseXTokens",
3322
- value: function canUseXTokens(_) {
3323
- return true;
3205
+ value: function canUseXTokens(_ref) {
3206
+ var asset = _ref.asset;
3207
+ var isEthAsset = asset.multiLocation && assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
3208
+ return !isEthAsset;
3324
3209
  }
3325
3210
  }, {
3326
3211
  key: "transfer",
3327
3212
  value: function () {
3328
3213
  var _transfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3329
- var api, asset, feeAsset, address, destination, paraIdTo, overriddenAsset, version, senderAddress, pallet, method, isRelayDestination, scenario, paraId, versionOrDefault, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input;
3214
+ var api, asset, feeAsset, address, destination, paraIdTo, overriddenAsset, version, senderAddress, pallet, method, isRelayDestination, scenario, paraId, versionOrDefault, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input, _options, isEthAsset, isAHPOrigin, isAHPDest, isEthDest;
3330
3215
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3331
3216
  while (1) switch (_context.prev = _context.next) {
3332
3217
  case 0:
@@ -3393,10 +3278,10 @@ var ParachainNode = /*#__PURE__*/function () {
3393
3278
  }));
3394
3279
  case 21:
3395
3280
  if (!supportsPolkadotXCM(this)) {
3396
- _context.next = 25;
3281
+ _context.next = 34;
3397
3282
  break;
3398
3283
  }
3399
- return _context.abrupt("return", this.transferPolkadotXCM({
3284
+ _options = {
3400
3285
  api: api,
3401
3286
  header: this.createPolkadotXcmHeader(scenario, versionOrDefault, destination, paraId),
3402
3287
  addressSelection: createVersionedBeneficiary({
@@ -3419,10 +3304,27 @@ var ParachainNode = /*#__PURE__*/function () {
3419
3304
  senderAddress: senderAddress,
3420
3305
  pallet: pallet,
3421
3306
  method: method
3422
- }));
3423
- case 25:
3307
+ }; // Handle common cases
3308
+ isEthAsset = asset.multiLocation && assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
3309
+ isAHPOrigin = this.node === 'AssetHubPolkadot' || this.node === 'AssetHubKusama';
3310
+ isAHPDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
3311
+ isEthDest = destination === 'Ethereum'; // Any origin to any dest via AH - DestinationReserve - multiple instructions
3312
+ if (!(isEthAsset && !isAHPOrigin && !isAHPDest && !isEthDest)) {
3313
+ _context.next = 29;
3314
+ break;
3315
+ }
3316
+ return _context.abrupt("return", this.transferEthAssetViaAH(_options));
3317
+ case 29:
3318
+ if (!(isEthAsset && isAHPDest && !isAHPOrigin && !isEthDest)) {
3319
+ _context.next = 31;
3320
+ break;
3321
+ }
3322
+ return _context.abrupt("return", this.transferToEthereum(_options, true));
3323
+ case 31:
3324
+ return _context.abrupt("return", this.transferPolkadotXCM(_options));
3325
+ case 34:
3424
3326
  throw new NoXCMSupportImplementedError(this._node);
3425
- case 26:
3327
+ case 35:
3426
3328
  case "end":
3427
3329
  return _context.stop();
3428
3330
  }
@@ -3478,108 +3380,264 @@ var ParachainNode = /*#__PURE__*/function () {
3478
3380
  return assets.getNativeAssetSymbol(this.node);
3479
3381
  }
3480
3382
  }, {
3481
- key: "transferToEthereum",
3383
+ key: "transferEthAssetViaAH",
3482
3384
  value: function () {
3483
- var _transferToEthereum = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3484
- var api, asset, scenario, version, destination, address, senderAddress, bridgeStatus, versionOrDefault, ethMultiAsset, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, fee, ethAsset, messageId, call;
3385
+ var _transferEthAssetViaAH = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
3386
+ var _feeAsset$multiLocati;
3387
+ var api, asset, scenario, _input$version, version, destination, address, senderAddress, feeAsset, paraIdTo, ethMultiAsset, PARA_TO_PARA_FEE_DOT, AH_EXECUTION_FEE_PADDED, dryRunResult, dryRunFeePadded, destWithHeader, _extractVersionFromHe, _extractVersionFromHe2, dest, call;
3485
3388
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3486
3389
  while (1) switch (_context2.prev = _context2.next) {
3487
3390
  case 0:
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:
3499
- if (assets.isForeignAsset(asset)) {
3500
- _context2.next = 8;
3391
+ api = input.api, asset = input.asset, scenario = input.scenario, _input$version = input.version, version = _input$version === void 0 ? exports.Version.V4 : _input$version, destination = input.destination, address = input.address, senderAddress = input.senderAddress, feeAsset = input.feeAsset, paraIdTo = input.paraIdTo;
3392
+ if (asset.multiLocation) {
3393
+ _context2.next = 3;
3501
3394
  break;
3502
3395
  }
3503
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3504
- case 8:
3396
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3397
+ case 3:
3505
3398
  if (!(senderAddress === undefined)) {
3506
- _context2.next = 10;
3399
+ _context2.next = 5;
3507
3400
  break;
3508
3401
  }
3509
3402
  throw new Error('Sender address is required for transfers to Ethereum');
3510
- case 10:
3403
+ case 5:
3511
3404
  if (!sdkCommon.isTMultiLocation(address)) {
3512
- _context2.next = 12;
3405
+ _context2.next = 7;
3513
3406
  break;
3514
3407
  }
3515
3408
  throw new Error('Multi-location address is not supported for Ethereum transfers');
3409
+ case 7:
3410
+ ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
3411
+ PARA_TO_PARA_FEE_DOT = 500000000n; // 0.5 DOT
3412
+ // Pad by 25%
3413
+ AH_EXECUTION_FEE_PADDED = ASSET_HUB_EXECUTION_FEE * 125n / 100n; // Perform a dry run AH -> dest to calculate the BuyExecution amount
3414
+ _context2.next = 12;
3415
+ return Builder(api.clone()).from('AssetHubPolkadot').to(destination).currency({
3416
+ symbol: 'DOT',
3417
+ amount: AH_EXECUTION_FEE_PADDED
3418
+ }).address(address).dryRun(senderAddress);
3516
3419
  case 12:
3517
- versionOrDefault = version !== null && version !== void 0 ? version : exports.Version.V4;
3518
- ethMultiAsset = createMultiAsset(versionOrDefault, asset.amount, asset.multiLocation);
3519
- _context2.next = 16;
3520
- return api.createApiForNode('AssetHubPolkadot');
3521
- case 16:
3522
- ahApi = _context2.sent;
3523
- _context2.next = 19;
3524
- return getParaEthTransferFees(ahApi);
3525
- case 19:
3526
- _yield$getParaEthTran = _context2.sent;
3527
- _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
3528
- bridgeFee = _yield$getParaEthTran2[0];
3529
- executionFee = _yield$getParaEthTran2[1];
3530
- fee = (bridgeFee + executionFee).toString();
3531
- ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
3532
- if (!(!ethAsset || !ethAsset.assetId)) {
3533
- _context2.next = 27;
3420
+ dryRunResult = _context2.sent;
3421
+ if (dryRunResult.success) {
3422
+ _context2.next = 15;
3534
3423
  break;
3535
3424
  }
3536
- throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3537
- case 27:
3538
- _context2.next = 29;
3539
- return generateMessageId(api, senderAddress, getParaId(this.node), ethAsset.assetId, address, asset.amount);
3540
- case 29:
3541
- messageId = _context2.sent;
3425
+ throw new DryRunFailedError(dryRunResult.failureReason);
3426
+ case 15:
3427
+ // Pad fee by 50%
3428
+ dryRunFeePadded = BigInt(dryRunResult.fee) * BigInt(3) / BigInt(2);
3429
+ destWithHeader = createPolkadotXcmHeader(scenario, version, destination, paraIdTo);
3430
+ _extractVersionFromHe = extractVersionFromHeader(destWithHeader), _extractVersionFromHe2 = _slicedToArray(_extractVersionFromHe, 2), _extractVersionFromHe2[0], dest = _extractVersionFromHe2[1];
3542
3431
  call = {
3543
3432
  module: 'PolkadotXcm',
3544
3433
  section: 'transfer_assets_using_type_and_then',
3545
3434
  parameters: {
3546
- dest: this.createPolkadotXcmHeader(scenario, versionOrDefault, destination, getParaId('AssetHubPolkadot')),
3547
- assets: _defineProperty({}, versionOrDefault, [createMultiAsset(versionOrDefault, fee, DOT_MULTILOCATION), ethMultiAsset]),
3435
+ dest: this.createPolkadotXcmHeader(scenario, version, destination, getParaId('AssetHubPolkadot')),
3436
+ assets: addXcmVersionHeader([].concat(_toConsumableArray(!feeAsset ? [createMultiAsset(version, PARA_TO_PARA_FEE_DOT, DOT_MULTILOCATION)] : []), [ethMultiAsset]), version),
3548
3437
  assets_transfer_type: 'DestinationReserve',
3549
- remote_fees_id: _defineProperty({}, versionOrDefault, {
3550
- parents: sdkCommon.Parents.ONE,
3551
- interior: 'Here'
3552
- }),
3438
+ remote_fees_id: addXcmVersionHeader((_feeAsset$multiLocati = feeAsset === null || feeAsset === void 0 ? void 0 : feeAsset.multiLocation) !== null && _feeAsset$multiLocati !== void 0 ? _feeAsset$multiLocati : DOT_MULTILOCATION, version),
3553
3439
  fees_transfer_type: 'DestinationReserve',
3554
- custom_xcm_on_dest: createCustomXcmOnDest(input, versionOrDefault, messageId),
3440
+ custom_xcm_on_dest: addXcmVersionHeader([{
3441
+ SetAppendix: [{
3442
+ DepositAsset: {
3443
+ assets: {
3444
+ Wild: 'All'
3445
+ },
3446
+ beneficiary: createBeneficiaryMultiLocation({
3447
+ api: api,
3448
+ scenario: scenario,
3449
+ pallet: 'PolkadotXcm',
3450
+ recipientAddress: senderAddress,
3451
+ version: version
3452
+ })
3453
+ }
3454
+ }]
3455
+ }, {
3456
+ DepositReserveAsset: {
3457
+ assets: {
3458
+ Wild: 'All'
3459
+ },
3460
+ dest: dest,
3461
+ xcm: [{
3462
+ BuyExecution: {
3463
+ fees: {
3464
+ id: DOT_MULTILOCATION,
3465
+ fun: {
3466
+ Fungible: dryRunFeePadded
3467
+ }
3468
+ },
3469
+ weight_limit: 'Unlimited'
3470
+ }
3471
+ }, {
3472
+ DepositAsset: {
3473
+ assets: {
3474
+ Wild: 'All'
3475
+ },
3476
+ beneficiary: createBeneficiaryMultiLocation({
3477
+ api: api,
3478
+ scenario: scenario,
3479
+ pallet: 'PolkadotXcm',
3480
+ recipientAddress: address,
3481
+ version: version
3482
+ })
3483
+ }
3484
+ }]
3485
+ }
3486
+ }], version),
3555
3487
  weight_limit: 'Unlimited'
3556
3488
  }
3557
3489
  };
3558
3490
  return _context2.abrupt("return", api.callTxMethod(call));
3559
- case 32:
3491
+ case 20:
3560
3492
  case "end":
3561
3493
  return _context2.stop();
3562
3494
  }
3563
3495
  }, _callee2, this);
3564
3496
  }));
3565
- function transferToEthereum(_x2) {
3566
- return _transferToEthereum.apply(this, arguments);
3497
+ function transferEthAssetViaAH(_x2) {
3498
+ return _transferEthAssetViaAH.apply(this, arguments);
3567
3499
  }
3568
- return transferToEthereum;
3500
+ return transferEthAssetViaAH;
3569
3501
  }()
3570
- }]);
3571
- }();
3572
-
3573
- var Acala = /*#__PURE__*/function (_ParachainNode) {
3574
- function Acala() {
3575
- _classCallCheck(this, Acala);
3576
- return _callSuper(this, Acala, ['Acala', 'acala', 'polkadot', exports.Version.V3]);
3577
- }
3578
- _inherits(Acala, _ParachainNode);
3579
- return _createClass(Acala, [{
3580
- key: "transferXTokens",
3581
- value: function transferXTokens(input) {
3582
- var asset = input.asset;
3502
+ }, {
3503
+ key: "transferToEthereum",
3504
+ value: function () {
3505
+ var _transferToEthereum = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(input) {
3506
+ var _feeAsset$multiLocati2;
3507
+ var useOnlyDepositInstruction,
3508
+ api,
3509
+ asset,
3510
+ scenario,
3511
+ _input$version2,
3512
+ version,
3513
+ destination,
3514
+ address,
3515
+ senderAddress,
3516
+ feeAsset,
3517
+ bridgeStatus,
3518
+ ethMultiAsset,
3519
+ ahApi,
3520
+ _yield$getParaEthTran,
3521
+ _yield$getParaEthTran2,
3522
+ bridgeFee,
3523
+ executionFee,
3524
+ PARA_TO_PARA_FEE_DOT,
3525
+ fee,
3526
+ ethAsset,
3527
+ messageId,
3528
+ call,
3529
+ _args3 = arguments;
3530
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3531
+ while (1) switch (_context3.prev = _context3.next) {
3532
+ case 0:
3533
+ useOnlyDepositInstruction = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
3534
+ api = input.api, asset = input.asset, scenario = input.scenario, _input$version2 = input.version, version = _input$version2 === void 0 ? exports.Version.V4 : _input$version2, destination = input.destination, address = input.address, senderAddress = input.senderAddress, feeAsset = input.feeAsset;
3535
+ _context3.next = 4;
3536
+ return getBridgeStatus(api.clone());
3537
+ case 4:
3538
+ bridgeStatus = _context3.sent;
3539
+ if (!(bridgeStatus !== 'Normal')) {
3540
+ _context3.next = 7;
3541
+ break;
3542
+ }
3543
+ throw new BridgeHaltedError();
3544
+ case 7:
3545
+ if (asset.multiLocation) {
3546
+ _context3.next = 9;
3547
+ break;
3548
+ }
3549
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3550
+ case 9:
3551
+ if (!(senderAddress === undefined)) {
3552
+ _context3.next = 11;
3553
+ break;
3554
+ }
3555
+ throw new Error('Sender address is required for transfers to Ethereum');
3556
+ case 11:
3557
+ if (!sdkCommon.isTMultiLocation(address)) {
3558
+ _context3.next = 13;
3559
+ break;
3560
+ }
3561
+ throw new Error('Multi-location address is not supported for Ethereum transfers');
3562
+ case 13:
3563
+ ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
3564
+ _context3.next = 16;
3565
+ return api.createApiForNode('AssetHubPolkadot');
3566
+ case 16:
3567
+ ahApi = _context3.sent;
3568
+ _context3.next = 19;
3569
+ return getParaEthTransferFees(ahApi);
3570
+ case 19:
3571
+ _yield$getParaEthTran = _context3.sent;
3572
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
3573
+ bridgeFee = _yield$getParaEthTran2[0];
3574
+ executionFee = _yield$getParaEthTran2[1];
3575
+ PARA_TO_PARA_FEE_DOT = 500000000; // 0.5 DOT
3576
+ fee = useOnlyDepositInstruction ? PARA_TO_PARA_FEE_DOT : (bridgeFee + executionFee).toString();
3577
+ ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
3578
+ if (!(!ethAsset || !ethAsset.assetId)) {
3579
+ _context3.next = 28;
3580
+ break;
3581
+ }
3582
+ throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3583
+ case 28:
3584
+ _context3.next = 30;
3585
+ return generateMessageId(api, senderAddress, getParaId(this.node), ethAsset.assetId, address, asset.amount);
3586
+ case 30:
3587
+ messageId = _context3.sent;
3588
+ call = {
3589
+ module: 'PolkadotXcm',
3590
+ section: 'transfer_assets_using_type_and_then',
3591
+ parameters: {
3592
+ dest: this.createPolkadotXcmHeader(scenario, version, destination, getParaId('AssetHubPolkadot')),
3593
+ assets: addXcmVersionHeader([].concat(_toConsumableArray(!feeAsset ? [createMultiAsset(version, fee, DOT_MULTILOCATION)] : []), [ethMultiAsset]), version),
3594
+ assets_transfer_type: 'DestinationReserve',
3595
+ remote_fees_id: addXcmVersionHeader((_feeAsset$multiLocati2 = feeAsset === null || feeAsset === void 0 ? void 0 : feeAsset.multiLocation) !== null && _feeAsset$multiLocati2 !== void 0 ? _feeAsset$multiLocati2 : DOT_MULTILOCATION, version),
3596
+ fees_transfer_type: 'DestinationReserve',
3597
+ custom_xcm_on_dest: useOnlyDepositInstruction ? addXcmVersionHeader([{
3598
+ DepositAsset: {
3599
+ assets: {
3600
+ Wild: {
3601
+ AllCounted: 1
3602
+ }
3603
+ },
3604
+ beneficiary: createBeneficiaryMultiLocation({
3605
+ api: api,
3606
+ scenario: scenario,
3607
+ pallet: 'PolkadotXcm',
3608
+ recipientAddress: address,
3609
+ version: version
3610
+ })
3611
+ }
3612
+ }], version) : createCustomXcmOnDest(input, version, messageId),
3613
+ weight_limit: 'Unlimited'
3614
+ }
3615
+ };
3616
+ return _context3.abrupt("return", api.callTxMethod(call));
3617
+ case 33:
3618
+ case "end":
3619
+ return _context3.stop();
3620
+ }
3621
+ }, _callee3, this);
3622
+ }));
3623
+ function transferToEthereum(_x3) {
3624
+ return _transferToEthereum.apply(this, arguments);
3625
+ }
3626
+ return transferToEthereum;
3627
+ }()
3628
+ }]);
3629
+ }();
3630
+
3631
+ var Acala = /*#__PURE__*/function (_ParachainNode) {
3632
+ function Acala() {
3633
+ _classCallCheck(this, Acala);
3634
+ return _callSuper(this, Acala, ['Acala', 'acala', 'polkadot', exports.Version.V3]);
3635
+ }
3636
+ _inherits(Acala, _ParachainNode);
3637
+ return _createClass(Acala, [{
3638
+ key: "transferXTokens",
3639
+ value: function transferXTokens(input) {
3640
+ var asset = input.asset;
3583
3641
  var currencySelection = assets.isForeignAsset(asset) ? {
3584
3642
  ForeignAsset: Number(asset.assetId)
3585
3643
  } : {
@@ -3846,28 +3904,29 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3846
3904
  _classCallCheck(this, AssetHubPolkadot);
3847
3905
  _this = _callSuper(this, AssetHubPolkadot, ['AssetHubPolkadot', 'PolkadotAssetHub', 'polkadot', exports.Version.V3]);
3848
3906
  _this.handleBifrostEthTransfer = function (input) {
3907
+ var useDOTAsFeeAsset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3849
3908
  var api = input.api,
3850
3909
  scenario = input.scenario,
3851
3910
  _input$version = input.version,
3852
- version = _input$version === void 0 ? _this.version : _input$version,
3911
+ version = _input$version === void 0 ? exports.Version.V4 : _input$version,
3853
3912
  destination = input.destination,
3854
- asset = input.asset;
3913
+ asset = input.asset,
3914
+ paraIdTo = input.paraIdTo;
3855
3915
  if (!assets.isForeignAsset(asset)) {
3856
3916
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3857
3917
  }
3858
3918
  if (!asset.multiLocation) {
3859
3919
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3860
3920
  }
3921
+ var PARA_TO_PARA_FEE_DOT = 500000000n; // 0.5 DOT
3861
3922
  var call = {
3862
3923
  module: 'PolkadotXcm',
3863
3924
  section: 'transfer_assets_using_type_and_then',
3864
3925
  parameters: {
3865
- dest: _this.createPolkadotXcmHeader(scenario, version, destination, getParaId('BifrostPolkadot')),
3866
- assets: _defineProperty({}, version, [createMultiAsset(version, asset.amount, asset.multiLocation)]),
3926
+ dest: _this.createPolkadotXcmHeader(scenario, version, destination, paraIdTo),
3927
+ assets: addXcmVersionHeader([].concat(_toConsumableArray(useDOTAsFeeAsset ? [createMultiAsset(version, PARA_TO_PARA_FEE_DOT, DOT_MULTILOCATION)] : []), [createMultiAsset(version, asset.amount, asset.multiLocation)]), version),
3867
3928
  assets_transfer_type: 'LocalReserve',
3868
- remote_fees_id: _defineProperty({}, version, {
3869
- Concrete: asset.multiLocation
3870
- }),
3929
+ remote_fees_id: addXcmVersionHeader(useDOTAsFeeAsset ? DOT_MULTILOCATION : asset.multiLocation, version),
3871
3930
  fees_transfer_type: 'LocalReserve',
3872
3931
  custom_xcm_on_dest: createCustomXcmToBifrost(input, version),
3873
3932
  weight_limit: 'Unlimited'
@@ -3909,14 +3968,14 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3909
3968
  throw new assets.InvalidCurrencyError("Polkadot <-> Kusama bridge does not support currency ".concat(input.asset.symbol));
3910
3969
  }
3911
3970
  }, {
3912
- key: "handleEthBridgeTransfer",
3971
+ key: "handleEthBridgeNativeTransfer",
3913
3972
  value: function () {
3914
- var _handleEthBridgeTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
3915
- var api, scenario, destination, paraIdTo, address, asset, bridgeStatus, modifiedInput;
3973
+ var _handleEthBridgeNativeTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
3974
+ var api, _input$version2, version, scenario, destination, senderAddress, address, paraIdTo, asset, bridgeStatus, messageId, multiLocation, call;
3916
3975
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3917
3976
  while (1) switch (_context.prev = _context.next) {
3918
3977
  case 0:
3919
- api = input.api, scenario = input.scenario, destination = input.destination, paraIdTo = input.paraIdTo, address = input.address, asset = input.asset;
3978
+ api = input.api, _input$version2 = input.version, version = _input$version2 === void 0 ? exports.Version.V4 : _input$version2, scenario = input.scenario, destination = input.destination, senderAddress = input.senderAddress, address = input.address, paraIdTo = input.paraIdTo, asset = input.asset;
3920
3979
  _context.next = 3;
3921
3980
  return getBridgeStatus(api.clone());
3922
3981
  case 3:
@@ -3927,24 +3986,120 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3927
3986
  }
3928
3987
  throw new BridgeHaltedError();
3929
3988
  case 6:
3930
- if (ethers.ethers.isAddress(address)) {
3989
+ if (!(senderAddress === undefined)) {
3931
3990
  _context.next = 8;
3932
3991
  break;
3933
3992
  }
3993
+ throw new Error('Sender address is required for transfers to Ethereum');
3994
+ case 8:
3995
+ if (!sdkCommon.isTMultiLocation(address)) {
3996
+ _context.next = 10;
3997
+ break;
3998
+ }
3999
+ throw new Error('Multi-location address is not supported for Ethereum transfers');
4000
+ case 10:
4001
+ if (assets.isForeignAsset(asset)) {
4002
+ _context.next = 12;
4003
+ break;
4004
+ }
4005
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
4006
+ case 12:
4007
+ if (asset.multiLocation) {
4008
+ _context.next = 14;
4009
+ break;
4010
+ }
4011
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
4012
+ case 14:
4013
+ _context.next = 16;
4014
+ return generateMessageId(api, senderAddress, getParaId(this.node), JSON.stringify(asset.multiLocation), address, asset.amount);
4015
+ case 16:
4016
+ messageId = _context.sent;
4017
+ multiLocation = asset.symbol === this.getNativeAssetSymbol() ? DOT_MULTILOCATION : asset.multiLocation;
4018
+ call = {
4019
+ module: 'PolkadotXcm',
4020
+ section: 'transfer_assets_using_type_and_then',
4021
+ parameters: {
4022
+ dest: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, sdkCommon.Parents.TWO),
4023
+ assets: addXcmVersionHeader([createMultiAsset(version, asset.amount, multiLocation)], version),
4024
+ assets_transfer_type: 'LocalReserve',
4025
+ remote_fees_id: addXcmVersionHeader(multiLocation, version),
4026
+ fees_transfer_type: 'LocalReserve',
4027
+ custom_xcm_on_dest: addXcmVersionHeader([{
4028
+ DepositAsset: {
4029
+ assets: {
4030
+ Wild: {
4031
+ AllCounted: 1
4032
+ }
4033
+ },
4034
+ beneficiary: createBeneficiaryMultiLocation({
4035
+ api: api,
4036
+ scenario: scenario,
4037
+ pallet: 'PolkadotXcm',
4038
+ recipientAddress: address,
4039
+ version: version
4040
+ })
4041
+ }
4042
+ }, {
4043
+ SetTopic: messageId
4044
+ }], version),
4045
+ weight_limit: 'Unlimited'
4046
+ }
4047
+ };
4048
+ return _context.abrupt("return", api.callTxMethod(call));
4049
+ case 20:
4050
+ case "end":
4051
+ return _context.stop();
4052
+ }
4053
+ }, _callee, this);
4054
+ }));
4055
+ function handleEthBridgeNativeTransfer(_x) {
4056
+ return _handleEthBridgeNativeTransfer.apply(this, arguments);
4057
+ }
4058
+ return handleEthBridgeNativeTransfer;
4059
+ }()
4060
+ }, {
4061
+ key: "handleEthBridgeTransfer",
4062
+ value: function () {
4063
+ var _handleEthBridgeTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
4064
+ var api, scenario, destination, paraIdTo, address, asset, bridgeStatus, modifiedInput;
4065
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4066
+ while (1) switch (_context2.prev = _context2.next) {
4067
+ case 0:
4068
+ api = input.api, scenario = input.scenario, destination = input.destination, paraIdTo = input.paraIdTo, address = input.address, asset = input.asset;
4069
+ _context2.next = 3;
4070
+ return getBridgeStatus(api.clone());
4071
+ case 3:
4072
+ bridgeStatus = _context2.sent;
4073
+ if (!(bridgeStatus !== 'Normal')) {
4074
+ _context2.next = 6;
4075
+ break;
4076
+ }
4077
+ throw new BridgeHaltedError();
4078
+ case 6:
4079
+ if (ethers.ethers.isAddress(address)) {
4080
+ _context2.next = 8;
4081
+ break;
4082
+ }
3934
4083
  throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
3935
4084
  case 8:
3936
4085
  if (assets.isForeignAsset(asset)) {
3937
- _context.next = 10;
4086
+ _context2.next = 10;
3938
4087
  break;
3939
4088
  }
3940
4089
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3941
4090
  case 10:
3942
4091
  if (asset.multiLocation) {
3943
- _context.next = 12;
4092
+ _context2.next = 12;
3944
4093
  break;
3945
4094
  }
3946
4095
  throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3947
4096
  case 12:
4097
+ if (!(asset.symbol === this.getNativeAssetSymbol() || asset.symbol === assets.getNativeAssetSymbol('Kusama'))) {
4098
+ _context2.next = 14;
4099
+ break;
4100
+ }
4101
+ return _context2.abrupt("return", this.handleEthBridgeNativeTransfer(input));
4102
+ case 14:
3948
4103
  modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
3949
4104
  header: createPolkadotXcmHeader(scenario, this.version, destination, paraIdTo, ETHEREUM_JUNCTION, sdkCommon.Parents.TWO),
3950
4105
  addressSelection: createVersionedBeneficiary({
@@ -3957,14 +4112,14 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
3957
4112
  }),
3958
4113
  currencySelection: createVersionedMultiAssets(exports.Version.V3, asset.amount, asset.multiLocation)
3959
4114
  });
3960
- return _context.abrupt("return", PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited'));
3961
- case 14:
4115
+ return _context2.abrupt("return", PolkadotXCMTransferImpl.transferPolkadotXCM(modifiedInput, 'transfer_assets', 'Unlimited'));
4116
+ case 16:
3962
4117
  case "end":
3963
- return _context.stop();
4118
+ return _context2.stop();
3964
4119
  }
3965
- }, _callee, this);
4120
+ }, _callee2, this);
3966
4121
  }));
3967
- function handleEthBridgeTransfer(_x) {
4122
+ function handleEthBridgeTransfer(_x2) {
3968
4123
  return _handleEthBridgeTransfer.apply(this, arguments);
3969
4124
  }
3970
4125
  return handleEthBridgeTransfer;
@@ -4011,12 +4166,12 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
4011
4166
  paraIdTo = input.paraIdTo,
4012
4167
  scenario = input.scenario,
4013
4168
  api = input.api,
4014
- _input$version2 = input.version,
4015
- version = _input$version2 === void 0 ? this.version : _input$version2,
4169
+ _input$version3 = input.version,
4170
+ version = _input$version3 === void 0 ? this.version : _input$version3,
4016
4171
  address = input.address;
4017
4172
  if ((((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toUpperCase()) === 'USDT' || ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toUpperCase()) === 'USDC') && destination === 'BifrostPolkadot') {
4018
- var _input$version3;
4019
- var versionOrDefault = (_input$version3 = input.version) !== null && _input$version3 !== void 0 ? _input$version3 : exports.Version.V2;
4173
+ var _input$version4;
4174
+ var versionOrDefault = (_input$version4 = input.version) !== null && _input$version4 !== void 0 ? _input$version4 : exports.Version.V2;
4020
4175
  return _objectSpread2(_objectSpread2({}, input), {}, {
4021
4176
  header: this.createPolkadotXcmHeader(scenario, versionOrDefault, destination, paraIdTo),
4022
4177
  addressSelection: createVersionedBeneficiary({
@@ -4047,14 +4202,14 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
4047
4202
  }, {
4048
4203
  key: "handleExecuteTransfer",
4049
4204
  value: function () {
4050
- var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
4205
+ var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(input) {
4051
4206
  var api, senderAddress, asset, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
4052
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4053
- while (1) switch (_context2.prev = _context2.next) {
4207
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4208
+ while (1) switch (_context3.prev = _context3.next) {
4054
4209
  case 0:
4055
4210
  api = input.api, senderAddress = input.senderAddress, asset = input.asset;
4056
4211
  if (senderAddress) {
4057
- _context2.next = 3;
4212
+ _context3.next = 3;
4058
4213
  break;
4059
4214
  }
4060
4215
  throw new Error('Please provide senderAddress');
@@ -4066,53 +4221,53 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
4066
4221
  refTime: maxU64,
4067
4222
  proofSize: maxU64
4068
4223
  }, MIN_FEE);
4069
- _context2.next = 9;
4224
+ _context3.next = 9;
4070
4225
  return api.getDryRun({
4071
4226
  node: this.node,
4072
4227
  tx: dummyTx,
4073
4228
  address: senderAddress
4074
4229
  });
4075
4230
  case 9:
4076
- dryRunResult = _context2.sent;
4231
+ dryRunResult = _context3.sent;
4077
4232
  if (dryRunResult.success) {
4078
- _context2.next = 12;
4233
+ _context3.next = 12;
4079
4234
  break;
4080
4235
  }
4081
4236
  throw new Error("Dry run failed: ".concat(dryRunResult.failureReason));
4082
4237
  case 12:
4083
4238
  if (dryRunResult.weight) {
4084
- _context2.next = 14;
4239
+ _context3.next = 14;
4085
4240
  break;
4086
4241
  }
4087
4242
  throw new Error('Dry run failed: weight not found');
4088
4243
  case 14:
4089
4244
  feeDotShifted = dryRunResult.fee / 10n;
4090
4245
  toMl = transformMultiLocation(asset.multiLocation);
4091
- _context2.next = 18;
4246
+ _context3.next = 18;
4092
4247
  return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
4093
4248
  case 18:
4094
- feeConverted = _context2.sent;
4249
+ feeConverted = _context3.sent;
4095
4250
  if (feeConverted) {
4096
- _context2.next = 21;
4251
+ _context3.next = 21;
4097
4252
  break;
4098
4253
  }
4099
4254
  throw new Error("Pool DOT -> ".concat(asset.symbol, " not found."));
4100
4255
  case 21:
4101
4256
  if (!(BigInt(asset.amount) - feeConverted < 0)) {
4102
- _context2.next = 23;
4257
+ _context3.next = 23;
4103
4258
  break;
4104
4259
  }
4105
4260
  throw new Error("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
4106
4261
  case 23:
4107
4262
  feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
4108
- return _context2.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4263
+ return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
4109
4264
  case 25:
4110
4265
  case "end":
4111
- return _context2.stop();
4266
+ return _context3.stop();
4112
4267
  }
4113
- }, _callee2, this);
4268
+ }, _callee3, this);
4114
4269
  }));
4115
- function handleExecuteTransfer(_x2) {
4270
+ function handleExecuteTransfer(_x3) {
4116
4271
  return _handleExecuteTransfer.apply(this, arguments);
4117
4272
  }
4118
4273
  return handleExecuteTransfer;
@@ -4143,15 +4298,13 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
4143
4298
  if (destination === 'Mythos') {
4144
4299
  return Promise.resolve(this.handleMythosTransfer(input));
4145
4300
  }
4146
- var ethereumAssets = assets.getOtherAssets('Ethereum');
4147
- var isEthereumAsset = ethereumAssets.some(function (_ref3) {
4148
- var symbol = _ref3.symbol,
4149
- assetId = _ref3.assetId;
4150
- return asset.symbol === symbol && assets.isForeignAsset(asset) && asset.assetId === assetId;
4151
- });
4301
+ var isEthereumAsset = asset.multiLocation && assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
4152
4302
  if (destination === 'BifrostPolkadot' && isEthereumAsset) {
4153
4303
  return Promise.resolve(this.handleBifrostEthTransfer(input));
4154
4304
  }
4305
+ if (isEthereumAsset) {
4306
+ return Promise.resolve(this.handleBifrostEthTransfer(input, true));
4307
+ }
4155
4308
  var isSystemNode = !sdkCommon.isTMultiLocation(destination) && SYSTEM_NODES_POLKADOT.includes(destination);
4156
4309
  if (scenario === 'ParaToPara' && asset.symbol === 'DOT' && !assets.isForeignAsset(asset) && destination !== 'Hydration' && destination !== 'Polimec' && destination !== 'Moonbeam' && destination !== 'BifrostPolkadot' && destination !== 'PeoplePolkadot' && !isSystemNode) {
4157
4310
  throw new ScenarioNotSupportedError(this.node, scenario, 'Para to Para scenarios for DOT transfer from AssetHub are not supported, you have to transfer DOT to Relay chain and transfer to destination chain from Relay chain.');
@@ -4331,6 +4484,8 @@ var BifrostPolkadot = /*#__PURE__*/function (_ParachainNode) {
4331
4484
  value: function canUseXTokens(_ref) {
4332
4485
  var asset = _ref.asset,
4333
4486
  destination = _ref.to;
4487
+ var isEthAsset = asset.multiLocation && assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
4488
+ if (isEthAsset) return false;
4334
4489
  if (destination === 'Ethereum') return false;
4335
4490
  return asset.symbol !== 'WETH' && asset.symbol !== 'DOT' || destination !== 'AssetHubPolkadot';
4336
4491
  }
@@ -5028,7 +5183,8 @@ var Hydration = /*#__PURE__*/function (_ParachainNode) {
5028
5183
  value: function canUseXTokens(_ref3) {
5029
5184
  var destination = _ref3.to,
5030
5185
  asset = _ref3.asset;
5031
- return destination !== 'Ethereum' && destination !== 'Polimec' && !(destination === 'AssetHubPolkadot' && asset.symbol === 'DOT');
5186
+ var isEthAsset = asset.multiLocation && assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), asset.multiLocation);
5187
+ return destination !== 'Ethereum' && destination !== 'Polimec' && !(destination === 'AssetHubPolkadot' && asset.symbol === 'DOT') && !isEthAsset;
5032
5188
  }
5033
5189
  }]);
5034
5190
  }(ParachainNode);
@@ -5758,17 +5914,154 @@ var nodes = function nodes() {
5758
5914
  };
5759
5915
  };
5760
5916
 
5761
- /**
5762
- * Retrieves the parachain ID for a specified node.
5763
- *
5764
- * @param node - The node for which to get the paraId.
5765
- * @returns The parachain ID of the node.
5766
- */
5767
- var getParaId = function getParaId(node) {
5768
- if (node === 'Ethereum') {
5769
- return ETH_PARA_ID;
5917
+ var getParaEthTransferFees = /*#__PURE__*/function () {
5918
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
5919
+ var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
5920
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
5921
+ while (1) switch (_context.prev = _context.next) {
5922
+ case 0:
5923
+ DEFAULT_FEE = 2750872500000n;
5924
+ _context.next = 3;
5925
+ return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
5926
+ case 3:
5927
+ feeStorageItem = _context.sent;
5928
+ leFeeHex = feeStorageItem.replace('0x', '');
5929
+ _context.next = 7;
5930
+ return ahApi.disconnect();
5931
+ case 7:
5932
+ bytes = leFeeHex.match(/.{1,2}/g) || [];
5933
+ reversedHex = bytes.reverse().join('');
5934
+ validReversedHex = reversedHex === '' ? '0' : reversedHex;
5935
+ leFee = BigInt('0x' + validReversedHex);
5936
+ transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
5937
+ finalBridgeFee = transferBridgeFee * 110n / 100n;
5938
+ finalAssethubExecutionFee = ASSET_HUB_EXECUTION_FEE * 110n / 100n;
5939
+ return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
5940
+ case 15:
5941
+ case "end":
5942
+ return _context.stop();
5943
+ }
5944
+ }, _callee);
5945
+ }));
5946
+ return function getParaEthTransferFees(_x) {
5947
+ return _ref.apply(this, arguments);
5948
+ };
5949
+ }();
5950
+
5951
+ var isEthersSigner = function isEthersSigner(signer) {
5952
+ return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
5953
+ };
5954
+ var isEthersContract = function isEthersContract(contract) {
5955
+ return !('abi' in contract);
5956
+ };
5957
+
5958
+ var abi$1 = [
5959
+ {
5960
+ inputs: [
5961
+ {
5962
+ internalType: "address",
5963
+ name: "currencyAddress",
5964
+ type: "address"
5965
+ },
5966
+ {
5967
+ internalType: "uint256",
5968
+ name: "amount",
5969
+ type: "uint256"
5970
+ },
5971
+ {
5972
+ components: [
5973
+ {
5974
+ internalType: "uint8",
5975
+ name: "parents",
5976
+ type: "uint8"
5977
+ },
5978
+ {
5979
+ internalType: "bytes[]",
5980
+ name: "interior",
5981
+ type: "bytes[]"
5982
+ }
5983
+ ],
5984
+ internalType: "struct Xtokens.Multilocation",
5985
+ name: "destination",
5986
+ type: "tuple"
5987
+ },
5988
+ {
5989
+ internalType: "uint64",
5990
+ name: "weight",
5991
+ type: "uint64"
5992
+ }
5993
+ ],
5994
+ name: "transfer",
5995
+ outputs: [
5996
+ ],
5997
+ stateMutability: "nonpayable",
5998
+ type: "function"
5999
+ },
6000
+ {
6001
+ inputs: [
6002
+ {
6003
+ components: [
6004
+ {
6005
+ internalType: "address",
6006
+ name: "currencyAddress",
6007
+ type: "address"
6008
+ },
6009
+ {
6010
+ internalType: "uint256",
6011
+ name: "amount",
6012
+ type: "uint256"
6013
+ }
6014
+ ],
6015
+ internalType: "struct Xtokens.Currency[]",
6016
+ name: "currencies",
6017
+ type: "tuple[]"
6018
+ },
6019
+ {
6020
+ internalType: "uint32",
6021
+ name: "feeItem",
6022
+ type: "uint32"
6023
+ },
6024
+ {
6025
+ components: [
6026
+ {
6027
+ internalType: "uint8",
6028
+ name: "parents",
6029
+ type: "uint8"
6030
+ },
6031
+ {
6032
+ internalType: "bytes[]",
6033
+ name: "interior",
6034
+ type: "bytes[]"
6035
+ }
6036
+ ],
6037
+ internalType: "struct Xtokens.Multilocation",
6038
+ name: "destination",
6039
+ type: "tuple"
6040
+ },
6041
+ {
6042
+ internalType: "uint64",
6043
+ name: "weight",
6044
+ type: "uint64"
6045
+ }
6046
+ ],
6047
+ name: "transferMultiCurrencies",
6048
+ outputs: [
6049
+ ],
6050
+ stateMutability: "nonpayable",
6051
+ type: "function"
6052
+ }
6053
+ ];
6054
+
6055
+ // Inspired by Moonbeam XCM-SDK
6056
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
6057
+ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
6058
+ if (id.startsWith('0x')) {
6059
+ return id;
5770
6060
  }
5771
- return getNodeConfig(node).paraId;
6061
+ if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
6062
+ throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
6063
+ }
6064
+ return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
5772
6065
  };
5773
6066
 
5774
6067
  // Partially inspired by Moonbeam XCM-SDK
@@ -7545,6 +7838,7 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
7545
7838
  exports.AssetClaimBuilder = AssetClaimBuilder;
7546
7839
  exports.BridgeHaltedError = BridgeHaltedError;
7547
7840
  exports.Builder = Builder;
7841
+ exports.DryRunFailedError = DryRunFailedError;
7548
7842
  exports.ETHEREUM_JUNCTION = ETHEREUM_JUNCTION;
7549
7843
  exports.ETH_CHAIN_ID = ETH_CHAIN_ID;
7550
7844
  exports.GeneralBuilder = GeneralBuilder;