@paraspell/sdk-core 11.14.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 +374 -277
- package/dist/index.d.ts +21 -7
- package/dist/index.mjs +373 -279
- package/package.json +4 -4
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
|
*
|
|
@@ -3306,33 +3333,6 @@ var throwUnsupportedCurrency = function throwUnsupportedCurrency(currency, chain
|
|
|
3306
3333
|
throw new assets.InvalidCurrencyError("".concat(isDestination ? 'Destination' : 'Origin', " chain ").concat(chain, " does not support currency ").concat(JSON.stringify(currency, sdkCommon.replaceBigInt), "."));
|
|
3307
3334
|
};
|
|
3308
3335
|
|
|
3309
|
-
var getAssetReserveChain = function getAssetReserveChain(chain, assetLocation) {
|
|
3310
|
-
var hasGlobalConsensusJunction = sdkCommon.hasJunction(assetLocation, 'GlobalConsensus');
|
|
3311
|
-
var paraId = sdkCommon.getJunctionValue(assetLocation, 'Parachain');
|
|
3312
|
-
if (paraId) {
|
|
3313
|
-
var resolvedChain = getTChain(paraId, getRelayChainOf(chain));
|
|
3314
|
-
if (!resolvedChain) {
|
|
3315
|
-
throw new InvalidParameterError("Chain with paraId ".concat(paraId, " not found"));
|
|
3316
|
-
}
|
|
3317
|
-
return resolvedChain;
|
|
3318
|
-
}
|
|
3319
|
-
if (sdkCommon.isRelayChain(chain)) return chain;
|
|
3320
|
-
var relaychain = getRelayChainOf(chain);
|
|
3321
|
-
var ahChain = "AssetHub".concat(relaychain);
|
|
3322
|
-
if (hasGlobalConsensusJunction) {
|
|
3323
|
-
return ahChain;
|
|
3324
|
-
}
|
|
3325
|
-
if (sdkCommon.deepEqual(assetLocation, {
|
|
3326
|
-
parents: sdkCommon.Parents.ONE,
|
|
3327
|
-
interior: {
|
|
3328
|
-
Here: null
|
|
3329
|
-
}
|
|
3330
|
-
})) {
|
|
3331
|
-
return ahChain;
|
|
3332
|
-
}
|
|
3333
|
-
return chain;
|
|
3334
|
-
};
|
|
3335
|
-
|
|
3336
3336
|
var prepareExecuteContext = function prepareExecuteContext(_ref) {
|
|
3337
3337
|
var chain = _ref.chain,
|
|
3338
3338
|
destChain = _ref.destChain,
|
|
@@ -3649,7 +3649,7 @@ var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
|
3649
3649
|
}
|
|
3650
3650
|
return hops[0].result.fee;
|
|
3651
3651
|
};
|
|
3652
|
-
var FEE_PADDING_PERCENTAGE$
|
|
3652
|
+
var FEE_PADDING_PERCENTAGE$1 = 40;
|
|
3653
3653
|
var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
3654
3654
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
3655
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;
|
|
@@ -3707,9 +3707,9 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
3707
3707
|
throw new DryRunFailedError(dryRunResult.failureReason);
|
|
3708
3708
|
case 2:
|
|
3709
3709
|
originFeeEstimate = dryRunResult.origin.fee;
|
|
3710
|
-
originFee = padValueBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$
|
|
3710
|
+
originFee = padValueBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
3711
3711
|
reserveFeeEstimate = getReserveFeeFromHops(dryRunResult.hops);
|
|
3712
|
-
reserveFee = padValueBy(reserveFeeEstimate, FEE_PADDING_PERCENTAGE$
|
|
3712
|
+
reserveFee = padValueBy(reserveFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
3713
3713
|
checkAmount(feeAssetInfo && !assets.isAssetEqual(assetInfo, feeAssetInfo) ? reserveFee : originFee + reserveFee);
|
|
3714
3714
|
xcm = createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
3715
3715
|
fees: {
|
|
@@ -3785,21 +3785,27 @@ var determineAddress = function determineAddress(chain, address, senderAddress)
|
|
|
3785
3785
|
};
|
|
3786
3786
|
var getReverseTxFee = /*#__PURE__*/function () {
|
|
3787
3787
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
3788
|
-
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;
|
|
3789
3789
|
return _regenerator().w(function (_context) {
|
|
3790
3790
|
while (1) switch (_context.n) {
|
|
3791
3791
|
case 0:
|
|
3792
|
-
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:
|
|
3793
3799
|
toAddress = determineAddress(origin, address, senderAddress);
|
|
3794
3800
|
fromAddress = determineAddress(destination, address, senderAddress);
|
|
3795
|
-
_context.n =
|
|
3801
|
+
_context.n = 2;
|
|
3796
3802
|
return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(currencyInput)['buildInternal']();
|
|
3797
|
-
case
|
|
3803
|
+
case 2:
|
|
3798
3804
|
_yield$Builder$from$t = _context.v;
|
|
3799
3805
|
tx = _yield$Builder$from$t.tx;
|
|
3800
|
-
_context.n =
|
|
3806
|
+
_context.n = 3;
|
|
3801
3807
|
return api.calculateTransactionFee(tx, fromAddress);
|
|
3802
|
-
case
|
|
3808
|
+
case 3:
|
|
3803
3809
|
rawFee = _context.v;
|
|
3804
3810
|
return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
|
|
3805
3811
|
}
|
|
@@ -3911,7 +3917,7 @@ var getBalanceForeignXTokens = /*#__PURE__*/function () {
|
|
|
3911
3917
|
return _regenerator().w(function (_context) {
|
|
3912
3918
|
while (1) switch (_context.n) {
|
|
3913
3919
|
case 0:
|
|
3914
|
-
if (!(chain === 'Astar' || chain === 'Shiden' || chain.startsWith('Integritee'))) {
|
|
3920
|
+
if (!(chain === 'Astar' || chain === 'Shiden' || chain === 'CrustShadow' || chain.startsWith('Integritee'))) {
|
|
3915
3921
|
_context.n = 1;
|
|
3916
3922
|
break;
|
|
3917
3923
|
}
|
|
@@ -5795,7 +5801,7 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
|
5795
5801
|
};
|
|
5796
5802
|
}();
|
|
5797
5803
|
|
|
5798
|
-
var FEE_PADDING_PERCENTAGE
|
|
5804
|
+
var FEE_PADDING_PERCENTAGE = 20;
|
|
5799
5805
|
var validateAmount = function validateAmount(amount, requiredFee) {
|
|
5800
5806
|
if (amount <= requiredFee) {
|
|
5801
5807
|
throw new AmountTooLowError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
@@ -5861,7 +5867,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
5861
5867
|
throw new DryRunFailedError("Exchange (destination) failed: ".concat(dryRunResult.destination.failureReason || 'Unknown reason'));
|
|
5862
5868
|
}
|
|
5863
5869
|
if (dryRunResult.destination && dryRunResult.destination.success) {
|
|
5864
|
-
fees.exchangeFee = padValueBy(dryRunResult.destination.fee, FEE_PADDING_PERCENTAGE
|
|
5870
|
+
fees.exchangeFee = padValueBy(dryRunResult.destination.fee, FEE_PADDING_PERCENTAGE);
|
|
5865
5871
|
}
|
|
5866
5872
|
} else {
|
|
5867
5873
|
// Normal case: exchange is an intermediate hop
|
|
@@ -5870,7 +5876,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
5870
5876
|
throw new DryRunFailedError("Exchange hop failed: ".concat(exchangeHop.result.failureReason || 'Unknown reason'));
|
|
5871
5877
|
}
|
|
5872
5878
|
if (exchangeHop.result.success) {
|
|
5873
|
-
fees.exchangeFee = padValueBy(exchangeHop.result.fee, FEE_PADDING_PERCENTAGE
|
|
5879
|
+
fees.exchangeFee = padValueBy(exchangeHop.result.fee, FEE_PADDING_PERCENTAGE);
|
|
5874
5880
|
}
|
|
5875
5881
|
}
|
|
5876
5882
|
} else {
|
|
@@ -5887,7 +5893,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
5887
5893
|
throw new DryRunFailedError("Hop before exchange failed: ".concat(hopBeforeExchange.result.failureReason || 'Unknown reason'));
|
|
5888
5894
|
}
|
|
5889
5895
|
if (hopBeforeExchange.result.success) {
|
|
5890
|
-
fees.originReserveFee = padValueBy(hopBeforeExchange.result.fee, FEE_PADDING_PERCENTAGE
|
|
5896
|
+
fees.originReserveFee = padValueBy(hopBeforeExchange.result.fee, FEE_PADDING_PERCENTAGE);
|
|
5891
5897
|
}
|
|
5892
5898
|
} else if (!destChain && hops.length > 0) {
|
|
5893
5899
|
// Special case: when destChain is undefined and we have hops,
|
|
@@ -5897,7 +5903,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
5897
5903
|
throw new DryRunFailedError("Origin reserve hop failed: ".concat(lastHop.result.failureReason || 'Unknown reason'));
|
|
5898
5904
|
}
|
|
5899
5905
|
if (lastHop.result.success) {
|
|
5900
|
-
fees.originReserveFee = padValueBy(lastHop.result.fee, FEE_PADDING_PERCENTAGE
|
|
5906
|
+
fees.originReserveFee = padValueBy(lastHop.result.fee, FEE_PADDING_PERCENTAGE);
|
|
5901
5907
|
}
|
|
5902
5908
|
}
|
|
5903
5909
|
// Handle destination reserve fee (hop after exchange)
|
|
@@ -5908,7 +5914,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
5908
5914
|
throw new DryRunFailedError("Hop after exchange failed: ".concat(hopAfterExchange.result.failureReason || 'Unknown reason'));
|
|
5909
5915
|
}
|
|
5910
5916
|
if (hopAfterExchange.result.success) {
|
|
5911
|
-
fees.destReserveFee = padValueBy(hopAfterExchange.result.fee, FEE_PADDING_PERCENTAGE
|
|
5917
|
+
fees.destReserveFee = padValueBy(hopAfterExchange.result.fee, FEE_PADDING_PERCENTAGE);
|
|
5912
5918
|
}
|
|
5913
5919
|
}
|
|
5914
5920
|
return fees;
|
|
@@ -6094,7 +6100,7 @@ var handleToAhTeleport = /*#__PURE__*/function () {
|
|
|
6094
6100
|
// Enter dummy fee values just to get the dry run to pass
|
|
6095
6101
|
asset.amount, asset.amount / 2n);
|
|
6096
6102
|
_context.n = 4;
|
|
6097
|
-
return
|
|
6103
|
+
return getXcmFeeOnce({
|
|
6098
6104
|
api: api,
|
|
6099
6105
|
tx: dummyTx,
|
|
6100
6106
|
origin: origin,
|
|
@@ -6697,7 +6703,7 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6697
6703
|
}
|
|
6698
6704
|
throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
|
|
6699
6705
|
case 2:
|
|
6700
|
-
return _context2.a(2,
|
|
6706
|
+
return _context2.a(2, createTypeThenAutoReserve(getRelayChainOf(destChain), _objectSpread2(_objectSpread2({}, options), {}, {
|
|
6701
6707
|
beneficiaryLocation: createBeneficiaryLocation({
|
|
6702
6708
|
api: api,
|
|
6703
6709
|
address: address,
|
|
@@ -7011,6 +7017,11 @@ var Acala = /*#__PURE__*/function (_Parachain) {
|
|
|
7011
7017
|
var currencySelection = this.getCurrencySelection(asset);
|
|
7012
7018
|
return transferXTokens(input, currencySelection);
|
|
7013
7019
|
}
|
|
7020
|
+
}, {
|
|
7021
|
+
key: "transferRelayToPara",
|
|
7022
|
+
value: function transferRelayToPara() {
|
|
7023
|
+
throw new ChainNotSupportedError();
|
|
7024
|
+
}
|
|
7014
7025
|
}, {
|
|
7015
7026
|
key: "transferLocalNativeAsset",
|
|
7016
7027
|
value: function () {
|
|
@@ -7703,6 +7714,11 @@ var Astar = /*#__PURE__*/function (_Parachain) {
|
|
|
7703
7714
|
var assetInfo = _ref.assetInfo;
|
|
7704
7715
|
return assetInfo.symbol !== this.getNativeAssetSymbol();
|
|
7705
7716
|
}
|
|
7717
|
+
}, {
|
|
7718
|
+
key: "transferRelayToPara",
|
|
7719
|
+
value: function transferRelayToPara() {
|
|
7720
|
+
throw new ChainNotSupportedError();
|
|
7721
|
+
}
|
|
7706
7722
|
}, {
|
|
7707
7723
|
key: "transferLocalNonNativeAsset",
|
|
7708
7724
|
value: function transferLocalNonNativeAsset(options) {
|
|
@@ -9760,6 +9776,11 @@ var Shiden = /*#__PURE__*/function (_Parachain) {
|
|
|
9760
9776
|
var assetInfo = _ref.assetInfo;
|
|
9761
9777
|
return assetInfo.symbol !== this.getNativeAssetSymbol();
|
|
9762
9778
|
}
|
|
9779
|
+
}, {
|
|
9780
|
+
key: "transferRelayToPara",
|
|
9781
|
+
value: function transferRelayToPara() {
|
|
9782
|
+
throw new ChainNotSupportedError();
|
|
9783
|
+
}
|
|
9763
9784
|
}, {
|
|
9764
9785
|
key: "transferLocalNonNativeAsset",
|
|
9765
9786
|
value: function transferLocalNonNativeAsset(options) {
|
|
@@ -10576,7 +10597,7 @@ var wrapTxBypass = /*#__PURE__*/function () {
|
|
|
10576
10597
|
api: api,
|
|
10577
10598
|
chain: chain,
|
|
10578
10599
|
address: address,
|
|
10579
|
-
currency: getCurrencySelection(asset)
|
|
10600
|
+
currency: getCurrencySelection(chain, asset)
|
|
10580
10601
|
});
|
|
10581
10602
|
case 9:
|
|
10582
10603
|
balance = _context.v;
|
|
@@ -11060,13 +11081,13 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
|
11060
11081
|
}
|
|
11061
11082
|
return {};
|
|
11062
11083
|
};
|
|
11063
|
-
var
|
|
11084
|
+
var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
11064
11085
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
11065
|
-
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, useRootOrigin, asset, amount, _yield$getOriginXcmFe, originFeeRaw,
|
|
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;
|
|
11066
11087
|
return _regenerator().w(function (_context2) {
|
|
11067
11088
|
while (1) switch (_context2.p = _context2.n) {
|
|
11068
11089
|
case 0:
|
|
11069
|
-
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;
|
|
11070
11091
|
asset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
11071
11092
|
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
11072
11093
|
_context2.n = 1;
|
|
@@ -11084,7 +11105,6 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11084
11105
|
case 1:
|
|
11085
11106
|
_yield$getOriginXcmFe = _context2.v;
|
|
11086
11107
|
originFeeRaw = _yield$getOriginXcmFe.fee;
|
|
11087
|
-
originCurrency = _yield$getOriginXcmFe.currency;
|
|
11088
11108
|
originAsset = _yield$getOriginXcmFe.asset;
|
|
11089
11109
|
originFeeType = _yield$getOriginXcmFe.feeType;
|
|
11090
11110
|
originDryRunError = _yield$getOriginXcmFe.dryRunError;
|
|
@@ -11137,7 +11157,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11137
11157
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
11138
11158
|
senderAddress: senderAddress,
|
|
11139
11159
|
disableFallback: disableFallback,
|
|
11140
|
-
swapConfig: swapConfig
|
|
11160
|
+
swapConfig: swapConfig,
|
|
11161
|
+
skipReverseFeeCalculation: skipReverseFeeCalculation
|
|
11141
11162
|
});
|
|
11142
11163
|
case 7:
|
|
11143
11164
|
destFeeRes = _context2.v;
|
|
@@ -11148,7 +11169,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11148
11169
|
feeType: originFeeType
|
|
11149
11170
|
}), {}, {
|
|
11150
11171
|
sufficient: sufficientOriginFee,
|
|
11151
|
-
currency:
|
|
11172
|
+
currency: originAsset.symbol,
|
|
11152
11173
|
asset: originAsset
|
|
11153
11174
|
}, originDryRunError && {
|
|
11154
11175
|
dryRunError: originDryRunError
|
|
@@ -11221,7 +11242,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11221
11242
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
11222
11243
|
disableFallback: disableFallback,
|
|
11223
11244
|
hasPassedExchange: hasPassedExchange,
|
|
11224
|
-
swapConfig: swapConfig
|
|
11245
|
+
swapConfig: swapConfig,
|
|
11246
|
+
skipReverseFeeCalculation: skipReverseFeeCalculation
|
|
11225
11247
|
});
|
|
11226
11248
|
case 1:
|
|
11227
11249
|
hopResult = _context.v;
|
|
@@ -11299,7 +11321,8 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11299
11321
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
11300
11322
|
senderAddress: senderAddress,
|
|
11301
11323
|
disableFallback: disableFallback,
|
|
11302
|
-
swapConfig: swapConfig
|
|
11324
|
+
swapConfig: swapConfig,
|
|
11325
|
+
skipReverseFeeCalculation: skipReverseFeeCalculation
|
|
11303
11326
|
});
|
|
11304
11327
|
case 14:
|
|
11305
11328
|
destFallback = _context2.v;
|
|
@@ -11371,7 +11394,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11371
11394
|
}), sufficientOriginFee !== undefined && {
|
|
11372
11395
|
sufficient: sufficientOriginFee
|
|
11373
11396
|
}), {}, {
|
|
11374
|
-
currency:
|
|
11397
|
+
currency: originAsset.symbol,
|
|
11375
11398
|
asset: originAsset
|
|
11376
11399
|
}, originDryRunError && {
|
|
11377
11400
|
dryRunError: originDryRunError
|
|
@@ -11416,32 +11439,32 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11416
11439
|
}
|
|
11417
11440
|
}, _callee2, null, [[5,, 8, 10]]);
|
|
11418
11441
|
}));
|
|
11419
|
-
return function
|
|
11442
|
+
return function getXcmFeeOnce(_x) {
|
|
11420
11443
|
return _ref2.apply(this, arguments);
|
|
11421
11444
|
};
|
|
11422
11445
|
}();
|
|
11423
11446
|
|
|
11424
|
-
var
|
|
11447
|
+
var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
11425
11448
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
11426
|
-
var buildTx,
|
|
11449
|
+
var buildTx, _real$assetHub, _real$bridgeHub, tx, real, forced, _forced, _t;
|
|
11427
11450
|
return _regenerator().w(function (_context) {
|
|
11428
11451
|
while (1) switch (_context.p = _context.n) {
|
|
11429
11452
|
case 0:
|
|
11430
|
-
buildTx = options.buildTx
|
|
11453
|
+
buildTx = options.buildTx;
|
|
11431
11454
|
_context.p = 1;
|
|
11432
11455
|
_context.n = 2;
|
|
11433
11456
|
return buildTx();
|
|
11434
11457
|
case 2:
|
|
11435
11458
|
tx = _context.v;
|
|
11436
11459
|
_context.n = 3;
|
|
11437
|
-
return
|
|
11460
|
+
return getXcmFeeOnce(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
11438
11461
|
tx: tx,
|
|
11439
11462
|
useRootOrigin: false
|
|
11440
11463
|
}));
|
|
11441
11464
|
case 3:
|
|
11442
11465
|
real = _context.v;
|
|
11443
11466
|
_context.n = 4;
|
|
11444
|
-
return getBypassResultWithRetries(options,
|
|
11467
|
+
return getBypassResultWithRetries(options, getXcmFeeOnce, tx);
|
|
11445
11468
|
case 4:
|
|
11446
11469
|
forced = _context.v;
|
|
11447
11470
|
return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, forced), {}, {
|
|
@@ -11479,7 +11502,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
11479
11502
|
throw _t;
|
|
11480
11503
|
case 6:
|
|
11481
11504
|
_context.n = 7;
|
|
11482
|
-
return getBypassResultWithRetries(options,
|
|
11505
|
+
return getBypassResultWithRetries(options, getXcmFeeOnce);
|
|
11483
11506
|
case 7:
|
|
11484
11507
|
_forced = _context.v;
|
|
11485
11508
|
return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, _forced), {}, {
|
|
@@ -11506,21 +11529,40 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
11506
11529
|
});
|
|
11507
11530
|
})
|
|
11508
11531
|
}));
|
|
11509
|
-
case 8:
|
|
11510
|
-
_context.p = 8;
|
|
11511
|
-
_context.n = 9;
|
|
11512
|
-
return api.disconnect();
|
|
11513
|
-
case 9:
|
|
11514
|
-
return _context.f(8);
|
|
11515
|
-
case 10:
|
|
11516
|
-
return _context.a(2);
|
|
11517
11532
|
}
|
|
11518
|
-
}, _callee, null, [[1, 5
|
|
11533
|
+
}, _callee, null, [[1, 5]]);
|
|
11519
11534
|
}));
|
|
11520
|
-
return function
|
|
11535
|
+
return function getXcmFeeInternal(_x) {
|
|
11521
11536
|
return _ref.apply(this, arguments);
|
|
11522
11537
|
};
|
|
11523
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
|
+
}();
|
|
11524
11566
|
|
|
11525
11567
|
var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
|
|
11526
11568
|
var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
|
|
@@ -11945,7 +11987,7 @@ var buildHopInfo = /*#__PURE__*/function () {
|
|
|
11945
11987
|
|
|
11946
11988
|
var getTransferInfo = /*#__PURE__*/function () {
|
|
11947
11989
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
11948
|
-
var api, buildTx, origin, destination, senderAddress, ahAddress, address, currency, feeAsset, resolvedFeeAsset, originAsset, amount, originBalanceFee, originBalance, edOrigin, _yield$
|
|
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;
|
|
11949
11991
|
return _regenerator().w(function (_context2) {
|
|
11950
11992
|
while (1) switch (_context2.p = _context2.n) {
|
|
11951
11993
|
case 0:
|
|
@@ -12013,15 +12055,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
12013
12055
|
disableFallback: false
|
|
12014
12056
|
});
|
|
12015
12057
|
case 9:
|
|
12016
|
-
_yield$
|
|
12017
|
-
_yield$
|
|
12018
|
-
originFee = _yield$
|
|
12019
|
-
originFeeCurrency = _yield$
|
|
12020
|
-
originFeeAsset = _yield$
|
|
12021
|
-
assetHubFeeResult = _yield$
|
|
12022
|
-
bridgeHubFeeResult = _yield$
|
|
12023
|
-
destFeeDetail = _yield$
|
|
12024
|
-
hops = _yield$
|
|
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;
|
|
12025
12067
|
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, originAsset);
|
|
12026
12068
|
originBalanceAfter = originBalance - amount;
|
|
12027
12069
|
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
|
|
@@ -12391,15 +12433,20 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
|
|
|
12391
12433
|
reserve = _ref.reserve,
|
|
12392
12434
|
dest = _ref.dest,
|
|
12393
12435
|
assetInfo = _ref.assetInfo,
|
|
12394
|
-
|
|
12436
|
+
_ref$options = _ref.options,
|
|
12437
|
+
version = _ref$options.version,
|
|
12438
|
+
pallet = _ref$options.pallet,
|
|
12439
|
+
method = _ref$options.method;
|
|
12395
12440
|
var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
|
|
12396
12441
|
var finalDest = origin.chain === reserve.chain ? dest.chain : reserve.chain;
|
|
12397
12442
|
var destLocation = createDestination(version, origin.chain, finalDest, getParaId(finalDest));
|
|
12398
12443
|
var reserveType = origin.chain === reserve.chain ? 'LocalReserve' : 'DestinationReserve';
|
|
12399
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';
|
|
12400
12447
|
return {
|
|
12401
|
-
module:
|
|
12402
|
-
method:
|
|
12448
|
+
module: module,
|
|
12449
|
+
method: methodName,
|
|
12403
12450
|
parameters: {
|
|
12404
12451
|
dest: addXcmVersionHeader(destLocation, version),
|
|
12405
12452
|
assets: addXcmVersionHeader(assets, version),
|
|
@@ -12412,130 +12459,76 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
|
|
|
12412
12459
|
};
|
|
12413
12460
|
};
|
|
12414
12461
|
|
|
12415
|
-
var
|
|
12416
|
-
var
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
};
|
|
12426
|
-
var computeInstructionFee = /*#__PURE__*/function () {
|
|
12427
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2, version, xcm, context) {
|
|
12428
|
-
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;
|
|
12429
12472
|
return _regenerator().w(function (_context) {
|
|
12430
12473
|
while (1) switch (_context.n) {
|
|
12431
12474
|
case 0:
|
|
12432
|
-
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
location: DOT_LOCATION
|
|
12438
|
-
}, true);
|
|
12439
|
-
case 1:
|
|
12440
|
-
return _context.a(2, _t(_context.v, padding));
|
|
12441
|
-
}
|
|
12442
|
-
}, _callee);
|
|
12443
|
-
}));
|
|
12444
|
-
return function computeInstructionFee(_x, _x2, _x3, _x4) {
|
|
12445
|
-
return _ref3.apply(this, arguments);
|
|
12446
|
-
};
|
|
12447
|
-
}();
|
|
12448
|
-
var computeAllFees = /*#__PURE__*/function () {
|
|
12449
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, customXcm, isDotAsset, refundInstruction) {
|
|
12450
|
-
var reserve, dest, version, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0;
|
|
12451
|
-
return _regenerator().w(function (_context2) {
|
|
12452
|
-
while (1) switch (_context2.n) {
|
|
12453
|
-
case 0:
|
|
12454
|
-
reserve = context.reserve, dest = context.dest, version = context.options.version;
|
|
12455
|
-
if (!customXcm.some(function (x) {
|
|
12456
|
-
return 'DepositReserveAsset' in x || 'InitiateTeleport' in x;
|
|
12457
|
-
})) {
|
|
12458
|
-
_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;
|
|
12459
12480
|
break;
|
|
12460
12481
|
}
|
|
12461
|
-
|
|
12462
|
-
return computeInstructionFee(reserve, version, customXcm, context);
|
|
12482
|
+
return _context.a(2, null);
|
|
12463
12483
|
case 1:
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
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
|
+
});
|
|
12471
12497
|
case 2:
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
|
|
12479
|
-
_context2.n = 5;
|
|
12480
|
-
return computeInstructionFee(assets.hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, function () {
|
|
12481
|
-
var instr = customXcm.find(function (j) {
|
|
12482
|
-
return 'DepositReserveAsset' in j || 'InitiateTeleport' in j;
|
|
12483
|
-
});
|
|
12484
|
-
return instr ? 'DepositReserveAsset' in instr ? instr.DepositReserveAsset.xcm : instr.InitiateTeleport.xcm : undefined;
|
|
12485
|
-
}(), context);
|
|
12486
|
-
case 5:
|
|
12487
|
-
_t6 = _context2.v;
|
|
12488
|
-
_t2 = {
|
|
12489
|
-
reserveFee: _t3,
|
|
12490
|
-
refundFee: _t5,
|
|
12491
|
-
destFee: _t6
|
|
12492
|
-
};
|
|
12493
|
-
_context2.n = 13;
|
|
12494
|
-
break;
|
|
12495
|
-
case 6:
|
|
12496
|
-
if (isDotAsset) {
|
|
12497
|
-
_context2.n = 8;
|
|
12498
|
-
break;
|
|
12499
|
-
}
|
|
12500
|
-
_context2.n = 7;
|
|
12501
|
-
return computeInstructionFee(assets.hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm, context);
|
|
12502
|
-
case 7:
|
|
12503
|
-
_t7 = _context2.v;
|
|
12504
|
-
_context2.n = 9;
|
|
12505
|
-
break;
|
|
12506
|
-
case 8:
|
|
12507
|
-
_t7 = 0n;
|
|
12508
|
-
case 9:
|
|
12509
|
-
_t8 = _t7;
|
|
12510
|
-
if (isDotAsset) {
|
|
12511
|
-
_context2.n = 11;
|
|
12512
|
-
break;
|
|
12513
|
-
}
|
|
12514
|
-
_context2.n = 10;
|
|
12515
|
-
return computeInstructionFee(assets.hasXcmPaymentApiSupport(reserve.chain) ? reserve : dest, version, [refundInstruction], context);
|
|
12516
|
-
case 10:
|
|
12517
|
-
_t9 = _context2.v;
|
|
12518
|
-
_context2.n = 12;
|
|
12519
|
-
break;
|
|
12520
|
-
case 11:
|
|
12521
|
-
_t9 = 0n;
|
|
12522
|
-
case 12:
|
|
12523
|
-
_t0 = _t9;
|
|
12524
|
-
_t2 = {
|
|
12525
|
-
reserveFee: 0n,
|
|
12526
|
-
destFee: _t8,
|
|
12527
|
-
refundFee: _t0
|
|
12528
|
-
};
|
|
12529
|
-
case 13:
|
|
12530
|
-
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
|
+
});
|
|
12531
12505
|
}
|
|
12532
|
-
},
|
|
12506
|
+
}, _callee);
|
|
12533
12507
|
}));
|
|
12534
|
-
return function computeAllFees(
|
|
12535
|
-
return
|
|
12508
|
+
return function computeAllFees(_x, _x2) {
|
|
12509
|
+
return _ref.apply(this, arguments);
|
|
12536
12510
|
};
|
|
12537
12511
|
}();
|
|
12538
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
|
+
}];
|
|
12539
12532
|
var getSubBridgeReserve = function getSubBridgeReserve(chain, destination, location) {
|
|
12540
12533
|
if (sdkCommon.deepEqual(location, RELAY_LOCATION)) return chain;
|
|
12541
12534
|
return destination;
|
|
@@ -12551,29 +12544,27 @@ var resolveReserveChain = function resolveReserveChain(chain, destination, asset
|
|
|
12551
12544
|
};
|
|
12552
12545
|
var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
12553
12546
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
|
|
12554
|
-
var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, destApi, reserveApi;
|
|
12547
|
+
var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, isRelayAsset, destApi, reserveApi;
|
|
12555
12548
|
return _regenerator().w(function (_context) {
|
|
12556
12549
|
while (1) switch (_context.n) {
|
|
12557
12550
|
case 0:
|
|
12558
12551
|
api = options.api, destination = options.destination, assetInfo = options.assetInfo;
|
|
12559
12552
|
assertHasLocation(assetInfo);
|
|
12560
|
-
|
|
12561
|
-
_context.n = 1;
|
|
12562
|
-
break;
|
|
12563
|
-
}
|
|
12564
|
-
throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
|
|
12565
|
-
case 1:
|
|
12553
|
+
assertToIsString(destination);
|
|
12566
12554
|
destinationChain = destination;
|
|
12567
12555
|
isSubBridge = sdkCommon.isSubstrateBridge(chain, destinationChain);
|
|
12568
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
|
+
});
|
|
12569
12560
|
destApi = api.clone();
|
|
12570
|
-
_context.n =
|
|
12561
|
+
_context.n = 1;
|
|
12571
12562
|
return destApi.init(destinationChain);
|
|
12572
|
-
case
|
|
12563
|
+
case 1:
|
|
12573
12564
|
reserveApi = reserveChain === chain ? api : reserveChain === destinationChain ? destApi : api.clone();
|
|
12574
|
-
_context.n =
|
|
12565
|
+
_context.n = 2;
|
|
12575
12566
|
return reserveApi.init(reserveChain);
|
|
12576
|
-
case
|
|
12567
|
+
case 2:
|
|
12577
12568
|
return _context.a(2, {
|
|
12578
12569
|
origin: {
|
|
12579
12570
|
api: api,
|
|
@@ -12588,6 +12579,7 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
|
12588
12579
|
chain: reserveChain
|
|
12589
12580
|
},
|
|
12590
12581
|
isSubBridge: isSubBridge,
|
|
12582
|
+
isRelayAsset: isRelayAsset,
|
|
12591
12583
|
assetInfo: assetInfo,
|
|
12592
12584
|
options: options
|
|
12593
12585
|
});
|
|
@@ -12599,26 +12591,37 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
|
12599
12591
|
};
|
|
12600
12592
|
}();
|
|
12601
12593
|
|
|
12602
|
-
var
|
|
12603
|
-
var
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
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) {
|
|
12609
12607
|
var fees = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
12610
|
-
|
|
12611
|
-
refundFee: 0n,
|
|
12608
|
+
hopFees: 0n,
|
|
12612
12609
|
destFee: 0n
|
|
12613
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;
|
|
12614
12618
|
var destination = options.destination,
|
|
12615
12619
|
version = options.version,
|
|
12616
12620
|
address = options.address,
|
|
12617
12621
|
paraIdTo = options.paraIdTo;
|
|
12618
|
-
var
|
|
12619
|
-
refundFee = fees.refundFee,
|
|
12622
|
+
var hopFees = fees.hopFees,
|
|
12620
12623
|
destFee = fees.destFee;
|
|
12621
|
-
var feeAssetLocation = !
|
|
12624
|
+
var feeAssetLocation = !isRelayAsset ? RELAY_LOCATION : assetInfo.location;
|
|
12622
12625
|
var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation, origin.chain);
|
|
12623
12626
|
var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location, origin.chain));
|
|
12624
12627
|
var depositInstruction = {
|
|
@@ -12641,10 +12644,10 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset, assetCount, isF
|
|
|
12641
12644
|
}
|
|
12642
12645
|
};
|
|
12643
12646
|
var assetsFilter = [];
|
|
12644
|
-
if (!
|
|
12647
|
+
if (!isRelayAsset) assetsFilter.push(createAsset(version, hopFees + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
|
|
12645
12648
|
assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
|
|
12646
12649
|
if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
|
|
12647
|
-
var buyExecutionAmount =
|
|
12650
|
+
var buyExecutionAmount = resolveBuyExecutionAmount(context, isForFeeCalc, fees, systemAssetAmount);
|
|
12648
12651
|
if (buyExecutionAmount < 0n && !isForFeeCalc) throw new AmountTooLowError();
|
|
12649
12652
|
var filter = isForFeeCalc ? {
|
|
12650
12653
|
Wild: 'All'
|
|
@@ -12709,63 +12712,166 @@ var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, vers
|
|
|
12709
12712
|
assets.push(createAsset(version, asset.amount, sdkCommon.isRelayChain(chain) ? localizeLocation(chain, asset.location) : asset.location));
|
|
12710
12713
|
return assets;
|
|
12711
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
|
+
};
|
|
12712
12747
|
/**
|
|
12713
12748
|
* Creates a type and then call for transferring assets using XCM. Works only for DOT and snowbridge assets so far.
|
|
12714
12749
|
*/
|
|
12715
12750
|
var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
12716
|
-
var
|
|
12717
|
-
var
|
|
12751
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
|
|
12752
|
+
var context, origin, assetInfo, fees;
|
|
12718
12753
|
return _regenerator().w(function (_context) {
|
|
12719
12754
|
while (1) switch (_context.n) {
|
|
12720
12755
|
case 0:
|
|
12721
|
-
api = options.api, senderAddress = options.senderAddress, version = options.version;
|
|
12722
12756
|
_context.n = 1;
|
|
12723
12757
|
return createTypeAndThenCallContext(chain, options, overrideReserve);
|
|
12724
12758
|
case 1:
|
|
12725
12759
|
context = _context.v;
|
|
12726
|
-
|
|
12727
|
-
LOCATIONS = [RELAY_LOCATION, {
|
|
12728
|
-
parents: 2,
|
|
12729
|
-
interior: {
|
|
12730
|
-
X1: [{
|
|
12731
|
-
GlobalConsensus: {
|
|
12732
|
-
Kusama: null
|
|
12733
|
-
}
|
|
12734
|
-
}]
|
|
12735
|
-
}
|
|
12736
|
-
}, {
|
|
12737
|
-
parents: 2,
|
|
12738
|
-
interior: {
|
|
12739
|
-
X1: [{
|
|
12740
|
-
GlobalConsensus: {
|
|
12741
|
-
Polkadot: null
|
|
12742
|
-
}
|
|
12743
|
-
}]
|
|
12744
|
-
}
|
|
12745
|
-
}];
|
|
12746
|
-
isRelayAsset = LOCATIONS.some(function (loc) {
|
|
12747
|
-
return sdkCommon.deepEqual(assetInfo.location, loc);
|
|
12748
|
-
});
|
|
12749
|
-
assetCount = isRelayAsset ? 1 : 2;
|
|
12750
|
-
customXcm = createCustomXcm(context, isRelayAsset, assetCount, true);
|
|
12751
|
-
refundInstruction = senderAddress ? createRefundInstruction(api, senderAddress, version, assetCount) : null;
|
|
12760
|
+
origin = context.origin, assetInfo = context.assetInfo;
|
|
12752
12761
|
_context.n = 2;
|
|
12753
|
-
return computeAllFees(context,
|
|
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
|
+
});
|
|
12754
12770
|
case 2:
|
|
12755
12771
|
fees = _context.v;
|
|
12756
|
-
|
|
12757
|
-
if (refundInstruction && !isSubBridge) finalCustomXcm.push(refundInstruction);
|
|
12758
|
-
finalCustomXcm.push.apply(finalCustomXcm, _toConsumableArray(createCustomXcm(context, isRelayAsset, assetCount, false, fees)));
|
|
12759
|
-
totalFee = fees.reserveFee + fees.destFee + fees.refundFee;
|
|
12760
|
-
assets = buildAssets(chain, assetInfo, totalFee, isRelayAsset, version);
|
|
12761
|
-
return _context.a(2, buildTypeAndThenCall(context, isRelayAsset, finalCustomXcm, assets));
|
|
12772
|
+
return _context.a(2, constructTypeAndThenCall(context, fees));
|
|
12762
12773
|
}
|
|
12763
12774
|
}, _callee);
|
|
12764
12775
|
}));
|
|
12765
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) {
|
|
12766
12819
|
return _ref.apply(this, arguments);
|
|
12767
12820
|
};
|
|
12768
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
|
+
}();
|
|
12769
12875
|
|
|
12770
12876
|
var calculateTotalXcmFee = function calculateTotalXcmFee(feeResult) {
|
|
12771
12877
|
var _feeResult$assetHub;
|
|
@@ -12826,7 +12932,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
12826
12932
|
case 5:
|
|
12827
12933
|
balance = _context.v;
|
|
12828
12934
|
_context.n = 6;
|
|
12829
|
-
return
|
|
12935
|
+
return getXcmFeeInternal({
|
|
12830
12936
|
api: api,
|
|
12831
12937
|
buildTx: buildTx,
|
|
12832
12938
|
origin: origin,
|
|
@@ -13570,7 +13676,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
13570
13676
|
var _options$disableFallb;
|
|
13571
13677
|
var disableFallback, _yield$this$prepareNo2, normalizedOptions, buildTx, api, from, to, senderAddress, address, currency, feeAsset;
|
|
13572
13678
|
return _regenerator().w(function (_context8) {
|
|
13573
|
-
while (1) switch (_context8.
|
|
13679
|
+
while (1) switch (_context8.n) {
|
|
13574
13680
|
case 0:
|
|
13575
13681
|
disableFallback = (_options$disableFallb = options === null || options === void 0 ? void 0 : options.disableFallback) !== null && _options$disableFallb !== void 0 ? _options$disableFallb : false;
|
|
13576
13682
|
_context8.n = 1;
|
|
@@ -13582,9 +13688,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
13582
13688
|
api = normalizedOptions.api, from = normalizedOptions.from, to = normalizedOptions.to, senderAddress = normalizedOptions.senderAddress, address = normalizedOptions.address, currency = normalizedOptions.currency, feeAsset = normalizedOptions.feeAsset;
|
|
13583
13689
|
assertToIsString(to);
|
|
13584
13690
|
assertAddressIsString(address);
|
|
13585
|
-
_context8.
|
|
13586
|
-
_context8.n = 3;
|
|
13587
|
-
return getXcmFee({
|
|
13691
|
+
return _context8.a(2, getXcmFee({
|
|
13588
13692
|
api: api,
|
|
13589
13693
|
buildTx: buildTx,
|
|
13590
13694
|
origin: from,
|
|
@@ -13594,19 +13698,9 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
13594
13698
|
currency: currency,
|
|
13595
13699
|
feeAsset: feeAsset,
|
|
13596
13700
|
disableFallback: disableFallback
|
|
13597
|
-
});
|
|
13598
|
-
case 3:
|
|
13599
|
-
return _context8.a(2, _context8.v);
|
|
13600
|
-
case 4:
|
|
13601
|
-
_context8.p = 4;
|
|
13602
|
-
_context8.n = 5;
|
|
13603
|
-
return this.api.disconnect();
|
|
13604
|
-
case 5:
|
|
13605
|
-
return _context8.f(4);
|
|
13606
|
-
case 6:
|
|
13607
|
-
return _context8.a(2);
|
|
13701
|
+
}));
|
|
13608
13702
|
}
|
|
13609
|
-
}, _callee8, this
|
|
13703
|
+
}, _callee8, this);
|
|
13610
13704
|
}));
|
|
13611
13705
|
function getXcmFee$1(_x7) {
|
|
13612
13706
|
return _getXcmFee2.apply(this, arguments);
|
|
@@ -14058,6 +14152,7 @@ exports.claimAssets = claimAssets;
|
|
|
14058
14152
|
exports.computeFeeFromDryRun = computeFeeFromDryRun;
|
|
14059
14153
|
exports.computeFeeFromDryRunPjs = computeFeeFromDryRunPjs;
|
|
14060
14154
|
exports.computeOverridenAmount = computeOverridenAmount;
|
|
14155
|
+
exports.constructTypeAndThenCall = constructTypeAndThenCall;
|
|
14061
14156
|
exports.convertSs58 = convertSs58;
|
|
14062
14157
|
exports.createAsset = createAsset;
|
|
14063
14158
|
exports.createAssetsFilter = createAssetsFilter;
|
|
@@ -14070,6 +14165,7 @@ exports.createExecuteCall = createExecuteCall;
|
|
|
14070
14165
|
exports.createExecuteExchangeXcm = createExecuteExchangeXcm;
|
|
14071
14166
|
exports.createTx = createTx;
|
|
14072
14167
|
exports.createTypeAndThenCall = createTypeAndThenCall;
|
|
14168
|
+
exports.createTypeThenAutoReserve = createTypeThenAutoReserve;
|
|
14073
14169
|
exports.createVersionedAssets = createVersionedAssets;
|
|
14074
14170
|
exports.createX1Payload = createX1Payload;
|
|
14075
14171
|
exports.deriveAccountId = deriveAccountId;
|
|
@@ -14110,6 +14206,7 @@ exports.getTransferableAmountInternal = getTransferableAmountInternal;
|
|
|
14110
14206
|
exports.getXcmFee = getXcmFee;
|
|
14111
14207
|
exports.getXcmFeeEstimate = getXcmFeeEstimate;
|
|
14112
14208
|
exports.getXcmFeeInternal = getXcmFeeInternal;
|
|
14209
|
+
exports.getXcmFeeOnce = getXcmFeeOnce;
|
|
14113
14210
|
exports.handleExecuteTransfer = handleExecuteTransfer;
|
|
14114
14211
|
exports.handleSwapExecuteTransfer = handleSwapExecuteTransfer;
|
|
14115
14212
|
exports.handleToAhTeleport = handleToAhTeleport;
|