@rhea-finance/confidential-swap 0.3.1 → 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,26 +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
- function swapQuoteRecipient(quote) {
997
- const data = quote.data;
998
- return String(data?.request?.recipient || "").trim();
999
- }
1000
- function depositQuoteForAddress(address, amount) {
1001
- return {
1002
- quote: {
1003
- amountIn: amount,
1004
- amountOut: amount,
1005
- minAmountOut: amount,
1006
- depositAddress: address
1007
- }
1008
- };
1009
- }
1010
1002
  function aggregateWithdrawalAppFee(quotes, assetId) {
1011
1003
  if (quotes.length === 0 || quotes.some((quote) => !quote.quoteRequest?.amount || !Array.isArray(quote.quoteRequest.appFees))) return void 0;
1012
1004
  let totalInput = 0n;
@@ -1068,40 +1060,23 @@ async function quoteDepositAndWithdrawals(params) {
1068
1060
  slippageBps: req.slippageBps
1069
1061
  };
1070
1062
  const initialSwapQuote = await deps.swap.quote(clone(swapRequest), signal);
1071
- const baselineOut = raw(initialSwapQuote.amountOut);
1072
- const baselineMinOut = raw(initialSwapQuote.minAmountOut);
1073
- assert(baselineMinOut <= baselineOut, "Invalid funding swap minimum output.");
1074
- const knownRecipient = swapQuoteRecipient(initialSwapQuote);
1075
- if (knownRecipient) {
1076
- swapRequest = { ...swapRequest, recipient: knownRecipient };
1077
- swapQuote = await deps.swap.quote(clone(swapRequest), signal);
1078
- const latestOut = raw(swapQuote.amountOut);
1079
- assert(raw(swapQuote.minAmountOut) <= latestOut, "Invalid funding swap minimum output.");
1080
- assertFundingQuoteWithinSlippage(baselineMinOut, latestOut);
1081
- fundingAmount = swapQuote.amountOut;
1082
- depositQuote = depositQuoteForAddress(knownRecipient, swapQuote.amountOut);
1083
- } else {
1084
- const seededDeposit = await deps.api.quote({
1085
- ...base,
1086
- amount: initialSwapQuote.amountOut,
1087
- refundTo: signerId,
1088
- refundType: "CONFIDENTIAL_INTENTS",
1089
- depositType: "ORIGIN_CHAIN",
1090
- swapType: "FLEX_INPUT",
1091
- dry: false
1092
- }, signal);
1093
- validateQuote(seededDeposit, true);
1094
- swapRequest = { ...swapRequest, recipient: seededDeposit.quote.depositAddress };
1095
- swapQuote = await deps.swap.quote(clone(swapRequest), signal);
1096
- const latestOut = raw(swapQuote.amountOut);
1097
- assert(raw(swapQuote.minAmountOut) <= latestOut, "Invalid funding swap minimum output.");
1098
- assertFundingQuoteWithinSlippage(baselineMinOut, latestOut);
1099
- fundingAmount = swapQuote.amountOut;
1100
- depositQuote = {
1101
- ...seededDeposit,
1102
- quote: { ...seededDeposit.quote, amountIn: swapQuote.amountOut }
1103
- };
1104
- }
1063
+ raw(initialSwapQuote.amountOut);
1064
+ assert(raw(initialSwapQuote.minAmountOut) <= raw(initialSwapQuote.amountOut), "Invalid funding swap minimum output.");
1065
+ depositQuote = await deps.api.quote({
1066
+ ...base,
1067
+ amount: initialSwapQuote.amountOut,
1068
+ refundTo: signerId,
1069
+ refundType: "CONFIDENTIAL_INTENTS",
1070
+ depositType: "ORIGIN_CHAIN",
1071
+ swapType: "FLEX_INPUT",
1072
+ dry: false
1073
+ }, signal);
1074
+ validateQuote(depositQuote, true);
1075
+ swapRequest = { ...swapRequest, recipient: depositQuote.quote.depositAddress };
1076
+ swapQuote = await deps.swap.quote(clone(swapRequest), signal);
1077
+ raw(swapQuote.amountOut);
1078
+ assert(raw(swapQuote.minAmountOut) <= raw(swapQuote.amountOut), "Invalid funding swap minimum output.");
1079
+ fundingAmount = swapQuote.amountOut;
1105
1080
  }
1106
1081
  }
1107
1082
  const shares = splitConfidentialRawAmount(fundingAmount, req.recipients.length, randomValues);