@paraspell/sdk-core 10.0.2 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { blake2b } from '@noble/hashes/blake2';
2
- import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset, findAsset, isTMultiAsset, hasDryRunSupport, findAssetForNodeOrThrow, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, hasSupportForAsset, extractMultiAssetLoc, isAssetEqual, isSymbolSpecifier, getAssetId, getExistentialDeposit, findAssetOnDestOrThrow, normalizeSymbol } from '@paraspell/assets';
2
+ import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset, findAssetForNodeOrThrow, findAsset, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, isTMultiAsset, hasDryRunSupport, hasSupportForAsset, extractMultiAssetLoc, isAssetEqual, isSymbolSpecifier, getAssetId, getExistentialDeposit, findAssetOnDestOrThrow, normalizeSymbol } from '@paraspell/assets';
3
3
  export * from '@paraspell/assets';
4
4
  import { base58 } from '@scure/base';
5
5
  import { ethers, Contract } from 'ethers';
6
- import { Parents, isTMultiLocation, NODE_NAMES_DOT_KSM, isRelayChain, hasJunction, deepEqual } from '@paraspell/sdk-common';
6
+ import { Parents, isTMultiLocation, NODE_NAMES_DOT_KSM, isRelayChain, hasJunction, deepEqual, isDotKsmBridge } from '@paraspell/sdk-common';
7
7
  export * from '@paraspell/sdk-common';
8
8
  import { getSupportedPalletsDetails, getDefaultPallet } from '@paraspell/pallets';
9
9
  export * from '@paraspell/pallets';
@@ -184,7 +184,10 @@ function _iterableToArrayLimit(r, l) {
184
184
  f = true,
185
185
  o = false;
186
186
  try {
187
- 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);
187
+ if (i = (t = t.call(r)).next, 0 === l) {
188
+ if (Object(t) !== t) return;
189
+ f = !1;
190
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
188
191
  } catch (r) {
189
192
  o = true, n = r;
190
193
  } finally {
@@ -607,7 +610,7 @@ var DryRunFailedError = /*#__PURE__*/function (_Error) {
607
610
  _classCallCheck(this, DryRunFailedError);
608
611
  var message = "Dry run failed: ".concat(reason);
609
612
  if (dryRunType) {
610
- message = "Dry run ".concat(dryRunType, " failed: ").concat(reason);
613
+ message = "Dry run on ".concat(dryRunType, " failed: ").concat(reason);
611
614
  }
612
615
  _this = _callSuper(this, DryRunFailedError, [message]);
613
616
  _this.name = 'DryRunFailedError';
@@ -2776,6 +2779,10 @@ var getNode = function getNode(node) {
2776
2779
  return nodeMap[node];
2777
2780
  };
2778
2781
 
2782
+ var replaceBigInt = function replaceBigInt(_key, value) {
2783
+ return typeof value === 'bigint' ? value.toString() : value;
2784
+ };
2785
+
2779
2786
  var resolveParaId = function resolveParaId(paraId, destination) {
2780
2787
  if (isTMultiLocation(destination) || isRelayChain(destination) || destination === 'Ethereum') {
2781
2788
  return undefined;
@@ -2961,652 +2968,310 @@ var getTNode = function getTNode(paraId, ecosystem) {
2961
2968
  })) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
2962
2969
  };
2963
2970
 
2964
- var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
2965
- var asset = findAsset(origin, feeAsset, !isTMultiLocation(destination) ? destination : null);
2966
- var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(isTMultiAsset);
2967
- if (!asset && !usesRawOverriddenMultiAssets) {
2968
- throwUnsupportedCurrency(feeAsset, origin);
2971
+ var getParaEthTransferFees = /*#__PURE__*/function () {
2972
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
2973
+ var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
2974
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2975
+ while (1) switch (_context.prev = _context.next) {
2976
+ case 0:
2977
+ DEFAULT_FEE = 2750872500000n;
2978
+ _context.next = 3;
2979
+ return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
2980
+ case 3:
2981
+ feeStorageItem = _context.sent;
2982
+ leFeeHex = feeStorageItem.replace('0x', '');
2983
+ _context.next = 7;
2984
+ return ahApi.disconnect();
2985
+ case 7:
2986
+ bytes = leFeeHex.match(/.{1,2}/g) || [];
2987
+ reversedHex = bytes.reverse().join('');
2988
+ validReversedHex = reversedHex === '' ? '0' : reversedHex;
2989
+ leFee = BigInt('0x' + validReversedHex);
2990
+ transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
2991
+ finalBridgeFee = transferBridgeFee * 110n / 100n;
2992
+ finalAssethubExecutionFee = ASSET_HUB_EXECUTION_FEE * 110n / 100n;
2993
+ return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
2994
+ case 15:
2995
+ case "end":
2996
+ return _context.stop();
2997
+ }
2998
+ }, _callee);
2999
+ }));
3000
+ return function getParaEthTransferFees(_x) {
3001
+ return _ref.apply(this, arguments);
3002
+ };
3003
+ }();
3004
+
3005
+ // Inspired by Moonbeam XCM-SDK
3006
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3007
+ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3008
+ if (id.startsWith('0x')) {
3009
+ return id;
2969
3010
  }
2970
- return asset !== null && asset !== void 0 ? asset : undefined;
3011
+ if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3012
+ throw new InvalidParameterError("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3013
+ }
3014
+ return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
2971
3015
  };
2972
3016
 
2973
- var isAssetHub = function isAssetHub(chain) {
2974
- return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
2975
- };
2976
- var isBridgeHub = function isBridgeHub(chain) {
2977
- return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
2978
- };
2979
- var isPeople = function isPeople(chain) {
2980
- return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
2981
- };
2982
- var isSystemPara = function isSystemPara(chain) {
2983
- return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
2984
- };
2985
- var mul = function mul(v, num) {
2986
- var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
2987
- return v * num / den;
2988
- };
2989
- var padFee = function padFee(raw, origin, dest, side) {
2990
- var relayOrigin = isRelayChain(origin);
2991
- var relayDest = isRelayChain(dest);
2992
- var sysParaOrigin = isSystemPara(origin);
2993
- var sysParaDest = isSystemPara(dest);
2994
- var relayToPara = relayOrigin && !relayDest;
2995
- var sysParaToPara = sysParaOrigin && !sysParaDest;
2996
- var paraToPara = !relayOrigin && !sysParaOrigin;
2997
- if (sysParaToPara) return raw * 40n;
2998
- if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
2999
- if (paraToPara) return mul(raw, 130n, 100n);
3000
- // apply default 30% padding
3001
- return mul(raw, 130n, 100n);
3002
- };
3017
+ var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
3018
+ var MOONBEAM_ID = 1284;
3019
+ var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
3020
+ var MOONRIVER_ID = 1285;
3021
+ var ERC20_ABI$1 = ['function balanceOf(address) view returns (uint256)'];
3022
+ function getMoonbeamErc20Balance(_x, _x2, _x3) {
3023
+ return _getMoonbeamErc20Balance.apply(this, arguments);
3024
+ }
3025
+ function _getMoonbeamErc20Balance() {
3026
+ _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
3027
+ var _ref, rpc, id, provider, addr, token;
3028
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3029
+ while (1) switch (_context.prev = _context.next) {
3030
+ case 0:
3031
+ _ref = node === 'Moonbeam' ? {
3032
+ rpc: MOONBEAM_RPC,
3033
+ id: MOONBEAM_ID
3034
+ } : {
3035
+ rpc: MOONRIVER_RPC,
3036
+ id: MOONRIVER_ID
3037
+ }, rpc = _ref.rpc, id = _ref.id;
3038
+ provider = new ethers.JsonRpcProvider(rpc, id);
3039
+ addr = formatAssetIdToERC20(assetId);
3040
+ token = new ethers.Contract(addr, ERC20_ABI$1, provider);
3041
+ _context.next = 6;
3042
+ return token.balanceOf(address);
3043
+ case 6:
3044
+ return _context.abrupt("return", _context.sent);
3045
+ case 7:
3046
+ case "end":
3047
+ return _context.stop();
3048
+ }
3049
+ }, _callee);
3050
+ }));
3051
+ return _getMoonbeamErc20Balance.apply(this, arguments);
3052
+ }
3003
3053
 
3004
- var getReverseTxFee = /*#__PURE__*/function () {
3005
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
3006
- var api, origin, destination, senderAddress, address, currency, tx, rawFee;
3054
+ var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
3055
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3056
+ var ASSETS_PALLET_ID, hasRequiredJunctions;
3007
3057
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3008
3058
  while (1) switch (_context.prev = _context.next) {
3009
3059
  case 0:
3010
- api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
3011
- if (!('multiasset' in currency)) {
3060
+ if (!(node === 'Moonbeam' || node === 'Moonriver')) {
3061
+ _context.next = 6;
3062
+ break;
3063
+ }
3064
+ if (!(!isForeignAsset(asset) || !asset.assetId)) {
3012
3065
  _context.next = 3;
3013
3066
  break;
3014
3067
  }
3015
- throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
3068
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3016
3069
  case 3:
3017
- _context.next = 5;
3018
- return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
3019
- amount: currency.amount
3020
- })).build();
3070
+ if (!(asset.multiLocation && hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
3071
+ _context.next = 5;
3072
+ break;
3073
+ }
3074
+ return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
3021
3075
  case 5:
3022
- tx = _context.sent;
3023
- _context.next = 8;
3024
- return api.calculateTransactionFee(tx, address);
3076
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3077
+ case 6:
3078
+ if (!(node === 'Mythos')) {
3079
+ _context.next = 8;
3080
+ break;
3081
+ }
3082
+ return _context.abrupt("return", api.getMythosForeignBalance(address));
3025
3083
  case 8:
3026
- rawFee = _context.sent;
3027
- return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
3084
+ if (isForeignAsset(asset)) {
3085
+ _context.next = 10;
3086
+ break;
3087
+ }
3088
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3028
3089
  case 10:
3090
+ if (!(node === 'Polimec')) {
3091
+ _context.next = 14;
3092
+ break;
3093
+ }
3094
+ if (!(asset.multiLocation === undefined)) {
3095
+ _context.next = 13;
3096
+ break;
3097
+ }
3098
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
3099
+ case 13:
3100
+ return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3101
+ case 14:
3102
+ if (!(node === 'AssetHubPolkadot')) {
3103
+ _context.next = 20;
3104
+ break;
3105
+ }
3106
+ ASSETS_PALLET_ID = 50;
3107
+ hasRequiredJunctions = asset.multiLocation && hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && hasJunction(asset.multiLocation, 'GeneralIndex');
3108
+ if (!(!asset.multiLocation || hasRequiredJunctions)) {
3109
+ _context.next = 19;
3110
+ break;
3111
+ }
3112
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
3113
+ case 19:
3114
+ return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3115
+ case 20:
3116
+ return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
3117
+ case 21:
3029
3118
  case "end":
3030
3119
  return _context.stop();
3031
3120
  }
3032
3121
  }, _callee);
3033
3122
  }));
3034
- return function getReverseTxFee(_x, _x2) {
3035
- return _ref2.apply(this, arguments);
3123
+ return function getBalanceForeignPolkadotXcm(_x, _x2, _x3, _x4) {
3124
+ return _ref.apply(this, arguments);
3036
3125
  };
3037
3126
  }();
3038
3127
 
3039
- var createOriginLocation = function createOriginLocation(origin, destination) {
3040
- if (isRelayChain(origin)) return DOT_MULTILOCATION;
3041
- return {
3042
- parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
3043
- interior: {
3044
- X1: [{
3045
- Parachain: getParaId(origin)
3046
- }]
3047
- }
3048
- };
3049
- };
3050
- var getDestXcmFee = /*#__PURE__*/function () {
3051
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3052
- var api, origin, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
3053
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3054
- while (1) switch (_context2.prev = _context2.next) {
3128
+ var getBalanceForeignXTokens = /*#__PURE__*/function () {
3129
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3130
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3131
+ while (1) switch (_context.prev = _context.next) {
3055
3132
  case 0:
3056
- 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;
3057
- resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
3058
- calcPaymentInfoFee = /*#__PURE__*/function () {
3059
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
3060
- var originAsset;
3061
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3062
- while (1) switch (_context.prev = _context.next) {
3063
- case 0:
3064
- originAsset = findAsset(origin, currency, destination);
3065
- if (originAsset) {
3066
- _context.next = 3;
3067
- break;
3068
- }
3069
- throw new InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
3070
- case 3:
3071
- if (!originAsset.multiLocation) {
3072
- _context.next = 17;
3073
- break;
3074
- }
3075
- _context.prev = 4;
3076
- _context.next = 7;
3077
- return getReverseTxFee(options, {
3078
- multilocation: originAsset.multiLocation
3079
- });
3080
- case 7:
3081
- return _context.abrupt("return", _context.sent);
3082
- case 10:
3083
- _context.prev = 10;
3084
- _context.t0 = _context["catch"](4);
3085
- if (!(_context.t0 instanceof InvalidCurrencyError)) {
3086
- _context.next = 16;
3087
- break;
3088
- }
3089
- _context.next = 15;
3090
- return getReverseTxFee(options, {
3091
- symbol: originAsset.symbol
3092
- });
3093
- case 15:
3094
- return _context.abrupt("return", _context.sent);
3095
- case 16:
3096
- throw _context.t0;
3097
- case 17:
3098
- _context.next = 19;
3099
- return getReverseTxFee(options, {
3100
- symbol: originAsset.symbol
3101
- });
3102
- case 19:
3103
- return _context.abrupt("return", _context.sent);
3104
- case 20:
3105
- case "end":
3106
- return _context.stop();
3107
- }
3108
- }, _callee, null, [[4, 10]]);
3109
- }));
3110
- return function calcPaymentInfoFee() {
3111
- return _ref2.apply(this, arguments);
3112
- };
3113
- }();
3114
- if (!(!hasDryRunSupport(destination) || !forwardedXcms)) {
3115
- _context2.next = 8;
3133
+ if (!(node === 'Astar' || node === 'Shiden')) {
3134
+ _context.next = 4;
3116
3135
  break;
3117
3136
  }
3118
- _context2.next = 6;
3119
- return calcPaymentInfoFee();
3120
- case 6:
3121
- _context2.t0 = _context2.sent;
3122
- return _context2.abrupt("return", {
3123
- fee: _context2.t0,
3124
- feeType: 'paymentInfo'
3125
- });
3126
- case 8:
3127
- _context2.next = 10;
3128
- return api.getDryRunXcm({
3129
- originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), Version.V4),
3130
- xcm: forwardedXcms[1][0],
3131
- node: destination,
3132
- origin: origin,
3133
- asset: asset,
3134
- originFee: originFee,
3135
- feeAsset: resolvedFeeAsset,
3136
- amount: BigInt(currency.amount)
3137
- });
3138
- case 10:
3139
- dryRunResult = _context2.sent;
3140
- if (dryRunResult.success) {
3141
- _context2.next = 19;
3137
+ if (!(!isForeignAsset(asset) || !asset.assetId)) {
3138
+ _context.next = 3;
3142
3139
  break;
3143
3140
  }
3144
- if (!disableFallback) {
3145
- _context2.next = 14;
3141
+ throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3142
+ case 3:
3143
+ return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3144
+ case 4:
3145
+ if (!(node === 'BifrostPolkadot' || node === 'BifrostKusama')) {
3146
+ _context.next = 6;
3146
3147
  break;
3147
3148
  }
3148
- return _context2.abrupt("return", {
3149
- dryRunError: dryRunResult.failureReason
3150
- });
3151
- case 14:
3152
- _context2.next = 16;
3153
- return calcPaymentInfoFee();
3154
- case 16:
3155
- _context2.t1 = _context2.sent;
3156
- _context2.t2 = dryRunResult.failureReason;
3157
- return _context2.abrupt("return", {
3158
- fee: _context2.t1,
3159
- feeType: 'paymentInfo',
3160
- dryRunError: _context2.t2
3161
- });
3162
- case 19:
3163
- fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
3164
- return _context2.abrupt("return", {
3165
- fee: fee,
3166
- feeType: 'dryRun',
3167
- forwardedXcms: newForwardedXcms,
3168
- destParaId: destParaId
3169
- });
3170
- case 21:
3149
+ return _context.abrupt("return", api.getBalanceForeignBifrost(address, asset));
3150
+ case 6:
3151
+ return _context.abrupt("return", api.getBalanceForeignXTokens(node, address, asset));
3152
+ case 7:
3171
3153
  case "end":
3172
- return _context2.stop();
3154
+ return _context.stop();
3173
3155
  }
3174
- }, _callee2);
3156
+ }, _callee);
3175
3157
  }));
3176
- return function getDestXcmFee(_x) {
3158
+ return function getBalanceForeignXTokens(_x, _x2, _x3, _x4) {
3177
3159
  return _ref.apply(this, arguments);
3178
3160
  };
3179
3161
  }();
3180
3162
 
3181
- var dryRunInternal = /*#__PURE__*/function () {
3182
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3183
- var _intermediateFees$ass, _intermediateFees$bri, _destinationDryRun;
3184
- var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
3163
+ var getBalanceForeignInternal = /*#__PURE__*/function () {
3164
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3165
+ var address, node, currency, api, asset, defaultPallet;
3185
3166
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3186
3167
  while (1) switch (_context.prev = _context.next) {
3187
3168
  case 0:
3188
- origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
3189
- resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
3190
- asset = findAssetForNodeOrThrow(origin, currency, destination);
3191
- _context.next = 5;
3192
- return api.getDryRunCall({
3193
- tx: tx,
3194
- node: origin,
3195
- address: senderAddress,
3196
- isFeeAsset: !!resolvedFeeAsset
3197
- });
3198
- case 5:
3199
- originDryRun = _context.sent;
3200
- if (originDryRun.success) {
3201
- _context.next = 8;
3202
- break;
3203
- }
3204
- return _context.abrupt("return", {
3205
- origin: originDryRun
3206
- });
3207
- case 8:
3208
- initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
3209
- currentOrigin = origin;
3210
- forwardedXcms = initialForwardedXcms;
3211
- nextParaId = initialDestParaId;
3212
- intermediateFees = {};
3213
- case 13:
3214
- 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)) {
3215
- _context.next = 40;
3216
- break;
3217
- }
3218
- nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
3219
- if (nextChain) {
3220
- _context.next = 17;
3221
- break;
3222
- }
3223
- throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
3224
- case 17:
3225
- hopApi = api.clone();
3226
- _context.prev = 18;
3227
- if (hasDryRunSupport(nextChain)) {
3228
- _context.next = 22;
3169
+ address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3170
+ _context.next = 3;
3171
+ return api.init(node);
3172
+ case 3:
3173
+ asset = findAssetForNodeOrThrow(node, currency, null);
3174
+ defaultPallet = getDefaultPallet(node);
3175
+ if (!(defaultPallet === 'XTokens')) {
3176
+ _context.next = 9;
3229
3177
  break;
3230
3178
  }
3231
- if (nextChain === destination) {
3232
- destinationDryRun = {
3233
- success: false,
3234
- failureReason: "DryRunApi is not available on node ".concat(nextChain)
3235
- };
3236
- }
3237
- return _context.abrupt("break", 40);
3238
- case 22:
3239
- _context.next = 24;
3240
- return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
3241
- case 24:
3242
- _context.next = 26;
3243
- return hopApi.getDryRunXcm({
3244
- originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), Version.V4),
3245
- xcm: forwardedXcms[1][0],
3246
- node: nextChain,
3247
- origin: currentOrigin,
3248
- asset: asset,
3249
- feeAsset: resolvedFeeAsset,
3250
- originFee: originDryRun.fee,
3251
- amount: BigInt(currency.amount)
3252
- });
3253
- case 26:
3254
- hopDryRun = _context.sent;
3255
- if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
3256
- destinationDryRun = hopDryRun;
3257
- } else if (nextChain === 'AssetHubPolkadot') {
3258
- intermediateFees.assetHub = hopDryRun;
3259
- } else if (nextChain === 'BridgeHubPolkadot') {
3260
- intermediateFees.bridgeHub = hopDryRun;
3261
- }
3262
- if (hopDryRun.success) {
3263
- _context.next = 30;
3179
+ return _context.abrupt("return", getBalanceForeignXTokens(api, node, address, asset));
3180
+ case 9:
3181
+ if (!(defaultPallet === 'PolkadotXcm')) {
3182
+ _context.next = 11;
3264
3183
  break;
3265
3184
  }
3266
- return _context.abrupt("break", 40);
3267
- case 30:
3268
- newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
3269
- forwardedXcms = newXcms;
3270
- nextParaId = destParaId;
3271
- currentOrigin = nextChain;
3272
- case 34:
3273
- _context.prev = 34;
3274
- _context.next = 37;
3275
- return hopApi.disconnect();
3276
- case 37:
3277
- return _context.finish(34);
3278
- case 38:
3279
- _context.next = 13;
3280
- break;
3281
- case 40:
3282
- return _context.abrupt("return", {
3283
- origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
3284
- currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
3285
- }) : originDryRun,
3286
- assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
3287
- currency: getNativeAssetSymbol('AssetHubPolkadot')
3288
- }) : intermediateFees.assetHub,
3289
- bridgeHub: (_intermediateFees$bri = intermediateFees.bridgeHub) !== null && _intermediateFees$bri !== void 0 && _intermediateFees$bri.success ? _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
3290
- currency: getNativeAssetSymbol('BridgeHubPolkadot')
3291
- }) : intermediateFees.bridgeHub,
3292
- destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
3293
- currency: asset.symbol
3294
- }) : destinationDryRun
3295
- });
3296
- case 41:
3185
+ return _context.abrupt("return", getBalanceForeignPolkadotXcm(api, node, address, asset));
3186
+ case 11:
3187
+ throw new InvalidParameterError('Unsupported pallet');
3188
+ case 12:
3297
3189
  case "end":
3298
3190
  return _context.stop();
3299
3191
  }
3300
- }, _callee, null, [[18,, 34, 38]]);
3192
+ }, _callee);
3301
3193
  }));
3302
- return function dryRunInternal(_x) {
3303
- return _ref.apply(this, arguments);
3194
+ return function getBalanceForeignInternal(_x) {
3195
+ return _ref2.apply(this, arguments);
3304
3196
  };
3305
3197
  }();
3306
-
3307
- var dryRun = /*#__PURE__*/function () {
3308
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3309
- var api, senderAddress, origin;
3310
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3311
- while (1) switch (_context.prev = _context.next) {
3198
+ var getBalanceForeign = /*#__PURE__*/function () {
3199
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3200
+ var api;
3201
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3202
+ while (1) switch (_context2.prev = _context2.next) {
3312
3203
  case 0:
3313
- api = options.api, senderAddress = options.senderAddress, origin = options.origin;
3314
- validateAddress(senderAddress, origin, false);
3315
- _context.next = 4;
3316
- return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
3204
+ api = options.api;
3205
+ _context2.prev = 1;
3206
+ _context2.next = 4;
3207
+ return getBalanceForeignInternal(options);
3317
3208
  case 4:
3318
- _context.prev = 4;
3319
- _context.next = 7;
3320
- return dryRunInternal(options);
3321
- case 7:
3322
- return _context.abrupt("return", _context.sent);
3323
- case 8:
3324
- _context.prev = 8;
3325
- _context.next = 11;
3209
+ return _context2.abrupt("return", _context2.sent);
3210
+ case 5:
3211
+ _context2.prev = 5;
3212
+ _context2.next = 8;
3326
3213
  return api.disconnect();
3327
- case 11:
3328
- return _context.finish(8);
3329
- case 12:
3214
+ case 8:
3215
+ return _context2.finish(5);
3216
+ case 9:
3330
3217
  case "end":
3331
- return _context.stop();
3218
+ return _context2.stop();
3332
3219
  }
3333
- }, _callee, null, [[4,, 8, 12]]);
3220
+ }, _callee2, null, [[1,, 5, 9]]);
3334
3221
  }));
3335
- return function dryRun(_x) {
3336
- return _ref.apply(this, arguments);
3222
+ return function getBalanceForeign(_x2) {
3223
+ return _ref3.apply(this, arguments);
3337
3224
  };
3338
3225
  }();
3339
3226
 
3340
- var dryRunOrigin = /*#__PURE__*/function () {
3341
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
3342
- var api, node, address, result;
3227
+ var getBalanceNativeInternal = /*#__PURE__*/function () {
3228
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3229
+ var address, node, api, currency, symbol;
3343
3230
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3344
3231
  while (1) switch (_context.prev = _context.next) {
3345
3232
  case 0:
3346
- api = options.api, node = options.node, address = options.address;
3347
- validateAddress(address, node, false);
3348
- _context.next = 4;
3349
- return api.init(node, DRY_RUN_CLIENT_TIMEOUT_MS);
3350
- case 4:
3351
- _context.prev = 4;
3352
- _context.next = 7;
3353
- return api.getDryRunCall(options);
3354
- case 7:
3355
- result = _context.sent;
3356
- if (!result.success) {
3357
- _context.next = 12;
3233
+ address = _ref.address, node = _ref.node, api = _ref.api, currency = _ref.currency;
3234
+ _context.next = 3;
3235
+ return api.init(node);
3236
+ case 3:
3237
+ if (!(node === 'Interlay' || node === 'Kintsugi')) {
3238
+ _context.next = 5;
3358
3239
  break;
3359
3240
  }
3360
- return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
3361
- currency: getNativeAssetSymbol(node)
3241
+ return _context.abrupt("return", getBalanceForeignInternal({
3242
+ address: address,
3243
+ node: node,
3244
+ api: api,
3245
+ currency: {
3246
+ symbol: currency ? currency.symbol : getAssetsObject(node).nativeAssetSymbol
3247
+ }
3362
3248
  }));
3363
- case 12:
3364
- return _context.abrupt("return", result);
3365
- case 13:
3366
- _context.prev = 13;
3367
- _context.next = 16;
3368
- return api.disconnect();
3369
- case 16:
3370
- return _context.finish(13);
3371
- case 17:
3372
- case "end":
3373
- return _context.stop();
3374
- }
3375
- }, _callee, null, [[4,, 13, 17]]);
3376
- }));
3377
- return function dryRunOrigin(_x) {
3378
- return _ref.apply(this, arguments);
3379
- };
3380
- }();
3381
-
3382
- var getParaEthTransferFees = /*#__PURE__*/function () {
3383
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ahApi) {
3384
- var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
3385
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3386
- while (1) switch (_context.prev = _context.next) {
3387
- case 0:
3388
- DEFAULT_FEE = 2750872500000n;
3389
- _context.next = 3;
3390
- return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
3391
- case 3:
3392
- feeStorageItem = _context.sent;
3393
- leFeeHex = feeStorageItem.replace('0x', '');
3394
- _context.next = 7;
3395
- return ahApi.disconnect();
3396
- case 7:
3397
- bytes = leFeeHex.match(/.{1,2}/g) || [];
3398
- reversedHex = bytes.reverse().join('');
3399
- validReversedHex = reversedHex === '' ? '0' : reversedHex;
3400
- leFee = BigInt('0x' + validReversedHex);
3401
- transferBridgeFee = leFee === 0n ? DEFAULT_FEE : BigInt(leFee.toString());
3402
- finalBridgeFee = transferBridgeFee * 110n / 100n;
3403
- finalAssethubExecutionFee = ASSET_HUB_EXECUTION_FEE * 110n / 100n;
3404
- return _context.abrupt("return", [finalBridgeFee, finalAssethubExecutionFee]);
3405
- case 15:
3406
- case "end":
3407
- return _context.stop();
3408
- }
3409
- }, _callee);
3410
- }));
3411
- return function getParaEthTransferFees(_x) {
3412
- return _ref.apply(this, arguments);
3413
- };
3414
- }();
3415
-
3416
- // Inspired by Moonbeam XCM-SDK
3417
- // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
3418
- var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
3419
- if (id.startsWith('0x')) {
3420
- return id;
3421
- }
3422
- if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
3423
- throw new InvalidParameterError("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
3424
- }
3425
- return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
3426
- };
3427
-
3428
- var MOONBEAM_RPC = 'https://rpc.api.moonbeam.network';
3429
- var MOONBEAM_ID = 1284;
3430
- var MOONRIVER_RPC = 'https://rpc.api.moonriver.moonbeam.network';
3431
- var MOONRIVER_ID = 1285;
3432
- var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
3433
- function getMoonbeamErc20Balance(_x, _x2, _x3) {
3434
- return _getMoonbeamErc20Balance.apply(this, arguments);
3435
- }
3436
- function _getMoonbeamErc20Balance() {
3437
- _getMoonbeamErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node, assetId, address) {
3438
- var _ref, rpc, id, provider, addr, token;
3439
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3440
- while (1) switch (_context.prev = _context.next) {
3441
- case 0:
3442
- _ref = node === 'Moonbeam' ? {
3443
- rpc: MOONBEAM_RPC,
3444
- id: MOONBEAM_ID
3445
- } : {
3446
- rpc: MOONRIVER_RPC,
3447
- id: MOONRIVER_ID
3448
- }, rpc = _ref.rpc, id = _ref.id;
3449
- provider = new ethers.JsonRpcProvider(rpc, id);
3450
- addr = formatAssetIdToERC20(assetId);
3451
- token = new ethers.Contract(addr, ERC20_ABI, provider);
3452
- _context.next = 6;
3453
- return token.balanceOf(address);
3454
- case 6:
3455
- return _context.abrupt("return", _context.sent);
3456
- case 7:
3457
- case "end":
3458
- return _context.stop();
3459
- }
3460
- }, _callee);
3461
- }));
3462
- return _getMoonbeamErc20Balance.apply(this, arguments);
3463
- }
3464
-
3465
- var getBalanceForeignPolkadotXcm = /*#__PURE__*/function () {
3466
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3467
- var ASSETS_PALLET_ID, hasRequiredJunctions;
3468
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3469
- while (1) switch (_context.prev = _context.next) {
3470
- case 0:
3471
- if (!(node === 'Moonbeam' || node === 'Moonriver')) {
3472
- _context.next = 6;
3473
- break;
3474
- }
3475
- if (!(!isForeignAsset(asset) || !asset.assetId)) {
3476
- _context.next = 3;
3477
- break;
3478
- }
3479
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3480
- case 3:
3481
- if (!(asset.multiLocation && hasJunction(asset.multiLocation, 'GlobalConsensus'))) {
3482
- _context.next = 5;
3483
- break;
3484
- }
3485
- return _context.abrupt("return", getMoonbeamErc20Balance(node, asset.assetId, address));
3486
3249
  case 5:
3487
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3488
- case 6:
3489
- if (!(node === 'Mythos')) {
3490
- _context.next = 8;
3491
- break;
3492
- }
3493
- return _context.abrupt("return", api.getMythosForeignBalance(address));
3494
- case 8:
3495
- if (isForeignAsset(asset)) {
3250
+ if (!(currency && currency.symbol !== getNativeAssetSymbol(node) && (node === 'Acala' || node === 'Karura'))) {
3496
3251
  _context.next = 10;
3497
3252
  break;
3498
3253
  }
3499
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset"));
3500
- case 10:
3501
- if (!(node === 'Polimec')) {
3502
- _context.next = 14;
3503
- break;
3504
- }
3505
- if (!(asset.multiLocation === undefined)) {
3506
- _context.next = 13;
3507
- break;
3508
- }
3509
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no multi-location"));
3510
- case 13:
3511
- return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3512
- case 14:
3513
- if (!(node === 'AssetHubPolkadot')) {
3514
- _context.next = 20;
3515
- break;
3516
- }
3517
- ASSETS_PALLET_ID = 50;
3518
- hasRequiredJunctions = asset.multiLocation && hasJunction(asset.multiLocation, 'PalletInstance', ASSETS_PALLET_ID) && hasJunction(asset.multiLocation, 'GeneralIndex');
3519
- if (!(!asset.multiLocation || hasRequiredJunctions)) {
3520
- _context.next = 19;
3521
- break;
3522
- }
3523
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, Number(asset.assetId)));
3524
- case 19:
3525
- return _context.abrupt("return", api.getBalanceForeignAssetsPallet(address, asset.multiLocation));
3526
- case 20:
3527
- return _context.abrupt("return", api.getBalanceForeignPolkadotXcm(address, asset.assetId));
3528
- case 21:
3529
- case "end":
3530
- return _context.stop();
3531
- }
3532
- }, _callee);
3533
- }));
3534
- return function getBalanceForeignPolkadotXcm(_x, _x2, _x3, _x4) {
3535
- return _ref.apply(this, arguments);
3536
- };
3537
- }();
3538
-
3539
- var getBalanceForeignXTokens = /*#__PURE__*/function () {
3540
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, node, address, asset) {
3541
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3542
- while (1) switch (_context.prev = _context.next) {
3543
- case 0:
3544
- if (!(node === 'Astar' || node === 'Shiden')) {
3545
- _context.next = 4;
3546
- break;
3547
- }
3548
- if (!(!isForeignAsset(asset) || !asset.assetId)) {
3549
- _context.next = 3;
3550
- break;
3551
- }
3552
- throw new InvalidCurrencyError("Asset ".concat(JSON.stringify(asset), " has no assetId"));
3553
- case 3:
3554
- return _context.abrupt("return", api.getBalanceAssetsPallet(address, BigInt(asset.assetId)));
3555
- case 4:
3556
- if (!(node === 'BifrostPolkadot' || node === 'BifrostKusama')) {
3557
- _context.next = 6;
3558
- break;
3559
- }
3560
- return _context.abrupt("return", api.getBalanceForeignBifrost(address, asset));
3561
- case 6:
3562
- return _context.abrupt("return", api.getBalanceForeignXTokens(node, address, asset));
3563
- case 7:
3564
- case "end":
3565
- return _context.stop();
3566
- }
3567
- }, _callee);
3568
- }));
3569
- return function getBalanceForeignXTokens(_x, _x2, _x3, _x4) {
3570
- return _ref.apply(this, arguments);
3571
- };
3572
- }();
3573
-
3574
- var getBalanceForeignInternal = /*#__PURE__*/function () {
3575
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3576
- var address, node, currency, api, asset, defaultPallet;
3577
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3578
- while (1) switch (_context.prev = _context.next) {
3579
- case 0:
3580
- address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3581
- _context.next = 3;
3582
- return api.init(node);
3583
- case 3:
3584
- asset = findAssetForNodeOrThrow(node, currency, null);
3585
- defaultPallet = getDefaultPallet(node);
3586
- if (!(defaultPallet === 'XTokens')) {
3254
+ symbol = currency.symbol === 'aSEED' ? 'AUSD' : currency.symbol;
3255
+ if (!(symbol.toLowerCase() === 'lcdot')) {
3587
3256
  _context.next = 9;
3588
3257
  break;
3589
3258
  }
3590
- return _context.abrupt("return", getBalanceForeignXTokens(api, node, address, asset));
3259
+ throw new InvalidCurrencyError('LcDOT balance is not supported');
3591
3260
  case 9:
3592
- if (!(defaultPallet === 'PolkadotXcm')) {
3593
- _context.next = 11;
3594
- break;
3595
- }
3596
- return _context.abrupt("return", getBalanceForeignPolkadotXcm(api, node, address, asset));
3261
+ return _context.abrupt("return", api.getBalanceNativeAcala(address, symbol));
3262
+ case 10:
3263
+ return _context.abrupt("return", api.getBalanceNative(address));
3597
3264
  case 11:
3598
- throw new InvalidParameterError('Unsupported pallet');
3599
- case 12:
3600
3265
  case "end":
3601
3266
  return _context.stop();
3602
3267
  }
3603
3268
  }, _callee);
3604
3269
  }));
3605
- return function getBalanceForeignInternal(_x) {
3270
+ return function getBalanceNativeInternal(_x) {
3606
3271
  return _ref2.apply(this, arguments);
3607
3272
  };
3608
3273
  }();
3609
- var getBalanceForeign = /*#__PURE__*/function () {
3274
+ var getBalanceNative = /*#__PURE__*/function () {
3610
3275
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3611
3276
  var api;
3612
3277
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -3615,7 +3280,7 @@ var getBalanceForeign = /*#__PURE__*/function () {
3615
3280
  api = options.api;
3616
3281
  _context2.prev = 1;
3617
3282
  _context2.next = 4;
3618
- return getBalanceForeignInternal(options);
3283
+ return getBalanceNativeInternal(options);
3619
3284
  case 4:
3620
3285
  return _context2.abrupt("return", _context2.sent);
3621
3286
  case 5:
@@ -3630,106 +3295,30 @@ var getBalanceForeign = /*#__PURE__*/function () {
3630
3295
  }
3631
3296
  }, _callee2, null, [[1,, 5, 9]]);
3632
3297
  }));
3633
- return function getBalanceForeign(_x2) {
3298
+ return function getBalanceNative(_x2) {
3634
3299
  return _ref3.apply(this, arguments);
3635
3300
  };
3636
3301
  }();
3637
3302
 
3638
- var getBalanceNativeInternal = /*#__PURE__*/function () {
3303
+ var getAssetBalanceInternal = /*#__PURE__*/function () {
3639
3304
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3640
- var address, node, api, currency, symbol;
3305
+ var _yield$getBalanceFore;
3306
+ var address, node, currency, api, asset, isNativeSymbol;
3641
3307
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3642
3308
  while (1) switch (_context.prev = _context.next) {
3643
3309
  case 0:
3644
- address = _ref.address, node = _ref.node, api = _ref.api, currency = _ref.currency;
3310
+ address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3645
3311
  _context.next = 3;
3646
3312
  return api.init(node);
3647
3313
  case 3:
3648
- if (!(node === 'Interlay' || node === 'Kintsugi')) {
3649
- _context.next = 5;
3314
+ asset = findAssetForNodeOrThrow(node, currency, null);
3315
+ isNativeSymbol = asset.symbol === getNativeAssetSymbol(node);
3316
+ if (!(isNativeSymbol && node !== 'Interlay' && node !== 'Kintsugi')) {
3317
+ _context.next = 11;
3650
3318
  break;
3651
3319
  }
3652
- return _context.abrupt("return", getBalanceForeignInternal({
3653
- address: address,
3654
- node: node,
3655
- api: api,
3656
- currency: {
3657
- symbol: currency ? currency.symbol : getAssetsObject(node).nativeAssetSymbol
3658
- }
3659
- }));
3660
- case 5:
3661
- if (!(currency && currency.symbol !== getNativeAssetSymbol(node) && (node === 'Acala' || node === 'Karura'))) {
3662
- _context.next = 10;
3663
- break;
3664
- }
3665
- symbol = currency.symbol === 'aSEED' ? 'AUSD' : currency.symbol;
3666
- if (!(symbol.toLowerCase() === 'lcdot')) {
3667
- _context.next = 9;
3668
- break;
3669
- }
3670
- throw new InvalidCurrencyError('LcDOT balance is not supported');
3671
- case 9:
3672
- return _context.abrupt("return", api.getBalanceNativeAcala(address, symbol));
3673
- case 10:
3674
- return _context.abrupt("return", api.getBalanceNative(address));
3675
- case 11:
3676
- case "end":
3677
- return _context.stop();
3678
- }
3679
- }, _callee);
3680
- }));
3681
- return function getBalanceNativeInternal(_x) {
3682
- return _ref2.apply(this, arguments);
3683
- };
3684
- }();
3685
- var getBalanceNative = /*#__PURE__*/function () {
3686
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
3687
- var api;
3688
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3689
- while (1) switch (_context2.prev = _context2.next) {
3690
- case 0:
3691
- api = options.api;
3692
- _context2.prev = 1;
3693
- _context2.next = 4;
3694
- return getBalanceNativeInternal(options);
3695
- case 4:
3696
- return _context2.abrupt("return", _context2.sent);
3697
- case 5:
3698
- _context2.prev = 5;
3699
- _context2.next = 8;
3700
- return api.disconnect();
3701
- case 8:
3702
- return _context2.finish(5);
3703
- case 9:
3704
- case "end":
3705
- return _context2.stop();
3706
- }
3707
- }, _callee2, null, [[1,, 5, 9]]);
3708
- }));
3709
- return function getBalanceNative(_x2) {
3710
- return _ref3.apply(this, arguments);
3711
- };
3712
- }();
3713
-
3714
- var getAssetBalanceInternal = /*#__PURE__*/function () {
3715
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3716
- var _yield$getBalanceFore;
3717
- var address, node, currency, api, asset, isNativeSymbol;
3718
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3719
- while (1) switch (_context.prev = _context.next) {
3720
- case 0:
3721
- address = _ref.address, node = _ref.node, currency = _ref.currency, api = _ref.api;
3722
- _context.next = 3;
3723
- return api.init(node);
3724
- case 3:
3725
- asset = findAssetForNodeOrThrow(node, currency, null);
3726
- isNativeSymbol = asset.symbol === getNativeAssetSymbol(node);
3727
- if (!(isNativeSymbol && node !== 'Interlay' && node !== 'Kintsugi')) {
3728
- _context.next = 11;
3729
- break;
3730
- }
3731
- _context.next = 8;
3732
- return getBalanceNativeInternal({
3320
+ _context.next = 8;
3321
+ return getBalanceNativeInternal({
3733
3322
  address: address,
3734
3323
  node: node,
3735
3324
  api: api
@@ -4405,10 +3994,461 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
4405
3994
  case "end":
4406
3995
  return _context.stop();
4407
3996
  }
4408
- }, _callee);
3997
+ }, _callee);
3998
+ }));
3999
+ return function transferMoonbeamToEth(_x) {
4000
+ return _ref2.apply(this, arguments);
4001
+ };
4002
+ }();
4003
+
4004
+ var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
4005
+ var asset = findAsset(origin, feeAsset, !isTMultiLocation(destination) ? destination : null);
4006
+ var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(isTMultiAsset);
4007
+ if (!asset && !usesRawOverriddenMultiAssets) {
4008
+ throwUnsupportedCurrency(feeAsset, origin);
4009
+ }
4010
+ return asset !== null && asset !== void 0 ? asset : undefined;
4011
+ };
4012
+
4013
+ var isAssetHub = function isAssetHub(chain) {
4014
+ return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
4015
+ };
4016
+ var isBridgeHub = function isBridgeHub(chain) {
4017
+ return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
4018
+ };
4019
+ var isPeople = function isPeople(chain) {
4020
+ return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
4021
+ };
4022
+ var isSystemPara = function isSystemPara(chain) {
4023
+ return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
4024
+ };
4025
+ var mul = function mul(v, num) {
4026
+ var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
4027
+ return v * num / den;
4028
+ };
4029
+ var padFee = function padFee(raw, origin, dest, side) {
4030
+ var relayOrigin = isRelayChain(origin);
4031
+ var relayDest = isRelayChain(dest);
4032
+ var sysParaOrigin = isSystemPara(origin);
4033
+ var sysParaDest = isSystemPara(dest);
4034
+ var relayToPara = relayOrigin && !relayDest;
4035
+ var sysParaToPara = sysParaOrigin && !sysParaDest;
4036
+ var paraToPara = !relayOrigin && !sysParaOrigin;
4037
+ if (sysParaToPara) return raw * 40n;
4038
+ if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
4039
+ if (paraToPara) return mul(raw, 130n, 100n);
4040
+ // apply default 30% padding
4041
+ return mul(raw, 130n, 100n);
4042
+ };
4043
+
4044
+ var getReverseTxFee = /*#__PURE__*/function () {
4045
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
4046
+ var api, origin, destination, senderAddress, address, currency, tx, rawFee;
4047
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4048
+ while (1) switch (_context.prev = _context.next) {
4049
+ case 0:
4050
+ api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
4051
+ if (!('multiasset' in currency)) {
4052
+ _context.next = 3;
4053
+ break;
4054
+ }
4055
+ throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
4056
+ case 3:
4057
+ _context.next = 5;
4058
+ return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
4059
+ amount: currency.amount
4060
+ })).build();
4061
+ case 5:
4062
+ tx = _context.sent;
4063
+ _context.next = 8;
4064
+ return api.calculateTransactionFee(tx, address);
4065
+ case 8:
4066
+ rawFee = _context.sent;
4067
+ return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
4068
+ case 10:
4069
+ case "end":
4070
+ return _context.stop();
4071
+ }
4072
+ }, _callee);
4073
+ }));
4074
+ return function getReverseTxFee(_x, _x2) {
4075
+ return _ref2.apply(this, arguments);
4076
+ };
4077
+ }();
4078
+
4079
+ var createOriginLocation = function createOriginLocation(origin, destination) {
4080
+ if (isRelayChain(origin)) return DOT_MULTILOCATION;
4081
+ return {
4082
+ parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
4083
+ interior: {
4084
+ X1: [{
4085
+ Parachain: getParaId(origin)
4086
+ }]
4087
+ }
4088
+ };
4089
+ };
4090
+ var getDestXcmFee = /*#__PURE__*/function () {
4091
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
4092
+ var api, origin, hopNode, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
4093
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4094
+ while (1) switch (_context2.prev = _context2.next) {
4095
+ case 0:
4096
+ api = options.api, origin = options.origin, hopNode = options.prevNode, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
4097
+ resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4098
+ calcPaymentInfoFee = /*#__PURE__*/function () {
4099
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4100
+ var originAsset;
4101
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4102
+ while (1) switch (_context.prev = _context.next) {
4103
+ case 0:
4104
+ if (!(destination === 'Ethereum')) {
4105
+ _context.next = 2;
4106
+ break;
4107
+ }
4108
+ return _context.abrupt("return", 0n);
4109
+ case 2:
4110
+ originAsset = findAsset(origin, currency, destination);
4111
+ if (originAsset) {
4112
+ _context.next = 5;
4113
+ break;
4114
+ }
4115
+ throw new InvalidCurrencyError("Currency ".concat(JSON.stringify(currency, replaceBigInt), " not found in ").concat(origin));
4116
+ case 5:
4117
+ if (!originAsset.multiLocation) {
4118
+ _context.next = 19;
4119
+ break;
4120
+ }
4121
+ _context.prev = 6;
4122
+ _context.next = 9;
4123
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4124
+ destination: destination
4125
+ }), {
4126
+ multilocation: originAsset.multiLocation
4127
+ });
4128
+ case 9:
4129
+ return _context.abrupt("return", _context.sent);
4130
+ case 12:
4131
+ _context.prev = 12;
4132
+ _context.t0 = _context["catch"](6);
4133
+ if (!(_context.t0 instanceof InvalidCurrencyError)) {
4134
+ _context.next = 18;
4135
+ break;
4136
+ }
4137
+ _context.next = 17;
4138
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4139
+ destination: destination
4140
+ }), {
4141
+ symbol: originAsset.symbol
4142
+ });
4143
+ case 17:
4144
+ return _context.abrupt("return", _context.sent);
4145
+ case 18:
4146
+ throw _context.t0;
4147
+ case 19:
4148
+ _context.next = 21;
4149
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4150
+ destination: destination
4151
+ }), {
4152
+ symbol: originAsset.symbol
4153
+ });
4154
+ case 21:
4155
+ return _context.abrupt("return", _context.sent);
4156
+ case 22:
4157
+ case "end":
4158
+ return _context.stop();
4159
+ }
4160
+ }, _callee, null, [[6, 12]]);
4161
+ }));
4162
+ return function calcPaymentInfoFee() {
4163
+ return _ref2.apply(this, arguments);
4164
+ };
4165
+ }();
4166
+ if (!(!hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
4167
+ _context2.next = 8;
4168
+ break;
4169
+ }
4170
+ _context2.next = 6;
4171
+ return calcPaymentInfoFee();
4172
+ case 6:
4173
+ _context2.t0 = _context2.sent;
4174
+ return _context2.abrupt("return", {
4175
+ fee: _context2.t0,
4176
+ feeType: 'paymentInfo'
4177
+ });
4178
+ case 8:
4179
+ _context2.next = 10;
4180
+ return api.getDryRunXcm({
4181
+ originLocation: addXcmVersionHeader(createOriginLocation(hopNode, destination), Version.V4),
4182
+ xcm: forwardedXcms[1][0],
4183
+ node: destination,
4184
+ origin: origin,
4185
+ asset: asset,
4186
+ originFee: originFee,
4187
+ feeAsset: resolvedFeeAsset,
4188
+ amount: BigInt(currency.amount)
4189
+ });
4190
+ case 10:
4191
+ dryRunResult = _context2.sent;
4192
+ if (dryRunResult.success) {
4193
+ _context2.next = 19;
4194
+ break;
4195
+ }
4196
+ if (!disableFallback) {
4197
+ _context2.next = 14;
4198
+ break;
4199
+ }
4200
+ return _context2.abrupt("return", {
4201
+ dryRunError: dryRunResult.failureReason
4202
+ });
4203
+ case 14:
4204
+ _context2.next = 16;
4205
+ return calcPaymentInfoFee();
4206
+ case 16:
4207
+ _context2.t1 = _context2.sent;
4208
+ _context2.t2 = dryRunResult.failureReason;
4209
+ return _context2.abrupt("return", {
4210
+ fee: _context2.t1,
4211
+ feeType: 'paymentInfo',
4212
+ dryRunError: _context2.t2
4213
+ });
4214
+ case 19:
4215
+ fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
4216
+ return _context2.abrupt("return", {
4217
+ fee: fee,
4218
+ feeType: 'dryRun',
4219
+ forwardedXcms: newForwardedXcms,
4220
+ destParaId: destParaId
4221
+ });
4222
+ case 21:
4223
+ case "end":
4224
+ return _context2.stop();
4225
+ }
4226
+ }, _callee2);
4227
+ }));
4228
+ return function getDestXcmFee(_x) {
4229
+ return _ref.apply(this, arguments);
4230
+ };
4231
+ }();
4232
+
4233
+ var dryRunInternal = /*#__PURE__*/function () {
4234
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4235
+ var _intermediateFees$bri, _intermediateFees$ass, _processedBridgeHubDa, _destinationDryRun;
4236
+ 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;
4237
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4238
+ while (1) switch (_context.prev = _context.next) {
4239
+ case 0:
4240
+ origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
4241
+ resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
4242
+ asset = 'multiasset' in currency ? null : findAssetForNodeOrThrow(origin, currency, destination);
4243
+ _context.next = 5;
4244
+ return api.getDryRunCall({
4245
+ tx: tx,
4246
+ node: origin,
4247
+ address: senderAddress,
4248
+ isFeeAsset: !!resolvedFeeAsset
4249
+ });
4250
+ case 5:
4251
+ originDryRun = _context.sent;
4252
+ if (originDryRun.success) {
4253
+ _context.next = 8;
4254
+ break;
4255
+ }
4256
+ return _context.abrupt("return", {
4257
+ origin: originDryRun
4258
+ });
4259
+ case 8:
4260
+ initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
4261
+ assetHubNode = determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama';
4262
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
4263
+ currentOrigin = origin;
4264
+ forwardedXcms = initialForwardedXcms;
4265
+ nextParaId = initialDestParaId;
4266
+ intermediateFees = {};
4267
+ case 15:
4268
+ 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)) {
4269
+ _context.next = 42;
4270
+ break;
4271
+ }
4272
+ nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
4273
+ if (nextChain) {
4274
+ _context.next = 19;
4275
+ break;
4276
+ }
4277
+ throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
4278
+ case 19:
4279
+ hopApi = api.clone();
4280
+ _context.prev = 20;
4281
+ if (hasDryRunSupport(nextChain)) {
4282
+ _context.next = 24;
4283
+ break;
4284
+ }
4285
+ if (nextChain === destination) {
4286
+ destinationDryRun = {
4287
+ success: false,
4288
+ failureReason: "DryRunApi is not available on node ".concat(nextChain)
4289
+ };
4290
+ }
4291
+ return _context.abrupt("break", 42);
4292
+ case 24:
4293
+ _context.next = 26;
4294
+ return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
4295
+ case 26:
4296
+ _context.next = 28;
4297
+ return hopApi.getDryRunXcm({
4298
+ originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), Version.V4),
4299
+ xcm: forwardedXcms[1][0],
4300
+ node: nextChain,
4301
+ origin: currentOrigin,
4302
+ asset: asset,
4303
+ feeAsset: resolvedFeeAsset,
4304
+ originFee: originDryRun.fee,
4305
+ amount: BigInt(currency.amount)
4306
+ });
4307
+ case 28:
4308
+ hopDryRun = _context.sent;
4309
+ if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
4310
+ destinationDryRun = hopDryRun;
4311
+ } else if (nextChain === assetHubNode) {
4312
+ intermediateFees.assetHub = hopDryRun;
4313
+ } else if (nextChain === bridgeHubNode) {
4314
+ intermediateFees.bridgeHub = hopDryRun;
4315
+ }
4316
+ if (hopDryRun.success) {
4317
+ _context.next = 32;
4318
+ break;
4319
+ }
4320
+ return _context.abrupt("break", 42);
4321
+ case 32:
4322
+ newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
4323
+ forwardedXcms = newXcms;
4324
+ nextParaId = destParaId;
4325
+ currentOrigin = nextChain;
4326
+ case 36:
4327
+ _context.prev = 36;
4328
+ _context.next = 39;
4329
+ return hopApi.disconnect();
4330
+ case 39:
4331
+ return _context.finish(36);
4332
+ case 40:
4333
+ _context.next = 15;
4334
+ break;
4335
+ case 42:
4336
+ processedBridgeHubData = intermediateFees.bridgeHub;
4337
+ if (!((_intermediateFees$bri = intermediateFees.bridgeHub) !== null && _intermediateFees$bri !== void 0 && _intermediateFees$bri.success && destination === 'Ethereum')) {
4338
+ _context.next = 53;
4339
+ break;
4340
+ }
4341
+ ahApi = api.clone();
4342
+ _context.next = 47;
4343
+ return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
4344
+ case 47:
4345
+ _context.next = 49;
4346
+ return getParaEthTransferFees(ahApi);
4347
+ case 49:
4348
+ _yield$getParaEthTran = _context.sent;
4349
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
4350
+ bridgeFee = _yield$getParaEthTran2[0];
4351
+ processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
4352
+ fee: intermediateFees.bridgeHub.fee + bridgeFee
4353
+ });
4354
+ case 53:
4355
+ return _context.abrupt("return", {
4356
+ origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
4357
+ currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
4358
+ }) : originDryRun,
4359
+ assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
4360
+ currency: getNativeAssetSymbol(assetHubNode)
4361
+ }) : intermediateFees.assetHub,
4362
+ bridgeHub: (_processedBridgeHubDa = processedBridgeHubData) !== null && _processedBridgeHubDa !== void 0 && _processedBridgeHubDa.success ? _objectSpread2(_objectSpread2({}, processedBridgeHubData), {}, {
4363
+ currency: getNativeAssetSymbol(bridgeHubNode)
4364
+ }) : processedBridgeHubData,
4365
+ destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
4366
+ currency: asset === null || asset === void 0 ? void 0 : asset.symbol
4367
+ }) : destinationDryRun
4368
+ });
4369
+ case 54:
4370
+ case "end":
4371
+ return _context.stop();
4372
+ }
4373
+ }, _callee, null, [[20,, 36, 40]]);
4374
+ }));
4375
+ return function dryRunInternal(_x) {
4376
+ return _ref.apply(this, arguments);
4377
+ };
4378
+ }();
4379
+
4380
+ var dryRun = /*#__PURE__*/function () {
4381
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4382
+ var api, senderAddress, origin;
4383
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4384
+ while (1) switch (_context.prev = _context.next) {
4385
+ case 0:
4386
+ api = options.api, senderAddress = options.senderAddress, origin = options.origin;
4387
+ validateAddress(senderAddress, origin, false);
4388
+ _context.next = 4;
4389
+ return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
4390
+ case 4:
4391
+ _context.prev = 4;
4392
+ _context.next = 7;
4393
+ return dryRunInternal(options);
4394
+ case 7:
4395
+ return _context.abrupt("return", _context.sent);
4396
+ case 8:
4397
+ _context.prev = 8;
4398
+ _context.next = 11;
4399
+ return api.disconnect();
4400
+ case 11:
4401
+ return _context.finish(8);
4402
+ case 12:
4403
+ case "end":
4404
+ return _context.stop();
4405
+ }
4406
+ }, _callee, null, [[4,, 8, 12]]);
4407
+ }));
4408
+ return function dryRun(_x) {
4409
+ return _ref.apply(this, arguments);
4410
+ };
4411
+ }();
4412
+
4413
+ var dryRunOrigin = /*#__PURE__*/function () {
4414
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4415
+ var api, node, address, result;
4416
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4417
+ while (1) switch (_context.prev = _context.next) {
4418
+ case 0:
4419
+ api = options.api, node = options.node, address = options.address;
4420
+ validateAddress(address, node, false);
4421
+ _context.next = 4;
4422
+ return api.init(node, DRY_RUN_CLIENT_TIMEOUT_MS);
4423
+ case 4:
4424
+ _context.prev = 4;
4425
+ _context.next = 7;
4426
+ return api.getDryRunCall(options);
4427
+ case 7:
4428
+ result = _context.sent;
4429
+ if (!result.success) {
4430
+ _context.next = 12;
4431
+ break;
4432
+ }
4433
+ return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
4434
+ currency: getNativeAssetSymbol(node)
4435
+ }));
4436
+ case 12:
4437
+ return _context.abrupt("return", result);
4438
+ case 13:
4439
+ _context.prev = 13;
4440
+ _context.next = 16;
4441
+ return api.disconnect();
4442
+ case 16:
4443
+ return _context.finish(13);
4444
+ case 17:
4445
+ case "end":
4446
+ return _context.stop();
4447
+ }
4448
+ }, _callee, null, [[4,, 13, 17]]);
4409
4449
  }));
4410
- return function transferMoonbeamToEth(_x) {
4411
- return _ref2.apply(this, arguments);
4450
+ return function dryRunOrigin(_x) {
4451
+ return _ref.apply(this, arguments);
4412
4452
  };
4413
4453
  }();
4414
4454
 
@@ -4518,7 +4558,7 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
4518
4558
 
4519
4559
  var getXcmFee = /*#__PURE__*/function () {
4520
4560
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
4521
- 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;
4561
+ 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, _destApi, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee;
4522
4562
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4523
4563
  while (1) switch (_context.prev = _context.next) {
4524
4564
  case 0:
@@ -4548,21 +4588,26 @@ var getXcmFee = /*#__PURE__*/function () {
4548
4588
  return api.disconnect();
4549
4589
  case 14:
4550
4590
  if (!(originDryRunError || originFeeType === 'paymentInfo')) {
4551
- _context.next = 29;
4591
+ _context.next = 30;
4552
4592
  break;
4553
4593
  }
4554
4594
  destApi = api.clone();
4555
4595
  _context.prev = 16;
4556
- _context.next = 19;
4596
+ if (!(destination !== 'Ethereum')) {
4597
+ _context.next = 20;
4598
+ break;
4599
+ }
4600
+ _context.next = 20;
4557
4601
  return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4558
- case 19:
4602
+ case 20:
4559
4603
  destApi.setDisconnectAllowed(false);
4560
- _context.next = 22;
4604
+ _context.next = 23;
4561
4605
  return getDestXcmFee({
4562
4606
  api: destApi,
4563
4607
  forwardedXcms: undefined,
4564
4608
  // force paymentInfo
4565
4609
  origin: origin,
4610
+ prevNode: origin,
4566
4611
  destination: destination,
4567
4612
  currency: currency,
4568
4613
  address: address,
@@ -4571,7 +4616,7 @@ var getXcmFee = /*#__PURE__*/function () {
4571
4616
  senderAddress: senderAddress,
4572
4617
  disableFallback: disableFallback
4573
4618
  });
4574
- case 22:
4619
+ case 23:
4575
4620
  destFeeRes = _context.sent;
4576
4621
  return _context.abrupt("return", {
4577
4622
  origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
@@ -4583,50 +4628,55 @@ var getXcmFee = /*#__PURE__*/function () {
4583
4628
  }, originDryRunError && {
4584
4629
  dryRunError: originDryRunError
4585
4630
  }),
4586
- destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
4631
+ destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee ? {
4587
4632
  fee: destFeeRes.fee
4633
+ } : {
4634
+ fee: 0n
4588
4635
  }), destFeeRes.feeType && {
4589
4636
  feeType: destFeeRes.feeType
4590
4637
  }), {}, {
4591
4638
  currency: getNativeAssetSymbol(destination)
4592
4639
  })
4593
4640
  });
4594
- case 24:
4595
- _context.prev = 24;
4641
+ case 25:
4642
+ _context.prev = 25;
4596
4643
  destApi.setDisconnectAllowed(true);
4597
- _context.next = 28;
4644
+ _context.next = 29;
4598
4645
  return destApi.disconnect();
4599
- case 28:
4600
- return _context.finish(24);
4601
4646
  case 29:
4647
+ return _context.finish(25);
4648
+ case 30:
4649
+ assetHubNode = determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama';
4650
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
4602
4651
  currentOrigin = origin;
4603
4652
  forwardedXcms = initialForwardedXcm;
4604
4653
  nextParaId = initialDestParaId;
4605
4654
  intermediateFees = {};
4606
4655
  destinationFee = 0n;
4607
- destinationFeeType = 'paymentInfo';
4608
- case 35:
4656
+ destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
4657
+ case 38:
4609
4658
  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)) {
4610
- _context.next = 67;
4659
+ _context.next = 74;
4611
4660
  break;
4612
4661
  }
4613
4662
  nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
4614
4663
  if (!(nextChain === null)) {
4615
- _context.next = 39;
4664
+ _context.next = 42;
4616
4665
  break;
4617
4666
  }
4618
4667
  throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
4619
- case 39:
4668
+ case 42:
4620
4669
  hopApi = api.clone();
4621
- _context.prev = 40;
4622
- _context.next = 43;
4670
+ _context.prev = 43;
4671
+ _context.next = 46;
4623
4672
  return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
4624
- case 43:
4625
- _context.next = 45;
4673
+ case 46:
4674
+ _context.next = 48;
4626
4675
  return getDestXcmFee({
4627
4676
  api: hopApi,
4628
4677
  forwardedXcms: forwardedXcms,
4629
- origin: currentOrigin,
4678
+ origin: origin,
4679
+ prevNode: currentOrigin,
4630
4680
  destination: nextChain,
4631
4681
  currency: currency,
4632
4682
  address: address,
@@ -4636,10 +4686,10 @@ var getXcmFee = /*#__PURE__*/function () {
4636
4686
  originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
4637
4687
  disableFallback: disableFallback
4638
4688
  });
4639
- case 45:
4689
+ case 48:
4640
4690
  hopResult = _context.sent;
4641
4691
  if (!hopResult.dryRunError) {
4642
- _context.next = 57;
4692
+ _context.next = 64;
4643
4693
  break;
4644
4694
  }
4645
4695
  failingRecord = {
@@ -4653,21 +4703,30 @@ var getXcmFee = /*#__PURE__*/function () {
4653
4703
  destinationFee = hopResult.fee;
4654
4704
  destinationFeeType = hopResult.feeType; // paymentInfo
4655
4705
  destinationDryRunError = hopResult.dryRunError;
4656
- } else if (nextChain === 'AssetHubPolkadot') {
4706
+ } else if (nextChain === assetHubNode) {
4657
4707
  intermediateFees.assetHub = failingRecord;
4658
- } else if (nextChain === 'BridgeHubPolkadot') {
4708
+ } else if (nextChain === bridgeHubNode) {
4659
4709
  intermediateFees.bridgeHub = failingRecord;
4660
4710
  }
4661
4711
  // We failed before the true destination, use fallback via paymentInfo.
4662
4712
  if (hopIsDestination) {
4663
- _context.next = 56;
4713
+ _context.next = 63;
4664
4714
  break;
4665
4715
  }
4666
- _context.next = 53;
4716
+ _destApi = api.clone();
4717
+ if (!(destination !== 'Ethereum')) {
4718
+ _context.next = 58;
4719
+ break;
4720
+ }
4721
+ _context.next = 58;
4722
+ return _destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4723
+ case 58:
4724
+ _context.next = 60;
4667
4725
  return getDestXcmFee({
4668
- api: hopApi,
4726
+ api: _destApi,
4669
4727
  forwardedXcms: undefined,
4670
- origin: nextChain,
4728
+ origin: origin,
4729
+ prevNode: currentOrigin,
4671
4730
  destination: destination,
4672
4731
  currency: currency,
4673
4732
  address: address,
@@ -4676,23 +4735,23 @@ var getXcmFee = /*#__PURE__*/function () {
4676
4735
  senderAddress: senderAddress,
4677
4736
  disableFallback: disableFallback
4678
4737
  });
4679
- case 53:
4738
+ case 60:
4680
4739
  destFallback = _context.sent;
4681
4740
  destinationFee = destFallback.fee;
4682
4741
  destinationFeeType = destFallback.feeType;
4683
- case 56:
4684
- return _context.abrupt("break", 67);
4685
- case 57:
4742
+ case 63:
4743
+ return _context.abrupt("break", 74);
4744
+ case 64:
4686
4745
  if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
4687
4746
  destinationFee = hopResult.fee;
4688
4747
  destinationFeeType = hopResult.feeType;
4689
- } else if (nextChain === 'AssetHubPolkadot') {
4748
+ } else if (nextChain === assetHubNode) {
4690
4749
  intermediateFees.assetHub = {
4691
4750
  fee: hopResult.fee,
4692
4751
  feeType: hopResult.feeType,
4693
4752
  currency: getNativeAssetSymbol(nextChain)
4694
4753
  };
4695
- } else if (nextChain === 'BridgeHubPolkadot') {
4754
+ } else if (nextChain === bridgeHubNode) {
4696
4755
  intermediateFees.bridgeHub = {
4697
4756
  fee: hopResult.fee,
4698
4757
  feeType: hopResult.feeType,
@@ -4702,16 +4761,36 @@ var getXcmFee = /*#__PURE__*/function () {
4702
4761
  forwardedXcms = hopResult.forwardedXcms;
4703
4762
  nextParaId = hopResult.destParaId;
4704
4763
  currentOrigin = nextChain;
4705
- case 61:
4706
- _context.prev = 61;
4707
- _context.next = 64;
4764
+ case 68:
4765
+ _context.prev = 68;
4766
+ _context.next = 71;
4708
4767
  return hopApi.disconnect();
4709
- case 64:
4710
- return _context.finish(61);
4711
- case 65:
4712
- _context.next = 35;
4768
+ case 71:
4769
+ return _context.finish(68);
4770
+ case 72:
4771
+ _context.next = 38;
4713
4772
  break;
4714
- case 67:
4773
+ case 74:
4774
+ processedBridgeHubData = intermediateFees.bridgeHub;
4775
+ if (!(intermediateFees.bridgeHub && !intermediateFees.bridgeHub.dryRunError && destination === 'Ethereum')) {
4776
+ _context.next = 85;
4777
+ break;
4778
+ }
4779
+ ahApi = api.clone();
4780
+ _context.next = 79;
4781
+ return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
4782
+ case 79:
4783
+ _context.next = 81;
4784
+ return getParaEthTransferFees(ahApi);
4785
+ case 81:
4786
+ _yield$getParaEthTran = _context.sent;
4787
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
4788
+ bridgeFee = _yield$getParaEthTran2[0];
4789
+ processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
4790
+ fee: intermediateFees.bridgeHub.fee + bridgeFee
4791
+ });
4792
+ case 85:
4793
+ intermediateFees.bridgeHub = processedBridgeHubData;
4715
4794
  return _context.abrupt("return", _objectSpread2(_objectSpread2({
4716
4795
  origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
4717
4796
  fee: originFee
@@ -4723,7 +4802,7 @@ var getXcmFee = /*#__PURE__*/function () {
4723
4802
  dryRunError: originDryRunError
4724
4803
  })
4725
4804
  }, intermediateFees), {}, {
4726
- destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destinationFee && {
4805
+ destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destinationFee !== undefined && {
4727
4806
  fee: destinationFee
4728
4807
  }), destinationFeeType && {
4729
4808
  feeType: destinationFeeType
@@ -4733,11 +4812,11 @@ var getXcmFee = /*#__PURE__*/function () {
4733
4812
  dryRunError: destinationDryRunError
4734
4813
  })
4735
4814
  }));
4736
- case 68:
4815
+ case 87:
4737
4816
  case "end":
4738
4817
  return _context.stop();
4739
4818
  }
4740
- }, _callee, null, [[16,, 24, 29], [40,, 61, 65]]);
4819
+ }, _callee, null, [[16,, 25, 30], [43,, 68, 72]]);
4741
4820
  }));
4742
4821
  return function getXcmFee(_x) {
4743
4822
  return _ref2.apply(this, arguments);
@@ -4748,11 +4827,11 @@ var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
4748
4827
  var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
4749
4828
  var getXcmFeeEstimate = /*#__PURE__*/function () {
4750
4829
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4751
- var api, origin, destination, address, senderAddress, currency, originFeeDetails, destApi, originAsset, currencyInput, flippedTx, rawDestFee, destinationFee, destFeeDetails;
4830
+ var api, origin, destination, currency, originFeeDetails, destApi, originAsset, currencyInput, destinationFee, destFeeDetails;
4752
4831
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4753
4832
  while (1) switch (_context.prev = _context.next) {
4754
4833
  case 0:
4755
- api = options.api, origin = options.origin, destination = options.destination, address = options.address, senderAddress = options.senderAddress, currency = options.currency;
4834
+ api = options.api, origin = options.origin, destination = options.destination, currency = options.currency;
4756
4835
  if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
4757
4836
  _context.next = 3;
4758
4837
  break;
@@ -4788,32 +4867,36 @@ var getXcmFeeEstimate = /*#__PURE__*/function () {
4788
4867
  case 7:
4789
4868
  originFeeDetails = _context.sent;
4790
4869
  destApi = api.clone();
4791
- _context.next = 11;
4792
- return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4793
- case 11:
4794
- if (!('multiasset' in currency)) {
4795
- _context.next = 13;
4870
+ if (!(destination !== 'Ethereum')) {
4871
+ _context.next = 12;
4796
4872
  break;
4797
4873
  }
4798
- throw new InvalidCurrencyError('Multi-assets are not yet supported for simple XCM fee estimation.');
4799
- case 13:
4874
+ _context.next = 12;
4875
+ return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
4876
+ case 12:
4800
4877
  originAsset = findAssetForNodeOrThrow(origin, currency, destination);
4801
4878
  currencyInput = originAsset.multiLocation ? {
4802
4879
  multilocation: originAsset.multiLocation
4803
4880
  } : {
4804
4881
  symbol: originAsset.symbol
4805
4882
  };
4806
- _context.next = 17;
4807
- return Builder(destApi).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
4808
- amount: currency.amount
4809
- })).build();
4810
- case 17:
4811
- flippedTx = _context.sent;
4883
+ if (!(destination === 'Ethereum')) {
4884
+ _context.next = 18;
4885
+ break;
4886
+ }
4887
+ _context.t0 = 0n;
4888
+ _context.next = 21;
4889
+ break;
4890
+ case 18:
4812
4891
  _context.next = 20;
4813
- return destApi.calculateTransactionFee(flippedTx, address);
4892
+ return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
4893
+ api: destApi,
4894
+ destination: destination
4895
+ }), currencyInput);
4814
4896
  case 20:
4815
- rawDestFee = _context.sent;
4816
- destinationFee = padFee(rawDestFee, origin, destination, 'destination');
4897
+ _context.t0 = _context.sent;
4898
+ case 21:
4899
+ destinationFee = _context.t0;
4817
4900
  destFeeDetails = {
4818
4901
  fee: destinationFee,
4819
4902
  currency: getNativeAssetSymbol(destination)
@@ -4879,10 +4962,6 @@ var determineAssetCheckEnabled = function determineAssetCheckEnabled(origin, cur
4879
4962
  return 'multiasset' in currency || 'multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation) ? false : originNode.assetCheckEnabled;
4880
4963
  };
4881
4964
 
4882
- var isBridgeTransfer = function isBridgeTransfer(origin, destination) {
4883
- return origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama' || origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot';
4884
- };
4885
-
4886
4965
  var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
4887
4966
  return assetCheckEnabled ? findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null) : null;
4888
4967
  };
@@ -5001,7 +5080,7 @@ var validateDestination = function validateDestination(origin, destination) {
5001
5080
  throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
5002
5081
  }
5003
5082
  var isMultiLocationDestination = _typeof(destination) === 'object';
5004
- var isBridge = isBridgeTransfer(origin, destination);
5083
+ var isBridge = !isTMultiLocation(destination) && isDotKsmBridge(origin, destination);
5005
5084
  var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
5006
5085
  if (!isRelayDestination && !isMultiLocationDestination) {
5007
5086
  var originRelayChainSymbol = getRelayChainSymbol(origin);
@@ -5022,7 +5101,7 @@ var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled
5022
5101
 
5023
5102
  var send = /*#__PURE__*/function () {
5024
5103
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
5025
- var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
5104
+ var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode, finalAsset;
5026
5105
  return _regeneratorRuntime().wrap(function _callee$(_context) {
5027
5106
  while (1) switch (_context.prev = _context.next) {
5028
5107
  case 0:
@@ -5031,7 +5110,7 @@ var send = /*#__PURE__*/function () {
5031
5110
  validateDestination(origin, destination);
5032
5111
  validateDestinationAddress(address, destination);
5033
5112
  if (senderAddress) validateAddress(senderAddress, origin, false);
5034
- isBridge = isBridgeTransfer(origin, destination);
5113
+ isBridge = !isTMultiLocation(destination) && isDotKsmBridge(origin, destination);
5035
5114
  assetCheckEnabled = determineAssetCheckEnabled(origin, currency);
5036
5115
  validateAssetSpecifiers(assetCheckEnabled, currency);
5037
5116
  asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
@@ -5101,11 +5180,15 @@ var send = /*#__PURE__*/function () {
5101
5180
  symbol: 'symbol' in currency ? currency.symbol : undefined
5102
5181
  };
5103
5182
  originNode = getNode(origin);
5183
+ finalAsset = 'multiasset' in currency ? _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5184
+ amount: 0,
5185
+ assetId: '1'
5186
+ }) : _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5187
+ amount: currency.amount
5188
+ });
5104
5189
  return _context.abrupt("return", originNode.transfer({
5105
5190
  api: api,
5106
- asset: _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
5107
- amount: 'multiasset' in currency ? 0 : currency.amount
5108
- }),
5191
+ asset: finalAsset,
5109
5192
  feeAsset: resolvedFeeAsset,
5110
5193
  address: address,
5111
5194
  to: destination,
@@ -5117,7 +5200,7 @@ var send = /*#__PURE__*/function () {
5117
5200
  pallet: pallet,
5118
5201
  method: method
5119
5202
  }));
5120
- case 30:
5203
+ case 31:
5121
5204
  case "end":
5122
5205
  return _context.stop();
5123
5206
  }
@@ -6006,7 +6089,7 @@ var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
6006
6089
  },
6007
6090
  weight_limit: {
6008
6091
  Limited: {
6009
- ref_time: 100n,
6092
+ ref_time: 150n,
6010
6093
  proof_size: 0n
6011
6094
  }
6012
6095
  }
@@ -6027,7 +6110,7 @@ var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
6027
6110
  fees: {
6028
6111
  id: asset.multiLocation,
6029
6112
  fun: {
6030
- Fungible: amountWithoutFee
6113
+ Fungible: amountWithoutFee - executionFee
6031
6114
  }
6032
6115
  },
6033
6116
  weight_limit: 'Unlimited'
@@ -6377,11 +6460,11 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6377
6460
  key: "handleExecuteTransfer",
6378
6461
  value: function () {
6379
6462
  var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(input) {
6380
- var api, senderAddress, asset, decimals, multiplier, base, scaledMultiplier, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
6463
+ var api, senderAddress, asset, feeAsset, decimals, multiplier, base, scaledMultiplier, MIN_FEE, maxU64, dummyTx, dryRunResult;
6381
6464
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
6382
6465
  while (1) switch (_context3.prev = _context3.next) {
6383
6466
  case 0:
6384
- api = input.api, senderAddress = input.senderAddress, asset = input.asset;
6467
+ api = input.api, senderAddress = input.senderAddress, asset = input.asset, feeAsset = input.feeAsset;
6385
6468
  if (senderAddress) {
6386
6469
  _context3.next = 3;
6387
6470
  break;
@@ -6404,7 +6487,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6404
6487
  node: this.node,
6405
6488
  tx: dummyTx,
6406
6489
  address: senderAddress,
6407
- isFeeAsset: false
6490
+ isFeeAsset: !!feeAsset
6408
6491
  });
6409
6492
  case 13:
6410
6493
  dryRunResult = _context3.sent;
@@ -6412,35 +6495,16 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
6412
6495
  _context3.next = 16;
6413
6496
  break;
6414
6497
  }
6415
- throw new DryRunFailedError("Dry run failed: ".concat(dryRunResult.failureReason));
6498
+ throw new DryRunFailedError(dryRunResult.failureReason);
6416
6499
  case 16:
6417
6500
  if (dryRunResult.weight) {
6418
6501
  _context3.next = 18;
6419
6502
  break;
6420
6503
  }
6421
- throw new DryRunFailedError('Dry run failed: weight not found');
6504
+ throw new DryRunFailedError('weight not found');
6422
6505
  case 18:
6423
- feeDotShifted = dryRunResult.fee / 10n;
6424
- toMl = transformMultiLocation(asset.multiLocation);
6425
- _context3.next = 22;
6426
- return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
6427
- case 22:
6428
- feeConverted = _context3.sent;
6429
- if (feeConverted) {
6430
- _context3.next = 25;
6431
- break;
6432
- }
6433
- throw new InvalidParameterError("Pool DOT -> ".concat(asset.symbol, " not found."));
6434
- case 25:
6435
- if (!(BigInt(asset.amount) - feeConverted < 0)) {
6436
- _context3.next = 27;
6437
- break;
6438
- }
6439
- throw new InvalidParameterError("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
6440
- case 27:
6441
- feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
6442
- return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
6443
- case 29:
6506
+ return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, dryRunResult.fee));
6507
+ case 19:
6444
6508
  case "end":
6445
6509
  return _context3.stop();
6446
6510
  }
@@ -8823,145 +8887,400 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
8823
8887
  currency: currency,
8824
8888
  disableFallback: false
8825
8889
  });
8826
- case 17:
8827
- _yield$getOriginXcmFe = _context.sent;
8828
- fee = _yield$getOriginXcmFe.fee;
8829
- if (!(fee === undefined)) {
8830
- _context.next = 21;
8831
- break;
8832
- }
8833
- throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
8834
- case 21:
8835
- feeToSubtract = fee;
8836
- case 22:
8837
- transferable = balance - edBN - feeToSubtract;
8838
- return _context.abrupt("return", transferable > 0n ? transferable : 0n);
8839
- case 24:
8890
+ case 17:
8891
+ _yield$getOriginXcmFe = _context.sent;
8892
+ fee = _yield$getOriginXcmFe.fee;
8893
+ if (!(fee === undefined)) {
8894
+ _context.next = 21;
8895
+ break;
8896
+ }
8897
+ throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
8898
+ case 21:
8899
+ feeToSubtract = fee;
8900
+ case 22:
8901
+ transferable = balance - edBN - feeToSubtract;
8902
+ return _context.abrupt("return", transferable > 0n ? transferable : 0n);
8903
+ case 24:
8904
+ case "end":
8905
+ return _context.stop();
8906
+ }
8907
+ }, _callee);
8908
+ }));
8909
+ return function getTransferableAmountInternal(_x) {
8910
+ return _ref2.apply(this, arguments);
8911
+ };
8912
+ }();
8913
+ var getTransferableAmount = /*#__PURE__*/function () {
8914
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
8915
+ var api;
8916
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8917
+ while (1) switch (_context2.prev = _context2.next) {
8918
+ case 0:
8919
+ api = options.api;
8920
+ api.setDisconnectAllowed(false);
8921
+ _context2.prev = 2;
8922
+ _context2.next = 5;
8923
+ return getTransferableAmountInternal(options);
8924
+ case 5:
8925
+ return _context2.abrupt("return", _context2.sent);
8926
+ case 6:
8927
+ _context2.prev = 6;
8928
+ api.setDisconnectAllowed(true);
8929
+ _context2.next = 10;
8930
+ return api.disconnect();
8931
+ case 10:
8932
+ return _context2.finish(6);
8933
+ case 11:
8934
+ case "end":
8935
+ return _context2.stop();
8936
+ }
8937
+ }, _callee2, null, [[2,, 6, 11]]);
8938
+ }));
8939
+ return function getTransferableAmount(_x2) {
8940
+ return _ref3.apply(this, arguments);
8941
+ };
8942
+ }();
8943
+
8944
+ var ETH_RPC = 'https://ethereum.publicnode.com/';
8945
+ var ETH_ID = 1;
8946
+ var ERC20_ABI = ['function balanceOf(address) view returns (uint256)'];
8947
+ function getEthErc20Balance(_x, _x2) {
8948
+ return _getEthErc20Balance.apply(this, arguments);
8949
+ }
8950
+ function _getEthErc20Balance() {
8951
+ _getEthErc20Balance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(currency, address) {
8952
+ var _rpc$id, rpc, id, asset, provider, tokenAddress, token;
8953
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8954
+ while (1) switch (_context.prev = _context.next) {
8955
+ case 0:
8956
+ _rpc$id = {
8957
+ rpc: ETH_RPC,
8958
+ id: ETH_ID
8959
+ }, rpc = _rpc$id.rpc, id = _rpc$id.id;
8960
+ asset = findAssetForNodeOrThrow('Ethereum', currency, null);
8961
+ if (!(!isForeignAsset(asset) || !asset.assetId)) {
8962
+ _context.next = 4;
8963
+ break;
8964
+ }
8965
+ throw new InvalidParameterError("Asset ".concat(JSON.stringify(asset), " is not a foreign asset."));
8966
+ case 4:
8967
+ provider = new ethers.JsonRpcProvider(rpc, id);
8968
+ if (!(asset.symbol === 'ETH')) {
8969
+ _context.next = 9;
8970
+ break;
8971
+ }
8972
+ _context.next = 8;
8973
+ return provider.getBalance(address);
8974
+ case 8:
8975
+ return _context.abrupt("return", _context.sent);
8976
+ case 9:
8977
+ tokenAddress = asset.assetId;
8978
+ token = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
8979
+ _context.next = 13;
8980
+ return token.balanceOf(address);
8981
+ case 13:
8982
+ return _context.abrupt("return", _context.sent);
8983
+ case 14:
8984
+ case "end":
8985
+ return _context.stop();
8986
+ }
8987
+ }, _callee);
8988
+ }));
8989
+ return _getEthErc20Balance.apply(this, arguments);
8990
+ }
8991
+
8992
+ var buildDestInfo = /*#__PURE__*/function () {
8993
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
8994
+ var api, origin, destination, address, currency, originFee, destAsset, isFeeAssetAh, destFeeDetail, assetHubFee, bridgeFee, destApi, destCurrency, edDest, edDestBn, destBalance, destAmount, effectiveAmountForBalance, destBalanceSufficient, destBalanceSufficientResult, destBalanceAfter, destbalanceAfterResult, receivedAmount, isAssetHubToAssetHubRoute, nativeAssetOfOriginSymbol, isOriginAssetNative, destXcmFeeBalance, isDestFeeInNativeCurrency, destRecipientNativeBalance, destXcmFeeBalanceAfter;
8995
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8996
+ while (1) switch (_context.prev = _context.next) {
8997
+ case 0:
8998
+ 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;
8999
+ destApi = api.clone();
9000
+ if (!(destination !== 'Ethereum')) {
9001
+ _context.next = 5;
9002
+ break;
9003
+ }
9004
+ _context.next = 5;
9005
+ return destApi.init(destination);
9006
+ case 5:
9007
+ destCurrency = destAsset.multiLocation ? {
9008
+ multilocation: destAsset.multiLocation
9009
+ } : {
9010
+ symbol: destAsset.symbol
9011
+ };
9012
+ edDest = getExistentialDeposit(destination, destCurrency);
9013
+ if (edDest) {
9014
+ _context.next = 9;
9015
+ break;
9016
+ }
9017
+ throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
9018
+ case 9:
9019
+ edDestBn = BigInt(edDest);
9020
+ if (!(destination === 'Ethereum')) {
9021
+ _context.next = 16;
9022
+ break;
9023
+ }
9024
+ _context.next = 13;
9025
+ return getEthErc20Balance(destCurrency, address);
9026
+ case 13:
9027
+ _context.t0 = _context.sent;
9028
+ _context.next = 19;
9029
+ break;
9030
+ case 16:
9031
+ _context.next = 18;
9032
+ return getAssetBalanceInternal({
9033
+ api: destApi,
9034
+ address: address,
9035
+ node: destination,
9036
+ currency: destCurrency
9037
+ });
9038
+ case 18:
9039
+ _context.t0 = _context.sent;
9040
+ case 19:
9041
+ destBalance = _context.t0;
9042
+ destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
9043
+ effectiveAmountForBalance = destAmount;
9044
+ if (destination === 'Ethereum' && assetHubFee !== undefined) {
9045
+ effectiveAmountForBalance -= assetHubFee;
9046
+ }
9047
+ destBalanceSufficient = effectiveAmountForBalance - destFeeDetail.fee > (destBalance < edDestBn ? edDestBn : 0);
9048
+ 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;
9049
+ destBalanceAfter = destBalance - (destFeeDetail.currency === destAsset.symbol ? destFeeDetail.fee : 0n) + effectiveAmountForBalance;
9050
+ 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;
9051
+ isAssetHubToAssetHubRoute = origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot' || origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama';
9052
+ if (isAssetHubToAssetHubRoute) {
9053
+ nativeAssetOfOriginSymbol = getNativeAssetSymbol(origin);
9054
+ isOriginAssetNative = false;
9055
+ if (destAsset.symbol === nativeAssetOfOriginSymbol) {
9056
+ isOriginAssetNative = true;
9057
+ }
9058
+ if (isOriginAssetNative) {
9059
+ if (bridgeFee === undefined) {
9060
+ receivedAmount = new UnableToComputeError("bridgeFee is required for native asset transfer from ".concat(origin, " to ").concat(destination, " but was not provided."));
9061
+ } else {
9062
+ receivedAmount = BigInt(currency.amount) - originFee - bridgeFee;
9063
+ }
9064
+ } else {
9065
+ 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."));
9066
+ }
9067
+ } else {
9068
+ if (destbalanceAfterResult instanceof UnableToComputeError) {
9069
+ receivedAmount = destbalanceAfterResult;
9070
+ } else {
9071
+ receivedAmount = destbalanceAfterResult - destBalance;
9072
+ }
9073
+ }
9074
+ isDestFeeInNativeCurrency = destFeeDetail.currency === getNativeAssetSymbol(destination);
9075
+ if (!isDestFeeInNativeCurrency) {
9076
+ _context.next = 44;
9077
+ break;
9078
+ }
9079
+ if (!(destination === 'Ethereum')) {
9080
+ _context.next = 37;
9081
+ break;
9082
+ }
9083
+ _context.next = 34;
9084
+ return getEthErc20Balance({
9085
+ symbol: getNativeAssetSymbol(destination)
9086
+ }, address);
9087
+ case 34:
9088
+ _context.t1 = _context.sent;
9089
+ _context.next = 40;
9090
+ break;
9091
+ case 37:
9092
+ _context.next = 39;
9093
+ return getBalanceNativeInternal({
9094
+ address: address,
9095
+ node: destination,
9096
+ api: destApi
9097
+ });
9098
+ case 39:
9099
+ _context.t1 = _context.sent;
9100
+ case 40:
9101
+ destRecipientNativeBalance = _context.t1;
9102
+ destXcmFeeBalance = destRecipientNativeBalance;
9103
+ _context.next = 45;
9104
+ break;
9105
+ case 44:
9106
+ destXcmFeeBalance = destBalance;
9107
+ case 45:
9108
+ destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFeeDetail.fee + (destFeeDetail.currency === destAsset.symbol ? effectiveAmountForBalance : 0n);
9109
+ return _context.abrupt("return", {
9110
+ receivedCurrency: {
9111
+ sufficient: destBalanceSufficientResult,
9112
+ receivedAmount: receivedAmount,
9113
+ balance: destBalance,
9114
+ balanceAfter: destbalanceAfterResult,
9115
+ currencySymbol: destAsset.symbol,
9116
+ existentialDeposit: edDestBn
9117
+ },
9118
+ xcmFee: {
9119
+ fee: destFeeDetail.fee,
9120
+ balance: destXcmFeeBalance,
9121
+ balanceAfter: destXcmFeeBalanceAfter,
9122
+ currencySymbol: destFeeDetail.currency
9123
+ }
9124
+ });
9125
+ case 47:
8840
9126
  case "end":
8841
9127
  return _context.stop();
8842
9128
  }
8843
9129
  }, _callee);
8844
9130
  }));
8845
- return function getTransferableAmountInternal(_x) {
9131
+ return function buildDestInfo(_x) {
8846
9132
  return _ref2.apply(this, arguments);
8847
9133
  };
8848
9134
  }();
8849
- var getTransferableAmount = /*#__PURE__*/function () {
8850
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
8851
- var api;
8852
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8853
- while (1) switch (_context2.prev = _context2.next) {
9135
+
9136
+ var buildHopInfo = /*#__PURE__*/function () {
9137
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
9138
+ var api, node, feeData, originNode, currency, senderAddress, ahAddress, hopApi, resolvedAddress, nativeBalanceOnHop, nativeAssetSymbolOnHop, xcmFeeDetails, isBridgeHubNode, hopAsset, hopCurrencyPayload, balance, ed;
9139
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
9140
+ while (1) switch (_context.prev = _context.next) {
8854
9141
  case 0:
8855
- api = options.api;
8856
- api.setDisconnectAllowed(false);
8857
- _context2.prev = 2;
8858
- _context2.next = 5;
8859
- return getTransferableAmountInternal(options);
8860
- case 5:
8861
- return _context2.abrupt("return", _context2.sent);
8862
- case 6:
8863
- _context2.prev = 6;
8864
- api.setDisconnectAllowed(true);
8865
- _context2.next = 10;
8866
- return api.disconnect();
8867
- case 10:
8868
- return _context2.finish(6);
8869
- case 11:
9142
+ api = _ref.api, node = _ref.node, feeData = _ref.feeData, originNode = _ref.originNode, currency = _ref.currency, senderAddress = _ref.senderAddress, ahAddress = _ref.ahAddress;
9143
+ hopApi = api.clone();
9144
+ _context.next = 4;
9145
+ return hopApi.init(node);
9146
+ case 4:
9147
+ hopApi.setDisconnectAllowed(false);
9148
+ _context.prev = 5;
9149
+ resolvedAddress = isNodeEvm(originNode) && ahAddress ? ahAddress : senderAddress;
9150
+ _context.next = 9;
9151
+ return getBalanceNativeInternal({
9152
+ api: hopApi,
9153
+ address: resolvedAddress,
9154
+ node: node
9155
+ });
9156
+ case 9:
9157
+ nativeBalanceOnHop = _context.sent;
9158
+ nativeAssetSymbolOnHop = getNativeAssetSymbol(node);
9159
+ xcmFeeDetails = {
9160
+ fee: feeData.fee,
9161
+ balance: nativeBalanceOnHop,
9162
+ currencySymbol: nativeAssetSymbolOnHop
9163
+ };
9164
+ isBridgeHubNode = node.includes('BridgeHub');
9165
+ if (!isBridgeHubNode) {
9166
+ _context.next = 17;
9167
+ break;
9168
+ }
9169
+ return _context.abrupt("return", {
9170
+ currencySymbol: getNativeAssetSymbol(node),
9171
+ xcmFee: xcmFeeDetails
9172
+ });
9173
+ case 17:
9174
+ hopAsset = findAssetOnDestOrThrow(originNode, node, currency);
9175
+ hopCurrencyPayload = hopAsset.multiLocation ? {
9176
+ multilocation: hopAsset.multiLocation
9177
+ } : {
9178
+ symbol: hopAsset.symbol
9179
+ };
9180
+ _context.next = 21;
9181
+ return getAssetBalanceInternal({
9182
+ api: hopApi,
9183
+ address: resolvedAddress,
9184
+ node: node,
9185
+ currency: hopCurrencyPayload
9186
+ });
9187
+ case 21:
9188
+ balance = _context.sent;
9189
+ ed = getExistentialDeposit(node, hopCurrencyPayload);
9190
+ if (ed) {
9191
+ _context.next = 25;
9192
+ break;
9193
+ }
9194
+ throw new InvalidParameterError("Existential deposit not found for node ".concat(node, " with currency ").concat(JSON.stringify(hopCurrencyPayload)));
9195
+ case 25:
9196
+ return _context.abrupt("return", {
9197
+ balance: balance,
9198
+ currencySymbol: hopAsset.symbol,
9199
+ existentialDeposit: BigInt(ed),
9200
+ xcmFee: xcmFeeDetails
9201
+ });
9202
+ case 26:
9203
+ _context.prev = 26;
9204
+ hopApi.setDisconnectAllowed(true);
9205
+ _context.next = 30;
9206
+ return hopApi.disconnect();
9207
+ case 30:
9208
+ return _context.finish(26);
9209
+ case 31:
8870
9210
  case "end":
8871
- return _context2.stop();
9211
+ return _context.stop();
8872
9212
  }
8873
- }, _callee2, null, [[2,, 6, 11]]);
9213
+ }, _callee, null, [[5,, 26, 31]]);
8874
9214
  }));
8875
- return function getTransferableAmount(_x2) {
8876
- return _ref3.apply(this, arguments);
9215
+ return function buildHopInfo(_x) {
9216
+ return _ref2.apply(this, arguments);
8877
9217
  };
8878
9218
  }();
8879
9219
 
8880
9220
  var getTransferInfo = /*#__PURE__*/function () {
8881
9221
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
8882
- 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;
9222
+ 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;
8883
9223
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8884
9224
  while (1) switch (_context.prev = _context.next) {
8885
9225
  case 0:
8886
- api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
9226
+ 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;
9227
+ if (!(isNodeEvm(origin) && !ahAddress)) {
9228
+ _context.next = 3;
9229
+ break;
9230
+ }
9231
+ throw new InvalidParameterError("ahAddress is required for EVM origin ".concat(origin, "."));
9232
+ case 3:
8887
9233
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
8888
- _context.next = 4;
9234
+ _context.next = 6;
8889
9235
  return api.init(origin);
8890
- case 4:
9236
+ case 6:
8891
9237
  api.setDisconnectAllowed(false);
8892
- destApi = api.clone();
8893
- _context.next = 8;
8894
- return destApi.init(destination);
8895
- case 8:
8896
- destApi.setDisconnectAllowed(false);
8897
- _context.prev = 9;
9238
+ _context.prev = 7;
8898
9239
  destAsset = findAssetOnDestOrThrow(origin, destination, currency);
8899
- destCurrency = destAsset.multiLocation ? {
8900
- multilocation: destAsset.multiLocation
8901
- } : {
8902
- symbol: destAsset.symbol
8903
- };
8904
9240
  if (!(feeAsset && resolvedFeeAsset)) {
8905
- _context.next = 18;
9241
+ _context.next = 15;
8906
9242
  break;
8907
9243
  }
8908
- _context.next = 15;
9244
+ _context.next = 12;
8909
9245
  return getAssetBalanceInternal({
8910
9246
  api: api,
8911
9247
  address: senderAddress,
8912
9248
  node: origin,
8913
9249
  currency: feeAsset
8914
9250
  });
8915
- case 15:
9251
+ case 12:
8916
9252
  _context.t0 = _context.sent;
8917
- _context.next = 21;
9253
+ _context.next = 18;
8918
9254
  break;
8919
- case 18:
8920
- _context.next = 20;
9255
+ case 15:
9256
+ _context.next = 17;
8921
9257
  return getBalanceNativeInternal({
8922
9258
  api: api,
8923
9259
  address: senderAddress,
8924
9260
  node: origin
8925
9261
  });
8926
- case 20:
9262
+ case 17:
8927
9263
  _context.t0 = _context.sent;
8928
- case 21:
9264
+ case 18:
8929
9265
  originBalanceFee = _context.t0;
8930
- _context.next = 24;
9266
+ _context.next = 21;
8931
9267
  return getAssetBalanceInternal({
8932
9268
  api: api,
8933
9269
  address: senderAddress,
8934
9270
  node: origin,
8935
9271
  currency: currency
8936
9272
  });
8937
- case 24:
9273
+ case 21:
8938
9274
  originBalance = _context.sent;
8939
- _context.next = 27;
8940
- return getAssetBalanceInternal({
8941
- api: destApi,
8942
- address: address,
8943
- node: destination,
8944
- currency: destCurrency
8945
- });
8946
- case 27:
8947
- destBalance = _context.sent;
8948
9275
  edOrigin = getExistentialDeposit(origin, currency);
8949
9276
  if (edOrigin) {
8950
- _context.next = 31;
9277
+ _context.next = 25;
8951
9278
  break;
8952
9279
  }
8953
9280
  throw new InvalidParameterError("Existential deposit not found for ".concat(origin, " with currency ").concat(JSON.stringify(currency)));
8954
- case 31:
9281
+ case 25:
8955
9282
  edOriginBn = BigInt(edOrigin);
8956
- edDest = getExistentialDeposit(destination, destCurrency);
8957
- if (edDest) {
8958
- _context.next = 35;
8959
- break;
8960
- }
8961
- throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
8962
- case 35:
8963
- edDestBn = BigInt(edDest);
8964
- _context.next = 38;
9283
+ _context.next = 28;
8965
9284
  return getXcmFee({
8966
9285
  api: api,
8967
9286
  tx: tx,
@@ -8973,51 +9292,76 @@ var getTransferInfo = /*#__PURE__*/function () {
8973
9292
  feeAsset: feeAsset,
8974
9293
  disableFallback: false
8975
9294
  });
8976
- case 38:
9295
+ case 28:
8977
9296
  _yield$getXcmFee = _context.sent;
8978
9297
  _yield$getXcmFee$orig = _yield$getXcmFee.origin;
8979
9298
  originFee = _yield$getXcmFee$orig.fee;
8980
9299
  originFeeCurrency = _yield$getXcmFee$orig.currency;
8981
- _yield$getXcmFee$dest = _yield$getXcmFee.destination;
8982
- destFee = _yield$getXcmFee$dest.fee;
8983
- destFeeCurrency = _yield$getXcmFee$dest.currency;
9300
+ assetHubFeeResult = _yield$getXcmFee.assetHub;
9301
+ bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
9302
+ destFeeDetail = _yield$getXcmFee.destination;
8984
9303
  if (!(originFee === undefined)) {
8985
- _context.next = 47;
9304
+ _context.next = 37;
8986
9305
  break;
8987
9306
  }
8988
9307
  throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(origin, "."));
8989
- case 47:
8990
- isDestFeeInNativeCurrency = destFeeCurrency === getNativeAssetSymbol(destination);
8991
- if (!isDestFeeInNativeCurrency) {
8992
- _context.next = 55;
8993
- break;
8994
- }
8995
- _context.next = 51;
8996
- return getBalanceNativeInternal({
8997
- address: address,
8998
- node: destination,
8999
- api: destApi
9000
- });
9001
- case 51:
9002
- destRecipientNativeBalance = _context.sent;
9003
- destXcmFeeBalance = destRecipientNativeBalance;
9004
- _context.next = 56;
9005
- break;
9006
- case 55:
9007
- destXcmFeeBalance = destBalance;
9008
- case 56:
9308
+ case 37:
9009
9309
  isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, destAsset);
9010
9310
  originBalanceAfter = originBalance - BigInt(currency.amount);
9011
9311
  originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - BigInt(currency.amount) : originBalanceFee - originFee;
9012
9312
  originBalanceNativeSufficient = originBalanceFee >= originFee;
9013
9313
  originBalanceSufficient = originBalanceAfter >= edOriginBn;
9014
- destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
9015
- destBalanceSufficient = destAmount - destFee > (destBalance < edDestBn ? edDestBn : 0);
9016
- destBalanceSufficientResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
9017
- destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) + destAmount;
9018
- destbalanceAfterResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
9019
- receivedAmount = destbalanceAfterResult instanceof UnableToComputeError ? destbalanceAfterResult : destbalanceAfterResult - destBalance;
9020
- destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFee + (destFeeCurrency === destAsset.symbol ? BigInt(currency.amount) : 0n);
9314
+ if (!assetHubFeeResult) {
9315
+ _context.next = 46;
9316
+ break;
9317
+ }
9318
+ _context.next = 45;
9319
+ return buildHopInfo({
9320
+ api: api,
9321
+ node: determineRelayChain(origin) === 'Polkadot' ? 'AssetHubPolkadot' : 'AssetHubKusama',
9322
+ feeData: assetHubFeeResult,
9323
+ originNode: origin,
9324
+ currency: currency,
9325
+ senderAddress: senderAddress,
9326
+ ahAddress: ahAddress
9327
+ });
9328
+ case 45:
9329
+ assetHub = _context.sent;
9330
+ case 46:
9331
+ if (!bridgeHubFeeResult) {
9332
+ _context.next = 51;
9333
+ break;
9334
+ }
9335
+ bridgeHubNode = determineRelayChain(origin) === 'Polkadot' ? 'BridgeHubPolkadot' : 'BridgeHubKusama';
9336
+ _context.next = 50;
9337
+ return buildHopInfo({
9338
+ api: api,
9339
+ node: bridgeHubNode,
9340
+ feeData: bridgeHubFeeResult,
9341
+ originNode: origin,
9342
+ currency: currency,
9343
+ senderAddress: senderAddress,
9344
+ ahAddress: ahAddress
9345
+ });
9346
+ case 50:
9347
+ bridgeHub = _context.sent;
9348
+ case 51:
9349
+ _context.next = 53;
9350
+ return buildDestInfo({
9351
+ api: api,
9352
+ origin: origin,
9353
+ destination: destination,
9354
+ address: address,
9355
+ currency: currency,
9356
+ destAsset: destAsset,
9357
+ originFee: originFee,
9358
+ isFeeAssetAh: !!isFeeAssetAh,
9359
+ destFeeDetail: destFeeDetail,
9360
+ assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
9361
+ bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
9362
+ });
9363
+ case 53:
9364
+ destinationInfo = _context.sent;
9021
9365
  return _context.abrupt("return", {
9022
9366
  chain: {
9023
9367
  origin: origin,
@@ -9040,57 +9384,69 @@ var getTransferInfo = /*#__PURE__*/function () {
9040
9384
  currencySymbol: originFeeCurrency
9041
9385
  }
9042
9386
  },
9043
- destination: {
9044
- receivedCurrency: {
9045
- sufficient: destBalanceSufficientResult,
9046
- receivedAmount: receivedAmount,
9047
- balance: destBalance,
9048
- balanceAfter: destbalanceAfterResult,
9049
- currencySymbol: destAsset.symbol,
9050
- existentialDeposit: edDestBn
9051
- },
9052
- xcmFee: {
9053
- fee: destFee,
9054
- balance: destXcmFeeBalance,
9055
- balanceAfter: destXcmFeeBalanceAfter,
9056
- currencySymbol: destFeeCurrency
9057
- }
9058
- }
9387
+ assetHub: assetHub,
9388
+ bridgeHub: bridgeHub,
9389
+ destination: destinationInfo
9059
9390
  });
9060
- case 69:
9061
- _context.prev = 69;
9391
+ case 55:
9392
+ _context.prev = 55;
9062
9393
  api.setDisconnectAllowed(true);
9063
- destApi.setDisconnectAllowed(true);
9064
- _context.next = 74;
9394
+ _context.next = 59;
9065
9395
  return api.disconnect();
9066
- case 74:
9067
- _context.next = 76;
9068
- return destApi.disconnect();
9069
- case 76:
9070
- return _context.finish(69);
9071
- case 77:
9396
+ case 59:
9397
+ return _context.finish(55);
9398
+ case 60:
9072
9399
  case "end":
9073
9400
  return _context.stop();
9074
9401
  }
9075
- }, _callee, null, [[9,, 69, 77]]);
9402
+ }, _callee, null, [[7,, 55, 60]]);
9076
9403
  }));
9077
9404
  return function getTransferInfo(_x) {
9078
9405
  return _ref2.apply(this, arguments);
9079
9406
  };
9080
9407
  }();
9081
9408
 
9409
+ var calculateTotalXcmFee = function calculateTotalXcmFee(feeResult) {
9410
+ var _feeResult$assetHub;
9411
+ var totalFee = 0n;
9412
+ if (((_feeResult$assetHub = feeResult.assetHub) === null || _feeResult$assetHub === void 0 ? void 0 : _feeResult$assetHub.fee) !== undefined) {
9413
+ totalFee += feeResult.assetHub.fee;
9414
+ }
9415
+ if (feeResult.destination.fee !== undefined) {
9416
+ totalFee += feeResult.destination.fee;
9417
+ }
9418
+ return totalFee;
9419
+ };
9082
9420
  var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9083
9421
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
9084
- var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
9422
+ var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, xcmFeeResult, dryRunError, assetHubFeeResult, bridgeHubFeeResult, _xcmFeeResult$destina, destFee, destFeeCurrency, destDryRunError, hopDryRunError, totalFee, method, feeToSubtract;
9085
9423
  return _regeneratorRuntime().wrap(function _callee$(_context) {
9086
9424
  while (1) switch (_context.prev = _context.next) {
9087
9425
  case 0:
9088
9426
  api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset, currency = _ref.currency;
9427
+ if (!(destination === 'Ethereum')) {
9428
+ _context.next = 3;
9429
+ break;
9430
+ }
9431
+ return _context.abrupt("return", true);
9432
+ case 3:
9089
9433
  validateAddress(address, destination);
9434
+ if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
9435
+ _context.next = 6;
9436
+ break;
9437
+ }
9438
+ throw new InvalidParameterError('Kusama is outside of Polkadot ecosystem, thus function is unable to verify the existential deposit for it.');
9439
+ case 6:
9440
+ if (!(origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot')) {
9441
+ _context.next = 8;
9442
+ break;
9443
+ }
9444
+ throw new InvalidParameterError('Polkadot is outside of Kusama ecosystem, thus function is unable to verify the existential deposit for it.');
9445
+ case 8:
9090
9446
  destApi = api.clone();
9091
- _context.next = 5;
9447
+ _context.next = 11;
9092
9448
  return destApi.init(destination);
9093
- case 5:
9449
+ case 11:
9094
9450
  asset = findAssetOnDestOrThrow(origin, destination, currency);
9095
9451
  destCurrency = asset.multiLocation ? {
9096
9452
  multilocation: asset.multiLocation
@@ -9099,22 +9455,22 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9099
9455
  };
9100
9456
  ed = getExistentialDeposit(destination, destCurrency);
9101
9457
  if (!(ed === null)) {
9102
- _context.next = 10;
9458
+ _context.next = 16;
9103
9459
  break;
9104
9460
  }
9105
9461
  throw new InvalidParameterError("Cannot get existential deposit for currency ".concat(JSON.stringify(currency)));
9106
- case 10:
9462
+ case 16:
9107
9463
  edBN = BigInt(ed);
9108
- _context.next = 13;
9464
+ _context.next = 19;
9109
9465
  return getAssetBalanceInternal({
9110
9466
  address: address,
9111
9467
  node: destination,
9112
9468
  api: destApi,
9113
9469
  currency: destCurrency
9114
9470
  });
9115
- case 13:
9471
+ case 19:
9116
9472
  balance = _context.sent;
9117
- _context.next = 16;
9473
+ _context.next = 22;
9118
9474
  return getXcmFee({
9119
9475
  api: api,
9120
9476
  tx: tx,
@@ -9126,39 +9482,49 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
9126
9482
  feeAsset: feeAsset,
9127
9483
  disableFallback: false
9128
9484
  });
9129
- case 16:
9130
- _yield$getXcmFee = _context.sent;
9131
- dryRunError = _yield$getXcmFee.origin.dryRunError;
9132
- _yield$getXcmFee$dest = _yield$getXcmFee.destination;
9133
- destFee = _yield$getXcmFee$dest.fee;
9134
- destFeeCurrency = _yield$getXcmFee$dest.currency;
9135
- destDryRunError = _yield$getXcmFee$dest.dryRunError;
9485
+ case 22:
9486
+ xcmFeeResult = _context.sent;
9487
+ dryRunError = xcmFeeResult.origin.dryRunError, assetHubFeeResult = xcmFeeResult.assetHub, bridgeHubFeeResult = xcmFeeResult.bridgeHub, _xcmFeeResult$destina = xcmFeeResult.destination, destFee = _xcmFeeResult$destina.fee, destFeeCurrency = _xcmFeeResult$destina.currency, destDryRunError = _xcmFeeResult$destina.dryRunError;
9136
9488
  if (!(destFee === undefined)) {
9137
- _context.next = 24;
9489
+ _context.next = 26;
9138
9490
  break;
9139
9491
  }
9140
9492
  throw new InvalidParameterError("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(destination, "."));
9141
- case 24:
9493
+ case 26:
9142
9494
  if (!dryRunError) {
9143
- _context.next = 26;
9495
+ _context.next = 28;
9144
9496
  break;
9145
9497
  }
9146
9498
  throw new DryRunFailedError(dryRunError, 'origin');
9147
- case 26:
9499
+ case 28:
9500
+ hopDryRunError = (assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.dryRunError) || (bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.dryRunError);
9501
+ if (!hopDryRunError) {
9502
+ _context.next = 31;
9503
+ break;
9504
+ }
9505
+ throw new DryRunFailedError(hopDryRunError, assetHubFeeResult !== null && assetHubFeeResult !== void 0 && assetHubFeeResult.dryRunError ? 'assetHub' : 'bridgeHub');
9506
+ case 31:
9148
9507
  if (!destDryRunError) {
9149
- _context.next = 28;
9508
+ _context.next = 33;
9150
9509
  break;
9151
9510
  }
9152
9511
  throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError));
9153
- case 28:
9512
+ case 33:
9154
9513
  if (!(normalizeSymbol(asset.symbol) !== normalizeSymbol(destFeeCurrency))) {
9155
- _context.next = 30;
9514
+ _context.next = 35;
9156
9515
  break;
9157
9516
  }
9158
9517
  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.");
9159
- case 30:
9160
- return _context.abrupt("return", BigInt(currency.amount) - destFee > (balance < edBN ? edBN : 0));
9161
- case 31:
9518
+ case 35:
9519
+ totalFee = calculateTotalXcmFee(xcmFeeResult);
9520
+ method = api.getMethod(tx);
9521
+ if (method === 'transfer_assets_using_type_and_then' || method === 'transferAssetsUsingTypeAndThen') {
9522
+ feeToSubtract = totalFee;
9523
+ } else {
9524
+ feeToSubtract = destFee;
9525
+ }
9526
+ return _context.abrupt("return", BigInt(currency.amount) - feeToSubtract > (balance < edBN ? edBN : 0));
9527
+ case 39:
9162
9528
  case "end":
9163
9529
  return _context.stop();
9164
9530
  }
@@ -9198,13 +9564,10 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
9198
9564
  };
9199
9565
  }();
9200
9566
 
9201
- var assertToIsStringAndNoEthereum = function assertToIsStringAndNoEthereum(to) {
9567
+ var assertToIsString = function assertToIsString(to) {
9202
9568
  if (isTMultiLocation(to)) {
9203
9569
  throw new InvalidParameterError('Multi-Location destination is not supported for XCM fee calculation.');
9204
9570
  }
9205
- if (to === 'Ethereum') {
9206
- throw new InvalidParameterError('Ethereum destination is not yet supported for XCM fee calculation.');
9207
- }
9208
9571
  };
9209
9572
  var assertAddressIsString = function assertAddressIsString(address) {
9210
9573
  if (isTMultiLocation(address)) {
@@ -9536,12 +9899,6 @@ var GeneralBuilder = /*#__PURE__*/function () {
9536
9899
  }
9537
9900
  throw new InvalidParameterError('Multi-Location address is not supported for XCM fee calculation.');
9538
9901
  case 8:
9539
- if (!(to === 'Ethereum')) {
9540
- _context3.next = 10;
9541
- break;
9542
- }
9543
- throw new InvalidParameterError('Ethereum destination is not yet supported for XCM fee calculation.');
9544
- case 10:
9545
9902
  return _context3.abrupt("return", dryRun({
9546
9903
  api: this.api,
9547
9904
  tx: tx,
@@ -9552,7 +9909,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9552
9909
  senderAddress: this._options.senderAddress,
9553
9910
  feeAsset: feeAsset
9554
9911
  }));
9555
- case 11:
9912
+ case 9:
9556
9913
  case "end":
9557
9914
  return _context3.stop();
9558
9915
  }
@@ -9589,7 +9946,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9589
9946
  disableFallback: false
9590
9947
  }, disableFallback = _ref.disableFallback;
9591
9948
  _this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress, feeAsset = _this$_options3.feeAsset;
9592
- assertToIsStringAndNoEthereum(to);
9949
+ assertToIsString(to);
9593
9950
  assertAddressIsString(address);
9594
9951
  _context4.next = 6;
9595
9952
  return this.build();
@@ -9654,7 +10011,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9654
10011
  disableFallback: false
9655
10012
  }, disableFallback = _ref2.disableFallback;
9656
10013
  _this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress, currency = _this$_options4.currency, feeAsset = _this$_options4.feeAsset;
9657
- assertToIsStringAndNoEthereum(to);
10014
+ assertToIsString(to);
9658
10015
  _context5.next = 5;
9659
10016
  return this.build();
9660
10017
  case 5:
@@ -9705,7 +10062,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9705
10062
  while (1) switch (_context6.prev = _context6.next) {
9706
10063
  case 0:
9707
10064
  _this$_options5 = this._options, from = _this$_options5.from, to = _this$_options5.to, address = _this$_options5.address, senderAddress = _this$_options5.senderAddress;
9708
- assertToIsStringAndNoEthereum(to);
10065
+ assertToIsString(to);
9709
10066
  assertAddressIsString(address);
9710
10067
  _context6.next = 5;
9711
10068
  return this.build();
@@ -9756,7 +10113,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9756
10113
  while (1) switch (_context7.prev = _context7.next) {
9757
10114
  case 0:
9758
10115
  _this$_options6 = this._options, from = _this$_options6.from, to = _this$_options6.to, senderAddress = _this$_options6.senderAddress;
9759
- assertToIsStringAndNoEthereum(to);
10116
+ assertToIsString(to);
9760
10117
  _context7.next = 4;
9761
10118
  return this.build();
9762
10119
  case 4:
@@ -9804,7 +10161,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9804
10161
  while (1) switch (_context8.prev = _context8.next) {
9805
10162
  case 0:
9806
10163
  _this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
9807
- assertToIsStringAndNoEthereum(to);
10164
+ assertToIsString(to);
9808
10165
  _context8.next = 4;
9809
10166
  return this.build();
9810
10167
  case 4:
@@ -9847,7 +10204,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9847
10204
  while (1) switch (_context9.prev = _context9.next) {
9848
10205
  case 0:
9849
10206
  _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;
9850
- assertToIsStringAndNoEthereum(to);
10207
+ assertToIsString(to);
9851
10208
  assertAddressIsString(address);
9852
10209
  _context9.next = 5;
9853
10210
  return this.build();
@@ -9889,7 +10246,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
9889
10246
  while (1) switch (_context0.prev = _context0.next) {
9890
10247
  case 0:
9891
10248
  _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;
9892
- assertToIsStringAndNoEthereum(to);
10249
+ assertToIsString(to);
9893
10250
  assertAddressIsString(address);
9894
10251
  _context0.next = 5;
9895
10252
  return this.build();
@@ -9949,4 +10306,4 @@ var Builder = function Builder(api) {
9949
10306
  return new GeneralBuilder(api, new BatchTransactionManager());
9950
10307
  };
9951
10308
 
9952
- export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
10309
+ export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, replaceBigInt, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };