@paraspell/sdk-core 10.0.1 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -183,7 +183,10 @@ function _iterableToArrayLimit(r, l) {
183
183
  f = true,
184
184
  o = false;
185
185
  try {
186
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
186
+ if (i = (t = t.call(r)).next, 0 === l) {
187
+ if (Object(t) !== t) return;
188
+ f = !1;
189
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
187
190
  } catch (r) {
188
191
  o = true, n = r;
189
192
  } finally {
@@ -785,7 +788,7 @@ var blake2b512 = function blake2b512(msg) {
785
788
  var ALLOWED_PUBKEY_BYTES = new Set([32, 33]);
786
789
  var deriveAccountId = function deriveAccountId(raw) {
787
790
  if (!ALLOWED_PUBKEY_BYTES.has(raw.length)) {
788
- throw new Error('public key length is invalid');
791
+ throw new InvalidParameterError('public key length is invalid');
789
792
  }
790
793
  return raw.length === 33 ? blake2b256(raw) : raw;
791
794
  };
@@ -803,7 +806,7 @@ var networkToBytes = function networkToBytes(net) {
803
806
  };
804
807
  var encodeSs58 = function encodeSs58(payload, network) {
805
808
  if (!VALID_ADDR_PAYLOAD.has(payload.length)) {
806
- throw new Error('unexpected payload length for SS58 address');
809
+ throw new InvalidParameterError('unexpected payload length for SS58 address');
807
810
  }
808
811
  var netBytes = networkToBytes(network);
809
812
  var chkInput = new Uint8Array(SS58_HARD_PREFIX.length + netBytes.length + payload.length);
@@ -2170,7 +2173,7 @@ var getNodeProviders = function getNodeProviders(node) {
2170
2173
  var _getNodeConfig = getNodeConfig(node),
2171
2174
  providers = _getNodeConfig.providers;
2172
2175
  if (providers.length === 0) {
2173
- throw new Error("No providers found for node ".concat(node));
2176
+ throw new InvalidParameterError("No providers found for node ".concat(node));
2174
2177
  }
2175
2178
  // Prefer Dwellir provider
2176
2179
  providers.sort(function (a, b) {
@@ -2383,12 +2386,12 @@ var addXcmVersionHeader = function addXcmVersionHeader(obj, version) {
2383
2386
  var extractVersionFromHeader = function extractVersionFromHeader(versionHeader) {
2384
2387
  var keys = Object.keys(versionHeader);
2385
2388
  if (keys.length !== 1) {
2386
- throw new Error('Invalid version header: expected exactly one key.');
2389
+ throw new InvalidParameterError('Invalid version header: expected exactly one key.');
2387
2390
  }
2388
2391
  var version = keys[0];
2389
2392
  var value = versionHeader[version];
2390
2393
  if (value === undefined) {
2391
- throw new Error('Invalid version header: value is undefined.');
2394
+ throw new InvalidParameterError('Invalid version header: value is undefined.');
2392
2395
  }
2393
2396
  return [version, value];
2394
2397
  };
@@ -2431,13 +2434,13 @@ var resolveTNodeFromMultiLocation = function resolveTNodeFromMultiLocation(relay
2431
2434
  var _NODE_NAMES_DOT_KSM$f;
2432
2435
  var parachainId = findParachainJunction(multiLocation);
2433
2436
  if (parachainId === null) {
2434
- throw new Error('Parachain ID not found in destination multi location.');
2437
+ throw new InvalidParameterError('Parachain ID not found in destination multi location.');
2435
2438
  }
2436
2439
  var node = (_NODE_NAMES_DOT_KSM$f = sdkCommon.NODE_NAMES_DOT_KSM.find(function (nodeName) {
2437
2440
  return getParaId(nodeName) === parachainId && determineRelayChain(nodeName) === relayChain;
2438
2441
  })) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
2439
2442
  if (node === null) {
2440
- throw new Error('Node with specified paraId not found in destination multi location.');
2443
+ throw new InvalidParameterError('Node with specified paraId not found in destination multi location.');
2441
2444
  }
2442
2445
  return node;
2443
2446
  };
@@ -2717,17 +2720,17 @@ var resolveModuleError = function resolveModuleError(node, error) {
2717
2720
  return p.index === Number(error.index);
2718
2721
  });
2719
2722
  if (!palletDetails) {
2720
- throw new Error("Pallet with index ".concat(error.index, " not found"));
2723
+ throw new InvalidParameterError("Pallet with index ".concat(error.index, " not found"));
2721
2724
  }
2722
2725
  // Use only the first byte of the error to get the error index
2723
2726
  var errorIndex = Number(error.error.slice(0, 4));
2724
2727
  var name = palletDetails.name;
2725
2728
  if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
2726
- throw new Error("Pallet ".concat(name, " is not supported"));
2729
+ throw new InvalidParameterError("Pallet ".concat(name, " is not supported"));
2727
2730
  }
2728
2731
  var failureReason = name === 'XTokens' ? Object.values(exports.XTokensError)[errorIndex] : Object.values(exports.PolkadotXcmError)[errorIndex];
2729
2732
  if (!failureReason) {
2730
- throw new Error("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
2733
+ throw new InvalidParameterError("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
2731
2734
  }
2732
2735
  return failureReason;
2733
2736
  };
@@ -2761,7 +2764,7 @@ var getFees = function getFees(scenario) {
2761
2764
  } else if (scenario === 'ParaToPara') {
2762
2765
  return 399600000000;
2763
2766
  }
2764
- throw new Error("Fees for scenario ".concat(scenario, " are not defined."));
2767
+ throw new InvalidParameterError("Fees for scenario ".concat(scenario, " are not defined."));
2765
2768
  };
2766
2769
 
2767
2770
  /**
@@ -2921,7 +2924,7 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
2921
2924
  useMultiAssetTransfer = _input$useMultiAssetT === void 0 ? false : _input$useMultiAssetT;
2922
2925
  var isMultiLocationDestination = _typeof(destination) === 'object';
2923
2926
  if (isMultiLocationDestination) {
2924
- 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.');
2927
+ throw new InvalidParameterError('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.');
2925
2928
  }
2926
2929
  var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
2927
2930
  var isAssetHubDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
@@ -2960,652 +2963,310 @@ var getTNode = function getTNode(paraId, ecosystem) {
2960
2963
  })) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
2961
2964
  };
2962
2965
 
2963
- var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
2964
- var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
2965
- var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
2966
- if (!asset && !usesRawOverriddenMultiAssets) {
2967
- throwUnsupportedCurrency(feeAsset, origin);
2966
+ var getParaEthTransferFees = /*#__PURE__*/function () {
2967
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
2968
+ var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
2969
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2970
+ while (1) switch (_context.prev = _context.next) {
2971
+ case 0:
2972
+ DEFAULT_FEE = 2750872500000n;
2973
+ _context.next = 3;
2974
+ return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
2975
+ case 3:
2976
+ feeStorageItem = _context.sent;
2977
+ leFeeHex = feeStorageItem.replace('0x', '');
2978
+ _context.next = 7;
2979
+ return ahApi.disconnect();
2980
+ case 7:
2981
+ bytes = leFeeHex.match(/.{1,2}/g) || [];
2982
+ reversedHex = bytes.reverse().join('');
2983
+ validReversedHex = reversedHex === '' ? '0' : reversedHex;
2984
+ leFee = BigInt('0x' + validReversedHex);
2985
+ transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
2986
+ finalBridgeFee = transferBridgeFee * 110n / 100n;
2987
+ finalAssethubExecutionFee = ASSET_HUB_EXECUTION_FEE * 110n / 100n;
2988
+ return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
2989
+ case 15:
2990
+ case "end":
2991
+ return _context.stop();
2992
+ }
2993
+ }, _callee);
2994
+ }));
2995
+ return function getParaEthTransferFees(_x) {
2996
+ return _ref.apply(this, arguments);
2997
+ };
2998
+ }();
2999
+
3000
+ // Inspired by Moonbeam XCM-SDK
3001
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3002
+ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3003
+ if (id.startsWith('0x')) {
3004
+ return id;
2968
3005
  }
2969
- return asset !== null && asset !== void 0 ? asset : undefined;
3006
+ if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3007
+ throw new InvalidParameterError("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3008
+ }
3009
+ return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
2970
3010
  };
2971
3011
 
2972
- var isAssetHub = function isAssetHub(chain) {
2973
- return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
2974
- };
2975
- var isBridgeHub = function isBridgeHub(chain) {
2976
- return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
2977
- };
2978
- var isPeople = function isPeople(chain) {
2979
- return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
2980
- };
2981
- var isSystemPara = function isSystemPara(chain) {
2982
- return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
2983
- };
2984
- var mul = function mul(v, num) {
2985
- var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
2986
- return v * num / den;
2987
- };
2988
- var padFee = function padFee(raw, origin, dest, side) {
2989
- var relayOrigin = sdkCommon.isRelayChain(origin);
2990
- var relayDest = sdkCommon.isRelayChain(dest);
2991
- var sysParaOrigin = isSystemPara(origin);
2992
- var sysParaDest = isSystemPara(dest);
2993
- var relayToPara = relayOrigin && !relayDest;
2994
- var sysParaToPara = sysParaOrigin && !sysParaDest;
2995
- var paraToPara = !relayOrigin && !sysParaOrigin;
2996
- if (sysParaToPara) return raw * 40n;
2997
- if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
2998
- if (paraToPara) return mul(raw, 130n, 100n);
2999
- // apply default 30% padding
3000
- return mul(raw, 130n, 100n);
3001
- };
3012
+ var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
3013
+ var MOONBEAM_ID = 1284;
3014
+ var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
3015
+ var MOONRIVER_ID = 1285;
3016
+ var ERC20_ABI$1 = ['function balanceOf(address) view returns (uint256)'];
3017
+ function getMoonbeamErc20Balance(_x, _x2, _x3) {
3018
+ return _getMoonbeamErc20Balance.apply(this, arguments);
3019
+ }
3020
+ function _getMoonbeamErc20Balance() {
3021
+ _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
3022
+ var _ref, rpc, id, provider, addr, token;
3023
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3024
+ while (1) switch (_context.prev = _context.next) {
3025
+ case 0:
3026
+ _ref = node === 'Moonbeam' ? {
3027
+ rpc: MOONBEAM_RPC,
3028
+ id: MOONBEAM_ID
3029
+ } : {
3030
+ rpc: MOONRIVER_RPC,
3031
+ id: MOONRIVER_ID
3032
+ }, rpc = _ref.rpc, id = _ref.id;
3033
+ provider = new ethers.ethers.JsonRpcProvider(rpc, id);
3034
+ addr = formatAssetIdToERC20(assetId);
3035
+ token = new ethers.ethers.Contract(addr, ERC20_ABI$1, provider);
3036
+ _context.next = 6;
3037
+ return token.balanceOf(address);
3038
+ case 6:
3039
+ return _context.abrupt("return", _context.sent);
3040
+ case 7:
3041
+ case "end":
3042
+ return _context.stop();
3043
+ }
3044
+ }, _callee);
3045
+ }));
3046
+ return _getMoonbeamErc20Balance.apply(this, arguments);
3047
+ }
3002
3048
 
3003
- var getReverseTxFee = /*#__PURE__*/function () {
3004
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
3005
- var api, origin, destination, senderAddress, address, currency, tx, rawFee;
3049
+ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
3050
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3051
+ var ASSETS_PALLET_ID, hasRequiredJunctions;
3006
3052
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3007
3053
  while (1) switch (_context.prev = _context.next) {
3008
3054
  case 0:
3009
- api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
3010
- if (!('multiasset' in currency)) {
3055
+ if (!(node === 'Moonbeam' || node === 'Moonriver')) {
3056
+ _context.next = 6;
3057
+ break;
3058
+ }
3059
+ if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
3011
3060
  _context.next = 3;
3012
3061
  break;
3013
3062
  }
3014
- throw new assets.InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
3063
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3015
3064
  case 3:
3016
- _context.next = 5;
3017
- return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
3018
- amount: currency.amount
3019
- })).build();
3065
+ if (!(asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
3066
+ _context.next = 5;
3067
+ break;
3068
+ }
3069
+ return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
3020
3070
  case 5:
3021
- tx = _context.sent;
3022
- _context.next = 8;
3023
- return api.calculateTransactionFee(tx, address);
3071
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3072
+ case 6:
3073
+ if (!(node === 'Mythos')) {
3074
+ _context.next = 8;
3075
+ break;
3076
+ }
3077
+ return _context.abrupt("return", api.getMythosForeignBalance(address));
3024
3078
  case 8:
3025
- rawFee = _context.sent;
3026
- return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
3079
+ if (assets.isForeignAsset(asset)) {
3080
+ _context.next = 10;
3081
+ break;
3082
+ }
3083
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3027
3084
  case 10:
3085
+ if (!(node === 'Polimec')) {
3086
+ _context.next = 14;
3087
+ break;
3088
+ }
3089
+ if (!(asset.multiLocation === undefined)) {
3090
+ _context.next = 13;
3091
+ break;
3092
+ }
3093
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
3094
+ case 13:
3095
+ return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3096
+ case 14:
3097
+ if (!(node === 'AssetHubPolkadot')) {
3098
+ _context.next = 20;
3099
+ break;
3100
+ }
3101
+ ASSETS_PALLET_ID = 50;
3102
+ hasRequiredJunctions = asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && sdkCommon.hasJunction(asset.multiLocation, 'GeneralIndex');
3103
+ if (!(!asset.multiLocation || hasRequiredJunctions)) {
3104
+ _context.next = 19;
3105
+ break;
3106
+ }
3107
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
3108
+ case 19:
3109
+ return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3110
+ case 20:
3111
+ return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
3112
+ case 21:
3028
3113
  case "end":
3029
3114
  return _context.stop();
3030
3115
  }
3031
3116
  }, _callee);
3032
3117
  }));
3033
- return function getReverseTxFee(_x, _x2) {
3034
- return _ref2.apply(this, arguments);
3118
+ return function getBalanceForeignPolkadotXcm(_x, _x2, _x3, _x4) {
3119
+ return _ref.apply(this, arguments);
3035
3120
  };
3036
3121
  }();
3037
3122
 
3038
- var createOriginLocation = function createOriginLocation(origin, destination) {
3039
- if (sdkCommon.isRelayChain(origin)) return DOT_MULTILOCATION;
3040
- return {
3041
- parents: sdkCommon.isRelayChain(destination) ? sdkCommon.Parents.ZERO : sdkCommon.Parents.ONE,
3042
- interior: {
3043
- X1: [{
3044
- Parachain: getParaId(origin)
3045
- }]
3046
- }
3047
- };
3048
- };
3049
- var getDestXcmFee = /*#__PURE__*/function () {
3050
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3051
- var api, origin, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
3052
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3053
- while (1) switch (_context2.prev = _context2.next) {
3123
+ var getBalanceForeignXTokens = /*#__PURE__*/function () {
3124
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3125
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3126
+ while (1) switch (_context.prev = _context.next) {
3054
3127
  case 0:
3055
- api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
3056
- resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
3057
- calcPaymentInfoFee = /*#__PURE__*/function () {
3058
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
3059
- var originAsset;
3060
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3061
- while (1) switch (_context.prev = _context.next) {
3062
- case 0:
3063
- originAsset = assets.findAsset(origin, currency, destination);
3064
- if (originAsset) {
3065
- _context.next = 3;
3066
- break;
3067
- }
3068
- throw new assets.InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
3069
- case 3:
3070
- if (!originAsset.multiLocation) {
3071
- _context.next = 17;
3072
- break;
3073
- }
3074
- _context.prev = 4;
3075
- _context.next = 7;
3076
- return getReverseTxFee(options, {
3077
- multilocation: originAsset.multiLocation
3078
- });
3079
- case 7:
3080
- return _context.abrupt("return", _context.sent);
3081
- case 10:
3082
- _context.prev = 10;
3083
- _context.t0 = _context["catch"](4);
3084
- if (!(_context.t0 instanceof assets.InvalidCurrencyError)) {
3085
- _context.next = 16;
3086
- break;
3087
- }
3088
- _context.next = 15;
3089
- return getReverseTxFee(options, {
3090
- symbol: originAsset.symbol
3091
- });
3092
- case 15:
3093
- return _context.abrupt("return", _context.sent);
3094
- case 16:
3095
- throw _context.t0;
3096
- case 17:
3097
- _context.next = 19;
3098
- return getReverseTxFee(options, {
3099
- symbol: originAsset.symbol
3100
- });
3101
- case 19:
3102
- return _context.abrupt("return", _context.sent);
3103
- case 20:
3104
- case "end":
3105
- return _context.stop();
3106
- }
3107
- }, _callee, null, [[4, 10]]);
3108
- }));
3109
- return function calcPaymentInfoFee() {
3110
- return _ref2.apply(this, arguments);
3111
- };
3112
- }();
3113
- if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms)) {
3114
- _context2.next = 8;
3128
+ if (!(node === 'Astar' || node === 'Shiden')) {
3129
+ _context.next = 4;
3115
3130
  break;
3116
3131
  }
3117
- _context2.next = 6;
3118
- return calcPaymentInfoFee();
3119
- case 6:
3120
- _context2.t0 = _context2.sent;
3121
- return _context2.abrupt("return", {
3122
- fee: _context2.t0,
3123
- feeType: 'paymentInfo'
3124
- });
3125
- case 8:
3126
- _context2.next = 10;
3127
- return api.getDryRunXcm({
3128
- originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), exports.Version.V4),
3129
- xcm: forwardedXcms[1][0],
3130
- node: destination,
3131
- origin: origin,
3132
- asset: asset,
3133
- originFee: originFee,
3134
- feeAsset: resolvedFeeAsset,
3135
- amount: BigInt(currency.amount)
3136
- });
3137
- case 10:
3138
- dryRunResult = _context2.sent;
3139
- if (dryRunResult.success) {
3140
- _context2.next = 19;
3132
+ if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
3133
+ _context.next = 3;
3141
3134
  break;
3142
3135
  }
3143
- if (!disableFallback) {
3144
- _context2.next = 14;
3136
+ throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3137
+ case 3:
3138
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3139
+ case 4:
3140
+ if (!(node === 'BifrostPolkadot' || node === 'BifrostKusama')) {
3141
+ _context.next = 6;
3145
3142
  break;
3146
3143
  }
3147
- return _context2.abrupt("return", {
3148
- dryRunError: dryRunResult.failureReason
3149
- });
3150
- case 14:
3151
- _context2.next = 16;
3152
- return calcPaymentInfoFee();
3153
- case 16:
3154
- _context2.t1 = _context2.sent;
3155
- _context2.t2 = dryRunResult.failureReason;
3156
- return _context2.abrupt("return", {
3157
- fee: _context2.t1,
3158
- feeType: 'paymentInfo',
3159
- dryRunError: _context2.t2
3160
- });
3161
- case 19:
3162
- fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
3163
- return _context2.abrupt("return", {
3164
- fee: fee,
3165
- feeType: 'dryRun',
3166
- forwardedXcms: newForwardedXcms,
3167
- destParaId: destParaId
3168
- });
3169
- case 21:
3144
+ return _context.abrupt("return", api.getBalanceForeignBifrost(address, asset));
3145
+ case 6:
3146
+ return _context.abrupt("return", api.getBalanceForeignXTokens(node, address, asset));
3147
+ case 7:
3170
3148
  case "end":
3171
- return _context2.stop();
3149
+ return _context.stop();
3172
3150
  }
3173
- }, _callee2);
3151
+ }, _callee);
3174
3152
  }));
3175
- return function getDestXcmFee(_x) {
3153
+ return function getBalanceForeignXTokens(_x, _x2, _x3, _x4) {
3176
3154
  return _ref.apply(this, arguments);
3177
3155
  };
3178
3156
  }();
3179
3157
 
3180
- var dryRunInternal = /*#__PURE__*/function () {
3181
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3182
- var _intermediateFees$ass, _intermediateFees$bri, _destinationDryRun;
3183
- var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
3158
+ var getBalanceForeignInternal = /*#__PURE__*/function () {
3159
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3160
+ var address, node, currency, api, asset, defaultPallet;
3184
3161
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3185
3162
  while (1) switch (_context.prev = _context.next) {
3186
3163
  case 0:
3187
- origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
3188
- resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
3189
- asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
3190
- _context.next = 5;
3191
- return api.getDryRunCall({
3192
- tx: tx,
3193
- node: origin,
3194
- address: senderAddress,
3195
- isFeeAsset: !!resolvedFeeAsset
3196
- });
3197
- case 5:
3198
- originDryRun = _context.sent;
3199
- if (originDryRun.success) {
3200
- _context.next = 8;
3201
- break;
3202
- }
3203
- return _context.abrupt("return", {
3204
- origin: originDryRun
3205
- });
3206
- case 8:
3207
- initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
3208
- currentOrigin = origin;
3209
- forwardedXcms = initialForwardedXcms;
3210
- nextParaId = initialDestParaId;
3211
- intermediateFees = {};
3212
- case 13:
3213
- 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)) {
3214
- _context.next = 40;
3215
- break;
3216
- }
3217
- nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
3218
- if (nextChain) {
3219
- _context.next = 17;
3220
- break;
3221
- }
3222
- throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
3223
- case 17:
3224
- hopApi = api.clone();
3225
- _context.prev = 18;
3226
- if (assets.hasDryRunSupport(nextChain)) {
3227
- _context.next = 22;
3164
+ address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3165
+ _context.next = 3;
3166
+ return api.init(node);
3167
+ case 3:
3168
+ asset = assets.findAssetForNodeOrThrow(node, currency, null);
3169
+ defaultPallet = pallets.getDefaultPallet(node);
3170
+ if (!(defaultPallet === 'XTokens')) {
3171
+ _context.next = 9;
3228
3172
  break;
3229
3173
  }
3230
- if (nextChain === destination) {
3231
- destinationDryRun = {
3232
- success: false,
3233
- failureReason: "DryRunApi is not available on node ".concat(nextChain)
3234
- };
3235
- }
3236
- return _context.abrupt("break", 40);
3237
- case 22:
3238
- _context.next = 24;
3239
- return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
3240
- case 24:
3241
- _context.next = 26;
3242
- return hopApi.getDryRunXcm({
3243
- originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), exports.Version.V4),
3244
- xcm: forwardedXcms[1][0],
3245
- node: nextChain,
3246
- origin: currentOrigin,
3247
- asset: asset,
3248
- feeAsset: resolvedFeeAsset,
3249
- originFee: originDryRun.fee,
3250
- amount: BigInt(currency.amount)
3251
- });
3252
- case 26:
3253
- hopDryRun = _context.sent;
3254
- if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
3255
- destinationDryRun = hopDryRun;
3256
- } else if (nextChain === 'AssetHubPolkadot') {
3257
- intermediateFees.assetHub = hopDryRun;
3258
- } else if (nextChain === 'BridgeHubPolkadot') {
3259
- intermediateFees.bridgeHub = hopDryRun;
3260
- }
3261
- if (hopDryRun.success) {
3262
- _context.next = 30;
3174
+ return _context.abrupt("return", getBalanceForeignXTokens(api, node, address, asset));
3175
+ case 9:
3176
+ if (!(defaultPallet === 'PolkadotXcm')) {
3177
+ _context.next = 11;
3263
3178
  break;
3264
3179
  }
3265
- return _context.abrupt("break", 40);
3266
- case 30:
3267
- newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
3268
- forwardedXcms = newXcms;
3269
- nextParaId = destParaId;
3270
- currentOrigin = nextChain;
3271
- case 34:
3272
- _context.prev = 34;
3273
- _context.next = 37;
3274
- return hopApi.disconnect();
3275
- case 37:
3276
- return _context.finish(34);
3277
- case 38:
3278
- _context.next = 13;
3279
- break;
3280
- case 40:
3281
- return _context.abrupt("return", {
3282
- origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
3283
- currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin)
3284
- }) : originDryRun,
3285
- assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
3286
- currency: assets.getNativeAssetSymbol('AssetHubPolkadot')
3287
- }) : intermediateFees.assetHub,
3288
- bridgeHub: (_intermediateFees$bri = intermediateFees.bridgeHub) !== null && _intermediateFees$bri !== void 0 && _intermediateFees$bri.success ? _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
3289
- currency: assets.getNativeAssetSymbol('BridgeHubPolkadot')
3290
- }) : intermediateFees.bridgeHub,
3291
- destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
3292
- currency: asset.symbol
3293
- }) : destinationDryRun
3294
- });
3295
- case 41:
3180
+ return _context.abrupt("return", getBalanceForeignPolkadotXcm(api, node, address, asset));
3181
+ case 11:
3182
+ throw new InvalidParameterError('Unsupported pallet');
3183
+ case 12:
3296
3184
  case "end":
3297
3185
  return _context.stop();
3298
3186
  }
3299
- }, _callee, null, [[18,, 34, 38]]);
3187
+ }, _callee);
3300
3188
  }));
3301
- return function dryRunInternal(_x) {
3302
- return _ref.apply(this, arguments);
3189
+ return function getBalanceForeignInternal(_x) {
3190
+ return _ref2.apply(this, arguments);
3303
3191
  };
3304
3192
  }();
3305
-
3306
- var dryRun = /*#__PURE__*/function () {
3307
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3308
- var api, senderAddress, origin;
3309
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3310
- while (1) switch (_context.prev = _context.next) {
3193
+ var getBalanceForeign = /*#__PURE__*/function () {
3194
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3195
+ var api;
3196
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3197
+ while (1) switch (_context2.prev = _context2.next) {
3311
3198
  case 0:
3312
- api = options.api, senderAddress = options.senderAddress, origin = options.origin;
3313
- validateAddress(senderAddress, origin, false);
3314
- _context.next = 4;
3315
- return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
3199
+ api = options.api;
3200
+ _context2.prev = 1;
3201
+ _context2.next = 4;
3202
+ return getBalanceForeignInternal(options);
3316
3203
  case 4:
3317
- _context.prev = 4;
3318
- _context.next = 7;
3319
- return dryRunInternal(options);
3320
- case 7:
3321
- return _context.abrupt("return", _context.sent);
3322
- case 8:
3323
- _context.prev = 8;
3324
- _context.next = 11;
3204
+ return _context2.abrupt("return", _context2.sent);
3205
+ case 5:
3206
+ _context2.prev = 5;
3207
+ _context2.next = 8;
3325
3208
  return api.disconnect();
3326
- case 11:
3327
- return _context.finish(8);
3328
- case 12:
3209
+ case 8:
3210
+ return _context2.finish(5);
3211
+ case 9:
3329
3212
  case "end":
3330
- return _context.stop();
3213
+ return _context2.stop();
3331
3214
  }
3332
- }, _callee, null, [[4,, 8, 12]]);
3215
+ }, _callee2, null, [[1,, 5, 9]]);
3333
3216
  }));
3334
- return function dryRun(_x) {
3335
- return _ref.apply(this, arguments);
3217
+ return function getBalanceForeign(_x2) {
3218
+ return _ref3.apply(this, arguments);
3336
3219
  };
3337
3220
  }();
3338
3221
 
3339
- var dryRunOrigin = /*#__PURE__*/function () {
3340
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3341
- var api, node, address, result;
3222
+ var getBalanceNativeInternal = /*#__PURE__*/function () {
3223
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3224
+ var address, node, api, currency, symbol;
3342
3225
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3343
3226
  while (1) switch (_context.prev = _context.next) {
3344
3227
  case 0:
3345
- api = options.api, node = options.node, address = options.address;
3346
- validateAddress(address, node, false);
3347
- _context.next = 4;
3348
- return api.init(node, DRY_RUN_CLIENT_TIMEOUT_MS);
3349
- case 4:
3350
- _context.prev = 4;
3351
- _context.next = 7;
3352
- return api.getDryRunCall(options);
3353
- case 7:
3354
- result = _context.sent;
3355
- if (!result.success) {
3356
- _context.next = 12;
3228
+ address = _ref.address, node = _ref.node, api = _ref.api, currency = _ref.currency;
3229
+ _context.next = 3;
3230
+ return api.init(node);
3231
+ case 3:
3232
+ if (!(node === 'Interlay' || node === 'Kintsugi')) {
3233
+ _context.next = 5;
3357
3234
  break;
3358
3235
  }
3359
- return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
3360
- currency: assets.getNativeAssetSymbol(node)
3236
+ return _context.abrupt("return", getBalanceForeignInternal({
3237
+ address: address,
3238
+ node: node,
3239
+ api: api,
3240
+ currency: {
3241
+ symbol: currency ? currency.symbol : assets.getAssetsObject(node).nativeAssetSymbol
3242
+ }
3361
3243
  }));
3362
- case 12:
3363
- return _context.abrupt("return", result);
3364
- case 13:
3365
- _context.prev = 13;
3366
- _context.next = 16;
3367
- return api.disconnect();
3368
- case 16:
3369
- return _context.finish(13);
3370
- case 17:
3371
- case "end":
3372
- return _context.stop();
3373
- }
3374
- }, _callee, null, [[4,, 13, 17]]);
3375
- }));
3376
- return function dryRunOrigin(_x) {
3377
- return _ref.apply(this, arguments);
3378
- };
3379
- }();
3380
-
3381
- var getParaEthTransferFees = /*#__PURE__*/function () {
3382
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
3383
- var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
3384
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3385
- while (1) switch (_context.prev = _context.next) {
3386
- case 0:
3387
- DEFAULT_FEE = 2750872500000n;
3388
- _context.next = 3;
3389
- return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
3390
- case 3:
3391
- feeStorageItem = _context.sent;
3392
- leFeeHex = feeStorageItem.replace('0x', '');
3393
- _context.next = 7;
3394
- return ahApi.disconnect();
3395
- case 7:
3396
- bytes = leFeeHex.match(/.{1,2}/g) || [];
3397
- reversedHex = bytes.reverse().join('');
3398
- validReversedHex = reversedHex === '' ? '0' : reversedHex;
3399
- leFee = BigInt('0x' + validReversedHex);
3400
- transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
3401
- finalBridgeFee = transferBridgeFee * 110n / 100n;
3402
- finalAssethubExecutionFee = ASSET_HUB_EXECUTION_FEE * 110n / 100n;
3403
- return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
3404
- case 15:
3405
- case "end":
3406
- return _context.stop();
3407
- }
3408
- }, _callee);
3409
- }));
3410
- return function getParaEthTransferFees(_x) {
3411
- return _ref.apply(this, arguments);
3412
- };
3413
- }();
3414
-
3415
- // Inspired by Moonbeam XCM-SDK
3416
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3417
- var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3418
- if (id.startsWith('0x')) {
3419
- return id;
3420
- }
3421
- if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3422
- throw new Error("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3423
- }
3424
- return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3425
- };
3426
-
3427
- var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
3428
- var MOONBEAM_ID = 1284;
3429
- var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
3430
- var MOONRIVER_ID = 1285;
3431
- var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
3432
- function getMoonbeamErc20Balance(_x, _x2, _x3) {
3433
- return _getMoonbeamErc20Balance.apply(this, arguments);
3434
- }
3435
- function _getMoonbeamErc20Balance() {
3436
- _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
3437
- var _ref, rpc, id, provider, addr, token;
3438
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3439
- while (1) switch (_context.prev = _context.next) {
3440
- case 0:
3441
- _ref = node === 'Moonbeam' ? {
3442
- rpc: MOONBEAM_RPC,
3443
- id: MOONBEAM_ID
3444
- } : {
3445
- rpc: MOONRIVER_RPC,
3446
- id: MOONRIVER_ID
3447
- }, rpc = _ref.rpc, id = _ref.id;
3448
- provider = new ethers.ethers.JsonRpcProvider(rpc, id);
3449
- addr = formatAssetIdToERC20(assetId);
3450
- token = new ethers.ethers.Contract(addr, ERC20_ABI, provider);
3451
- _context.next = 6;
3452
- return token.balanceOf(address);
3453
- case 6:
3454
- return _context.abrupt("return", _context.sent);
3455
- case 7:
3456
- case "end":
3457
- return _context.stop();
3458
- }
3459
- }, _callee);
3460
- }));
3461
- return _getMoonbeamErc20Balance.apply(this, arguments);
3462
- }
3463
-
3464
- var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
3465
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3466
- var ASSETS_PALLET_ID, hasRequiredJunctions;
3467
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3468
- while (1) switch (_context.prev = _context.next) {
3469
- case 0:
3470
- if (!(node === 'Moonbeam' || node === 'Moonriver')) {
3471
- _context.next = 6;
3472
- break;
3473
- }
3474
- if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
3475
- _context.next = 3;
3476
- break;
3477
- }
3478
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3479
- case 3:
3480
- if (!(asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
3481
- _context.next = 5;
3482
- break;
3483
- }
3484
- return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
3485
3244
  case 5:
3486
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3487
- case 6:
3488
- if (!(node === 'Mythos')) {
3489
- _context.next = 8;
3490
- break;
3491
- }
3492
- return _context.abrupt("return", api.getMythosForeignBalance(address));
3493
- case 8:
3494
- if (assets.isForeignAsset(asset)) {
3245
+ if (!(currency && currency.symbol !== assets.getNativeAssetSymbol(node) && (node === 'Acala' || node === 'Karura'))) {
3495
3246
  _context.next = 10;
3496
3247
  break;
3497
3248
  }
3498
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3499
- case 10:
3500
- if (!(node === 'Polimec')) {
3501
- _context.next = 14;
3502
- break;
3503
- }
3504
- if (!(asset.multiLocation === undefined)) {
3505
- _context.next = 13;
3506
- break;
3507
- }
3508
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
3509
- case 13:
3510
- return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3511
- case 14:
3512
- if (!(node === 'AssetHubPolkadot')) {
3513
- _context.next = 20;
3514
- break;
3515
- }
3516
- ASSETS_PALLET_ID = 50;
3517
- hasRequiredJunctions = asset.multiLocation && sdkCommon.hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && sdkCommon.hasJunction(asset.multiLocation, 'GeneralIndex');
3518
- if (!(!asset.multiLocation || hasRequiredJunctions)) {
3519
- _context.next = 19;
3520
- break;
3521
- }
3522
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
3523
- case 19:
3524
- return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3525
- case 20:
3526
- return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
3527
- case 21:
3528
- case "end":
3529
- return _context.stop();
3530
- }
3531
- }, _callee);
3532
- }));
3533
- return function getBalanceForeignPolkadotXcm(_x, _x2, _x3, _x4) {
3534
- return _ref.apply(this, arguments);
3535
- };
3536
- }();
3537
-
3538
- var getBalanceForeignXTokens = /*#__PURE__*/function () {
3539
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3540
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3541
- while (1) switch (_context.prev = _context.next) {
3542
- case 0:
3543
- if (!(node === 'Astar' || node === 'Shiden')) {
3544
- _context.next = 4;
3545
- break;
3546
- }
3547
- if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
3548
- _context.next = 3;
3549
- break;
3550
- }
3551
- throw new assets.InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3552
- case 3:
3553
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3554
- case 4:
3555
- if (!(node === 'BifrostPolkadot' || node === 'BifrostKusama')) {
3556
- _context.next = 6;
3557
- break;
3558
- }
3559
- return _context.abrupt("return", api.getBalanceForeignBifrost(address, asset));
3560
- case 6:
3561
- return _context.abrupt("return", api.getBalanceForeignXTokens(node, address, asset));
3562
- case 7:
3563
- case "end":
3564
- return _context.stop();
3565
- }
3566
- }, _callee);
3567
- }));
3568
- return function getBalanceForeignXTokens(_x, _x2, _x3, _x4) {
3569
- return _ref.apply(this, arguments);
3570
- };
3571
- }();
3572
-
3573
- var getBalanceForeignInternal = /*#__PURE__*/function () {
3574
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3575
- var address, node, currency, api, asset, defaultPallet;
3576
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3577
- while (1) switch (_context.prev = _context.next) {
3578
- case 0:
3579
- address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3580
- _context.next = 3;
3581
- return api.init(node);
3582
- case 3:
3583
- asset = assets.findAssetForNodeOrThrow(node, currency, null);
3584
- defaultPallet = pallets.getDefaultPallet(node);
3585
- if (!(defaultPallet === 'XTokens')) {
3249
+ symbol = currency.symbol === 'aSEED' ? 'AUSD' : currency.symbol;
3250
+ if (!(symbol.toLowerCase() === 'lcdot')) {
3586
3251
  _context.next = 9;
3587
3252
  break;
3588
3253
  }
3589
- return _context.abrupt("return", getBalanceForeignXTokens(api, node, address, asset));
3254
+ throw new assets.InvalidCurrencyError('LcDOT balance is not supported');
3590
3255
  case 9:
3591
- if (!(defaultPallet === 'PolkadotXcm')) {
3592
- _context.next = 11;
3593
- break;
3594
- }
3595
- return _context.abrupt("return", getBalanceForeignPolkadotXcm(api, node, address, asset));
3256
+ return _context.abrupt("return", api.getBalanceNativeAcala(address, symbol));
3257
+ case 10:
3258
+ return _context.abrupt("return", api.getBalanceNative(address));
3596
3259
  case 11:
3597
- throw new Error('Unsupported pallet');
3598
- case 12:
3599
3260
  case "end":
3600
3261
  return _context.stop();
3601
3262
  }
3602
3263
  }, _callee);
3603
3264
  }));
3604
- return function getBalanceForeignInternal(_x) {
3265
+ return function getBalanceNativeInternal(_x) {
3605
3266
  return _ref2.apply(this, arguments);
3606
3267
  };
3607
3268
  }();
3608
- var getBalanceForeign = /*#__PURE__*/function () {
3269
+ var getBalanceNative = /*#__PURE__*/function () {
3609
3270
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3610
3271
  var api;
3611
3272
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -3614,7 +3275,7 @@ var getBalanceForeign = /*#__PURE__*/function () {
3614
3275
  api = options.api;
3615
3276
  _context2.prev = 1;
3616
3277
  _context2.next = 4;
3617
- return getBalanceForeignInternal(options);
3278
+ return getBalanceNativeInternal(options);
3618
3279
  case 4:
3619
3280
  return _context2.abrupt("return", _context2.sent);
3620
3281
  case 5:
@@ -3629,106 +3290,30 @@ var getBalanceForeign = /*#__PURE__*/function () {
3629
3290
  }
3630
3291
  }, _callee2, null, [[1,, 5, 9]]);
3631
3292
  }));
3632
- return function getBalanceForeign(_x2) {
3293
+ return function getBalanceNative(_x2) {
3633
3294
  return _ref3.apply(this, arguments);
3634
3295
  };
3635
3296
  }();
3636
3297
 
3637
- var getBalanceNativeInternal = /*#__PURE__*/function () {
3298
+ var getAssetBalanceInternal = /*#__PURE__*/function () {
3638
3299
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3639
- var address, node, api, currency, symbol;
3300
+ var _yield$getBalanceFore;
3301
+ var address, node, currency, api, asset, isNativeSymbol;
3640
3302
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3641
3303
  while (1) switch (_context.prev = _context.next) {
3642
3304
  case 0:
3643
- address = _ref.address, node = _ref.node, api = _ref.api, currency = _ref.currency;
3305
+ address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3644
3306
  _context.next = 3;
3645
3307
  return api.init(node);
3646
3308
  case 3:
3647
- if (!(node === 'Interlay' || node === 'Kintsugi')) {
3648
- _context.next = 5;
3309
+ asset = assets.findAssetForNodeOrThrow(node, currency, null);
3310
+ isNativeSymbol = asset.symbol === assets.getNativeAssetSymbol(node);
3311
+ if (!(isNativeSymbol && node !== 'Interlay' && node !== 'Kintsugi')) {
3312
+ _context.next = 11;
3649
3313
  break;
3650
3314
  }
3651
- return _context.abrupt("return", getBalanceForeignInternal({
3652
- address: address,
3653
- node: node,
3654
- api: api,
3655
- currency: {
3656
- symbol: currency ? currency.symbol : assets.getAssetsObject(node).nativeAssetSymbol
3657
- }
3658
- }));
3659
- case 5:
3660
- if (!(currency && currency.symbol !== assets.getNativeAssetSymbol(node) && (node === 'Acala' || node === 'Karura'))) {
3661
- _context.next = 10;
3662
- break;
3663
- }
3664
- symbol = currency.symbol === 'aSEED' ? 'AUSD' : currency.symbol;
3665
- if (!(symbol.toLowerCase() === 'lcdot')) {
3666
- _context.next = 9;
3667
- break;
3668
- }
3669
- throw new assets.InvalidCurrencyError('LcDOT balance is not supported');
3670
- case 9:
3671
- return _context.abrupt("return", api.getBalanceNativeAcala(address, symbol));
3672
- case 10:
3673
- return _context.abrupt("return", api.getBalanceNative(address));
3674
- case 11:
3675
- case "end":
3676
- return _context.stop();
3677
- }
3678
- }, _callee);
3679
- }));
3680
- return function getBalanceNativeInternal(_x) {
3681
- return _ref2.apply(this, arguments);
3682
- };
3683
- }();
3684
- var getBalanceNative = /*#__PURE__*/function () {
3685
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3686
- var api;
3687
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3688
- while (1) switch (_context2.prev = _context2.next) {
3689
- case 0:
3690
- api = options.api;
3691
- _context2.prev = 1;
3692
- _context2.next = 4;
3693
- return getBalanceNativeInternal(options);
3694
- case 4:
3695
- return _context2.abrupt("return", _context2.sent);
3696
- case 5:
3697
- _context2.prev = 5;
3698
- _context2.next = 8;
3699
- return api.disconnect();
3700
- case 8:
3701
- return _context2.finish(5);
3702
- case 9:
3703
- case "end":
3704
- return _context2.stop();
3705
- }
3706
- }, _callee2, null, [[1,, 5, 9]]);
3707
- }));
3708
- return function getBalanceNative(_x2) {
3709
- return _ref3.apply(this, arguments);
3710
- };
3711
- }();
3712
-
3713
- var getAssetBalanceInternal = /*#__PURE__*/function () {
3714
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3715
- var _yield$getBalanceFore;
3716
- var address, node, currency, api, asset, isNativeSymbol;
3717
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3718
- while (1) switch (_context.prev = _context.next) {
3719
- case 0:
3720
- address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3721
- _context.next = 3;
3722
- return api.init(node);
3723
- case 3:
3724
- asset = assets.findAssetForNodeOrThrow(node, currency, null);
3725
- isNativeSymbol = asset.symbol === assets.getNativeAssetSymbol(node);
3726
- if (!(isNativeSymbol && node !== 'Interlay' && node !== 'Kintsugi')) {
3727
- _context.next = 11;
3728
- break;
3729
- }
3730
- _context.next = 8;
3731
- return getBalanceNativeInternal({
3315
+ _context.next = 8;
3316
+ return getBalanceNativeInternal({
3732
3317
  address: address,
3733
3318
  node: node,
3734
3319
  api: api
@@ -3939,13 +3524,13 @@ var transferMoonbeamEvm = /*#__PURE__*/function () {
3939
3524
  _context.next = 3;
3940
3525
  break;
3941
3526
  }
3942
- throw new Error('Multiassets syntax is not supported for Evm transfers');
3527
+ throw new InvalidParameterError('Multiassets syntax is not supported for Evm transfers');
3943
3528
  case 3:
3944
3529
  if (!('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation))) {
3945
3530
  _context.next = 5;
3946
3531
  break;
3947
3532
  }
3948
- throw new Error('Override multilocation is not supported for Evm transfers');
3533
+ throw new InvalidParameterError('Override multilocation is not supported for Evm transfers');
3949
3534
  case 5:
3950
3535
  contract = isEthersSigner(signer) ? new ethers.Contract(CONTRACT_ADDRESS, abi$1, signer) : viem.getContract({
3951
3536
  abi: abi$1,
@@ -4251,163 +3836,614 @@ var abi = [
4251
3836
  }
4252
3837
  ];
4253
3838
 
4254
- // https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
4255
- var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
4256
- var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
4257
- var transferMoonbeamToEth = /*#__PURE__*/function () {
4258
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
4259
- var _signer$account;
4260
- var api, from, to, signer, address, ahAddress, currency, bridgeStatus, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
3839
+ // https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
3840
+ var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
3841
+ var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
3842
+ var transferMoonbeamToEth = /*#__PURE__*/function () {
3843
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3844
+ var _signer$account;
3845
+ var api, from, to, signer, address, ahAddress, currency, bridgeStatus, foundAsset, ethAsset, contract, senderAddress, messageId, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
3846
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3847
+ while (1) switch (_context.prev = _context.next) {
3848
+ case 0:
3849
+ api = _ref.api, from = _ref.from, to = _ref.to, signer = _ref.signer, address = _ref.address, ahAddress = _ref.ahAddress, currency = _ref.currency;
3850
+ if (ahAddress) {
3851
+ _context.next = 3;
3852
+ break;
3853
+ }
3854
+ throw new InvalidParameterError('AssetHub address is required');
3855
+ case 3:
3856
+ _context.next = 5;
3857
+ return getBridgeStatus(api.clone());
3858
+ case 5:
3859
+ bridgeStatus = _context.sent;
3860
+ if (!(bridgeStatus !== 'Normal')) {
3861
+ _context.next = 8;
3862
+ break;
3863
+ }
3864
+ throw new BridgeHaltedError();
3865
+ case 8:
3866
+ if (!('multiasset' in currency)) {
3867
+ _context.next = 10;
3868
+ break;
3869
+ }
3870
+ throw new InvalidParameterError('Multiassets syntax is not supported for Evm transfers');
3871
+ case 10:
3872
+ if (!('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation))) {
3873
+ _context.next = 12;
3874
+ break;
3875
+ }
3876
+ throw new InvalidParameterError('Override multilocation is not supported for Evm transfers');
3877
+ case 12:
3878
+ foundAsset = assets.findAsset(from, currency, to);
3879
+ if (!(foundAsset === null)) {
3880
+ _context.next = 15;
3881
+ break;
3882
+ }
3883
+ throw new assets.InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
3884
+ case 15:
3885
+ if (!(!assets.isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
3886
+ _context.next = 17;
3887
+ break;
3888
+ }
3889
+ throw new assets.InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
3890
+ case 17:
3891
+ ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), foundAsset.multiLocation);
3892
+ if (!(!ethAsset || !ethAsset.assetId)) {
3893
+ _context.next = 20;
3894
+ break;
3895
+ }
3896
+ throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
3897
+ case 20:
3898
+ contract = isEthersSigner(signer) ? new ethers.Contract(xcmInterfacePrecompile, abi, signer) : viem.getContract({
3899
+ abi: abi,
3900
+ address: xcmInterfacePrecompile,
3901
+ client: {
3902
+ "public": viem.createPublicClient({
3903
+ chain: signer.chain,
3904
+ transport: viem.http()
3905
+ }),
3906
+ wallet: signer
3907
+ }
3908
+ });
3909
+ if (!isEthersSigner(signer)) {
3910
+ _context.next = 27;
3911
+ break;
3912
+ }
3913
+ _context.next = 24;
3914
+ return signer.getAddress();
3915
+ case 24:
3916
+ _context.t0 = _context.sent;
3917
+ _context.next = 28;
3918
+ break;
3919
+ case 27:
3920
+ _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
3921
+ case 28:
3922
+ senderAddress = _context.t0;
3923
+ if (senderAddress) {
3924
+ _context.next = 31;
3925
+ break;
3926
+ }
3927
+ throw new InvalidParameterError('Unable to get sender address');
3928
+ case 31:
3929
+ _context.next = 33;
3930
+ return api.init(from, TX_CLIENT_TIMEOUT_MS);
3931
+ case 33:
3932
+ _context.next = 35;
3933
+ return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
3934
+ case 35:
3935
+ messageId = _context.sent;
3936
+ customXcm = createCustomXcmOnDest({
3937
+ api: api,
3938
+ address: address,
3939
+ scenario: 'ParaToPara',
3940
+ senderAddress: senderAddress,
3941
+ ahAddress: ahAddress,
3942
+ asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
3943
+ amount: currency.amount
3944
+ })}, from, exports.Version.V4, messageId);
3945
+ _context.next = 39;
3946
+ return api.objectToHex(customXcm, 'XcmVersionedXcm');
3947
+ case 39:
3948
+ customXcmOnDest = _context.sent;
3949
+ _context.next = 42;
3950
+ return api.createApiForNode('AssetHubPolkadot');
3951
+ case 42:
3952
+ assetHubApi = _context.sent;
3953
+ _context.next = 45;
3954
+ return getParaEthTransferFees(assetHubApi);
3955
+ case 45:
3956
+ _yield$getParaEthTran = _context.sent;
3957
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
3958
+ bridgeFee = _yield$getParaEthTran2[0];
3959
+ executionFee = _yield$getParaEthTran2[1];
3960
+ transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
3961
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
3962
+ createTx = function createTx(func, args) {
3963
+ if (isEthersContract(contract)) {
3964
+ return contract[func].apply(contract, _toConsumableArray(args));
3965
+ }
3966
+ return contract.write[func](args);
3967
+ };
3968
+ numberToHex32 = function numberToHex32(num) {
3969
+ return typeof num !== 'number' || isNaN(num) ? function () {
3970
+ throw new InvalidParameterError('Input must be a valid number');
3971
+ }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
3972
+ }; // Execute the custom XCM message with the precompile
3973
+ _context.next = 54;
3974
+ return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
3975
+ // This represents (1,X1(Parachain(1000)))
3976
+ [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
3977
+ // Assets including fee and the ERC20 asset, with fee be the first
3978
+ [[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
3979
+ // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
3980
+ 2,
3981
+ // index for the fee
3982
+ 0,
3983
+ // The TransferType corresponding to fee asset
3984
+ 2, customXcmOnDest]);
3985
+ case 54:
3986
+ tx = _context.sent;
3987
+ return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
3988
+ case 56:
3989
+ case "end":
3990
+ return _context.stop();
3991
+ }
3992
+ }, _callee);
3993
+ }));
3994
+ return function transferMoonbeamToEth(_x) {
3995
+ return _ref2.apply(this, arguments);
3996
+ };
3997
+ }();
3998
+
3999
+ var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
4000
+ var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
4001
+ var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
4002
+ if (!asset && !usesRawOverriddenMultiAssets) {
4003
+ throwUnsupportedCurrency(feeAsset, origin);
4004
+ }
4005
+ return asset !== null && asset !== void 0 ? asset : undefined;
4006
+ };
4007
+
4008
+ var isAssetHub = function isAssetHub(chain) {
4009
+ return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
4010
+ };
4011
+ var isBridgeHub = function isBridgeHub(chain) {
4012
+ return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
4013
+ };
4014
+ var isPeople = function isPeople(chain) {
4015
+ return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
4016
+ };
4017
+ var isSystemPara = function isSystemPara(chain) {
4018
+ return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
4019
+ };
4020
+ var mul = function mul(v, num) {
4021
+ var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
4022
+ return v * num / den;
4023
+ };
4024
+ var padFee = function padFee(raw, origin, dest, side) {
4025
+ var relayOrigin = sdkCommon.isRelayChain(origin);
4026
+ var relayDest = sdkCommon.isRelayChain(dest);
4027
+ var sysParaOrigin = isSystemPara(origin);
4028
+ var sysParaDest = isSystemPara(dest);
4029
+ var relayToPara = relayOrigin && !relayDest;
4030
+ var sysParaToPara = sysParaOrigin && !sysParaDest;
4031
+ var paraToPara = !relayOrigin && !sysParaOrigin;
4032
+ if (sysParaToPara) return raw * 40n;
4033
+ if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
4034
+ if (paraToPara) return mul(raw, 130n, 100n);
4035
+ // apply default 30% padding
4036
+ return mul(raw, 130n, 100n);
4037
+ };
4038
+
4039
+ var getReverseTxFee = /*#__PURE__*/function () {
4040
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
4041
+ var api, origin, destination, senderAddress, address, currency, tx, rawFee;
4042
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4043
+ while (1) switch (_context.prev = _context.next) {
4044
+ case 0:
4045
+ api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
4046
+ if (!('multiasset' in currency)) {
4047
+ _context.next = 3;
4048
+ break;
4049
+ }
4050
+ throw new assets.InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
4051
+ case 3:
4052
+ _context.next = 5;
4053
+ return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
4054
+ amount: currency.amount
4055
+ })).build();
4056
+ case 5:
4057
+ tx = _context.sent;
4058
+ _context.next = 8;
4059
+ return api.calculateTransactionFee(tx, address);
4060
+ case 8:
4061
+ rawFee = _context.sent;
4062
+ return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
4063
+ case 10:
4064
+ case "end":
4065
+ return _context.stop();
4066
+ }
4067
+ }, _callee);
4068
+ }));
4069
+ return function getReverseTxFee(_x, _x2) {
4070
+ return _ref2.apply(this, arguments);
4071
+ };
4072
+ }();
4073
+
4074
+ var createOriginLocation = function createOriginLocation(origin, destination) {
4075
+ if (sdkCommon.isRelayChain(origin)) return DOT_MULTILOCATION;
4076
+ return {
4077
+ parents: sdkCommon.isRelayChain(destination) ? sdkCommon.Parents.ZERO : sdkCommon.Parents.ONE,
4078
+ interior: {
4079
+ X1: [{
4080
+ Parachain: getParaId(origin)
4081
+ }]
4082
+ }
4083
+ };
4084
+ };
4085
+ var getDestXcmFee = /*#__PURE__*/function () {
4086
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
4087
+ var api, origin, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
4088
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4089
+ while (1) switch (_context2.prev = _context2.next) {
4090
+ case 0:
4091
+ api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
4092
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4093
+ calcPaymentInfoFee = /*#__PURE__*/function () {
4094
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4095
+ var originAsset;
4096
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4097
+ while (1) switch (_context.prev = _context.next) {
4098
+ case 0:
4099
+ if (!(destination === 'Ethereum')) {
4100
+ _context.next = 2;
4101
+ break;
4102
+ }
4103
+ return _context.abrupt("return", 0n);
4104
+ case 2:
4105
+ originAsset = assets.findAsset(origin, currency, destination);
4106
+ if (originAsset) {
4107
+ _context.next = 5;
4108
+ break;
4109
+ }
4110
+ throw new assets.InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
4111
+ case 5:
4112
+ if (!originAsset.multiLocation) {
4113
+ _context.next = 19;
4114
+ break;
4115
+ }
4116
+ _context.prev = 6;
4117
+ _context.next = 9;
4118
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4119
+ destination: destination
4120
+ }), {
4121
+ multilocation: originAsset.multiLocation
4122
+ });
4123
+ case 9:
4124
+ return _context.abrupt("return", _context.sent);
4125
+ case 12:
4126
+ _context.prev = 12;
4127
+ _context.t0 = _context["catch"](6);
4128
+ if (!(_context.t0 instanceof assets.InvalidCurrencyError)) {
4129
+ _context.next = 18;
4130
+ break;
4131
+ }
4132
+ _context.next = 17;
4133
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4134
+ destination: destination
4135
+ }), {
4136
+ symbol: originAsset.symbol
4137
+ });
4138
+ case 17:
4139
+ return _context.abrupt("return", _context.sent);
4140
+ case 18:
4141
+ throw _context.t0;
4142
+ case 19:
4143
+ _context.next = 21;
4144
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4145
+ destination: destination
4146
+ }), {
4147
+ symbol: originAsset.symbol
4148
+ });
4149
+ case 21:
4150
+ return _context.abrupt("return", _context.sent);
4151
+ case 22:
4152
+ case "end":
4153
+ return _context.stop();
4154
+ }
4155
+ }, _callee, null, [[6, 12]]);
4156
+ }));
4157
+ return function calcPaymentInfoFee() {
4158
+ return _ref2.apply(this, arguments);
4159
+ };
4160
+ }();
4161
+ if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
4162
+ _context2.next = 8;
4163
+ break;
4164
+ }
4165
+ _context2.next = 6;
4166
+ return calcPaymentInfoFee();
4167
+ case 6:
4168
+ _context2.t0 = _context2.sent;
4169
+ return _context2.abrupt("return", {
4170
+ fee: _context2.t0,
4171
+ feeType: 'paymentInfo'
4172
+ });
4173
+ case 8:
4174
+ _context2.next = 10;
4175
+ return api.getDryRunXcm({
4176
+ originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), exports.Version.V4),
4177
+ xcm: forwardedXcms[1][0],
4178
+ node: destination,
4179
+ origin: origin,
4180
+ asset: asset,
4181
+ originFee: originFee,
4182
+ feeAsset: resolvedFeeAsset,
4183
+ amount: BigInt(currency.amount)
4184
+ });
4185
+ case 10:
4186
+ dryRunResult = _context2.sent;
4187
+ if (dryRunResult.success) {
4188
+ _context2.next = 19;
4189
+ break;
4190
+ }
4191
+ if (!disableFallback) {
4192
+ _context2.next = 14;
4193
+ break;
4194
+ }
4195
+ return _context2.abrupt("return", {
4196
+ dryRunError: dryRunResult.failureReason
4197
+ });
4198
+ case 14:
4199
+ _context2.next = 16;
4200
+ return calcPaymentInfoFee();
4201
+ case 16:
4202
+ _context2.t1 = _context2.sent;
4203
+ _context2.t2 = dryRunResult.failureReason;
4204
+ return _context2.abrupt("return", {
4205
+ fee: _context2.t1,
4206
+ feeType: 'paymentInfo',
4207
+ dryRunError: _context2.t2
4208
+ });
4209
+ case 19:
4210
+ fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
4211
+ return _context2.abrupt("return", {
4212
+ fee: fee,
4213
+ feeType: 'dryRun',
4214
+ forwardedXcms: newForwardedXcms,
4215
+ destParaId: destParaId
4216
+ });
4217
+ case 21:
4218
+ case "end":
4219
+ return _context2.stop();
4220
+ }
4221
+ }, _callee2);
4222
+ }));
4223
+ return function getDestXcmFee(_x) {
4224
+ return _ref.apply(this, arguments);
4225
+ };
4226
+ }();
4227
+
4228
+ var dryRunInternal = /*#__PURE__*/function () {
4229
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4230
+ var _intermediateFees$bri, _intermediateFees$ass, _processedBridgeHubDa, _destinationDryRun;
4231
+ var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee;
4261
4232
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4262
4233
  while (1) switch (_context.prev = _context.next) {
4263
4234
  case 0:
4264
- api = _ref.api, from = _ref.from, to = _ref.to, signer = _ref.signer, address = _ref.address, ahAddress = _ref.ahAddress, currency = _ref.currency;
4265
- if (ahAddress) {
4266
- _context.next = 3;
4267
- break;
4268
- }
4269
- throw new Error('AssetHub address is required');
4270
- case 3:
4235
+ origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
4236
+ resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4237
+ asset = 'multiasset' in currency ? null : assets.findAssetForNodeOrThrow(origin, currency, destination);
4271
4238
  _context.next = 5;
4272
- return getBridgeStatus(api.clone());
4239
+ return api.getDryRunCall({
4240
+ tx: tx,
4241
+ node: origin,
4242
+ address: senderAddress,
4243
+ isFeeAsset: !!resolvedFeeAsset
4244
+ });
4273
4245
  case 5:
4274
- bridgeStatus = _context.sent;
4275
- if (!(bridgeStatus !== 'Normal')) {
4246
+ originDryRun = _context.sent;
4247
+ if (originDryRun.success) {
4276
4248
  _context.next = 8;
4277
4249
  break;
4278
4250
  }
4279
- throw new BridgeHaltedError();
4251
+ return _context.abrupt("return", {
4252
+ origin: originDryRun
4253
+ });
4280
4254
  case 8:
4281
- if (!('multiasset' in currency)) {
4282
- _context.next = 10;
4283
- break;
4284
- }
4285
- throw new Error('Multiassets syntax is not supported for Evm transfers');
4286
- case 10:
4287
- if (!('multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation))) {
4288
- _context.next = 12;
4289
- break;
4290
- }
4291
- throw new Error('Override multilocation is not supported for Evm transfers');
4292
- case 12:
4293
- foundAsset = assets.findAsset(from, currency, to);
4294
- if (!(foundAsset === null)) {
4295
- _context.next = 15;
4296
- break;
4297
- }
4298
- throw new assets.InvalidCurrencyError("Origin node ".concat(from, " does not support currency ").concat(JSON.stringify(currency), "."));
4255
+ initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
4256
+ assetHubNode = determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama';
4257
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
4258
+ currentOrigin = origin;
4259
+ forwardedXcms = initialForwardedXcms;
4260
+ nextParaId = initialDestParaId;
4261
+ intermediateFees = {};
4299
4262
  case 15:
4300
- if (!(!assets.isForeignAsset(foundAsset) || !foundAsset.multiLocation)) {
4301
- _context.next = 17;
4263
+ 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)) {
4264
+ _context.next = 42;
4302
4265
  break;
4303
4266
  }
4304
- throw new assets.InvalidCurrencyError('Currency must be a foreign asset with valid multi-location');
4305
- case 17:
4306
- ethAsset = assets.findAssetByMultiLocation(assets.getOtherAssets('Ethereum'), foundAsset.multiLocation);
4307
- if (!(!ethAsset || !ethAsset.assetId)) {
4308
- _context.next = 20;
4267
+ nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
4268
+ if (nextChain) {
4269
+ _context.next = 19;
4309
4270
  break;
4310
4271
  }
4311
- throw new assets.InvalidCurrencyError("Could not obtain Ethereum asset address for ".concat(JSON.stringify(foundAsset)));
4312
- case 20:
4313
- contract = isEthersSigner(signer) ? new ethers.Contract(xcmInterfacePrecompile, abi, signer) : viem.getContract({
4314
- abi: abi,
4315
- address: xcmInterfacePrecompile,
4316
- client: {
4317
- "public": viem.createPublicClient({
4318
- chain: signer.chain,
4319
- transport: viem.http()
4320
- }),
4321
- wallet: signer
4322
- }
4323
- });
4324
- if (!isEthersSigner(signer)) {
4325
- _context.next = 27;
4272
+ throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
4273
+ case 19:
4274
+ hopApi = api.clone();
4275
+ _context.prev = 20;
4276
+ if (assets.hasDryRunSupport(nextChain)) {
4277
+ _context.next = 24;
4326
4278
  break;
4327
4279
  }
4328
- _context.next = 24;
4329
- return signer.getAddress();
4280
+ if (nextChain === destination) {
4281
+ destinationDryRun = {
4282
+ success: false,
4283
+ failureReason: "DryRunApi is not available on node ".concat(nextChain)
4284
+ };
4285
+ }
4286
+ return _context.abrupt("break", 42);
4330
4287
  case 24:
4331
- _context.t0 = _context.sent;
4288
+ _context.next = 26;
4289
+ return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
4290
+ case 26:
4332
4291
  _context.next = 28;
4333
- break;
4334
- case 27:
4335
- _context.t0 = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
4292
+ return hopApi.getDryRunXcm({
4293
+ originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), exports.Version.V4),
4294
+ xcm: forwardedXcms[1][0],
4295
+ node: nextChain,
4296
+ origin: currentOrigin,
4297
+ asset: asset,
4298
+ feeAsset: resolvedFeeAsset,
4299
+ originFee: originDryRun.fee,
4300
+ amount: BigInt(currency.amount)
4301
+ });
4336
4302
  case 28:
4337
- senderAddress = _context.t0;
4338
- if (senderAddress) {
4339
- _context.next = 31;
4303
+ hopDryRun = _context.sent;
4304
+ if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
4305
+ destinationDryRun = hopDryRun;
4306
+ } else if (nextChain === assetHubNode) {
4307
+ intermediateFees.assetHub = hopDryRun;
4308
+ } else if (nextChain === bridgeHubNode) {
4309
+ intermediateFees.bridgeHub = hopDryRun;
4310
+ }
4311
+ if (hopDryRun.success) {
4312
+ _context.next = 32;
4340
4313
  break;
4341
4314
  }
4342
- throw new Error('Unable to get sender address');
4343
- case 31:
4344
- _context.next = 33;
4345
- return api.init(from, TX_CLIENT_TIMEOUT_MS);
4346
- case 33:
4347
- _context.next = 35;
4348
- return generateMessageId(api, senderAddress, getParaId(from), ethAsset.assetId, address, currency.amount);
4349
- case 35:
4350
- messageId = _context.sent;
4351
- customXcm = createCustomXcmOnDest({
4352
- api: api,
4353
- address: address,
4354
- scenario: 'ParaToPara',
4355
- senderAddress: senderAddress,
4356
- ahAddress: ahAddress,
4357
- asset: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
4358
- amount: currency.amount
4359
- })}, from, exports.Version.V4, messageId);
4315
+ return _context.abrupt("break", 42);
4316
+ case 32:
4317
+ newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
4318
+ forwardedXcms = newXcms;
4319
+ nextParaId = destParaId;
4320
+ currentOrigin = nextChain;
4321
+ case 36:
4322
+ _context.prev = 36;
4360
4323
  _context.next = 39;
4361
- return api.objectToHex(customXcm, 'XcmVersionedXcm');
4324
+ return hopApi.disconnect();
4362
4325
  case 39:
4363
- customXcmOnDest = _context.sent;
4364
- _context.next = 42;
4365
- return api.createApiForNode('AssetHubPolkadot');
4326
+ return _context.finish(36);
4327
+ case 40:
4328
+ _context.next = 15;
4329
+ break;
4366
4330
  case 42:
4367
- assetHubApi = _context.sent;
4368
- _context.next = 45;
4369
- return getParaEthTransferFees(assetHubApi);
4370
- case 45:
4331
+ processedBridgeHubData = intermediateFees.bridgeHub;
4332
+ if (!((_intermediateFees$bri = intermediateFees.bridgeHub) !== null && _intermediateFees$bri !== void 0 && _intermediateFees$bri.success && destination === 'Ethereum')) {
4333
+ _context.next = 53;
4334
+ break;
4335
+ }
4336
+ ahApi = api.clone();
4337
+ _context.next = 47;
4338
+ return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
4339
+ case 47:
4340
+ _context.next = 49;
4341
+ return getParaEthTransferFees(ahApi);
4342
+ case 49:
4371
4343
  _yield$getParaEthTran = _context.sent;
4372
- _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
4344
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
4373
4345
  bridgeFee = _yield$getParaEthTran2[0];
4374
- executionFee = _yield$getParaEthTran2[1];
4375
- transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
4376
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
4377
- createTx = function createTx(func, args) {
4378
- if (isEthersContract(contract)) {
4379
- return contract[func].apply(contract, _toConsumableArray(args));
4380
- }
4381
- return contract.write[func](args);
4382
- };
4383
- numberToHex32 = function numberToHex32(num) {
4384
- return typeof num !== 'number' || isNaN(num) ? function () {
4385
- throw new Error('Input must be a valid number');
4386
- }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
4387
- }; // Execute the custom XCM message with the precompile
4388
- _context.next = 54;
4389
- return createTx(isEthersSigner(signer) ? 'transferAssetsUsingTypeAndThenAddress((uint8,bytes[]),(address,uint256)[],uint8,uint8,uint8,bytes)' : 'transferAssetsUsingTypeAndThenAddress', [
4390
- // This represents (1,X1(Parachain(1000)))
4391
- [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
4392
- // Assets including fee and the ERC20 asset, with fee be the first
4393
- [[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
4394
- // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
4395
- 2,
4396
- // index for the fee
4397
- 0,
4398
- // The TransferType corresponding to fee asset
4399
- 2, customXcmOnDest]);
4346
+ processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
4347
+ fee: intermediateFees.bridgeHub.fee + bridgeFee
4348
+ });
4349
+ case 53:
4350
+ return _context.abrupt("return", {
4351
+ origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
4352
+ currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin)
4353
+ }) : originDryRun,
4354
+ assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
4355
+ currency: assets.getNativeAssetSymbol(assetHubNode)
4356
+ }) : intermediateFees.assetHub,
4357
+ bridgeHub: (_processedBridgeHubDa = processedBridgeHubData) !== null && _processedBridgeHubDa !== void 0 && _processedBridgeHubDa.success ? _objectSpread2(_objectSpread2({}, processedBridgeHubData), {}, {
4358
+ currency: assets.getNativeAssetSymbol(bridgeHubNode)
4359
+ }) : processedBridgeHubData,
4360
+ destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
4361
+ currency: asset === null || asset === void 0 ? void 0 : asset.symbol
4362
+ }) : destinationDryRun
4363
+ });
4400
4364
  case 54:
4401
- tx = _context.sent;
4402
- return _context.abrupt("return", _typeof(tx) === 'object' ? tx.hash : tx);
4403
- case 56:
4404
4365
  case "end":
4405
4366
  return _context.stop();
4406
4367
  }
4407
- }, _callee);
4368
+ }, _callee, null, [[20,, 36, 40]]);
4369
+ }));
4370
+ return function dryRunInternal(_x) {
4371
+ return _ref.apply(this, arguments);
4372
+ };
4373
+ }();
4374
+
4375
+ var dryRun = /*#__PURE__*/function () {
4376
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4377
+ var api, senderAddress, origin;
4378
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4379
+ while (1) switch (_context.prev = _context.next) {
4380
+ case 0:
4381
+ api = options.api, senderAddress = options.senderAddress, origin = options.origin;
4382
+ validateAddress(senderAddress, origin, false);
4383
+ _context.next = 4;
4384
+ return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
4385
+ case 4:
4386
+ _context.prev = 4;
4387
+ _context.next = 7;
4388
+ return dryRunInternal(options);
4389
+ case 7:
4390
+ return _context.abrupt("return", _context.sent);
4391
+ case 8:
4392
+ _context.prev = 8;
4393
+ _context.next = 11;
4394
+ return api.disconnect();
4395
+ case 11:
4396
+ return _context.finish(8);
4397
+ case 12:
4398
+ case "end":
4399
+ return _context.stop();
4400
+ }
4401
+ }, _callee, null, [[4,, 8, 12]]);
4402
+ }));
4403
+ return function dryRun(_x) {
4404
+ return _ref.apply(this, arguments);
4405
+ };
4406
+ }();
4407
+
4408
+ var dryRunOrigin = /*#__PURE__*/function () {
4409
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4410
+ var api, node, address, result;
4411
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4412
+ while (1) switch (_context.prev = _context.next) {
4413
+ case 0:
4414
+ api = options.api, node = options.node, address = options.address;
4415
+ validateAddress(address, node, false);
4416
+ _context.next = 4;
4417
+ return api.init(node, DRY_RUN_CLIENT_TIMEOUT_MS);
4418
+ case 4:
4419
+ _context.prev = 4;
4420
+ _context.next = 7;
4421
+ return api.getDryRunCall(options);
4422
+ case 7:
4423
+ result = _context.sent;
4424
+ if (!result.success) {
4425
+ _context.next = 12;
4426
+ break;
4427
+ }
4428
+ return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
4429
+ currency: assets.getNativeAssetSymbol(node)
4430
+ }));
4431
+ case 12:
4432
+ return _context.abrupt("return", result);
4433
+ case 13:
4434
+ _context.prev = 13;
4435
+ _context.next = 16;
4436
+ return api.disconnect();
4437
+ case 16:
4438
+ return _context.finish(13);
4439
+ case 17:
4440
+ case "end":
4441
+ return _context.stop();
4442
+ }
4443
+ }, _callee, null, [[4,, 13, 17]]);
4408
4444
  }));
4409
- return function transferMoonbeamToEth(_x) {
4410
- return _ref2.apply(this, arguments);
4445
+ return function dryRunOrigin(_x) {
4446
+ return _ref.apply(this, arguments);
4411
4447
  };
4412
4448
  }();
4413
4449
 
@@ -4517,7 +4553,7 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
4517
4553
 
4518
4554
  var getXcmFee = /*#__PURE__*/function () {
4519
4555
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
4520
- var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback;
4556
+ var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee;
4521
4557
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4522
4558
  while (1) switch (_context.prev = _context.next) {
4523
4559
  case 0:
@@ -4547,16 +4583,20 @@ var getXcmFee = /*#__PURE__*/function () {
4547
4583
  return api.disconnect();
4548
4584
  case 14:
4549
4585
  if (!(originDryRunError || originFeeType === 'paymentInfo')) {
4550
- _context.next = 29;
4586
+ _context.next = 30;
4551
4587
  break;
4552
4588
  }
4553
4589
  destApi = api.clone();
4554
4590
  _context.prev = 16;
4555
- _context.next = 19;
4591
+ if (!(destination !== 'Ethereum')) {
4592
+ _context.next = 20;
4593
+ break;
4594
+ }
4595
+ _context.next = 20;
4556
4596
  return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4557
- case 19:
4597
+ case 20:
4558
4598
  destApi.setDisconnectAllowed(false);
4559
- _context.next = 22;
4599
+ _context.next = 23;
4560
4600
  return getDestXcmFee({
4561
4601
  api: destApi,
4562
4602
  forwardedXcms: undefined,
@@ -4570,7 +4610,7 @@ var getXcmFee = /*#__PURE__*/function () {
4570
4610
  senderAddress: senderAddress,
4571
4611
  disableFallback: disableFallback
4572
4612
  });
4573
- case 22:
4613
+ case 23:
4574
4614
  destFeeRes = _context.sent;
4575
4615
  return _context.abrupt("return", {
4576
4616
  origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
@@ -4582,46 +4622,50 @@ var getXcmFee = /*#__PURE__*/function () {
4582
4622
  }, originDryRunError && {
4583
4623
  dryRunError: originDryRunError
4584
4624
  }),
4585
- destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
4625
+ destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee ? {
4586
4626
  fee: destFeeRes.fee
4627
+ } : {
4628
+ fee: 0n
4587
4629
  }), destFeeRes.feeType && {
4588
4630
  feeType: destFeeRes.feeType
4589
4631
  }), {}, {
4590
4632
  currency: assets.getNativeAssetSymbol(destination)
4591
4633
  })
4592
4634
  });
4593
- case 24:
4594
- _context.prev = 24;
4635
+ case 25:
4636
+ _context.prev = 25;
4595
4637
  destApi.setDisconnectAllowed(true);
4596
- _context.next = 28;
4638
+ _context.next = 29;
4597
4639
  return destApi.disconnect();
4598
- case 28:
4599
- return _context.finish(24);
4600
4640
  case 29:
4641
+ return _context.finish(25);
4642
+ case 30:
4643
+ assetHubNode = determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama';
4644
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
4601
4645
  currentOrigin = origin;
4602
4646
  forwardedXcms = initialForwardedXcm;
4603
4647
  nextParaId = initialDestParaId;
4604
4648
  intermediateFees = {};
4605
4649
  destinationFee = 0n;
4606
- destinationFeeType = 'paymentInfo';
4607
- case 35:
4650
+ destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
4651
+ case 38:
4608
4652
  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)) {
4609
- _context.next = 67;
4653
+ _context.next = 70;
4610
4654
  break;
4611
4655
  }
4612
4656
  nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
4613
4657
  if (!(nextChain === null)) {
4614
- _context.next = 39;
4658
+ _context.next = 42;
4615
4659
  break;
4616
4660
  }
4617
- throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
4618
- case 39:
4661
+ throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
4662
+ case 42:
4619
4663
  hopApi = api.clone();
4620
- _context.prev = 40;
4621
- _context.next = 43;
4664
+ _context.prev = 43;
4665
+ _context.next = 46;
4622
4666
  return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
4623
- case 43:
4624
- _context.next = 45;
4667
+ case 46:
4668
+ _context.next = 48;
4625
4669
  return getDestXcmFee({
4626
4670
  api: hopApi,
4627
4671
  forwardedXcms: forwardedXcms,
@@ -4635,10 +4679,10 @@ var getXcmFee = /*#__PURE__*/function () {
4635
4679
  originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
4636
4680
  disableFallback: disableFallback
4637
4681
  });
4638
- case 45:
4682
+ case 48:
4639
4683
  hopResult = _context.sent;
4640
4684
  if (!hopResult.dryRunError) {
4641
- _context.next = 57;
4685
+ _context.next = 60;
4642
4686
  break;
4643
4687
  }
4644
4688
  failingRecord = {
@@ -4652,17 +4696,17 @@ var getXcmFee = /*#__PURE__*/function () {
4652
4696
  destinationFee = hopResult.fee;
4653
4697
  destinationFeeType = hopResult.feeType; // paymentInfo
4654
4698
  destinationDryRunError = hopResult.dryRunError;
4655
- } else if (nextChain === 'AssetHubPolkadot') {
4699
+ } else if (nextChain === assetHubNode) {
4656
4700
  intermediateFees.assetHub = failingRecord;
4657
- } else if (nextChain === 'BridgeHubPolkadot') {
4701
+ } else if (nextChain === bridgeHubNode) {
4658
4702
  intermediateFees.bridgeHub = failingRecord;
4659
4703
  }
4660
4704
  // We failed before the true destination, use fallback via paymentInfo.
4661
4705
  if (hopIsDestination) {
4662
- _context.next = 56;
4706
+ _context.next = 59;
4663
4707
  break;
4664
4708
  }
4665
- _context.next = 53;
4709
+ _context.next = 56;
4666
4710
  return getDestXcmFee({
4667
4711
  api: hopApi,
4668
4712
  forwardedXcms: undefined,
@@ -4675,23 +4719,23 @@ var getXcmFee = /*#__PURE__*/function () {
4675
4719
  senderAddress: senderAddress,
4676
4720
  disableFallback: disableFallback
4677
4721
  });
4678
- case 53:
4722
+ case 56:
4679
4723
  destFallback = _context.sent;
4680
4724
  destinationFee = destFallback.fee;
4681
4725
  destinationFeeType = destFallback.feeType;
4682
- case 56:
4683
- return _context.abrupt("break", 67);
4684
- case 57:
4726
+ case 59:
4727
+ return _context.abrupt("break", 70);
4728
+ case 60:
4685
4729
  if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
4686
4730
  destinationFee = hopResult.fee;
4687
4731
  destinationFeeType = hopResult.feeType;
4688
- } else if (nextChain === 'AssetHubPolkadot') {
4732
+ } else if (nextChain === assetHubNode) {
4689
4733
  intermediateFees.assetHub = {
4690
4734
  fee: hopResult.fee,
4691
4735
  feeType: hopResult.feeType,
4692
4736
  currency: assets.getNativeAssetSymbol(nextChain)
4693
4737
  };
4694
- } else if (nextChain === 'BridgeHubPolkadot') {
4738
+ } else if (nextChain === bridgeHubNode) {
4695
4739
  intermediateFees.bridgeHub = {
4696
4740
  fee: hopResult.fee,
4697
4741
  feeType: hopResult.feeType,
@@ -4701,16 +4745,36 @@ var getXcmFee = /*#__PURE__*/function () {
4701
4745
  forwardedXcms = hopResult.forwardedXcms;
4702
4746
  nextParaId = hopResult.destParaId;
4703
4747
  currentOrigin = nextChain;
4704
- case 61:
4705
- _context.prev = 61;
4706
- _context.next = 64;
4707
- return hopApi.disconnect();
4708
4748
  case 64:
4709
- return _context.finish(61);
4710
- case 65:
4711
- _context.next = 35;
4712
- break;
4749
+ _context.prev = 64;
4750
+ _context.next = 67;
4751
+ return hopApi.disconnect();
4713
4752
  case 67:
4753
+ return _context.finish(64);
4754
+ case 68:
4755
+ _context.next = 38;
4756
+ break;
4757
+ case 70:
4758
+ processedBridgeHubData = intermediateFees.bridgeHub;
4759
+ if (!(intermediateFees.bridgeHub && !intermediateFees.bridgeHub.dryRunError && destination === 'Ethereum')) {
4760
+ _context.next = 81;
4761
+ break;
4762
+ }
4763
+ ahApi = api.clone();
4764
+ _context.next = 75;
4765
+ return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
4766
+ case 75:
4767
+ _context.next = 77;
4768
+ return getParaEthTransferFees(ahApi);
4769
+ case 77:
4770
+ _yield$getParaEthTran = _context.sent;
4771
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
4772
+ bridgeFee = _yield$getParaEthTran2[0];
4773
+ processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
4774
+ fee: intermediateFees.bridgeHub.fee + bridgeFee
4775
+ });
4776
+ case 81:
4777
+ intermediateFees.bridgeHub = processedBridgeHubData;
4714
4778
  return _context.abrupt("return", _objectSpread2(_objectSpread2({
4715
4779
  origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
4716
4780
  fee: originFee
@@ -4722,7 +4786,7 @@ var getXcmFee = /*#__PURE__*/function () {
4722
4786
  dryRunError: originDryRunError
4723
4787
  })
4724
4788
  }, intermediateFees), {}, {
4725
- destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destinationFee && {
4789
+ destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destinationFee !== undefined && {
4726
4790
  fee: destinationFee
4727
4791
  }), destinationFeeType && {
4728
4792
  feeType: destinationFeeType
@@ -4732,11 +4796,11 @@ var getXcmFee = /*#__PURE__*/function () {
4732
4796
  dryRunError: destinationDryRunError
4733
4797
  })
4734
4798
  }));
4735
- case 68:
4799
+ case 83:
4736
4800
  case "end":
4737
4801
  return _context.stop();
4738
4802
  }
4739
- }, _callee, null, [[16,, 24, 29], [40,, 61, 65]]);
4803
+ }, _callee, null, [[16,, 25, 30], [43,, 64, 68]]);
4740
4804
  }));
4741
4805
  return function getXcmFee(_x) {
4742
4806
  return _ref2.apply(this, arguments);
@@ -4747,11 +4811,11 @@ var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
4747
4811
  var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
4748
4812
  var getXcmFeeEstimate = /*#__PURE__*/function () {
4749
4813
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4750
- var api, origin, destination, address, senderAddress, currency, originFeeDetails, destApi, originAsset, currencyInput, flippedTx, rawDestFee, destinationFee, destFeeDetails;
4814
+ var api, origin, destination, currency, originFeeDetails, destApi, originAsset, currencyInput, destinationFee, destFeeDetails;
4751
4815
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4752
4816
  while (1) switch (_context.prev = _context.next) {
4753
4817
  case 0:
4754
- api = options.api, origin = options.origin, destination = options.destination, address = options.address, senderAddress = options.senderAddress, currency = options.currency;
4818
+ api = options.api, origin = options.origin, destination = options.destination, currency = options.currency;
4755
4819
  if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
4756
4820
  _context.next = 3;
4757
4821
  break;
@@ -4787,32 +4851,35 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
4787
4851
  case 7:
4788
4852
  originFeeDetails = _context.sent;
4789
4853
  destApi = api.clone();
4790
- _context.next = 11;
4791
- return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4792
- case 11:
4793
- if (!('multiasset' in currency)) {
4794
- _context.next = 13;
4854
+ if (!(destination !== 'Ethereum')) {
4855
+ _context.next = 12;
4795
4856
  break;
4796
4857
  }
4797
- throw new assets.InvalidCurrencyError('Multi-assets are not yet supported for simple XCM fee estimation.');
4798
- case 13:
4858
+ _context.next = 12;
4859
+ return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4860
+ case 12:
4799
4861
  originAsset = assets.findAssetForNodeOrThrow(origin, currency, destination);
4800
4862
  currencyInput = originAsset.multiLocation ? {
4801
4863
  multilocation: originAsset.multiLocation
4802
4864
  } : {
4803
4865
  symbol: originAsset.symbol
4804
4866
  };
4805
- _context.next = 17;
4806
- return Builder(destApi).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
4807
- amount: currency.amount
4808
- })).build();
4809
- case 17:
4810
- flippedTx = _context.sent;
4867
+ if (!(destination === 'Ethereum')) {
4868
+ _context.next = 18;
4869
+ break;
4870
+ }
4871
+ _context.t0 = 0n;
4872
+ _context.next = 21;
4873
+ break;
4874
+ case 18:
4811
4875
  _context.next = 20;
4812
- return destApi.calculateTransactionFee(flippedTx, address);
4876
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4877
+ destination: destination
4878
+ }), currencyInput);
4813
4879
  case 20:
4814
- rawDestFee = _context.sent;
4815
- destinationFee = padFee(rawDestFee, origin, destination, 'destination');
4880
+ _context.t0 = _context.sent;
4881
+ case 21:
4882
+ destinationFee = _context.t0;
4816
4883
  destFeeDetails = {
4817
4884
  fee: destinationFee,
4818
4885
  currency: assets.getNativeAssetSymbol(destination)
@@ -4844,7 +4911,7 @@ var transferRelayToPara = /*#__PURE__*/function () {
4844
4911
  _context.next = 4;
4845
4912
  break;
4846
4913
  }
4847
- throw new Error('API is required when using MultiLocation as destination.');
4914
+ throw new InvalidParameterError('API is required when using MultiLocation as destination.');
4848
4915
  case 4:
4849
4916
  _context.next = 6;
4850
4917
  return api.init(origin, TX_CLIENT_TIMEOUT_MS);
@@ -4878,10 +4945,6 @@ var determineAssetCheckEnabled = function determineAssetCheckEnabled(origin, cur
4878
4945
  return 'multiasset' in currency || 'multilocation' in currency && assets.isOverrideMultiLocationSpecifier(currency.multilocation) ? false : originNode.assetCheckEnabled;
4879
4946
  };
4880
4947
 
4881
- var isBridgeTransfer = function isBridgeTransfer(origin, destination) {
4882
- return origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama' || origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot';
4883
- };
4884
-
4885
4948
  var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
4886
4949
  return assetCheckEnabled ? assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null) : null;
4887
4950
  };
@@ -5000,7 +5063,7 @@ var validateDestination = function validateDestination(origin, destination) {
5000
5063
  throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5001
5064
  }
5002
5065
  var isMultiLocationDestination = _typeof(destination) === 'object';
5003
- var isBridge = isBridgeTransfer(origin, destination);
5066
+ var isBridge = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isDotKsmBridge(origin, destination);
5004
5067
  var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
5005
5068
  if (!isRelayDestination && !isMultiLocationDestination) {
5006
5069
  var originRelayChainSymbol = assets.getRelayChainSymbol(origin);
@@ -5021,7 +5084,7 @@ var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled
5021
5084
 
5022
5085
  var send = /*#__PURE__*/function () {
5023
5086
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
5024
- var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
5087
+ var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode, finalAsset;
5025
5088
  return _regeneratorRuntime().wrap(function _callee$(_context) {
5026
5089
  while (1) switch (_context.prev = _context.next) {
5027
5090
  case 0:
@@ -5030,7 +5093,7 @@ var send = /*#__PURE__*/function () {
5030
5093
  validateDestination(origin, destination);
5031
5094
  validateDestinationAddress(address, destination);
5032
5095
  if (senderAddress) validateAddress(senderAddress, origin, false);
5033
- isBridge = isBridgeTransfer(origin, destination);
5096
+ isBridge = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isDotKsmBridge(origin, destination);
5034
5097
  assetCheckEnabled = determineAssetCheckEnabled(origin, currency);
5035
5098
  validateAssetSpecifiers(assetCheckEnabled, currency);
5036
5099
  asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
@@ -5044,13 +5107,13 @@ var send = /*#__PURE__*/function () {
5044
5107
  _context.next = 14;
5045
5108
  break;
5046
5109
  }
5047
- throw new Error('Transfers from relay chain to Ethereum are not supported.');
5110
+ throw new InvalidParameterError('Transfers from relay chain to Ethereum are not supported.');
5048
5111
  case 14:
5049
5112
  if (asset) {
5050
5113
  _context.next = 16;
5051
5114
  break;
5052
5115
  }
5053
- throw new Error('Asset is required for relay chain to relay chain transfers.');
5116
+ throw new InvalidParameterError('Asset is required for relay chain to relay chain transfers.');
5054
5117
  case 16:
5055
5118
  isLocalTransfer = origin === destination;
5056
5119
  if (!isLocalTransfer) {
@@ -5100,11 +5163,15 @@ var send = /*#__PURE__*/function () {
5100
5163
  symbol: 'symbol' in currency ? currency.symbol : undefined
5101
5164
  };
5102
5165
  originNode = getNode(origin);
5166
+ finalAsset = 'multiasset' in currency ? _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5167
+ amount: 0,
5168
+ assetId: '1'
5169
+ }) : _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5170
+ amount: currency.amount
5171
+ });
5103
5172
  return _context.abrupt("return", originNode.transfer({
5104
5173
  api: api,
5105
- asset: _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5106
- amount: 'multiasset' in currency ? 0 : currency.amount
5107
- }),
5174
+ asset: finalAsset,
5108
5175
  feeAsset: resolvedFeeAsset,
5109
5176
  address: address,
5110
5177
  to: destination,
@@ -5116,7 +5183,7 @@ var send = /*#__PURE__*/function () {
5116
5183
  pallet: pallet,
5117
5184
  method: method
5118
5185
  }));
5119
- case 30:
5186
+ case 31:
5120
5187
  case "end":
5121
5188
  return _context.stop();
5122
5189
  }
@@ -5193,7 +5260,7 @@ var ParachainNode = /*#__PURE__*/function () {
5193
5260
  _context.next = 6;
5194
5261
  break;
5195
5262
  }
5196
- throw new Error('Sending assets to Polimec is supported only from AssetHubPolkadot and Hydration');
5263
+ throw new InvalidParameterError('Sending assets to Polimec is supported only from AssetHubPolkadot and Hydration');
5197
5264
  case 6:
5198
5265
  versionOrDefault = version !== null && version !== void 0 ? version : this.version;
5199
5266
  isLocalTransfer = this.node === destination;
@@ -5436,13 +5503,13 @@ var ParachainNode = /*#__PURE__*/function () {
5436
5503
  _context2.next = 5;
5437
5504
  break;
5438
5505
  }
5439
- throw new Error('Sender address is required for transfers to Ethereum');
5506
+ throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
5440
5507
  case 5:
5441
5508
  if (!sdkCommon.isTMultiLocation(address)) {
5442
5509
  _context2.next = 7;
5443
5510
  break;
5444
5511
  }
5445
- throw new Error('Multi-location address is not supported for Ethereum transfers');
5512
+ throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
5446
5513
  case 7:
5447
5514
  ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
5448
5515
  PARA_TO_PARA_FEE_DOT = 500000000n; // 0.5 DOT
@@ -5589,13 +5656,13 @@ var ParachainNode = /*#__PURE__*/function () {
5589
5656
  _context3.next = 11;
5590
5657
  break;
5591
5658
  }
5592
- throw new Error('Sender address is required for transfers to Ethereum');
5659
+ throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
5593
5660
  case 11:
5594
5661
  if (!sdkCommon.isTMultiLocation(address)) {
5595
5662
  _context3.next = 13;
5596
5663
  break;
5597
5664
  }
5598
- throw new Error('Multi-location address is not supported for Ethereum transfers');
5665
+ throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
5599
5666
  case 13:
5600
5667
  ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
5601
5668
  _context3.next = 16;
@@ -5980,7 +6047,7 @@ var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
5980
6047
  _extractVersionFromHe4[0];
5981
6048
  var beneficiary = _extractVersionFromHe4[1];
5982
6049
  if (!asset.multiLocation) {
5983
- throw new Error("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
6050
+ throw new InvalidParameterError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
5984
6051
  }
5985
6052
  var transformedMultiLocation = transformMultiLocation(asset.multiLocation);
5986
6053
  var amountWithoutFee = BigInt(asset.amount) - executionFee;
@@ -6163,13 +6230,13 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6163
6230
  _context.next = 8;
6164
6231
  break;
6165
6232
  }
6166
- throw new Error('Sender address is required for transfers to Ethereum');
6233
+ throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
6167
6234
  case 8:
6168
6235
  if (!sdkCommon.isTMultiLocation(address)) {
6169
6236
  _context.next = 10;
6170
6237
  break;
6171
6238
  }
6172
- throw new Error('Multi-location address is not supported for Ethereum transfers');
6239
+ throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
6173
6240
  case 10:
6174
6241
  if (assets.isForeignAsset(asset)) {
6175
6242
  _context.next = 12;
@@ -6253,7 +6320,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6253
6320
  _context2.next = 8;
6254
6321
  break;
6255
6322
  }
6256
- throw new Error('Only Ethereum addresses are supported for Ethereum transfers');
6323
+ throw new InvalidParameterError('Only Ethereum addresses are supported for Ethereum transfers');
6257
6324
  case 8:
6258
6325
  if (assets.isForeignAsset(asset)) {
6259
6326
  _context2.next = 10;
@@ -6385,7 +6452,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6385
6452
  _context3.next = 3;
6386
6453
  break;
6387
6454
  }
6388
- throw new Error('Please provide senderAddress');
6455
+ throw new InvalidParameterError('Please provide senderAddress');
6389
6456
  case 3:
6390
6457
  validateAddress(senderAddress, this.node, false);
6391
6458
  decimals = asset.decimals;
@@ -6411,13 +6478,13 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6411
6478
  _context3.next = 16;
6412
6479
  break;
6413
6480
  }
6414
- throw new Error("Dry run failed: ".concat(dryRunResult.failureReason));
6481
+ throw new DryRunFailedError("Dry run failed: ".concat(dryRunResult.failureReason));
6415
6482
  case 16:
6416
6483
  if (dryRunResult.weight) {
6417
6484
  _context3.next = 18;
6418
6485
  break;
6419
6486
  }
6420
- throw new Error('Dry run failed: weight not found');
6487
+ throw new DryRunFailedError('Dry run failed: weight not found');
6421
6488
  case 18:
6422
6489
  feeDotShifted = dryRunResult.fee / 10n;
6423
6490
  toMl = transformMultiLocation(asset.multiLocation);
@@ -6429,13 +6496,13 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6429
6496
  _context3.next = 25;
6430
6497
  break;
6431
6498
  }
6432
- throw new Error("Pool DOT -> ".concat(asset.symbol, " not found."));
6499
+ throw new InvalidParameterError("Pool DOT -> ".concat(asset.symbol, " not found."));
6433
6500
  case 25:
6434
6501
  if (!(BigInt(asset.amount) - feeConverted < 0)) {
6435
6502
  _context3.next = 27;
6436
6503
  break;
6437
6504
  }
6438
- throw new Error("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
6505
+ throw new InvalidParameterError("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
6439
6506
  case 27:
6440
6507
  feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
6441
6508
  return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
@@ -8179,7 +8246,7 @@ var XTransferTransferImpl = /*#__PURE__*/function () {
8179
8246
  method = input.method;
8180
8247
  var isMultiLocationDestination = _typeof(destination) === 'object';
8181
8248
  if (isMultiLocationDestination) {
8182
- 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.');
8249
+ throw new InvalidParameterError('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.');
8183
8250
  }
8184
8251
  var version = exports.Version.V1;
8185
8252
  var multiAssets = [createMultiAsset(version, asset.amount, {
@@ -8801,7 +8868,7 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
8801
8868
  _context.next = 10;
8802
8869
  break;
8803
8870
  }
8804
- throw new Error("Cannot get existential deposit for currency ".concat(JSON.stringify(currency), "."));
8871
+ throw new InvalidParameterError("Cannot get existential deposit for currency ".concat(JSON.stringify(currency), "."));
8805
8872
  case 10:
8806
8873
  edBN = BigInt(ed);
8807
8874
  isNativeAsset = assets.getNativeAssetSymbol(node) === asset.symbol;
@@ -8822,145 +8889,399 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
8822
8889
  currency: currency,
8823
8890
  disableFallback: false
8824
8891
  });
8825
- case 17:
8826
- _yield$getOriginXcmFe = _context.sent;
8827
- fee = _yield$getOriginXcmFe.fee;
8828
- if (!(fee === undefined)) {
8829
- _context.next = 21;
8830
- break;
8831
- }
8832
- throw new Error("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
8833
- case 21:
8834
- feeToSubtract = fee;
8835
- case 22:
8836
- transferable = balance - edBN - feeToSubtract;
8837
- return _context.abrupt("return", transferable > 0n ? transferable : 0n);
8838
- case 24:
8892
+ case 17:
8893
+ _yield$getOriginXcmFe = _context.sent;
8894
+ fee = _yield$getOriginXcmFe.fee;
8895
+ if (!(fee === undefined)) {
8896
+ _context.next = 21;
8897
+ break;
8898
+ }
8899
+ throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
8900
+ case 21:
8901
+ feeToSubtract = fee;
8902
+ case 22:
8903
+ transferable = balance - edBN - feeToSubtract;
8904
+ return _context.abrupt("return", transferable > 0n ? transferable : 0n);
8905
+ case 24:
8906
+ case "end":
8907
+ return _context.stop();
8908
+ }
8909
+ }, _callee);
8910
+ }));
8911
+ return function getTransferableAmountInternal(_x) {
8912
+ return _ref2.apply(this, arguments);
8913
+ };
8914
+ }();
8915
+ var getTransferableAmount = /*#__PURE__*/function () {
8916
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
8917
+ var api;
8918
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8919
+ while (1) switch (_context2.prev = _context2.next) {
8920
+ case 0:
8921
+ api = options.api;
8922
+ api.setDisconnectAllowed(false);
8923
+ _context2.prev = 2;
8924
+ _context2.next = 5;
8925
+ return getTransferableAmountInternal(options);
8926
+ case 5:
8927
+ return _context2.abrupt("return", _context2.sent);
8928
+ case 6:
8929
+ _context2.prev = 6;
8930
+ api.setDisconnectAllowed(true);
8931
+ _context2.next = 10;
8932
+ return api.disconnect();
8933
+ case 10:
8934
+ return _context2.finish(6);
8935
+ case 11:
8936
+ case "end":
8937
+ return _context2.stop();
8938
+ }
8939
+ }, _callee2, null, [[2,, 6, 11]]);
8940
+ }));
8941
+ return function getTransferableAmount(_x2) {
8942
+ return _ref3.apply(this, arguments);
8943
+ };
8944
+ }();
8945
+
8946
+ var ETH_RPC = 'https://ethereum.publicnode.com/';
8947
+ var ETH_ID = 1;
8948
+ var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
8949
+ function getEthErc20Balance(_x, _x2) {
8950
+ return _getEthErc20Balance.apply(this, arguments);
8951
+ }
8952
+ function _getEthErc20Balance() {
8953
+ _getEthErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(currency, address) {
8954
+ var _rpc$id, rpc, id, asset, provider, tokenAddress, token;
8955
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8956
+ while (1) switch (_context.prev = _context.next) {
8957
+ case 0:
8958
+ _rpc$id = {
8959
+ rpc: ETH_RPC,
8960
+ id: ETH_ID
8961
+ }, rpc = _rpc$id.rpc, id = _rpc$id.id;
8962
+ asset = assets.findAssetForNodeOrThrow('Ethereum', currency, null);
8963
+ if (!(!assets.isForeignAsset(asset) || !asset.assetId)) {
8964
+ _context.next = 4;
8965
+ break;
8966
+ }
8967
+ throw new InvalidParameterError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset."));
8968
+ case 4:
8969
+ provider = new ethers.ethers.JsonRpcProvider(rpc, id);
8970
+ if (!(asset.symbol === 'ETH')) {
8971
+ _context.next = 9;
8972
+ break;
8973
+ }
8974
+ _context.next = 8;
8975
+ return provider.getBalance(address);
8976
+ case 8:
8977
+ return _context.abrupt("return", _context.sent);
8978
+ case 9:
8979
+ tokenAddress = asset.assetId;
8980
+ token = new ethers.ethers.Contract(tokenAddress, ERC20_ABI, provider);
8981
+ _context.next = 13;
8982
+ return token.balanceOf(address);
8983
+ case 13:
8984
+ return _context.abrupt("return", _context.sent);
8985
+ case 14:
8986
+ case "end":
8987
+ return _context.stop();
8988
+ }
8989
+ }, _callee);
8990
+ }));
8991
+ return _getEthErc20Balance.apply(this, arguments);
8992
+ }
8993
+
8994
+ var buildDestInfo = /*#__PURE__*/function () {
8995
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
8996
+ var api, origin, destination, address, currency, originFee, destAsset, isFeeAssetAh, destFeeDetail, assetHubFee, bridgeFee, destApi, destCurrency, edDest, edDestBn, destBalance, destAmount, destBalanceSufficient, destBalanceSufficientResult, destBalanceAfter, destbalanceAfterResult, receivedAmount, isAssetHubToAssetHubRoute, nativeAssetOfOriginSymbol, isOriginAssetNative, destXcmFeeBalance, isDestFeeInNativeCurrency, destRecipientNativeBalance, destXcmFeeBalanceAfter;
8997
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8998
+ while (1) switch (_context.prev = _context.next) {
8999
+ case 0:
9000
+ api = _ref.api, origin = _ref.origin, destination = _ref.destination, address = _ref.address, currency = _ref.currency, originFee = _ref.originFee, destAsset = _ref.destAsset, isFeeAssetAh = _ref.isFeeAssetAh, destFeeDetail = _ref.destFeeDetail, assetHubFee = _ref.assetHubFee, bridgeFee = _ref.bridgeFee;
9001
+ destApi = api.clone();
9002
+ if (!(destination !== 'Ethereum')) {
9003
+ _context.next = 5;
9004
+ break;
9005
+ }
9006
+ _context.next = 5;
9007
+ return destApi.init(destination);
9008
+ case 5:
9009
+ destCurrency = destAsset.multiLocation ? {
9010
+ multilocation: destAsset.multiLocation
9011
+ } : {
9012
+ symbol: destAsset.symbol
9013
+ };
9014
+ edDest = assets.getExistentialDeposit(destination, destCurrency);
9015
+ if (edDest) {
9016
+ _context.next = 9;
9017
+ break;
9018
+ }
9019
+ throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
9020
+ case 9:
9021
+ edDestBn = BigInt(edDest);
9022
+ if (!(destination === 'Ethereum')) {
9023
+ _context.next = 16;
9024
+ break;
9025
+ }
9026
+ _context.next = 13;
9027
+ return getEthErc20Balance(destCurrency, address);
9028
+ case 13:
9029
+ _context.t0 = _context.sent;
9030
+ _context.next = 19;
9031
+ break;
9032
+ case 16:
9033
+ _context.next = 18;
9034
+ return getAssetBalanceInternal({
9035
+ api: destApi,
9036
+ address: address,
9037
+ node: destination,
9038
+ currency: destCurrency
9039
+ });
9040
+ case 18:
9041
+ _context.t0 = _context.sent;
9042
+ case 19:
9043
+ destBalance = _context.t0;
9044
+ destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
9045
+ destBalanceSufficient = destAmount - destFeeDetail.fee > (destBalance < edDestBn ? edDestBn : 0);
9046
+ destBalanceSufficientResult = destFeeDetail.currency !== destAsset.symbol && destination !== 'Ethereum' ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
9047
+ destBalanceAfter = destBalance - (destFeeDetail.currency === destAsset.symbol ? destFeeDetail.fee : 0n) + destAmount;
9048
+ destbalanceAfterResult = destFeeDetail.currency !== destAsset.symbol && destination !== 'Ethereum' ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
9049
+ isAssetHubToAssetHubRoute = origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot' || origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama';
9050
+ if (isAssetHubToAssetHubRoute) {
9051
+ nativeAssetOfOriginSymbol = assets.getNativeAssetSymbol(origin);
9052
+ isOriginAssetNative = false;
9053
+ if (destAsset.symbol === nativeAssetOfOriginSymbol) {
9054
+ isOriginAssetNative = true;
9055
+ }
9056
+ if (isOriginAssetNative) {
9057
+ if (bridgeFee === undefined) {
9058
+ receivedAmount = new UnableToComputeError("bridgeFee is required for native asset transfer from ".concat(origin, " to ").concat(destination, " but was not provided."));
9059
+ } else {
9060
+ receivedAmount = BigInt(currency.amount) - originFee - bridgeFee;
9061
+ }
9062
+ } else {
9063
+ receivedAmount = new UnableToComputeError("Unable to compute received amount: The transferred asset (".concat(destAsset.symbol, ") is not the native asset (").concat(nativeAssetOfOriginSymbol, ") of origin ").concat(origin, " for the ").concat(origin, "->").concat(destination, " route."));
9064
+ }
9065
+ } else {
9066
+ if (destbalanceAfterResult instanceof UnableToComputeError) {
9067
+ receivedAmount = destbalanceAfterResult;
9068
+ } else {
9069
+ receivedAmount = destbalanceAfterResult - destBalance;
9070
+ }
9071
+ }
9072
+ if (destination === 'Ethereum' && assetHubFee && !(receivedAmount instanceof UnableToComputeError)) {
9073
+ receivedAmount -= assetHubFee;
9074
+ }
9075
+ isDestFeeInNativeCurrency = destFeeDetail.currency === assets.getNativeAssetSymbol(destination);
9076
+ if (!isDestFeeInNativeCurrency) {
9077
+ _context.next = 43;
9078
+ break;
9079
+ }
9080
+ if (!(destination === 'Ethereum')) {
9081
+ _context.next = 36;
9082
+ break;
9083
+ }
9084
+ _context.next = 33;
9085
+ return getEthErc20Balance({
9086
+ symbol: assets.getNativeAssetSymbol(destination)
9087
+ }, address);
9088
+ case 33:
9089
+ _context.t1 = _context.sent;
9090
+ _context.next = 39;
9091
+ break;
9092
+ case 36:
9093
+ _context.next = 38;
9094
+ return getBalanceNativeInternal({
9095
+ address: address,
9096
+ node: destination,
9097
+ api: destApi
9098
+ });
9099
+ case 38:
9100
+ _context.t1 = _context.sent;
9101
+ case 39:
9102
+ destRecipientNativeBalance = _context.t1;
9103
+ destXcmFeeBalance = destRecipientNativeBalance;
9104
+ _context.next = 44;
9105
+ break;
9106
+ case 43:
9107
+ destXcmFeeBalance = destBalance;
9108
+ case 44:
9109
+ destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFeeDetail.fee + (destFeeDetail.currency === destAsset.symbol ? BigInt(currency.amount) : 0n);
9110
+ return _context.abrupt("return", {
9111
+ receivedCurrency: {
9112
+ sufficient: destBalanceSufficientResult,
9113
+ receivedAmount: receivedAmount,
9114
+ balance: destBalance,
9115
+ balanceAfter: destbalanceAfterResult,
9116
+ currencySymbol: destAsset.symbol,
9117
+ existentialDeposit: edDestBn
9118
+ },
9119
+ xcmFee: {
9120
+ fee: destFeeDetail.fee,
9121
+ balance: destXcmFeeBalance,
9122
+ balanceAfter: destXcmFeeBalanceAfter,
9123
+ currencySymbol: destFeeDetail.currency
9124
+ }
9125
+ });
9126
+ case 46:
8839
9127
  case "end":
8840
9128
  return _context.stop();
8841
9129
  }
8842
9130
  }, _callee);
8843
9131
  }));
8844
- return function getTransferableAmountInternal(_x) {
9132
+ return function buildDestInfo(_x) {
8845
9133
  return _ref2.apply(this, arguments);
8846
9134
  };
8847
9135
  }();
8848
- var getTransferableAmount = /*#__PURE__*/function () {
8849
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
8850
- var api;
8851
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8852
- while (1) switch (_context2.prev = _context2.next) {
9136
+
9137
+ var buildHopInfo = /*#__PURE__*/function () {
9138
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
9139
+ var api, node, feeData, originNode, currency, senderAddress, ahAddress, hopApi, resolvedAddress, nativeBalanceOnHop, nativeAssetSymbolOnHop, xcmFeeDetails, isBridgeHubNode, hopAsset, hopCurrencyPayload, balance, ed;
9140
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
9141
+ while (1) switch (_context.prev = _context.next) {
8853
9142
  case 0:
8854
- api = options.api;
8855
- api.setDisconnectAllowed(false);
8856
- _context2.prev = 2;
8857
- _context2.next = 5;
8858
- return getTransferableAmountInternal(options);
8859
- case 5:
8860
- return _context2.abrupt("return", _context2.sent);
8861
- case 6:
8862
- _context2.prev = 6;
8863
- api.setDisconnectAllowed(true);
8864
- _context2.next = 10;
8865
- return api.disconnect();
8866
- case 10:
8867
- return _context2.finish(6);
8868
- case 11:
9143
+ api = _ref.api, node = _ref.node, feeData = _ref.feeData, originNode = _ref.originNode, currency = _ref.currency, senderAddress = _ref.senderAddress, ahAddress = _ref.ahAddress;
9144
+ hopApi = api.clone();
9145
+ _context.next = 4;
9146
+ return hopApi.init(node);
9147
+ case 4:
9148
+ hopApi.setDisconnectAllowed(false);
9149
+ _context.prev = 5;
9150
+ resolvedAddress = assets.isNodeEvm(originNode) && ahAddress ? ahAddress : senderAddress;
9151
+ _context.next = 9;
9152
+ return getBalanceNativeInternal({
9153
+ api: hopApi,
9154
+ address: resolvedAddress,
9155
+ node: node
9156
+ });
9157
+ case 9:
9158
+ nativeBalanceOnHop = _context.sent;
9159
+ nativeAssetSymbolOnHop = assets.getNativeAssetSymbol(node);
9160
+ xcmFeeDetails = {
9161
+ fee: feeData.fee,
9162
+ balance: nativeBalanceOnHop,
9163
+ currencySymbol: nativeAssetSymbolOnHop
9164
+ };
9165
+ isBridgeHubNode = node.includes('BridgeHub');
9166
+ if (!isBridgeHubNode) {
9167
+ _context.next = 17;
9168
+ break;
9169
+ }
9170
+ return _context.abrupt("return", {
9171
+ currencySymbol: assets.getNativeAssetSymbol(node),
9172
+ xcmFee: xcmFeeDetails
9173
+ });
9174
+ case 17:
9175
+ hopAsset = assets.findAssetOnDestOrThrow(originNode, node, currency);
9176
+ hopCurrencyPayload = hopAsset.multiLocation ? {
9177
+ multilocation: hopAsset.multiLocation
9178
+ } : {
9179
+ symbol: hopAsset.symbol
9180
+ };
9181
+ _context.next = 21;
9182
+ return getAssetBalanceInternal({
9183
+ api: hopApi,
9184
+ address: resolvedAddress,
9185
+ node: node,
9186
+ currency: hopCurrencyPayload
9187
+ });
9188
+ case 21:
9189
+ balance = _context.sent;
9190
+ ed = assets.getExistentialDeposit(node, hopCurrencyPayload);
9191
+ if (ed) {
9192
+ _context.next = 25;
9193
+ break;
9194
+ }
9195
+ throw new InvalidParameterError("Existential deposit not found for node ".concat(node, " with currency ").concat(JSON.stringify(hopCurrencyPayload)));
9196
+ case 25:
9197
+ return _context.abrupt("return", {
9198
+ balance: balance,
9199
+ currencySymbol: hopAsset.symbol,
9200
+ existentialDeposit: BigInt(ed),
9201
+ xcmFee: xcmFeeDetails
9202
+ });
9203
+ case 26:
9204
+ _context.prev = 26;
9205
+ hopApi.setDisconnectAllowed(true);
9206
+ _context.next = 30;
9207
+ return hopApi.disconnect();
9208
+ case 30:
9209
+ return _context.finish(26);
9210
+ case 31:
8869
9211
  case "end":
8870
- return _context2.stop();
9212
+ return _context.stop();
8871
9213
  }
8872
- }, _callee2, null, [[2,, 6, 11]]);
9214
+ }, _callee, null, [[5,, 26, 31]]);
8873
9215
  }));
8874
- return function getTransferableAmount(_x2) {
8875
- return _ref3.apply(this, arguments);
9216
+ return function buildHopInfo(_x) {
9217
+ return _ref2.apply(this, arguments);
8876
9218
  };
8877
9219
  }();
8878
9220
 
8879
9221
  var getTransferInfo = /*#__PURE__*/function () {
8880
9222
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
8881
- var api, tx, origin, destination, senderAddress, address, currency, feeAsset, resolvedFeeAsset, destApi, destAsset, destCurrency, originBalanceFee, originBalance, destBalance, edOrigin, edOriginBn, edDest, edDestBn, _yield$getXcmFee, _yield$getXcmFee$orig, originFee, originFeeCurrency, _yield$getXcmFee$dest, destFee, destFeeCurrency, destXcmFeeBalance, isDestFeeInNativeCurrency, destRecipientNativeBalance, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, destAmount, destBalanceSufficient, destBalanceSufficientResult, destBalanceAfter, destbalanceAfterResult, receivedAmount, destXcmFeeBalanceAfter;
9223
+ var api, tx, origin, destination, senderAddress, ahAddress, address, currency, feeAsset, resolvedFeeAsset, destAsset, originBalanceFee, originBalance, edOrigin, edOriginBn, _yield$getXcmFee, _yield$getXcmFee$orig, originFee, originFeeCurrency, assetHubFeeResult, bridgeHubFeeResult, destFeeDetail, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, assetHub, bridgeHub, bridgeHubNode, destinationInfo;
8882
9224
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8883
9225
  while (1) switch (_context.prev = _context.next) {
8884
9226
  case 0:
8885
- api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
9227
+ api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, ahAddress = _ref.ahAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
9228
+ if (!(assets.isNodeEvm(origin) && !ahAddress)) {
9229
+ _context.next = 3;
9230
+ break;
9231
+ }
9232
+ throw new InvalidParameterError("ahAddress is required for EVM origin ".concat(origin, "."));
9233
+ case 3:
8886
9234
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
8887
- _context.next = 4;
9235
+ _context.next = 6;
8888
9236
  return api.init(origin);
8889
- case 4:
9237
+ case 6:
8890
9238
  api.setDisconnectAllowed(false);
8891
- destApi = api.clone();
8892
- _context.next = 8;
8893
- return destApi.init(destination);
8894
- case 8:
8895
- destApi.setDisconnectAllowed(false);
8896
- _context.prev = 9;
9239
+ _context.prev = 7;
8897
9240
  destAsset = assets.findAssetOnDestOrThrow(origin, destination, currency);
8898
- destCurrency = destAsset.multiLocation ? {
8899
- multilocation: destAsset.multiLocation
8900
- } : {
8901
- symbol: destAsset.symbol
8902
- };
8903
9241
  if (!(feeAsset && resolvedFeeAsset)) {
8904
- _context.next = 18;
9242
+ _context.next = 15;
8905
9243
  break;
8906
9244
  }
8907
- _context.next = 15;
9245
+ _context.next = 12;
8908
9246
  return getAssetBalanceInternal({
8909
9247
  api: api,
8910
9248
  address: senderAddress,
8911
9249
  node: origin,
8912
9250
  currency: feeAsset
8913
9251
  });
8914
- case 15:
9252
+ case 12:
8915
9253
  _context.t0 = _context.sent;
8916
- _context.next = 21;
9254
+ _context.next = 18;
8917
9255
  break;
8918
- case 18:
8919
- _context.next = 20;
9256
+ case 15:
9257
+ _context.next = 17;
8920
9258
  return getBalanceNativeInternal({
8921
9259
  api: api,
8922
9260
  address: senderAddress,
8923
9261
  node: origin
8924
9262
  });
8925
- case 20:
9263
+ case 17:
8926
9264
  _context.t0 = _context.sent;
8927
- case 21:
9265
+ case 18:
8928
9266
  originBalanceFee = _context.t0;
8929
- _context.next = 24;
9267
+ _context.next = 21;
8930
9268
  return getAssetBalanceInternal({
8931
9269
  api: api,
8932
9270
  address: senderAddress,
8933
9271
  node: origin,
8934
9272
  currency: currency
8935
9273
  });
8936
- case 24:
9274
+ case 21:
8937
9275
  originBalance = _context.sent;
8938
- _context.next = 27;
8939
- return getAssetBalanceInternal({
8940
- api: destApi,
8941
- address: address,
8942
- node: destination,
8943
- currency: destCurrency
8944
- });
8945
- case 27:
8946
- destBalance = _context.sent;
8947
9276
  edOrigin = assets.getExistentialDeposit(origin, currency);
8948
9277
  if (edOrigin) {
8949
- _context.next = 31;
9278
+ _context.next = 25;
8950
9279
  break;
8951
9280
  }
8952
9281
  throw new InvalidParameterError("Existential deposit not found for ".concat(origin, " with currency ").concat(JSON.stringify(currency)));
8953
- case 31:
9282
+ case 25:
8954
9283
  edOriginBn = BigInt(edOrigin);
8955
- edDest = assets.getExistentialDeposit(destination, destCurrency);
8956
- if (edDest) {
8957
- _context.next = 35;
8958
- break;
8959
- }
8960
- throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
8961
- case 35:
8962
- edDestBn = BigInt(edDest);
8963
- _context.next = 38;
9284
+ _context.next = 28;
8964
9285
  return getXcmFee({
8965
9286
  api: api,
8966
9287
  tx: tx,
@@ -8972,51 +9293,76 @@ var getTransferInfo = /*#__PURE__*/function () {
8972
9293
  feeAsset: feeAsset,
8973
9294
  disableFallback: false
8974
9295
  });
8975
- case 38:
9296
+ case 28:
8976
9297
  _yield$getXcmFee = _context.sent;
8977
9298
  _yield$getXcmFee$orig = _yield$getXcmFee.origin;
8978
9299
  originFee = _yield$getXcmFee$orig.fee;
8979
9300
  originFeeCurrency = _yield$getXcmFee$orig.currency;
8980
- _yield$getXcmFee$dest = _yield$getXcmFee.destination;
8981
- destFee = _yield$getXcmFee$dest.fee;
8982
- destFeeCurrency = _yield$getXcmFee$dest.currency;
9301
+ assetHubFeeResult = _yield$getXcmFee.assetHub;
9302
+ bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
9303
+ destFeeDetail = _yield$getXcmFee.destination;
8983
9304
  if (!(originFee === undefined)) {
8984
- _context.next = 47;
8985
- break;
8986
- }
8987
- throw new Error("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(origin, "."));
8988
- case 47:
8989
- isDestFeeInNativeCurrency = destFeeCurrency === assets.getNativeAssetSymbol(destination);
8990
- if (!isDestFeeInNativeCurrency) {
8991
- _context.next = 55;
9305
+ _context.next = 37;
8992
9306
  break;
8993
9307
  }
8994
- _context.next = 51;
8995
- return getBalanceNativeInternal({
8996
- address: address,
8997
- node: destination,
8998
- api: destApi
8999
- });
9000
- case 51:
9001
- destRecipientNativeBalance = _context.sent;
9002
- destXcmFeeBalance = destRecipientNativeBalance;
9003
- _context.next = 56;
9004
- break;
9005
- case 55:
9006
- destXcmFeeBalance = destBalance;
9007
- case 56:
9308
+ throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(origin, "."));
9309
+ case 37:
9008
9310
  isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, destAsset);
9009
9311
  originBalanceAfter = originBalance - BigInt(currency.amount);
9010
9312
  originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - BigInt(currency.amount) : originBalanceFee - originFee;
9011
9313
  originBalanceNativeSufficient = originBalanceFee >= originFee;
9012
9314
  originBalanceSufficient = originBalanceAfter >= edOriginBn;
9013
- destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
9014
- destBalanceSufficient = destAmount - destFee > (destBalance < edDestBn ? edDestBn : 0);
9015
- destBalanceSufficientResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
9016
- destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) + destAmount;
9017
- destbalanceAfterResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
9018
- receivedAmount = destbalanceAfterResult instanceof UnableToComputeError ? destbalanceAfterResult : destbalanceAfterResult - destBalance;
9019
- destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFee + (destFeeCurrency === destAsset.symbol ? BigInt(currency.amount) : 0n);
9315
+ if (!assetHubFeeResult) {
9316
+ _context.next = 46;
9317
+ break;
9318
+ }
9319
+ _context.next = 45;
9320
+ return buildHopInfo({
9321
+ api: api,
9322
+ node: determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama',
9323
+ feeData: assetHubFeeResult,
9324
+ originNode: origin,
9325
+ currency: currency,
9326
+ senderAddress: senderAddress,
9327
+ ahAddress: ahAddress
9328
+ });
9329
+ case 45:
9330
+ assetHub = _context.sent;
9331
+ case 46:
9332
+ if (!bridgeHubFeeResult) {
9333
+ _context.next = 51;
9334
+ break;
9335
+ }
9336
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
9337
+ _context.next = 50;
9338
+ return buildHopInfo({
9339
+ api: api,
9340
+ node: bridgeHubNode,
9341
+ feeData: bridgeHubFeeResult,
9342
+ originNode: origin,
9343
+ currency: currency,
9344
+ senderAddress: senderAddress,
9345
+ ahAddress: ahAddress
9346
+ });
9347
+ case 50:
9348
+ bridgeHub = _context.sent;
9349
+ case 51:
9350
+ _context.next = 53;
9351
+ return buildDestInfo({
9352
+ api: api,
9353
+ origin: origin,
9354
+ destination: destination,
9355
+ address: address,
9356
+ currency: currency,
9357
+ destAsset: destAsset,
9358
+ originFee: originFee,
9359
+ isFeeAssetAh: !!isFeeAssetAh,
9360
+ destFeeDetail: destFeeDetail,
9361
+ assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
9362
+ bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
9363
+ });
9364
+ case 53:
9365
+ destinationInfo = _context.sent;
9020
9366
  return _context.abrupt("return", {
9021
9367
  chain: {
9022
9368
  origin: origin,
@@ -9039,57 +9385,69 @@ var getTransferInfo = /*#__PURE__*/function () {
9039
9385
  currencySymbol: originFeeCurrency
9040
9386
  }
9041
9387
  },
9042
- destination: {
9043
- receivedCurrency: {
9044
- sufficient: destBalanceSufficientResult,
9045
- receivedAmount: receivedAmount,
9046
- balance: destBalance,
9047
- balanceAfter: destbalanceAfterResult,
9048
- currencySymbol: destAsset.symbol,
9049
- existentialDeposit: edDestBn
9050
- },
9051
- xcmFee: {
9052
- fee: destFee,
9053
- balance: destXcmFeeBalance,
9054
- balanceAfter: destXcmFeeBalanceAfter,
9055
- currencySymbol: destFeeCurrency
9056
- }
9057
- }
9388
+ assetHub: assetHub,
9389
+ bridgeHub: bridgeHub,
9390
+ destination: destinationInfo
9058
9391
  });
9059
- case 69:
9060
- _context.prev = 69;
9392
+ case 55:
9393
+ _context.prev = 55;
9061
9394
  api.setDisconnectAllowed(true);
9062
- destApi.setDisconnectAllowed(true);
9063
- _context.next = 74;
9395
+ _context.next = 59;
9064
9396
  return api.disconnect();
9065
- case 74:
9066
- _context.next = 76;
9067
- return destApi.disconnect();
9068
- case 76:
9069
- return _context.finish(69);
9070
- case 77:
9397
+ case 59:
9398
+ return _context.finish(55);
9399
+ case 60:
9071
9400
  case "end":
9072
9401
  return _context.stop();
9073
9402
  }
9074
- }, _callee, null, [[9,, 69, 77]]);
9403
+ }, _callee, null, [[7,, 55, 60]]);
9075
9404
  }));
9076
9405
  return function getTransferInfo(_x) {
9077
9406
  return _ref2.apply(this, arguments);
9078
9407
  };
9079
9408
  }();
9080
9409
 
9410
+ var calculateTotalXcmFee = function calculateTotalXcmFee(feeResult) {
9411
+ var _feeResult$assetHub;
9412
+ var totalFee = 0n;
9413
+ if (((_feeResult$assetHub = feeResult.assetHub) === null || _feeResult$assetHub === void 0 ? void 0 : _feeResult$assetHub.fee) !== undefined) {
9414
+ totalFee += feeResult.assetHub.fee;
9415
+ }
9416
+ if (feeResult.destination.fee !== undefined) {
9417
+ totalFee += feeResult.destination.fee;
9418
+ }
9419
+ return totalFee;
9420
+ };
9081
9421
  var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9082
9422
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
9083
- var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
9423
+ var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, xcmFeeResult, dryRunError, _xcmFeeResult$destina, destFee, destFeeCurrency, destDryRunError, totalFee, method, feeToSubtract;
9084
9424
  return _regeneratorRuntime().wrap(function _callee$(_context) {
9085
9425
  while (1) switch (_context.prev = _context.next) {
9086
9426
  case 0:
9087
9427
  api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset, currency = _ref.currency;
9428
+ if (!(destination === 'Ethereum')) {
9429
+ _context.next = 3;
9430
+ break;
9431
+ }
9432
+ return _context.abrupt("return", true);
9433
+ case 3:
9088
9434
  validateAddress(address, destination);
9435
+ if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
9436
+ _context.next = 6;
9437
+ break;
9438
+ }
9439
+ throw new InvalidParameterError('Kusama is outside of Polkadot ecosystem, thus function is unable to verify the existential deposit for it.');
9440
+ case 6:
9441
+ if (!(origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot')) {
9442
+ _context.next = 8;
9443
+ break;
9444
+ }
9445
+ throw new InvalidParameterError('Polkadot is outside of Kusama ecosystem, thus function is unable to verify the existential deposit for it.');
9446
+ case 8:
9089
9447
  destApi = api.clone();
9090
- _context.next = 5;
9448
+ _context.next = 11;
9091
9449
  return destApi.init(destination);
9092
- case 5:
9450
+ case 11:
9093
9451
  asset = assets.findAssetOnDestOrThrow(origin, destination, currency);
9094
9452
  destCurrency = asset.multiLocation ? {
9095
9453
  multilocation: asset.multiLocation
@@ -9098,22 +9456,22 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9098
9456
  };
9099
9457
  ed = assets.getExistentialDeposit(destination, destCurrency);
9100
9458
  if (!(ed === null)) {
9101
- _context.next = 10;
9459
+ _context.next = 16;
9102
9460
  break;
9103
9461
  }
9104
- throw new Error("Cannot get existential deposit for currency ".concat(JSON.stringify(currency)));
9105
- case 10:
9462
+ throw new InvalidParameterError("Cannot get existential deposit for currency ".concat(JSON.stringify(currency)));
9463
+ case 16:
9106
9464
  edBN = BigInt(ed);
9107
- _context.next = 13;
9465
+ _context.next = 19;
9108
9466
  return getAssetBalanceInternal({
9109
9467
  address: address,
9110
9468
  node: destination,
9111
9469
  api: destApi,
9112
9470
  currency: destCurrency
9113
9471
  });
9114
- case 13:
9472
+ case 19:
9115
9473
  balance = _context.sent;
9116
- _context.next = 16;
9474
+ _context.next = 22;
9117
9475
  return getXcmFee({
9118
9476
  api: api,
9119
9477
  tx: tx,
@@ -9125,39 +9483,42 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9125
9483
  feeAsset: feeAsset,
9126
9484
  disableFallback: false
9127
9485
  });
9128
- case 16:
9129
- _yield$getXcmFee = _context.sent;
9130
- dryRunError = _yield$getXcmFee.origin.dryRunError;
9131
- _yield$getXcmFee$dest = _yield$getXcmFee.destination;
9132
- destFee = _yield$getXcmFee$dest.fee;
9133
- destFeeCurrency = _yield$getXcmFee$dest.currency;
9134
- destDryRunError = _yield$getXcmFee$dest.dryRunError;
9486
+ case 22:
9487
+ xcmFeeResult = _context.sent;
9488
+ dryRunError = xcmFeeResult.origin.dryRunError, _xcmFeeResult$destina = xcmFeeResult.destination, destFee = _xcmFeeResult$destina.fee, destFeeCurrency = _xcmFeeResult$destina.currency, destDryRunError = _xcmFeeResult$destina.dryRunError;
9135
9489
  if (!(destFee === undefined)) {
9136
- _context.next = 24;
9490
+ _context.next = 26;
9137
9491
  break;
9138
9492
  }
9139
- throw new Error("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(destination, "."));
9140
- case 24:
9493
+ throw new InvalidParameterError("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(destination, "."));
9494
+ case 26:
9141
9495
  if (!dryRunError) {
9142
- _context.next = 26;
9496
+ _context.next = 28;
9143
9497
  break;
9144
9498
  }
9145
9499
  throw new DryRunFailedError(dryRunError, 'origin');
9146
- case 26:
9500
+ case 28:
9147
9501
  if (!destDryRunError) {
9148
- _context.next = 28;
9502
+ _context.next = 30;
9149
9503
  break;
9150
9504
  }
9151
9505
  throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError));
9152
- case 28:
9506
+ case 30:
9153
9507
  if (!(assets.normalizeSymbol(asset.symbol) !== assets.normalizeSymbol(destFeeCurrency))) {
9154
- _context.next = 30;
9508
+ _context.next = 32;
9155
9509
  break;
9156
9510
  }
9157
9511
  throw new UnableToComputeError("The XCM fee could not be calculated because the origin or destination chain does not support DryRun.\n As a result, fee estimation is only available through PaymentInfo, which provides the cost in the native asset.\n This limitation restricts support to transfers involving the native asset of the Destination chain only.");
9158
- case 30:
9159
- return _context.abrupt("return", BigInt(currency.amount) - destFee > (balance < edBN ? edBN : 0));
9160
- case 31:
9512
+ case 32:
9513
+ totalFee = calculateTotalXcmFee(xcmFeeResult);
9514
+ method = api.getMethod(tx);
9515
+ if (method === 'transfer_assets_using_type_and_then' || method === 'transferAssetsUsingTypeAndThen') {
9516
+ feeToSubtract = totalFee;
9517
+ } else {
9518
+ feeToSubtract = destFee;
9519
+ }
9520
+ return _context.abrupt("return", BigInt(currency.amount) - feeToSubtract > (balance < edBN ? edBN : 0));
9521
+ case 36:
9161
9522
  case "end":
9162
9523
  return _context.stop();
9163
9524
  }
@@ -9197,13 +9558,10 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
9197
9558
  };
9198
9559
  }();
9199
9560
 
9200
- var assertToIsStringAndNoEthereum = function assertToIsStringAndNoEthereum(to) {
9561
+ var assertToIsString = function assertToIsString(to) {
9201
9562
  if (sdkCommon.isTMultiLocation(to)) {
9202
9563
  throw new InvalidParameterError('Multi-Location destination is not supported for XCM fee calculation.');
9203
9564
  }
9204
- if (to === 'Ethereum') {
9205
- throw new InvalidParameterError('Ethereum destination is not yet supported for XCM fee calculation.');
9206
- }
9207
9565
  };
9208
9566
  var assertAddressIsString = function assertAddressIsString(address) {
9209
9567
  if (sdkCommon.isTMultiLocation(address)) {
@@ -9250,7 +9608,7 @@ var BatchTransactionManager = /*#__PURE__*/function () {
9250
9608
  _context.next = 6;
9251
9609
  break;
9252
9610
  }
9253
- throw new Error('No transactions to batch.');
9611
+ throw new InvalidParameterError('No transactions to batch.');
9254
9612
  case 6:
9255
9613
  sameFrom = this.transactionOptions.every(function (tx) {
9256
9614
  return tx.from === from;
@@ -9259,7 +9617,7 @@ var BatchTransactionManager = /*#__PURE__*/function () {
9259
9617
  _context.next = 9;
9260
9618
  break;
9261
9619
  }
9262
- throw new Error('All transactions must have the same origin.');
9620
+ throw new InvalidParameterError('All transactions must have the same origin.');
9263
9621
  case 9:
9264
9622
  results = this.transactionOptions.map(function (options) {
9265
9623
  return send(options);
@@ -9317,7 +9675,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9317
9675
  key: "to",
9318
9676
  value: function to(node, paraIdTo) {
9319
9677
  if (this._options.from && sdkCommon.isRelayChain(this._options.from) && node === 'Ethereum') {
9320
- throw new Error('Transfers from Relay chain to Ethereum are not yet supported.');
9678
+ throw new InvalidParameterError('Transfers from Relay chain to Ethereum are not yet supported.');
9321
9679
  }
9322
9680
  return new GeneralBuilder(this.api, this.batchManager, _objectSpread2(_objectSpread2({}, this._options), {}, {
9323
9681
  to: node,
@@ -9487,14 +9845,14 @@ var GeneralBuilder = /*#__PURE__*/function () {
9487
9845
  _context2.next = 2;
9488
9846
  break;
9489
9847
  }
9490
- throw new Error('Transaction manager contains batched items. Use buildBatch() to process them.');
9848
+ throw new InvalidParameterError('Transaction manager contains batched items. Use buildBatch() to process them.');
9491
9849
  case 2:
9492
9850
  _this$_options = this._options, from = _this$_options.from, to = _this$_options.to;
9493
9851
  if (!(!sdkCommon.isTMultiLocation(to) && sdkCommon.isRelayChain(from) && sdkCommon.isRelayChain(to) && from !== to)) {
9494
9852
  _context2.next = 5;
9495
9853
  break;
9496
9854
  }
9497
- throw new Error('Transfers between relay chains are not yet supported.');
9855
+ throw new InvalidParameterError('Transfers between relay chains are not yet supported.');
9498
9856
  case 5:
9499
9857
  return _context2.abrupt("return", send(_objectSpread2({
9500
9858
  api: this.api
@@ -9535,12 +9893,6 @@ var GeneralBuilder = /*#__PURE__*/function () {
9535
9893
  }
9536
9894
  throw new InvalidParameterError('Multi-Location address is not supported for XCM fee calculation.');
9537
9895
  case 8:
9538
- if (!(to === 'Ethereum')) {
9539
- _context3.next = 10;
9540
- break;
9541
- }
9542
- throw new InvalidParameterError('Ethereum destination is not yet supported for XCM fee calculation.');
9543
- case 10:
9544
9896
  return _context3.abrupt("return", dryRun({
9545
9897
  api: this.api,
9546
9898
  tx: tx,
@@ -9551,7 +9903,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9551
9903
  senderAddress: this._options.senderAddress,
9552
9904
  feeAsset: feeAsset
9553
9905
  }));
9554
- case 11:
9906
+ case 9:
9555
9907
  case "end":
9556
9908
  return _context3.stop();
9557
9909
  }
@@ -9588,7 +9940,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9588
9940
  disableFallback: false
9589
9941
  }, disableFallback = _ref.disableFallback;
9590
9942
  _this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress, feeAsset = _this$_options3.feeAsset;
9591
- assertToIsStringAndNoEthereum(to);
9943
+ assertToIsString(to);
9592
9944
  assertAddressIsString(address);
9593
9945
  _context4.next = 6;
9594
9946
  return this.build();
@@ -9653,7 +10005,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9653
10005
  disableFallback: false
9654
10006
  }, disableFallback = _ref2.disableFallback;
9655
10007
  _this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress, currency = _this$_options4.currency, feeAsset = _this$_options4.feeAsset;
9656
- assertToIsStringAndNoEthereum(to);
10008
+ assertToIsString(to);
9657
10009
  _context5.next = 5;
9658
10010
  return this.build();
9659
10011
  case 5:
@@ -9704,7 +10056,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9704
10056
  while (1) switch (_context6.prev = _context6.next) {
9705
10057
  case 0:
9706
10058
  _this$_options5 = this._options, from = _this$_options5.from, to = _this$_options5.to, address = _this$_options5.address, senderAddress = _this$_options5.senderAddress;
9707
- assertToIsStringAndNoEthereum(to);
10059
+ assertToIsString(to);
9708
10060
  assertAddressIsString(address);
9709
10061
  _context6.next = 5;
9710
10062
  return this.build();
@@ -9755,7 +10107,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9755
10107
  while (1) switch (_context7.prev = _context7.next) {
9756
10108
  case 0:
9757
10109
  _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress;
9758
- assertToIsStringAndNoEthereum(to);
10110
+ assertToIsString(to);
9759
10111
  _context7.next = 4;
9760
10112
  return this.build();
9761
10113
  case 4:
@@ -9803,7 +10155,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9803
10155
  while (1) switch (_context8.prev = _context8.next) {
9804
10156
  case 0:
9805
10157
  _this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
9806
- assertToIsStringAndNoEthereum(to);
10158
+ assertToIsString(to);
9807
10159
  _context8.next = 4;
9808
10160
  return this.build();
9809
10161
  case 4:
@@ -9846,7 +10198,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9846
10198
  while (1) switch (_context9.prev = _context9.next) {
9847
10199
  case 0:
9848
10200
  _this$_options8 = this._options, from = _this$_options8.from, to = _this$_options8.to, address = _this$_options8.address, currency = _this$_options8.currency, senderAddress = _this$_options8.senderAddress, feeAsset = _this$_options8.feeAsset;
9849
- assertToIsStringAndNoEthereum(to);
10201
+ assertToIsString(to);
9850
10202
  assertAddressIsString(address);
9851
10203
  _context9.next = 5;
9852
10204
  return this.build();
@@ -9888,7 +10240,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9888
10240
  while (1) switch (_context0.prev = _context0.next) {
9889
10241
  case 0:
9890
10242
  _this$_options9 = this._options, from = _this$_options9.from, to = _this$_options9.to, address = _this$_options9.address, currency = _this$_options9.currency, senderAddress = _this$_options9.senderAddress, feeAsset = _this$_options9.feeAsset;
9891
- assertToIsStringAndNoEthereum(to);
10243
+ assertToIsString(to);
9892
10244
  assertAddressIsString(address);
9893
10245
  _context0.next = 5;
9894
10246
  return this.build();