@rhea-finance/confidential-swap 0.2.9 → 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 CHANGED
@@ -987,7 +987,6 @@ var SessionManager = class {
987
987
  };
988
988
 
989
989
  // src/quote.ts
990
- var MAX_FLEX_FUNDING_REQUOTES = 3;
991
990
  function assertFundingQuoteWithinSlippage(baselineMinOut, nextAmountOut) {
992
991
  assert(
993
992
  nextAmountOut >= baselineMinOut,
@@ -1058,14 +1057,27 @@ async function quoteDepositAndWithdrawals(params) {
1058
1057
  const baselineOut = raw(initialSwapQuote.amountOut);
1059
1058
  const baselineMinOut = raw(initialSwapQuote.minAmountOut);
1060
1059
  assert(baselineMinOut <= baselineOut, "Invalid funding swap minimum output.");
1061
- let latestDepositAmountIn = initialSwapQuote.amountOut;
1062
- let covered = false;
1063
- for (let attempt = 0; attempt < MAX_FLEX_FUNDING_REQUOTES; attempt++) {
1060
+ const seededDeposit = await deps.api.quote({
1061
+ ...base,
1062
+ amount: initialSwapQuote.amountOut,
1063
+ refundTo: signerId,
1064
+ refundType: "CONFIDENTIAL_INTENTS",
1065
+ depositType: "ORIGIN_CHAIN",
1066
+ swapType: "FLEX_INPUT",
1067
+ dry: false
1068
+ }, signal);
1069
+ validateQuote(seededDeposit, true);
1070
+ swapRequest = { ...swapRequest, recipient: seededDeposit.quote.depositAddress };
1071
+ swapQuote = await deps.swap.quote(clone(swapRequest), signal);
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 {
1064
1078
  depositQuote = await deps.api.quote({
1065
1079
  ...base,
1066
- // Always the most recent funding-swap amountOut — never stick on pass 1
1067
- // after a requote.
1068
- amount: latestDepositAmountIn,
1080
+ amount: swapQuote.amountOut,
1069
1081
  refundTo: signerId,
1070
1082
  refundType: "CONFIDENTIAL_INTENTS",
1071
1083
  depositType: "ORIGIN_CHAIN",
@@ -1073,24 +1085,15 @@ async function quoteDepositAndWithdrawals(params) {
1073
1085
  dry: false
1074
1086
  }, signal);
1075
1087
  validateQuote(depositQuote, true);
1076
- swapRequest = { ...swapRequest, recipient: depositQuote.quote.depositAddress };
1077
- swapQuote = await deps.swap.quote(clone(swapRequest), signal);
1078
- const nextOut = raw(swapQuote.amountOut);
1079
- const nextMinOut = raw(swapQuote.minAmountOut);
1080
- assert(nextMinOut <= nextOut, "Invalid funding swap minimum output.");
1081
- assertFundingQuoteWithinSlippage(baselineMinOut, nextOut);
1082
- const flexMinIn = depositQuote.quote.minAmountIn !== void 0 ? raw(depositQuote.quote.minAmountIn) : void 0;
1083
- if (flexMinIn === void 0 || nextMinOut >= flexMinIn) {
1084
- fundingAmount = swapQuote.amountOut;
1085
- covered = true;
1086
- break;
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);
1087
1094
  }
1088
- latestDepositAmountIn = swapQuote.amountOut;
1089
1095
  }
1090
- assert(
1091
- covered && swapQuote,
1092
- "Final funding quote does not cover FLEX minimum input."
1093
- );
1096
+ fundingAmount = swapQuote.amountOut;
1094
1097
  }
1095
1098
  }
1096
1099
  const shares = splitConfidentialRawAmount(fundingAmount, req.recipients.length, randomValues);