@rhea-finance/confidential-swap 0.2.8 → 0.3.0
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 +36 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -987,6 +987,12 @@ var SessionManager = class {
|
|
|
987
987
|
};
|
|
988
988
|
|
|
989
989
|
// src/quote.ts
|
|
990
|
+
function assertFundingQuoteWithinSlippage(baselineMinOut, nextAmountOut) {
|
|
991
|
+
assert(
|
|
992
|
+
nextAmountOut >= baselineMinOut,
|
|
993
|
+
"Funding quote moved beyond max slippage."
|
|
994
|
+
);
|
|
995
|
+
}
|
|
990
996
|
function aggregateWithdrawalAppFee(quotes, assetId) {
|
|
991
997
|
if (quotes.length === 0 || quotes.some((quote) => !quote.quoteRequest?.amount || !Array.isArray(quote.quoteRequest.appFees))) return void 0;
|
|
992
998
|
let totalInput = 0n;
|
|
@@ -1048,9 +1054,10 @@ async function quoteDepositAndWithdrawals(params) {
|
|
|
1048
1054
|
slippageBps: req.slippageBps
|
|
1049
1055
|
};
|
|
1050
1056
|
const initialSwapQuote = await deps.swap.quote(clone(swapRequest), signal);
|
|
1051
|
-
raw(initialSwapQuote.amountOut);
|
|
1052
|
-
|
|
1053
|
-
|
|
1057
|
+
const baselineOut = raw(initialSwapQuote.amountOut);
|
|
1058
|
+
const baselineMinOut = raw(initialSwapQuote.minAmountOut);
|
|
1059
|
+
assert(baselineMinOut <= baselineOut, "Invalid funding swap minimum output.");
|
|
1060
|
+
const seededDeposit = await deps.api.quote({
|
|
1054
1061
|
...base,
|
|
1055
1062
|
amount: initialSwapQuote.amountOut,
|
|
1056
1063
|
refundTo: signerId,
|
|
@@ -1059,11 +1066,33 @@ async function quoteDepositAndWithdrawals(params) {
|
|
|
1059
1066
|
swapType: "FLEX_INPUT",
|
|
1060
1067
|
dry: false
|
|
1061
1068
|
}, signal);
|
|
1062
|
-
validateQuote(
|
|
1063
|
-
swapRequest = { ...swapRequest, recipient:
|
|
1069
|
+
validateQuote(seededDeposit, true);
|
|
1070
|
+
swapRequest = { ...swapRequest, recipient: seededDeposit.quote.depositAddress };
|
|
1064
1071
|
swapQuote = await deps.swap.quote(clone(swapRequest), signal);
|
|
1065
|
-
raw(swapQuote.amountOut);
|
|
1066
|
-
assert(raw(swapQuote.minAmountOut) <=
|
|
1072
|
+
const latestOut = raw(swapQuote.amountOut);
|
|
1073
|
+
assert(raw(swapQuote.minAmountOut) <= latestOut, "Invalid funding swap minimum output.");
|
|
1074
|
+
assertFundingQuoteWithinSlippage(baselineMinOut, latestOut);
|
|
1075
|
+
if (latestOut === baselineOut) {
|
|
1076
|
+
depositQuote = seededDeposit;
|
|
1077
|
+
} else {
|
|
1078
|
+
depositQuote = await deps.api.quote({
|
|
1079
|
+
...base,
|
|
1080
|
+
amount: swapQuote.amountOut,
|
|
1081
|
+
refundTo: signerId,
|
|
1082
|
+
refundType: "CONFIDENTIAL_INTENTS",
|
|
1083
|
+
depositType: "ORIGIN_CHAIN",
|
|
1084
|
+
swapType: "FLEX_INPUT",
|
|
1085
|
+
dry: false
|
|
1086
|
+
}, signal);
|
|
1087
|
+
validateQuote(depositQuote, true);
|
|
1088
|
+
if (depositQuote.quote.depositAddress !== seededDeposit.quote.depositAddress) {
|
|
1089
|
+
swapRequest = { ...swapRequest, recipient: depositQuote.quote.depositAddress };
|
|
1090
|
+
swapQuote = await deps.swap.quote(clone(swapRequest), signal);
|
|
1091
|
+
const boundOut = raw(swapQuote.amountOut);
|
|
1092
|
+
assert(raw(swapQuote.minAmountOut) <= boundOut, "Invalid funding swap minimum output.");
|
|
1093
|
+
assertFundingQuoteWithinSlippage(baselineMinOut, boundOut);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1067
1096
|
fundingAmount = swapQuote.amountOut;
|
|
1068
1097
|
}
|
|
1069
1098
|
}
|