@compass-labs/api-sdk 2.2.77-rc.0 → 2.2.77

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 (115) hide show
  1. package/README.md +5 -3
  2. package/codeSamples_typescript.yaml +6 -0
  3. package/dist/commonjs/funcs/creditCreditLoopedPositions.d.ts +26 -0
  4. package/dist/commonjs/funcs/creditCreditLoopedPositions.d.ts.map +1 -0
  5. package/dist/commonjs/funcs/creditCreditLoopedPositions.js +131 -0
  6. package/dist/commonjs/funcs/creditCreditLoopedPositions.js.map +1 -0
  7. package/dist/commonjs/models/components/creditloopedpositionsresponse.d.ts +26 -0
  8. package/dist/commonjs/models/components/creditloopedpositionsresponse.d.ts.map +1 -0
  9. package/dist/commonjs/models/components/creditloopedpositionsresponse.js +60 -0
  10. package/dist/commonjs/models/components/creditloopedpositionsresponse.js.map +1 -0
  11. package/dist/commonjs/models/components/index.d.ts +6 -0
  12. package/dist/commonjs/models/components/index.d.ts.map +1 -1
  13. package/dist/commonjs/models/components/index.js +6 -0
  14. package/dist/commonjs/models/components/index.js.map +1 -1
  15. package/dist/commonjs/models/components/loopedposition.d.ts +88 -0
  16. package/dist/commonjs/models/components/loopedposition.d.ts.map +1 -0
  17. package/dist/commonjs/models/components/loopedposition.js +85 -0
  18. package/dist/commonjs/models/components/loopedposition.js.map +1 -0
  19. package/dist/commonjs/models/components/loopedpositioncurrentstate.d.ts +58 -0
  20. package/dist/commonjs/models/components/loopedpositioncurrentstate.d.ts.map +1 -0
  21. package/dist/commonjs/models/components/loopedpositioncurrentstate.js +77 -0
  22. package/dist/commonjs/models/components/loopedpositioncurrentstate.js.map +1 -0
  23. package/dist/commonjs/models/components/loopedpositionhistoryentry.d.ts +71 -0
  24. package/dist/commonjs/models/components/loopedpositionhistoryentry.d.ts.map +1 -0
  25. package/dist/commonjs/models/components/loopedpositionhistoryentry.js +85 -0
  26. package/dist/commonjs/models/components/loopedpositionhistoryentry.js.map +1 -0
  27. package/dist/commonjs/models/components/loopedpositiontotals.d.ts +40 -0
  28. package/dist/commonjs/models/components/loopedpositiontotals.d.ts.map +1 -0
  29. package/dist/commonjs/models/components/loopedpositiontotals.js +67 -0
  30. package/dist/commonjs/models/components/loopedpositiontotals.js.map +1 -0
  31. package/dist/commonjs/models/components/swapinfo.d.ts +48 -0
  32. package/dist/commonjs/models/components/swapinfo.d.ts.map +1 -0
  33. package/dist/commonjs/models/components/swapinfo.js +66 -0
  34. package/dist/commonjs/models/components/swapinfo.js.map +1 -0
  35. package/dist/commonjs/models/operations/index.d.ts +1 -0
  36. package/dist/commonjs/models/operations/index.d.ts.map +1 -1
  37. package/dist/commonjs/models/operations/index.js +1 -0
  38. package/dist/commonjs/models/operations/index.js.map +1 -1
  39. package/dist/commonjs/models/operations/v2creditloopedpositions.d.ts +28 -0
  40. package/dist/commonjs/models/operations/v2creditloopedpositions.d.ts.map +1 -0
  41. package/dist/commonjs/models/operations/v2creditloopedpositions.js +59 -0
  42. package/dist/commonjs/models/operations/v2creditloopedpositions.js.map +1 -0
  43. package/dist/commonjs/sdk/credit.d.ts +14 -0
  44. package/dist/commonjs/sdk/credit.d.ts.map +1 -1
  45. package/dist/commonjs/sdk/credit.js +17 -0
  46. package/dist/commonjs/sdk/credit.js.map +1 -1
  47. package/dist/esm/funcs/creditCreditLoopedPositions.d.ts +26 -0
  48. package/dist/esm/funcs/creditCreditLoopedPositions.d.ts.map +1 -0
  49. package/dist/esm/funcs/creditCreditLoopedPositions.js +95 -0
  50. package/dist/esm/funcs/creditCreditLoopedPositions.js.map +1 -0
  51. package/dist/esm/models/components/creditloopedpositionsresponse.d.ts +26 -0
  52. package/dist/esm/models/components/creditloopedpositionsresponse.d.ts.map +1 -0
  53. package/dist/esm/models/components/creditloopedpositionsresponse.js +23 -0
  54. package/dist/esm/models/components/creditloopedpositionsresponse.js.map +1 -0
  55. package/dist/esm/models/components/index.d.ts +6 -0
  56. package/dist/esm/models/components/index.d.ts.map +1 -1
  57. package/dist/esm/models/components/index.js +6 -0
  58. package/dist/esm/models/components/index.js.map +1 -1
  59. package/dist/esm/models/components/loopedposition.d.ts +88 -0
  60. package/dist/esm/models/components/loopedposition.d.ts.map +1 -0
  61. package/dist/esm/models/components/loopedposition.js +48 -0
  62. package/dist/esm/models/components/loopedposition.js.map +1 -0
  63. package/dist/esm/models/components/loopedpositioncurrentstate.d.ts +58 -0
  64. package/dist/esm/models/components/loopedpositioncurrentstate.d.ts.map +1 -0
  65. package/dist/esm/models/components/loopedpositioncurrentstate.js +40 -0
  66. package/dist/esm/models/components/loopedpositioncurrentstate.js.map +1 -0
  67. package/dist/esm/models/components/loopedpositionhistoryentry.d.ts +71 -0
  68. package/dist/esm/models/components/loopedpositionhistoryentry.d.ts.map +1 -0
  69. package/dist/esm/models/components/loopedpositionhistoryentry.js +48 -0
  70. package/dist/esm/models/components/loopedpositionhistoryentry.js.map +1 -0
  71. package/dist/esm/models/components/loopedpositiontotals.d.ts +40 -0
  72. package/dist/esm/models/components/loopedpositiontotals.d.ts.map +1 -0
  73. package/dist/esm/models/components/loopedpositiontotals.js +30 -0
  74. package/dist/esm/models/components/loopedpositiontotals.js.map +1 -0
  75. package/dist/esm/models/components/swapinfo.d.ts +48 -0
  76. package/dist/esm/models/components/swapinfo.d.ts.map +1 -0
  77. package/dist/esm/models/components/swapinfo.js +29 -0
  78. package/dist/esm/models/components/swapinfo.js.map +1 -0
  79. package/dist/esm/models/operations/index.d.ts +1 -0
  80. package/dist/esm/models/operations/index.d.ts.map +1 -1
  81. package/dist/esm/models/operations/index.js +1 -0
  82. package/dist/esm/models/operations/index.js.map +1 -1
  83. package/dist/esm/models/operations/v2creditloopedpositions.d.ts +28 -0
  84. package/dist/esm/models/operations/v2creditloopedpositions.d.ts.map +1 -0
  85. package/dist/esm/models/operations/v2creditloopedpositions.js +22 -0
  86. package/dist/esm/models/operations/v2creditloopedpositions.js.map +1 -0
  87. package/dist/esm/sdk/credit.d.ts +14 -0
  88. package/dist/esm/sdk/credit.d.ts.map +1 -1
  89. package/dist/esm/sdk/credit.js +17 -0
  90. package/dist/esm/sdk/credit.js.map +1 -1
  91. package/docs/models/components/classification.md +17 -0
  92. package/docs/models/components/creditloopedpositionsresponse.md +30 -0
  93. package/docs/models/components/healthfactorscope.md +17 -0
  94. package/docs/models/components/loopedposition.md +46 -0
  95. package/docs/models/components/loopedpositioncurrentstate.md +28 -0
  96. package/docs/models/components/loopedpositionhistoryentry.md +33 -0
  97. package/docs/models/components/loopedpositionstatus.md +17 -0
  98. package/docs/models/components/loopedpositiontotals.md +31 -0
  99. package/docs/models/components/swapinfo.md +36 -0
  100. package/docs/models/operations/v2creditloopedpositionschain.md +15 -0
  101. package/docs/models/operations/v2creditloopedpositionsrequest.md +19 -0
  102. package/docs/sdks/credit/README.md +84 -0
  103. package/openapi_prepped_for_speakeasy.json +510 -0
  104. package/package.json +1 -1
  105. package/src/funcs/creditCreditLoopedPositions.ts +185 -0
  106. package/src/models/components/creditloopedpositionsresponse.ts +61 -0
  107. package/src/models/components/index.ts +6 -0
  108. package/src/models/components/loopedposition.ts +149 -0
  109. package/src/models/components/loopedpositioncurrentstate.ts +101 -0
  110. package/src/models/components/loopedpositionhistoryentry.ts +115 -0
  111. package/src/models/components/loopedpositiontotals.ts +78 -0
  112. package/src/models/components/swapinfo.ts +85 -0
  113. package/src/models/operations/index.ts +1 -0
  114. package/src/models/operations/v2creditloopedpositions.ts +56 -0
  115. package/src/sdk/credit.ts +25 -0
@@ -0,0 +1,185 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import { CompassApiSDKCore } from "../core.js";
6
+ import { encodeFormQuery } 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 * as operations from "../models/operations/index.js";
27
+ import { APICall, APIPromise } from "../types/async.js";
28
+ import { Result } from "../types/fp.js";
29
+
30
+ /**
31
+ * List looped (leveraged) credit positions
32
+ *
33
+ * @remarks
34
+ * List looped (leveraged) positions for a credit account owner.
35
+ *
36
+ * Detects loops from the account's on-chain history: a transaction containing
37
+ * lending + borrowing + swap legs is a loop transaction. Returns one position
38
+ * per Morpho market / Aave collateral+debt reserve pair, each with its complete
39
+ * per-transaction history, lifetime totals, and live on-chain state (health
40
+ * factor, USD values, leverage) for open positions. Covers Aave V3 and Morpho
41
+ * Blue.
42
+ */
43
+ export function creditCreditLoopedPositions(
44
+ client: CompassApiSDKCore,
45
+ request: operations.V2CreditLoopedPositionsRequest,
46
+ options?: RequestOptions,
47
+ ): APIPromise<
48
+ Result<
49
+ components.CreditLoopedPositionsResponse,
50
+ | errors.HTTPValidationError
51
+ | CompassAPISDKError
52
+ | ResponseValidationError
53
+ | ConnectionError
54
+ | RequestAbortedError
55
+ | RequestTimeoutError
56
+ | InvalidRequestError
57
+ | UnexpectedClientError
58
+ | SDKValidationError
59
+ >
60
+ > {
61
+ return new APIPromise($do(
62
+ client,
63
+ request,
64
+ options,
65
+ ));
66
+ }
67
+
68
+ async function $do(
69
+ client: CompassApiSDKCore,
70
+ request: operations.V2CreditLoopedPositionsRequest,
71
+ options?: RequestOptions,
72
+ ): Promise<
73
+ [
74
+ Result<
75
+ components.CreditLoopedPositionsResponse,
76
+ | errors.HTTPValidationError
77
+ | CompassAPISDKError
78
+ | ResponseValidationError
79
+ | ConnectionError
80
+ | RequestAbortedError
81
+ | RequestTimeoutError
82
+ | InvalidRequestError
83
+ | UnexpectedClientError
84
+ | SDKValidationError
85
+ >,
86
+ APICall,
87
+ ]
88
+ > {
89
+ const parsed = safeParse(
90
+ request,
91
+ (value) =>
92
+ operations.V2CreditLoopedPositionsRequest$outboundSchema.parse(value),
93
+ "Input validation failed",
94
+ );
95
+ if (!parsed.ok) {
96
+ return [parsed, { status: "invalid" }];
97
+ }
98
+ const payload = parsed.value;
99
+ const body = null;
100
+
101
+ const path = pathToFunc("/v2/credit/looped_positions")();
102
+
103
+ const query = encodeFormQuery({
104
+ "chain": payload.chain,
105
+ "owner": payload.owner,
106
+ });
107
+
108
+ const headers = new Headers(compactMap({
109
+ Accept: "application/json",
110
+ }));
111
+
112
+ const secConfig = await extractSecurity(client._options.apiKeyAuth);
113
+ const securityInput = secConfig == null ? {} : { apiKeyAuth: secConfig };
114
+ const requestSecurity = resolveGlobalSecurity(securityInput);
115
+
116
+ const context = {
117
+ options: client._options,
118
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
119
+ operationID: "v2_credit_looped_positions",
120
+ oAuth2Scopes: null,
121
+
122
+ resolvedSecurity: requestSecurity,
123
+
124
+ securitySource: client._options.apiKeyAuth,
125
+ retryConfig: options?.retries
126
+ || client._options.retryConfig
127
+ || { strategy: "none" },
128
+ retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
129
+ };
130
+
131
+ const requestRes = client._createRequest(context, {
132
+ security: requestSecurity,
133
+ method: "GET",
134
+ baseURL: options?.serverURL,
135
+ path: path,
136
+ headers: headers,
137
+ query: query,
138
+ body: body,
139
+ userAgent: client._options.userAgent,
140
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
141
+ }, options);
142
+ if (!requestRes.ok) {
143
+ return [requestRes, { status: "invalid" }];
144
+ }
145
+ const req = requestRes.value;
146
+
147
+ const doResult = await client._do(req, {
148
+ context,
149
+ isErrorStatusCode: (statusCode: number) =>
150
+ matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
151
+ retryConfig: context.retryConfig,
152
+ retryCodes: context.retryCodes,
153
+ });
154
+ if (!doResult.ok) {
155
+ return [doResult, { status: "request-error", request: req }];
156
+ }
157
+ const response = doResult.value;
158
+
159
+ const responseFields = {
160
+ HttpMeta: { Response: response, Request: req },
161
+ };
162
+
163
+ const [result] = await M.match<
164
+ components.CreditLoopedPositionsResponse,
165
+ | errors.HTTPValidationError
166
+ | CompassAPISDKError
167
+ | ResponseValidationError
168
+ | ConnectionError
169
+ | RequestAbortedError
170
+ | RequestTimeoutError
171
+ | InvalidRequestError
172
+ | UnexpectedClientError
173
+ | SDKValidationError
174
+ >(
175
+ M.json(200, components.CreditLoopedPositionsResponse$inboundSchema),
176
+ M.jsonErr(422, errors.HTTPValidationError$inboundSchema),
177
+ M.fail("4XX"),
178
+ M.fail("5XX"),
179
+ )(response, req, { extraFields: responseFields });
180
+ if (!result.ok) {
181
+ return [result, { status: "complete", request: req, response }];
182
+ }
183
+
184
+ return [result, { status: "complete", request: req, response }];
185
+ }
@@ -0,0 +1,61 @@
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
+ AccountSummary,
12
+ AccountSummary$inboundSchema,
13
+ } from "./accountsummary.js";
14
+ import {
15
+ LoopedPosition,
16
+ LoopedPosition$inboundSchema,
17
+ } from "./loopedposition.js";
18
+
19
+ /**
20
+ * Looped positions across Aave V3 and Morpho Blue for a credit account.
21
+ */
22
+ export type CreditLoopedPositionsResponse = {
23
+ /**
24
+ * The credit product account address derived from the owner.
25
+ */
26
+ creditAccountAddress: string;
27
+ /**
28
+ * All looped positions, on both Aave and Morpho.
29
+ */
30
+ positions?: Array<LoopedPosition> | undefined;
31
+ /**
32
+ * Aave account-level summary (health factor, LTV, borrow capacity). Present when the account holds any open Aave looped position, since Aave collateral is pooled and health is account-level. Null for Morpho-only accounts.
33
+ */
34
+ aaveAccountSummary?: AccountSummary | null | undefined;
35
+ };
36
+
37
+ /** @internal */
38
+ export const CreditLoopedPositionsResponse$inboundSchema: z.ZodType<
39
+ CreditLoopedPositionsResponse,
40
+ z.ZodTypeDef,
41
+ unknown
42
+ > = z.object({
43
+ credit_account_address: z.string(),
44
+ positions: z.array(LoopedPosition$inboundSchema).optional(),
45
+ aave_account_summary: z.nullable(AccountSummary$inboundSchema).optional(),
46
+ }).transform((v) => {
47
+ return remap$(v, {
48
+ "credit_account_address": "creditAccountAddress",
49
+ "aave_account_summary": "aaveAccountSummary",
50
+ });
51
+ });
52
+
53
+ export function creditLoopedPositionsResponseFromJSON(
54
+ jsonString: string,
55
+ ): SafeParseResult<CreditLoopedPositionsResponse, SDKValidationError> {
56
+ return safeParse(
57
+ jsonString,
58
+ (x) => CreditLoopedPositionsResponse$inboundSchema.parse(JSON.parse(x)),
59
+ `Failed to parse 'CreditLoopedPositionsResponse' from JSON`,
60
+ );
61
+ }
@@ -102,6 +102,7 @@ export * from "./creditbundleresponse.js";
102
102
  export * from "./creditenablecollateralparams.js";
103
103
  export * from "./creditevent.js";
104
104
  export * from "./creditfee.js";
105
+ export * from "./creditloopedpositionsresponse.js";
105
106
  export * from "./creditlooppreview.js";
106
107
  export * from "./creditlooprequest.js";
107
108
  export * from "./creditloopresponse.js";
@@ -185,6 +186,10 @@ export * from "./globalmarketsperpswithdrawrequest.js";
185
186
  export * from "./interestratemode.js";
186
187
  export * from "./liquidationcall.js";
187
188
  export * from "./listaavemarketsresponse.js";
189
+ export * from "./loopedposition.js";
190
+ export * from "./loopedpositioncurrentstate.js";
191
+ export * from "./loopedpositionhistoryentry.js";
192
+ export * from "./loopedpositiontotals.js";
188
193
  export * from "./looplegpreview.js";
189
194
  export * from "./lpbalance.js";
190
195
  export * from "./marketallocation.js";
@@ -299,6 +304,7 @@ export * from "./sponsorgasresponse.js";
299
304
  export * from "./supply.js";
300
305
  export * from "./supportedchaininfo.js";
301
306
  export * from "./swapborrowrate.js";
307
+ export * from "./swapinfo.js";
302
308
  export * from "./syposition.js";
303
309
  export * from "./tokenamount.js";
304
310
  export * from "./tokenbalanceresponse.js";
@@ -0,0 +1,149 @@
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 { ClosedEnum } from "../../types/enums.js";
9
+ import { Result as SafeParseResult } from "../../types/fp.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+ import {
12
+ CreditProtocol,
13
+ CreditProtocol$inboundSchema,
14
+ } from "./creditprotocol.js";
15
+ import {
16
+ LoopedPositionCurrentState,
17
+ LoopedPositionCurrentState$inboundSchema,
18
+ } from "./loopedpositioncurrentstate.js";
19
+ import {
20
+ LoopedPositionHistoryEntry,
21
+ LoopedPositionHistoryEntry$inboundSchema,
22
+ } from "./loopedpositionhistoryentry.js";
23
+ import {
24
+ LoopedPositionTotals,
25
+ LoopedPositionTotals$inboundSchema,
26
+ } from "./loopedpositiontotals.js";
27
+
28
+ /**
29
+ * Whether the position is currently open or fully closed.
30
+ */
31
+ export const LoopedPositionStatus = {
32
+ Open: "OPEN",
33
+ Closed: "CLOSED",
34
+ } as const;
35
+ /**
36
+ * Whether the position is currently open or fully closed.
37
+ */
38
+ export type LoopedPositionStatus = ClosedEnum<typeof LoopedPositionStatus>;
39
+
40
+ /**
41
+ * A single looped (leveraged) position with its full history.
42
+ */
43
+ export type LoopedPosition = {
44
+ /**
45
+ * Which lending protocol a credit action targets.
46
+ *
47
+ * @remarks
48
+ *
49
+ * ``AAVE`` is the default so existing callers (which never send a ``protocol``
50
+ * field) keep hitting the unchanged Aave code path. ``EULER`` opts in to the
51
+ * Euler V2 path, where the market is identified by EVK vault address(es).
52
+ * ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id) and is
53
+ * currently read-only: positions and market discovery only — transaction
54
+ * builders land with the looping work (COM-7106/7107/7108), so transact
55
+ * endpoints reject it with a 422.
56
+ */
57
+ protocol: CreditProtocol;
58
+ /**
59
+ * Morpho only: the bytes32 id of the isolated market.
60
+ */
61
+ marketId?: string | null | undefined;
62
+ /**
63
+ * Address of the collateral token.
64
+ */
65
+ collateralToken: string;
66
+ /**
67
+ * Symbol of the collateral token.
68
+ */
69
+ collateralSymbol: string;
70
+ /**
71
+ * Address of the debt token.
72
+ */
73
+ debtToken: string;
74
+ /**
75
+ * Symbol of the debt token.
76
+ */
77
+ debtSymbol: string;
78
+ /**
79
+ * Whether the position is currently open or fully closed.
80
+ */
81
+ status: LoopedPositionStatus;
82
+ /**
83
+ * Timestamp of the position's first transaction.
84
+ */
85
+ openedAt: Date;
86
+ /**
87
+ * Timestamp the position was fully closed; null while open.
88
+ */
89
+ closedAt?: Date | null | undefined;
90
+ /**
91
+ * Live on-chain state; null for CLOSED positions.
92
+ */
93
+ current?: LoopedPositionCurrentState | null | undefined;
94
+ /**
95
+ * Lifetime totals across all of a looped position's transactions.
96
+ */
97
+ totals: LoopedPositionTotals;
98
+ /**
99
+ * All transactions for this position, chronological.
100
+ */
101
+ history?: Array<LoopedPositionHistoryEntry> | undefined;
102
+ };
103
+
104
+ /** @internal */
105
+ export const LoopedPositionStatus$inboundSchema: z.ZodNativeEnum<
106
+ typeof LoopedPositionStatus
107
+ > = z.nativeEnum(LoopedPositionStatus);
108
+
109
+ /** @internal */
110
+ export const LoopedPosition$inboundSchema: z.ZodType<
111
+ LoopedPosition,
112
+ z.ZodTypeDef,
113
+ unknown
114
+ > = z.object({
115
+ protocol: CreditProtocol$inboundSchema,
116
+ market_id: z.nullable(z.string()).optional(),
117
+ collateral_token: z.string(),
118
+ collateral_symbol: z.string(),
119
+ debt_token: z.string(),
120
+ debt_symbol: z.string(),
121
+ status: LoopedPositionStatus$inboundSchema,
122
+ opened_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
123
+ closed_at: z.nullable(
124
+ z.string().datetime({ offset: true }).transform(v => new Date(v)),
125
+ ).optional(),
126
+ current: z.nullable(LoopedPositionCurrentState$inboundSchema).optional(),
127
+ totals: LoopedPositionTotals$inboundSchema,
128
+ history: z.array(LoopedPositionHistoryEntry$inboundSchema).optional(),
129
+ }).transform((v) => {
130
+ return remap$(v, {
131
+ "market_id": "marketId",
132
+ "collateral_token": "collateralToken",
133
+ "collateral_symbol": "collateralSymbol",
134
+ "debt_token": "debtToken",
135
+ "debt_symbol": "debtSymbol",
136
+ "opened_at": "openedAt",
137
+ "closed_at": "closedAt",
138
+ });
139
+ });
140
+
141
+ export function loopedPositionFromJSON(
142
+ jsonString: string,
143
+ ): SafeParseResult<LoopedPosition, SDKValidationError> {
144
+ return safeParse(
145
+ jsonString,
146
+ (x) => LoopedPosition$inboundSchema.parse(JSON.parse(x)),
147
+ `Failed to parse 'LoopedPosition' from JSON`,
148
+ );
149
+ }
@@ -0,0 +1,101 @@
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 { ClosedEnum } from "../../types/enums.js";
9
+ import { Result as SafeParseResult } from "../../types/fp.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+
12
+ /**
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
+ */
15
+ export const HealthFactorScope = {
16
+ Market: "market",
17
+ Account: "account",
18
+ } as const;
19
+ /**
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
+ */
22
+ export type HealthFactorScope = ClosedEnum<typeof HealthFactorScope>;
23
+
24
+ /**
25
+ * Live on-chain state of an OPEN looped position.
26
+ */
27
+ export type LoopedPositionCurrentState = {
28
+ /**
29
+ * Current on-chain collateral amount for this position.
30
+ */
31
+ collateralAmount: string | null;
32
+ /**
33
+ * Current on-chain debt amount for this position.
34
+ */
35
+ debtAmount: string | null;
36
+ /**
37
+ * Collateral value in USD (null if unpriced).
38
+ */
39
+ collateralUsd?: string | null | undefined;
40
+ /**
41
+ * Debt value in USD (null if unpriced).
42
+ */
43
+ debtUsd?: string | null | undefined;
44
+ /**
45
+ * Net position value in USD (collateral - debt); null if unpriced.
46
+ */
47
+ netUsdValue?: string | null | undefined;
48
+ /**
49
+ * Leverage multiplier: collateral_usd / (collateral_usd - debt_usd). Null when unpriced or net value is non-positive.
50
+ */
51
+ leverage?: string | null | undefined;
52
+ /**
53
+ * Health factor. Above 1 is safe; below 1 risks liquidation. See health_factor_scope for what it covers.
54
+ */
55
+ healthFactor?: string | null | undefined;
56
+ /**
57
+ * '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
+ */
59
+ healthFactorScope: HealthFactorScope;
60
+ };
61
+
62
+ /** @internal */
63
+ export const HealthFactorScope$inboundSchema: z.ZodNativeEnum<
64
+ typeof HealthFactorScope
65
+ > = z.nativeEnum(HealthFactorScope);
66
+
67
+ /** @internal */
68
+ export const LoopedPositionCurrentState$inboundSchema: z.ZodType<
69
+ LoopedPositionCurrentState,
70
+ z.ZodTypeDef,
71
+ unknown
72
+ > = z.object({
73
+ collateral_amount: z.nullable(z.string()),
74
+ debt_amount: z.nullable(z.string()),
75
+ collateral_usd: z.nullable(z.string()).optional(),
76
+ debt_usd: z.nullable(z.string()).optional(),
77
+ net_usd_value: z.nullable(z.string()).optional(),
78
+ leverage: z.nullable(z.string()).optional(),
79
+ health_factor: z.nullable(z.string()).optional(),
80
+ health_factor_scope: HealthFactorScope$inboundSchema,
81
+ }).transform((v) => {
82
+ return remap$(v, {
83
+ "collateral_amount": "collateralAmount",
84
+ "debt_amount": "debtAmount",
85
+ "collateral_usd": "collateralUsd",
86
+ "debt_usd": "debtUsd",
87
+ "net_usd_value": "netUsdValue",
88
+ "health_factor": "healthFactor",
89
+ "health_factor_scope": "healthFactorScope",
90
+ });
91
+ });
92
+
93
+ export function loopedPositionCurrentStateFromJSON(
94
+ jsonString: string,
95
+ ): SafeParseResult<LoopedPositionCurrentState, SDKValidationError> {
96
+ return safeParse(
97
+ jsonString,
98
+ (x) => LoopedPositionCurrentState$inboundSchema.parse(JSON.parse(x)),
99
+ `Failed to parse 'LoopedPositionCurrentState' from JSON`,
100
+ );
101
+ }
@@ -0,0 +1,115 @@
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 { ClosedEnum } from "../../types/enums.js";
9
+ import { Result as SafeParseResult } from "../../types/fp.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+ import { CreditEvent, CreditEvent$inboundSchema } from "./creditevent.js";
12
+ import { SwapInfo, SwapInfo$inboundSchema } from "./swapinfo.js";
13
+
14
+ /**
15
+ * What this transaction did to the position: loop_open / loop_increase (lever up with a swap), unwind (delever), single-sided supply/withdraw/borrow/repay, liquidation, or mixed.
16
+ */
17
+ export const Classification = {
18
+ LoopOpen: "loop_open",
19
+ LoopIncrease: "loop_increase",
20
+ Unwind: "unwind",
21
+ Supply: "supply",
22
+ Withdraw: "withdraw",
23
+ Borrow: "borrow",
24
+ Repay: "repay",
25
+ Liquidation: "liquidation",
26
+ Mixed: "mixed",
27
+ } as const;
28
+ /**
29
+ * What this transaction did to the position: loop_open / loop_increase (lever up with a swap), unwind (delever), single-sided supply/withdraw/borrow/repay, liquidation, or mixed.
30
+ */
31
+ export type Classification = ClosedEnum<typeof Classification>;
32
+
33
+ /**
34
+ * One transaction in a looped position's lifetime.
35
+ */
36
+ export type LoopedPositionHistoryEntry = {
37
+ /**
38
+ * Transaction hash.
39
+ */
40
+ transactionHash: string;
41
+ /**
42
+ * Block number of the transaction.
43
+ */
44
+ blockNumber: number;
45
+ /**
46
+ * Timestamp of the transaction.
47
+ */
48
+ blockTimestamp: Date;
49
+ /**
50
+ * What this transaction did to the position: loop_open / loop_increase (lever up with a swap), unwind (delever), single-sided supply/withdraw/borrow/repay, liquidation, or mixed.
51
+ */
52
+ classification: Classification;
53
+ /**
54
+ * Loop transactions only: number of borrow legs in this transaction (one per loop iteration). Null for non-loop transactions.
55
+ */
56
+ iterations?: number | null | undefined;
57
+ /**
58
+ * Signed change in collateral in this transaction (positive = added).
59
+ */
60
+ collateralDelta: string;
61
+ /**
62
+ * Signed change in debt in this transaction (positive = borrowed).
63
+ */
64
+ debtDelta: string;
65
+ /**
66
+ * The swap leg detected in this transaction, if any.
67
+ */
68
+ swap?: SwapInfo | null | undefined;
69
+ /**
70
+ * The raw lending events that make up this transaction (Morpho supply_collateral maps to 'supply', withdraw_collateral to 'withdraw').
71
+ */
72
+ events?: Array<CreditEvent> | undefined;
73
+ };
74
+
75
+ /** @internal */
76
+ export const Classification$inboundSchema: z.ZodNativeEnum<
77
+ typeof Classification
78
+ > = z.nativeEnum(Classification);
79
+
80
+ /** @internal */
81
+ export const LoopedPositionHistoryEntry$inboundSchema: z.ZodType<
82
+ LoopedPositionHistoryEntry,
83
+ z.ZodTypeDef,
84
+ unknown
85
+ > = z.object({
86
+ transaction_hash: z.string(),
87
+ block_number: z.number().int(),
88
+ block_timestamp: z.string().datetime({ offset: true }).transform(v =>
89
+ new Date(v)
90
+ ),
91
+ classification: Classification$inboundSchema,
92
+ iterations: z.nullable(z.number().int()).optional(),
93
+ collateral_delta: z.string(),
94
+ debt_delta: z.string(),
95
+ swap: z.nullable(SwapInfo$inboundSchema).optional(),
96
+ events: z.array(CreditEvent$inboundSchema).optional(),
97
+ }).transform((v) => {
98
+ return remap$(v, {
99
+ "transaction_hash": "transactionHash",
100
+ "block_number": "blockNumber",
101
+ "block_timestamp": "blockTimestamp",
102
+ "collateral_delta": "collateralDelta",
103
+ "debt_delta": "debtDelta",
104
+ });
105
+ });
106
+
107
+ export function loopedPositionHistoryEntryFromJSON(
108
+ jsonString: string,
109
+ ): SafeParseResult<LoopedPositionHistoryEntry, SDKValidationError> {
110
+ return safeParse(
111
+ jsonString,
112
+ (x) => LoopedPositionHistoryEntry$inboundSchema.parse(JSON.parse(x)),
113
+ `Failed to parse 'LoopedPositionHistoryEntry' from JSON`,
114
+ );
115
+ }