@compass-labs/api-sdk 2.2.79 → 2.2.80-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.
- 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,178 @@
|
|
|
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 {
|
|
8
|
+
CreditProtocol,
|
|
9
|
+
CreditProtocol$outboundSchema,
|
|
10
|
+
} from "./creditprotocol.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SIZE knob: the net value (collateral − debt, in USD) to commit to this position; total collateral ≈ target_equity_usd × target_multiplier. To remove a position use close=true, never target_equity_usd=0.
|
|
14
|
+
*/
|
|
15
|
+
export type TargetEquityUsd = number | string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* LEVERAGE knob: total collateral exposure ÷ equity. 1 means unlevered supplied collateral. The protocol maximum is enforced when the plan is built.
|
|
19
|
+
*/
|
|
20
|
+
export type RebalanceTargetTargetMultiplier = number | string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Per-target override of the request-level per-swap slippage tolerance in percent.
|
|
24
|
+
*/
|
|
25
|
+
export type RebalanceTargetMaxSlippagePercent = number | string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The desired end-state of ONE position in the Credit Account.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
*
|
|
32
|
+
* Scoped-declarative: only positions named in ``targets`` are touched; anything
|
|
33
|
+
* unlisted is left as-is. Set ``close=true`` to fully unwind a position — never
|
|
34
|
+
* ``target_equity_usd=0``.
|
|
35
|
+
*/
|
|
36
|
+
export type RebalanceTarget = {
|
|
37
|
+
/**
|
|
38
|
+
* Which lending protocol a credit action targets.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
*
|
|
42
|
+
* ``AAVE`` is the default so existing callers (which never send a ``protocol``
|
|
43
|
+
* field) keep hitting the unchanged Aave code path. ``EULER`` opts in to the
|
|
44
|
+
* Euler V2 path, where the market is identified by EVK vault address(es).
|
|
45
|
+
* ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id) and is
|
|
46
|
+
* currently read-only: positions and market discovery only — transaction
|
|
47
|
+
* builders land with the looping work (COM-7106/7107/7108), so transact
|
|
48
|
+
* endpoints reject it with a 422.
|
|
49
|
+
*/
|
|
50
|
+
protocol?: CreditProtocol | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.
|
|
53
|
+
*/
|
|
54
|
+
marketId?: string | null | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Token supplied as collateral for this position. For MORPHO it must be the market's collateral token.
|
|
57
|
+
*/
|
|
58
|
+
collateralToken: string;
|
|
59
|
+
/**
|
|
60
|
+
* Token borrowed against the collateral for this position. For MORPHO it must be the market's loan token.
|
|
61
|
+
*/
|
|
62
|
+
borrowToken: string;
|
|
63
|
+
/**
|
|
64
|
+
* SIZE knob: the net value (collateral − debt, in USD) to commit to this position; total collateral ≈ target_equity_usd × target_multiplier. To remove a position use close=true, never target_equity_usd=0.
|
|
65
|
+
*/
|
|
66
|
+
targetEquityUsd?: number | string | null | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* LEVERAGE knob: total collateral exposure ÷ equity. 1 means unlevered supplied collateral. The protocol maximum is enforced when the plan is built.
|
|
69
|
+
*/
|
|
70
|
+
targetMultiplier?: number | string | null | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* If true, fully unwind this position: the debt is cleared exactly (accrued interest included) and the pair collateral is returned to the Credit Account.
|
|
73
|
+
*/
|
|
74
|
+
close?: boolean | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Per-target override of the request-level per-swap slippage tolerance in percent.
|
|
77
|
+
*/
|
|
78
|
+
maxSlippagePercent?: number | string | null | undefined;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** @internal */
|
|
82
|
+
export type TargetEquityUsd$Outbound = number | string;
|
|
83
|
+
|
|
84
|
+
/** @internal */
|
|
85
|
+
export const TargetEquityUsd$outboundSchema: z.ZodType<
|
|
86
|
+
TargetEquityUsd$Outbound,
|
|
87
|
+
z.ZodTypeDef,
|
|
88
|
+
TargetEquityUsd
|
|
89
|
+
> = z.union([z.number(), z.string()]);
|
|
90
|
+
|
|
91
|
+
export function targetEquityUsdToJSON(
|
|
92
|
+
targetEquityUsd: TargetEquityUsd,
|
|
93
|
+
): string {
|
|
94
|
+
return JSON.stringify(TargetEquityUsd$outboundSchema.parse(targetEquityUsd));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @internal */
|
|
98
|
+
export type RebalanceTargetTargetMultiplier$Outbound = number | string;
|
|
99
|
+
|
|
100
|
+
/** @internal */
|
|
101
|
+
export const RebalanceTargetTargetMultiplier$outboundSchema: z.ZodType<
|
|
102
|
+
RebalanceTargetTargetMultiplier$Outbound,
|
|
103
|
+
z.ZodTypeDef,
|
|
104
|
+
RebalanceTargetTargetMultiplier
|
|
105
|
+
> = z.union([z.number(), z.string()]);
|
|
106
|
+
|
|
107
|
+
export function rebalanceTargetTargetMultiplierToJSON(
|
|
108
|
+
rebalanceTargetTargetMultiplier: RebalanceTargetTargetMultiplier,
|
|
109
|
+
): string {
|
|
110
|
+
return JSON.stringify(
|
|
111
|
+
RebalanceTargetTargetMultiplier$outboundSchema.parse(
|
|
112
|
+
rebalanceTargetTargetMultiplier,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @internal */
|
|
118
|
+
export type RebalanceTargetMaxSlippagePercent$Outbound = number | string;
|
|
119
|
+
|
|
120
|
+
/** @internal */
|
|
121
|
+
export const RebalanceTargetMaxSlippagePercent$outboundSchema: z.ZodType<
|
|
122
|
+
RebalanceTargetMaxSlippagePercent$Outbound,
|
|
123
|
+
z.ZodTypeDef,
|
|
124
|
+
RebalanceTargetMaxSlippagePercent
|
|
125
|
+
> = z.union([z.number(), z.string()]);
|
|
126
|
+
|
|
127
|
+
export function rebalanceTargetMaxSlippagePercentToJSON(
|
|
128
|
+
rebalanceTargetMaxSlippagePercent: RebalanceTargetMaxSlippagePercent,
|
|
129
|
+
): string {
|
|
130
|
+
return JSON.stringify(
|
|
131
|
+
RebalanceTargetMaxSlippagePercent$outboundSchema.parse(
|
|
132
|
+
rebalanceTargetMaxSlippagePercent,
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** @internal */
|
|
138
|
+
export type RebalanceTarget$Outbound = {
|
|
139
|
+
protocol?: string | undefined;
|
|
140
|
+
market_id?: string | null | undefined;
|
|
141
|
+
collateral_token: string;
|
|
142
|
+
borrow_token: string;
|
|
143
|
+
target_equity_usd?: number | string | null | undefined;
|
|
144
|
+
target_multiplier?: number | string | null | undefined;
|
|
145
|
+
close?: boolean | undefined;
|
|
146
|
+
max_slippage_percent?: number | string | null | undefined;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** @internal */
|
|
150
|
+
export const RebalanceTarget$outboundSchema: z.ZodType<
|
|
151
|
+
RebalanceTarget$Outbound,
|
|
152
|
+
z.ZodTypeDef,
|
|
153
|
+
RebalanceTarget
|
|
154
|
+
> = z.object({
|
|
155
|
+
protocol: CreditProtocol$outboundSchema.optional(),
|
|
156
|
+
marketId: z.nullable(z.string()).optional(),
|
|
157
|
+
collateralToken: z.string(),
|
|
158
|
+
borrowToken: z.string(),
|
|
159
|
+
targetEquityUsd: z.nullable(z.union([z.number(), z.string()])).optional(),
|
|
160
|
+
targetMultiplier: z.nullable(z.union([z.number(), z.string()])).optional(),
|
|
161
|
+
close: z.boolean().optional(),
|
|
162
|
+
maxSlippagePercent: z.nullable(z.union([z.number(), z.string()])).optional(),
|
|
163
|
+
}).transform((v) => {
|
|
164
|
+
return remap$(v, {
|
|
165
|
+
marketId: "market_id",
|
|
166
|
+
collateralToken: "collateral_token",
|
|
167
|
+
borrowToken: "borrow_token",
|
|
168
|
+
targetEquityUsd: "target_equity_usd",
|
|
169
|
+
targetMultiplier: "target_multiplier",
|
|
170
|
+
maxSlippagePercent: "max_slippage_percent",
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export function rebalanceTargetToJSON(
|
|
175
|
+
rebalanceTarget: RebalanceTarget,
|
|
176
|
+
): string {
|
|
177
|
+
return JSON.stringify(RebalanceTarget$outboundSchema.parse(rebalanceTarget));
|
|
178
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
LoopLegPreview,
|
|
17
|
+
LoopLegPreview$inboundSchema,
|
|
18
|
+
} from "./looplegpreview.js";
|
|
19
|
+
import {
|
|
20
|
+
RebalanceDirection,
|
|
21
|
+
RebalanceDirection$inboundSchema,
|
|
22
|
+
} from "./rebalancedirection.js";
|
|
23
|
+
import {
|
|
24
|
+
UnloopLegPreview,
|
|
25
|
+
UnloopLegPreview$inboundSchema,
|
|
26
|
+
} from "./unlooplegpreview.js";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* '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.
|
|
30
|
+
*/
|
|
31
|
+
export const RebalanceTargetPreviewHealthFactorScope = {
|
|
32
|
+
Market: "market",
|
|
33
|
+
Account: "account",
|
|
34
|
+
} as const;
|
|
35
|
+
/**
|
|
36
|
+
* '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.
|
|
37
|
+
*/
|
|
38
|
+
export type RebalanceTargetPreviewHealthFactorScope = ClosedEnum<
|
|
39
|
+
typeof RebalanceTargetPreviewHealthFactorScope
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Projected end state of ONE named target, computed on guaranteed swap floors.
|
|
44
|
+
*/
|
|
45
|
+
export type RebalanceTargetPreview = {
|
|
46
|
+
/**
|
|
47
|
+
* Which lending protocol a credit action targets.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
*
|
|
51
|
+
* ``AAVE`` is the default so existing callers (which never send a ``protocol``
|
|
52
|
+
* field) keep hitting the unchanged Aave code path. ``EULER`` opts in to the
|
|
53
|
+
* Euler V2 path, where the market is identified by EVK vault address(es).
|
|
54
|
+
* ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id) and is
|
|
55
|
+
* currently read-only: positions and market discovery only — transaction
|
|
56
|
+
* builders land with the looping work (COM-7106/7107/7108), so transact
|
|
57
|
+
* endpoints reject it with a 422.
|
|
58
|
+
*/
|
|
59
|
+
protocol: CreditProtocol;
|
|
60
|
+
/**
|
|
61
|
+
* Morpho only: the bytes32 market id of this position.
|
|
62
|
+
*/
|
|
63
|
+
marketId?: string | null | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Collateral token address (echoes the request target; joins against /v2/credit/looped_positions).
|
|
66
|
+
*/
|
|
67
|
+
collateralToken: string;
|
|
68
|
+
/**
|
|
69
|
+
* Borrow token address (echoes the request target).
|
|
70
|
+
*/
|
|
71
|
+
borrowToken: string;
|
|
72
|
+
/**
|
|
73
|
+
* What the plan does to one named target.
|
|
74
|
+
*/
|
|
75
|
+
direction: RebalanceDirection;
|
|
76
|
+
/**
|
|
77
|
+
* On-chain legs planned for this target (loop + unloop iterations); 0 for a noop.
|
|
78
|
+
*/
|
|
79
|
+
legs: number;
|
|
80
|
+
/**
|
|
81
|
+
* Per-iteration unwind breakdown — populated for releasers (close / shrink / lever_down).
|
|
82
|
+
*/
|
|
83
|
+
unloopLegs?: Array<UnloopLegPreview> | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Per-iteration loop breakdown — populated for consumers (open / grow / lever_up).
|
|
86
|
+
*/
|
|
87
|
+
loopLegs?: Array<LoopLegPreview> | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Guaranteed minimum collateral supplied to this position after the rebalance (token units).
|
|
90
|
+
*/
|
|
91
|
+
resultingCollateral: string;
|
|
92
|
+
/**
|
|
93
|
+
* Projected debt owed by this position after the rebalance (borrow-token units); 0 on a close.
|
|
94
|
+
*/
|
|
95
|
+
resultingDebt: string;
|
|
96
|
+
/**
|
|
97
|
+
* Projected leverage of this position after the rebalance; 1 when the debt is cleared. Never promises more leverage (or, when deleveraging, more deleverage) than is guaranteed.
|
|
98
|
+
*/
|
|
99
|
+
resultingMultiplier: string;
|
|
100
|
+
/**
|
|
101
|
+
* Projected health factor of this position after the rebalance. Never overstated at the 1.0 boundary — a liquidatable position is never presented as safe. See health_factor_scope for what it covers.
|
|
102
|
+
*/
|
|
103
|
+
resultingHealthFactor: string;
|
|
104
|
+
/**
|
|
105
|
+
* '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.
|
|
106
|
+
*/
|
|
107
|
+
healthFactorScope: RebalanceTargetPreviewHealthFactorScope;
|
|
108
|
+
/**
|
|
109
|
+
* Upper bound of surplus this target's own swaps can leave in the Credit Account (sum of each swap's quote minus its guaranteed floor). Routing swaps are counted book-level, not here. It accumulates in the Credit Account, is recoverable, and is never lost.
|
|
110
|
+
*/
|
|
111
|
+
estimatedMaxDust: string;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** @internal */
|
|
115
|
+
export const RebalanceTargetPreviewHealthFactorScope$inboundSchema:
|
|
116
|
+
z.ZodNativeEnum<typeof RebalanceTargetPreviewHealthFactorScope> = z
|
|
117
|
+
.nativeEnum(RebalanceTargetPreviewHealthFactorScope);
|
|
118
|
+
|
|
119
|
+
/** @internal */
|
|
120
|
+
export const RebalanceTargetPreview$inboundSchema: z.ZodType<
|
|
121
|
+
RebalanceTargetPreview,
|
|
122
|
+
z.ZodTypeDef,
|
|
123
|
+
unknown
|
|
124
|
+
> = z.object({
|
|
125
|
+
protocol: CreditProtocol$inboundSchema,
|
|
126
|
+
market_id: z.nullable(z.string()).optional(),
|
|
127
|
+
collateral_token: z.string(),
|
|
128
|
+
borrow_token: z.string(),
|
|
129
|
+
direction: RebalanceDirection$inboundSchema,
|
|
130
|
+
legs: z.number().int(),
|
|
131
|
+
unloop_legs: z.array(UnloopLegPreview$inboundSchema).optional(),
|
|
132
|
+
loop_legs: z.array(LoopLegPreview$inboundSchema).optional(),
|
|
133
|
+
resulting_collateral: z.string(),
|
|
134
|
+
resulting_debt: z.string(),
|
|
135
|
+
resulting_multiplier: z.string(),
|
|
136
|
+
resulting_health_factor: z.string(),
|
|
137
|
+
health_factor_scope: RebalanceTargetPreviewHealthFactorScope$inboundSchema,
|
|
138
|
+
estimated_max_dust: z.string(),
|
|
139
|
+
}).transform((v) => {
|
|
140
|
+
return remap$(v, {
|
|
141
|
+
"market_id": "marketId",
|
|
142
|
+
"collateral_token": "collateralToken",
|
|
143
|
+
"borrow_token": "borrowToken",
|
|
144
|
+
"unloop_legs": "unloopLegs",
|
|
145
|
+
"loop_legs": "loopLegs",
|
|
146
|
+
"resulting_collateral": "resultingCollateral",
|
|
147
|
+
"resulting_debt": "resultingDebt",
|
|
148
|
+
"resulting_multiplier": "resultingMultiplier",
|
|
149
|
+
"resulting_health_factor": "resultingHealthFactor",
|
|
150
|
+
"health_factor_scope": "healthFactorScope",
|
|
151
|
+
"estimated_max_dust": "estimatedMaxDust",
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export function rebalanceTargetPreviewFromJSON(
|
|
156
|
+
jsonString: string,
|
|
157
|
+
): SafeParseResult<RebalanceTargetPreview, SDKValidationError> {
|
|
158
|
+
return safeParse(
|
|
159
|
+
jsonString,
|
|
160
|
+
(x) => RebalanceTargetPreview$inboundSchema.parse(JSON.parse(x)),
|
|
161
|
+
`Failed to parse 'RebalanceTargetPreview' from JSON`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 Phase-B capital-routing swap that moves freed tokens between positions.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
*
|
|
16
|
+
* Book-level: it is not attributable to a single target.
|
|
17
|
+
*/
|
|
18
|
+
export type RoutingSwapPreview = {
|
|
19
|
+
/**
|
|
20
|
+
* Token sold by the Credit Account into this routing swap.
|
|
21
|
+
*/
|
|
22
|
+
tokenIn: string;
|
|
23
|
+
/**
|
|
24
|
+
* Token bought and delivered to fund a consuming position.
|
|
25
|
+
*/
|
|
26
|
+
tokenOut: string;
|
|
27
|
+
/**
|
|
28
|
+
* Token-in amount the Credit Account gives up to this swap.
|
|
29
|
+
*/
|
|
30
|
+
amountIn: string;
|
|
31
|
+
/**
|
|
32
|
+
* Guaranteed minimum output (token-out units), enforced on-chain by the swap's minimum-return. Any fill above it stays in the Credit Account as recoverable dust.
|
|
33
|
+
*/
|
|
34
|
+
minAmountOut: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** @internal */
|
|
38
|
+
export const RoutingSwapPreview$inboundSchema: z.ZodType<
|
|
39
|
+
RoutingSwapPreview,
|
|
40
|
+
z.ZodTypeDef,
|
|
41
|
+
unknown
|
|
42
|
+
> = z.object({
|
|
43
|
+
token_in: z.string(),
|
|
44
|
+
token_out: z.string(),
|
|
45
|
+
amount_in: z.string(),
|
|
46
|
+
min_amount_out: z.string(),
|
|
47
|
+
}).transform((v) => {
|
|
48
|
+
return remap$(v, {
|
|
49
|
+
"token_in": "tokenIn",
|
|
50
|
+
"token_out": "tokenOut",
|
|
51
|
+
"amount_in": "amountIn",
|
|
52
|
+
"min_amount_out": "minAmountOut",
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export function routingSwapPreviewFromJSON(
|
|
57
|
+
jsonString: string,
|
|
58
|
+
): SafeParseResult<RoutingSwapPreview, SDKValidationError> {
|
|
59
|
+
return safeParse(
|
|
60
|
+
jsonString,
|
|
61
|
+
(x) => RoutingSwapPreview$inboundSchema.parse(JSON.parse(x)),
|
|
62
|
+
`Failed to parse 'RoutingSwapPreview' from JSON`,
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/sdk/credit.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { creditCreditLoop } from "../funcs/creditCreditLoop.js";
|
|
|
11
11
|
import { creditCreditLoopedPositions } from "../funcs/creditCreditLoopedPositions.js";
|
|
12
12
|
import { creditCreditMorphoMarkets } from "../funcs/creditCreditMorphoMarkets.js";
|
|
13
13
|
import { creditCreditPositions } from "../funcs/creditCreditPositions.js";
|
|
14
|
+
import { creditCreditRebalance } from "../funcs/creditCreditRebalance.js";
|
|
14
15
|
import { creditCreditRepay } from "../funcs/creditCreditRepay.js";
|
|
15
16
|
import { creditCreditTransfer } from "../funcs/creditCreditTransfer.js";
|
|
16
17
|
import { creditCreditUnloop } from "../funcs/creditCreditUnloop.js";
|
|
@@ -246,6 +247,50 @@ export class Credit extends ClientSDK {
|
|
|
246
247
|
));
|
|
247
248
|
}
|
|
248
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Rebalance the leveraged credit book
|
|
252
|
+
*
|
|
253
|
+
* @remarks
|
|
254
|
+
* Rebalance the leveraged credit book in ONE atomic transaction.
|
|
255
|
+
*
|
|
256
|
+
* List only the positions to change — anything not named is left untouched;
|
|
257
|
+
* remove a position with close=true. Each target states an end state:
|
|
258
|
+
* target_equity_usd (net USD committed) × target_multiplier.
|
|
259
|
+
*
|
|
260
|
+
* Releasing targets run first (each unwind/delever frees tokens into the Credit
|
|
261
|
+
* Account), the freed tokens are then routed by swaps at a GUARANTEED minimum
|
|
262
|
+
* output (enforced on-chain), and consuming targets run last — so moving a
|
|
263
|
+
* levered position between markets, token pairs, or protocols (Aave ↔ Morpho) is
|
|
264
|
+
* simply a close plus an open in the same transaction.
|
|
265
|
+
*
|
|
266
|
+
* Net book growth is funded from the Credit Account's existing idle balance —
|
|
267
|
+
* fund it first via /v2/credit/transfer; a net release stays in the Credit
|
|
268
|
+
* Account as idle balance. Any swap surplus above the guaranteed floors also
|
|
269
|
+
* stays in the Credit Account (preview.estimated_max_dust) — recoverable, never
|
|
270
|
+
* lost.
|
|
271
|
+
*
|
|
272
|
+
* A book already at its target returns transaction: null with the preview — the
|
|
273
|
+
* call is idempotent and safe to drive from a converge-to-target loop.
|
|
274
|
+
*
|
|
275
|
+
* A rebalance too large for one transaction is rejected with a 422 — split it
|
|
276
|
+
* into two calls. Every deleveraging step keeps the health factor ≥ 1.02 and
|
|
277
|
+
* every leveraging step respects the protocol's borrow limits; Aave targets share
|
|
278
|
+
* one account-level health factor, which the preview reports.
|
|
279
|
+
*
|
|
280
|
+
* For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect the
|
|
281
|
+
* current book via /v2/credit/looped_positions.
|
|
282
|
+
*/
|
|
283
|
+
async creditRebalance(
|
|
284
|
+
request: components.CreditRebalanceRequest,
|
|
285
|
+
options?: RequestOptions,
|
|
286
|
+
): Promise<components.CreditRebalanceResponse> {
|
|
287
|
+
return unwrapAsync(creditCreditRebalance(
|
|
288
|
+
this,
|
|
289
|
+
request,
|
|
290
|
+
options,
|
|
291
|
+
));
|
|
292
|
+
}
|
|
293
|
+
|
|
249
294
|
/**
|
|
250
295
|
* Transfer tokens to/from Credit Account
|
|
251
296
|
*
|