@paraspell/sdk-core 11.13.0 → 11.14.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
@@ -771,11 +771,11 @@ var createVersionedAssets = function createVersionedAssets(version, amount, loca
771
771
  return addXcmVersionHeader([asset], version);
772
772
  };
773
773
 
774
- var getCurrencySelection = function getCurrencySelection(asset) {
774
+ var getCurrencySelection = function getCurrencySelection(chain, asset) {
775
775
  if (asset.location) return {
776
776
  location: asset.location
777
777
  };
778
- if (assets.isForeignAsset(asset) && asset.assetId) {
778
+ if (assets.isForeignAsset(asset) && asset.assetId && !chain.startsWith('Bifrost')) {
779
779
  return {
780
780
  id: asset.assetId
781
781
  };
@@ -917,6 +917,33 @@ var createTx = /*#__PURE__*/function () {
917
917
  };
918
918
  }();
919
919
 
920
+ var getAssetReserveChain = function getAssetReserveChain(chain, assetLocation) {
921
+ var hasGlobalConsensusJunction = sdkCommon.hasJunction(assetLocation, 'GlobalConsensus');
922
+ var paraId = sdkCommon.getJunctionValue(assetLocation, 'Parachain');
923
+ if (paraId) {
924
+ var resolvedChain = getTChain(paraId, getRelayChainOf(chain));
925
+ if (!resolvedChain) {
926
+ throw new InvalidParameterError("Chain with paraId ".concat(paraId, " not found"));
927
+ }
928
+ return resolvedChain;
929
+ }
930
+ if (sdkCommon.isRelayChain(chain)) return chain;
931
+ var relaychain = getRelayChainOf(chain);
932
+ var ahChain = "AssetHub".concat(relaychain);
933
+ if (hasGlobalConsensusJunction) {
934
+ return ahChain;
935
+ }
936
+ if (sdkCommon.deepEqual(assetLocation, {
937
+ parents: sdkCommon.Parents.ONE,
938
+ interior: {
939
+ Here: null
940
+ }
941
+ })) {
942
+ return ahChain;
943
+ }
944
+ return chain;
945
+ };
946
+
920
947
  /**
921
948
  * Retrieves the chain instance for a given chain.
922
949
  *
@@ -1141,6 +1168,7 @@ exports.XTokensError = void 0;
1141
1168
  XTokensError["MinXcmFeeNotDefined"] = "MinXcmFeeNotDefined";
1142
1169
  XTokensError["RateLimited"] = "RateLimited";
1143
1170
  })(exports.XTokensError || (exports.XTokensError = {}));
1171
+ // Mirrors https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/pallet-xcm/src/errors.rs
1144
1172
  exports.PolkadotXcmError = void 0;
1145
1173
  (function (PolkadotXcmError) {
1146
1174
  PolkadotXcmError["Unreachable"] = "Unreachable";
@@ -1173,6 +1201,50 @@ exports.PolkadotXcmError = void 0;
1173
1201
  PolkadotXcmError["AliasNotFound"] = "AliasNotFound";
1174
1202
  PolkadotXcmError["LocalExecutionIncompleteWithError"] = "LocalExecutionIncompleteWithError";
1175
1203
  })(exports.PolkadotXcmError || (exports.PolkadotXcmError = {}));
1204
+ exports.PolkadotXcmExecutionError = void 0;
1205
+ (function (PolkadotXcmExecutionError) {
1206
+ PolkadotXcmExecutionError["Overflow"] = "Overflow";
1207
+ PolkadotXcmExecutionError["Unimplemented"] = "Unimplemented";
1208
+ PolkadotXcmExecutionError["UntrustedReserveLocation"] = "UntrustedReserveLocation";
1209
+ PolkadotXcmExecutionError["UntrustedTeleportLocation"] = "UntrustedTeleportLocation";
1210
+ PolkadotXcmExecutionError["LocationFull"] = "LocationFull";
1211
+ PolkadotXcmExecutionError["LocationNotInvertible"] = "LocationNotInvertible";
1212
+ PolkadotXcmExecutionError["BadOrigin"] = "BadOrigin";
1213
+ PolkadotXcmExecutionError["InvalidLocation"] = "InvalidLocation";
1214
+ PolkadotXcmExecutionError["AssetNotFound"] = "AssetNotFound";
1215
+ PolkadotXcmExecutionError["FailedToTransactAsset"] = "FailedToTransactAsset";
1216
+ PolkadotXcmExecutionError["NotWithdrawable"] = "NotWithdrawable";
1217
+ PolkadotXcmExecutionError["LocationCannotHold"] = "LocationCannotHold";
1218
+ PolkadotXcmExecutionError["ExceedsMaxMessageSize"] = "ExceedsMaxMessageSize";
1219
+ PolkadotXcmExecutionError["DestinationUnsupported"] = "DestinationUnsupported";
1220
+ PolkadotXcmExecutionError["Transport"] = "Transport";
1221
+ PolkadotXcmExecutionError["Unroutable"] = "Unroutable";
1222
+ PolkadotXcmExecutionError["UnknownClaim"] = "UnknownClaim";
1223
+ PolkadotXcmExecutionError["FailedToDecode"] = "FailedToDecode";
1224
+ PolkadotXcmExecutionError["MaxWeightInvalid"] = "MaxWeightInvalid";
1225
+ PolkadotXcmExecutionError["NotHoldingFees"] = "NotHoldingFees";
1226
+ PolkadotXcmExecutionError["TooExpensive"] = "TooExpensive";
1227
+ PolkadotXcmExecutionError["Trap"] = "Trap";
1228
+ PolkadotXcmExecutionError["ExpectationFalse"] = "ExpectationFalse";
1229
+ PolkadotXcmExecutionError["PalletNotFound"] = "PalletNotFound";
1230
+ PolkadotXcmExecutionError["NameMismatch"] = "NameMismatch";
1231
+ PolkadotXcmExecutionError["VersionIncompatible"] = "VersionIncompatible";
1232
+ PolkadotXcmExecutionError["HoldingWouldOverflow"] = "HoldingWouldOverflow";
1233
+ PolkadotXcmExecutionError["ExportError"] = "ExportError";
1234
+ PolkadotXcmExecutionError["ReanchorFailed"] = "ReanchorFailed";
1235
+ PolkadotXcmExecutionError["NoDeal"] = "NoDeal";
1236
+ PolkadotXcmExecutionError["FeesNotMet"] = "FeesNotMet";
1237
+ PolkadotXcmExecutionError["LockError"] = "LockError";
1238
+ PolkadotXcmExecutionError["NoPermission"] = "NoPermission";
1239
+ PolkadotXcmExecutionError["Unanchored"] = "Unanchored";
1240
+ PolkadotXcmExecutionError["NotDepositable"] = "NotDepositable";
1241
+ PolkadotXcmExecutionError["TooManyAssets"] = "TooManyAssets";
1242
+ PolkadotXcmExecutionError["UnhandledXcmVersion"] = "UnhandledXcmVersion";
1243
+ PolkadotXcmExecutionError["WeightLimitReached"] = "WeightLimitReached";
1244
+ PolkadotXcmExecutionError["Barrier"] = "Barrier";
1245
+ PolkadotXcmExecutionError["WeightNotComputable"] = "WeightNotComputable";
1246
+ PolkadotXcmExecutionError["ExceedsStackLimit"] = "ExceedsStackLimit";
1247
+ })(exports.PolkadotXcmExecutionError || (exports.PolkadotXcmExecutionError = {}));
1176
1248
 
1177
1249
  var resolveModuleError = function resolveModuleError(chain, error) {
1178
1250
  var palletDetails = pallets.getSupportedPalletsDetails(chain).find(function (p) {
@@ -1182,6 +1254,7 @@ var resolveModuleError = function resolveModuleError(chain, error) {
1182
1254
  throw new InvalidParameterError("Pallet with index ".concat(error.index, " not found"));
1183
1255
  }
1184
1256
  // Use only the first byte of the error to get the error index
1257
+ // Including 0x prefix
1185
1258
  var errorIndex = Number(error.error.slice(0, 4));
1186
1259
  var name = palletDetails.name;
1187
1260
  if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
@@ -1191,7 +1264,20 @@ var resolveModuleError = function resolveModuleError(chain, error) {
1191
1264
  if (!failureReason) {
1192
1265
  throw new InvalidParameterError("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
1193
1266
  }
1194
- return failureReason;
1267
+ if (failureReason === exports.PolkadotXcmError.LocalExecutionIncompleteWithError) {
1268
+ var subErrorIndex = Number("0x".concat(error.error.slice(6, 8)));
1269
+ var failureSubReason = Object.values(exports.PolkadotXcmExecutionError)[subErrorIndex];
1270
+ if (!failureSubReason) {
1271
+ throw new InvalidParameterError("Sub-error index ".concat(subErrorIndex, " not found in PolkadotXcm pallet"));
1272
+ }
1273
+ return {
1274
+ failureReason: failureReason,
1275
+ failureSubReason: failureSubReason
1276
+ };
1277
+ }
1278
+ return {
1279
+ failureReason: failureReason
1280
+ };
1195
1281
  };
1196
1282
 
1197
1283
  var isAssetHub = function isAssetHub(chain) {
@@ -1228,7 +1314,8 @@ var padFee = function padFee(raw, origin, dest, side) {
1228
1314
  return mul(raw, 130n, 100n);
1229
1315
  };
1230
1316
  var padValueBy = function padValueBy(amount, percent) {
1231
- return mul(amount, BigInt(100 + percent), 100n);
1317
+ var scaled = BigInt(Math.round(percent * 100)); // 2 decimal precision
1318
+ return amount * (BigInt(10000) + scaled) / BigInt(10000);
1232
1319
  };
1233
1320
 
1234
1321
  var resolveScenario = function resolveScenario(origin, destination) {
@@ -3246,33 +3333,6 @@ var throwUnsupportedCurrency = function throwUnsupportedCurrency(currency, chain
3246
3333
  throw new assets.InvalidCurrencyError("".concat(isDestination ? 'Destination' : 'Origin', " chain ").concat(chain, " does not support currency ").concat(JSON.stringify(currency, sdkCommon.replaceBigInt), "."));
3247
3334
  };
3248
3335
 
3249
- var getAssetReserveChain = function getAssetReserveChain(chain, assetLocation) {
3250
- var hasGlobalConsensusJunction = sdkCommon.hasJunction(assetLocation, 'GlobalConsensus');
3251
- var paraId = sdkCommon.getJunctionValue(assetLocation, 'Parachain');
3252
- if (paraId) {
3253
- var resolvedChain = getTChain(paraId, getRelayChainOf(chain));
3254
- if (!resolvedChain) {
3255
- throw new InvalidParameterError("Chain with paraId ".concat(paraId, " not found"));
3256
- }
3257
- return resolvedChain;
3258
- }
3259
- if (sdkCommon.isRelayChain(chain)) return chain;
3260
- var relaychain = getRelayChainOf(chain);
3261
- var ahChain = "AssetHub".concat(relaychain);
3262
- if (hasGlobalConsensusJunction) {
3263
- return ahChain;
3264
- }
3265
- if (sdkCommon.deepEqual(assetLocation, {
3266
- parents: sdkCommon.Parents.ONE,
3267
- interior: {
3268
- Here: null
3269
- }
3270
- })) {
3271
- return ahChain;
3272
- }
3273
- return chain;
3274
- };
3275
-
3276
3336
  var prepareExecuteContext = function prepareExecuteContext(_ref) {
3277
3337
  var chain = _ref.chain,
3278
3338
  destChain = _ref.destChain,
@@ -3589,7 +3649,7 @@ var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
3589
3649
  }
3590
3650
  return hops[0].result.fee;
3591
3651
  };
3592
- var FEE_PADDING_PERCENTAGE$2 = 40;
3652
+ var FEE_PADDING_PERCENTAGE$1 = 40;
3593
3653
  var handleExecuteTransfer = /*#__PURE__*/function () {
3594
3654
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
3595
3655
  var api, senderAddress, paraIdTo, assetInfo, currency, feeCurrency, address, feeAssetInfo, version, checkAmount, destChain, internalOptions, FEE_ASSET_AMOUNT, feeAssetAmount, call, dryRunResult, originFeeEstimate, originFee, reserveFeeEstimate, reserveFee, xcm, weight;
@@ -3647,9 +3707,9 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
3647
3707
  throw new DryRunFailedError(dryRunResult.failureReason);
3648
3708
  case 2:
3649
3709
  originFeeEstimate = dryRunResult.origin.fee;
3650
- originFee = padValueBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$2);
3710
+ originFee = padValueBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
3651
3711
  reserveFeeEstimate = getReserveFeeFromHops(dryRunResult.hops);
3652
- reserveFee = padValueBy(reserveFeeEstimate, FEE_PADDING_PERCENTAGE$2);
3712
+ reserveFee = padValueBy(reserveFeeEstimate, FEE_PADDING_PERCENTAGE$1);
3653
3713
  checkAmount(feeAssetInfo && !assets.isAssetEqual(assetInfo, feeAssetInfo) ? reserveFee : originFee + reserveFee);
3654
3714
  xcm = createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
3655
3715
  fees: {
@@ -3725,21 +3785,27 @@ var determineAddress = function determineAddress(chain, address, senderAddress)
3725
3785
  };
3726
3786
  var getReverseTxFee = /*#__PURE__*/function () {
3727
3787
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
3728
- var api, origin, destination, senderAddress, address, toAddress, fromAddress, _yield$Builder$from$t, tx, rawFee;
3788
+ var api, origin, destination, senderAddress, address, skipReverseFeeCalculation, toAddress, fromAddress, _yield$Builder$from$t, tx, rawFee;
3729
3789
  return _regenerator().w(function (_context) {
3730
3790
  while (1) switch (_context.n) {
3731
3791
  case 0:
3732
- api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address;
3792
+ api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, skipReverseFeeCalculation = _ref.skipReverseFeeCalculation;
3793
+ if (!skipReverseFeeCalculation) {
3794
+ _context.n = 1;
3795
+ break;
3796
+ }
3797
+ return _context.a(2, 0n);
3798
+ case 1:
3733
3799
  toAddress = determineAddress(origin, address, senderAddress);
3734
3800
  fromAddress = determineAddress(destination, address, senderAddress);
3735
- _context.n = 1;
3801
+ _context.n = 2;
3736
3802
  return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(currencyInput)['buildInternal']();
3737
- case 1:
3803
+ case 2:
3738
3804
  _yield$Builder$from$t = _context.v;
3739
3805
  tx = _yield$Builder$from$t.tx;
3740
- _context.n = 2;
3806
+ _context.n = 3;
3741
3807
  return api.calculateTransactionFee(tx, fromAddress);
3742
- case 2:
3808
+ case 3:
3743
3809
  rawFee = _context.v;
3744
3810
  return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
3745
3811
  }
@@ -3851,7 +3917,7 @@ var getBalanceForeignXTokens = /*#__PURE__*/function () {
3851
3917
  return _regenerator().w(function (_context) {
3852
3918
  while (1) switch (_context.n) {
3853
3919
  case 0:
3854
- if (!(chain === 'Astar' || chain === 'Shiden' || chain.startsWith('Integritee'))) {
3920
+ if (!(chain === 'Astar' || chain === 'Shiden' || chain === 'CrustShadow' || chain.startsWith('Integritee'))) {
3855
3921
  _context.n = 1;
3856
3922
  break;
3857
3923
  }
@@ -4408,7 +4474,8 @@ var getDestXcmFee = /*#__PURE__*/function () {
4408
4474
  break;
4409
4475
  }
4410
4476
  return _context3.a(2, {
4411
- dryRunError: dryRunResult.failureReason
4477
+ dryRunError: dryRunResult.failureReason,
4478
+ dryRunSubError: dryRunResult.failureSubReason
4412
4479
  });
4413
4480
  case 5:
4414
4481
  _context3.n = 6;
@@ -4419,6 +4486,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
4419
4486
  fee: _fee2,
4420
4487
  feeType: 'paymentInfo',
4421
4488
  dryRunError: dryRunResult.failureReason,
4489
+ dryRunSubError: dryRunResult.failureSubReason,
4422
4490
  sufficient: false,
4423
4491
  asset: asset,
4424
4492
  currency: asset.symbol
@@ -4673,7 +4741,8 @@ var getFailureInfo$1 = function getFailureInfo(result) {
4673
4741
  if (chainResult && chainResult.success === false && chainResult.failureReason) {
4674
4742
  return {
4675
4743
  failureChain: chain,
4676
- failureReason: chainResult.failureReason
4744
+ failureReason: chainResult.failureReason,
4745
+ failureSubReason: chainResult.failureSubReason
4677
4746
  };
4678
4747
  }
4679
4748
  }
@@ -4684,7 +4753,8 @@ var getFailureInfo$1 = function getFailureInfo(result) {
4684
4753
  }
4685
4754
  return {
4686
4755
  failureChain: result.failureChain,
4687
- failureReason: result.failureReason
4756
+ failureReason: result.failureReason,
4757
+ failureSubReason: result.failureSubReason
4688
4758
  };
4689
4759
  };
4690
4760
 
@@ -5445,6 +5515,7 @@ var dryRunInternal = /*#__PURE__*/function () {
5445
5515
  }
5446
5516
  return _context2.a(2, {
5447
5517
  failureReason: originDryRun.failureReason,
5518
+ failureSubReason: originDryRun.failureSubReason,
5448
5519
  failureChain: 'origin',
5449
5520
  origin: originDryRun,
5450
5521
  hops: []
@@ -5730,7 +5801,7 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
5730
5801
  };
5731
5802
  }();
5732
5803
 
5733
- var FEE_PADDING_PERCENTAGE$1 = 20;
5804
+ var FEE_PADDING_PERCENTAGE = 20;
5734
5805
  var validateAmount = function validateAmount(amount, requiredFee) {
5735
5806
  if (amount <= requiredFee) {
5736
5807
  throw new AmountTooLowError("Asset amount is too low, please increase the amount or use a different fee asset.");
@@ -5796,7 +5867,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
5796
5867
  throw new DryRunFailedError("Exchange (destination) failed: ".concat(dryRunResult.destination.failureReason || 'Unknown reason'));
5797
5868
  }
5798
5869
  if (dryRunResult.destination && dryRunResult.destination.success) {
5799
- fees.exchangeFee = padValueBy(dryRunResult.destination.fee, FEE_PADDING_PERCENTAGE$1);
5870
+ fees.exchangeFee = padValueBy(dryRunResult.destination.fee, FEE_PADDING_PERCENTAGE);
5800
5871
  }
5801
5872
  } else {
5802
5873
  // Normal case: exchange is an intermediate hop
@@ -5805,7 +5876,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
5805
5876
  throw new DryRunFailedError("Exchange hop failed: ".concat(exchangeHop.result.failureReason || 'Unknown reason'));
5806
5877
  }
5807
5878
  if (exchangeHop.result.success) {
5808
- fees.exchangeFee = padValueBy(exchangeHop.result.fee, FEE_PADDING_PERCENTAGE$1);
5879
+ fees.exchangeFee = padValueBy(exchangeHop.result.fee, FEE_PADDING_PERCENTAGE);
5809
5880
  }
5810
5881
  }
5811
5882
  } else {
@@ -5822,7 +5893,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
5822
5893
  throw new DryRunFailedError("Hop before exchange failed: ".concat(hopBeforeExchange.result.failureReason || 'Unknown reason'));
5823
5894
  }
5824
5895
  if (hopBeforeExchange.result.success) {
5825
- fees.originReserveFee = padValueBy(hopBeforeExchange.result.fee, FEE_PADDING_PERCENTAGE$1);
5896
+ fees.originReserveFee = padValueBy(hopBeforeExchange.result.fee, FEE_PADDING_PERCENTAGE);
5826
5897
  }
5827
5898
  } else if (!destChain && hops.length > 0) {
5828
5899
  // Special case: when destChain is undefined and we have hops,
@@ -5832,7 +5903,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
5832
5903
  throw new DryRunFailedError("Origin reserve hop failed: ".concat(lastHop.result.failureReason || 'Unknown reason'));
5833
5904
  }
5834
5905
  if (lastHop.result.success) {
5835
- fees.originReserveFee = padValueBy(lastHop.result.fee, FEE_PADDING_PERCENTAGE$1);
5906
+ fees.originReserveFee = padValueBy(lastHop.result.fee, FEE_PADDING_PERCENTAGE);
5836
5907
  }
5837
5908
  }
5838
5909
  // Handle destination reserve fee (hop after exchange)
@@ -5843,7 +5914,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
5843
5914
  throw new DryRunFailedError("Hop after exchange failed: ".concat(hopAfterExchange.result.failureReason || 'Unknown reason'));
5844
5915
  }
5845
5916
  if (hopAfterExchange.result.success) {
5846
- fees.destReserveFee = padValueBy(hopAfterExchange.result.fee, FEE_PADDING_PERCENTAGE$1);
5917
+ fees.destReserveFee = padValueBy(hopAfterExchange.result.fee, FEE_PADDING_PERCENTAGE);
5847
5918
  }
5848
5919
  }
5849
5920
  return fees;
@@ -6029,7 +6100,7 @@ var handleToAhTeleport = /*#__PURE__*/function () {
6029
6100
  // Enter dummy fee values just to get the dry run to pass
6030
6101
  asset.amount, asset.amount / 2n);
6031
6102
  _context.n = 4;
6032
- return getXcmFeeInternal({
6103
+ return getXcmFeeOnce({
6033
6104
  api: api,
6034
6105
  tx: dummyTx,
6035
6106
  origin: origin,
@@ -6632,7 +6703,7 @@ var Parachain = /*#__PURE__*/function () {
6632
6703
  }
6633
6704
  throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
6634
6705
  case 2:
6635
- return _context2.a(2, createTypeAndThenCall(getRelayChainOf(destChain), _objectSpread2(_objectSpread2({}, options), {}, {
6706
+ return _context2.a(2, createTypeThenAutoReserve(getRelayChainOf(destChain), _objectSpread2(_objectSpread2({}, options), {}, {
6636
6707
  beneficiaryLocation: createBeneficiaryLocation({
6637
6708
  api: api,
6638
6709
  address: address,
@@ -6946,6 +7017,11 @@ var Acala = /*#__PURE__*/function (_Parachain) {
6946
7017
  var currencySelection = this.getCurrencySelection(asset);
6947
7018
  return transferXTokens(input, currencySelection);
6948
7019
  }
7020
+ }, {
7021
+ key: "transferRelayToPara",
7022
+ value: function transferRelayToPara() {
7023
+ throw new ChainNotSupportedError();
7024
+ }
6949
7025
  }, {
6950
7026
  key: "transferLocalNativeAsset",
6951
7027
  value: function () {
@@ -7638,6 +7714,11 @@ var Astar = /*#__PURE__*/function (_Parachain) {
7638
7714
  var assetInfo = _ref.assetInfo;
7639
7715
  return assetInfo.symbol !== this.getNativeAssetSymbol();
7640
7716
  }
7717
+ }, {
7718
+ key: "transferRelayToPara",
7719
+ value: function transferRelayToPara() {
7720
+ throw new ChainNotSupportedError();
7721
+ }
7641
7722
  }, {
7642
7723
  key: "transferLocalNonNativeAsset",
7643
7724
  value: function transferLocalNonNativeAsset(options) {
@@ -7700,25 +7781,6 @@ var Basilisk = /*#__PURE__*/function (_Parachain) {
7700
7781
  }]);
7701
7782
  }(Parachain);
7702
7783
 
7703
- var BifrostKusama = /*#__PURE__*/function (_Parachain) {
7704
- function BifrostKusama() {
7705
- _classCallCheck(this, BifrostKusama);
7706
- return _callSuper(this, BifrostKusama, ['BifrostKusama', 'bifrost', 'Kusama', sdkCommon.Version.V5]);
7707
- }
7708
- _inherits(BifrostKusama, _Parachain);
7709
- return _createClass(BifrostKusama, [{
7710
- key: "transferXTokens",
7711
- value: function transferXTokens(input) {
7712
- return getChain('BifrostPolkadot').transferXTokens(input);
7713
- }
7714
- }, {
7715
- key: "transferLocalNonNativeAsset",
7716
- value: function transferLocalNonNativeAsset(options) {
7717
- return getChain('BifrostPolkadot').transferLocalNonNativeAsset(options);
7718
- }
7719
- }]);
7720
- }(Parachain);
7721
-
7722
7784
  var BifrostPolkadot = /*#__PURE__*/function (_Parachain) {
7723
7785
  function BifrostPolkadot() {
7724
7786
  var chain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'BifrostPolkadot';
@@ -7740,7 +7802,7 @@ var BifrostPolkadot = /*#__PURE__*/function (_Parachain) {
7740
7802
  }
7741
7803
  var isVToken = asset.symbol && asset.symbol.startsWith('v');
7742
7804
  var isVSToken = asset.symbol && asset.symbol.startsWith('vs');
7743
- if (!assets.isForeignAsset(asset)) {
7805
+ if (!assets.isForeignAsset(asset) || assets.isForeignAsset(asset) && !asset.assetId) {
7744
7806
  return isVToken ? {
7745
7807
  VToken: asset.symbol.substring(1)
7746
7808
  } : {
@@ -7820,6 +7882,15 @@ var BifrostPolkadot = /*#__PURE__*/function (_Parachain) {
7820
7882
  }]);
7821
7883
  }(Parachain);
7822
7884
 
7885
+ var BifrostKusama = /*#__PURE__*/function (_BifrostPolkadot) {
7886
+ function BifrostKusama() {
7887
+ _classCallCheck(this, BifrostKusama);
7888
+ return _callSuper(this, BifrostKusama, ['BifrostKusama', 'bifrost', 'Kusama', sdkCommon.Version.V5]);
7889
+ }
7890
+ _inherits(BifrostKusama, _BifrostPolkadot);
7891
+ return _createClass(BifrostKusama);
7892
+ }(BifrostPolkadot);
7893
+
7823
7894
  var BifrostPaseo = /*#__PURE__*/function (_BifrostPolkadot) {
7824
7895
  function BifrostPaseo() {
7825
7896
  _classCallCheck(this, BifrostPaseo);
@@ -8609,6 +8680,16 @@ var IntegriteePolkadot = /*#__PURE__*/function (_Parachain) {
8609
8680
  value: function transferRelayToPara() {
8610
8681
  throw new ChainNotSupportedError();
8611
8682
  }
8683
+ }, {
8684
+ key: "isSendingTempDisabled",
8685
+ value: function isSendingTempDisabled(_options) {
8686
+ return true;
8687
+ }
8688
+ }, {
8689
+ key: "isReceivingTempDisabled",
8690
+ value: function isReceivingTempDisabled(_scenario) {
8691
+ return true;
8692
+ }
8612
8693
  }, {
8613
8694
  key: "transferLocalNonNativeAsset",
8614
8695
  value: function transferLocalNonNativeAsset(options) {
@@ -9695,6 +9776,11 @@ var Shiden = /*#__PURE__*/function (_Parachain) {
9695
9776
  var assetInfo = _ref.assetInfo;
9696
9777
  return assetInfo.symbol !== this.getNativeAssetSymbol();
9697
9778
  }
9779
+ }, {
9780
+ key: "transferRelayToPara",
9781
+ value: function transferRelayToPara() {
9782
+ throw new ChainNotSupportedError();
9783
+ }
9698
9784
  }, {
9699
9785
  key: "transferLocalNonNativeAsset",
9700
9786
  value: function transferLocalNonNativeAsset(options) {
@@ -10290,14 +10376,13 @@ var SystemPallet = /*#__PURE__*/function (_BaseAssetsPallet) {
10290
10376
  }(BaseAssetsPallet);
10291
10377
 
10292
10378
  var resolveId = function resolveId(asset, chain) {
10293
- var isBifrost = chain.startsWith('Bifrost');
10294
- if (isBifrost) {
10379
+ if (chain === 'BifrostPolkadot' || chain === 'BifrostKusama' || chain === 'BifrostPaseo') {
10295
10380
  var _asset$assetId;
10296
10381
  var isEthAsset = assets.isForeignAsset(asset) && ((_asset$assetId = asset.assetId) === null || _asset$assetId === void 0 ? void 0 : _asset$assetId.startsWith('0x'));
10297
10382
  var resolvedAsset = isEthAsset && asset.location ? assets.findAssetInfoOrThrow(chain, {
10298
10383
  location: asset.location
10299
10384
  }, null) : asset;
10300
- return getChain('BifrostPolkadot').getCurrencySelection(resolvedAsset);
10385
+ return getChain(chain).getCurrencySelection(resolvedAsset);
10301
10386
  } else {
10302
10387
  assertHasId(asset);
10303
10388
  return asset.assetId;
@@ -10512,7 +10597,7 @@ var wrapTxBypass = /*#__PURE__*/function () {
10512
10597
  api: api,
10513
10598
  chain: chain,
10514
10599
  address: address,
10515
- currency: getCurrencySelection(asset)
10600
+ currency: getCurrencySelection(chain, asset)
10516
10601
  });
10517
10602
  case 9:
10518
10603
  balance = _context.v;
@@ -10827,6 +10912,7 @@ var getOriginXcmFeeInternal = /*#__PURE__*/function () {
10827
10912
  }
10828
10913
  return _context.a(2, {
10829
10914
  dryRunError: dryRunResult.failureReason,
10915
+ dryRunSubError: dryRunResult.failureSubReason,
10830
10916
  currency: dryRunResult.currency,
10831
10917
  asset: dryRunResult.asset
10832
10918
  });
@@ -10842,6 +10928,7 @@ var getOriginXcmFeeInternal = /*#__PURE__*/function () {
10842
10928
  asset: dryRunResult.asset,
10843
10929
  feeType: 'paymentInfo',
10844
10930
  dryRunError: dryRunResult.failureReason,
10931
+ dryRunSubError: dryRunResult.failureSubReason,
10845
10932
  sufficient: false
10846
10933
  });
10847
10934
  case 8:
@@ -10955,19 +11042,23 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
10955
11042
  // Check standard chains first for backwards compatibility
10956
11043
  if ((_chains$origin = chains.origin) !== null && _chains$origin !== void 0 && _chains$origin.dryRunError) return {
10957
11044
  failureChain: 'origin',
10958
- failureReason: chains.origin.dryRunError
11045
+ failureReason: chains.origin.dryRunError,
11046
+ failureSubReason: chains.origin.dryRunSubError
10959
11047
  };
10960
11048
  if ((_chains$assetHub = chains.assetHub) !== null && _chains$assetHub !== void 0 && _chains$assetHub.dryRunError) return {
10961
11049
  failureChain: 'assetHub',
10962
- failureReason: chains.assetHub.dryRunError
11050
+ failureReason: chains.assetHub.dryRunError,
11051
+ failureSubReason: chains.assetHub.dryRunSubError
10963
11052
  };
10964
11053
  if ((_chains$bridgeHub = chains.bridgeHub) !== null && _chains$bridgeHub !== void 0 && _chains$bridgeHub.dryRunError) return {
10965
11054
  failureChain: 'bridgeHub',
10966
- failureReason: chains.bridgeHub.dryRunError
11055
+ failureReason: chains.bridgeHub.dryRunError,
11056
+ failureSubReason: chains.bridgeHub.dryRunSubError
10967
11057
  };
10968
11058
  if ((_chains$destination = chains.destination) !== null && _chains$destination !== void 0 && _chains$destination.dryRunError) return {
10969
11059
  failureChain: 'destination',
10970
- failureReason: chains.destination.dryRunError
11060
+ failureReason: chains.destination.dryRunError,
11061
+ failureSubReason: chains.destination.dryRunSubError
10971
11062
  };
10972
11063
  // Check hops for failures
10973
11064
  var _iterator = _createForOfIteratorHelper(hops),
@@ -10978,7 +11069,8 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
10978
11069
  if (hop.result.dryRunError) {
10979
11070
  return {
10980
11071
  failureChain: hop.chain,
10981
- failureReason: hop.result.dryRunError
11072
+ failureReason: hop.result.dryRunError,
11073
+ failureSubReason: hop.result.dryRunSubError
10982
11074
  };
10983
11075
  }
10984
11076
  }
@@ -10989,13 +11081,13 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
10989
11081
  }
10990
11082
  return {};
10991
11083
  };
10992
- var getXcmFeeInternal = /*#__PURE__*/function () {
11084
+ var getXcmFeeOnce = /*#__PURE__*/function () {
10993
11085
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
10994
- var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, useRootOrigin, asset, amount, _yield$getOriginXcmFe, originFeeRaw, originCurrency, originAsset, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, isMythosToEthereum, originFee, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, processHop, traversalResult, destFee, destCurrency, destAsset, destFeeType, destDryRunError, destSufficient, destResult, _destApi, destFallback, assetHubChain, processedBridgeHub, bridgeHubChain, bridgeHubHopIndex, convertToFeeDetail, result, _getFailureInfo2, failureChain, failureReason, _t, _t2, _t3, _t4;
11086
+ var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, asset, amount, _yield$getOriginXcmFe, originFeeRaw, originAsset, originFeeType, originDryRunError, originDryRunSubError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, isMythosToEthereum, originFee, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, processHop, traversalResult, destFee, destCurrency, destAsset, destFeeType, destDryRunError, destDryRunSubError, destSufficient, destResult, _destApi, destFallback, assetHubChain, processedBridgeHub, bridgeHubChain, bridgeHubHopIndex, convertToFeeDetail, result, _getFailureInfo2, failureChain, failureReason, _t, _t2, _t3, _t4;
10995
11087
  return _regenerator().w(function (_context2) {
10996
11088
  while (1) switch (_context2.p = _context2.n) {
10997
11089
  case 0:
10998
- api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset, disableFallback = _ref.disableFallback, swapConfig = _ref.swapConfig, useRootOrigin = _ref.useRootOrigin;
11090
+ api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset, disableFallback = _ref.disableFallback, swapConfig = _ref.swapConfig, useRootOrigin = _ref.useRootOrigin, skipReverseFeeCalculation = _ref.skipReverseFeeCalculation;
10999
11091
  asset = assets.findAssetInfoOrThrow(origin, currency, destination);
11000
11092
  amount = abstractDecimals(currency.amount, asset.decimals, api);
11001
11093
  _context2.n = 1;
@@ -11013,10 +11105,10 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11013
11105
  case 1:
11014
11106
  _yield$getOriginXcmFe = _context2.v;
11015
11107
  originFeeRaw = _yield$getOriginXcmFe.fee;
11016
- originCurrency = _yield$getOriginXcmFe.currency;
11017
11108
  originAsset = _yield$getOriginXcmFe.asset;
11018
11109
  originFeeType = _yield$getOriginXcmFe.feeType;
11019
11110
  originDryRunError = _yield$getOriginXcmFe.dryRunError;
11111
+ originDryRunSubError = _yield$getOriginXcmFe.dryRunSubError;
11020
11112
  initialForwardedXcm = _yield$getOriginXcmFe.forwardedXcms;
11021
11113
  initialDestParaId = _yield$getOriginXcmFe.destParaId;
11022
11114
  originWeight = _yield$getOriginXcmFe.weight;
@@ -11065,21 +11157,24 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11065
11157
  originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
11066
11158
  senderAddress: senderAddress,
11067
11159
  disableFallback: disableFallback,
11068
- swapConfig: swapConfig
11160
+ swapConfig: swapConfig,
11161
+ skipReverseFeeCalculation: skipReverseFeeCalculation
11069
11162
  });
11070
11163
  case 7:
11071
11164
  destFeeRes = _context2.v;
11072
11165
  _result = {
11073
- origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
11166
+ origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
11074
11167
  fee: originFee
11075
11168
  }), originFeeType && {
11076
11169
  feeType: originFeeType
11077
11170
  }), {}, {
11078
11171
  sufficient: sufficientOriginFee,
11079
- currency: originCurrency,
11172
+ currency: originAsset.symbol,
11080
11173
  asset: originAsset
11081
11174
  }, originDryRunError && {
11082
11175
  dryRunError: originDryRunError
11176
+ }), originDryRunSubError && {
11177
+ dryRunSubError: originDryRunSubError
11083
11178
  }),
11084
11179
  destination: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee ? {
11085
11180
  fee: destFeeRes.fee
@@ -11147,7 +11242,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11147
11242
  originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
11148
11243
  disableFallback: disableFallback,
11149
11244
  hasPassedExchange: hasPassedExchange,
11150
- swapConfig: swapConfig
11245
+ swapConfig: swapConfig,
11246
+ skipReverseFeeCalculation: skipReverseFeeCalculation
11151
11247
  });
11152
11248
  case 1:
11153
11249
  hopResult = _context.v;
@@ -11193,6 +11289,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11193
11289
  destFee = destResult.fee;
11194
11290
  destFeeType = destResult.feeType;
11195
11291
  destDryRunError = destResult.dryRunError;
11292
+ destDryRunSubError = destResult.dryRunSubError;
11196
11293
  destSufficient = destResult.sufficient;
11197
11294
  destCurrency = destResult.currency;
11198
11295
  destAsset = destResult.asset;
@@ -11224,7 +11321,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11224
11321
  originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
11225
11322
  senderAddress: senderAddress,
11226
11323
  disableFallback: disableFallback,
11227
- swapConfig: swapConfig
11324
+ swapConfig: swapConfig,
11325
+ skipReverseFeeCalculation: skipReverseFeeCalculation
11228
11326
  });
11229
11327
  case 14:
11230
11328
  destFallback = _context2.v;
@@ -11271,7 +11369,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11271
11369
  }
11272
11370
  }
11273
11371
  convertToFeeDetail = function convertToFeeDetail(result) {
11274
- return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, result.fee !== undefined && {
11372
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, result.fee !== undefined && {
11275
11373
  fee: result.fee
11276
11374
  }), result.feeType && {
11277
11375
  feeType: result.feeType
@@ -11282,10 +11380,12 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11282
11380
  asset: result.asset
11283
11381
  }, result.dryRunError && {
11284
11382
  dryRunError: result.dryRunError
11383
+ }), result.dryRunSubError && {
11384
+ dryRunSubError: result.dryRunSubError
11285
11385
  });
11286
11386
  };
11287
11387
  result = _objectSpread2(_objectSpread2(_objectSpread2({
11288
- origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
11388
+ origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
11289
11389
  weight: originWeight
11290
11390
  }), originFee && {
11291
11391
  fee: originFee
@@ -11294,17 +11394,19 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11294
11394
  }), sufficientOriginFee !== undefined && {
11295
11395
  sufficient: sufficientOriginFee
11296
11396
  }), {}, {
11297
- currency: originCurrency,
11397
+ currency: originAsset.symbol,
11298
11398
  asset: originAsset
11299
11399
  }, originDryRunError && {
11300
11400
  dryRunError: originDryRunError
11401
+ }), originDryRunSubError && {
11402
+ dryRunSubError: originDryRunSubError
11301
11403
  })
11302
11404
  }, traversalResult.assetHub && {
11303
11405
  assetHub: convertToFeeDetail(traversalResult.assetHub)
11304
11406
  }), processedBridgeHub && {
11305
11407
  bridgeHub: convertToFeeDetail(processedBridgeHub)
11306
11408
  }), {}, {
11307
- destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFee !== undefined && {
11409
+ destination: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, destFee !== undefined && {
11308
11410
  fee: destFee
11309
11411
  }), destFeeType && {
11310
11412
  feeType: destFeeType
@@ -11314,6 +11416,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11314
11416
  asset: destAsset
11315
11417
  }, destDryRunError && {
11316
11418
  dryRunError: destDryRunError
11419
+ }), destDryRunSubError && {
11420
+ dryRunSubError: destDryRunSubError
11317
11421
  }),
11318
11422
  hops: traversalResult.hops.map(function (hop) {
11319
11423
  return {
@@ -11335,32 +11439,32 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
11335
11439
  }
11336
11440
  }, _callee2, null, [[5,, 8, 10]]);
11337
11441
  }));
11338
- return function getXcmFeeInternal(_x) {
11442
+ return function getXcmFeeOnce(_x) {
11339
11443
  return _ref2.apply(this, arguments);
11340
11444
  };
11341
11445
  }();
11342
11446
 
11343
- var getXcmFee = /*#__PURE__*/function () {
11447
+ var getXcmFeeInternal = /*#__PURE__*/function () {
11344
11448
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
11345
- var buildTx, api, _real$assetHub, _real$bridgeHub, tx, real, forced, _forced, _t;
11449
+ var buildTx, _real$assetHub, _real$bridgeHub, tx, real, forced, _forced, _t;
11346
11450
  return _regenerator().w(function (_context) {
11347
11451
  while (1) switch (_context.p = _context.n) {
11348
11452
  case 0:
11349
- buildTx = options.buildTx, api = options.api;
11453
+ buildTx = options.buildTx;
11350
11454
  _context.p = 1;
11351
11455
  _context.n = 2;
11352
11456
  return buildTx();
11353
11457
  case 2:
11354
11458
  tx = _context.v;
11355
11459
  _context.n = 3;
11356
- return getXcmFeeInternal(_objectSpread2(_objectSpread2({}, options), {}, {
11460
+ return getXcmFeeOnce(_objectSpread2(_objectSpread2({}, options), {}, {
11357
11461
  tx: tx,
11358
11462
  useRootOrigin: false
11359
11463
  }));
11360
11464
  case 3:
11361
11465
  real = _context.v;
11362
11466
  _context.n = 4;
11363
- return getBypassResultWithRetries(options, getXcmFeeInternal, tx);
11467
+ return getBypassResultWithRetries(options, getXcmFeeOnce, tx);
11364
11468
  case 4:
11365
11469
  forced = _context.v;
11366
11470
  return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, forced), {}, {
@@ -11398,7 +11502,7 @@ var getXcmFee = /*#__PURE__*/function () {
11398
11502
  throw _t;
11399
11503
  case 6:
11400
11504
  _context.n = 7;
11401
- return getBypassResultWithRetries(options, getXcmFeeInternal);
11505
+ return getBypassResultWithRetries(options, getXcmFeeOnce);
11402
11506
  case 7:
11403
11507
  _forced = _context.v;
11404
11508
  return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, _forced), {}, {
@@ -11425,21 +11529,40 @@ var getXcmFee = /*#__PURE__*/function () {
11425
11529
  });
11426
11530
  })
11427
11531
  }));
11428
- case 8:
11429
- _context.p = 8;
11430
- _context.n = 9;
11431
- return api.disconnect();
11432
- case 9:
11433
- return _context.f(8);
11434
- case 10:
11435
- return _context.a(2);
11436
11532
  }
11437
- }, _callee, null, [[1, 5, 8, 10]]);
11533
+ }, _callee, null, [[1, 5]]);
11438
11534
  }));
11439
- return function getXcmFee(_x) {
11535
+ return function getXcmFeeInternal(_x) {
11440
11536
  return _ref.apply(this, arguments);
11441
11537
  };
11442
11538
  }();
11539
+ var getXcmFee = /*#__PURE__*/function () {
11540
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
11541
+ var api;
11542
+ return _regenerator().w(function (_context2) {
11543
+ while (1) switch (_context2.p = _context2.n) {
11544
+ case 0:
11545
+ api = options.api;
11546
+ _context2.p = 1;
11547
+ _context2.n = 2;
11548
+ return getXcmFeeInternal(options);
11549
+ case 2:
11550
+ return _context2.a(2, _context2.v);
11551
+ case 3:
11552
+ _context2.p = 3;
11553
+ _context2.n = 4;
11554
+ return api.disconnect();
11555
+ case 4:
11556
+ return _context2.f(3);
11557
+ case 5:
11558
+ return _context2.a(2);
11559
+ }
11560
+ }, _callee2, null, [[1,, 3, 5]]);
11561
+ }));
11562
+ return function getXcmFee(_x2) {
11563
+ return _ref2.apply(this, arguments);
11564
+ };
11565
+ }();
11443
11566
 
11444
11567
  var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
11445
11568
  var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
@@ -11864,7 +11987,7 @@ var buildHopInfo = /*#__PURE__*/function () {
11864
11987
 
11865
11988
  var getTransferInfo = /*#__PURE__*/function () {
11866
11989
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
11867
- var api, buildTx, origin, destination, senderAddress, ahAddress, address, currency, feeAsset, resolvedFeeAsset, originAsset, amount, originBalanceFee, originBalance, edOrigin, _yield$getXcmFee, _yield$getXcmFee$orig, originFee, originFeeCurrency, originFeeAsset, assetHubFeeResult, bridgeHubFeeResult, destFeeDetail, hops, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, assetHub, bridgeHub, bridgeHubChain, builtHops, totalHopFee, destinationInfo, _t;
11990
+ var api, buildTx, origin, destination, senderAddress, ahAddress, address, currency, feeAsset, resolvedFeeAsset, originAsset, amount, originBalanceFee, originBalance, edOrigin, _yield$getXcmFeeInter, _yield$getXcmFeeInter2, originFee, originFeeCurrency, originFeeAsset, assetHubFeeResult, bridgeHubFeeResult, destFeeDetail, hops, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, assetHub, bridgeHub, bridgeHubChain, builtHops, totalHopFee, destinationInfo, _t;
11868
11991
  return _regenerator().w(function (_context2) {
11869
11992
  while (1) switch (_context2.p = _context2.n) {
11870
11993
  case 0:
@@ -11932,15 +12055,15 @@ var getTransferInfo = /*#__PURE__*/function () {
11932
12055
  disableFallback: false
11933
12056
  });
11934
12057
  case 9:
11935
- _yield$getXcmFee = _context2.v;
11936
- _yield$getXcmFee$orig = _yield$getXcmFee.origin;
11937
- originFee = _yield$getXcmFee$orig.fee;
11938
- originFeeCurrency = _yield$getXcmFee$orig.currency;
11939
- originFeeAsset = _yield$getXcmFee$orig.asset;
11940
- assetHubFeeResult = _yield$getXcmFee.assetHub;
11941
- bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
11942
- destFeeDetail = _yield$getXcmFee.destination;
11943
- hops = _yield$getXcmFee.hops;
12058
+ _yield$getXcmFeeInter = _context2.v;
12059
+ _yield$getXcmFeeInter2 = _yield$getXcmFeeInter.origin;
12060
+ originFee = _yield$getXcmFeeInter2.fee;
12061
+ originFeeCurrency = _yield$getXcmFeeInter2.currency;
12062
+ originFeeAsset = _yield$getXcmFeeInter2.asset;
12063
+ assetHubFeeResult = _yield$getXcmFeeInter.assetHub;
12064
+ bridgeHubFeeResult = _yield$getXcmFeeInter.bridgeHub;
12065
+ destFeeDetail = _yield$getXcmFeeInter.destination;
12066
+ hops = _yield$getXcmFeeInter.hops;
11944
12067
  isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, originAsset);
11945
12068
  originBalanceAfter = originBalance - amount;
11946
12069
  originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
@@ -12310,15 +12433,20 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
12310
12433
  reserve = _ref.reserve,
12311
12434
  dest = _ref.dest,
12312
12435
  assetInfo = _ref.assetInfo,
12313
- version = _ref.options.version;
12436
+ _ref$options = _ref.options,
12437
+ version = _ref$options.version,
12438
+ pallet = _ref$options.pallet,
12439
+ method = _ref$options.method;
12314
12440
  var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
12315
12441
  var finalDest = origin.chain === reserve.chain ? dest.chain : reserve.chain;
12316
12442
  var destLocation = createDestination(version, origin.chain, finalDest, getParaId(finalDest));
12317
12443
  var reserveType = origin.chain === reserve.chain ? 'LocalReserve' : 'DestinationReserve';
12318
12444
  var feeMultiAsset = createAsset(version, assetInfo.amount, sdkCommon.isRelayChain(origin.chain) ? localizeLocation(origin.chain, feeAssetLocation) : feeAssetLocation);
12445
+ var module = pallet !== null && pallet !== void 0 ? pallet : sdkCommon.isRelayChain(origin.chain) ? 'XcmPallet' : 'PolkadotXcm';
12446
+ var methodName = method !== null && method !== void 0 ? method : 'transfer_assets_using_type_and_then';
12319
12447
  return {
12320
- module: sdkCommon.isRelayChain(origin.chain) ? 'XcmPallet' : 'PolkadotXcm',
12321
- method: 'transfer_assets_using_type_and_then',
12448
+ module: module,
12449
+ method: methodName,
12322
12450
  parameters: {
12323
12451
  dest: addXcmVersionHeader(destLocation, version),
12324
12452
  assets: addXcmVersionHeader(assets, version),
@@ -12331,130 +12459,76 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
12331
12459
  };
12332
12460
  };
12333
12461
 
12334
- var FEE_PADDING_PERCENTAGE = 20;
12335
- var FEE_ETH_ASSET_PADDING_PERCENTAGE = 100;
12336
- var FEE_PADDING_HYDRATION = 500;
12337
- var getPadding = function getPadding(chain, _ref) {
12338
- var assetInfo = _ref.assetInfo,
12339
- dest = _ref.dest;
12340
- var isEthAsset = assetInfo.location && assets.findAssetInfoByLoc(assets.getOtherAssets('Ethereum'), assetInfo.location);
12341
- if (chain === 'Hydration') return FEE_PADDING_HYDRATION;
12342
- if (isEthAsset && dest.chain.startsWith('AssetHub')) return FEE_ETH_ASSET_PADDING_PERCENTAGE;
12343
- return FEE_PADDING_PERCENTAGE;
12344
- };
12345
- var computeInstructionFee = /*#__PURE__*/function () {
12346
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2, version, xcm, context) {
12347
- var chain, api, padding, _t;
12462
+ var FEE_PADDING = 30;
12463
+ var sumHopFees = function sumHopFees(result, asset) {
12464
+ return result.hops.reduce(function (acc, hop) {
12465
+ // only add if asset is equal
12466
+ return assets.isAssetEqual(hop.result.asset, asset) ? acc + hop.result.fee : acc;
12467
+ }, 0n);
12468
+ };
12469
+ var computeAllFees = /*#__PURE__*/function () {
12470
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, buildTx) {
12471
+ var origin, dest, assetInfo, _context$options, senderAddress, address, currency, feeCurrency, result, hopFees, destFee;
12348
12472
  return _regenerator().w(function (_context) {
12349
12473
  while (1) switch (_context.n) {
12350
12474
  case 0:
12351
- chain = _ref2.chain, api = _ref2.api;
12352
- padding = getPadding(chain, context);
12353
- _t = padValueBy;
12354
- _context.n = 1;
12355
- return api.getXcmPaymentApiFee(chain, addXcmVersionHeader(xcm, version), [], {
12356
- location: DOT_LOCATION
12357
- }, true);
12358
- case 1:
12359
- return _context.a(2, _t(_context.v, padding));
12360
- }
12361
- }, _callee);
12362
- }));
12363
- return function computeInstructionFee(_x, _x2, _x3, _x4) {
12364
- return _ref3.apply(this, arguments);
12365
- };
12366
- }();
12367
- var computeAllFees = /*#__PURE__*/function () {
12368
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, customXcm, isDotAsset, refundInstruction) {
12369
- var reserve, dest, version, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0;
12370
- return _regenerator().w(function (_context2) {
12371
- while (1) switch (_context2.n) {
12372
- case 0:
12373
- reserve = context.reserve, dest = context.dest, version = context.options.version;
12374
- if (!customXcm.some(function (x) {
12375
- return 'DepositReserveAsset' in x || 'InitiateTeleport' in x;
12376
- })) {
12377
- _context2.n = 6;
12475
+ origin = context.origin, dest = context.dest, assetInfo = context.assetInfo, _context$options = context.options, senderAddress = _context$options.senderAddress, address = _context$options.address, currency = _context$options.currency, feeCurrency = _context$options.feeCurrency;
12476
+ assertSenderAddress(senderAddress);
12477
+ assertAddressIsString(address);
12478
+ if (assets.hasDryRunSupport(context.origin.chain)) {
12479
+ _context.n = 1;
12378
12480
  break;
12379
12481
  }
12380
- _context2.n = 1;
12381
- return computeInstructionFee(reserve, version, customXcm, context);
12482
+ return _context.a(2, null);
12382
12483
  case 1:
12383
- _t3 = _context2.v;
12384
- if (!refundInstruction) {
12385
- _context2.n = 3;
12386
- break;
12387
- }
12388
- _context2.n = 2;
12389
- return computeInstructionFee(reserve, version, [refundInstruction], context);
12484
+ _context.n = 2;
12485
+ return getXcmFeeInternal({
12486
+ api: origin.api,
12487
+ buildTx: buildTx,
12488
+ origin: origin.chain,
12489
+ destination: dest.chain,
12490
+ senderAddress: senderAddress,
12491
+ address: address,
12492
+ currency: currency,
12493
+ feeAsset: feeCurrency,
12494
+ disableFallback: false,
12495
+ skipReverseFeeCalculation: true
12496
+ });
12390
12497
  case 2:
12391
- _t4 = _context2.v;
12392
- _context2.n = 4;
12393
- break;
12394
- case 3:
12395
- _t4 = 0n;
12396
- case 4:
12397
- _t5 = _t4;
12398
- _context2.n = 5;
12399
- return computeInstructionFee(assets.hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, function () {
12400
- var instr = customXcm.find(function (j) {
12401
- return 'DepositReserveAsset' in j || 'InitiateTeleport' in j;
12402
- });
12403
- return instr ? 'DepositReserveAsset' in instr ? instr.DepositReserveAsset.xcm : instr.InitiateTeleport.xcm : undefined;
12404
- }(), context);
12405
- case 5:
12406
- _t6 = _context2.v;
12407
- _t2 = {
12408
- reserveFee: _t3,
12409
- refundFee: _t5,
12410
- destFee: _t6
12411
- };
12412
- _context2.n = 13;
12413
- break;
12414
- case 6:
12415
- if (isDotAsset) {
12416
- _context2.n = 8;
12417
- break;
12418
- }
12419
- _context2.n = 7;
12420
- return computeInstructionFee(assets.hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm, context);
12421
- case 7:
12422
- _t7 = _context2.v;
12423
- _context2.n = 9;
12424
- break;
12425
- case 8:
12426
- _t7 = 0n;
12427
- case 9:
12428
- _t8 = _t7;
12429
- if (isDotAsset) {
12430
- _context2.n = 11;
12431
- break;
12432
- }
12433
- _context2.n = 10;
12434
- return computeInstructionFee(assets.hasXcmPaymentApiSupport(reserve.chain) ? reserve : dest, version, [refundInstruction], context);
12435
- case 10:
12436
- _t9 = _context2.v;
12437
- _context2.n = 12;
12438
- break;
12439
- case 11:
12440
- _t9 = 0n;
12441
- case 12:
12442
- _t0 = _t9;
12443
- _t2 = {
12444
- reserveFee: 0n,
12445
- destFee: _t8,
12446
- refundFee: _t0
12447
- };
12448
- case 13:
12449
- return _context2.a(2, _t2);
12498
+ result = _context.v;
12499
+ hopFees = sumHopFees(result, assetInfo);
12500
+ destFee = result.destination.fee;
12501
+ return _context.a(2, {
12502
+ hopFees: padValueBy(hopFees, FEE_PADDING),
12503
+ destFee: padValueBy(destFee, FEE_PADDING)
12504
+ });
12450
12505
  }
12451
- }, _callee2);
12506
+ }, _callee);
12452
12507
  }));
12453
- return function computeAllFees(_x5, _x6, _x7, _x8) {
12454
- return _ref4.apply(this, arguments);
12508
+ return function computeAllFees(_x, _x2) {
12509
+ return _ref.apply(this, arguments);
12455
12510
  };
12456
12511
  }();
12457
12512
 
12513
+ var RELAY_ASSET_LOCATIONS = [RELAY_LOCATION, {
12514
+ parents: 2,
12515
+ interior: {
12516
+ X1: [{
12517
+ GlobalConsensus: {
12518
+ Kusama: null
12519
+ }
12520
+ }]
12521
+ }
12522
+ }, {
12523
+ parents: 2,
12524
+ interior: {
12525
+ X1: [{
12526
+ GlobalConsensus: {
12527
+ Polkadot: null
12528
+ }
12529
+ }]
12530
+ }
12531
+ }];
12458
12532
  var getSubBridgeReserve = function getSubBridgeReserve(chain, destination, location) {
12459
12533
  if (sdkCommon.deepEqual(location, RELAY_LOCATION)) return chain;
12460
12534
  return destination;
@@ -12470,29 +12544,27 @@ var resolveReserveChain = function resolveReserveChain(chain, destination, asset
12470
12544
  };
12471
12545
  var createTypeAndThenCallContext = /*#__PURE__*/function () {
12472
12546
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
12473
- var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, destApi, reserveApi;
12547
+ var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, isRelayAsset, destApi, reserveApi;
12474
12548
  return _regenerator().w(function (_context) {
12475
12549
  while (1) switch (_context.n) {
12476
12550
  case 0:
12477
12551
  api = options.api, destination = options.destination, assetInfo = options.assetInfo;
12478
12552
  assertHasLocation(assetInfo);
12479
- if (!sdkCommon.isTLocation(destination)) {
12480
- _context.n = 1;
12481
- break;
12482
- }
12483
- throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
12484
- case 1:
12553
+ assertToIsString(destination);
12485
12554
  destinationChain = destination;
12486
12555
  isSubBridge = sdkCommon.isSubstrateBridge(chain, destinationChain);
12487
12556
  reserveChain = resolveReserveChain(chain, destinationChain, assetInfo.location, isSubBridge, overrideReserve);
12557
+ isRelayAsset = RELAY_ASSET_LOCATIONS.some(function (loc) {
12558
+ return sdkCommon.deepEqual(assetInfo.location, loc);
12559
+ });
12488
12560
  destApi = api.clone();
12489
- _context.n = 2;
12561
+ _context.n = 1;
12490
12562
  return destApi.init(destinationChain);
12491
- case 2:
12563
+ case 1:
12492
12564
  reserveApi = reserveChain === chain ? api : reserveChain === destinationChain ? destApi : api.clone();
12493
- _context.n = 3;
12565
+ _context.n = 2;
12494
12566
  return reserveApi.init(reserveChain);
12495
- case 3:
12567
+ case 2:
12496
12568
  return _context.a(2, {
12497
12569
  origin: {
12498
12570
  api: api,
@@ -12507,6 +12579,7 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
12507
12579
  chain: reserveChain
12508
12580
  },
12509
12581
  isSubBridge: isSubBridge,
12582
+ isRelayAsset: isRelayAsset,
12510
12583
  assetInfo: assetInfo,
12511
12584
  options: options
12512
12585
  });
@@ -12518,26 +12591,37 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
12518
12591
  };
12519
12592
  }();
12520
12593
 
12521
- var createCustomXcm = function createCustomXcm(_ref, isDotAsset, assetCount, isForFeeCalc) {
12522
- var origin = _ref.origin,
12523
- dest = _ref.dest,
12524
- reserve = _ref.reserve,
12525
- isSubBridge = _ref.isSubBridge,
12526
- assetInfo = _ref.assetInfo,
12527
- options = _ref.options;
12594
+ var resolveBuyExecutionAmount = function resolveBuyExecutionAmount(_ref, isForFeeCalc, _ref2, systemAssetAmount) {
12595
+ var isRelayAsset = _ref.isRelayAsset,
12596
+ assetInfo = _ref.assetInfo;
12597
+ var hopFees = _ref2.hopFees,
12598
+ destFee = _ref2.destFee;
12599
+ if (isForFeeCalc) {
12600
+ // Rough estimates for dummy XCM call, that is later dryRunned
12601
+ return isRelayAsset ? assetInfo.amount / 2n : systemAssetAmount / 2n;
12602
+ }
12603
+ // We have actual fees, calculate exact buy execution amount
12604
+ return isRelayAsset ? assetInfo.amount - hopFees : destFee;
12605
+ };
12606
+ var createCustomXcm = function createCustomXcm(context, assetCount, isForFeeCalc, systemAssetAmount) {
12528
12607
  var fees = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
12529
- reserveFee: 0n,
12530
- refundFee: 0n,
12608
+ hopFees: 0n,
12531
12609
  destFee: 0n
12532
12610
  };
12611
+ var origin = context.origin,
12612
+ dest = context.dest,
12613
+ reserve = context.reserve,
12614
+ isSubBridge = context.isSubBridge,
12615
+ isRelayAsset = context.isRelayAsset,
12616
+ assetInfo = context.assetInfo,
12617
+ options = context.options;
12533
12618
  var destination = options.destination,
12534
12619
  version = options.version,
12535
12620
  address = options.address,
12536
12621
  paraIdTo = options.paraIdTo;
12537
- var reserveFee = fees.reserveFee,
12538
- refundFee = fees.refundFee,
12622
+ var hopFees = fees.hopFees,
12539
12623
  destFee = fees.destFee;
12540
- var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
12624
+ var feeAssetLocation = !isRelayAsset ? RELAY_LOCATION : assetInfo.location;
12541
12625
  var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation, origin.chain);
12542
12626
  var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location, origin.chain));
12543
12627
  var depositInstruction = {
@@ -12560,10 +12644,10 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset, assetCount, isF
12560
12644
  }
12561
12645
  };
12562
12646
  var assetsFilter = [];
12563
- if (!isDotAsset) assetsFilter.push(createAsset(version, reserveFee + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
12647
+ if (!isRelayAsset) assetsFilter.push(createAsset(version, hopFees + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
12564
12648
  assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
12565
12649
  if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
12566
- var buyExecutionAmount = !isDotAsset ? destFee : assetInfo.amount - reserveFee - refundFee;
12650
+ var buyExecutionAmount = resolveBuyExecutionAmount(context, isForFeeCalc, fees, systemAssetAmount);
12567
12651
  if (buyExecutionAmount < 0n && !isForFeeCalc) throw new AmountTooLowError();
12568
12652
  var filter = isForFeeCalc ? {
12569
12653
  Wild: 'All'
@@ -12628,63 +12712,166 @@ var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, vers
12628
12712
  assets.push(createAsset(version, asset.amount, sdkCommon.isRelayChain(chain) ? localizeLocation(chain, asset.location) : asset.location));
12629
12713
  return assets;
12630
12714
  };
12715
+ var DEFAULT_SYSTEM_ASSET_AMOUNT = '1';
12716
+ var resolveSystemAssetAmount = function resolveSystemAssetAmount(_ref, isForFeeCalc, fees) {
12717
+ var origin = _ref.origin;
12718
+ if (isForFeeCalc) {
12719
+ var systemAsset = assets.findNativeAssetInfoOrThrow(getRelayChainOf(origin.chain));
12720
+ return parseUnits(DEFAULT_SYSTEM_ASSET_AMOUNT, systemAsset.decimals);
12721
+ }
12722
+ return fees.destFee + fees.hopFees;
12723
+ };
12724
+ var constructTypeAndThenCall = function constructTypeAndThenCall(context) {
12725
+ var fees = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12726
+ var origin = context.origin,
12727
+ assetInfo = context.assetInfo,
12728
+ isSubBridge = context.isSubBridge,
12729
+ isRelayAsset = context.isRelayAsset,
12730
+ _context$options = context.options,
12731
+ senderAddress = _context$options.senderAddress,
12732
+ version = _context$options.version;
12733
+ var assetCount = isRelayAsset ? 1 : 2;
12734
+ var refundInstruction = senderAddress ? createRefundInstruction(origin.api, senderAddress, version, assetCount) : null;
12735
+ var finalCustomXcm = [];
12736
+ if (refundInstruction && !isSubBridge) finalCustomXcm.push(refundInstruction);
12737
+ var resolvedFees = fees !== null && fees !== void 0 ? fees : {
12738
+ hopFees: 0n,
12739
+ destFee: 0n
12740
+ };
12741
+ var isForFeeCalc = fees === null;
12742
+ var systemAssetAmount = resolveSystemAssetAmount(context, isForFeeCalc, resolvedFees);
12743
+ finalCustomXcm.push.apply(finalCustomXcm, _toConsumableArray(createCustomXcm(context, assetCount, isForFeeCalc, systemAssetAmount, resolvedFees)));
12744
+ var assets = buildAssets(origin.chain, assetInfo, systemAssetAmount, isRelayAsset, version);
12745
+ return buildTypeAndThenCall(context, isRelayAsset, finalCustomXcm, assets);
12746
+ };
12631
12747
  /**
12632
12748
  * Creates a type and then call for transferring assets using XCM. Works only for DOT and snowbridge assets so far.
12633
12749
  */
12634
12750
  var createTypeAndThenCall = /*#__PURE__*/function () {
12635
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
12636
- var api, senderAddress, version, context, assetInfo, isSubBridge, LOCATIONS, isRelayAsset, assetCount, customXcm, refundInstruction, fees, finalCustomXcm, totalFee, assets;
12751
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
12752
+ var context, origin, assetInfo, fees;
12637
12753
  return _regenerator().w(function (_context) {
12638
12754
  while (1) switch (_context.n) {
12639
12755
  case 0:
12640
- api = options.api, senderAddress = options.senderAddress, version = options.version;
12641
12756
  _context.n = 1;
12642
12757
  return createTypeAndThenCallContext(chain, options, overrideReserve);
12643
12758
  case 1:
12644
12759
  context = _context.v;
12645
- assetInfo = context.assetInfo, isSubBridge = context.isSubBridge;
12646
- LOCATIONS = [RELAY_LOCATION, {
12647
- parents: 2,
12648
- interior: {
12649
- X1: [{
12650
- GlobalConsensus: {
12651
- Kusama: null
12652
- }
12653
- }]
12654
- }
12655
- }, {
12656
- parents: 2,
12657
- interior: {
12658
- X1: [{
12659
- GlobalConsensus: {
12660
- Polkadot: null
12661
- }
12662
- }]
12663
- }
12664
- }];
12665
- isRelayAsset = LOCATIONS.some(function (loc) {
12666
- return sdkCommon.deepEqual(assetInfo.location, loc);
12667
- });
12668
- assetCount = isRelayAsset ? 1 : 2;
12669
- customXcm = createCustomXcm(context, isRelayAsset, assetCount, true);
12670
- refundInstruction = senderAddress ? createRefundInstruction(api, senderAddress, version, assetCount) : null;
12760
+ origin = context.origin, assetInfo = context.assetInfo;
12671
12761
  _context.n = 2;
12672
- return computeAllFees(context, customXcm, isRelayAsset, refundInstruction);
12762
+ return computeAllFees(context, function (amount, relative) {
12763
+ var overridenAmount = amount ? relative ? assetInfo.amount + parseUnits(amount, assetInfo.decimals) : parseUnits(amount, assetInfo.decimals) : assetInfo.amount;
12764
+ return Promise.resolve(origin.api.callTxMethod(constructTypeAndThenCall(_objectSpread2(_objectSpread2({}, context), {}, {
12765
+ assetInfo: _objectSpread2(_objectSpread2({}, assetInfo), {}, {
12766
+ amount: overridenAmount
12767
+ })
12768
+ }))));
12769
+ });
12673
12770
  case 2:
12674
12771
  fees = _context.v;
12675
- finalCustomXcm = [];
12676
- if (refundInstruction && !isSubBridge) finalCustomXcm.push(refundInstruction);
12677
- finalCustomXcm.push.apply(finalCustomXcm, _toConsumableArray(createCustomXcm(context, isRelayAsset, assetCount, false, fees)));
12678
- totalFee = fees.reserveFee + fees.destFee + fees.refundFee;
12679
- assets = buildAssets(chain, assetInfo, totalFee, isRelayAsset, version);
12680
- return _context.a(2, buildTypeAndThenCall(context, isRelayAsset, finalCustomXcm, assets));
12772
+ return _context.a(2, constructTypeAndThenCall(context, fees));
12681
12773
  }
12682
12774
  }, _callee);
12683
12775
  }));
12684
12776
  return function createTypeAndThenCall(_x, _x2, _x3) {
12777
+ return _ref2.apply(this, arguments);
12778
+ };
12779
+ }();
12780
+
12781
+ var createCallForReserve = /*#__PURE__*/function () {
12782
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, reserveChain, options) {
12783
+ var api, destination, address, senderAddress, currency, feeCurrency, serialized, tx, dryRunResult, success;
12784
+ return _regenerator().w(function (_context) {
12785
+ while (1) switch (_context.n) {
12786
+ case 0:
12787
+ api = options.api, destination = options.destination, address = options.address, senderAddress = options.senderAddress, currency = options.currency, feeCurrency = options.feeCurrency;
12788
+ _context.n = 1;
12789
+ return createTypeAndThenCall(chain, options, reserveChain);
12790
+ case 1:
12791
+ serialized = _context.v;
12792
+ assertAddressIsString(address);
12793
+ assertToIsString(destination, 'Location destination is not supported for reserve auto-selection.');
12794
+ assertSenderAddress(senderAddress);
12795
+ tx = api.callTxMethod(serialized);
12796
+ _context.n = 2;
12797
+ return dryRunInternal({
12798
+ api: api,
12799
+ tx: tx,
12800
+ origin: chain,
12801
+ destination: destination,
12802
+ address: address,
12803
+ senderAddress: senderAddress,
12804
+ currency: currency,
12805
+ feeAsset: feeCurrency,
12806
+ useRootOrigin: true
12807
+ });
12808
+ case 2:
12809
+ dryRunResult = _context.v;
12810
+ success = !dryRunResult.failureReason;
12811
+ return _context.a(2, {
12812
+ call: serialized,
12813
+ success: success
12814
+ });
12815
+ }
12816
+ }, _callee);
12817
+ }));
12818
+ return function createCallForReserve(_x, _x2, _x3) {
12685
12819
  return _ref.apply(this, arguments);
12686
12820
  };
12687
12821
  }();
12822
+ /**
12823
+ * Creates a type-and-then call but auto-selects the asset reserve between AssetHub and the Relay chain
12824
+ * by dry-running both variants and preferring the one that succeeds. If both fail, returns the
12825
+ * AssetHub variant. Supports only relaychain assets.
12826
+ */
12827
+ var createTypeThenAutoReserve = /*#__PURE__*/function () {
12828
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(chain, options) {
12829
+ var originSupports, destSupports, relay, assetHubReserve, ahResult, relayResult;
12830
+ return _regenerator().w(function (_context2) {
12831
+ while (1) switch (_context2.n) {
12832
+ case 0:
12833
+ // Use dry-run path only when BOTH origin and destination support it
12834
+ originSupports = assets.hasDryRunSupport(chain);
12835
+ destSupports = options.destChain ? assets.hasDryRunSupport(options.destChain) : false;
12836
+ if (originSupports && destSupports) {
12837
+ _context2.n = 2;
12838
+ break;
12839
+ }
12840
+ _context2.n = 1;
12841
+ return createTypeAndThenCall(chain, options);
12842
+ case 1:
12843
+ return _context2.a(2, _context2.v);
12844
+ case 2:
12845
+ relay = getRelayChainOf(chain);
12846
+ assetHubReserve = "AssetHub".concat(relay);
12847
+ _context2.n = 3;
12848
+ return createCallForReserve(chain, assetHubReserve, options);
12849
+ case 3:
12850
+ ahResult = _context2.v;
12851
+ if (!ahResult.success) {
12852
+ _context2.n = 4;
12853
+ break;
12854
+ }
12855
+ return _context2.a(2, ahResult.call);
12856
+ case 4:
12857
+ _context2.n = 5;
12858
+ return createCallForReserve(chain, relay, options);
12859
+ case 5:
12860
+ relayResult = _context2.v;
12861
+ if (!relayResult.success) {
12862
+ _context2.n = 6;
12863
+ break;
12864
+ }
12865
+ return _context2.a(2, relayResult.call);
12866
+ case 6:
12867
+ return _context2.a(2, ahResult.call);
12868
+ }
12869
+ }, _callee2);
12870
+ }));
12871
+ return function createTypeThenAutoReserve(_x4, _x5) {
12872
+ return _ref2.apply(this, arguments);
12873
+ };
12874
+ }();
12688
12875
 
12689
12876
  var calculateTotalXcmFee = function calculateTotalXcmFee(feeResult) {
12690
12877
  var _feeResult$assetHub;
@@ -12745,7 +12932,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
12745
12932
  case 5:
12746
12933
  balance = _context.v;
12747
12934
  _context.n = 6;
12748
- return getXcmFee({
12935
+ return getXcmFeeInternal({
12749
12936
  api: api,
12750
12937
  buildTx: buildTx,
12751
12938
  origin: origin,
@@ -13489,7 +13676,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
13489
13676
  var _options$disableFallb;
13490
13677
  var disableFallback, _yield$this$prepareNo2, normalizedOptions, buildTx, api, from, to, senderAddress, address, currency, feeAsset;
13491
13678
  return _regenerator().w(function (_context8) {
13492
- while (1) switch (_context8.p = _context8.n) {
13679
+ while (1) switch (_context8.n) {
13493
13680
  case 0:
13494
13681
  disableFallback = (_options$disableFallb = options === null || options === void 0 ? void 0 : options.disableFallback) !== null && _options$disableFallb !== void 0 ? _options$disableFallb : false;
13495
13682
  _context8.n = 1;
@@ -13501,9 +13688,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
13501
13688
  api = normalizedOptions.api, from = normalizedOptions.from, to = normalizedOptions.to, senderAddress = normalizedOptions.senderAddress, address = normalizedOptions.address, currency = normalizedOptions.currency, feeAsset = normalizedOptions.feeAsset;
13502
13689
  assertToIsString(to);
13503
13690
  assertAddressIsString(address);
13504
- _context8.p = 2;
13505
- _context8.n = 3;
13506
- return getXcmFee({
13691
+ return _context8.a(2, getXcmFee({
13507
13692
  api: api,
13508
13693
  buildTx: buildTx,
13509
13694
  origin: from,
@@ -13513,19 +13698,9 @@ var GeneralBuilder = /*#__PURE__*/function () {
13513
13698
  currency: currency,
13514
13699
  feeAsset: feeAsset,
13515
13700
  disableFallback: disableFallback
13516
- });
13517
- case 3:
13518
- return _context8.a(2, _context8.v);
13519
- case 4:
13520
- _context8.p = 4;
13521
- _context8.n = 5;
13522
- return this.api.disconnect();
13523
- case 5:
13524
- return _context8.f(4);
13525
- case 6:
13526
- return _context8.a(2);
13701
+ }));
13527
13702
  }
13528
- }, _callee8, this, [[2,, 4, 6]]);
13703
+ }, _callee8, this);
13529
13704
  }));
13530
13705
  function getXcmFee$1(_x7) {
13531
13706
  return _getXcmFee2.apply(this, arguments);
@@ -13977,6 +14152,7 @@ exports.claimAssets = claimAssets;
13977
14152
  exports.computeFeeFromDryRun = computeFeeFromDryRun;
13978
14153
  exports.computeFeeFromDryRunPjs = computeFeeFromDryRunPjs;
13979
14154
  exports.computeOverridenAmount = computeOverridenAmount;
14155
+ exports.constructTypeAndThenCall = constructTypeAndThenCall;
13980
14156
  exports.convertSs58 = convertSs58;
13981
14157
  exports.createAsset = createAsset;
13982
14158
  exports.createAssetsFilter = createAssetsFilter;
@@ -13989,6 +14165,7 @@ exports.createExecuteCall = createExecuteCall;
13989
14165
  exports.createExecuteExchangeXcm = createExecuteExchangeXcm;
13990
14166
  exports.createTx = createTx;
13991
14167
  exports.createTypeAndThenCall = createTypeAndThenCall;
14168
+ exports.createTypeThenAutoReserve = createTypeThenAutoReserve;
13992
14169
  exports.createVersionedAssets = createVersionedAssets;
13993
14170
  exports.createX1Payload = createX1Payload;
13994
14171
  exports.deriveAccountId = deriveAccountId;
@@ -14029,6 +14206,7 @@ exports.getTransferableAmountInternal = getTransferableAmountInternal;
14029
14206
  exports.getXcmFee = getXcmFee;
14030
14207
  exports.getXcmFeeEstimate = getXcmFeeEstimate;
14031
14208
  exports.getXcmFeeInternal = getXcmFeeInternal;
14209
+ exports.getXcmFeeOnce = getXcmFeeOnce;
14032
14210
  exports.handleExecuteTransfer = handleExecuteTransfer;
14033
14211
  exports.handleSwapExecuteTransfer = handleSwapExecuteTransfer;
14034
14212
  exports.handleToAhTeleport = handleToAhTeleport;