@paraspell/sdk-core 8.12.0 → 8.13.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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isTMultiLocation, Parents, isRelayChain, NODE_NAMES_DOT_KSM, hasJunction, deepEqual } from '@paraspell/sdk-common';
2
2
  export * from '@paraspell/sdk-common';
3
3
  import { ethers, Contract } from 'ethers';
4
- import { InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, isNodeEvm, getRelayChainSymbol, isForeignAsset, findAssetByMultiLocation, isAssetEqual, getAssetId, getAssetsObject, findAsset, isOverrideMultiLocationSpecifier, hasDryRunSupport, isTMultiAsset, isSymbolSpecifier, getNativeAssets, hasSupportForAsset, extractMultiAssetLoc, getExistentialDeposit } from '@paraspell/assets';
4
+ import { InvalidCurrencyError, isForeignAsset, getOtherAssets, isNodeEvm, findAssetByMultiLocation, getNativeAssetSymbol, isAssetEqual, getAssetId, getRelayChainSymbol, hasDryRunSupport, findAsset, getAssetsObject, isOverrideMultiLocationSpecifier, isTMultiAsset, isSymbolSpecifier, getNativeAssets, hasSupportForAsset, extractMultiAssetLoc, getExistentialDeposit } from '@paraspell/assets';
5
5
  export * from '@paraspell/assets';
6
6
  import { getSupportedPalletsDetails, getDefaultPallet } from '@paraspell/pallets';
7
7
  export * from '@paraspell/pallets';
@@ -955,25 +955,6 @@ var ScenarioNotSupportedError = /*#__PURE__*/function (_Error) {
955
955
  return _createClass(ScenarioNotSupportedError);
956
956
  }(/*#__PURE__*/_wrapNativeSuper(Error));
957
957
 
958
- var DEFAULT_FEE_ASSET = 0;
959
- var ETH_PARA_ID = 1;
960
- var ETH_CHAIN_ID = BigInt(ETH_PARA_ID);
961
- var ETHEREUM_JUNCTION = {
962
- GlobalConsensus: {
963
- Ethereum: {
964
- chainId: ETH_CHAIN_ID
965
- }
966
- }
967
- };
968
- var DOT_MULTILOCATION = {
969
- parents: Parents.ONE,
970
- interior: 'Here'
971
- };
972
- var SYSTEM_NODES_POLKADOT = ['PeoplePolkadot', 'CoretimePolkadot', 'Collectives'];
973
- var SYSTEM_NODES_KUSAMA = ['PeopleKusama', 'CoretimeKusama'];
974
- var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
975
- // 30% padding
976
-
977
958
  var AssetHubPolkadot$1 = {
978
959
  name: "AssetHub",
979
960
  info: "PolkadotAssetHub",
@@ -1227,14 +1208,14 @@ var Centrifuge$1 = {
1227
1208
  info: "centrifuge",
1228
1209
  paraId: 2031,
1229
1210
  providers: [
1230
- {
1231
- name: "Centrifuge",
1232
- endpoint: "wss://fullnode.centrifuge.io"
1233
- },
1234
1211
  {
1235
1212
  name: "LuckyFriday",
1236
1213
  endpoint: "wss://rpc-centrifuge.luckyfriday.io"
1237
1214
  },
1215
+ {
1216
+ name: "Centrifuge",
1217
+ endpoint: "wss://fullnode.centrifuge.io"
1218
+ },
1238
1219
  {
1239
1220
  name: "OnFinality",
1240
1221
  endpoint: "wss://centrifuge-parachain.api.onfinality.io/public-ws"
@@ -1330,20 +1311,20 @@ var Moonbeam$1 = {
1330
1311
  paraId: 2004,
1331
1312
  providers: [
1332
1313
  {
1333
- name: "Allnodes",
1334
- endpoint: "wss://moonbeam-rpc.publicnode.com"
1314
+ name: "IBP1",
1315
+ endpoint: "wss://moonbeam.ibp.network"
1335
1316
  },
1336
1317
  {
1337
- name: "Blast",
1338
- endpoint: "wss://moonbeam.public.blastapi.io"
1318
+ name: "RadiumBlock",
1319
+ endpoint: "wss://moonbeam.public.curie.radiumblock.co/ws"
1339
1320
  },
1340
1321
  {
1341
- name: "Dwellir",
1342
- endpoint: "wss://moonbeam-rpc.n.dwellir.com"
1322
+ name: "Allnodes",
1323
+ endpoint: "wss://moonbeam-rpc.publicnode.com"
1343
1324
  },
1344
1325
  {
1345
- name: "IBP1",
1346
- endpoint: "wss://moonbeam.ibp.network"
1326
+ name: "Blast",
1327
+ endpoint: "wss://moonbeam.public.blastapi.io"
1347
1328
  },
1348
1329
  {
1349
1330
  name: "IBP2",
@@ -1357,10 +1338,6 @@ var Moonbeam$1 = {
1357
1338
  name: "OnFinality",
1358
1339
  endpoint: "wss://moonbeam.api.onfinality.io/public-ws"
1359
1340
  },
1360
- {
1361
- name: "RadiumBlock",
1362
- endpoint: "wss://moonbeam.public.curie.radiumblock.co/ws"
1363
- },
1364
1341
  {
1365
1342
  name: "UnitedBloc",
1366
1343
  endpoint: "wss://moonbeam.unitedbloc.com"
@@ -2305,57 +2282,24 @@ var getNodeProviders = function getNodeProviders(node) {
2305
2282
  });
2306
2283
  };
2307
2284
 
2308
- /**
2309
- * Retrieves the parachain ID for a specified node.
2310
- *
2311
- * @param node - The node for which to get the paraId.
2312
- * @returns The parachain ID of the node.
2313
- */
2314
- var getParaId = function getParaId(node) {
2315
- if (node === 'Ethereum') {
2316
- return ETH_PARA_ID;
2317
- }
2318
- return getNodeConfig(node).paraId;
2319
- };
2320
-
2321
- var shuffleArray = function shuffleArray(array) {
2322
- var copy = _toConsumableArray(array);
2323
- for (var i = copy.length - 1; i > 0; i--) {
2324
- var j = Math.floor(Math.random() * (i + 1));
2325
- var _ref = [copy[j], copy[i]];
2326
- copy[i] = _ref[0];
2327
- copy[j] = _ref[1];
2285
+ var DEFAULT_FEE_ASSET = 0;
2286
+ var ETH_PARA_ID = 1;
2287
+ var ETH_CHAIN_ID = BigInt(ETH_PARA_ID);
2288
+ var ETHEREUM_JUNCTION = {
2289
+ GlobalConsensus: {
2290
+ Ethereum: {
2291
+ chainId: ETH_CHAIN_ID
2292
+ }
2328
2293
  }
2329
- return copy;
2330
2294
  };
2331
-
2332
- var shuffleWsProviders = function shuffleWsProviders(node, wsProviders) {
2333
- var ALLOWED_NODES = ['Hydration', 'Acala'];
2334
- if (ALLOWED_NODES.includes(node)) {
2335
- return shuffleArray(wsProviders);
2336
- }
2337
- return wsProviders;
2295
+ var DOT_MULTILOCATION = {
2296
+ parents: Parents.ONE,
2297
+ interior: 'Here'
2338
2298
  };
2339
-
2340
- var createApiInstanceForNode = /*#__PURE__*/function () {
2341
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node) {
2342
- var wsUrl, resolvedWsUrl;
2343
- return _regeneratorRuntime().wrap(function _callee$(_context) {
2344
- while (1) switch (_context.prev = _context.next) {
2345
- case 0:
2346
- wsUrl = getNodeProviders(node);
2347
- resolvedWsUrl = Array.isArray(wsUrl) ? shuffleWsProviders(node, wsUrl) : wsUrl;
2348
- return _context.abrupt("return", api.createApiInstance(resolvedWsUrl));
2349
- case 3:
2350
- case "end":
2351
- return _context.stop();
2352
- }
2353
- }, _callee);
2354
- }));
2355
- return function createApiInstanceForNode(_x, _x2) {
2356
- return _ref.apply(this, arguments);
2357
- };
2358
- }();
2299
+ var SYSTEM_NODES_POLKADOT = ['PeoplePolkadot', 'CoretimePolkadot', 'Collectives'];
2300
+ var SYSTEM_NODES_KUSAMA = ['PeopleKusama', 'CoretimeKusama'];
2301
+ var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
2302
+ // 30% padding
2359
2303
 
2360
2304
  var createX1Payload = function createX1Payload(version, junction) {
2361
2305
  return version === Version.V4 ? {
@@ -2518,297 +2462,389 @@ var throwUnsupportedCurrency = function throwUnsupportedCurrency(currency, node)
2518
2462
  throw new InvalidCurrencyError("".concat(isDestination ? 'Destination' : 'Origin', " node ").concat(node, " does not support currency ").concat(JSON.stringify(currency), "."));
2519
2463
  };
2520
2464
 
2521
- var createBeneficiaryMultiLocation = function createBeneficiaryMultiLocation(_ref) {
2522
- var api = _ref.api,
2523
- scenario = _ref.scenario,
2524
- pallet = _ref.pallet,
2525
- recipientAddress = _ref.recipientAddress,
2526
- version = _ref.version,
2527
- paraId = _ref.paraId;
2528
- if (isTMultiLocation(recipientAddress)) {
2529
- return recipientAddress;
2530
- }
2531
- var isEthAddress = ethers.isAddress(recipientAddress);
2532
- var getAccountPayload = function getAccountPayload(allowNetwork) {
2533
- if (isEthAddress) {
2534
- return {
2535
- AccountKey20: _objectSpread2({
2536
- key: recipientAddress
2537
- }, allowNetwork ? {
2538
- network: 'any'
2539
- } : {})
2540
- };
2465
+ var buildMultiLocation = function buildMultiLocation(_ref) {
2466
+ var paraIdTo = _ref.paraIdTo,
2467
+ asset = _ref.asset,
2468
+ origin = _ref.origin,
2469
+ destination = _ref.destination;
2470
+ if (!isForeignAsset(asset)) {
2471
+ if (_typeof(destination) === 'object') {
2472
+ return destination;
2541
2473
  }
2542
- return {
2543
- AccountId32: _objectSpread2({
2544
- id: api.accountToHex(recipientAddress)
2545
- }, allowNetwork ? {
2546
- network: 'any'
2547
- } : {})
2548
- };
2549
- };
2550
- if (scenario === 'ParaToRelay') {
2551
- return {
2552
- parents: pallet === 'XTokens' ? Parents.ONE : Parents.ZERO,
2553
- interior: createX1Payload(version, {
2554
- AccountId32: _objectSpread2({
2555
- id: api.accountToHex(recipientAddress)
2556
- }, version === Version.V1 ? {
2557
- network: 'any'
2558
- } : {})
2559
- })
2560
- };
2561
- } else if (scenario === 'ParaToPara' && pallet === 'XTokens') {
2474
+ // ParaToRelay scenario
2475
+ if (isRelayChain(destination)) {
2476
+ return DOT_MULTILOCATION;
2477
+ }
2478
+ // If it is a native asset, search by symbol on AssetHub and use the multiLocation from there
2479
+ var assetHubAsset = getOtherAssets(destination).find(function (ahAsset) {
2480
+ var _ahAsset$symbol, _asset$symbol;
2481
+ return ((_ahAsset$symbol = ahAsset.symbol) === null || _ahAsset$symbol === void 0 ? void 0 : _ahAsset$symbol.toLowerCase()) === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase());
2482
+ });
2483
+ if (assetHubAsset === undefined) {
2484
+ throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " not found in AssetHub"));
2485
+ }
2486
+ if (assetHubAsset.multiLocation) {
2487
+ return assetHubAsset.multiLocation;
2488
+ }
2489
+ throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " has no multiLocation"));
2490
+ }
2491
+ var createDefaultMultiLocation = function createDefaultMultiLocation(assetId) {
2562
2492
  return {
2563
2493
  parents: Parents.ONE,
2564
2494
  interior: {
2565
- X2: [{
2566
- Parachain: paraId
2567
- }, getAccountPayload(version === Version.V1 || version === Version.V2)]
2495
+ X3: [{
2496
+ Parachain: paraIdTo
2497
+ }, {
2498
+ PalletInstance: '50'
2499
+ }, {
2500
+ GeneralIndex: BigInt(assetId)
2501
+ }]
2568
2502
  }
2569
2503
  };
2570
- } else if (scenario === 'ParaToPara' && pallet === 'PolkadotXcm') {
2571
- return {
2572
- parents: Parents.ZERO,
2573
- interior: createX1Payload(version, getAccountPayload(version === Version.V1 || version === Version.V2))
2574
- };
2504
+ };
2505
+ var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
2506
+ if (isBifrostOrigin) {
2507
+ return createDefaultMultiLocation(asset.assetId);
2508
+ }
2509
+ if (asset.multiLocation) {
2510
+ return asset.multiLocation;
2575
2511
  } else {
2576
- return {
2577
- parents: Parents.ZERO,
2578
- interior: createX1Payload(version, getAccountPayload(false))
2579
- };
2512
+ return createDefaultMultiLocation(asset.assetId);
2580
2513
  }
2581
2514
  };
2582
-
2583
- /**
2584
- * This function transforms a multiLocation by removing the `Parachain` junction
2585
- * if it exists and setting the `parents` to `0`.
2586
- *
2587
- * @param multiLocation - The multiLocation to transform
2588
- * @returns The transformed multiLocation
2589
- */
2590
- var transformMultiLocation = function transformMultiLocation(multiLocation) {
2591
- var newInterior;
2592
- if (multiLocation.interior === 'Here') {
2593
- newInterior = 'Here';
2594
- } else {
2595
- var junctions = Object.values(multiLocation.interior).flat().filter(function (junction) {
2596
- return _typeof(junction) === 'object' && junction !== null;
2597
- });
2598
- var filteredJunctions = junctions.filter(function (junction) {
2599
- return !('Parachain' in junction);
2600
- });
2601
- if (filteredJunctions.length === 0) {
2602
- newInterior = 'Here';
2603
- } else {
2604
- newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
2605
- }
2515
+ var getModifiedCurrencySelection = function getModifiedCurrencySelection(version, input) {
2516
+ var amount = input.asset.amount,
2517
+ overriddenAsset = input.overriddenAsset;
2518
+ if (overriddenAsset) {
2519
+ return addXcmVersionHeader(maybeOverrideMultiAssets(version, amount, [], overriddenAsset), version);
2606
2520
  }
2607
- return _objectSpread2(_objectSpread2({}, multiLocation), {}, {
2608
- parents: Parents.ZERO,
2609
- interior: newInterior
2610
- });
2521
+ var multiLocation = buildMultiLocation(input);
2522
+ var multiAsset = createMultiAsset(version, amount, multiLocation);
2523
+ return addXcmVersionHeader(multiAsset, version);
2611
2524
  };
2612
2525
 
2613
- var createVersionedBeneficiary = function createVersionedBeneficiary(options) {
2614
- var version = options.version;
2615
- var multiLocation = createBeneficiaryMultiLocation(options);
2616
- return addXcmVersionHeader(multiLocation, version);
2526
+ var getCurrencySelection = function getCurrencySelection(input, useMultiAssets, currencySelection) {
2527
+ var origin = input.origin;
2528
+ var _getNode = getNode(origin),
2529
+ version = _getNode.version;
2530
+ if (useMultiAssets) {
2531
+ return getModifiedCurrencySelection(version, input);
2532
+ }
2533
+ return currencySelection;
2617
2534
  };
2618
2535
 
2619
- var getMultiLocationTokenId = function getMultiLocationTokenId(location, node) {
2620
- if (location.interior.type === 'Here') {
2621
- // native token
2622
- return getNativeAssetSymbol(node);
2623
- }
2624
- var foreignAssets = getOtherAssets(node);
2625
- if (location.interior.type === 'X2') {
2626
- if (location.interior.value[0].type === 'PalletInstance' && location.interior.value[0].value === 50 && location.interior.value[1].type === 'GeneralIndex') {
2627
- var _foreignAssets$find$a, _foreignAssets$find;
2628
- var assetId = location.interior.value[1].value;
2629
- return (_foreignAssets$find$a = (_foreignAssets$find = foreignAssets.find(function (asset) {
2630
- return asset.assetId === String(assetId);
2631
- })) === null || _foreignAssets$find === void 0 ? void 0 : _foreignAssets$find.assetId) !== null && _foreignAssets$find$a !== void 0 ? _foreignAssets$find$a : null;
2632
- }
2536
+ var getXTokensParameters = function getXTokensParameters(isMultiAssetTransfer, currencySelection, addressSelection, amount, fees, overriddenAsset) {
2537
+ if (isMultiAssetTransfer) {
2538
+ var isOverridenMultiAssets = overriddenAsset && !isTMultiLocation(overriddenAsset);
2539
+ var feeAssetIndex = isOverridenMultiAssets ? overriddenAsset.findIndex(function (asset) {
2540
+ return asset.isFeeAsset;
2541
+ }) : undefined;
2542
+ return _objectSpread2(_objectSpread2(_defineProperty({}, isOverridenMultiAssets ? 'assets' : 'asset', currencySelection), isOverridenMultiAssets && {
2543
+ fee_item: feeAssetIndex
2544
+ }), {}, {
2545
+ dest: addressSelection,
2546
+ dest_weight_limit: fees
2547
+ });
2633
2548
  }
2634
- return null;
2549
+ return {
2550
+ currency_id: currencySelection,
2551
+ amount: BigInt(amount),
2552
+ dest: addressSelection,
2553
+ dest_weight_limit: fees
2554
+ };
2635
2555
  };
2636
2556
 
2637
- var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, executionFee) {
2638
- // Extract delivery fees from emitted events
2639
- var deliveryFees = [];
2640
- var _iterator = _createForOfIteratorHelper(dryRun.value.emitted_events),
2641
- _step;
2642
- try {
2643
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2644
- var e = _step.value;
2645
- var isXcmEvent = e.type === 'XcmPallet' || e.type === 'PolkadotXcm' || e.type === 'CumulusXcm';
2646
- var isFeesPaid = e.value.type === 'FeesPaid';
2647
- if (isXcmEvent && isFeesPaid && e.value.value.fees) {
2648
- var _iterator2 = _createForOfIteratorHelper(e.value.value.fees),
2649
- _step2;
2650
- try {
2651
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2652
- var feeItem = _step2.value;
2653
- if (feeItem.fun.type === 'NonFungible') continue;
2654
- var plancks = feeItem.fun.value;
2655
- var tokenSymbol = getMultiLocationTokenId(feeItem.id, node);
2656
- if (!tokenSymbol || !plancks) continue;
2657
- deliveryFees.push({
2658
- plancks: plancks,
2659
- tokenSymbol: tokenSymbol
2660
- });
2661
- }
2662
- } catch (err) {
2663
- _iterator2.e(err);
2664
- } finally {
2665
- _iterator2.f();
2666
- }
2557
+ var XTokensTransferImpl = /*#__PURE__*/function () {
2558
+ function XTokensTransferImpl() {
2559
+ _classCallCheck(this, XTokensTransferImpl);
2560
+ }
2561
+ return _createClass(XTokensTransferImpl, null, [{
2562
+ key: "transferXTokens",
2563
+ value: function transferXTokens(input, currencySelection) {
2564
+ var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Unlimited';
2565
+ var api = input.api,
2566
+ origin = input.origin,
2567
+ asset = input.asset,
2568
+ addressSelection = input.addressSelection,
2569
+ destination = input.destination,
2570
+ scenario = input.scenario,
2571
+ overriddenAsset = input.overriddenAsset,
2572
+ pallet = input.pallet,
2573
+ method = input.method,
2574
+ _input$useMultiAssetT = input.useMultiAssetTransfer,
2575
+ useMultiAssetTransfer = _input$useMultiAssetT === void 0 ? false : _input$useMultiAssetT;
2576
+ var isMultiLocationDestination = _typeof(destination) === 'object';
2577
+ if (isMultiLocationDestination) {
2578
+ throw new Error('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
2667
2579
  }
2580
+ var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
2581
+ var isAssetHubDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
2582
+ var isAstarOrShidenToRelay = scenario === 'ParaToRelay' && (origin === 'Astar' || origin === 'Shiden');
2583
+ var isOverridenMultiAssets = overriddenAsset && !isTMultiLocation(overriddenAsset);
2584
+ var shouldUseMultiasset = useMultiAssetTransfer || isAstarOrShidenToRelay || isAssetHubDest && !isBifrostOrigin || !!isOverridenMultiAssets;
2585
+ var modifiedCurrencySelection = getCurrencySelection(input, shouldUseMultiasset, currencySelection);
2586
+ var section = shouldUseMultiasset ? isOverridenMultiAssets ? 'transfer_multiassets' : 'transfer_multiasset' : 'transfer';
2587
+ var parameters = getXTokensParameters(shouldUseMultiasset, modifiedCurrencySelection, addressSelection, asset.amount, fees, overriddenAsset);
2588
+ var call = {
2589
+ module: pallet !== null && pallet !== void 0 ? pallet : 'XTokens',
2590
+ section: method !== null && method !== void 0 ? method : section,
2591
+ parameters: parameters
2592
+ };
2593
+ return api.callTxMethod(call);
2668
2594
  }
2669
- } catch (err) {
2670
- _iterator.e(err);
2671
- } finally {
2672
- _iterator.f();
2673
- }
2674
- var nativeAssetSymbol = getNativeAssetSymbol(node);
2675
- // Sum the fees that match the feeToken
2676
- var totalDeliveryFees = deliveryFees.filter(function (df) {
2677
- return df.tokenSymbol === nativeAssetSymbol;
2678
- }).reduce(function (acc, df) {
2679
- return acc + df.plancks;
2680
- }, 0n);
2681
- return totalDeliveryFees + executionFee;
2682
- };
2595
+ }]);
2596
+ }();
2683
2597
 
2684
- var getMultiLocationTokenIdPjs = function getMultiLocationTokenIdPjs(location, node) {
2685
- if (location.interior === 'Here') {
2686
- // native token
2687
- return getNativeAssetSymbol(node);
2598
+ var getBridgeStatus = /*#__PURE__*/function () {
2599
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
2600
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2601
+ while (1) switch (_context.prev = _context.next) {
2602
+ case 0:
2603
+ _context.next = 2;
2604
+ return api.init('BridgeHubPolkadot');
2605
+ case 2:
2606
+ _context.prev = 2;
2607
+ _context.next = 5;
2608
+ return api.getBridgeStatus();
2609
+ case 5:
2610
+ return _context.abrupt("return", _context.sent);
2611
+ case 6:
2612
+ _context.prev = 6;
2613
+ _context.next = 9;
2614
+ return api.disconnect();
2615
+ case 9:
2616
+ return _context.finish(6);
2617
+ case 10:
2618
+ case "end":
2619
+ return _context.stop();
2620
+ }
2621
+ }, _callee, null, [[2,, 6, 10]]);
2622
+ }));
2623
+ return function getBridgeStatus(_x) {
2624
+ return _ref.apply(this, arguments);
2625
+ };
2626
+ }();
2627
+
2628
+ var createBeneficiaryMultiLocation = function createBeneficiaryMultiLocation(_ref) {
2629
+ var api = _ref.api,
2630
+ scenario = _ref.scenario,
2631
+ pallet = _ref.pallet,
2632
+ recipientAddress = _ref.recipientAddress,
2633
+ version = _ref.version,
2634
+ paraId = _ref.paraId;
2635
+ if (isTMultiLocation(recipientAddress)) {
2636
+ return recipientAddress;
2688
2637
  }
2689
- var foreignAssets = getOtherAssets(node);
2690
- if (Object.keys(location.interior)[0] === 'X2') {
2691
- var junctions = Object.values(location.interior)[0];
2692
- if (Object.keys(junctions[0])[0] === 'PalletInstance' && junctions[0].PalletInstance === '50' && Object.keys(junctions[1])[0] === 'GeneralIndex') {
2693
- var _foreignAssets$find$s, _foreignAssets$find;
2694
- var assetId = junctions[1].GeneralIndex;
2695
- return (_foreignAssets$find$s = (_foreignAssets$find = foreignAssets.find(function (asset) {
2696
- return asset.assetId === String(assetId);
2697
- })) === null || _foreignAssets$find === void 0 ? void 0 : _foreignAssets$find.symbol) !== null && _foreignAssets$find$s !== void 0 ? _foreignAssets$find$s : null;
2638
+ var isEthAddress = ethers.isAddress(recipientAddress);
2639
+ var getAccountPayload = function getAccountPayload(allowNetwork) {
2640
+ if (isEthAddress) {
2641
+ return {
2642
+ AccountKey20: _objectSpread2({
2643
+ key: recipientAddress
2644
+ }, allowNetwork ? {
2645
+ network: 'any'
2646
+ } : {})
2647
+ };
2698
2648
  }
2699
- }
2700
- return null;
2701
- };
2702
-
2703
- var computeFeeFromDryRunPjs = function computeFeeFromDryRunPjs(dryRun, node, executionFee) {
2704
- // Extract delivery fees from emitted events
2705
- var deliveryFees = [];
2706
- var _iterator = _createForOfIteratorHelper(dryRun.Ok.emittedEvents),
2707
- _step;
2708
- try {
2709
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2710
- var e = _step.value;
2711
- var isXcmEvent = e.section === 'xcmPallet' || e.section === 'polkadotXcm' || e.section === 'cumulusXcm';
2712
- var isFeesPaid = e.method === 'FeesPaid';
2713
- if (isXcmEvent && isFeesPaid && e.data.fees) {
2714
- var _iterator2 = _createForOfIteratorHelper(e.data.fees),
2715
- _step2;
2716
- try {
2717
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2718
- var feeItem = _step2.value;
2719
- if (feeItem.fun.NonFungible) continue;
2720
- var plancks = BigInt(feeItem.fun.Fungible.replace(/,/g, ''));
2721
- var tokenSymbol = getMultiLocationTokenIdPjs(feeItem.id, node);
2722
- if (!tokenSymbol || !plancks) continue;
2723
- deliveryFees.push({
2724
- plancks: plancks,
2725
- tokenSymbol: tokenSymbol
2726
- });
2727
- }
2728
- } catch (err) {
2729
- _iterator2.e(err);
2730
- } finally {
2731
- _iterator2.f();
2732
- }
2649
+ return {
2650
+ AccountId32: _objectSpread2({
2651
+ id: api.accountToHex(recipientAddress)
2652
+ }, allowNetwork ? {
2653
+ network: 'any'
2654
+ } : {})
2655
+ };
2656
+ };
2657
+ if (scenario === 'ParaToRelay') {
2658
+ return {
2659
+ parents: pallet === 'XTokens' ? Parents.ONE : Parents.ZERO,
2660
+ interior: createX1Payload(version, {
2661
+ AccountId32: _objectSpread2({
2662
+ id: api.accountToHex(recipientAddress)
2663
+ }, version === Version.V1 ? {
2664
+ network: 'any'
2665
+ } : {})
2666
+ })
2667
+ };
2668
+ } else if (scenario === 'ParaToPara' && pallet === 'XTokens') {
2669
+ return {
2670
+ parents: Parents.ONE,
2671
+ interior: {
2672
+ X2: [{
2673
+ Parachain: paraId
2674
+ }, getAccountPayload(version === Version.V1 || version === Version.V2)]
2733
2675
  }
2734
- }
2735
- } catch (err) {
2736
- _iterator.e(err);
2737
- } finally {
2738
- _iterator.f();
2676
+ };
2677
+ } else if (scenario === 'ParaToPara' && pallet === 'PolkadotXcm') {
2678
+ return {
2679
+ parents: Parents.ZERO,
2680
+ interior: createX1Payload(version, getAccountPayload(version === Version.V1 || version === Version.V2))
2681
+ };
2682
+ } else {
2683
+ return {
2684
+ parents: Parents.ZERO,
2685
+ interior: createX1Payload(version, getAccountPayload(false))
2686
+ };
2739
2687
  }
2740
- var nativeAssetSymbol = getNativeAssetSymbol(node);
2741
- // Sum the fees that match the feeToken
2742
- var totalDeliveryFees = deliveryFees.filter(function (df) {
2743
- return df.tokenSymbol === nativeAssetSymbol;
2744
- }).reduce(function (acc, df) {
2745
- return acc + df.plancks;
2746
- }, 0n);
2747
- return totalDeliveryFees + executionFee;
2748
2688
  };
2749
2689
 
2750
- var resolveModuleError = function resolveModuleError(node, error) {
2751
- var palletDetails = getSupportedPalletsDetails(node).find(function (p) {
2752
- return p.index === Number(error.index);
2690
+ /**
2691
+ * This function transforms a multiLocation by removing the `Parachain` junction
2692
+ * if it exists and setting the `parents` to `0`.
2693
+ *
2694
+ * @param multiLocation - The multiLocation to transform
2695
+ * @returns The transformed multiLocation
2696
+ */
2697
+ var transformMultiLocation = function transformMultiLocation(multiLocation) {
2698
+ var newInterior;
2699
+ if (multiLocation.interior === 'Here') {
2700
+ newInterior = 'Here';
2701
+ } else {
2702
+ var junctions = Object.values(multiLocation.interior).flat().filter(function (junction) {
2703
+ return _typeof(junction) === 'object' && junction !== null;
2704
+ });
2705
+ var filteredJunctions = junctions.filter(function (junction) {
2706
+ return !('Parachain' in junction);
2707
+ });
2708
+ if (filteredJunctions.length === 0) {
2709
+ newInterior = 'Here';
2710
+ } else {
2711
+ newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
2712
+ }
2713
+ }
2714
+ return _objectSpread2(_objectSpread2({}, multiLocation), {}, {
2715
+ parents: Parents.ZERO,
2716
+ interior: newInterior
2753
2717
  });
2754
- if (!palletDetails) {
2755
- throw new Error("Pallet with index ".concat(error.index, " not found"));
2718
+ };
2719
+
2720
+ var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, origin, version, messageId) {
2721
+ var api = _ref.api,
2722
+ address = _ref.address,
2723
+ asset = _ref.asset,
2724
+ scenario = _ref.scenario,
2725
+ senderAddress = _ref.senderAddress,
2726
+ ahAddress = _ref.ahAddress;
2727
+ if (!isForeignAsset(asset)) {
2728
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
2756
2729
  }
2757
- // Use only the first byte of the error to get the error index
2758
- var errorIndex = Number(error.error.slice(0, 4));
2759
- var name = palletDetails.name;
2760
- if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
2761
- throw new Error("Pallet ".concat(name, " is not supported"));
2730
+ if (!asset.multiLocation) {
2731
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
2762
2732
  }
2763
- var failureReason = name === 'XTokens' ? Object.values(XTokensError)[errorIndex] : Object.values(PolkadotXcmError)[errorIndex];
2764
- if (!failureReason) {
2765
- throw new Error("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
2733
+ if (!senderAddress) {
2734
+ throw new InvalidParameterError("Please provide senderAddress");
2766
2735
  }
2767
- return failureReason;
2768
- };
2769
-
2770
- var generateAddressMultiLocationV4 = function generateAddressMultiLocationV4(api, address) {
2771
- var isMultiLocation = _typeof(address) === 'object';
2772
- if (isMultiLocation) {
2773
- return _defineProperty({}, Version.V4, address);
2736
+ if (isNodeEvm(origin) && !ahAddress) {
2737
+ throw new InvalidParameterError("Please provide ahAddress");
2774
2738
  }
2775
- var isEthAddress = ethers.isAddress(address);
2776
- return addXcmVersionHeader({
2777
- parents: Parents.ZERO,
2778
- interior: {
2779
- X1: [isEthAddress ? {
2780
- AccountKey20: {
2781
- key: address
2739
+ var ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
2740
+ if (!ethAsset) {
2741
+ throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
2742
+ }
2743
+ var interiorSb = ethAsset.symbol === 'ETH' ? {
2744
+ Here: null
2745
+ } : {
2746
+ X1: [{
2747
+ AccountKey20: {
2748
+ network: null,
2749
+ key: ethAsset.assetId
2750
+ }
2751
+ }]
2752
+ };
2753
+ return _defineProperty({}, version, [{
2754
+ SetAppendix: [{
2755
+ DepositAsset: {
2756
+ assets: {
2757
+ Wild: 'All'
2758
+ },
2759
+ beneficiary: createBeneficiaryMultiLocation({
2760
+ api: api,
2761
+ scenario: scenario,
2762
+ pallet: 'PolkadotXcm',
2763
+ recipientAddress: isNodeEvm(origin) ? ahAddress : senderAddress,
2764
+ version: version
2765
+ })
2766
+ }
2767
+ }]
2768
+ }, {
2769
+ InitiateReserveWithdraw: {
2770
+ assets: {
2771
+ Wild: {
2772
+ AllOf: {
2773
+ id: asset.multiLocation,
2774
+ fun: 'Fungible'
2775
+ }
2782
2776
  }
2783
- } : {
2784
- AccountId32: {
2785
- id: api.accountToHex(address),
2786
- network: null
2777
+ },
2778
+ reserve: {
2779
+ parents: Parents.TWO,
2780
+ interior: {
2781
+ X1: [ETHEREUM_JUNCTION]
2782
+ }
2783
+ },
2784
+ xcm: [{
2785
+ BuyExecution: {
2786
+ fees: {
2787
+ id: {
2788
+ parents: Parents.ZERO,
2789
+ interior: interiorSb
2790
+ },
2791
+ fun: {
2792
+ Fungible: 1n
2793
+ }
2794
+ },
2795
+ weight_limit: 'Unlimited'
2796
+ }
2797
+ }, {
2798
+ DepositAsset: {
2799
+ assets: {
2800
+ Wild: {
2801
+ AllCounted: 1
2802
+ }
2803
+ },
2804
+ beneficiary: {
2805
+ parents: Parents.ZERO,
2806
+ interior: {
2807
+ X1: [{
2808
+ AccountKey20: {
2809
+ network: null,
2810
+ key: address
2811
+ }
2812
+ }]
2813
+ }
2814
+ }
2787
2815
  }
2816
+ }, {
2817
+ SetTopic: messageId
2788
2818
  }]
2789
2819
  }
2790
- }, Version.V4);
2791
- };
2792
-
2793
- var getFees = function getFees(scenario) {
2794
- if (scenario === 'ParaToRelay') {
2795
- return 4600000000;
2796
- } else if (scenario === 'ParaToPara') {
2797
- return 399600000000;
2798
- }
2799
- throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
2820
+ }, {
2821
+ SetTopic: messageId
2822
+ }]);
2800
2823
  };
2801
2824
 
2802
- /**
2803
- * Retrieves the node instance for a given node.
2804
- *
2805
- * @param node - The node identifier.
2806
- * @returns The node instance
2807
- */
2808
- var getNode = function getNode(node) {
2809
- var nodeMap = nodes();
2810
- return nodeMap[node];
2811
- };
2825
+ var generateMessageId = /*#__PURE__*/function () {
2826
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, senderAddress, sourceParaId, tokenAddress, recipientAddress, amount) {
2827
+ var accountNextId, sourceAccountHex, entropy;
2828
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2829
+ while (1) switch (_context.prev = _context.next) {
2830
+ case 0:
2831
+ _context.next = 2;
2832
+ return api.getFromRpc('system', 'accountNextIndex', senderAddress);
2833
+ case 2:
2834
+ accountNextId = _context.sent;
2835
+ sourceAccountHex = api.accountToHex(senderAddress);
2836
+ entropy = new Uint8Array([].concat(_toConsumableArray(api.stringToUint8a(sourceParaId.toString())), _toConsumableArray(api.hexToUint8a(sourceAccountHex)), _toConsumableArray(api.stringToUint8a(accountNextId)), _toConsumableArray(api.hexToUint8a(tokenAddress)), _toConsumableArray(api.stringToUint8a(recipientAddress)), _toConsumableArray(api.stringToUint8a(amount.toString()))));
2837
+ return _context.abrupt("return", api.blake2AsHex(entropy));
2838
+ case 6:
2839
+ case "end":
2840
+ return _context.stop();
2841
+ }
2842
+ }, _callee);
2843
+ }));
2844
+ return function generateMessageId(_x, _x2, _x3, _x4, _x5, _x6) {
2845
+ return _ref.apply(this, arguments);
2846
+ };
2847
+ }();
2812
2848
 
2813
2849
  var resolveParaId = function resolveParaId(paraId, destination) {
2814
2850
  if (isTMultiLocation(destination) || isRelayChain(destination) || destination === 'Ethereum') {
@@ -2817,379 +2853,65 @@ var resolveParaId = function resolveParaId(paraId, destination) {
2817
2853
  return paraId !== null && paraId !== void 0 ? paraId : getParaId(destination);
2818
2854
  };
2819
2855
 
2820
- var validateAddress = function validateAddress(address, node) {
2821
- var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
2822
- var isEvm = isNodeEvm(node);
2823
- var isEthereumAddress = ethers.isAddress(address);
2824
- if (isEvm) {
2825
- if (!isEthereumAddress) {
2826
- throw new InvalidAddressError("".concat(isDestination ? 'Destination node' : 'Node', " is an EVM chain, but the address provided is not a valid Ethereum address."));
2827
- }
2828
- } else {
2829
- if (isEthereumAddress) {
2830
- throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "node is not an EVM chain."));
2831
- }
2832
- }
2856
+ var supportsXTokens = function supportsXTokens(obj) {
2857
+ return _typeof(obj) === 'object' && obj !== null && 'transferXTokens' in obj;
2833
2858
  };
2834
-
2835
- // Contains important call creation utils (Selection of fees,formating of header and more.. )
2836
- /**
2837
- * Determines the relay chain for a given node.
2838
- *
2839
- * @param node - The node for which to determine the relay chain.
2840
- * @returns 'Kusama' if the node's relay chain symbol is 'KSM'; otherwise, 'Polkadot'.
2841
- */
2842
- var determineRelayChain = function determineRelayChain(node) {
2843
- return getRelayChainSymbol(node) === 'KSM' ? 'Kusama' : 'Polkadot';
2859
+ var supportsXTransfer = function supportsXTransfer(obj) {
2860
+ return _typeof(obj) === 'object' && obj !== null && 'transferXTransfer' in obj;
2844
2861
  };
2845
-
2846
- var buildMultiLocation = function buildMultiLocation(_ref) {
2847
- var paraIdTo = _ref.paraIdTo,
2848
- asset = _ref.asset,
2849
- origin = _ref.origin,
2850
- destination = _ref.destination;
2851
- if (!isForeignAsset(asset)) {
2852
- if (_typeof(destination) === 'object') {
2853
- return destination;
2862
+ var supportsPolkadotXCM = function supportsPolkadotXCM(obj) {
2863
+ return _typeof(obj) === 'object' && obj !== null && 'transferPolkadotXCM' in obj;
2864
+ };
2865
+ var ParachainNode = /*#__PURE__*/function () {
2866
+ function ParachainNode(node, info, type, version) {
2867
+ _classCallCheck(this, ParachainNode);
2868
+ this._assetCheckEnabled = true;
2869
+ this._info = info;
2870
+ this._type = type;
2871
+ this._node = node;
2872
+ this._version = version;
2873
+ }
2874
+ return _createClass(ParachainNode, [{
2875
+ key: "info",
2876
+ get: function get() {
2877
+ return this._info;
2854
2878
  }
2855
- // ParaToRelay scenario
2856
- if (isRelayChain(destination)) {
2857
- return DOT_MULTILOCATION;
2879
+ }, {
2880
+ key: "type",
2881
+ get: function get() {
2882
+ return this._type;
2858
2883
  }
2859
- // If it is a native asset, search by symbol on AssetHub and use the multiLocation from there
2860
- var assetHubAsset = getOtherAssets(destination).find(function (ahAsset) {
2861
- var _ahAsset$symbol, _asset$symbol;
2862
- return ((_ahAsset$symbol = ahAsset.symbol) === null || _ahAsset$symbol === void 0 ? void 0 : _ahAsset$symbol.toLowerCase()) === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase());
2863
- });
2864
- if (assetHubAsset === undefined) {
2865
- throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " not found in AssetHub"));
2884
+ }, {
2885
+ key: "node",
2886
+ get: function get() {
2887
+ return this._node;
2866
2888
  }
2867
- if (assetHubAsset.multiLocation) {
2868
- return assetHubAsset.multiLocation;
2889
+ }, {
2890
+ key: "version",
2891
+ get: function get() {
2892
+ return this._version;
2869
2893
  }
2870
- throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " has no multiLocation"));
2871
- }
2872
- var createDefaultMultiLocation = function createDefaultMultiLocation(assetId) {
2873
- return {
2874
- parents: Parents.ONE,
2875
- interior: {
2876
- X3: [{
2877
- Parachain: paraIdTo
2878
- }, {
2879
- PalletInstance: '50'
2880
- }, {
2881
- GeneralIndex: BigInt(assetId)
2882
- }]
2883
- }
2884
- };
2885
- };
2886
- var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
2887
- if (isBifrostOrigin) {
2888
- return createDefaultMultiLocation(asset.assetId);
2889
- }
2890
- if (asset.multiLocation) {
2891
- return asset.multiLocation;
2892
- } else {
2893
- return createDefaultMultiLocation(asset.assetId);
2894
- }
2895
- };
2896
- var getModifiedCurrencySelection = function getModifiedCurrencySelection(version, input) {
2897
- var amount = input.asset.amount,
2898
- overriddenAsset = input.overriddenAsset;
2899
- if (overriddenAsset) {
2900
- return addXcmVersionHeader(maybeOverrideMultiAssets(version, amount, [], overriddenAsset), version);
2901
- }
2902
- var multiLocation = buildMultiLocation(input);
2903
- var multiAsset = createMultiAsset(version, amount, multiLocation);
2904
- return addXcmVersionHeader(multiAsset, version);
2905
- };
2906
-
2907
- var getCurrencySelection = function getCurrencySelection(input, useMultiAssets, currencySelection) {
2908
- var origin = input.origin;
2909
- var _getNode = getNode(origin),
2910
- version = _getNode.version;
2911
- if (useMultiAssets) {
2912
- return getModifiedCurrencySelection(version, input);
2913
- }
2914
- return currencySelection;
2915
- };
2916
-
2917
- var getXTokensParameters = function getXTokensParameters(isMultiAssetTransfer, currencySelection, addressSelection, amount, fees, overriddenAsset) {
2918
- if (isMultiAssetTransfer) {
2919
- var isOverridenMultiAssets = overriddenAsset && !isTMultiLocation(overriddenAsset);
2920
- var feeAssetIndex = isOverridenMultiAssets ? overriddenAsset.findIndex(function (asset) {
2921
- return asset.isFeeAsset;
2922
- }) : undefined;
2923
- return _objectSpread2(_objectSpread2(_defineProperty({}, isOverridenMultiAssets ? 'assets' : 'asset', currencySelection), isOverridenMultiAssets && {
2924
- fee_item: feeAssetIndex
2925
- }), {}, {
2926
- dest: addressSelection,
2927
- dest_weight_limit: fees
2928
- });
2929
- }
2930
- return {
2931
- currency_id: currencySelection,
2932
- amount: BigInt(amount),
2933
- dest: addressSelection,
2934
- dest_weight_limit: fees
2935
- };
2936
- };
2937
-
2938
- var XTokensTransferImpl = /*#__PURE__*/function () {
2939
- function XTokensTransferImpl() {
2940
- _classCallCheck(this, XTokensTransferImpl);
2941
- }
2942
- return _createClass(XTokensTransferImpl, null, [{
2943
- key: "transferXTokens",
2944
- value: function transferXTokens(input, currencySelection) {
2945
- var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Unlimited';
2946
- var api = input.api,
2947
- origin = input.origin,
2948
- asset = input.asset,
2949
- addressSelection = input.addressSelection,
2950
- destination = input.destination,
2951
- scenario = input.scenario,
2952
- overriddenAsset = input.overriddenAsset,
2953
- pallet = input.pallet,
2954
- method = input.method,
2955
- _input$useMultiAssetT = input.useMultiAssetTransfer,
2956
- useMultiAssetTransfer = _input$useMultiAssetT === void 0 ? false : _input$useMultiAssetT;
2957
- var isMultiLocationDestination = _typeof(destination) === 'object';
2958
- if (isMultiLocationDestination) {
2959
- throw new Error('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
2960
- }
2961
- var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
2962
- var isAssetHubDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
2963
- var isAstarOrShidenToRelay = scenario === 'ParaToRelay' && (origin === 'Astar' || origin === 'Shiden');
2964
- var isOverridenMultiAssets = overriddenAsset && !isTMultiLocation(overriddenAsset);
2965
- var shouldUseMultiasset = useMultiAssetTransfer || isAstarOrShidenToRelay || isAssetHubDest && !isBifrostOrigin || !!isOverridenMultiAssets;
2966
- var modifiedCurrencySelection = getCurrencySelection(input, shouldUseMultiasset, currencySelection);
2967
- var section = shouldUseMultiasset ? isOverridenMultiAssets ? 'transfer_multiassets' : 'transfer_multiasset' : 'transfer';
2968
- var parameters = getXTokensParameters(shouldUseMultiasset, modifiedCurrencySelection, addressSelection, asset.amount, fees, overriddenAsset);
2969
- var call = {
2970
- module: pallet !== null && pallet !== void 0 ? pallet : 'XTokens',
2971
- section: method !== null && method !== void 0 ? method : section,
2972
- parameters: parameters
2973
- };
2974
- return api.callTxMethod(call);
2894
+ }, {
2895
+ key: "assetCheckEnabled",
2896
+ get: function get() {
2897
+ return this._assetCheckEnabled;
2975
2898
  }
2976
- }]);
2977
- }();
2978
-
2979
- var getBridgeStatus = /*#__PURE__*/function () {
2980
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
2981
- return _regeneratorRuntime().wrap(function _callee$(_context) {
2982
- while (1) switch (_context.prev = _context.next) {
2983
- case 0:
2984
- _context.next = 2;
2985
- return api.init('BridgeHubPolkadot');
2986
- case 2:
2987
- _context.prev = 2;
2988
- _context.next = 5;
2989
- return api.getBridgeStatus();
2990
- case 5:
2991
- return _context.abrupt("return", _context.sent);
2992
- case 6:
2993
- _context.prev = 6;
2994
- _context.next = 9;
2995
- return api.disconnect();
2996
- case 9:
2997
- return _context.finish(6);
2998
- case 10:
2999
- case "end":
3000
- return _context.stop();
3001
- }
3002
- }, _callee, null, [[2,, 6, 10]]);
3003
- }));
3004
- return function getBridgeStatus(_x) {
3005
- return _ref.apply(this, arguments);
3006
- };
3007
- }();
3008
-
3009
- var createCustomXcmOnDest = function createCustomXcmOnDest(_ref, version, messageId) {
3010
- var api = _ref.api,
3011
- address = _ref.address,
3012
- asset = _ref.asset,
3013
- scenario = _ref.scenario,
3014
- senderAddress = _ref.senderAddress;
3015
- if (!isForeignAsset(asset)) {
3016
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3017
- }
3018
- if (!asset.multiLocation) {
3019
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
3020
- }
3021
- if (!senderAddress) {
3022
- throw new InvalidCurrencyError("Please provide senderAddress");
3023
- }
3024
- var ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
3025
- if (!ethAsset) {
3026
- throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(asset)));
3027
- }
3028
- var interiorSb = ethAsset.symbol === 'ETH' ? {
3029
- Here: null
3030
- } : {
3031
- X1: [{
3032
- AccountKey20: {
3033
- network: null,
3034
- key: ethAsset.assetId
3035
- }
3036
- }]
3037
- };
3038
- return _defineProperty({}, version, [{
3039
- SetAppendix: [{
3040
- DepositAsset: {
3041
- assets: {
3042
- Wild: 'All'
3043
- },
3044
- beneficiary: createBeneficiaryMultiLocation({
3045
- api: api,
3046
- scenario: scenario,
3047
- pallet: 'PolkadotXcm',
3048
- recipientAddress: senderAddress,
3049
- version: version
3050
- })
3051
- }
3052
- }]
3053
2899
  }, {
3054
- InitiateReserveWithdraw: {
3055
- assets: {
3056
- Wild: {
3057
- AllOf: {
3058
- id: asset.multiLocation,
3059
- fun: 'Fungible'
3060
- }
3061
- }
3062
- },
3063
- reserve: {
3064
- parents: Parents.TWO,
3065
- interior: {
3066
- X1: [ETHEREUM_JUNCTION]
3067
- }
3068
- },
3069
- xcm: [{
3070
- BuyExecution: {
3071
- fees: {
3072
- id: {
3073
- parents: Parents.ZERO,
3074
- interior: interiorSb
3075
- },
3076
- fun: {
3077
- Fungible: 1n
3078
- }
3079
- },
3080
- weight_limit: 'Unlimited'
3081
- }
3082
- }, {
3083
- DepositAsset: {
3084
- assets: {
3085
- Wild: {
3086
- AllCounted: 1
3087
- }
3088
- },
3089
- beneficiary: {
3090
- parents: Parents.ZERO,
3091
- interior: {
3092
- X1: [{
3093
- AccountKey20: {
3094
- network: null,
3095
- key: address
3096
- }
3097
- }]
3098
- }
3099
- }
3100
- }
3101
- }, {
3102
- SetTopic: messageId
3103
- }]
3104
- }
3105
- }, {
3106
- SetTopic: messageId
3107
- }]);
3108
- };
3109
-
3110
- var generateMessageId = /*#__PURE__*/function () {
3111
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, senderAddress, sourceParaId, tokenAddress, recipientAddress, amount) {
3112
- var accountNextId, sourceAccountHex, entropy;
3113
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3114
- while (1) switch (_context.prev = _context.next) {
3115
- case 0:
3116
- _context.next = 2;
3117
- return api.getFromRpc('system', 'accountNextIndex', senderAddress);
3118
- case 2:
3119
- accountNextId = _context.sent;
3120
- sourceAccountHex = api.accountToHex(senderAddress);
3121
- entropy = new Uint8Array([].concat(_toConsumableArray(api.stringToUint8a(sourceParaId.toString())), _toConsumableArray(api.hexToUint8a(sourceAccountHex)), _toConsumableArray(api.stringToUint8a(accountNextId)), _toConsumableArray(api.hexToUint8a(tokenAddress)), _toConsumableArray(api.stringToUint8a(recipientAddress)), _toConsumableArray(api.stringToUint8a(amount.toString()))));
3122
- return _context.abrupt("return", api.blake2AsHex(entropy));
3123
- case 6:
3124
- case "end":
3125
- return _context.stop();
3126
- }
3127
- }, _callee);
3128
- }));
3129
- return function generateMessageId(_x, _x2, _x3, _x4, _x5, _x6) {
3130
- return _ref.apply(this, arguments);
3131
- };
3132
- }();
3133
-
3134
- var supportsXTokens = function supportsXTokens(obj) {
3135
- return _typeof(obj) === 'object' && obj !== null && 'transferXTokens' in obj;
3136
- };
3137
- var supportsXTransfer = function supportsXTransfer(obj) {
3138
- return _typeof(obj) === 'object' && obj !== null && 'transferXTransfer' in obj;
3139
- };
3140
- var supportsPolkadotXCM = function supportsPolkadotXCM(obj) {
3141
- return _typeof(obj) === 'object' && obj !== null && 'transferPolkadotXCM' in obj;
3142
- };
3143
- var ParachainNode = /*#__PURE__*/function () {
3144
- function ParachainNode(node, info, type, version) {
3145
- _classCallCheck(this, ParachainNode);
3146
- this._assetCheckEnabled = true;
3147
- this._info = info;
3148
- this._type = type;
3149
- this._node = node;
3150
- this._version = version;
3151
- }
3152
- return _createClass(ParachainNode, [{
3153
- key: "info",
3154
- get: function get() {
3155
- return this._info;
3156
- }
3157
- }, {
3158
- key: "type",
3159
- get: function get() {
3160
- return this._type;
3161
- }
3162
- }, {
3163
- key: "node",
3164
- get: function get() {
3165
- return this._node;
3166
- }
3167
- }, {
3168
- key: "version",
3169
- get: function get() {
3170
- return this._version;
3171
- }
3172
- }, {
3173
- key: "assetCheckEnabled",
3174
- get: function get() {
3175
- return this._assetCheckEnabled;
3176
- }
3177
- }, {
3178
- key: "canUseXTokens",
3179
- value: function canUseXTokens(_ref) {
3180
- var asset = _ref.asset;
3181
- var isEthAsset = asset.multiLocation && findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
3182
- return !isEthAsset;
2900
+ key: "canUseXTokens",
2901
+ value: function canUseXTokens(_ref) {
2902
+ var asset = _ref.asset;
2903
+ var isEthAsset = asset.multiLocation && findAssetByMultiLocation(getOtherAssets('Ethereum'), asset.multiLocation);
2904
+ return !isEthAsset;
3183
2905
  }
3184
2906
  }, {
3185
2907
  key: "transfer",
3186
2908
  value: function () {
3187
2909
  var _transfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3188
- var api, asset, feeAsset, address, destination, paraIdTo, overriddenAsset, version, senderAddress, pallet, method, isRelayDestination, scenario, paraId, versionOrDefault, isLocalTransfer, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input, _options, isEthAsset, isAHPOrigin, isAHPDest, isEthDest;
2910
+ var api, asset, feeAsset, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, isRelayDestination, scenario, paraId, versionOrDefault, isLocalTransfer, isBifrostOrigin, isAssetHubDest, shouldUseMultiasset, input, _options, isEthAsset, isAHPOrigin, isAHPDest, isEthDest;
3189
2911
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3190
2912
  while (1) switch (_context.prev = _context.next) {
3191
2913
  case 0:
3192
- api = options.api, asset = options.asset, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, overriddenAsset = options.overriddenAsset, version = options.version, senderAddress = options.senderAddress, pallet = options.pallet, method = options.method;
2914
+ api = options.api, asset = options.asset, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, overriddenAsset = options.overriddenAsset, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method;
3193
2915
  isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
3194
2916
  scenario = isRelayDestination ? 'ParaToRelay' : 'ParaToPara';
3195
2917
  paraId = resolveParaId(paraIdTo, destination);
@@ -3283,6 +3005,7 @@ var ParachainNode = /*#__PURE__*/function () {
3283
3005
  paraIdTo: paraId,
3284
3006
  version: version,
3285
3007
  senderAddress: senderAddress,
3008
+ ahAddress: ahAddress,
3286
3009
  pallet: pallet,
3287
3010
  method: method
3288
3011
  }; // Handle common cases
@@ -3455,17 +3178,17 @@ var ParachainNode = /*#__PURE__*/function () {
3455
3178
  return Builder(api.clone()).from('AssetHubPolkadot').to(destination).currency({
3456
3179
  symbol: 'DOT',
3457
3180
  amount: AH_EXECUTION_FEE_PADDED
3458
- }).address(address).dryRun(senderAddress);
3181
+ }).address(address).senderAddress(senderAddress).dryRun();
3459
3182
  case 12:
3460
3183
  dryRunResult = _context2.sent;
3461
- if (dryRunResult.success) {
3184
+ if (dryRunResult.origin.success) {
3462
3185
  _context2.next = 15;
3463
3186
  break;
3464
3187
  }
3465
- throw new DryRunFailedError(dryRunResult.failureReason);
3188
+ throw new DryRunFailedError(dryRunResult.origin.failureReason);
3466
3189
  case 15:
3467
3190
  // Pad fee by 50%
3468
- dryRunFeePadded = BigInt(dryRunResult.fee) * BigInt(3) / BigInt(2);
3191
+ dryRunFeePadded = BigInt(dryRunResult.origin.fee) * BigInt(3) / BigInt(2);
3469
3192
  destWithHeader = createVersionedDestination(scenario, version, destination, paraIdTo);
3470
3193
  _extractVersionFromHe = extractVersionFromHeader(destWithHeader), _extractVersionFromHe2 = _slicedToArray(_extractVersionFromHe, 2), _extractVersionFromHe2[0], dest = _extractVersionFromHe2[1];
3471
3194
  call = {
@@ -3649,7 +3372,7 @@ var ParachainNode = /*#__PURE__*/function () {
3649
3372
  version: version
3650
3373
  })
3651
3374
  }
3652
- }], version) : createCustomXcmOnDest(input, version, messageId),
3375
+ }], version) : createCustomXcmOnDest(input, this.node, version, messageId),
3653
3376
  weight_limit: 'Unlimited'
3654
3377
  }
3655
3378
  };
@@ -3956,6 +3679,12 @@ var AssetHubKusama = /*#__PURE__*/function (_ParachainNode) {
3956
3679
  }]);
3957
3680
  }(ParachainNode);
3958
3681
 
3682
+ var createVersionedBeneficiary = function createVersionedBeneficiary(options) {
3683
+ var version = options.version;
3684
+ var multiLocation = createBeneficiaryMultiLocation(options);
3685
+ return addXcmVersionHeader(multiLocation, version);
3686
+ };
3687
+
3959
3688
  var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
3960
3689
  var api = input.api,
3961
3690
  _input$version = input.version,
@@ -4055,6 +3784,44 @@ var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
4055
3784
  return api.callTxMethod(call);
4056
3785
  };
4057
3786
 
3787
+ var generateAddressMultiLocationV4 = function generateAddressMultiLocationV4(api, address) {
3788
+ var isMultiLocation = _typeof(address) === 'object';
3789
+ if (isMultiLocation) {
3790
+ return _defineProperty({}, Version.V4, address);
3791
+ }
3792
+ var isEthAddress = ethers.isAddress(address);
3793
+ return addXcmVersionHeader({
3794
+ parents: Parents.ZERO,
3795
+ interior: {
3796
+ X1: [isEthAddress ? {
3797
+ AccountKey20: {
3798
+ key: address
3799
+ }
3800
+ } : {
3801
+ AccountId32: {
3802
+ id: api.accountToHex(address),
3803
+ network: null
3804
+ }
3805
+ }]
3806
+ }
3807
+ }, Version.V4);
3808
+ };
3809
+
3810
+ var validateAddress = function validateAddress(address, node) {
3811
+ var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3812
+ var isEvm = isNodeEvm(node);
3813
+ var isEthereumAddress = ethers.isAddress(address);
3814
+ if (isEvm) {
3815
+ if (!isEthereumAddress) {
3816
+ throw new InvalidAddressError("".concat(isDestination ? 'Destination node' : 'Node', " is an EVM chain, but the address provided is not a valid Ethereum address."));
3817
+ }
3818
+ } else {
3819
+ if (isEthereumAddress) {
3820
+ throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "node is not an EVM chain."));
3821
+ }
3822
+ }
3823
+ };
3824
+
4058
3825
  var createCustomXcmToBifrost = function createCustomXcmToBifrost(_ref, version) {
4059
3826
  var api = _ref.api,
4060
3827
  address = _ref.address,
@@ -5810,10 +5577,14 @@ var Moonbeam = /*#__PURE__*/function (_ParachainNode) {
5810
5577
  }, {
5811
5578
  key: "transferPolkadotXCM",
5812
5579
  value: function transferPolkadotXCM(input) {
5813
- var asset = input.asset,
5580
+ var destination = input.destination,
5581
+ asset = input.asset,
5814
5582
  scenario = input.scenario,
5815
5583
  _input$version = input.version,
5816
5584
  version = _input$version === void 0 ? this.version : _input$version;
5585
+ if (destination === 'Ethereum') {
5586
+ return this.transferToEthereum(input);
5587
+ }
5817
5588
  var multiLocation = this.getMultiLocation(asset, scenario);
5818
5589
  return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(_objectSpread2(_objectSpread2({}, input), {}, {
5819
5590
  currencySelection: createVersionedMultiAssets(version, asset.amount, multiLocation)
@@ -6545,7 +6316,618 @@ var nodes = function nodes() {
6545
6316
  Peaq: new Peaq(),
6546
6317
  Polimec: new Polimec()
6547
6318
  };
6548
- };
6319
+ };
6320
+
6321
+ /**
6322
+ * Retrieves the parachain ID for a specified node.
6323
+ *
6324
+ * @param node - The node for which to get the paraId.
6325
+ * @returns The parachain ID of the node.
6326
+ */
6327
+ var getParaId = function getParaId(node) {
6328
+ if (node === 'Ethereum') {
6329
+ return ETH_PARA_ID;
6330
+ }
6331
+ return getNodeConfig(node).paraId;
6332
+ };
6333
+
6334
+ var shuffleArray = function shuffleArray(array) {
6335
+ var copy = _toConsumableArray(array);
6336
+ for (var i = copy.length - 1; i > 0; i--) {
6337
+ var j = Math.floor(Math.random() * (i + 1));
6338
+ var _ref = [copy[j], copy[i]];
6339
+ copy[i] = _ref[0];
6340
+ copy[j] = _ref[1];
6341
+ }
6342
+ return copy;
6343
+ };
6344
+
6345
+ var shuffleWsProviders = function shuffleWsProviders(node, wsProviders) {
6346
+ var ALLOWED_NODES = ['Hydration', 'Acala'];
6347
+ if (ALLOWED_NODES.includes(node)) {
6348
+ return shuffleArray(wsProviders);
6349
+ }
6350
+ return wsProviders;
6351
+ };
6352
+
6353
+ var createApiInstanceForNode = /*#__PURE__*/function () {
6354
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node) {
6355
+ var wsUrl, resolvedWsUrl;
6356
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6357
+ while (1) switch (_context.prev = _context.next) {
6358
+ case 0:
6359
+ wsUrl = getNodeProviders(node);
6360
+ resolvedWsUrl = Array.isArray(wsUrl) ? shuffleWsProviders(node, wsUrl) : wsUrl;
6361
+ return _context.abrupt("return", api.createApiInstance(resolvedWsUrl));
6362
+ case 3:
6363
+ case "end":
6364
+ return _context.stop();
6365
+ }
6366
+ }, _callee);
6367
+ }));
6368
+ return function createApiInstanceForNode(_x, _x2) {
6369
+ return _ref.apply(this, arguments);
6370
+ };
6371
+ }();
6372
+
6373
+ var getMultiLocationTokenId = function getMultiLocationTokenId(location, node) {
6374
+ if (location.interior.type === 'Here') {
6375
+ // native token
6376
+ return getNativeAssetSymbol(node);
6377
+ }
6378
+ var foreignAssets = getOtherAssets(node);
6379
+ if (location.interior.type === 'X2') {
6380
+ if (location.interior.value[0].type === 'PalletInstance' && location.interior.value[0].value === 50 && location.interior.value[1].type === 'GeneralIndex') {
6381
+ var _foreignAssets$find$a, _foreignAssets$find;
6382
+ var assetId = location.interior.value[1].value;
6383
+ return (_foreignAssets$find$a = (_foreignAssets$find = foreignAssets.find(function (asset) {
6384
+ return asset.assetId === String(assetId);
6385
+ })) === null || _foreignAssets$find === void 0 ? void 0 : _foreignAssets$find.assetId) !== null && _foreignAssets$find$a !== void 0 ? _foreignAssets$find$a : null;
6386
+ }
6387
+ }
6388
+ return null;
6389
+ };
6390
+
6391
+ var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, executionFee) {
6392
+ // Extract delivery fees from emitted events
6393
+ var deliveryFees = [];
6394
+ var _iterator = _createForOfIteratorHelper(dryRun.value.emitted_events),
6395
+ _step;
6396
+ try {
6397
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6398
+ var e = _step.value;
6399
+ var isXcmEvent = e.type === 'XcmPallet' || e.type === 'PolkadotXcm' || e.type === 'CumulusXcm';
6400
+ var isFeesPaid = e.value.type === 'FeesPaid';
6401
+ if (isXcmEvent && isFeesPaid && e.value.value.fees) {
6402
+ var _iterator2 = _createForOfIteratorHelper(e.value.value.fees),
6403
+ _step2;
6404
+ try {
6405
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6406
+ var feeItem = _step2.value;
6407
+ if (feeItem.fun.type === 'NonFungible') continue;
6408
+ var plancks = feeItem.fun.value;
6409
+ var tokenSymbol = getMultiLocationTokenId(feeItem.id, node);
6410
+ if (!tokenSymbol || !plancks) continue;
6411
+ deliveryFees.push({
6412
+ plancks: plancks,
6413
+ tokenSymbol: tokenSymbol
6414
+ });
6415
+ }
6416
+ } catch (err) {
6417
+ _iterator2.e(err);
6418
+ } finally {
6419
+ _iterator2.f();
6420
+ }
6421
+ }
6422
+ }
6423
+ } catch (err) {
6424
+ _iterator.e(err);
6425
+ } finally {
6426
+ _iterator.f();
6427
+ }
6428
+ var nativeAssetSymbol = getNativeAssetSymbol(node);
6429
+ // Sum the fees that match the feeToken
6430
+ var totalDeliveryFees = deliveryFees.filter(function (df) {
6431
+ return df.tokenSymbol === nativeAssetSymbol;
6432
+ }).reduce(function (acc, df) {
6433
+ return acc + df.plancks;
6434
+ }, 0n);
6435
+ return totalDeliveryFees + executionFee;
6436
+ };
6437
+
6438
+ var getMultiLocationTokenIdPjs = function getMultiLocationTokenIdPjs(location, node) {
6439
+ if (location.interior === 'Here') {
6440
+ // native token
6441
+ return getNativeAssetSymbol(node);
6442
+ }
6443
+ var foreignAssets = getOtherAssets(node);
6444
+ if (Object.keys(location.interior)[0] === 'X2') {
6445
+ var junctions = Object.values(location.interior)[0];
6446
+ if (Object.keys(junctions[0])[0] === 'PalletInstance' && junctions[0].PalletInstance === '50' && Object.keys(junctions[1])[0] === 'GeneralIndex') {
6447
+ var _foreignAssets$find$s, _foreignAssets$find;
6448
+ var assetId = junctions[1].GeneralIndex;
6449
+ return (_foreignAssets$find$s = (_foreignAssets$find = foreignAssets.find(function (asset) {
6450
+ return asset.assetId === String(assetId);
6451
+ })) === null || _foreignAssets$find === void 0 ? void 0 : _foreignAssets$find.symbol) !== null && _foreignAssets$find$s !== void 0 ? _foreignAssets$find$s : null;
6452
+ }
6453
+ }
6454
+ return null;
6455
+ };
6456
+
6457
+ var computeFeeFromDryRunPjs = function computeFeeFromDryRunPjs(dryRun, node, executionFee) {
6458
+ // Extract delivery fees from emitted events
6459
+ var deliveryFees = [];
6460
+ var _iterator = _createForOfIteratorHelper(dryRun.Ok.emittedEvents),
6461
+ _step;
6462
+ try {
6463
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6464
+ var e = _step.value;
6465
+ var isXcmEvent = e.section === 'xcmPallet' || e.section === 'polkadotXcm' || e.section === 'cumulusXcm';
6466
+ var isFeesPaid = e.method === 'FeesPaid';
6467
+ if (isXcmEvent && isFeesPaid && e.data.fees) {
6468
+ var _iterator2 = _createForOfIteratorHelper(e.data.fees),
6469
+ _step2;
6470
+ try {
6471
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6472
+ var feeItem = _step2.value;
6473
+ if (feeItem.fun.NonFungible) continue;
6474
+ var plancks = BigInt(feeItem.fun.Fungible.replace(/,/g, ''));
6475
+ var tokenSymbol = getMultiLocationTokenIdPjs(feeItem.id, node);
6476
+ if (!tokenSymbol || !plancks) continue;
6477
+ deliveryFees.push({
6478
+ plancks: plancks,
6479
+ tokenSymbol: tokenSymbol
6480
+ });
6481
+ }
6482
+ } catch (err) {
6483
+ _iterator2.e(err);
6484
+ } finally {
6485
+ _iterator2.f();
6486
+ }
6487
+ }
6488
+ }
6489
+ } catch (err) {
6490
+ _iterator.e(err);
6491
+ } finally {
6492
+ _iterator.f();
6493
+ }
6494
+ var nativeAssetSymbol = getNativeAssetSymbol(node);
6495
+ // Sum the fees that match the feeToken
6496
+ var totalDeliveryFees = deliveryFees.filter(function (df) {
6497
+ return df.tokenSymbol === nativeAssetSymbol;
6498
+ }).reduce(function (acc, df) {
6499
+ return acc + df.plancks;
6500
+ }, 0n);
6501
+ return totalDeliveryFees + executionFee;
6502
+ };
6503
+
6504
+ var resolveModuleError = function resolveModuleError(node, error) {
6505
+ var palletDetails = getSupportedPalletsDetails(node).find(function (p) {
6506
+ return p.index === Number(error.index);
6507
+ });
6508
+ if (!palletDetails) {
6509
+ throw new Error("Pallet with index ".concat(error.index, " not found"));
6510
+ }
6511
+ // Use only the first byte of the error to get the error index
6512
+ var errorIndex = Number(error.error.slice(0, 4));
6513
+ var name = palletDetails.name;
6514
+ if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
6515
+ throw new Error("Pallet ".concat(name, " is not supported"));
6516
+ }
6517
+ var failureReason = name === 'XTokens' ? Object.values(XTokensError)[errorIndex] : Object.values(PolkadotXcmError)[errorIndex];
6518
+ if (!failureReason) {
6519
+ throw new Error("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
6520
+ }
6521
+ return failureReason;
6522
+ };
6523
+
6524
+ var getFees = function getFees(scenario) {
6525
+ if (scenario === 'ParaToRelay') {
6526
+ return 4600000000;
6527
+ } else if (scenario === 'ParaToPara') {
6528
+ return 399600000000;
6529
+ }
6530
+ throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
6531
+ };
6532
+
6533
+ /**
6534
+ * Retrieves the node instance for a given node.
6535
+ *
6536
+ * @param node - The node identifier.
6537
+ * @returns The node instance
6538
+ */
6539
+ var getNode = function getNode(node) {
6540
+ var nodeMap = nodes();
6541
+ return nodeMap[node];
6542
+ };
6543
+
6544
+ // Contains important call creation utils (Selection of fees,formating of header and more.. )
6545
+ /**
6546
+ * Determines the relay chain for a given node.
6547
+ *
6548
+ * @param node - The node for which to determine the relay chain.
6549
+ * @returns 'Kusama' if the node's relay chain symbol is 'KSM'; otherwise, 'Polkadot'.
6550
+ */
6551
+ var determineRelayChain = function determineRelayChain(node) {
6552
+ return getRelayChainSymbol(node) === 'KSM' ? 'Kusama' : 'Polkadot';
6553
+ };
6554
+
6555
+ /**
6556
+ * Retrieves the node name corresponding to a specified parachain ID.
6557
+ *
6558
+ * @param paraId - The parachain ID.
6559
+ * @returns The node name if found; otherwise, null.
6560
+ */
6561
+ var getTNode = function getTNode(paraId, ecosystem) {
6562
+ var _NODE_NAMES_DOT_KSM$f;
6563
+ if (paraId === 0) {
6564
+ return ecosystem === 'polkadot' ? 'Polkadot' : 'Kusama';
6565
+ }
6566
+ if (paraId === 1) {
6567
+ return 'Ethereum';
6568
+ }
6569
+ return (_NODE_NAMES_DOT_KSM$f = NODE_NAMES_DOT_KSM.find(function (nodeName) {
6570
+ return getNode(nodeName).type === ecosystem && getParaId(nodeName) === paraId;
6571
+ })) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
6572
+ };
6573
+
6574
+ var isAssetHub = function isAssetHub(chain) {
6575
+ return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
6576
+ };
6577
+ var isBridgeHub = function isBridgeHub(chain) {
6578
+ return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
6579
+ };
6580
+ var isPeople = function isPeople(chain) {
6581
+ return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
6582
+ };
6583
+ var isSystemPara = function isSystemPara(chain) {
6584
+ return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
6585
+ };
6586
+ var mul = function mul(v, num) {
6587
+ var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
6588
+ return v * num / den;
6589
+ };
6590
+ var padFee = function padFee(raw, origin, dest, side) {
6591
+ var relayOrigin = isRelayChain(origin);
6592
+ var relayDest = isRelayChain(dest);
6593
+ var sysParaOrigin = isSystemPara(origin);
6594
+ var sysParaDest = isSystemPara(dest);
6595
+ var relayToPara = relayOrigin && !relayDest;
6596
+ var sysParaToPara = sysParaOrigin && !sysParaDest;
6597
+ var paraToPara = !relayOrigin && !sysParaOrigin;
6598
+ if (sysParaToPara) return raw * 40n;
6599
+ if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
6600
+ if (paraToPara) return mul(raw, 130n, 100n);
6601
+ // apply default 30% padding
6602
+ return mul(raw, 130n, 100n);
6603
+ };
6604
+
6605
+ var createOriginLocation = function createOriginLocation(origin, destination) {
6606
+ if (isRelayChain(origin)) return DOT_MULTILOCATION;
6607
+ return {
6608
+ parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
6609
+ interior: {
6610
+ X1: [{
6611
+ Parachain: getParaId(origin)
6612
+ }]
6613
+ }
6614
+ };
6615
+ };
6616
+ var getFeeForDestNode = /*#__PURE__*/function () {
6617
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
6618
+ var api, forwardedXcms, origin, destination, address, senderAddress, currency, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
6619
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6620
+ while (1) switch (_context2.prev = _context2.next) {
6621
+ case 0:
6622
+ api = _ref.api, forwardedXcms = _ref.forwardedXcms, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, currency = _ref.currency, disableFallback = _ref.disableFallback;
6623
+ calcPaymentInfoFee = /*#__PURE__*/function () {
6624
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
6625
+ var originAsset, currencyInput, tx, rawFee;
6626
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6627
+ while (1) switch (_context.prev = _context.next) {
6628
+ case 0:
6629
+ if (!('multiasset' in currency)) {
6630
+ _context.next = 2;
6631
+ break;
6632
+ }
6633
+ throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
6634
+ case 2:
6635
+ originAsset = findAsset(origin, currency, destination);
6636
+ if (originAsset) {
6637
+ _context.next = 5;
6638
+ break;
6639
+ }
6640
+ throw new InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
6641
+ case 5:
6642
+ currencyInput = originAsset.multiLocation ? {
6643
+ multilocation: originAsset.multiLocation
6644
+ } : {
6645
+ symbol: originAsset.symbol
6646
+ };
6647
+ _context.next = 8;
6648
+ return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
6649
+ amount: currency.amount
6650
+ })).build();
6651
+ case 8:
6652
+ tx = _context.sent;
6653
+ _context.next = 11;
6654
+ return api.calculateTransactionFee(tx, address);
6655
+ case 11:
6656
+ rawFee = _context.sent;
6657
+ return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
6658
+ case 13:
6659
+ case "end":
6660
+ return _context.stop();
6661
+ }
6662
+ }, _callee);
6663
+ }));
6664
+ return function calcPaymentInfoFee() {
6665
+ return _ref3.apply(this, arguments);
6666
+ };
6667
+ }();
6668
+ if (!(!hasDryRunSupport(destination) || !forwardedXcms)) {
6669
+ _context2.next = 7;
6670
+ break;
6671
+ }
6672
+ _context2.next = 5;
6673
+ return calcPaymentInfoFee();
6674
+ case 5:
6675
+ _context2.t0 = _context2.sent;
6676
+ return _context2.abrupt("return", {
6677
+ fee: _context2.t0,
6678
+ feeType: 'paymentInfo'
6679
+ });
6680
+ case 7:
6681
+ _context2.next = 9;
6682
+ return api.getDryRunXcm({
6683
+ originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), Version.V4),
6684
+ xcm: forwardedXcms[1][0],
6685
+ node: destination,
6686
+ origin: origin
6687
+ });
6688
+ case 9:
6689
+ dryRunResult = _context2.sent;
6690
+ if (dryRunResult.success) {
6691
+ _context2.next = 18;
6692
+ break;
6693
+ }
6694
+ if (!disableFallback) {
6695
+ _context2.next = 13;
6696
+ break;
6697
+ }
6698
+ return _context2.abrupt("return", {
6699
+ dryRunError: dryRunResult.failureReason
6700
+ });
6701
+ case 13:
6702
+ _context2.next = 15;
6703
+ return calcPaymentInfoFee();
6704
+ case 15:
6705
+ _context2.t1 = _context2.sent;
6706
+ _context2.t2 = dryRunResult.failureReason;
6707
+ return _context2.abrupt("return", {
6708
+ fee: _context2.t1,
6709
+ feeType: 'paymentInfo',
6710
+ dryRunError: _context2.t2
6711
+ });
6712
+ case 18:
6713
+ fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
6714
+ return _context2.abrupt("return", {
6715
+ fee: fee,
6716
+ feeType: 'dryRun',
6717
+ forwardedXcms: newForwardedXcms,
6718
+ destParaId: destParaId
6719
+ });
6720
+ case 20:
6721
+ case "end":
6722
+ return _context2.stop();
6723
+ }
6724
+ }, _callee2);
6725
+ }));
6726
+ return function getFeeForDestNode(_x) {
6727
+ return _ref2.apply(this, arguments);
6728
+ };
6729
+ }();
6730
+
6731
+ var dryRunInternal = /*#__PURE__*/function () {
6732
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
6733
+ var _findAsset, _intermediateFees$ass, _intermediateFees$bri, _destinationDryRun;
6734
+ var origin, destination, currency, api, tx, senderAddress, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
6735
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6736
+ while (1) switch (_context.prev = _context.next) {
6737
+ case 0:
6738
+ origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress;
6739
+ asset = (_findAsset = findAsset(origin, currency, destination)) !== null && _findAsset !== void 0 ? _findAsset : origin === 'AssetHubPolkadot' ? findAsset('Ethereum', currency, null) : null;
6740
+ if (asset) {
6741
+ _context.next = 4;
6742
+ break;
6743
+ }
6744
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(currency), " not found on ").concat(origin));
6745
+ case 4:
6746
+ _context.next = 6;
6747
+ return api.getDryRunCall({
6748
+ tx: tx,
6749
+ node: origin,
6750
+ address: senderAddress
6751
+ });
6752
+ case 6:
6753
+ originDryRun = _context.sent;
6754
+ if (originDryRun.success) {
6755
+ _context.next = 9;
6756
+ break;
6757
+ }
6758
+ return _context.abrupt("return", {
6759
+ origin: originDryRun
6760
+ });
6761
+ case 9:
6762
+ initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
6763
+ currentOrigin = origin;
6764
+ forwardedXcms = initialForwardedXcms;
6765
+ nextParaId = initialDestParaId;
6766
+ intermediateFees = {};
6767
+ case 14:
6768
+ if (!(Array.isArray(forwardedXcms) && forwardedXcms.length && forwardedXcms[1].length && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
6769
+ _context.next = 41;
6770
+ break;
6771
+ }
6772
+ nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
6773
+ if (nextChain) {
6774
+ _context.next = 18;
6775
+ break;
6776
+ }
6777
+ throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
6778
+ case 18:
6779
+ hopApi = api.clone();
6780
+ _context.prev = 19;
6781
+ if (hasDryRunSupport(nextChain)) {
6782
+ _context.next = 23;
6783
+ break;
6784
+ }
6785
+ if (nextChain === destination) {
6786
+ destinationDryRun = {
6787
+ success: false,
6788
+ failureReason: "DryRunApi is not available on node ".concat(nextChain)
6789
+ };
6790
+ }
6791
+ return _context.abrupt("break", 41);
6792
+ case 23:
6793
+ _context.next = 25;
6794
+ return hopApi.init(nextChain);
6795
+ case 25:
6796
+ _context.next = 27;
6797
+ return hopApi.getDryRunXcm({
6798
+ originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), Version.V4),
6799
+ xcm: forwardedXcms[1][0],
6800
+ node: nextChain,
6801
+ origin: currentOrigin
6802
+ });
6803
+ case 27:
6804
+ hopDryRun = _context.sent;
6805
+ if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
6806
+ destinationDryRun = hopDryRun;
6807
+ } else if (nextChain === 'AssetHubPolkadot') {
6808
+ intermediateFees.assetHub = hopDryRun;
6809
+ } else if (nextChain === 'BridgeHubPolkadot') {
6810
+ intermediateFees.bridgeHub = hopDryRun;
6811
+ }
6812
+ if (hopDryRun.success) {
6813
+ _context.next = 31;
6814
+ break;
6815
+ }
6816
+ return _context.abrupt("break", 41);
6817
+ case 31:
6818
+ newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
6819
+ forwardedXcms = newXcms;
6820
+ nextParaId = destParaId;
6821
+ currentOrigin = nextChain;
6822
+ case 35:
6823
+ _context.prev = 35;
6824
+ _context.next = 38;
6825
+ return hopApi.disconnect();
6826
+ case 38:
6827
+ return _context.finish(35);
6828
+ case 39:
6829
+ _context.next = 14;
6830
+ break;
6831
+ case 41:
6832
+ return _context.abrupt("return", {
6833
+ origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
6834
+ currency: getNativeAssetSymbol(origin)
6835
+ }) : originDryRun,
6836
+ assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
6837
+ currency: getNativeAssetSymbol('AssetHubPolkadot')
6838
+ }) : intermediateFees.assetHub,
6839
+ bridgeHub: (_intermediateFees$bri = intermediateFees.bridgeHub) !== null && _intermediateFees$bri !== void 0 && _intermediateFees$bri.success ? _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
6840
+ currency: getNativeAssetSymbol('BridgeHubPolkadot')
6841
+ }) : intermediateFees.bridgeHub,
6842
+ destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
6843
+ currency: asset.symbol
6844
+ }) : destinationDryRun
6845
+ });
6846
+ case 42:
6847
+ case "end":
6848
+ return _context.stop();
6849
+ }
6850
+ }, _callee, null, [[19,, 35, 39]]);
6851
+ }));
6852
+ return function dryRunInternal(_x) {
6853
+ return _ref.apply(this, arguments);
6854
+ };
6855
+ }();
6856
+
6857
+ var dryRun = /*#__PURE__*/function () {
6858
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
6859
+ var api, senderAddress, origin;
6860
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6861
+ while (1) switch (_context.prev = _context.next) {
6862
+ case 0:
6863
+ api = options.api, senderAddress = options.senderAddress, origin = options.origin;
6864
+ validateAddress(senderAddress, origin, false);
6865
+ _context.next = 4;
6866
+ return api.init(origin);
6867
+ case 4:
6868
+ _context.prev = 4;
6869
+ _context.next = 7;
6870
+ return dryRunInternal(options);
6871
+ case 7:
6872
+ return _context.abrupt("return", _context.sent);
6873
+ case 8:
6874
+ _context.prev = 8;
6875
+ _context.next = 11;
6876
+ return api.disconnect();
6877
+ case 11:
6878
+ return _context.finish(8);
6879
+ case 12:
6880
+ case "end":
6881
+ return _context.stop();
6882
+ }
6883
+ }, _callee, null, [[4,, 8, 12]]);
6884
+ }));
6885
+ return function dryRun(_x) {
6886
+ return _ref.apply(this, arguments);
6887
+ };
6888
+ }();
6889
+
6890
+ var dryRunOrigin = /*#__PURE__*/function () {
6891
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
6892
+ var api, node, address, result;
6893
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6894
+ while (1) switch (_context.prev = _context.next) {
6895
+ case 0:
6896
+ api = options.api, node = options.node, address = options.address;
6897
+ validateAddress(address, node, false);
6898
+ _context.next = 4;
6899
+ return api.init(node);
6900
+ case 4:
6901
+ _context.prev = 4;
6902
+ _context.next = 7;
6903
+ return api.getDryRunCall(options);
6904
+ case 7:
6905
+ result = _context.sent;
6906
+ if (!result.success) {
6907
+ _context.next = 12;
6908
+ break;
6909
+ }
6910
+ return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
6911
+ currency: getNativeAssetSymbol(node)
6912
+ }));
6913
+ case 12:
6914
+ return _context.abrupt("return", result);
6915
+ case 13:
6916
+ _context.prev = 13;
6917
+ _context.next = 16;
6918
+ return api.disconnect();
6919
+ case 16:
6920
+ return _context.finish(13);
6921
+ case 17:
6922
+ case "end":
6923
+ return _context.stop();
6924
+ }
6925
+ }, _callee, null, [[4,, 13, 17]]);
6926
+ }));
6927
+ return function dryRunOrigin(_x) {
6928
+ return _ref.apply(this, arguments);
6929
+ };
6930
+ }();
6549
6931
 
6550
6932
  var getParaEthTransferFees = /*#__PURE__*/function () {
6551
6933
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
@@ -6905,345 +7287,137 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
6905
7287
  break;
6906
7288
  }
6907
7289
  throw new BridgeHaltedError();
6908
- case 8:
6909
- if (!('multiasset' in currency)) {
6910
- _context.next = 10;
6911
- break;
6912
- }
6913
- throw new Error('Multiassets syntax is not supported for Evm transfers');
6914
- case 10:
6915
- if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
6916
- _context.next = 12;
6917
- break;
6918
- }
6919
- throw new Error('Override multilocation is not supported for Evm transfers');
6920
- case 12:
6921
- foundAsset = findAsset(from, currency, to);
6922
- if (!(foundAsset === null)) {
6923
- _context.next = 15;
6924
- break;
6925
- }
6926
- throw new InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
6927
- case 15:
6928
- if (!(!isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
6929
- _context.next = 17;
6930
- break;
6931
- }
6932
- throw new InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
6933
- case 17:
6934
- ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), foundAsset.multiLocation);
6935
- if (!(!ethAsset || !ethAsset.assetId)) {
6936
- _context.next = 20;
6937
- break;
6938
- }
6939
- throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
6940
- case 20:
6941
- contract = isEthersSigner(signer) ? new Contract(xcmInterfacePrecompile, abi, signer) : getContract({
6942
- abi: abi,
6943
- address: xcmInterfacePrecompile,
6944
- client: {
6945
- "public": createPublicClient({
6946
- chain: signer.chain,
6947
- transport: http()
6948
- }),
6949
- wallet: signer
6950
- }
6951
- });
6952
- if (!isEthersSigner(signer)) {
6953
- _context.next = 27;
6954
- break;
6955
- }
6956
- _context.next = 24;
6957
- return signer.getAddress();
6958
- case 24:
6959
- _context.t0 = _context.sent;
6960
- _context.next = 28;
6961
- break;
6962
- case 27:
6963
- _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
6964
- case 28:
6965
- senderAddress = _context.t0;
6966
- if (senderAddress) {
6967
- _context.next = 31;
6968
- break;
6969
- }
6970
- throw new Error('Unable to get sender address');
6971
- case 31:
6972
- _context.next = 33;
6973
- return api.init(from);
6974
- case 33:
6975
- _context.next = 35;
6976
- return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
6977
- case 35:
6978
- messageId = _context.sent;
6979
- customXcm = createCustomXcmOnDest({
6980
- api: api,
6981
- address: address,
6982
- scenario: 'ParaToPara',
6983
- senderAddress: senderAddress,
6984
- asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
6985
- amount: currency.amount
6986
- })}, Version.V4, messageId);
6987
- _context.next = 39;
6988
- return api.objectToHex(customXcm, 'XcmVersionedXcm');
6989
- case 39:
6990
- customXcmOnDest = _context.sent;
6991
- _context.next = 42;
6992
- return api.createApiForNode('AssetHubPolkadot');
6993
- case 42:
6994
- assetHubApi = _context.sent;
6995
- _context.next = 45;
6996
- return getParaEthTransferFees(assetHubApi);
6997
- case 45:
6998
- _yield$getParaEthTran = _context.sent;
6999
- _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
7000
- bridgeFee = _yield$getParaEthTran2[0];
7001
- executionFee = _yield$getParaEthTran2[1];
7002
- transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
7003
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
7004
- createTx = function createTx(func, args) {
7005
- if (isEthersContract(contract)) {
7006
- return contract[func].apply(contract, _toConsumableArray(args));
7007
- }
7008
- return contract.write[func](args);
7009
- };
7010
- numberToHex32 = function numberToHex32(num) {
7011
- return typeof num !== 'number' || isNaN(num) ? function () {
7012
- throw new Error('Input must be a valid number');
7013
- }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
7014
- }; // Execute the custom XCM message with the precompile
7015
- _context.next = 54;
7016
- return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
7017
- // This represents (1,X1(Parachain(1000)))
7018
- [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
7019
- // Assets including fee and the ERC20 asset, with fee be the first
7020
- [[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
7021
- // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
7022
- 2,
7023
- // index for the fee
7024
- 0,
7025
- // The TransferType corresponding to fee asset
7026
- 2, customXcmOnDest]);
7027
- case 54:
7028
- tx = _context.sent;
7029
- return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
7030
- case 56:
7031
- case "end":
7032
- return _context.stop();
7033
- }
7034
- }, _callee);
7035
- }));
7036
- return function transferMoonbeamToEth(_x) {
7037
- return _ref2.apply(this, arguments);
7038
- };
7039
- }();
7040
-
7041
- /**
7042
- * Retrieves the node name corresponding to a specified parachain ID.
7043
- *
7044
- * @param paraId - The parachain ID.
7045
- * @returns The node name if found; otherwise, null.
7046
- */
7047
- var getTNode = function getTNode(paraId, ecosystem) {
7048
- var _NODE_NAMES_DOT_KSM$f;
7049
- if (paraId === 0) {
7050
- return ecosystem === 'polkadot' ? 'Polkadot' : 'Kusama';
7051
- }
7052
- if (paraId === 1) {
7053
- return 'Ethereum';
7054
- }
7055
- return (_NODE_NAMES_DOT_KSM$f = NODE_NAMES_DOT_KSM.find(function (nodeName) {
7056
- return getNode(nodeName).type === ecosystem && getParaId(nodeName) === paraId;
7057
- })) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
7058
- };
7059
-
7060
- var isAssetHub = function isAssetHub(chain) {
7061
- return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
7062
- };
7063
- var isBridgeHub = function isBridgeHub(chain) {
7064
- return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
7065
- };
7066
- var isPeople = function isPeople(chain) {
7067
- return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
7068
- };
7069
- var isSystemPara = function isSystemPara(chain) {
7070
- return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
7071
- };
7072
- var mul = function mul(v, num) {
7073
- var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
7074
- return v * num / den;
7075
- };
7076
- var padFee = function padFee(raw, origin, dest, side) {
7077
- var relayOrigin = isRelayChain(origin);
7078
- var relayDest = isRelayChain(dest);
7079
- var sysParaOrigin = isSystemPara(origin);
7080
- var sysParaDest = isSystemPara(dest);
7081
- var relayToPara = relayOrigin && !relayDest;
7082
- var sysParaToPara = sysParaOrigin && !sysParaDest;
7083
- var paraToPara = !relayOrigin && !sysParaOrigin;
7084
- if (sysParaToPara) return raw * 40n;
7085
- if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
7086
- if (paraToPara) return mul(raw, 130n, 100n);
7087
- // apply default 30% padding
7088
- return mul(raw, 130n, 100n);
7089
- };
7090
-
7091
- var createOriginLocation = function createOriginLocation(origin, destination) {
7092
- if (isRelayChain(origin)) return DOT_MULTILOCATION;
7093
- return {
7094
- parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
7095
- interior: {
7096
- X1: [{
7097
- Parachain: getParaId(origin)
7098
- }]
7099
- }
7100
- };
7101
- };
7102
- var getFeeForDestNode = /*#__PURE__*/function () {
7103
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
7104
- var api, forwardedXcms, origin, destination, address, senderAddress, currency, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
7105
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7106
- while (1) switch (_context2.prev = _context2.next) {
7107
- case 0:
7108
- api = _ref.api, forwardedXcms = _ref.forwardedXcms, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, currency = _ref.currency, disableFallback = _ref.disableFallback;
7109
- calcPaymentInfoFee = /*#__PURE__*/function () {
7110
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
7111
- var originAsset, currencyInput, tx, rawFee;
7112
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7113
- while (1) switch (_context.prev = _context.next) {
7114
- case 0:
7115
- if (!('multiasset' in currency)) {
7116
- _context.next = 2;
7117
- break;
7118
- }
7119
- throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
7120
- case 2:
7121
- originAsset = findAsset(origin, currency, destination);
7122
- if (originAsset) {
7123
- _context.next = 5;
7124
- break;
7125
- }
7126
- throw new InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
7127
- case 5:
7128
- currencyInput = originAsset.multiLocation ? {
7129
- multilocation: originAsset.multiLocation
7130
- } : {
7131
- symbol: originAsset.symbol
7132
- };
7133
- _context.next = 8;
7134
- return Builder(api).from(destination).to(origin).address(senderAddress, address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
7135
- amount: currency.amount
7136
- })).build();
7137
- case 8:
7138
- tx = _context.sent;
7139
- _context.next = 11;
7140
- return api.calculateTransactionFee(tx, address);
7141
- case 11:
7142
- rawFee = _context.sent;
7143
- return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
7144
- case 13:
7145
- case "end":
7146
- return _context.stop();
7147
- }
7148
- }, _callee);
7149
- }));
7150
- return function calcPaymentInfoFee() {
7151
- return _ref3.apply(this, arguments);
7152
- };
7153
- }();
7154
- if (!(!hasDryRunSupport(destination) || !forwardedXcms)) {
7155
- _context2.next = 7;
7290
+ case 8:
7291
+ if (!('multiasset' in currency)) {
7292
+ _context.next = 10;
7156
7293
  break;
7157
7294
  }
7158
- _context2.next = 5;
7159
- return calcPaymentInfoFee();
7160
- case 5:
7161
- _context2.t0 = _context2.sent;
7162
- return _context2.abrupt("return", {
7163
- fee: _context2.t0,
7164
- feeType: 'paymentInfo'
7165
- });
7166
- case 7:
7167
- _context2.next = 9;
7168
- return api.getDryRunXcm({
7169
- originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), Version.V4),
7170
- xcm: forwardedXcms[1][0],
7171
- node: destination,
7172
- origin: origin
7173
- });
7174
- case 9:
7175
- dryRunResult = _context2.sent;
7176
- if (dryRunResult.success) {
7177
- _context2.next = 18;
7295
+ throw new Error('Multiassets syntax is not supported for Evm transfers');
7296
+ case 10:
7297
+ if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
7298
+ _context.next = 12;
7178
7299
  break;
7179
7300
  }
7180
- if (!disableFallback) {
7181
- _context2.next = 13;
7301
+ throw new Error('Override multilocation is not supported for Evm transfers');
7302
+ case 12:
7303
+ foundAsset = findAsset(from, currency, to);
7304
+ if (!(foundAsset === null)) {
7305
+ _context.next = 15;
7182
7306
  break;
7183
7307
  }
7184
- return _context2.abrupt("return", {
7185
- dryRunError: dryRunResult.failureReason
7186
- });
7187
- case 13:
7188
- _context2.next = 15;
7189
- return calcPaymentInfoFee();
7308
+ throw new InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
7190
7309
  case 15:
7191
- _context2.t1 = _context2.sent;
7192
- _context2.t2 = dryRunResult.failureReason;
7193
- return _context2.abrupt("return", {
7194
- fee: _context2.t1,
7195
- feeType: 'paymentInfo',
7196
- dryRunError: _context2.t2
7197
- });
7198
- case 18:
7199
- fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
7200
- return _context2.abrupt("return", {
7201
- fee: fee,
7202
- feeType: 'dryRun',
7203
- forwardedXcms: newForwardedXcms,
7204
- destParaId: destParaId
7205
- });
7310
+ if (!(!isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
7311
+ _context.next = 17;
7312
+ break;
7313
+ }
7314
+ throw new InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
7315
+ case 17:
7316
+ ethAsset = findAssetByMultiLocation(getOtherAssets('Ethereum'), foundAsset.multiLocation);
7317
+ if (!(!ethAsset || !ethAsset.assetId)) {
7318
+ _context.next = 20;
7319
+ break;
7320
+ }
7321
+ throw new InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
7206
7322
  case 20:
7207
- case "end":
7208
- return _context2.stop();
7209
- }
7210
- }, _callee2);
7211
- }));
7212
- return function getFeeForDestNode(_x) {
7213
- return _ref2.apply(this, arguments);
7214
- };
7215
- }();
7216
-
7217
- var getDryRun = /*#__PURE__*/function () {
7218
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
7219
- var api, node, address;
7220
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7221
- while (1) switch (_context.prev = _context.next) {
7222
- case 0:
7223
- api = options.api, node = options.node, address = options.address;
7224
- validateAddress(address, node, false);
7225
- _context.next = 4;
7226
- return api.init(node);
7227
- case 4:
7228
- _context.prev = 4;
7229
- _context.next = 7;
7230
- return api.getDryRunCall(options);
7231
- case 7:
7232
- return _context.abrupt("return", _context.sent);
7233
- case 8:
7234
- _context.prev = 8;
7235
- _context.next = 11;
7236
- return api.disconnect();
7237
- case 11:
7238
- return _context.finish(8);
7239
- case 12:
7323
+ contract = isEthersSigner(signer) ? new Contract(xcmInterfacePrecompile, abi, signer) : getContract({
7324
+ abi: abi,
7325
+ address: xcmInterfacePrecompile,
7326
+ client: {
7327
+ "public": createPublicClient({
7328
+ chain: signer.chain,
7329
+ transport: http()
7330
+ }),
7331
+ wallet: signer
7332
+ }
7333
+ });
7334
+ if (!isEthersSigner(signer)) {
7335
+ _context.next = 27;
7336
+ break;
7337
+ }
7338
+ _context.next = 24;
7339
+ return signer.getAddress();
7340
+ case 24:
7341
+ _context.t0 = _context.sent;
7342
+ _context.next = 28;
7343
+ break;
7344
+ case 27:
7345
+ _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
7346
+ case 28:
7347
+ senderAddress = _context.t0;
7348
+ if (senderAddress) {
7349
+ _context.next = 31;
7350
+ break;
7351
+ }
7352
+ throw new Error('Unable to get sender address');
7353
+ case 31:
7354
+ _context.next = 33;
7355
+ return api.init(from);
7356
+ case 33:
7357
+ _context.next = 35;
7358
+ return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
7359
+ case 35:
7360
+ messageId = _context.sent;
7361
+ customXcm = createCustomXcmOnDest({
7362
+ api: api,
7363
+ address: address,
7364
+ scenario: 'ParaToPara',
7365
+ senderAddress: senderAddress,
7366
+ ahAddress: ahAddress,
7367
+ asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
7368
+ amount: currency.amount
7369
+ })}, from, Version.V4, messageId);
7370
+ _context.next = 39;
7371
+ return api.objectToHex(customXcm, 'XcmVersionedXcm');
7372
+ case 39:
7373
+ customXcmOnDest = _context.sent;
7374
+ _context.next = 42;
7375
+ return api.createApiForNode('AssetHubPolkadot');
7376
+ case 42:
7377
+ assetHubApi = _context.sent;
7378
+ _context.next = 45;
7379
+ return getParaEthTransferFees(assetHubApi);
7380
+ case 45:
7381
+ _yield$getParaEthTran = _context.sent;
7382
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
7383
+ bridgeFee = _yield$getParaEthTran2[0];
7384
+ executionFee = _yield$getParaEthTran2[1];
7385
+ transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
7386
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
7387
+ createTx = function createTx(func, args) {
7388
+ if (isEthersContract(contract)) {
7389
+ return contract[func].apply(contract, _toConsumableArray(args));
7390
+ }
7391
+ return contract.write[func](args);
7392
+ };
7393
+ numberToHex32 = function numberToHex32(num) {
7394
+ return typeof num !== 'number' || isNaN(num) ? function () {
7395
+ throw new Error('Input must be a valid number');
7396
+ }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
7397
+ }; // Execute the custom XCM message with the precompile
7398
+ _context.next = 54;
7399
+ return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
7400
+ // This represents (1,X1(Parachain(1000)))
7401
+ [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
7402
+ // Assets including fee and the ERC20 asset, with fee be the first
7403
+ [[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
7404
+ // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
7405
+ 2,
7406
+ // index for the fee
7407
+ 0,
7408
+ // The TransferType corresponding to fee asset
7409
+ 2, customXcmOnDest]);
7410
+ case 54:
7411
+ tx = _context.sent;
7412
+ return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
7413
+ case 56:
7240
7414
  case "end":
7241
7415
  return _context.stop();
7242
7416
  }
7243
- }, _callee, null, [[4,, 8, 12]]);
7417
+ }, _callee);
7244
7418
  }));
7245
- return function getDryRun(_x) {
7246
- return _ref.apply(this, arguments);
7419
+ return function transferMoonbeamToEth(_x) {
7420
+ return _ref2.apply(this, arguments);
7247
7421
  };
7248
7422
  }();
7249
7423
 
@@ -7268,8 +7442,7 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
7268
7442
  });
7269
7443
  case 6:
7270
7444
  _context.next = 8;
7271
- return getDryRun({
7272
- api: api,
7445
+ return api.getDryRunCall({
7273
7446
  tx: tx,
7274
7447
  node: origin,
7275
7448
  address: senderAddress
@@ -7408,7 +7581,7 @@ var getXcmFee = /*#__PURE__*/function () {
7408
7581
  destinationFeeType = 'paymentInfo';
7409
7582
  case 36:
7410
7583
  if (!(Array.isArray(forwardedXcms) && forwardedXcms.length > 0 && forwardedXcms[1].length > 0 && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
7411
- _context.next = 69;
7584
+ _context.next = 68;
7412
7585
  break;
7413
7586
  }
7414
7587
  nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
@@ -7479,7 +7652,7 @@ var getXcmFee = /*#__PURE__*/function () {
7479
7652
  destinationFee = destFallback.fee;
7480
7653
  destinationFeeType = destFallback.feeType; // paymentInfo
7481
7654
  case 57:
7482
- return _context.abrupt("break", 69);
7655
+ return _context.abrupt("break", 68);
7483
7656
  case 58:
7484
7657
  if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
7485
7658
  destinationFee = hopResult.fee;
@@ -7502,15 +7675,14 @@ var getXcmFee = /*#__PURE__*/function () {
7502
7675
  currentOrigin = nextChain;
7503
7676
  case 62:
7504
7677
  _context.prev = 62;
7505
- hopApi.setDisconnectAllowed(true);
7506
- _context.next = 66;
7678
+ _context.next = 65;
7507
7679
  return hopApi.disconnect();
7508
- case 66:
7680
+ case 65:
7509
7681
  return _context.finish(62);
7510
- case 67:
7682
+ case 66:
7511
7683
  _context.next = 36;
7512
7684
  break;
7513
- case 69:
7685
+ case 68:
7514
7686
  return _context.abrupt("return", _objectSpread2(_objectSpread2({
7515
7687
  origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
7516
7688
  fee: originFee
@@ -7532,11 +7704,11 @@ var getXcmFee = /*#__PURE__*/function () {
7532
7704
  dryRunError: destinationDryRunError
7533
7705
  })
7534
7706
  }));
7535
- case 70:
7707
+ case 69:
7536
7708
  case "end":
7537
7709
  return _context.stop();
7538
7710
  }
7539
- }, _callee, null, [[17,, 25, 30], [41,, 62, 67]]);
7711
+ }, _callee, null, [[17,, 25, 30], [41,, 62, 66]]);
7540
7712
  }));
7541
7713
  return function getXcmFee(_x) {
7542
7714
  return _ref2.apply(this, arguments);
@@ -7610,7 +7782,7 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
7610
7782
  symbol: originAsset.symbol
7611
7783
  };
7612
7784
  _context.next = 20;
7613
- return Builder(destApi).from(destination).to(origin).address(senderAddress, address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
7785
+ return Builder(destApi).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
7614
7786
  amount: currency.amount
7615
7787
  })).build();
7616
7788
  case 20:
@@ -7723,7 +7895,7 @@ var validateDestination = function validateDestination(origin, destination) {
7723
7895
  if (isRelayChain(origin) && !isTMultiLocation(destination) && isRelayChain(destination) && origin !== destination) {
7724
7896
  throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
7725
7897
  }
7726
- if (destination === 'Ethereum' && origin !== 'AssetHubPolkadot' && origin !== 'Hydration' && origin !== 'BifrostPolkadot') {
7898
+ if (destination === 'Ethereum' && origin !== 'AssetHubPolkadot' && origin !== 'Hydration' && origin !== 'BifrostPolkadot' && origin !== 'Moonbeam') {
7727
7899
  throw new IncompatibleNodesError('Transfers to Ethereum are only supported from AssetHubPolkadot and Hydration.');
7728
7900
  }
7729
7901
  var isMultiLocationDestination = _typeof(destination) === 'object';
@@ -7849,11 +8021,11 @@ var validateDestinationAddress = function validateDestinationAddress(address, de
7849
8021
 
7850
8022
  var send = /*#__PURE__*/function () {
7851
8023
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
7852
- var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
8024
+ var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
7853
8025
  return _regeneratorRuntime().wrap(function _callee$(_context) {
7854
8026
  while (1) switch (_context.prev = _context.next) {
7855
8027
  case 0:
7856
- api = options.api, origin = options.from, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, version = options.version, senderAddress = options.senderAddress, pallet = options.pallet, method = options.method;
8028
+ api = options.api, origin = options.from, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method;
7857
8029
  validateCurrency(currency, feeAsset);
7858
8030
  validateDestination(origin, destination);
7859
8031
  validateDestinationAddress(address, destination);
@@ -7940,6 +8112,7 @@ var send = /*#__PURE__*/function () {
7940
8112
  overriddenAsset: overriddenAsset,
7941
8113
  version: version,
7942
8114
  senderAddress: senderAddress,
8115
+ ahAddress: ahAddress,
7943
8116
  pallet: pallet,
7944
8117
  method: method
7945
8118
  }));
@@ -8093,14 +8266,44 @@ var GeneralBuilder = /*#__PURE__*/function () {
8093
8266
  currency: _currency
8094
8267
  }));
8095
8268
  }
8269
+ /**
8270
+ * Sets the recipient address.
8271
+ *
8272
+ * @param address - The destination address.
8273
+ * @returns An instance of Builder
8274
+ */
8096
8275
  }, {
8097
8276
  key: "address",
8098
- value: function address(_address, senderAddress) {
8277
+ value: function address(_address) {
8099
8278
  return new GeneralBuilder(this.api, this.batchManager, _objectSpread2(_objectSpread2({}, this._options), {}, {
8100
8279
  address: _address
8101
- }, senderAddress ? {
8102
- senderAddress: senderAddress
8103
- } : {}));
8280
+ }));
8281
+ }
8282
+ /**
8283
+ * Sets the sender address.
8284
+ *
8285
+ * @param address - The sender address.
8286
+ * @returns
8287
+ */
8288
+ }, {
8289
+ key: "senderAddress",
8290
+ value: function senderAddress(address) {
8291
+ return new GeneralBuilder(this.api, this.batchManager, _objectSpread2(_objectSpread2({}, this._options), {}, {
8292
+ senderAddress: address
8293
+ }));
8294
+ }
8295
+ /**
8296
+ * Sets the asset hub address. This is used for transfers that go through the Asset Hub and originate from an EVM chain.
8297
+ *
8298
+ * @param address - The address to be used.
8299
+ * @returns An instance of Builder
8300
+ */
8301
+ }, {
8302
+ key: "ahAddress",
8303
+ value: function ahAddress(address) {
8304
+ return new GeneralBuilder(this.api, this.batchManager, _objectSpread2(_objectSpread2({}, this._options), {}, {
8305
+ ahAddress: address
8306
+ }));
8104
8307
  }
8105
8308
  /**
8106
8309
  * Sets the XCM version to be used for the transfer.
@@ -8226,33 +8429,53 @@ var GeneralBuilder = /*#__PURE__*/function () {
8226
8429
  }, {
8227
8430
  key: "dryRun",
8228
8431
  value: function () {
8229
- var _dryRun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(senderAddress) {
8230
- var tx;
8432
+ var _dryRun2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
8433
+ var _this$_options2, to, address, senderAddress, tx;
8231
8434
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
8232
8435
  while (1) switch (_context3.prev = _context3.next) {
8233
8436
  case 0:
8234
- this.api.setDisconnectAllowed(false);
8437
+ _this$_options2 = this._options, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress;
8235
8438
  _context3.next = 3;
8236
8439
  return this.build();
8237
8440
  case 3:
8238
8441
  tx = _context3.sent;
8239
- this.api.setDisconnectAllowed(true);
8240
- return _context3.abrupt("return", getDryRun({
8442
+ if (!isTMultiLocation(to)) {
8443
+ _context3.next = 6;
8444
+ break;
8445
+ }
8446
+ throw new InvalidParameterError('Multi-Location destination is not supported for XCM fee calculation.');
8447
+ case 6:
8448
+ if (!isTMultiLocation(address)) {
8449
+ _context3.next = 8;
8450
+ break;
8451
+ }
8452
+ throw new InvalidParameterError('Multi-Location address is not supported for XCM fee calculation.');
8453
+ case 8:
8454
+ if (!(to === 'Ethereum')) {
8455
+ _context3.next = 10;
8456
+ break;
8457
+ }
8458
+ throw new InvalidParameterError('Ethereum destination is not yet supported for XCM fee calculation.');
8459
+ case 10:
8460
+ return _context3.abrupt("return", dryRun({
8241
8461
  api: this.api,
8242
8462
  tx: tx,
8243
8463
  address: senderAddress,
8244
- node: this._options.from
8464
+ origin: this._options.from,
8465
+ destination: to,
8466
+ currency: this._options.currency,
8467
+ senderAddress: this._options.senderAddress
8245
8468
  }));
8246
- case 6:
8469
+ case 11:
8247
8470
  case "end":
8248
8471
  return _context3.stop();
8249
8472
  }
8250
8473
  }, _callee3, this);
8251
8474
  }));
8252
- function dryRun(_x2) {
8253
- return _dryRun.apply(this, arguments);
8475
+ function dryRun$1() {
8476
+ return _dryRun2.apply(this, arguments);
8254
8477
  }
8255
- return dryRun;
8478
+ return dryRun$1;
8256
8479
  }()
8257
8480
  /**
8258
8481
  * Estimates the XCM fee for the transfer using paymentInfo function.
@@ -8263,11 +8486,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
8263
8486
  key: "getXcmFeeEstimate",
8264
8487
  value: (function () {
8265
8488
  var _getXcmFeeEstimate2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
8266
- var _this$_options2, from, to, address, senderAddress, tx;
8489
+ var _this$_options3, from, to, address, senderAddress, tx;
8267
8490
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
8268
8491
  while (1) switch (_context4.prev = _context4.next) {
8269
8492
  case 0:
8270
- _this$_options2 = this._options, from = _this$_options2.from, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress;
8493
+ _this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress;
8271
8494
  if (!isTMultiLocation(to)) {
8272
8495
  _context4.next = 3;
8273
8496
  break;
@@ -8292,7 +8515,9 @@ var GeneralBuilder = /*#__PURE__*/function () {
8292
8515
  case 10:
8293
8516
  tx = _context4.sent;
8294
8517
  this.api.setDisconnectAllowed(true);
8295
- return _context4.abrupt("return", getXcmFeeEstimate({
8518
+ _context4.prev = 12;
8519
+ _context4.next = 15;
8520
+ return getXcmFeeEstimate({
8296
8521
  api: this.api,
8297
8522
  tx: tx,
8298
8523
  origin: from,
@@ -8300,12 +8525,20 @@ var GeneralBuilder = /*#__PURE__*/function () {
8300
8525
  address: address,
8301
8526
  senderAddress: senderAddress,
8302
8527
  currency: this._options.currency
8303
- }));
8304
- case 13:
8528
+ });
8529
+ case 15:
8530
+ return _context4.abrupt("return", _context4.sent);
8531
+ case 16:
8532
+ _context4.prev = 16;
8533
+ _context4.next = 19;
8534
+ return this.api.disconnect();
8535
+ case 19:
8536
+ return _context4.finish(16);
8537
+ case 20:
8305
8538
  case "end":
8306
8539
  return _context4.stop();
8307
8540
  }
8308
- }, _callee4, this);
8541
+ }, _callee4, this, [[12,, 16, 20]]);
8309
8542
  }));
8310
8543
  function getXcmFeeEstimate$1() {
8311
8544
  return _getXcmFeeEstimate2.apply(this, arguments);
@@ -8324,7 +8557,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
8324
8557
  var _getXcmFee2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
8325
8558
  var _ref,
8326
8559
  disableFallback,
8327
- _this$_options3,
8560
+ _this$_options4,
8328
8561
  from,
8329
8562
  to,
8330
8563
  address,
@@ -8337,7 +8570,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
8337
8570
  _ref = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {
8338
8571
  disableFallback: false
8339
8572
  }, disableFallback = _ref.disableFallback;
8340
- _this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress;
8573
+ _this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, address = _this$_options4.address, senderAddress = _this$_options4.senderAddress;
8341
8574
  if (!isTMultiLocation(to)) {
8342
8575
  _context5.next = 4;
8343
8576
  break;
@@ -8360,8 +8593,9 @@ var GeneralBuilder = /*#__PURE__*/function () {
8360
8593
  return this.build();
8361
8594
  case 10:
8362
8595
  tx = _context5.sent;
8363
- this.api.setDisconnectAllowed(false);
8364
- return _context5.abrupt("return", getXcmFee({
8596
+ _context5.prev = 11;
8597
+ _context5.next = 14;
8598
+ return getXcmFee({
8365
8599
  api: this.api,
8366
8600
  tx: tx,
8367
8601
  origin: from,
@@ -8370,12 +8604,20 @@ var GeneralBuilder = /*#__PURE__*/function () {
8370
8604
  address: address,
8371
8605
  currency: this._options.currency,
8372
8606
  disableFallback: disableFallback
8373
- }));
8374
- case 13:
8607
+ });
8608
+ case 14:
8609
+ return _context5.abrupt("return", _context5.sent);
8610
+ case 15:
8611
+ _context5.prev = 15;
8612
+ _context5.next = 18;
8613
+ return this.api.disconnect();
8614
+ case 18:
8615
+ return _context5.finish(15);
8616
+ case 19:
8375
8617
  case "end":
8376
8618
  return _context5.stop();
8377
8619
  }
8378
- }, _callee5, this);
8620
+ }, _callee5, this, [[11,, 15, 19]]);
8379
8621
  }));
8380
8622
  function getXcmFee$1() {
8381
8623
  return _getXcmFee2.apply(this, arguments);
@@ -8776,7 +9018,7 @@ var getOriginFeeDetailsInternal = /*#__PURE__*/function () {
8776
9018
  return api.init(origin);
8777
9019
  case 3:
8778
9020
  _context.next = 5;
8779
- return Builder(api).from(origin).to(destination).currency(currency).address(accountDestination, account).build();
9021
+ return Builder(api).from(origin).to(destination).currency(currency).address(accountDestination).senderAddress(account).build();
8780
9022
  case 5:
8781
9023
  tx = _context.sent;
8782
9024
  _context.next = 8;
@@ -9171,4 +9413,4 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
9171
9413
  };
9172
9414
  }();
9173
9415
 
9174
- export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, 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, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
9416
+ export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, Version, XTokensError, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, determineRelayChain, dryRun, dryRunOrigin, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };