@rhea-finance/confidential-swap 0.3.1 → 0.3.3
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 +29 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -654,7 +654,11 @@ var HttpConfidentialApi = class {
|
|
|
654
654
|
const response = await this.fetcher(url, {
|
|
655
655
|
method,
|
|
656
656
|
signal: combined,
|
|
657
|
-
headers: {
|
|
657
|
+
headers: {
|
|
658
|
+
Accept: "application/json",
|
|
659
|
+
...body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
660
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
661
|
+
},
|
|
658
662
|
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
659
663
|
});
|
|
660
664
|
const content = await response.text();
|
|
@@ -792,7 +796,13 @@ var HttpConfidentialApi = class {
|
|
|
792
796
|
return data;
|
|
793
797
|
}
|
|
794
798
|
async submitWithdraws(request, token, signal) {
|
|
795
|
-
const data = record(await this.privateRequest(
|
|
799
|
+
const data = record(await this.privateRequest(
|
|
800
|
+
"withdraws",
|
|
801
|
+
"POST",
|
|
802
|
+
request,
|
|
803
|
+
this.config.withdrawAuthorization === "bearer" ? token : void 0,
|
|
804
|
+
signal
|
|
805
|
+
));
|
|
796
806
|
return text(data.order_id, "Private order id");
|
|
797
807
|
}
|
|
798
808
|
async getStatus(address, memo, signal) {
|
|
@@ -987,26 +997,6 @@ var SessionManager = class {
|
|
|
987
997
|
};
|
|
988
998
|
|
|
989
999
|
// 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
1000
|
function aggregateWithdrawalAppFee(quotes, assetId) {
|
|
1011
1001
|
if (quotes.length === 0 || quotes.some((quote) => !quote.quoteRequest?.amount || !Array.isArray(quote.quoteRequest.appFees))) return void 0;
|
|
1012
1002
|
let totalInput = 0n;
|
|
@@ -1068,40 +1058,23 @@ async function quoteDepositAndWithdrawals(params) {
|
|
|
1068
1058
|
slippageBps: req.slippageBps
|
|
1069
1059
|
};
|
|
1070
1060
|
const initialSwapQuote = await deps.swap.quote(clone(swapRequest), signal);
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
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
|
-
}
|
|
1061
|
+
raw(initialSwapQuote.amountOut);
|
|
1062
|
+
assert(raw(initialSwapQuote.minAmountOut) <= raw(initialSwapQuote.amountOut), "Invalid funding swap minimum output.");
|
|
1063
|
+
depositQuote = await deps.api.quote({
|
|
1064
|
+
...base,
|
|
1065
|
+
amount: initialSwapQuote.amountOut,
|
|
1066
|
+
refundTo: signerId,
|
|
1067
|
+
refundType: "CONFIDENTIAL_INTENTS",
|
|
1068
|
+
depositType: "ORIGIN_CHAIN",
|
|
1069
|
+
swapType: "FLEX_INPUT",
|
|
1070
|
+
dry: false
|
|
1071
|
+
}, signal);
|
|
1072
|
+
validateQuote(depositQuote, true);
|
|
1073
|
+
swapRequest = { ...swapRequest, recipient: depositQuote.quote.depositAddress };
|
|
1074
|
+
swapQuote = await deps.swap.quote(clone(swapRequest), signal);
|
|
1075
|
+
raw(swapQuote.amountOut);
|
|
1076
|
+
assert(raw(swapQuote.minAmountOut) <= raw(swapQuote.amountOut), "Invalid funding swap minimum output.");
|
|
1077
|
+
fundingAmount = swapQuote.amountOut;
|
|
1105
1078
|
}
|
|
1106
1079
|
}
|
|
1107
1080
|
const shares = splitConfidentialRawAmount(fundingAmount, req.recipients.length, randomValues);
|