@paraspell/sdk-core 10.10.1 → 10.10.2
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 +81 -28
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +82 -29
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -4896,11 +4896,11 @@ var getFailureInfo$1 = function getFailureInfo(results, hops) {
|
|
|
4896
4896
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
4897
4897
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4898
4898
|
var _intermediateFees$bri, _intermediateFees$ass, _processedBridgeHubDa, _destinationDryRun;
|
|
4899
|
-
var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, hops, destinationDryRun, nextChain, hopApi, hopDryRun, hopCurrency, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, _getFailureInfo, failureReason, failureChain;
|
|
4899
|
+
var origin, destination, currency, api, tx, senderAddress, feeAsset, swapConfig, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentAsset, hasPassedExchange, currentOrigin, forwardedXcms, nextParaId, intermediateFees, hops, destinationDryRun, nextChain, hopApi, hopDryRun, hopCurrency, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, _getFailureInfo, failureReason, failureChain;
|
|
4900
4900
|
return _regenerator().w(function (_context) {
|
|
4901
4901
|
while (1) switch (_context.n) {
|
|
4902
4902
|
case 0:
|
|
4903
|
-
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
|
|
4903
|
+
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset, swapConfig = options.swapConfig;
|
|
4904
4904
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4905
4905
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
4906
4906
|
_context.n = 1;
|
|
@@ -4926,6 +4926,8 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4926
4926
|
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
4927
4927
|
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
4928
4928
|
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
4929
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? assets.findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
4930
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
4929
4931
|
currentOrigin = origin;
|
|
4930
4932
|
forwardedXcms = initialForwardedXcms;
|
|
4931
4933
|
nextParaId = initialDestParaId;
|
|
@@ -4966,14 +4968,20 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4966
4968
|
xcm: forwardedXcms[1][0],
|
|
4967
4969
|
node: nextChain,
|
|
4968
4970
|
origin: currentOrigin,
|
|
4969
|
-
asset:
|
|
4971
|
+
asset: currentAsset,
|
|
4970
4972
|
feeAsset: resolvedFeeAsset,
|
|
4971
4973
|
originFee: originDryRun.fee,
|
|
4972
4974
|
amount: BigInt(currency.amount)
|
|
4973
4975
|
});
|
|
4974
4976
|
case 8:
|
|
4975
4977
|
hopDryRun = _context.v;
|
|
4976
|
-
hopCurrency =
|
|
4978
|
+
hopCurrency = void 0;
|
|
4979
|
+
if (hasPassedExchange && swapConfig && nextChain !== swapConfig.exchangeChain) {
|
|
4980
|
+
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo).symbol;
|
|
4981
|
+
} else {
|
|
4982
|
+
hopCurrency = asset.symbol;
|
|
4983
|
+
}
|
|
4984
|
+
// Add to hops array (only if not the destination)
|
|
4977
4985
|
if (nextChain !== destination) {
|
|
4978
4986
|
hops.push({
|
|
4979
4987
|
chain: nextChain,
|
|
@@ -4996,6 +5004,10 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4996
5004
|
}
|
|
4997
5005
|
return _context.a(3, 13);
|
|
4998
5006
|
case 9:
|
|
5007
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5008
|
+
hasPassedExchange = true;
|
|
5009
|
+
currentAsset = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5010
|
+
}
|
|
4999
5011
|
newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
|
|
5000
5012
|
forwardedXcms = newXcms;
|
|
5001
5013
|
nextParaId = destParaId;
|
|
@@ -5474,12 +5486,11 @@ var getFailureInfo = function getFailureInfo(nodes, hops) {
|
|
|
5474
5486
|
};
|
|
5475
5487
|
var getXcmFee = /*#__PURE__*/function () {
|
|
5476
5488
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
5477
|
-
var
|
|
5478
|
-
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, hops, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, destinationSufficient, nextChain, hopApi, _findAssetOnDest, hopResult, hopCurrency, hopDetail, failingRecord, hopIsDestination, _destApi, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, destCurrency, result, _getFailureInfo2, failureChain, failureReason;
|
|
5489
|
+
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, hops, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, currentAsset, hasPassedExchange, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, destinationSufficient, nextChain, hopApi, hopResult, hopCurrency, hopDetail, failingRecord, hopIsDestination, _destApi, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, destCurrency, result, _getFailureInfo2, failureChain, failureReason;
|
|
5479
5490
|
return _regenerator().w(function (_context) {
|
|
5480
5491
|
while (1) switch (_context.n) {
|
|
5481
5492
|
case 0:
|
|
5482
|
-
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;
|
|
5493
|
+
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;
|
|
5483
5494
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
5484
5495
|
_context.n = 1;
|
|
5485
5496
|
return getOriginXcmFee({
|
|
@@ -5581,6 +5592,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5581
5592
|
currentOrigin = origin;
|
|
5582
5593
|
forwardedXcms = initialForwardedXcm;
|
|
5583
5594
|
nextParaId = initialDestParaId;
|
|
5595
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? assets.findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
5596
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
5584
5597
|
intermediateFees = {};
|
|
5585
5598
|
destinationFee = 0n;
|
|
5586
5599
|
destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
|
|
@@ -5612,14 +5625,25 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5612
5625
|
currency: currency,
|
|
5613
5626
|
address: address,
|
|
5614
5627
|
senderAddress: senderAddress,
|
|
5615
|
-
asset:
|
|
5628
|
+
asset: currentAsset,
|
|
5616
5629
|
feeAsset: feeAsset,
|
|
5617
5630
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
5618
5631
|
disableFallback: disableFallback
|
|
5619
5632
|
});
|
|
5620
5633
|
case 13:
|
|
5621
5634
|
hopResult = _context.v;
|
|
5622
|
-
hopCurrency =
|
|
5635
|
+
hopCurrency = void 0;
|
|
5636
|
+
if (hopResult.feeType === 'dryRun') {
|
|
5637
|
+
if (hasPassedExchange && swapConfig && nextChain !== swapConfig.exchangeChain) {
|
|
5638
|
+
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo).symbol;
|
|
5639
|
+
} else if (destination === nextChain) {
|
|
5640
|
+
hopCurrency = assets.findAssetOnDestOrThrow(origin, nextChain, currency).symbol;
|
|
5641
|
+
} else {
|
|
5642
|
+
hopCurrency = asset.symbol;
|
|
5643
|
+
}
|
|
5644
|
+
} else {
|
|
5645
|
+
hopCurrency = assets.getNativeAssetSymbol(nextChain);
|
|
5646
|
+
}
|
|
5623
5647
|
hopDetail = hopResult.dryRunError ? {
|
|
5624
5648
|
fee: hopResult.fee,
|
|
5625
5649
|
feeType: hopResult.feeType,
|
|
@@ -5698,6 +5722,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5698
5722
|
} else if (nextChain === bridgeHubNode) {
|
|
5699
5723
|
intermediateFees.bridgeHub = hopDetail;
|
|
5700
5724
|
} else ;
|
|
5725
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5726
|
+
hasPassedExchange = true;
|
|
5727
|
+
currentAsset = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5728
|
+
}
|
|
5701
5729
|
forwardedXcms = hopResult.forwardedXcms;
|
|
5702
5730
|
nextParaId = hopResult.destParaId;
|
|
5703
5731
|
currentOrigin = nextChain;
|
|
@@ -5739,7 +5767,15 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5739
5767
|
}
|
|
5740
5768
|
case 24:
|
|
5741
5769
|
intermediateFees.bridgeHub = processedBridgeHubData;
|
|
5742
|
-
|
|
5770
|
+
if (destinationFeeType === 'dryRun') {
|
|
5771
|
+
if (hasPassedExchange && swapConfig && destination !== swapConfig.exchangeChain) {
|
|
5772
|
+
destCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, destination, swapConfig.currencyTo).symbol;
|
|
5773
|
+
} else {
|
|
5774
|
+
destCurrency = assets.findAssetOnDestOrThrow(origin, destination, currency).symbol;
|
|
5775
|
+
}
|
|
5776
|
+
} else {
|
|
5777
|
+
destCurrency = assets.getNativeAssetSymbol(destination);
|
|
5778
|
+
}
|
|
5743
5779
|
result = _objectSpread2(_objectSpread2({
|
|
5744
5780
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
|
|
5745
5781
|
weight: originWeight
|
|
@@ -6758,7 +6794,8 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
6758
6794
|
feeCurrency: feeCurrency,
|
|
6759
6795
|
recipientAddress: address,
|
|
6760
6796
|
senderAddress: senderAddress,
|
|
6761
|
-
version: version
|
|
6797
|
+
version: version,
|
|
6798
|
+
paraIdTo: paraIdTo
|
|
6762
6799
|
};
|
|
6763
6800
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
6764
6801
|
fees: {
|
|
@@ -6818,7 +6855,7 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
6818
6855
|
|
|
6819
6856
|
var createExchangeInstructions = /*#__PURE__*/function () {
|
|
6820
6857
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, multiAssetFrom, multiAssetTo) {
|
|
6821
|
-
var chain, exchangeChain, assetFrom, assetTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, nativeSymbol, needsMultiHop, nativeAsset, nativeAmountOut, multiAssetNative;
|
|
6858
|
+
var chain, exchangeChain, assetFrom, assetTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, nativeSymbol, needsMultiHop, nativeAsset, shouldUseMaximal, nativeAmountOut, multiAssetNative;
|
|
6822
6859
|
return _regenerator().w(function (_context) {
|
|
6823
6860
|
while (1) switch (_context.n) {
|
|
6824
6861
|
case 0:
|
|
@@ -6829,6 +6866,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6829
6866
|
symbol: nativeSymbol
|
|
6830
6867
|
}, null);
|
|
6831
6868
|
assertHasLocation(nativeAsset);
|
|
6869
|
+
shouldUseMaximal = !chain || exchangeChain === 'Hydration' && exchangeFee === 0n;
|
|
6832
6870
|
if (needsMultiHop) {
|
|
6833
6871
|
_context.n = 1;
|
|
6834
6872
|
break;
|
|
@@ -6837,7 +6875,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6837
6875
|
ExchangeAsset: {
|
|
6838
6876
|
give: createAssetsFilter(multiAssetFrom),
|
|
6839
6877
|
want: [multiAssetTo],
|
|
6840
|
-
maximal:
|
|
6878
|
+
maximal: shouldUseMaximal
|
|
6841
6879
|
}
|
|
6842
6880
|
}]);
|
|
6843
6881
|
case 1:
|
|
@@ -6850,7 +6888,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6850
6888
|
ExchangeAsset: {
|
|
6851
6889
|
give: createAssetsFilter(multiAssetFrom),
|
|
6852
6890
|
want: [multiAssetNative],
|
|
6853
|
-
maximal:
|
|
6891
|
+
maximal: shouldUseMaximal
|
|
6854
6892
|
}
|
|
6855
6893
|
}, {
|
|
6856
6894
|
ExchangeAsset: {
|
|
@@ -7013,7 +7051,8 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
7013
7051
|
if (!dryRunResult.origin.success) {
|
|
7014
7052
|
throw new DryRunFailedError("Origin dry run failed: ".concat(dryRunResult.origin.failureReason || 'Unknown reason'));
|
|
7015
7053
|
}
|
|
7016
|
-
|
|
7054
|
+
// There is no exchange fee if origin is exchange, because jit_withdraw is used
|
|
7055
|
+
fees.exchangeFee = 0n;
|
|
7017
7056
|
}
|
|
7018
7057
|
// Handle origin reserve fee (hop before exchange)
|
|
7019
7058
|
if (exchangeHopIndex > 0) {
|
|
@@ -7078,11 +7117,11 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7078
7117
|
}();
|
|
7079
7118
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7080
7119
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
7081
|
-
var api, chain, exchangeChain, destChain, assetFrom, assetTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, hasOriginReserveHop, requireExchangeSuccess, extractedFees, exchangeHop, totalFeesInFromAsset, amountAvailableForSwap, recalculatedMinAmountOut,
|
|
7120
|
+
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, hasOriginReserveHop, requireExchangeSuccess, extractedFees, exchangeHop, totalFeesInFromAsset, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, secondCall, secondDryRunResult, finalFees, hasHopsInSecondRun, isOnExchangeChain, finalExchangeHopIndex, finalTotalFeesInFromAsset, finalAmountAvailableForSwap, finalMinAmountOut, finalAssetTo, _yield$createXcmAndCa3, finalCall;
|
|
7082
7121
|
return _regenerator().w(function (_context3) {
|
|
7083
7122
|
while (1) switch (_context3.n) {
|
|
7084
7123
|
case 0:
|
|
7085
|
-
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, destChain = options.destChain, assetFrom = options.assetFrom, assetTo = options.assetTo, senderAddress = options.senderAddress, recipientAddress = options.recipientAddress, calculateMinAmountOut = options.calculateMinAmountOut;
|
|
7124
|
+
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, destChain = options.destChain, assetFrom = options.assetFrom, assetTo = options.assetTo, currencyTo = options.currencyTo, senderAddress = options.senderAddress, recipientAddress = options.recipientAddress, calculateMinAmountOut = options.calculateMinAmountOut;
|
|
7086
7125
|
_context3.n = 1;
|
|
7087
7126
|
return api.init(chain !== null && chain !== void 0 ? chain : exchangeChain);
|
|
7088
7127
|
case 1:
|
|
@@ -7101,6 +7140,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7101
7140
|
currency: {
|
|
7102
7141
|
multilocation: assetFrom.multiLocation,
|
|
7103
7142
|
amount: assetFrom.amount
|
|
7143
|
+
},
|
|
7144
|
+
swapConfig: {
|
|
7145
|
+
currencyTo: currencyTo,
|
|
7146
|
+
exchangeChain: exchangeChain
|
|
7104
7147
|
}
|
|
7105
7148
|
}; // First dry run with dummy fees to extract actual fees
|
|
7106
7149
|
_context3.n = 2;
|
|
@@ -7132,6 +7175,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7132
7175
|
_context3.n = 5;
|
|
7133
7176
|
break;
|
|
7134
7177
|
}
|
|
7178
|
+
if (!chain) {
|
|
7179
|
+
_context3.n = 4;
|
|
7180
|
+
break;
|
|
7181
|
+
}
|
|
7135
7182
|
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7136
7183
|
if (exchangeHop.result.success) {
|
|
7137
7184
|
_context3.n = 4;
|
|
@@ -7155,6 +7202,11 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7155
7202
|
// Calculate actual amount available for swap
|
|
7156
7203
|
totalFeesInFromAsset = chain ? extractedFees.originReserveFee + extractedFees.exchangeFee : 0n;
|
|
7157
7204
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7205
|
+
updatedAssetTo = assetTo;
|
|
7206
|
+
if (!chain) {
|
|
7207
|
+
_context3.n = 8;
|
|
7208
|
+
break;
|
|
7209
|
+
}
|
|
7158
7210
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7159
7211
|
_context3.n = 7;
|
|
7160
7212
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
@@ -7162,20 +7214,21 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7162
7214
|
recalculatedMinAmountOut = _context3.v;
|
|
7163
7215
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7164
7216
|
amount: recalculatedMinAmountOut.toString()
|
|
7165
|
-
});
|
|
7166
|
-
|
|
7217
|
+
});
|
|
7218
|
+
case 8:
|
|
7219
|
+
_context3.n = 9;
|
|
7167
7220
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7168
7221
|
assetTo: updatedAssetTo,
|
|
7169
7222
|
fees: extractedFees
|
|
7170
7223
|
}));
|
|
7171
|
-
case
|
|
7224
|
+
case 9:
|
|
7172
7225
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7173
7226
|
secondCall = _yield$createXcmAndCa2.call;
|
|
7174
|
-
_context3.n =
|
|
7227
|
+
_context3.n = 10;
|
|
7175
7228
|
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7176
7229
|
tx: api.callTxMethod(secondCall)
|
|
7177
7230
|
}));
|
|
7178
|
-
case
|
|
7231
|
+
case 10:
|
|
7179
7232
|
secondDryRunResult = _context3.v;
|
|
7180
7233
|
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7181
7234
|
isOnExchangeChain = chain === exchangeChain;
|
|
@@ -7190,27 +7243,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7190
7243
|
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7191
7244
|
// If the final fees are different, we might need one more iteration
|
|
7192
7245
|
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7193
|
-
_context3.n =
|
|
7246
|
+
_context3.n = 13;
|
|
7194
7247
|
break;
|
|
7195
7248
|
}
|
|
7196
7249
|
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7197
|
-
_context3.n =
|
|
7250
|
+
_context3.n = 11;
|
|
7198
7251
|
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7199
|
-
case
|
|
7252
|
+
case 11:
|
|
7200
7253
|
finalMinAmountOut = _context3.v;
|
|
7201
7254
|
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7202
7255
|
amount: finalMinAmountOut.toString()
|
|
7203
7256
|
});
|
|
7204
|
-
_context3.n =
|
|
7257
|
+
_context3.n = 12;
|
|
7205
7258
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7206
7259
|
assetTo: finalAssetTo,
|
|
7207
7260
|
fees: finalFees
|
|
7208
7261
|
}));
|
|
7209
|
-
case
|
|
7262
|
+
case 12:
|
|
7210
7263
|
_yield$createXcmAndCa3 = _context3.v;
|
|
7211
7264
|
finalCall = _yield$createXcmAndCa3.call;
|
|
7212
7265
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7213
|
-
case
|
|
7266
|
+
case 13:
|
|
7214
7267
|
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7215
7268
|
}
|
|
7216
7269
|
}, _callee3);
|
package/dist/index.d.ts
CHANGED
|
@@ -233,6 +233,7 @@ type TCreateBaseSwapXcmOptions = {
|
|
|
233
233
|
destChain?: TNodeWithRelayChains;
|
|
234
234
|
assetFrom: WithAmount<TAsset>;
|
|
235
235
|
assetTo: WithAmount<TAsset>;
|
|
236
|
+
currencyTo: TCurrencyInput;
|
|
236
237
|
senderAddress: string;
|
|
237
238
|
recipientAddress: string;
|
|
238
239
|
calculateMinAmountOut: (amountIn: bigint, assetTo?: TAsset) => Promise<bigint>;
|
|
@@ -563,6 +564,10 @@ type TDryRunBaseOptions<TRes> = {
|
|
|
563
564
|
address: string;
|
|
564
565
|
currency: TCurrencyInputWithAmount;
|
|
565
566
|
feeAsset?: TCurrencyInput;
|
|
567
|
+
swapConfig?: {
|
|
568
|
+
currencyTo: TCurrencyCore;
|
|
569
|
+
exchangeChain: TNodePolkadotKusama;
|
|
570
|
+
};
|
|
566
571
|
};
|
|
567
572
|
type TDryRunOptions<TApi, TRes> = WithApi<TDryRunBaseOptions<TRes>, TApi, TRes>;
|
|
568
573
|
type TDryRunCallBaseOptions<TRes> = {
|
|
@@ -900,6 +905,10 @@ type TGetXcmFeeBaseOptions<TRes> = {
|
|
|
900
905
|
currency: WithAmount<TCurrencyCore>;
|
|
901
906
|
feeAsset?: TCurrencyInput;
|
|
902
907
|
disableFallback: boolean;
|
|
908
|
+
swapConfig?: {
|
|
909
|
+
currencyTo: TCurrencyCore;
|
|
910
|
+
exchangeChain: TNodePolkadotKusama;
|
|
911
|
+
};
|
|
903
912
|
};
|
|
904
913
|
type TGetXcmFeeOptions<TApi, TRes> = WithApi<TGetXcmFeeBaseOptions<TRes>, TApi, TRes>;
|
|
905
914
|
type TGetXcmFeeEstimateOptions<TApi, TRes> = Omit<TGetXcmFeeOptions<TApi, TRes>, 'disableFallback'>;
|
|
@@ -1897,7 +1906,7 @@ declare const getOriginXcmFee: <TApi, TRes>({ api, tx, origin, destination, send
|
|
|
1897
1906
|
|
|
1898
1907
|
declare const getOriginXcmFeeEstimate: <TApi, TRes>({ api, tx, origin, destination, currency, senderAddress, feeAsset }: TGetOriginXcmFeeEstimateOptions<TApi, TRes>) => Promise<TGetXcmFeeEstimateDetail>;
|
|
1899
1908
|
|
|
1900
|
-
declare const getXcmFee: <TApi, TRes>({ api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback }: TGetXcmFeeOptions<TApi, TRes>) => Promise<TGetXcmFeeResult>;
|
|
1909
|
+
declare const getXcmFee: <TApi, TRes>({ api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig }: TGetXcmFeeOptions<TApi, TRes>) => Promise<TGetXcmFeeResult>;
|
|
1901
1910
|
|
|
1902
1911
|
declare const getXcmFeeEstimate: <TApi, TRes>(options: TGetXcmFeeEstimateOptions<TApi, TRes>) => Promise<TGetXcmFeeEstimateResult>;
|
|
1903
1912
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2';
|
|
2
|
-
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, extractMultiAssetLoc, isAssetEqual, isForeignAsset, findAssetForNodeOrThrow, getExistentialDeposit, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, findAsset, isTMultiAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, hasSupportForAsset, getRelayChainSymbol, isSymbolSpecifier,
|
|
2
|
+
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, extractMultiAssetLoc, isAssetEqual, isForeignAsset, findAssetForNodeOrThrow, getExistentialDeposit, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, findAsset, isTMultiAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, findAssetOnDestOrThrow, hasSupportForAsset, getRelayChainSymbol, isSymbolSpecifier, normalizeMultiLocation, normalizeSymbol, getAssetId, getNativeAssets } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { isAddress, createPublicClient, http, getContract } from 'viem';
|
|
@@ -4897,11 +4897,11 @@ var getFailureInfo$1 = function getFailureInfo(results, hops) {
|
|
|
4897
4897
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
4898
4898
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4899
4899
|
var _intermediateFees$bri, _intermediateFees$ass, _processedBridgeHubDa, _destinationDryRun;
|
|
4900
|
-
var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, hops, destinationDryRun, nextChain, hopApi, hopDryRun, hopCurrency, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, _getFailureInfo, failureReason, failureChain;
|
|
4900
|
+
var origin, destination, currency, api, tx, senderAddress, feeAsset, swapConfig, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, assetHubNode, bridgeHubNode, currentAsset, hasPassedExchange, currentOrigin, forwardedXcms, nextParaId, intermediateFees, hops, destinationDryRun, nextChain, hopApi, hopDryRun, hopCurrency, newXcms, destParaId, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, _getFailureInfo, failureReason, failureChain;
|
|
4901
4901
|
return _regenerator().w(function (_context) {
|
|
4902
4902
|
while (1) switch (_context.n) {
|
|
4903
4903
|
case 0:
|
|
4904
|
-
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
|
|
4904
|
+
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset, swapConfig = options.swapConfig;
|
|
4905
4905
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4906
4906
|
asset = findAssetForNodeOrThrow(origin, currency, destination);
|
|
4907
4907
|
_context.n = 1;
|
|
@@ -4927,6 +4927,8 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4927
4927
|
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
4928
4928
|
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
4929
4929
|
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
4930
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
4931
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
4930
4932
|
currentOrigin = origin;
|
|
4931
4933
|
forwardedXcms = initialForwardedXcms;
|
|
4932
4934
|
nextParaId = initialDestParaId;
|
|
@@ -4967,14 +4969,20 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4967
4969
|
xcm: forwardedXcms[1][0],
|
|
4968
4970
|
node: nextChain,
|
|
4969
4971
|
origin: currentOrigin,
|
|
4970
|
-
asset:
|
|
4972
|
+
asset: currentAsset,
|
|
4971
4973
|
feeAsset: resolvedFeeAsset,
|
|
4972
4974
|
originFee: originDryRun.fee,
|
|
4973
4975
|
amount: BigInt(currency.amount)
|
|
4974
4976
|
});
|
|
4975
4977
|
case 8:
|
|
4976
4978
|
hopDryRun = _context.v;
|
|
4977
|
-
hopCurrency =
|
|
4979
|
+
hopCurrency = void 0;
|
|
4980
|
+
if (hasPassedExchange && swapConfig && nextChain !== swapConfig.exchangeChain) {
|
|
4981
|
+
hopCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo).symbol;
|
|
4982
|
+
} else {
|
|
4983
|
+
hopCurrency = asset.symbol;
|
|
4984
|
+
}
|
|
4985
|
+
// Add to hops array (only if not the destination)
|
|
4978
4986
|
if (nextChain !== destination) {
|
|
4979
4987
|
hops.push({
|
|
4980
4988
|
chain: nextChain,
|
|
@@ -4997,6 +5005,10 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
4997
5005
|
}
|
|
4998
5006
|
return _context.a(3, 13);
|
|
4999
5007
|
case 9:
|
|
5008
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5009
|
+
hasPassedExchange = true;
|
|
5010
|
+
currentAsset = findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5011
|
+
}
|
|
5000
5012
|
newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
|
|
5001
5013
|
forwardedXcms = newXcms;
|
|
5002
5014
|
nextParaId = destParaId;
|
|
@@ -5475,12 +5487,11 @@ var getFailureInfo = function getFailureInfo(nodes, hops) {
|
|
|
5475
5487
|
};
|
|
5476
5488
|
var getXcmFee = /*#__PURE__*/function () {
|
|
5477
5489
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
5478
|
-
var
|
|
5479
|
-
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, hops, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, destinationSufficient, nextChain, hopApi, _findAssetOnDest, hopResult, hopCurrency, hopDetail, failingRecord, hopIsDestination, _destApi, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, destCurrency, result, _getFailureInfo2, failureChain, failureReason;
|
|
5490
|
+
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, hops, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, currentAsset, hasPassedExchange, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, destinationSufficient, nextChain, hopApi, hopResult, hopCurrency, hopDetail, failingRecord, hopIsDestination, _destApi, destFallback, processedBridgeHubData, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, bridgeHubHopIndex, destCurrency, result, _getFailureInfo2, failureChain, failureReason;
|
|
5480
5491
|
return _regenerator().w(function (_context) {
|
|
5481
5492
|
while (1) switch (_context.n) {
|
|
5482
5493
|
case 0:
|
|
5483
|
-
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;
|
|
5494
|
+
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;
|
|
5484
5495
|
asset = findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
5485
5496
|
_context.n = 1;
|
|
5486
5497
|
return getOriginXcmFee({
|
|
@@ -5582,6 +5593,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5582
5593
|
currentOrigin = origin;
|
|
5583
5594
|
forwardedXcms = initialForwardedXcm;
|
|
5584
5595
|
nextParaId = initialDestParaId;
|
|
5596
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
5597
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
5585
5598
|
intermediateFees = {};
|
|
5586
5599
|
destinationFee = 0n;
|
|
5587
5600
|
destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
|
|
@@ -5613,14 +5626,25 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5613
5626
|
currency: currency,
|
|
5614
5627
|
address: address,
|
|
5615
5628
|
senderAddress: senderAddress,
|
|
5616
|
-
asset:
|
|
5629
|
+
asset: currentAsset,
|
|
5617
5630
|
feeAsset: feeAsset,
|
|
5618
5631
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
5619
5632
|
disableFallback: disableFallback
|
|
5620
5633
|
});
|
|
5621
5634
|
case 13:
|
|
5622
5635
|
hopResult = _context.v;
|
|
5623
|
-
hopCurrency =
|
|
5636
|
+
hopCurrency = void 0;
|
|
5637
|
+
if (hopResult.feeType === 'dryRun') {
|
|
5638
|
+
if (hasPassedExchange && swapConfig && nextChain !== swapConfig.exchangeChain) {
|
|
5639
|
+
hopCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo).symbol;
|
|
5640
|
+
} else if (destination === nextChain) {
|
|
5641
|
+
hopCurrency = findAssetOnDestOrThrow(origin, nextChain, currency).symbol;
|
|
5642
|
+
} else {
|
|
5643
|
+
hopCurrency = asset.symbol;
|
|
5644
|
+
}
|
|
5645
|
+
} else {
|
|
5646
|
+
hopCurrency = getNativeAssetSymbol(nextChain);
|
|
5647
|
+
}
|
|
5624
5648
|
hopDetail = hopResult.dryRunError ? {
|
|
5625
5649
|
fee: hopResult.fee,
|
|
5626
5650
|
feeType: hopResult.feeType,
|
|
@@ -5699,6 +5723,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5699
5723
|
} else if (nextChain === bridgeHubNode) {
|
|
5700
5724
|
intermediateFees.bridgeHub = hopDetail;
|
|
5701
5725
|
} else ;
|
|
5726
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5727
|
+
hasPassedExchange = true;
|
|
5728
|
+
currentAsset = findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5729
|
+
}
|
|
5702
5730
|
forwardedXcms = hopResult.forwardedXcms;
|
|
5703
5731
|
nextParaId = hopResult.destParaId;
|
|
5704
5732
|
currentOrigin = nextChain;
|
|
@@ -5740,7 +5768,15 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5740
5768
|
}
|
|
5741
5769
|
case 24:
|
|
5742
5770
|
intermediateFees.bridgeHub = processedBridgeHubData;
|
|
5743
|
-
|
|
5771
|
+
if (destinationFeeType === 'dryRun') {
|
|
5772
|
+
if (hasPassedExchange && swapConfig && destination !== swapConfig.exchangeChain) {
|
|
5773
|
+
destCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, destination, swapConfig.currencyTo).symbol;
|
|
5774
|
+
} else {
|
|
5775
|
+
destCurrency = findAssetOnDestOrThrow(origin, destination, currency).symbol;
|
|
5776
|
+
}
|
|
5777
|
+
} else {
|
|
5778
|
+
destCurrency = getNativeAssetSymbol(destination);
|
|
5779
|
+
}
|
|
5744
5780
|
result = _objectSpread2(_objectSpread2({
|
|
5745
5781
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
|
|
5746
5782
|
weight: originWeight
|
|
@@ -6759,7 +6795,8 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
6759
6795
|
feeCurrency: feeCurrency,
|
|
6760
6796
|
recipientAddress: address,
|
|
6761
6797
|
senderAddress: senderAddress,
|
|
6762
|
-
version: version
|
|
6798
|
+
version: version,
|
|
6799
|
+
paraIdTo: paraIdTo
|
|
6763
6800
|
};
|
|
6764
6801
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
6765
6802
|
fees: {
|
|
@@ -6819,7 +6856,7 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
6819
6856
|
|
|
6820
6857
|
var createExchangeInstructions = /*#__PURE__*/function () {
|
|
6821
6858
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, multiAssetFrom, multiAssetTo) {
|
|
6822
|
-
var chain, exchangeChain, assetFrom, assetTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, nativeSymbol, needsMultiHop, nativeAsset, nativeAmountOut, multiAssetNative;
|
|
6859
|
+
var chain, exchangeChain, assetFrom, assetTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, nativeSymbol, needsMultiHop, nativeAsset, shouldUseMaximal, nativeAmountOut, multiAssetNative;
|
|
6823
6860
|
return _regenerator().w(function (_context) {
|
|
6824
6861
|
while (1) switch (_context.n) {
|
|
6825
6862
|
case 0:
|
|
@@ -6830,6 +6867,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6830
6867
|
symbol: nativeSymbol
|
|
6831
6868
|
}, null);
|
|
6832
6869
|
assertHasLocation(nativeAsset);
|
|
6870
|
+
shouldUseMaximal = !chain || exchangeChain === 'Hydration' && exchangeFee === 0n;
|
|
6833
6871
|
if (needsMultiHop) {
|
|
6834
6872
|
_context.n = 1;
|
|
6835
6873
|
break;
|
|
@@ -6838,7 +6876,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6838
6876
|
ExchangeAsset: {
|
|
6839
6877
|
give: createAssetsFilter(multiAssetFrom),
|
|
6840
6878
|
want: [multiAssetTo],
|
|
6841
|
-
maximal:
|
|
6879
|
+
maximal: shouldUseMaximal
|
|
6842
6880
|
}
|
|
6843
6881
|
}]);
|
|
6844
6882
|
case 1:
|
|
@@ -6851,7 +6889,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6851
6889
|
ExchangeAsset: {
|
|
6852
6890
|
give: createAssetsFilter(multiAssetFrom),
|
|
6853
6891
|
want: [multiAssetNative],
|
|
6854
|
-
maximal:
|
|
6892
|
+
maximal: shouldUseMaximal
|
|
6855
6893
|
}
|
|
6856
6894
|
}, {
|
|
6857
6895
|
ExchangeAsset: {
|
|
@@ -7014,7 +7052,8 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
7014
7052
|
if (!dryRunResult.origin.success) {
|
|
7015
7053
|
throw new DryRunFailedError("Origin dry run failed: ".concat(dryRunResult.origin.failureReason || 'Unknown reason'));
|
|
7016
7054
|
}
|
|
7017
|
-
|
|
7055
|
+
// There is no exchange fee if origin is exchange, because jit_withdraw is used
|
|
7056
|
+
fees.exchangeFee = 0n;
|
|
7018
7057
|
}
|
|
7019
7058
|
// Handle origin reserve fee (hop before exchange)
|
|
7020
7059
|
if (exchangeHopIndex > 0) {
|
|
@@ -7079,11 +7118,11 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7079
7118
|
}();
|
|
7080
7119
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7081
7120
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
7082
|
-
var api, chain, exchangeChain, destChain, assetFrom, assetTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, hasOriginReserveHop, requireExchangeSuccess, extractedFees, exchangeHop, totalFeesInFromAsset, amountAvailableForSwap, recalculatedMinAmountOut,
|
|
7121
|
+
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, hasOriginReserveHop, requireExchangeSuccess, extractedFees, exchangeHop, totalFeesInFromAsset, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, secondCall, secondDryRunResult, finalFees, hasHopsInSecondRun, isOnExchangeChain, finalExchangeHopIndex, finalTotalFeesInFromAsset, finalAmountAvailableForSwap, finalMinAmountOut, finalAssetTo, _yield$createXcmAndCa3, finalCall;
|
|
7083
7122
|
return _regenerator().w(function (_context3) {
|
|
7084
7123
|
while (1) switch (_context3.n) {
|
|
7085
7124
|
case 0:
|
|
7086
|
-
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, destChain = options.destChain, assetFrom = options.assetFrom, assetTo = options.assetTo, senderAddress = options.senderAddress, recipientAddress = options.recipientAddress, calculateMinAmountOut = options.calculateMinAmountOut;
|
|
7125
|
+
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, destChain = options.destChain, assetFrom = options.assetFrom, assetTo = options.assetTo, currencyTo = options.currencyTo, senderAddress = options.senderAddress, recipientAddress = options.recipientAddress, calculateMinAmountOut = options.calculateMinAmountOut;
|
|
7087
7126
|
_context3.n = 1;
|
|
7088
7127
|
return api.init(chain !== null && chain !== void 0 ? chain : exchangeChain);
|
|
7089
7128
|
case 1:
|
|
@@ -7102,6 +7141,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7102
7141
|
currency: {
|
|
7103
7142
|
multilocation: assetFrom.multiLocation,
|
|
7104
7143
|
amount: assetFrom.amount
|
|
7144
|
+
},
|
|
7145
|
+
swapConfig: {
|
|
7146
|
+
currencyTo: currencyTo,
|
|
7147
|
+
exchangeChain: exchangeChain
|
|
7105
7148
|
}
|
|
7106
7149
|
}; // First dry run with dummy fees to extract actual fees
|
|
7107
7150
|
_context3.n = 2;
|
|
@@ -7133,6 +7176,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7133
7176
|
_context3.n = 5;
|
|
7134
7177
|
break;
|
|
7135
7178
|
}
|
|
7179
|
+
if (!chain) {
|
|
7180
|
+
_context3.n = 4;
|
|
7181
|
+
break;
|
|
7182
|
+
}
|
|
7136
7183
|
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7137
7184
|
if (exchangeHop.result.success) {
|
|
7138
7185
|
_context3.n = 4;
|
|
@@ -7156,6 +7203,11 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7156
7203
|
// Calculate actual amount available for swap
|
|
7157
7204
|
totalFeesInFromAsset = chain ? extractedFees.originReserveFee + extractedFees.exchangeFee : 0n;
|
|
7158
7205
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7206
|
+
updatedAssetTo = assetTo;
|
|
7207
|
+
if (!chain) {
|
|
7208
|
+
_context3.n = 8;
|
|
7209
|
+
break;
|
|
7210
|
+
}
|
|
7159
7211
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7160
7212
|
_context3.n = 7;
|
|
7161
7213
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
@@ -7163,20 +7215,21 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7163
7215
|
recalculatedMinAmountOut = _context3.v;
|
|
7164
7216
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7165
7217
|
amount: recalculatedMinAmountOut.toString()
|
|
7166
|
-
});
|
|
7167
|
-
|
|
7218
|
+
});
|
|
7219
|
+
case 8:
|
|
7220
|
+
_context3.n = 9;
|
|
7168
7221
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7169
7222
|
assetTo: updatedAssetTo,
|
|
7170
7223
|
fees: extractedFees
|
|
7171
7224
|
}));
|
|
7172
|
-
case
|
|
7225
|
+
case 9:
|
|
7173
7226
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7174
7227
|
secondCall = _yield$createXcmAndCa2.call;
|
|
7175
|
-
_context3.n =
|
|
7228
|
+
_context3.n = 10;
|
|
7176
7229
|
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7177
7230
|
tx: api.callTxMethod(secondCall)
|
|
7178
7231
|
}));
|
|
7179
|
-
case
|
|
7232
|
+
case 10:
|
|
7180
7233
|
secondDryRunResult = _context3.v;
|
|
7181
7234
|
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7182
7235
|
isOnExchangeChain = chain === exchangeChain;
|
|
@@ -7191,27 +7244,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7191
7244
|
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7192
7245
|
// If the final fees are different, we might need one more iteration
|
|
7193
7246
|
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7194
|
-
_context3.n =
|
|
7247
|
+
_context3.n = 13;
|
|
7195
7248
|
break;
|
|
7196
7249
|
}
|
|
7197
7250
|
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7198
|
-
_context3.n =
|
|
7251
|
+
_context3.n = 11;
|
|
7199
7252
|
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7200
|
-
case
|
|
7253
|
+
case 11:
|
|
7201
7254
|
finalMinAmountOut = _context3.v;
|
|
7202
7255
|
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7203
7256
|
amount: finalMinAmountOut.toString()
|
|
7204
7257
|
});
|
|
7205
|
-
_context3.n =
|
|
7258
|
+
_context3.n = 12;
|
|
7206
7259
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7207
7260
|
assetTo: finalAssetTo,
|
|
7208
7261
|
fees: finalFees
|
|
7209
7262
|
}));
|
|
7210
|
-
case
|
|
7263
|
+
case 12:
|
|
7211
7264
|
_yield$createXcmAndCa3 = _context3.v;
|
|
7212
7265
|
finalCall = _yield$createXcmAndCa3.call;
|
|
7213
7266
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7214
|
-
case
|
|
7267
|
+
case 13:
|
|
7215
7268
|
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7216
7269
|
}
|
|
7217
7270
|
}, _callee3);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-core",
|
|
3
|
-
"version": "10.10.
|
|
3
|
+
"version": "10.10.2",
|
|
4
4
|
"description": "SDK core for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"@noble/hashes": "^1.8.0",
|
|
27
27
|
"@scure/base": "^1.2.6",
|
|
28
28
|
"viem": "^2.31.6",
|
|
29
|
-
"@paraspell/assets": "10.10.
|
|
30
|
-
"@paraspell/sdk-common": "10.10.
|
|
31
|
-
"@paraspell/pallets": "10.10.
|
|
29
|
+
"@paraspell/assets": "10.10.2",
|
|
30
|
+
"@paraspell/sdk-common": "10.10.2",
|
|
31
|
+
"@paraspell/pallets": "10.10.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/plugin-syntax-import-attributes": "^7.27.1",
|