@rhea-finance/confidential-swap 0.3.0 → 0.3.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 CHANGED
@@ -646,7 +646,7 @@ var HttpConfidentialApi = class {
646
646
  proxy;
647
647
  indexer;
648
648
  appFees;
649
- async request(url, method = "GET", body, token, signal) {
649
+ async request(url, method = "GET", body, token, signal, auth = "bearer") {
650
650
  throwIfAborted(signal);
651
651
  const timeout = AbortSignal.timeout(this.config.requestTimeoutMs ?? 3e4);
652
652
  const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
@@ -654,7 +654,12 @@ var HttpConfidentialApi = class {
654
654
  const response = await this.fetcher(url, {
655
655
  method,
656
656
  signal: combined,
657
- headers: { Accept: "application/json", ...body !== void 0 ? { "Content-Type": "application/json" } : {}, ...token ? { Authorization: `Bearer ${token}` } : {} },
657
+ headers: {
658
+ Accept: "application/json",
659
+ ...body !== void 0 ? { "Content-Type": "application/json" } : {},
660
+ ...token && auth === "bearer" ? { Authorization: `Bearer ${token}` } : {},
661
+ ...token && auth === "authentication" ? { Authentication: token } : {}
662
+ },
658
663
  ...body !== void 0 ? { body: JSON.stringify(body) } : {}
659
664
  });
660
665
  const content = await response.text();
@@ -782,8 +787,8 @@ var HttpConfidentialApi = class {
782
787
  const data = record(await this.request(`${this.proxy}/submit-intent`, "POST", { type: "swap_transfer", signedData }, void 0, signal));
783
788
  return text(data.intentHash, "Intent hash");
784
789
  }
785
- async privateRequest(path, method, body, token, signal) {
786
- const data = await this.request(`${this.indexer}/v3/private/${path}`, method, body, token, signal);
790
+ async privateRequest(path, method, body, token, signal, auth = "bearer") {
791
+ const data = await this.request(`${this.indexer}/v3/private/${path}`, method, body, token, signal, auth);
787
792
  if (data && typeof data === "object" && "code" in data) {
788
793
  const envelope = record(data);
789
794
  responseAssert(envelope.code === 0, "Indexer returned an unsuccessful envelope.");
@@ -792,7 +797,14 @@ var HttpConfidentialApi = class {
792
797
  return data;
793
798
  }
794
799
  async submitWithdraws(request, token, signal) {
795
- const data = record(await this.privateRequest("withdraws", "POST", request, this.config.withdrawAuthorization === "bearer" ? token : void 0, signal));
800
+ const data = record(await this.privateRequest(
801
+ "withdraws",
802
+ "POST",
803
+ request,
804
+ this.config.withdrawAuthorization === "bearer" ? token : void 0,
805
+ signal,
806
+ "authentication"
807
+ ));
796
808
  return text(data.order_id, "Private order id");
797
809
  }
798
810
  async getStatus(address, memo, signal) {
@@ -987,12 +999,6 @@ var SessionManager = class {
987
999
  };
988
1000
 
989
1001
  // src/quote.ts
990
- function assertFundingQuoteWithinSlippage(baselineMinOut, nextAmountOut) {
991
- assert(
992
- nextAmountOut >= baselineMinOut,
993
- "Funding quote moved beyond max slippage."
994
- );
995
- }
996
1002
  function aggregateWithdrawalAppFee(quotes, assetId) {
997
1003
  if (quotes.length === 0 || quotes.some((quote) => !quote.quoteRequest?.amount || !Array.isArray(quote.quoteRequest.appFees))) return void 0;
998
1004
  let totalInput = 0n;
@@ -1054,10 +1060,9 @@ async function quoteDepositAndWithdrawals(params) {
1054
1060
  slippageBps: req.slippageBps
1055
1061
  };
1056
1062
  const initialSwapQuote = await deps.swap.quote(clone(swapRequest), signal);
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({
1063
+ raw(initialSwapQuote.amountOut);
1064
+ assert(raw(initialSwapQuote.minAmountOut) <= raw(initialSwapQuote.amountOut), "Invalid funding swap minimum output.");
1065
+ depositQuote = await deps.api.quote({
1061
1066
  ...base,
1062
1067
  amount: initialSwapQuote.amountOut,
1063
1068
  refundTo: signerId,
@@ -1066,33 +1071,11 @@ async function quoteDepositAndWithdrawals(params) {
1066
1071
  swapType: "FLEX_INPUT",
1067
1072
  dry: false
1068
1073
  }, signal);
1069
- validateQuote(seededDeposit, true);
1070
- swapRequest = { ...swapRequest, recipient: seededDeposit.quote.depositAddress };
1074
+ validateQuote(depositQuote, true);
1075
+ swapRequest = { ...swapRequest, recipient: depositQuote.quote.depositAddress };
1071
1076
  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 {
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
- }
1077
+ raw(swapQuote.amountOut);
1078
+ assert(raw(swapQuote.minAmountOut) <= raw(swapQuote.amountOut), "Invalid funding swap minimum output.");
1096
1079
  fundingAmount = swapQuote.amountOut;
1097
1080
  }
1098
1081
  }