@compass-labs/api-sdk 2.2.79 → 2.2.80
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/README.md +5 -3
- package/codeSamples_typescript.yaml +6 -0
- package/dist/commonjs/funcs/creditCreditRebalance.d.ts +45 -0
- package/dist/commonjs/funcs/creditCreditRebalance.d.ts.map +1 -0
- package/dist/commonjs/funcs/creditCreditRebalance.js +146 -0
- package/dist/commonjs/funcs/creditCreditRebalance.js.map +1 -0
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/commonjs/models/components/creditrebalancepreview.d.ts +38 -0
- package/dist/commonjs/models/components/creditrebalancepreview.d.ts.map +1 -0
- package/dist/commonjs/models/components/creditrebalancepreview.js +67 -0
- package/dist/commonjs/models/components/creditrebalancepreview.js.map +1 -0
- package/dist/commonjs/models/components/creditrebalancerequest.d.ts +54 -0
- package/dist/commonjs/models/components/creditrebalancerequest.d.ts.map +1 -0
- package/dist/commonjs/models/components/creditrebalancerequest.js +67 -0
- package/dist/commonjs/models/components/creditrebalancerequest.js.map +1 -0
- package/dist/commonjs/models/components/creditrebalanceresponse.d.ts +27 -0
- package/dist/commonjs/models/components/creditrebalanceresponse.d.ts.map +1 -0
- package/dist/commonjs/models/components/creditrebalanceresponse.js +61 -0
- package/dist/commonjs/models/components/creditrebalanceresponse.js.map +1 -0
- package/dist/commonjs/models/components/creditunlooprequest.d.ts +4 -4
- package/dist/commonjs/models/components/creditunlooprequest.d.ts.map +1 -1
- package/dist/commonjs/models/components/creditunlooprequest.js +5 -5
- package/dist/commonjs/models/components/creditunlooprequest.js.map +1 -1
- package/dist/commonjs/models/components/index.d.ts +7 -0
- package/dist/commonjs/models/components/index.d.ts.map +1 -1
- package/dist/commonjs/models/components/index.js +7 -0
- package/dist/commonjs/models/components/index.js.map +1 -1
- package/dist/commonjs/models/components/loopedpositioncurrentstate.d.ts +4 -4
- package/dist/commonjs/models/components/loopedpositioncurrentstate.d.ts.map +1 -1
- package/dist/commonjs/models/components/loopedpositioncurrentstate.js +5 -4
- package/dist/commonjs/models/components/loopedpositioncurrentstate.js.map +1 -1
- package/dist/commonjs/models/components/rebalancedirection.d.ts +21 -0
- package/dist/commonjs/models/components/rebalancedirection.d.ts.map +1 -0
- package/dist/commonjs/models/components/rebalancedirection.js +55 -0
- package/dist/commonjs/models/components/rebalancedirection.js.map +1 -0
- package/dist/commonjs/models/components/rebalancetarget.d.ts +97 -0
- package/dist/commonjs/models/components/rebalancetarget.d.ts.map +1 -0
- package/dist/commonjs/models/components/rebalancetarget.js +85 -0
- package/dist/commonjs/models/components/rebalancetarget.js.map +1 -0
- package/dist/commonjs/models/components/rebalancetargetpreview.d.ts +96 -0
- package/dist/commonjs/models/components/rebalancetargetpreview.d.ts.map +1 -0
- package/dist/commonjs/models/components/rebalancetargetpreview.js +92 -0
- package/dist/commonjs/models/components/rebalancetargetpreview.js.map +1 -0
- package/dist/commonjs/models/components/routingswappreview.d.ts +32 -0
- package/dist/commonjs/models/components/routingswappreview.d.ts.map +1 -0
- package/dist/commonjs/models/components/routingswappreview.js +61 -0
- package/dist/commonjs/models/components/routingswappreview.js.map +1 -0
- package/dist/commonjs/sdk/credit.d.ts +34 -0
- package/dist/commonjs/sdk/credit.d.ts.map +1 -1
- package/dist/commonjs/sdk/credit.js +37 -0
- package/dist/commonjs/sdk/credit.js.map +1 -1
- package/dist/esm/funcs/creditCreditRebalance.d.ts +45 -0
- package/dist/esm/funcs/creditCreditRebalance.d.ts.map +1 -0
- package/dist/esm/funcs/creditCreditRebalance.js +110 -0
- package/dist/esm/funcs/creditCreditRebalance.js.map +1 -0
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/models/components/creditrebalancepreview.d.ts +38 -0
- package/dist/esm/models/components/creditrebalancepreview.d.ts.map +1 -0
- package/dist/esm/models/components/creditrebalancepreview.js +30 -0
- package/dist/esm/models/components/creditrebalancepreview.js.map +1 -0
- package/dist/esm/models/components/creditrebalancerequest.d.ts +54 -0
- package/dist/esm/models/components/creditrebalancerequest.d.ts.map +1 -0
- package/dist/esm/models/components/creditrebalancerequest.js +29 -0
- package/dist/esm/models/components/creditrebalancerequest.js.map +1 -0
- package/dist/esm/models/components/creditrebalanceresponse.d.ts +27 -0
- package/dist/esm/models/components/creditrebalanceresponse.d.ts.map +1 -0
- package/dist/esm/models/components/creditrebalanceresponse.js +24 -0
- package/dist/esm/models/components/creditrebalanceresponse.js.map +1 -0
- package/dist/esm/models/components/creditunlooprequest.d.ts +4 -4
- package/dist/esm/models/components/creditunlooprequest.d.ts.map +1 -1
- package/dist/esm/models/components/creditunlooprequest.js +3 -3
- package/dist/esm/models/components/creditunlooprequest.js.map +1 -1
- package/dist/esm/models/components/index.d.ts +7 -0
- package/dist/esm/models/components/index.d.ts.map +1 -1
- package/dist/esm/models/components/index.js +7 -0
- package/dist/esm/models/components/index.js.map +1 -1
- package/dist/esm/models/components/loopedpositioncurrentstate.d.ts +4 -4
- package/dist/esm/models/components/loopedpositioncurrentstate.d.ts.map +1 -1
- package/dist/esm/models/components/loopedpositioncurrentstate.js +4 -3
- package/dist/esm/models/components/loopedpositioncurrentstate.js.map +1 -1
- package/dist/esm/models/components/rebalancedirection.d.ts +21 -0
- package/dist/esm/models/components/rebalancedirection.d.ts.map +1 -0
- package/dist/esm/models/components/rebalancedirection.js +19 -0
- package/dist/esm/models/components/rebalancedirection.js.map +1 -0
- package/dist/esm/models/components/rebalancetarget.d.ts +97 -0
- package/dist/esm/models/components/rebalancetarget.d.ts.map +1 -0
- package/dist/esm/models/components/rebalancetarget.js +45 -0
- package/dist/esm/models/components/rebalancetarget.js.map +1 -0
- package/dist/esm/models/components/rebalancetargetpreview.d.ts +96 -0
- package/dist/esm/models/components/rebalancetargetpreview.d.ts.map +1 -0
- package/dist/esm/models/components/rebalancetargetpreview.js +55 -0
- package/dist/esm/models/components/rebalancetargetpreview.js.map +1 -0
- package/dist/esm/models/components/routingswappreview.d.ts +32 -0
- package/dist/esm/models/components/routingswappreview.d.ts.map +1 -0
- package/dist/esm/models/components/routingswappreview.js +24 -0
- package/dist/esm/models/components/routingswappreview.js.map +1 -0
- package/dist/esm/sdk/credit.d.ts +34 -0
- package/dist/esm/sdk/credit.d.ts.map +1 -1
- package/dist/esm/sdk/credit.js +37 -0
- package/dist/esm/sdk/credit.js.map +1 -1
- package/docs/models/components/creditrebalancepreview.md +44 -0
- package/docs/models/components/creditrebalancerequest.md +37 -0
- package/docs/models/components/creditrebalancerequestmaxslippagepercent.md +19 -0
- package/docs/models/components/creditrebalanceresponse.md +27 -0
- package/docs/models/components/creditunlooprequest.md +1 -1
- package/docs/models/components/{targetmultiplier.md → creditunlooprequesttargetmultiplier.md} +1 -1
- package/docs/models/components/loopedpositioncurrentstate.md +1 -1
- package/docs/models/components/{healthfactorscope.md → loopedpositioncurrentstatehealthfactorscope.md} +3 -3
- package/docs/models/components/rebalancedirection.md +17 -0
- package/docs/models/components/rebalancetarget.md +32 -0
- package/docs/models/components/rebalancetargetmaxslippagepercent.md +19 -0
- package/docs/models/components/rebalancetargetpreview.md +44 -0
- package/docs/models/components/rebalancetargetpreviewhealthfactorscope.md +17 -0
- package/docs/models/components/rebalancetargettargetmultiplier.md +19 -0
- package/docs/models/components/routingswappreview.md +27 -0
- package/docs/models/components/targetequityusd.md +19 -0
- package/docs/sdks/credit/README.md +124 -0
- package/openapi_prepped_for_speakeasy.json +465 -0
- package/package.json +1 -1
- package/src/funcs/creditCreditRebalance.ts +198 -0
- package/src/lib/config.ts +2 -2
- package/src/models/components/creditrebalancepreview.ts +80 -0
- package/src/models/components/creditrebalancerequest.ts +104 -0
- package/src/models/components/creditrebalanceresponse.ts +65 -0
- package/src/models/components/creditunlooprequest.ts +10 -8
- package/src/models/components/index.ts +7 -0
- package/src/models/components/loopedpositioncurrentstate.ts +10 -7
- package/src/models/components/rebalancedirection.ts +28 -0
- package/src/models/components/rebalancetarget.ts +178 -0
- package/src/models/components/rebalancetargetpreview.ts +163 -0
- package/src/models/components/routingswappreview.ts +64 -0
- package/src/sdk/credit.ts +45 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CompassApiSDKCore } from "../core.js";
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
|
+
import { matchStatusCode } from "../lib/http.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
13
|
+
import { pathToFunc } from "../lib/url.js";
|
|
14
|
+
import * as components from "../models/components/index.js";
|
|
15
|
+
import { CompassAPISDKError } from "../models/errors/compassapisdkerror.js";
|
|
16
|
+
import {
|
|
17
|
+
ConnectionError,
|
|
18
|
+
InvalidRequestError,
|
|
19
|
+
RequestAbortedError,
|
|
20
|
+
RequestTimeoutError,
|
|
21
|
+
UnexpectedClientError,
|
|
22
|
+
} from "../models/errors/httpclienterrors.js";
|
|
23
|
+
import * as errors from "../models/errors/index.js";
|
|
24
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
25
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { Result } from "../types/fp.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Rebalance the leveraged credit book
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Rebalance the leveraged credit book in ONE atomic transaction.
|
|
34
|
+
*
|
|
35
|
+
* List only the positions to change — anything not named is left untouched;
|
|
36
|
+
* remove a position with close=true. Each target states an end state:
|
|
37
|
+
* target_equity_usd (net USD committed) × target_multiplier.
|
|
38
|
+
*
|
|
39
|
+
* Releasing targets run first (each unwind/delever frees tokens into the Credit
|
|
40
|
+
* Account), the freed tokens are then routed by swaps at a GUARANTEED minimum
|
|
41
|
+
* output (enforced on-chain), and consuming targets run last — so moving a
|
|
42
|
+
* levered position between markets, token pairs, or protocols (Aave ↔ Morpho) is
|
|
43
|
+
* simply a close plus an open in the same transaction.
|
|
44
|
+
*
|
|
45
|
+
* Net book growth is funded from the Credit Account's existing idle balance —
|
|
46
|
+
* fund it first via /v2/credit/transfer; a net release stays in the Credit
|
|
47
|
+
* Account as idle balance. Any swap surplus above the guaranteed floors also
|
|
48
|
+
* stays in the Credit Account (preview.estimated_max_dust) — recoverable, never
|
|
49
|
+
* lost.
|
|
50
|
+
*
|
|
51
|
+
* A book already at its target returns transaction: null with the preview — the
|
|
52
|
+
* call is idempotent and safe to drive from a converge-to-target loop.
|
|
53
|
+
*
|
|
54
|
+
* A rebalance too large for one transaction is rejected with a 422 — split it
|
|
55
|
+
* into two calls. Every deleveraging step keeps the health factor ≥ 1.02 and
|
|
56
|
+
* every leveraging step respects the protocol's borrow limits; Aave targets share
|
|
57
|
+
* one account-level health factor, which the preview reports.
|
|
58
|
+
*
|
|
59
|
+
* For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect the
|
|
60
|
+
* current book via /v2/credit/looped_positions.
|
|
61
|
+
*/
|
|
62
|
+
export function creditCreditRebalance(
|
|
63
|
+
client: CompassApiSDKCore,
|
|
64
|
+
request: components.CreditRebalanceRequest,
|
|
65
|
+
options?: RequestOptions,
|
|
66
|
+
): APIPromise<
|
|
67
|
+
Result<
|
|
68
|
+
components.CreditRebalanceResponse,
|
|
69
|
+
| errors.HTTPValidationError
|
|
70
|
+
| CompassAPISDKError
|
|
71
|
+
| ResponseValidationError
|
|
72
|
+
| ConnectionError
|
|
73
|
+
| RequestAbortedError
|
|
74
|
+
| RequestTimeoutError
|
|
75
|
+
| InvalidRequestError
|
|
76
|
+
| UnexpectedClientError
|
|
77
|
+
| SDKValidationError
|
|
78
|
+
>
|
|
79
|
+
> {
|
|
80
|
+
return new APIPromise($do(
|
|
81
|
+
client,
|
|
82
|
+
request,
|
|
83
|
+
options,
|
|
84
|
+
));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function $do(
|
|
88
|
+
client: CompassApiSDKCore,
|
|
89
|
+
request: components.CreditRebalanceRequest,
|
|
90
|
+
options?: RequestOptions,
|
|
91
|
+
): Promise<
|
|
92
|
+
[
|
|
93
|
+
Result<
|
|
94
|
+
components.CreditRebalanceResponse,
|
|
95
|
+
| errors.HTTPValidationError
|
|
96
|
+
| CompassAPISDKError
|
|
97
|
+
| ResponseValidationError
|
|
98
|
+
| ConnectionError
|
|
99
|
+
| RequestAbortedError
|
|
100
|
+
| RequestTimeoutError
|
|
101
|
+
| InvalidRequestError
|
|
102
|
+
| UnexpectedClientError
|
|
103
|
+
| SDKValidationError
|
|
104
|
+
>,
|
|
105
|
+
APICall,
|
|
106
|
+
]
|
|
107
|
+
> {
|
|
108
|
+
const parsed = safeParse(
|
|
109
|
+
request,
|
|
110
|
+
(value) => components.CreditRebalanceRequest$outboundSchema.parse(value),
|
|
111
|
+
"Input validation failed",
|
|
112
|
+
);
|
|
113
|
+
if (!parsed.ok) {
|
|
114
|
+
return [parsed, { status: "invalid" }];
|
|
115
|
+
}
|
|
116
|
+
const payload = parsed.value;
|
|
117
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
118
|
+
|
|
119
|
+
const path = pathToFunc("/v2/credit/rebalance")();
|
|
120
|
+
|
|
121
|
+
const headers = new Headers(compactMap({
|
|
122
|
+
"Content-Type": "application/json",
|
|
123
|
+
Accept: "application/json",
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
const secConfig = await extractSecurity(client._options.apiKeyAuth);
|
|
127
|
+
const securityInput = secConfig == null ? {} : { apiKeyAuth: secConfig };
|
|
128
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
129
|
+
|
|
130
|
+
const context = {
|
|
131
|
+
options: client._options,
|
|
132
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
133
|
+
operationID: "v2_credit_rebalance",
|
|
134
|
+
oAuth2Scopes: null,
|
|
135
|
+
|
|
136
|
+
resolvedSecurity: requestSecurity,
|
|
137
|
+
|
|
138
|
+
securitySource: client._options.apiKeyAuth,
|
|
139
|
+
retryConfig: options?.retries
|
|
140
|
+
|| client._options.retryConfig
|
|
141
|
+
|| { strategy: "none" },
|
|
142
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const requestRes = client._createRequest(context, {
|
|
146
|
+
security: requestSecurity,
|
|
147
|
+
method: "POST",
|
|
148
|
+
baseURL: options?.serverURL,
|
|
149
|
+
path: path,
|
|
150
|
+
headers: headers,
|
|
151
|
+
body: body,
|
|
152
|
+
userAgent: client._options.userAgent,
|
|
153
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
154
|
+
}, options);
|
|
155
|
+
if (!requestRes.ok) {
|
|
156
|
+
return [requestRes, { status: "invalid" }];
|
|
157
|
+
}
|
|
158
|
+
const req = requestRes.value;
|
|
159
|
+
|
|
160
|
+
const doResult = await client._do(req, {
|
|
161
|
+
context,
|
|
162
|
+
isErrorStatusCode: (statusCode: number) =>
|
|
163
|
+
matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
|
|
164
|
+
retryConfig: context.retryConfig,
|
|
165
|
+
retryCodes: context.retryCodes,
|
|
166
|
+
});
|
|
167
|
+
if (!doResult.ok) {
|
|
168
|
+
return [doResult, { status: "request-error", request: req }];
|
|
169
|
+
}
|
|
170
|
+
const response = doResult.value;
|
|
171
|
+
|
|
172
|
+
const responseFields = {
|
|
173
|
+
HttpMeta: { Response: response, Request: req },
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const [result] = await M.match<
|
|
177
|
+
components.CreditRebalanceResponse,
|
|
178
|
+
| errors.HTTPValidationError
|
|
179
|
+
| CompassAPISDKError
|
|
180
|
+
| ResponseValidationError
|
|
181
|
+
| ConnectionError
|
|
182
|
+
| RequestAbortedError
|
|
183
|
+
| RequestTimeoutError
|
|
184
|
+
| InvalidRequestError
|
|
185
|
+
| UnexpectedClientError
|
|
186
|
+
| SDKValidationError
|
|
187
|
+
>(
|
|
188
|
+
M.json(200, components.CreditRebalanceResponse$inboundSchema),
|
|
189
|
+
M.jsonErr(422, errors.HTTPValidationError$inboundSchema),
|
|
190
|
+
M.fail("4XX"),
|
|
191
|
+
M.fail("5XX"),
|
|
192
|
+
)(response, req, { extraFields: responseFields });
|
|
193
|
+
if (!result.ok) {
|
|
194
|
+
return [result, { status: "complete", request: req, response }];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return [result, { status: "complete", request: req, response }];
|
|
198
|
+
}
|
package/src/lib/config.ts
CHANGED
|
@@ -62,7 +62,7 @@ export const SDK_METADATA = {
|
|
|
62
62
|
language: "typescript",
|
|
63
63
|
openapiDocVersion: "0.0.1",
|
|
64
64
|
sdkVersion: "2.0.0",
|
|
65
|
-
genVersion: "2.
|
|
65
|
+
genVersion: "2.916.2",
|
|
66
66
|
userAgent:
|
|
67
|
-
"speakeasy-sdk/typescript 2.0.0 2.
|
|
67
|
+
"speakeasy-sdk/typescript 2.0.0 2.916.2 0.0.1 @compass-labs/api-sdk",
|
|
68
68
|
} as const;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
9
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
10
|
+
import {
|
|
11
|
+
RebalanceTargetPreview,
|
|
12
|
+
RebalanceTargetPreview$inboundSchema,
|
|
13
|
+
} from "./rebalancetargetpreview.js";
|
|
14
|
+
import {
|
|
15
|
+
RoutingSwapPreview,
|
|
16
|
+
RoutingSwapPreview$inboundSchema,
|
|
17
|
+
} from "./routingswappreview.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Projected end state of the whole rebalance, computed on GUARANTEED swap floors.
|
|
21
|
+
*/
|
|
22
|
+
export type CreditRebalancePreview = {
|
|
23
|
+
/**
|
|
24
|
+
* Signed net equity moved: Σ(target − current equity, in USD) over the named targets. Positive = net book growth funded from the Credit Account's idle balance; negative = surplus equity released to idle. Truncated toward zero, so the reported magnitude is never larger than the true amount in either sign.
|
|
25
|
+
*/
|
|
26
|
+
netEquityMovedUsd: string;
|
|
27
|
+
/**
|
|
28
|
+
* Total on-chain legs across the whole transaction, including capital-routing swaps. A rebalance too large for one transaction is rejected with a 422.
|
|
29
|
+
*/
|
|
30
|
+
totalLegs: number;
|
|
31
|
+
/**
|
|
32
|
+
* The capital-routing swaps that move freed tokens between positions, at a guaranteed minimum output enforced on-chain.
|
|
33
|
+
*/
|
|
34
|
+
routingSwaps?: Array<RoutingSwapPreview> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Upper bound of surplus all swaps (per-target and routing) can leave in the Credit Account (sum of each swap's quote minus its guaranteed floor). It accumulates in the Credit Account, is recoverable, and is never lost.
|
|
37
|
+
*/
|
|
38
|
+
estimatedMaxDust: string;
|
|
39
|
+
/**
|
|
40
|
+
* Projected account-level Aave health factor after the rebalance — Aave collateral is pooled, so this is shared by every Aave target. Present whenever the end state holds any Aave collateral or debt; null for Morpho-only books. Never overstated at the 1.0 boundary.
|
|
41
|
+
*/
|
|
42
|
+
aaveAccountHealthFactor?: string | null | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Per-target end state, in the same order as the request targets.
|
|
45
|
+
*/
|
|
46
|
+
perTarget: Array<RebalanceTargetPreview>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** @internal */
|
|
50
|
+
export const CreditRebalancePreview$inboundSchema: z.ZodType<
|
|
51
|
+
CreditRebalancePreview,
|
|
52
|
+
z.ZodTypeDef,
|
|
53
|
+
unknown
|
|
54
|
+
> = z.object({
|
|
55
|
+
net_equity_moved_usd: z.string(),
|
|
56
|
+
total_legs: z.number().int(),
|
|
57
|
+
routing_swaps: z.array(RoutingSwapPreview$inboundSchema).optional(),
|
|
58
|
+
estimated_max_dust: z.string(),
|
|
59
|
+
aave_account_health_factor: z.nullable(z.string()).optional(),
|
|
60
|
+
per_target: z.array(RebalanceTargetPreview$inboundSchema),
|
|
61
|
+
}).transform((v) => {
|
|
62
|
+
return remap$(v, {
|
|
63
|
+
"net_equity_moved_usd": "netEquityMovedUsd",
|
|
64
|
+
"total_legs": "totalLegs",
|
|
65
|
+
"routing_swaps": "routingSwaps",
|
|
66
|
+
"estimated_max_dust": "estimatedMaxDust",
|
|
67
|
+
"aave_account_health_factor": "aaveAccountHealthFactor",
|
|
68
|
+
"per_target": "perTarget",
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export function creditRebalancePreviewFromJSON(
|
|
73
|
+
jsonString: string,
|
|
74
|
+
): SafeParseResult<CreditRebalancePreview, SDKValidationError> {
|
|
75
|
+
return safeParse(
|
|
76
|
+
jsonString,
|
|
77
|
+
(x) => CreditRebalancePreview$inboundSchema.parse(JSON.parse(x)),
|
|
78
|
+
`Failed to parse 'CreditRebalancePreview' from JSON`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { Chain, Chain$outboundSchema } from "./chain.js";
|
|
8
|
+
import {
|
|
9
|
+
RebalanceTarget,
|
|
10
|
+
RebalanceTarget$Outbound,
|
|
11
|
+
RebalanceTarget$outboundSchema,
|
|
12
|
+
} from "./rebalancetarget.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Request-level per-swap slippage tolerance in percent (including routing swaps). A per-target max_slippage_percent overrides it where set.
|
|
16
|
+
*/
|
|
17
|
+
export type CreditRebalanceRequestMaxSlippagePercent = number | string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Rebalance one or more Credit Account positions to their named end-states —
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* lever up or down, grow or shrink equity, open a new position, close an existing
|
|
24
|
+
* one, or migrate (close one and open another) — all in ONE atomic transaction
|
|
25
|
+
* from the Credit Account.
|
|
26
|
+
*/
|
|
27
|
+
export type CreditRebalanceRequest = {
|
|
28
|
+
/**
|
|
29
|
+
* The address that owns the Credit Account.
|
|
30
|
+
*/
|
|
31
|
+
owner: string;
|
|
32
|
+
/**
|
|
33
|
+
* The chain to use.
|
|
34
|
+
*/
|
|
35
|
+
chain: Chain;
|
|
36
|
+
/**
|
|
37
|
+
* The positions to change. Scoped: only positions named here are touched; any position not listed is left untouched.
|
|
38
|
+
*/
|
|
39
|
+
targets: Array<RebalanceTarget>;
|
|
40
|
+
/**
|
|
41
|
+
* Request-level per-swap slippage tolerance in percent (including routing swaps). A per-target max_slippage_percent overrides it where set.
|
|
42
|
+
*/
|
|
43
|
+
maxSlippagePercent?: number | string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* If true, returns EIP-712 typed data for gas-sponsored execution instead of an unsigned transaction.
|
|
46
|
+
*/
|
|
47
|
+
gasSponsorship?: boolean | undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** @internal */
|
|
51
|
+
export type CreditRebalanceRequestMaxSlippagePercent$Outbound = number | string;
|
|
52
|
+
|
|
53
|
+
/** @internal */
|
|
54
|
+
export const CreditRebalanceRequestMaxSlippagePercent$outboundSchema: z.ZodType<
|
|
55
|
+
CreditRebalanceRequestMaxSlippagePercent$Outbound,
|
|
56
|
+
z.ZodTypeDef,
|
|
57
|
+
CreditRebalanceRequestMaxSlippagePercent
|
|
58
|
+
> = z.union([z.number(), z.string()]);
|
|
59
|
+
|
|
60
|
+
export function creditRebalanceRequestMaxSlippagePercentToJSON(
|
|
61
|
+
creditRebalanceRequestMaxSlippagePercent:
|
|
62
|
+
CreditRebalanceRequestMaxSlippagePercent,
|
|
63
|
+
): string {
|
|
64
|
+
return JSON.stringify(
|
|
65
|
+
CreditRebalanceRequestMaxSlippagePercent$outboundSchema.parse(
|
|
66
|
+
creditRebalanceRequestMaxSlippagePercent,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
export type CreditRebalanceRequest$Outbound = {
|
|
73
|
+
owner: string;
|
|
74
|
+
chain: string;
|
|
75
|
+
targets: Array<RebalanceTarget$Outbound>;
|
|
76
|
+
max_slippage_percent?: number | string | undefined;
|
|
77
|
+
gas_sponsorship?: boolean | undefined;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** @internal */
|
|
81
|
+
export const CreditRebalanceRequest$outboundSchema: z.ZodType<
|
|
82
|
+
CreditRebalanceRequest$Outbound,
|
|
83
|
+
z.ZodTypeDef,
|
|
84
|
+
CreditRebalanceRequest
|
|
85
|
+
> = z.object({
|
|
86
|
+
owner: z.string(),
|
|
87
|
+
chain: Chain$outboundSchema,
|
|
88
|
+
targets: z.array(RebalanceTarget$outboundSchema),
|
|
89
|
+
maxSlippagePercent: z.union([z.number(), z.string()]).optional(),
|
|
90
|
+
gasSponsorship: z.boolean().optional(),
|
|
91
|
+
}).transform((v) => {
|
|
92
|
+
return remap$(v, {
|
|
93
|
+
maxSlippagePercent: "max_slippage_percent",
|
|
94
|
+
gasSponsorship: "gas_sponsorship",
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export function creditRebalanceRequestToJSON(
|
|
99
|
+
creditRebalanceRequest: CreditRebalanceRequest,
|
|
100
|
+
): string {
|
|
101
|
+
return JSON.stringify(
|
|
102
|
+
CreditRebalanceRequest$outboundSchema.parse(creditRebalanceRequest),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
9
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
10
|
+
import {
|
|
11
|
+
BatchedSafeOperationsResponseOutput,
|
|
12
|
+
BatchedSafeOperationsResponseOutput$inboundSchema,
|
|
13
|
+
} from "./batchedsafeoperationsresponseoutput.js";
|
|
14
|
+
import {
|
|
15
|
+
CreditRebalancePreview,
|
|
16
|
+
CreditRebalancePreview$inboundSchema,
|
|
17
|
+
} from "./creditrebalancepreview.js";
|
|
18
|
+
import {
|
|
19
|
+
UnsignedTransaction,
|
|
20
|
+
UnsignedTransaction$inboundSchema,
|
|
21
|
+
} from "./unsignedtransaction.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The atomic rebalance transaction plus its guaranteed-floor preview.
|
|
25
|
+
*/
|
|
26
|
+
export type CreditRebalanceResponse = {
|
|
27
|
+
/**
|
|
28
|
+
* Unsigned transaction for direct execution by the owner. Present when gas_sponsorship=false. Null when the book is already at its target — nothing to execute.
|
|
29
|
+
*/
|
|
30
|
+
transaction?: UnsignedTransaction | null | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* EIP-712 typed data for gas-sponsored execution. Present when gas_sponsorship=true.
|
|
33
|
+
*/
|
|
34
|
+
eip712?: BatchedSafeOperationsResponseOutput | null | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Projected end state of the whole rebalance, computed on GUARANTEED swap floors.
|
|
37
|
+
*/
|
|
38
|
+
preview: CreditRebalancePreview;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** @internal */
|
|
42
|
+
export const CreditRebalanceResponse$inboundSchema: z.ZodType<
|
|
43
|
+
CreditRebalanceResponse,
|
|
44
|
+
z.ZodTypeDef,
|
|
45
|
+
unknown
|
|
46
|
+
> = z.object({
|
|
47
|
+
transaction: z.nullable(UnsignedTransaction$inboundSchema).optional(),
|
|
48
|
+
eip_712: z.nullable(BatchedSafeOperationsResponseOutput$inboundSchema)
|
|
49
|
+
.optional(),
|
|
50
|
+
preview: CreditRebalancePreview$inboundSchema,
|
|
51
|
+
}).transform((v) => {
|
|
52
|
+
return remap$(v, {
|
|
53
|
+
"eip_712": "eip712",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export function creditRebalanceResponseFromJSON(
|
|
58
|
+
jsonString: string,
|
|
59
|
+
): SafeParseResult<CreditRebalanceResponse, SDKValidationError> {
|
|
60
|
+
return safeParse(
|
|
61
|
+
jsonString,
|
|
62
|
+
(x) => CreditRebalanceResponse$inboundSchema.parse(JSON.parse(x)),
|
|
63
|
+
`Failed to parse 'CreditRebalanceResponse' from JSON`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
/**
|
|
14
14
|
* Target leverage after the unwind. Omit (null) for a FULL unwind: the debt is cleared exactly — accrued interest included — and all pair collateral is withdrawn back to the Credit Account. `1` runs the same exact debt close but leaves the collateral supplied (earning). A value greater than 1 delevers the position to that multiplier. Must be below the position's current multiplier.
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
16
|
+
export type CreditUnloopRequestTargetMultiplier = number | string;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Per-swap slippage tolerance in percent. Unwind dust is bounded by this per iteration, so tighter slippage means less dust.
|
|
@@ -81,20 +81,22 @@ export type CreditUnloopRequest = {
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/** @internal */
|
|
84
|
-
export type
|
|
84
|
+
export type CreditUnloopRequestTargetMultiplier$Outbound = number | string;
|
|
85
85
|
|
|
86
86
|
/** @internal */
|
|
87
|
-
export const
|
|
88
|
-
|
|
87
|
+
export const CreditUnloopRequestTargetMultiplier$outboundSchema: z.ZodType<
|
|
88
|
+
CreditUnloopRequestTargetMultiplier$Outbound,
|
|
89
89
|
z.ZodTypeDef,
|
|
90
|
-
|
|
90
|
+
CreditUnloopRequestTargetMultiplier
|
|
91
91
|
> = z.union([z.number(), z.string()]);
|
|
92
92
|
|
|
93
|
-
export function
|
|
94
|
-
|
|
93
|
+
export function creditUnloopRequestTargetMultiplierToJSON(
|
|
94
|
+
creditUnloopRequestTargetMultiplier: CreditUnloopRequestTargetMultiplier,
|
|
95
95
|
): string {
|
|
96
96
|
return JSON.stringify(
|
|
97
|
-
|
|
97
|
+
CreditUnloopRequestTargetMultiplier$outboundSchema.parse(
|
|
98
|
+
creditUnloopRequestTargetMultiplier,
|
|
99
|
+
),
|
|
98
100
|
);
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -108,6 +108,9 @@ export * from "./creditlooprequest.js";
|
|
|
108
108
|
export * from "./creditloopresponse.js";
|
|
109
109
|
export * from "./creditpositionsresponse.js";
|
|
110
110
|
export * from "./creditprotocol.js";
|
|
111
|
+
export * from "./creditrebalancepreview.js";
|
|
112
|
+
export * from "./creditrebalancerequest.js";
|
|
113
|
+
export * from "./creditrebalanceresponse.js";
|
|
111
114
|
export * from "./creditrepayparams.js";
|
|
112
115
|
export * from "./creditrepayrequest.js";
|
|
113
116
|
export * from "./creditrepayresponse.js";
|
|
@@ -276,11 +279,15 @@ export * from "./pricepoint.js";
|
|
|
276
279
|
export * from "./protocol.js";
|
|
277
280
|
export * from "./quote.js";
|
|
278
281
|
export * from "./quotefee.js";
|
|
282
|
+
export * from "./rebalancedirection.js";
|
|
283
|
+
export * from "./rebalancetarget.js";
|
|
284
|
+
export * from "./rebalancetargetpreview.js";
|
|
279
285
|
export * from "./redemption.js";
|
|
280
286
|
export * from "./redemptionsresponse.js";
|
|
281
287
|
export * from "./repay.js";
|
|
282
288
|
export * from "./reserve.js";
|
|
283
289
|
export * from "./reserveinfo.js";
|
|
290
|
+
export * from "./routingswappreview.js";
|
|
284
291
|
export * from "./safemessageeip712response.js";
|
|
285
292
|
export * from "./safemessageeip712types.js";
|
|
286
293
|
export * from "./safemessagefield.js";
|
|
@@ -12,14 +12,16 @@ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
|
12
12
|
/**
|
|
13
13
|
* 'market' for Morpho (isolated per-market health). 'account' for Aave: collateral is pooled, so all collateral backs all debt and this health factor is shared by every Aave position on the account — see aave_account_summary for the account-level figures.
|
|
14
14
|
*/
|
|
15
|
-
export const
|
|
15
|
+
export const LoopedPositionCurrentStateHealthFactorScope = {
|
|
16
16
|
Market: "market",
|
|
17
17
|
Account: "account",
|
|
18
18
|
} as const;
|
|
19
19
|
/**
|
|
20
20
|
* 'market' for Morpho (isolated per-market health). 'account' for Aave: collateral is pooled, so all collateral backs all debt and this health factor is shared by every Aave position on the account — see aave_account_summary for the account-level figures.
|
|
21
21
|
*/
|
|
22
|
-
export type
|
|
22
|
+
export type LoopedPositionCurrentStateHealthFactorScope = ClosedEnum<
|
|
23
|
+
typeof LoopedPositionCurrentStateHealthFactorScope
|
|
24
|
+
>;
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* Live on-chain state of an OPEN looped position.
|
|
@@ -56,13 +58,13 @@ export type LoopedPositionCurrentState = {
|
|
|
56
58
|
/**
|
|
57
59
|
* 'market' for Morpho (isolated per-market health). 'account' for Aave: collateral is pooled, so all collateral backs all debt and this health factor is shared by every Aave position on the account — see aave_account_summary for the account-level figures.
|
|
58
60
|
*/
|
|
59
|
-
healthFactorScope:
|
|
61
|
+
healthFactorScope: LoopedPositionCurrentStateHealthFactorScope;
|
|
60
62
|
};
|
|
61
63
|
|
|
62
64
|
/** @internal */
|
|
63
|
-
export const
|
|
64
|
-
typeof
|
|
65
|
-
|
|
65
|
+
export const LoopedPositionCurrentStateHealthFactorScope$inboundSchema:
|
|
66
|
+
z.ZodNativeEnum<typeof LoopedPositionCurrentStateHealthFactorScope> = z
|
|
67
|
+
.nativeEnum(LoopedPositionCurrentStateHealthFactorScope);
|
|
66
68
|
|
|
67
69
|
/** @internal */
|
|
68
70
|
export const LoopedPositionCurrentState$inboundSchema: z.ZodType<
|
|
@@ -77,7 +79,8 @@ export const LoopedPositionCurrentState$inboundSchema: z.ZodType<
|
|
|
77
79
|
net_usd_value: z.nullable(z.string()).optional(),
|
|
78
80
|
leverage: z.nullable(z.string()).optional(),
|
|
79
81
|
health_factor: z.nullable(z.string()).optional(),
|
|
80
|
-
health_factor_scope:
|
|
82
|
+
health_factor_scope:
|
|
83
|
+
LoopedPositionCurrentStateHealthFactorScope$inboundSchema,
|
|
81
84
|
}).transform((v) => {
|
|
82
85
|
return remap$(v, {
|
|
83
86
|
"collateral_amount": "collateralAmount",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { ClosedEnum } from "../../types/enums.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What the plan does to one named target.
|
|
10
|
+
*/
|
|
11
|
+
export const RebalanceDirection = {
|
|
12
|
+
Open: "open",
|
|
13
|
+
Close: "close",
|
|
14
|
+
Grow: "grow",
|
|
15
|
+
Shrink: "shrink",
|
|
16
|
+
LeverUp: "lever_up",
|
|
17
|
+
LeverDown: "lever_down",
|
|
18
|
+
Noop: "noop",
|
|
19
|
+
} as const;
|
|
20
|
+
/**
|
|
21
|
+
* What the plan does to one named target.
|
|
22
|
+
*/
|
|
23
|
+
export type RebalanceDirection = ClosedEnum<typeof RebalanceDirection>;
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const RebalanceDirection$inboundSchema: z.ZodNativeEnum<
|
|
27
|
+
typeof RebalanceDirection
|
|
28
|
+
> = z.nativeEnum(RebalanceDirection);
|