@paraspell/sdk-core 10.10.0 → 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 +85 -30
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +86 -31
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -695,7 +695,7 @@ var DOT_MULTILOCATION = {
|
|
|
695
695
|
parents: sdkCommon.Parents.ONE,
|
|
696
696
|
interior: 'Here'
|
|
697
697
|
};
|
|
698
|
-
var CHAINS_DOT_RESERVE_AH = new Set(['
|
|
698
|
+
var CHAINS_DOT_RESERVE_AH = new Set(['Polimec', 'Moonbeam', 'BifrostPolkadot', 'PeoplePolkadot', 'Ajuna']);
|
|
699
699
|
var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
|
|
700
700
|
var TX_CLIENT_TIMEOUT_MS = 20 * 60 * 1000; // 20 minutes
|
|
701
701
|
var DRY_RUN_CLIENT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
@@ -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,11 +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 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, 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;
|
|
5478
5490
|
return _regenerator().w(function (_context) {
|
|
5479
5491
|
while (1) switch (_context.n) {
|
|
5480
5492
|
case 0:
|
|
5481
|
-
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;
|
|
5482
5494
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
5483
5495
|
_context.n = 1;
|
|
5484
5496
|
return getOriginXcmFee({
|
|
@@ -5580,6 +5592,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5580
5592
|
currentOrigin = origin;
|
|
5581
5593
|
forwardedXcms = initialForwardedXcm;
|
|
5582
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);
|
|
5583
5597
|
intermediateFees = {};
|
|
5584
5598
|
destinationFee = 0n;
|
|
5585
5599
|
destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
|
|
@@ -5611,14 +5625,25 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5611
5625
|
currency: currency,
|
|
5612
5626
|
address: address,
|
|
5613
5627
|
senderAddress: senderAddress,
|
|
5614
|
-
asset:
|
|
5628
|
+
asset: currentAsset,
|
|
5615
5629
|
feeAsset: feeAsset,
|
|
5616
5630
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
5617
5631
|
disableFallback: disableFallback
|
|
5618
5632
|
});
|
|
5619
5633
|
case 13:
|
|
5620
5634
|
hopResult = _context.v;
|
|
5621
|
-
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
|
+
}
|
|
5622
5647
|
hopDetail = hopResult.dryRunError ? {
|
|
5623
5648
|
fee: hopResult.fee,
|
|
5624
5649
|
feeType: hopResult.feeType,
|
|
@@ -5697,6 +5722,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5697
5722
|
} else if (nextChain === bridgeHubNode) {
|
|
5698
5723
|
intermediateFees.bridgeHub = hopDetail;
|
|
5699
5724
|
} else ;
|
|
5725
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5726
|
+
hasPassedExchange = true;
|
|
5727
|
+
currentAsset = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5728
|
+
}
|
|
5700
5729
|
forwardedXcms = hopResult.forwardedXcms;
|
|
5701
5730
|
nextParaId = hopResult.destParaId;
|
|
5702
5731
|
currentOrigin = nextChain;
|
|
@@ -5738,7 +5767,15 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5738
5767
|
}
|
|
5739
5768
|
case 24:
|
|
5740
5769
|
intermediateFees.bridgeHub = processedBridgeHubData;
|
|
5741
|
-
|
|
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
|
+
}
|
|
5742
5779
|
result = _objectSpread2(_objectSpread2({
|
|
5743
5780
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
|
|
5744
5781
|
weight: originWeight
|
|
@@ -6757,7 +6794,8 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
6757
6794
|
feeCurrency: feeCurrency,
|
|
6758
6795
|
recipientAddress: address,
|
|
6759
6796
|
senderAddress: senderAddress,
|
|
6760
|
-
version: version
|
|
6797
|
+
version: version,
|
|
6798
|
+
paraIdTo: paraIdTo
|
|
6761
6799
|
};
|
|
6762
6800
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
6763
6801
|
fees: {
|
|
@@ -6817,7 +6855,7 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
6817
6855
|
|
|
6818
6856
|
var createExchangeInstructions = /*#__PURE__*/function () {
|
|
6819
6857
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, multiAssetFrom, multiAssetTo) {
|
|
6820
|
-
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;
|
|
6821
6859
|
return _regenerator().w(function (_context) {
|
|
6822
6860
|
while (1) switch (_context.n) {
|
|
6823
6861
|
case 0:
|
|
@@ -6828,6 +6866,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6828
6866
|
symbol: nativeSymbol
|
|
6829
6867
|
}, null);
|
|
6830
6868
|
assertHasLocation(nativeAsset);
|
|
6869
|
+
shouldUseMaximal = !chain || exchangeChain === 'Hydration' && exchangeFee === 0n;
|
|
6831
6870
|
if (needsMultiHop) {
|
|
6832
6871
|
_context.n = 1;
|
|
6833
6872
|
break;
|
|
@@ -6836,7 +6875,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6836
6875
|
ExchangeAsset: {
|
|
6837
6876
|
give: createAssetsFilter(multiAssetFrom),
|
|
6838
6877
|
want: [multiAssetTo],
|
|
6839
|
-
maximal:
|
|
6878
|
+
maximal: shouldUseMaximal
|
|
6840
6879
|
}
|
|
6841
6880
|
}]);
|
|
6842
6881
|
case 1:
|
|
@@ -6849,7 +6888,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6849
6888
|
ExchangeAsset: {
|
|
6850
6889
|
give: createAssetsFilter(multiAssetFrom),
|
|
6851
6890
|
want: [multiAssetNative],
|
|
6852
|
-
maximal:
|
|
6891
|
+
maximal: shouldUseMaximal
|
|
6853
6892
|
}
|
|
6854
6893
|
}, {
|
|
6855
6894
|
ExchangeAsset: {
|
|
@@ -7012,7 +7051,8 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
7012
7051
|
if (!dryRunResult.origin.success) {
|
|
7013
7052
|
throw new DryRunFailedError("Origin dry run failed: ".concat(dryRunResult.origin.failureReason || 'Unknown reason'));
|
|
7014
7053
|
}
|
|
7015
|
-
|
|
7054
|
+
// There is no exchange fee if origin is exchange, because jit_withdraw is used
|
|
7055
|
+
fees.exchangeFee = 0n;
|
|
7016
7056
|
}
|
|
7017
7057
|
// Handle origin reserve fee (hop before exchange)
|
|
7018
7058
|
if (exchangeHopIndex > 0) {
|
|
@@ -7077,11 +7117,11 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7077
7117
|
}();
|
|
7078
7118
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7079
7119
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
7080
|
-
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;
|
|
7081
7121
|
return _regenerator().w(function (_context3) {
|
|
7082
7122
|
while (1) switch (_context3.n) {
|
|
7083
7123
|
case 0:
|
|
7084
|
-
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;
|
|
7085
7125
|
_context3.n = 1;
|
|
7086
7126
|
return api.init(chain !== null && chain !== void 0 ? chain : exchangeChain);
|
|
7087
7127
|
case 1:
|
|
@@ -7100,6 +7140,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7100
7140
|
currency: {
|
|
7101
7141
|
multilocation: assetFrom.multiLocation,
|
|
7102
7142
|
amount: assetFrom.amount
|
|
7143
|
+
},
|
|
7144
|
+
swapConfig: {
|
|
7145
|
+
currencyTo: currencyTo,
|
|
7146
|
+
exchangeChain: exchangeChain
|
|
7103
7147
|
}
|
|
7104
7148
|
}; // First dry run with dummy fees to extract actual fees
|
|
7105
7149
|
_context3.n = 2;
|
|
@@ -7131,6 +7175,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7131
7175
|
_context3.n = 5;
|
|
7132
7176
|
break;
|
|
7133
7177
|
}
|
|
7178
|
+
if (!chain) {
|
|
7179
|
+
_context3.n = 4;
|
|
7180
|
+
break;
|
|
7181
|
+
}
|
|
7134
7182
|
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7135
7183
|
if (exchangeHop.result.success) {
|
|
7136
7184
|
_context3.n = 4;
|
|
@@ -7154,6 +7202,11 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7154
7202
|
// Calculate actual amount available for swap
|
|
7155
7203
|
totalFeesInFromAsset = chain ? extractedFees.originReserveFee + extractedFees.exchangeFee : 0n;
|
|
7156
7204
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7205
|
+
updatedAssetTo = assetTo;
|
|
7206
|
+
if (!chain) {
|
|
7207
|
+
_context3.n = 8;
|
|
7208
|
+
break;
|
|
7209
|
+
}
|
|
7157
7210
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7158
7211
|
_context3.n = 7;
|
|
7159
7212
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
@@ -7161,20 +7214,21 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7161
7214
|
recalculatedMinAmountOut = _context3.v;
|
|
7162
7215
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7163
7216
|
amount: recalculatedMinAmountOut.toString()
|
|
7164
|
-
});
|
|
7165
|
-
|
|
7217
|
+
});
|
|
7218
|
+
case 8:
|
|
7219
|
+
_context3.n = 9;
|
|
7166
7220
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7167
7221
|
assetTo: updatedAssetTo,
|
|
7168
7222
|
fees: extractedFees
|
|
7169
7223
|
}));
|
|
7170
|
-
case
|
|
7224
|
+
case 9:
|
|
7171
7225
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7172
7226
|
secondCall = _yield$createXcmAndCa2.call;
|
|
7173
|
-
_context3.n =
|
|
7227
|
+
_context3.n = 10;
|
|
7174
7228
|
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7175
7229
|
tx: api.callTxMethod(secondCall)
|
|
7176
7230
|
}));
|
|
7177
|
-
case
|
|
7231
|
+
case 10:
|
|
7178
7232
|
secondDryRunResult = _context3.v;
|
|
7179
7233
|
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7180
7234
|
isOnExchangeChain = chain === exchangeChain;
|
|
@@ -7189,27 +7243,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7189
7243
|
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7190
7244
|
// If the final fees are different, we might need one more iteration
|
|
7191
7245
|
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7192
|
-
_context3.n =
|
|
7246
|
+
_context3.n = 13;
|
|
7193
7247
|
break;
|
|
7194
7248
|
}
|
|
7195
7249
|
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7196
|
-
_context3.n =
|
|
7250
|
+
_context3.n = 11;
|
|
7197
7251
|
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7198
|
-
case
|
|
7252
|
+
case 11:
|
|
7199
7253
|
finalMinAmountOut = _context3.v;
|
|
7200
7254
|
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7201
7255
|
amount: finalMinAmountOut.toString()
|
|
7202
7256
|
});
|
|
7203
|
-
_context3.n =
|
|
7257
|
+
_context3.n = 12;
|
|
7204
7258
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7205
7259
|
assetTo: finalAssetTo,
|
|
7206
7260
|
fees: finalFees
|
|
7207
7261
|
}));
|
|
7208
|
-
case
|
|
7262
|
+
case 12:
|
|
7209
7263
|
_yield$createXcmAndCa3 = _context3.v;
|
|
7210
7264
|
finalCall = _yield$createXcmAndCa3.call;
|
|
7211
7265
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7212
|
-
case
|
|
7266
|
+
case 13:
|
|
7213
7267
|
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7214
7268
|
}
|
|
7215
7269
|
}, _callee3);
|
|
@@ -8504,7 +8558,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
8504
8558
|
key: "transferPolkadotXCM",
|
|
8505
8559
|
value: function () {
|
|
8506
8560
|
var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
|
|
8507
|
-
var api, scenario, asset, destination, feeAsset, overriddenAsset, isNativeAsset, isNativeFeeAsset, isEthereumAsset, isTrusted, isDotReserveAh, method, modifiedInput, _t, _t2;
|
|
8561
|
+
var api, scenario, asset, destination, feeAsset, overriddenAsset, isNativeAsset, isNativeFeeAsset, isEthereumAsset, CHAINS_SUPPORT_DOT_TRANSFER, isTrusted, isDotReserveAh, method, modifiedInput, _t, _t2;
|
|
8508
8562
|
return _regenerator().w(function (_context3) {
|
|
8509
8563
|
while (1) switch (_context3.n) {
|
|
8510
8564
|
case 0:
|
|
@@ -8569,8 +8623,9 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
8569
8623
|
}
|
|
8570
8624
|
return _context3.a(2, this.handleLocalReserveTransfer(input, true));
|
|
8571
8625
|
case 9:
|
|
8626
|
+
CHAINS_SUPPORT_DOT_TRANSFER = new Set(['Hydration', 'Polimec', 'Moonbeam', 'BifrostPolkadot', 'PeoplePolkadot', 'Ajuna']);
|
|
8572
8627
|
isTrusted = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isSystemChain(destination);
|
|
8573
|
-
isDotReserveAh = !sdkCommon.isTMultiLocation(destination) &&
|
|
8628
|
+
isDotReserveAh = !sdkCommon.isTMultiLocation(destination) && CHAINS_SUPPORT_DOT_TRANSFER.has(destination);
|
|
8574
8629
|
if (!(scenario === 'ParaToPara' && asset.symbol === this.getNativeAssetSymbol() && !assets.isForeignAsset(asset) && !isDotReserveAh && !isTrusted)) {
|
|
8575
8630
|
_context3.n = 10;
|
|
8576
8631
|
break;
|
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';
|
|
@@ -696,7 +696,7 @@ var DOT_MULTILOCATION = {
|
|
|
696
696
|
parents: Parents.ONE,
|
|
697
697
|
interior: 'Here'
|
|
698
698
|
};
|
|
699
|
-
var CHAINS_DOT_RESERVE_AH = new Set(['
|
|
699
|
+
var CHAINS_DOT_RESERVE_AH = new Set(['Polimec', 'Moonbeam', 'BifrostPolkadot', 'PeoplePolkadot', 'Ajuna']);
|
|
700
700
|
var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
|
|
701
701
|
var TX_CLIENT_TIMEOUT_MS = 20 * 60 * 1000; // 20 minutes
|
|
702
702
|
var DRY_RUN_CLIENT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
@@ -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,11 +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 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, 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;
|
|
5479
5491
|
return _regenerator().w(function (_context) {
|
|
5480
5492
|
while (1) switch (_context.n) {
|
|
5481
5493
|
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;
|
|
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;
|
|
5483
5495
|
asset = findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
5484
5496
|
_context.n = 1;
|
|
5485
5497
|
return getOriginXcmFee({
|
|
@@ -5581,6 +5593,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5581
5593
|
currentOrigin = origin;
|
|
5582
5594
|
forwardedXcms = initialForwardedXcm;
|
|
5583
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);
|
|
5584
5598
|
intermediateFees = {};
|
|
5585
5599
|
destinationFee = 0n;
|
|
5586
5600
|
destinationFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
|
|
@@ -5612,14 +5626,25 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5612
5626
|
currency: currency,
|
|
5613
5627
|
address: address,
|
|
5614
5628
|
senderAddress: senderAddress,
|
|
5615
|
-
asset:
|
|
5629
|
+
asset: currentAsset,
|
|
5616
5630
|
feeAsset: feeAsset,
|
|
5617
5631
|
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
5618
5632
|
disableFallback: disableFallback
|
|
5619
5633
|
});
|
|
5620
5634
|
case 13:
|
|
5621
5635
|
hopResult = _context.v;
|
|
5622
|
-
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
|
+
}
|
|
5623
5648
|
hopDetail = hopResult.dryRunError ? {
|
|
5624
5649
|
fee: hopResult.fee,
|
|
5625
5650
|
feeType: hopResult.feeType,
|
|
@@ -5698,6 +5723,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5698
5723
|
} else if (nextChain === bridgeHubNode) {
|
|
5699
5724
|
intermediateFees.bridgeHub = hopDetail;
|
|
5700
5725
|
} else ;
|
|
5726
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5727
|
+
hasPassedExchange = true;
|
|
5728
|
+
currentAsset = findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5729
|
+
}
|
|
5701
5730
|
forwardedXcms = hopResult.forwardedXcms;
|
|
5702
5731
|
nextParaId = hopResult.destParaId;
|
|
5703
5732
|
currentOrigin = nextChain;
|
|
@@ -5739,7 +5768,15 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5739
5768
|
}
|
|
5740
5769
|
case 24:
|
|
5741
5770
|
intermediateFees.bridgeHub = processedBridgeHubData;
|
|
5742
|
-
|
|
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
|
+
}
|
|
5743
5780
|
result = _objectSpread2(_objectSpread2({
|
|
5744
5781
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
|
|
5745
5782
|
weight: originWeight
|
|
@@ -6758,7 +6795,8 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
6758
6795
|
feeCurrency: feeCurrency,
|
|
6759
6796
|
recipientAddress: address,
|
|
6760
6797
|
senderAddress: senderAddress,
|
|
6761
|
-
version: version
|
|
6798
|
+
version: version,
|
|
6799
|
+
paraIdTo: paraIdTo
|
|
6762
6800
|
};
|
|
6763
6801
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
6764
6802
|
fees: {
|
|
@@ -6818,7 +6856,7 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
6818
6856
|
|
|
6819
6857
|
var createExchangeInstructions = /*#__PURE__*/function () {
|
|
6820
6858
|
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;
|
|
6859
|
+
var chain, exchangeChain, assetFrom, assetTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, nativeSymbol, needsMultiHop, nativeAsset, shouldUseMaximal, nativeAmountOut, multiAssetNative;
|
|
6822
6860
|
return _regenerator().w(function (_context) {
|
|
6823
6861
|
while (1) switch (_context.n) {
|
|
6824
6862
|
case 0:
|
|
@@ -6829,6 +6867,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6829
6867
|
symbol: nativeSymbol
|
|
6830
6868
|
}, null);
|
|
6831
6869
|
assertHasLocation(nativeAsset);
|
|
6870
|
+
shouldUseMaximal = !chain || exchangeChain === 'Hydration' && exchangeFee === 0n;
|
|
6832
6871
|
if (needsMultiHop) {
|
|
6833
6872
|
_context.n = 1;
|
|
6834
6873
|
break;
|
|
@@ -6837,7 +6876,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6837
6876
|
ExchangeAsset: {
|
|
6838
6877
|
give: createAssetsFilter(multiAssetFrom),
|
|
6839
6878
|
want: [multiAssetTo],
|
|
6840
|
-
maximal:
|
|
6879
|
+
maximal: shouldUseMaximal
|
|
6841
6880
|
}
|
|
6842
6881
|
}]);
|
|
6843
6882
|
case 1:
|
|
@@ -6850,7 +6889,7 @@ var createExchangeInstructions = /*#__PURE__*/function () {
|
|
|
6850
6889
|
ExchangeAsset: {
|
|
6851
6890
|
give: createAssetsFilter(multiAssetFrom),
|
|
6852
6891
|
want: [multiAssetNative],
|
|
6853
|
-
maximal:
|
|
6892
|
+
maximal: shouldUseMaximal
|
|
6854
6893
|
}
|
|
6855
6894
|
}, {
|
|
6856
6895
|
ExchangeAsset: {
|
|
@@ -7013,7 +7052,8 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
7013
7052
|
if (!dryRunResult.origin.success) {
|
|
7014
7053
|
throw new DryRunFailedError("Origin dry run failed: ".concat(dryRunResult.origin.failureReason || 'Unknown reason'));
|
|
7015
7054
|
}
|
|
7016
|
-
|
|
7055
|
+
// There is no exchange fee if origin is exchange, because jit_withdraw is used
|
|
7056
|
+
fees.exchangeFee = 0n;
|
|
7017
7057
|
}
|
|
7018
7058
|
// Handle origin reserve fee (hop before exchange)
|
|
7019
7059
|
if (exchangeHopIndex > 0) {
|
|
@@ -7078,11 +7118,11 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7078
7118
|
}();
|
|
7079
7119
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7080
7120
|
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,
|
|
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;
|
|
7082
7122
|
return _regenerator().w(function (_context3) {
|
|
7083
7123
|
while (1) switch (_context3.n) {
|
|
7084
7124
|
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;
|
|
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;
|
|
7086
7126
|
_context3.n = 1;
|
|
7087
7127
|
return api.init(chain !== null && chain !== void 0 ? chain : exchangeChain);
|
|
7088
7128
|
case 1:
|
|
@@ -7101,6 +7141,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7101
7141
|
currency: {
|
|
7102
7142
|
multilocation: assetFrom.multiLocation,
|
|
7103
7143
|
amount: assetFrom.amount
|
|
7144
|
+
},
|
|
7145
|
+
swapConfig: {
|
|
7146
|
+
currencyTo: currencyTo,
|
|
7147
|
+
exchangeChain: exchangeChain
|
|
7104
7148
|
}
|
|
7105
7149
|
}; // First dry run with dummy fees to extract actual fees
|
|
7106
7150
|
_context3.n = 2;
|
|
@@ -7132,6 +7176,10 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7132
7176
|
_context3.n = 5;
|
|
7133
7177
|
break;
|
|
7134
7178
|
}
|
|
7179
|
+
if (!chain) {
|
|
7180
|
+
_context3.n = 4;
|
|
7181
|
+
break;
|
|
7182
|
+
}
|
|
7135
7183
|
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7136
7184
|
if (exchangeHop.result.success) {
|
|
7137
7185
|
_context3.n = 4;
|
|
@@ -7155,6 +7203,11 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7155
7203
|
// Calculate actual amount available for swap
|
|
7156
7204
|
totalFeesInFromAsset = chain ? extractedFees.originReserveFee + extractedFees.exchangeFee : 0n;
|
|
7157
7205
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7206
|
+
updatedAssetTo = assetTo;
|
|
7207
|
+
if (!chain) {
|
|
7208
|
+
_context3.n = 8;
|
|
7209
|
+
break;
|
|
7210
|
+
}
|
|
7158
7211
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7159
7212
|
_context3.n = 7;
|
|
7160
7213
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
@@ -7162,20 +7215,21 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7162
7215
|
recalculatedMinAmountOut = _context3.v;
|
|
7163
7216
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7164
7217
|
amount: recalculatedMinAmountOut.toString()
|
|
7165
|
-
});
|
|
7166
|
-
|
|
7218
|
+
});
|
|
7219
|
+
case 8:
|
|
7220
|
+
_context3.n = 9;
|
|
7167
7221
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7168
7222
|
assetTo: updatedAssetTo,
|
|
7169
7223
|
fees: extractedFees
|
|
7170
7224
|
}));
|
|
7171
|
-
case
|
|
7225
|
+
case 9:
|
|
7172
7226
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7173
7227
|
secondCall = _yield$createXcmAndCa2.call;
|
|
7174
|
-
_context3.n =
|
|
7228
|
+
_context3.n = 10;
|
|
7175
7229
|
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7176
7230
|
tx: api.callTxMethod(secondCall)
|
|
7177
7231
|
}));
|
|
7178
|
-
case
|
|
7232
|
+
case 10:
|
|
7179
7233
|
secondDryRunResult = _context3.v;
|
|
7180
7234
|
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7181
7235
|
isOnExchangeChain = chain === exchangeChain;
|
|
@@ -7190,27 +7244,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7190
7244
|
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7191
7245
|
// If the final fees are different, we might need one more iteration
|
|
7192
7246
|
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7193
|
-
_context3.n =
|
|
7247
|
+
_context3.n = 13;
|
|
7194
7248
|
break;
|
|
7195
7249
|
}
|
|
7196
7250
|
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7197
|
-
_context3.n =
|
|
7251
|
+
_context3.n = 11;
|
|
7198
7252
|
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7199
|
-
case
|
|
7253
|
+
case 11:
|
|
7200
7254
|
finalMinAmountOut = _context3.v;
|
|
7201
7255
|
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7202
7256
|
amount: finalMinAmountOut.toString()
|
|
7203
7257
|
});
|
|
7204
|
-
_context3.n =
|
|
7258
|
+
_context3.n = 12;
|
|
7205
7259
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7206
7260
|
assetTo: finalAssetTo,
|
|
7207
7261
|
fees: finalFees
|
|
7208
7262
|
}));
|
|
7209
|
-
case
|
|
7263
|
+
case 12:
|
|
7210
7264
|
_yield$createXcmAndCa3 = _context3.v;
|
|
7211
7265
|
finalCall = _yield$createXcmAndCa3.call;
|
|
7212
7266
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7213
|
-
case
|
|
7267
|
+
case 13:
|
|
7214
7268
|
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7215
7269
|
}
|
|
7216
7270
|
}, _callee3);
|
|
@@ -8505,7 +8559,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
8505
8559
|
key: "transferPolkadotXCM",
|
|
8506
8560
|
value: function () {
|
|
8507
8561
|
var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
|
|
8508
|
-
var api, scenario, asset, destination, feeAsset, overriddenAsset, isNativeAsset, isNativeFeeAsset, isEthereumAsset, isTrusted, isDotReserveAh, method, modifiedInput, _t, _t2;
|
|
8562
|
+
var api, scenario, asset, destination, feeAsset, overriddenAsset, isNativeAsset, isNativeFeeAsset, isEthereumAsset, CHAINS_SUPPORT_DOT_TRANSFER, isTrusted, isDotReserveAh, method, modifiedInput, _t, _t2;
|
|
8509
8563
|
return _regenerator().w(function (_context3) {
|
|
8510
8564
|
while (1) switch (_context3.n) {
|
|
8511
8565
|
case 0:
|
|
@@ -8570,8 +8624,9 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
8570
8624
|
}
|
|
8571
8625
|
return _context3.a(2, this.handleLocalReserveTransfer(input, true));
|
|
8572
8626
|
case 9:
|
|
8627
|
+
CHAINS_SUPPORT_DOT_TRANSFER = new Set(['Hydration', 'Polimec', 'Moonbeam', 'BifrostPolkadot', 'PeoplePolkadot', 'Ajuna']);
|
|
8573
8628
|
isTrusted = !isTMultiLocation(destination) && isSystemChain(destination);
|
|
8574
|
-
isDotReserveAh = !isTMultiLocation(destination) &&
|
|
8629
|
+
isDotReserveAh = !isTMultiLocation(destination) && CHAINS_SUPPORT_DOT_TRANSFER.has(destination);
|
|
8575
8630
|
if (!(scenario === 'ParaToPara' && asset.symbol === this.getNativeAssetSymbol() && !isForeignAsset(asset) && !isDotReserveAh && !isTrusted)) {
|
|
8576
8631
|
_context3.n = 10;
|
|
8577
8632
|
break;
|
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",
|