@paraspell/sdk-core 8.9.9 → 8.10.0

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