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