@compass-labs/api-sdk 2.2.77-rc.1 → 2.2.78-rc.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.
Files changed (108) hide show
  1. package/README.md +5 -3
  2. package/codeSamples_typescript.yaml +6 -0
  3. package/dist/commonjs/funcs/creditCreditUnloop.d.ts +40 -0
  4. package/dist/commonjs/funcs/creditCreditUnloop.d.ts.map +1 -0
  5. package/dist/commonjs/funcs/creditCreditUnloop.js +141 -0
  6. package/dist/commonjs/funcs/creditCreditUnloop.js.map +1 -0
  7. package/dist/commonjs/lib/config.d.ts +2 -2
  8. package/dist/commonjs/lib/config.js +2 -2
  9. package/dist/commonjs/models/components/creditunlooppreview.d.ts +57 -0
  10. package/dist/commonjs/models/components/creditunlooppreview.d.ts.map +1 -0
  11. package/dist/commonjs/models/components/creditunlooppreview.js +74 -0
  12. package/dist/commonjs/models/components/creditunlooppreview.js.map +1 -0
  13. package/dist/commonjs/models/components/creditunlooprequest.d.ts +97 -0
  14. package/dist/commonjs/models/components/creditunlooprequest.d.ts.map +1 -0
  15. package/dist/commonjs/models/components/creditunlooprequest.js +83 -0
  16. package/dist/commonjs/models/components/creditunlooprequest.js.map +1 -0
  17. package/dist/commonjs/models/components/creditunloopresponse.d.ts +27 -0
  18. package/dist/commonjs/models/components/creditunloopresponse.d.ts.map +1 -0
  19. package/dist/commonjs/models/components/creditunloopresponse.js +61 -0
  20. package/dist/commonjs/models/components/creditunloopresponse.js.map +1 -0
  21. package/dist/commonjs/models/components/index.d.ts +4 -0
  22. package/dist/commonjs/models/components/index.d.ts.map +1 -1
  23. package/dist/commonjs/models/components/index.js +4 -0
  24. package/dist/commonjs/models/components/index.js.map +1 -1
  25. package/dist/commonjs/models/components/unlooplegpreview.d.ts +28 -0
  26. package/dist/commonjs/models/components/unlooplegpreview.d.ts.map +1 -0
  27. package/dist/commonjs/models/components/unlooplegpreview.js +61 -0
  28. package/dist/commonjs/models/components/unlooplegpreview.js.map +1 -0
  29. package/dist/commonjs/sdk/credit.d.ts +29 -0
  30. package/dist/commonjs/sdk/credit.d.ts.map +1 -1
  31. package/dist/commonjs/sdk/credit.js +32 -0
  32. package/dist/commonjs/sdk/credit.js.map +1 -1
  33. package/dist/esm/funcs/creditCreditUnloop.d.ts +40 -0
  34. package/dist/esm/funcs/creditCreditUnloop.d.ts.map +1 -0
  35. package/dist/esm/funcs/creditCreditUnloop.js +105 -0
  36. package/dist/esm/funcs/creditCreditUnloop.js.map +1 -0
  37. package/dist/esm/lib/config.d.ts +2 -2
  38. package/dist/esm/lib/config.js +2 -2
  39. package/dist/esm/models/components/creditunlooppreview.d.ts +57 -0
  40. package/dist/esm/models/components/creditunlooppreview.d.ts.map +1 -0
  41. package/dist/esm/models/components/creditunlooppreview.js +37 -0
  42. package/dist/esm/models/components/creditunlooppreview.js.map +1 -0
  43. package/dist/esm/models/components/creditunlooprequest.d.ts +97 -0
  44. package/dist/esm/models/components/creditunlooprequest.d.ts.map +1 -0
  45. package/dist/esm/models/components/creditunlooprequest.js +44 -0
  46. package/dist/esm/models/components/creditunlooprequest.js.map +1 -0
  47. package/dist/esm/models/components/creditunloopresponse.d.ts +27 -0
  48. package/dist/esm/models/components/creditunloopresponse.d.ts.map +1 -0
  49. package/dist/esm/models/components/creditunloopresponse.js +24 -0
  50. package/dist/esm/models/components/creditunloopresponse.js.map +1 -0
  51. package/dist/esm/models/components/index.d.ts +4 -0
  52. package/dist/esm/models/components/index.d.ts.map +1 -1
  53. package/dist/esm/models/components/index.js +4 -0
  54. package/dist/esm/models/components/index.js.map +1 -1
  55. package/dist/esm/models/components/unlooplegpreview.d.ts +28 -0
  56. package/dist/esm/models/components/unlooplegpreview.d.ts.map +1 -0
  57. package/dist/esm/models/components/unlooplegpreview.js +24 -0
  58. package/dist/esm/models/components/unlooplegpreview.js.map +1 -0
  59. package/dist/esm/sdk/credit.d.ts +29 -0
  60. package/dist/esm/sdk/credit.d.ts.map +1 -1
  61. package/dist/esm/sdk/credit.js +32 -0
  62. package/dist/esm/sdk/credit.js.map +1 -1
  63. package/docs/models/components/creditunlooppreview.md +39 -0
  64. package/docs/models/components/creditunlooprequest.md +37 -0
  65. package/docs/models/components/creditunlooprequestmaxslippagepercent.md +19 -0
  66. package/docs/models/components/creditunloopresponse.md +33 -0
  67. package/docs/models/components/targetmultiplier.md +19 -0
  68. package/docs/models/components/unlooplegpreview.md +23 -0
  69. package/docs/sdks/credit/README.md +111 -0
  70. package/examples/node_modules/tsx/dist/cjs/api/index.cjs +1 -1
  71. package/examples/node_modules/tsx/dist/cjs/api/index.mjs +1 -1
  72. package/examples/node_modules/tsx/dist/cjs/index.cjs +1 -1
  73. package/examples/node_modules/tsx/dist/cjs/index.mjs +1 -1
  74. package/examples/node_modules/tsx/dist/cli.cjs +1 -1
  75. package/examples/node_modules/tsx/dist/cli.mjs +1 -1
  76. package/examples/node_modules/tsx/dist/esm/api/index.cjs +1 -1
  77. package/examples/node_modules/tsx/dist/esm/api/index.mjs +1 -1
  78. package/examples/node_modules/tsx/dist/esm/index.cjs +1 -1
  79. package/examples/node_modules/tsx/dist/esm/index.mjs +1 -1
  80. package/examples/node_modules/tsx/dist/loader.cjs +1 -1
  81. package/examples/node_modules/tsx/dist/loader.mjs +1 -1
  82. package/examples/node_modules/tsx/dist/package-BgaOhdqD.mjs +1 -0
  83. package/examples/node_modules/tsx/dist/package-BqwdNe35.cjs +1 -0
  84. package/examples/node_modules/tsx/dist/register-BLKDwPDF.mjs +10 -0
  85. package/examples/node_modules/tsx/dist/{register-BOkp8V6j.cjs → register-BLUABhh3.cjs} +7 -7
  86. package/examples/node_modules/tsx/dist/register-CN6UEFH9.cjs +2 -0
  87. package/examples/node_modules/tsx/dist/register-D5KIhaFJ.mjs +2 -0
  88. package/examples/node_modules/tsx/dist/repl.cjs +1 -1
  89. package/examples/node_modules/tsx/dist/repl.mjs +1 -1
  90. package/examples/node_modules/tsx/dist/{require-CjvaJWEr.cjs → require-DVoFfmDN.cjs} +1 -1
  91. package/examples/node_modules/tsx/dist/{require-DzmC1hVr.mjs → require-l-oOTCoT.mjs} +1 -1
  92. package/examples/node_modules/tsx/package.json +1 -1
  93. package/examples/package-lock.json +3 -3
  94. package/openapi_prepped_for_speakeasy.json +319 -0
  95. package/package.json +1 -1
  96. package/src/funcs/creditCreditUnloop.ts +193 -0
  97. package/src/lib/config.ts +2 -2
  98. package/src/models/components/creditunlooppreview.ts +104 -0
  99. package/src/models/components/creditunlooprequest.ts +169 -0
  100. package/src/models/components/creditunloopresponse.ts +65 -0
  101. package/src/models/components/index.ts +4 -0
  102. package/src/models/components/unlooplegpreview.ts +60 -0
  103. package/src/sdk/credit.ts +40 -0
  104. package/examples/node_modules/tsx/dist/package-BhsaYzSJ.cjs +0 -1
  105. package/examples/node_modules/tsx/dist/package-REq4Oepp.mjs +0 -1
  106. package/examples/node_modules/tsx/dist/register-BBZNEaBg.cjs +0 -2
  107. package/examples/node_modules/tsx/dist/register-BnTWPeIB.mjs +0 -10
  108. package/examples/node_modules/tsx/dist/register-tkXbOgAS.mjs +0 -2
@@ -0,0 +1,193 @@
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
+ * Unwind a leveraged loop
31
+ *
32
+ * @remarks
33
+ * Unwind an Aave or Morpho loop in ONE atomic transaction.
34
+ *
35
+ * Repeatedly withdraws collateral, swaps it to the borrow token at a GUARANTEED
36
+ * minimum output (enforced on-chain), and repays. The floor discipline means a
37
+ * swap filling anywhere within the slippage tolerance can never break a later
38
+ * step; any positive surplus stays in the Credit Account as borrow-token dust
39
+ * (the preview reports the bound as estimated_max_dust).
40
+ *
41
+ * Omit target_multiplier for a full close: the debt is cleared exactly —
42
+ * accrued interest included — and the pair collateral is returned to the Credit
43
+ * Account. Pass 1 to clear the debt but keep the collateral supplied, or a value
44
+ * above 1 to delever to that multiplier (it must be below the position's current
45
+ * multiplier).
46
+ *
47
+ * Each withdrawal is sized to keep the position's health factor ≥ 1.02 at that
48
+ * step, so a position opened very close to the liquidation threshold may need
49
+ * more than one transaction to fully close — set allow_partial=true to return
50
+ * the maximum single-transaction progress (preview.fully_unwound=false), then
51
+ * call unloop again to finish. Very large unwinds relative to pool depth can
52
+ * still exceed the slippage tolerance through their own cumulative price impact.
53
+ *
54
+ * For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect
55
+ * open loops via /v2/credit/looped_positions.
56
+ */
57
+ export function creditCreditUnloop(
58
+ client: CompassApiSDKCore,
59
+ request: components.CreditUnloopRequest,
60
+ options?: RequestOptions,
61
+ ): APIPromise<
62
+ Result<
63
+ components.CreditUnloopResponse,
64
+ | errors.HTTPValidationError
65
+ | CompassAPISDKError
66
+ | ResponseValidationError
67
+ | ConnectionError
68
+ | RequestAbortedError
69
+ | RequestTimeoutError
70
+ | InvalidRequestError
71
+ | UnexpectedClientError
72
+ | SDKValidationError
73
+ >
74
+ > {
75
+ return new APIPromise($do(
76
+ client,
77
+ request,
78
+ options,
79
+ ));
80
+ }
81
+
82
+ async function $do(
83
+ client: CompassApiSDKCore,
84
+ request: components.CreditUnloopRequest,
85
+ options?: RequestOptions,
86
+ ): Promise<
87
+ [
88
+ Result<
89
+ components.CreditUnloopResponse,
90
+ | errors.HTTPValidationError
91
+ | CompassAPISDKError
92
+ | ResponseValidationError
93
+ | ConnectionError
94
+ | RequestAbortedError
95
+ | RequestTimeoutError
96
+ | InvalidRequestError
97
+ | UnexpectedClientError
98
+ | SDKValidationError
99
+ >,
100
+ APICall,
101
+ ]
102
+ > {
103
+ const parsed = safeParse(
104
+ request,
105
+ (value) => components.CreditUnloopRequest$outboundSchema.parse(value),
106
+ "Input validation failed",
107
+ );
108
+ if (!parsed.ok) {
109
+ return [parsed, { status: "invalid" }];
110
+ }
111
+ const payload = parsed.value;
112
+ const body = encodeJSON("body", payload, { explode: true });
113
+
114
+ const path = pathToFunc("/v2/credit/unloop")();
115
+
116
+ const headers = new Headers(compactMap({
117
+ "Content-Type": "application/json",
118
+ Accept: "application/json",
119
+ }));
120
+
121
+ const secConfig = await extractSecurity(client._options.apiKeyAuth);
122
+ const securityInput = secConfig == null ? {} : { apiKeyAuth: secConfig };
123
+ const requestSecurity = resolveGlobalSecurity(securityInput);
124
+
125
+ const context = {
126
+ options: client._options,
127
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
128
+ operationID: "v2_credit_unloop",
129
+ oAuth2Scopes: null,
130
+
131
+ resolvedSecurity: requestSecurity,
132
+
133
+ securitySource: client._options.apiKeyAuth,
134
+ retryConfig: options?.retries
135
+ || client._options.retryConfig
136
+ || { strategy: "none" },
137
+ retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
138
+ };
139
+
140
+ const requestRes = client._createRequest(context, {
141
+ security: requestSecurity,
142
+ method: "POST",
143
+ baseURL: options?.serverURL,
144
+ path: path,
145
+ headers: headers,
146
+ body: body,
147
+ userAgent: client._options.userAgent,
148
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
149
+ }, options);
150
+ if (!requestRes.ok) {
151
+ return [requestRes, { status: "invalid" }];
152
+ }
153
+ const req = requestRes.value;
154
+
155
+ const doResult = await client._do(req, {
156
+ context,
157
+ isErrorStatusCode: (statusCode: number) =>
158
+ matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
159
+ retryConfig: context.retryConfig,
160
+ retryCodes: context.retryCodes,
161
+ });
162
+ if (!doResult.ok) {
163
+ return [doResult, { status: "request-error", request: req }];
164
+ }
165
+ const response = doResult.value;
166
+
167
+ const responseFields = {
168
+ HttpMeta: { Response: response, Request: req },
169
+ };
170
+
171
+ const [result] = await M.match<
172
+ components.CreditUnloopResponse,
173
+ | errors.HTTPValidationError
174
+ | CompassAPISDKError
175
+ | ResponseValidationError
176
+ | ConnectionError
177
+ | RequestAbortedError
178
+ | RequestTimeoutError
179
+ | InvalidRequestError
180
+ | UnexpectedClientError
181
+ | SDKValidationError
182
+ >(
183
+ M.json(200, components.CreditUnloopResponse$inboundSchema),
184
+ M.jsonErr(422, errors.HTTPValidationError$inboundSchema),
185
+ M.fail("4XX"),
186
+ M.fail("5XX"),
187
+ )(response, req, { extraFields: responseFields });
188
+ if (!result.ok) {
189
+ return [result, { status: "complete", request: req, response }];
190
+ }
191
+
192
+ return [result, { status: "complete", request: req, response }];
193
+ }
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.915.0",
65
+ genVersion: "2.915.1",
66
66
  userAgent:
67
- "speakeasy-sdk/typescript 2.0.0 2.915.0 0.0.1 @compass-labs/api-sdk",
67
+ "speakeasy-sdk/typescript 2.0.0 2.915.1 0.0.1 @compass-labs/api-sdk",
68
68
  } as const;
@@ -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 { safeParse } from "../../lib/schemas.js";
8
+ import { Result as SafeParseResult } from "../../types/fp.js";
9
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
10
+ import {
11
+ UnloopLegPreview,
12
+ UnloopLegPreview$inboundSchema,
13
+ } from "./unlooplegpreview.js";
14
+
15
+ /**
16
+ * Projected end state of the unwind, computed on GUARANTEED swap floors.
17
+ */
18
+ export type CreditUnloopPreview = {
19
+ /**
20
+ * Number of swap-bearing unwind iterations bundled (the final collateral sweep leg does not count).
21
+ */
22
+ iterations: number;
23
+ /**
24
+ * Guaranteed minimum total collateral withdrawn (token units).
25
+ */
26
+ totalCollateralWithdrawn: string;
27
+ /**
28
+ * Guaranteed minimum total debt repaid (borrow-token units); actual can only be higher (swap fills above the floor repay more).
29
+ */
30
+ totalDebtRepaid: string;
31
+ /**
32
+ * Pair collateral left supplied after the unwind (token units). On a full close this is 0, except when non-pair Aave debt still needs this collateral as backing — then the final sweep is capped and this reports the residual left supplied.
33
+ */
34
+ endingCollateral: string;
35
+ /**
36
+ * Projected remaining debt (borrow-token units); 0 on a full close.
37
+ */
38
+ endingDebt: string;
39
+ /**
40
+ * Projected leverage after the unwind; 1 when the debt is cleared. Never promises more deleverage than is guaranteed.
41
+ */
42
+ endingMultiplier: string;
43
+ /**
44
+ * Projected end loan-to-value in percent, at the sizing oracle prices; 0 when the debt is cleared.
45
+ */
46
+ projectedLtv: string;
47
+ /**
48
+ * Projected health factor (Aave account-level / Morpho market-level). Never overstated at the 1.0 boundary.
49
+ */
50
+ projectedHealthFactor: string;
51
+ /**
52
+ * Upper bound of borrow-token surplus the unwind can leave in the Credit Account — the sum of each swap's quote minus its guaranteed floor plus the full-close overshoot. It accumulates in the Credit Account, is recoverable, and is never lost.
53
+ */
54
+ estimatedMaxDust: string;
55
+ /**
56
+ * True when the requested target was fully reached in this transaction. False on a partial-progress plan (allow_partial=true) — call unloop again to finish.
57
+ */
58
+ fullyUnwound: boolean;
59
+ /**
60
+ * Per-iteration breakdown.
61
+ */
62
+ legs?: Array<UnloopLegPreview> | undefined;
63
+ };
64
+
65
+ /** @internal */
66
+ export const CreditUnloopPreview$inboundSchema: z.ZodType<
67
+ CreditUnloopPreview,
68
+ z.ZodTypeDef,
69
+ unknown
70
+ > = z.object({
71
+ iterations: z.number().int(),
72
+ total_collateral_withdrawn: z.string(),
73
+ total_debt_repaid: z.string(),
74
+ ending_collateral: z.string(),
75
+ ending_debt: z.string(),
76
+ ending_multiplier: z.string(),
77
+ projected_ltv: z.string(),
78
+ projected_health_factor: z.string(),
79
+ estimated_max_dust: z.string(),
80
+ fully_unwound: z.boolean(),
81
+ legs: z.array(UnloopLegPreview$inboundSchema).optional(),
82
+ }).transform((v) => {
83
+ return remap$(v, {
84
+ "total_collateral_withdrawn": "totalCollateralWithdrawn",
85
+ "total_debt_repaid": "totalDebtRepaid",
86
+ "ending_collateral": "endingCollateral",
87
+ "ending_debt": "endingDebt",
88
+ "ending_multiplier": "endingMultiplier",
89
+ "projected_ltv": "projectedLtv",
90
+ "projected_health_factor": "projectedHealthFactor",
91
+ "estimated_max_dust": "estimatedMaxDust",
92
+ "fully_unwound": "fullyUnwound",
93
+ });
94
+ });
95
+
96
+ export function creditUnloopPreviewFromJSON(
97
+ jsonString: string,
98
+ ): SafeParseResult<CreditUnloopPreview, SDKValidationError> {
99
+ return safeParse(
100
+ jsonString,
101
+ (x) => CreditUnloopPreview$inboundSchema.parse(JSON.parse(x)),
102
+ `Failed to parse 'CreditUnloopPreview' from JSON`,
103
+ );
104
+ }
@@ -0,0 +1,169 @@
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
+ CreditProtocol,
10
+ CreditProtocol$outboundSchema,
11
+ } from "./creditprotocol.js";
12
+
13
+ /**
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
+ */
16
+ export type TargetMultiplier = number | string;
17
+
18
+ /**
19
+ * Per-swap slippage tolerance in percent. Unwind dust is bounded by this per iteration, so tighter slippage means less dust.
20
+ */
21
+ export type CreditUnloopRequestMaxSlippagePercent = number | string;
22
+
23
+ /**
24
+ * Unwind a leveraged loop: repeatedly withdraw collateral, swap it back to
25
+ *
26
+ * @remarks
27
+ * the borrow token at a guaranteed minimum output, and repay — all in ONE
28
+ * atomic transaction from the Credit Account.
29
+ */
30
+ export type CreditUnloopRequest = {
31
+ /**
32
+ * The address that owns the Credit Account.
33
+ */
34
+ owner: string;
35
+ /**
36
+ * The chain to use.
37
+ */
38
+ chain: Chain;
39
+ /**
40
+ * Which lending protocol a credit action targets.
41
+ *
42
+ * @remarks
43
+ *
44
+ * ``AAVE`` is the default so existing callers (which never send a ``protocol``
45
+ * field) keep hitting the unchanged Aave code path. ``EULER`` opts in to the
46
+ * Euler V2 path, where the market is identified by EVK vault address(es).
47
+ * ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id) and is
48
+ * currently read-only: positions and market discovery only — transaction
49
+ * builders land with the looping work (COM-7106/7107/7108), so transact
50
+ * endpoints reject it with a 422.
51
+ */
52
+ protocol?: CreditProtocol | undefined;
53
+ /**
54
+ * Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.
55
+ */
56
+ marketId?: string | null | undefined;
57
+ /**
58
+ * Token supplied as collateral in the loop being unwound. For MORPHO it must be the market's collateral token.
59
+ */
60
+ collateralToken: string;
61
+ /**
62
+ * Token borrowed in the loop; withdrawn collateral is swapped back to it and used to repay. For MORPHO it must be the market's loan token.
63
+ */
64
+ borrowToken: string;
65
+ /**
66
+ * 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.
67
+ */
68
+ targetMultiplier?: number | string | null | undefined;
69
+ /**
70
+ * Per-swap slippage tolerance in percent. Unwind dust is bounded by this per iteration, so tighter slippage means less dust.
71
+ */
72
+ maxSlippagePercent?: number | string | undefined;
73
+ /**
74
+ * If the target cannot be reached in one transaction (e.g. a position opened very close to the liquidation threshold), return the maximum-progress plan (preview.fully_unwound=false) instead of a 400. A second unloop call, now from a much lower leverage, finishes the job.
75
+ */
76
+ allowPartial?: boolean | undefined;
77
+ /**
78
+ * If true, returns EIP-712 typed data for gas-sponsored execution instead of an unsigned transaction.
79
+ */
80
+ gasSponsorship?: boolean | undefined;
81
+ };
82
+
83
+ /** @internal */
84
+ export type TargetMultiplier$Outbound = number | string;
85
+
86
+ /** @internal */
87
+ export const TargetMultiplier$outboundSchema: z.ZodType<
88
+ TargetMultiplier$Outbound,
89
+ z.ZodTypeDef,
90
+ TargetMultiplier
91
+ > = z.union([z.number(), z.string()]);
92
+
93
+ export function targetMultiplierToJSON(
94
+ targetMultiplier: TargetMultiplier,
95
+ ): string {
96
+ return JSON.stringify(
97
+ TargetMultiplier$outboundSchema.parse(targetMultiplier),
98
+ );
99
+ }
100
+
101
+ /** @internal */
102
+ export type CreditUnloopRequestMaxSlippagePercent$Outbound = number | string;
103
+
104
+ /** @internal */
105
+ export const CreditUnloopRequestMaxSlippagePercent$outboundSchema: z.ZodType<
106
+ CreditUnloopRequestMaxSlippagePercent$Outbound,
107
+ z.ZodTypeDef,
108
+ CreditUnloopRequestMaxSlippagePercent
109
+ > = z.union([z.number(), z.string()]);
110
+
111
+ export function creditUnloopRequestMaxSlippagePercentToJSON(
112
+ creditUnloopRequestMaxSlippagePercent: CreditUnloopRequestMaxSlippagePercent,
113
+ ): string {
114
+ return JSON.stringify(
115
+ CreditUnloopRequestMaxSlippagePercent$outboundSchema.parse(
116
+ creditUnloopRequestMaxSlippagePercent,
117
+ ),
118
+ );
119
+ }
120
+
121
+ /** @internal */
122
+ export type CreditUnloopRequest$Outbound = {
123
+ owner: string;
124
+ chain: string;
125
+ protocol?: string | undefined;
126
+ market_id?: string | null | undefined;
127
+ collateral_token: string;
128
+ borrow_token: string;
129
+ target_multiplier?: number | string | null | undefined;
130
+ max_slippage_percent?: number | string | undefined;
131
+ allow_partial?: boolean | undefined;
132
+ gas_sponsorship?: boolean | undefined;
133
+ };
134
+
135
+ /** @internal */
136
+ export const CreditUnloopRequest$outboundSchema: z.ZodType<
137
+ CreditUnloopRequest$Outbound,
138
+ z.ZodTypeDef,
139
+ CreditUnloopRequest
140
+ > = z.object({
141
+ owner: z.string(),
142
+ chain: Chain$outboundSchema,
143
+ protocol: CreditProtocol$outboundSchema.optional(),
144
+ marketId: z.nullable(z.string()).optional(),
145
+ collateralToken: z.string(),
146
+ borrowToken: z.string(),
147
+ targetMultiplier: z.nullable(z.union([z.number(), z.string()])).optional(),
148
+ maxSlippagePercent: z.union([z.number(), z.string()]).optional(),
149
+ allowPartial: z.boolean().optional(),
150
+ gasSponsorship: z.boolean().optional(),
151
+ }).transform((v) => {
152
+ return remap$(v, {
153
+ marketId: "market_id",
154
+ collateralToken: "collateral_token",
155
+ borrowToken: "borrow_token",
156
+ targetMultiplier: "target_multiplier",
157
+ maxSlippagePercent: "max_slippage_percent",
158
+ allowPartial: "allow_partial",
159
+ gasSponsorship: "gas_sponsorship",
160
+ });
161
+ });
162
+
163
+ export function creditUnloopRequestToJSON(
164
+ creditUnloopRequest: CreditUnloopRequest,
165
+ ): string {
166
+ return JSON.stringify(
167
+ CreditUnloopRequest$outboundSchema.parse(creditUnloopRequest),
168
+ );
169
+ }
@@ -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
+ CreditUnloopPreview,
16
+ CreditUnloopPreview$inboundSchema,
17
+ } from "./creditunlooppreview.js";
18
+ import {
19
+ UnsignedTransaction,
20
+ UnsignedTransaction$inboundSchema,
21
+ } from "./unsignedtransaction.js";
22
+
23
+ /**
24
+ * The atomic unwind transaction plus its guaranteed-floor preview.
25
+ */
26
+ export type CreditUnloopResponse = {
27
+ /**
28
+ * Unsigned transaction for direct execution by the owner. Present when gas_sponsorship=false.
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 unwind, computed on GUARANTEED swap floors.
37
+ */
38
+ preview: CreditUnloopPreview;
39
+ };
40
+
41
+ /** @internal */
42
+ export const CreditUnloopResponse$inboundSchema: z.ZodType<
43
+ CreditUnloopResponse,
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: CreditUnloopPreview$inboundSchema,
51
+ }).transform((v) => {
52
+ return remap$(v, {
53
+ "eip_712": "eip712",
54
+ });
55
+ });
56
+
57
+ export function creditUnloopResponseFromJSON(
58
+ jsonString: string,
59
+ ): SafeParseResult<CreditUnloopResponse, SDKValidationError> {
60
+ return safeParse(
61
+ jsonString,
62
+ (x) => CreditUnloopResponse$inboundSchema.parse(JSON.parse(x)),
63
+ `Failed to parse 'CreditUnloopResponse' from JSON`,
64
+ );
65
+ }
@@ -115,6 +115,9 @@ export * from "./creditsupplyparams.js";
115
115
  export * from "./credittransferrequest.js";
116
116
  export * from "./credittransferresponse.js";
117
117
  export * from "./credittransfertoaddressparams.js";
118
+ export * from "./creditunlooppreview.js";
119
+ export * from "./creditunlooprequest.js";
120
+ export * from "./creditunloopresponse.js";
118
121
  export * from "./credituseroperation.js";
119
122
  export * from "./creditwithdrawparams.js";
120
123
  export * from "./debtposition.js";
@@ -360,6 +363,7 @@ export * from "./uniswapsellexactlytransactionresponse.js";
360
363
  export * from "./uniswapsellquoteinforesponse.js";
361
364
  export * from "./uniswapwithdrawliquidityprovisionparams.js";
362
365
  export * from "./uniswapwithdrawliquidityprovisionrequest.js";
366
+ export * from "./unlooplegpreview.js";
363
367
  export * from "./unsignedmulticalltransaction.js";
364
368
  export * from "./unsignedtransaction.js";
365
369
  export * from "./unwrapwethparams.js";
@@ -0,0 +1,60 @@
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
+
11
+ /**
12
+ * One planned unwind iteration: withdraw [+ swap + repay].
13
+ */
14
+ export type UnloopLegPreview = {
15
+ /**
16
+ * Collateral withdrawn this iteration (token units).
17
+ */
18
+ withdrawAmount: string | null;
19
+ /**
20
+ * Guaranteed swap output (borrow-token units) — enforced on-chain by the swap's minimum-return. Null on the final collateral sweep leg, which does not swap.
21
+ */
22
+ minSwapOut?: string | null | undefined;
23
+ /**
24
+ * Debt repaid this iteration (borrow-token units); null on the final collateral sweep leg.
25
+ */
26
+ repayAmount?: string | null | undefined;
27
+ /**
28
+ * True on the closing leg that clears the remaining debt exactly (Aave clamps to live debt; Morpho repays the remaining shares).
29
+ */
30
+ fullRepay?: boolean | undefined;
31
+ };
32
+
33
+ /** @internal */
34
+ export const UnloopLegPreview$inboundSchema: z.ZodType<
35
+ UnloopLegPreview,
36
+ z.ZodTypeDef,
37
+ unknown
38
+ > = z.object({
39
+ withdraw_amount: z.nullable(z.string()),
40
+ min_swap_out: z.nullable(z.string()).optional(),
41
+ repay_amount: z.nullable(z.string()).optional(),
42
+ full_repay: z.boolean().optional(),
43
+ }).transform((v) => {
44
+ return remap$(v, {
45
+ "withdraw_amount": "withdrawAmount",
46
+ "min_swap_out": "minSwapOut",
47
+ "repay_amount": "repayAmount",
48
+ "full_repay": "fullRepay",
49
+ });
50
+ });
51
+
52
+ export function unloopLegPreviewFromJSON(
53
+ jsonString: string,
54
+ ): SafeParseResult<UnloopLegPreview, SDKValidationError> {
55
+ return safeParse(
56
+ jsonString,
57
+ (x) => UnloopLegPreview$inboundSchema.parse(JSON.parse(x)),
58
+ `Failed to parse 'UnloopLegPreview' from JSON`,
59
+ );
60
+ }
package/src/sdk/credit.ts CHANGED
@@ -13,6 +13,7 @@ import { creditCreditMorphoMarkets } from "../funcs/creditCreditMorphoMarkets.js
13
13
  import { creditCreditPositions } from "../funcs/creditCreditPositions.js";
14
14
  import { creditCreditRepay } from "../funcs/creditCreditRepay.js";
15
15
  import { creditCreditTransfer } from "../funcs/creditCreditTransfer.js";
16
+ import { creditCreditUnloop } from "../funcs/creditCreditUnloop.js";
16
17
  import { ClientSDK, RequestOptions } from "../lib/sdks.js";
17
18
  import * as components from "../models/components/index.js";
18
19
  import * as operations from "../models/operations/index.js";
@@ -206,6 +207,45 @@ export class Credit extends ClientSDK {
206
207
  ));
207
208
  }
208
209
 
210
+ /**
211
+ * Unwind a leveraged loop
212
+ *
213
+ * @remarks
214
+ * Unwind an Aave or Morpho loop in ONE atomic transaction.
215
+ *
216
+ * Repeatedly withdraws collateral, swaps it to the borrow token at a GUARANTEED
217
+ * minimum output (enforced on-chain), and repays. The floor discipline means a
218
+ * swap filling anywhere within the slippage tolerance can never break a later
219
+ * step; any positive surplus stays in the Credit Account as borrow-token dust
220
+ * (the preview reports the bound as estimated_max_dust).
221
+ *
222
+ * Omit target_multiplier for a full close: the debt is cleared exactly —
223
+ * accrued interest included — and the pair collateral is returned to the Credit
224
+ * Account. Pass 1 to clear the debt but keep the collateral supplied, or a value
225
+ * above 1 to delever to that multiplier (it must be below the position's current
226
+ * multiplier).
227
+ *
228
+ * Each withdrawal is sized to keep the position's health factor ≥ 1.02 at that
229
+ * step, so a position opened very close to the liquidation threshold may need
230
+ * more than one transaction to fully close — set allow_partial=true to return
231
+ * the maximum single-transaction progress (preview.fully_unwound=false), then
232
+ * call unloop again to finish. Very large unwinds relative to pool depth can
233
+ * still exceed the slippage tolerance through their own cumulative price impact.
234
+ *
235
+ * For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect
236
+ * open loops via /v2/credit/looped_positions.
237
+ */
238
+ async creditUnloop(
239
+ request: components.CreditUnloopRequest,
240
+ options?: RequestOptions,
241
+ ): Promise<components.CreditUnloopResponse> {
242
+ return unwrapAsync(creditCreditUnloop(
243
+ this,
244
+ request,
245
+ options,
246
+ ));
247
+ }
248
+
209
249
  /**
210
250
  * Transfer tokens to/from Credit Account
211
251
  *
@@ -1 +0,0 @@
1
- "use strict";var r="4.22.5";exports.version=r;
@@ -1 +0,0 @@
1
- var r="4.22.5";export{r as v};