@compass-labs/api-sdk 2.2.60 → 2.2.61
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 +4 -2
- package/codeSamples_typescript.yaml +6 -0
- package/dist/commonjs/funcs/earnEarnSwapQuote.d.ts +27 -0
- package/dist/commonjs/funcs/earnEarnSwapQuote.d.ts.map +1 -0
- package/dist/commonjs/funcs/earnEarnSwapQuote.js +136 -0
- package/dist/commonjs/funcs/earnEarnSwapQuote.js.map +1 -0
- package/dist/commonjs/hooks/types.d.ts +1 -0
- package/dist/commonjs/hooks/types.d.ts.map +1 -1
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/commonjs/lib/sdks.d.ts.map +1 -1
- package/dist/commonjs/lib/sdks.js +13 -4
- package/dist/commonjs/lib/sdks.js.map +1 -1
- package/dist/commonjs/models/components/chainmarketinfo.d.ts +13 -1
- package/dist/commonjs/models/components/chainmarketinfo.d.ts.map +1 -1
- package/dist/commonjs/models/components/chainmarketinfo.js +2 -0
- package/dist/commonjs/models/components/chainmarketinfo.js.map +1 -1
- package/dist/commonjs/models/components/earnswapquoteresponse.d.ts +24 -0
- package/dist/commonjs/models/components/earnswapquoteresponse.d.ts.map +1 -0
- package/dist/commonjs/models/components/earnswapquoteresponse.js +59 -0
- package/dist/commonjs/models/components/earnswapquoteresponse.js.map +1 -0
- package/dist/commonjs/models/components/index.d.ts +2 -0
- package/dist/commonjs/models/components/index.d.ts.map +1 -1
- package/dist/commonjs/models/components/index.js +2 -0
- package/dist/commonjs/models/components/index.js.map +1 -1
- package/dist/commonjs/models/components/reserveinfo.d.ts +55 -0
- package/dist/commonjs/models/components/reserveinfo.d.ts.map +1 -0
- package/dist/commonjs/models/components/reserveinfo.js +70 -0
- package/dist/commonjs/models/components/reserveinfo.js.map +1 -0
- package/dist/commonjs/models/operations/index.d.ts +1 -0
- package/dist/commonjs/models/operations/index.d.ts.map +1 -1
- package/dist/commonjs/models/operations/index.js +1 -0
- package/dist/commonjs/models/operations/index.js.map +1 -1
- package/dist/commonjs/models/operations/v1uniswapquotesellexactly.d.ts +4 -4
- package/dist/commonjs/models/operations/v1uniswapquotesellexactly.d.ts.map +1 -1
- package/dist/commonjs/models/operations/v1uniswapquotesellexactly.js +5 -5
- package/dist/commonjs/models/operations/v1uniswapquotesellexactly.js.map +1 -1
- package/dist/commonjs/models/operations/v2earnswapquote.d.ts +75 -0
- package/dist/commonjs/models/operations/v2earnswapquote.d.ts.map +1 -0
- package/dist/commonjs/models/operations/v2earnswapquote.js +86 -0
- package/dist/commonjs/models/operations/v2earnswapquote.js.map +1 -0
- package/dist/commonjs/sdk/earn.d.ts +15 -0
- package/dist/commonjs/sdk/earn.d.ts.map +1 -1
- package/dist/commonjs/sdk/earn.js +18 -0
- package/dist/commonjs/sdk/earn.js.map +1 -1
- package/dist/esm/funcs/earnEarnSwapQuote.d.ts +27 -0
- package/dist/esm/funcs/earnEarnSwapQuote.d.ts.map +1 -0
- package/dist/esm/funcs/earnEarnSwapQuote.js +100 -0
- package/dist/esm/funcs/earnEarnSwapQuote.js.map +1 -0
- package/dist/esm/hooks/types.d.ts +1 -0
- package/dist/esm/hooks/types.d.ts.map +1 -1
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/lib/sdks.d.ts.map +1 -1
- package/dist/esm/lib/sdks.js +13 -4
- package/dist/esm/lib/sdks.js.map +1 -1
- package/dist/esm/models/components/chainmarketinfo.d.ts +13 -1
- package/dist/esm/models/components/chainmarketinfo.d.ts.map +1 -1
- package/dist/esm/models/components/chainmarketinfo.js +2 -0
- package/dist/esm/models/components/chainmarketinfo.js.map +1 -1
- package/dist/esm/models/components/earnswapquoteresponse.d.ts +24 -0
- package/dist/esm/models/components/earnswapquoteresponse.d.ts.map +1 -0
- package/dist/esm/models/components/earnswapquoteresponse.js +22 -0
- package/dist/esm/models/components/earnswapquoteresponse.js.map +1 -0
- package/dist/esm/models/components/index.d.ts +2 -0
- package/dist/esm/models/components/index.d.ts.map +1 -1
- package/dist/esm/models/components/index.js +2 -0
- package/dist/esm/models/components/index.js.map +1 -1
- package/dist/esm/models/components/reserveinfo.d.ts +55 -0
- package/dist/esm/models/components/reserveinfo.d.ts.map +1 -0
- package/dist/esm/models/components/reserveinfo.js +33 -0
- package/dist/esm/models/components/reserveinfo.js.map +1 -0
- package/dist/esm/models/operations/index.d.ts +1 -0
- package/dist/esm/models/operations/index.d.ts.map +1 -1
- package/dist/esm/models/operations/index.js +1 -0
- package/dist/esm/models/operations/index.js.map +1 -1
- package/dist/esm/models/operations/v1uniswapquotesellexactly.d.ts +4 -4
- package/dist/esm/models/operations/v1uniswapquotesellexactly.d.ts.map +1 -1
- package/dist/esm/models/operations/v1uniswapquotesellexactly.js +3 -3
- package/dist/esm/models/operations/v1uniswapquotesellexactly.js.map +1 -1
- package/dist/esm/models/operations/v2earnswapquote.d.ts +75 -0
- package/dist/esm/models/operations/v2earnswapquote.d.ts.map +1 -0
- package/dist/esm/models/operations/v2earnswapquote.js +47 -0
- package/dist/esm/models/operations/v2earnswapquote.js.map +1 -0
- package/dist/esm/sdk/earn.d.ts +15 -0
- package/dist/esm/sdk/earn.d.ts.map +1 -1
- package/dist/esm/sdk/earn.js +18 -0
- package/dist/esm/sdk/earn.js.map +1 -1
- package/docs/models/components/chainmarketinfo.md +18 -11
- package/docs/models/components/earnswapquoteresponse.md +23 -0
- package/docs/models/components/listaavemarketsresponse.md +1 -0
- package/docs/models/components/reserveinfo.md +40 -0
- package/docs/models/operations/slippage.md +19 -0
- package/docs/models/operations/{amountin.md → v1uniswapquotesellexactlyamountin.md} +1 -1
- package/docs/models/operations/v1uniswapquotesellexactlyrequest.md +1 -1
- package/docs/models/operations/v2earnswapquoteamountin.md +19 -0
- package/docs/models/operations/v2earnswapquotechain.md +17 -0
- package/docs/models/operations/v2earnswapquoterequest.md +26 -0
- package/docs/sdks/earn/README.md +91 -0
- package/examples/node_modules/@types/node/README.md +1 -1
- package/examples/node_modules/@types/node/http2.d.ts +3 -0
- package/examples/node_modules/@types/node/package.json +2 -2
- package/examples/package-lock.json +3 -3
- package/openapi_prepped_for_speakeasy.json +234 -2
- package/package.json +1 -1
- package/src/funcs/earnEarnSwapQuote.ts +189 -0
- package/src/hooks/types.ts +1 -0
- package/src/lib/config.ts +2 -2
- package/src/lib/sdks.ts +13 -4
- package/src/models/components/chainmarketinfo.ts +14 -1
- package/src/models/components/earnswapquoteresponse.ts +54 -0
- package/src/models/components/index.ts +2 -0
- package/src/models/components/reserveinfo.ts +96 -0
- package/src/models/operations/index.ts +1 -0
- package/src/models/operations/v1uniswapquotesellexactly.ts +13 -7
- package/src/models/operations/v2earnswapquote.ts +135 -0
- package/src/sdk/earn.ts +26 -0
|
@@ -0,0 +1,189 @@
|
|
|
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
|
+
* Quote a swap (read-only)
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Estimate the output of a swap without building a transaction.
|
|
35
|
+
*
|
|
36
|
+
* Returns the expected amount of `token_out` received for selling `amount_in`
|
|
37
|
+
* of `token_in`, routed via 1inch. This is read-only: it does not build a
|
|
38
|
+
* transaction, require an account, or check balances.
|
|
39
|
+
*
|
|
40
|
+
* Use it to gauge exit liquidity and price impact for a token before entering
|
|
41
|
+
* a position — for example, to warn when a market's underlying asset cannot be
|
|
42
|
+
* swapped back to a stablecoin without large slippage.
|
|
43
|
+
*/
|
|
44
|
+
export function earnEarnSwapQuote(
|
|
45
|
+
client: CompassApiSDKCore,
|
|
46
|
+
request: operations.V2EarnSwapQuoteRequest,
|
|
47
|
+
options?: RequestOptions,
|
|
48
|
+
): APIPromise<
|
|
49
|
+
Result<
|
|
50
|
+
components.EarnSwapQuoteResponse,
|
|
51
|
+
| errors.HTTPValidationError
|
|
52
|
+
| CompassAPISDKError
|
|
53
|
+
| ResponseValidationError
|
|
54
|
+
| ConnectionError
|
|
55
|
+
| RequestAbortedError
|
|
56
|
+
| RequestTimeoutError
|
|
57
|
+
| InvalidRequestError
|
|
58
|
+
| UnexpectedClientError
|
|
59
|
+
| SDKValidationError
|
|
60
|
+
>
|
|
61
|
+
> {
|
|
62
|
+
return new APIPromise($do(
|
|
63
|
+
client,
|
|
64
|
+
request,
|
|
65
|
+
options,
|
|
66
|
+
));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function $do(
|
|
70
|
+
client: CompassApiSDKCore,
|
|
71
|
+
request: operations.V2EarnSwapQuoteRequest,
|
|
72
|
+
options?: RequestOptions,
|
|
73
|
+
): Promise<
|
|
74
|
+
[
|
|
75
|
+
Result<
|
|
76
|
+
components.EarnSwapQuoteResponse,
|
|
77
|
+
| errors.HTTPValidationError
|
|
78
|
+
| CompassAPISDKError
|
|
79
|
+
| ResponseValidationError
|
|
80
|
+
| ConnectionError
|
|
81
|
+
| RequestAbortedError
|
|
82
|
+
| RequestTimeoutError
|
|
83
|
+
| InvalidRequestError
|
|
84
|
+
| UnexpectedClientError
|
|
85
|
+
| SDKValidationError
|
|
86
|
+
>,
|
|
87
|
+
APICall,
|
|
88
|
+
]
|
|
89
|
+
> {
|
|
90
|
+
const parsed = safeParse(
|
|
91
|
+
request,
|
|
92
|
+
(value) => operations.V2EarnSwapQuoteRequest$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/earn/swap_quote")();
|
|
102
|
+
|
|
103
|
+
const query = encodeFormQuery({
|
|
104
|
+
"amount_in": payload.amount_in,
|
|
105
|
+
"chain": payload.chain,
|
|
106
|
+
"slippage": payload.slippage,
|
|
107
|
+
"sy_address": payload.sy_address,
|
|
108
|
+
"token_in": payload.token_in,
|
|
109
|
+
"token_out": payload.token_out,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const headers = new Headers(compactMap({
|
|
113
|
+
Accept: "application/json",
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
const secConfig = await extractSecurity(client._options.apiKeyAuth);
|
|
117
|
+
const securityInput = secConfig == null ? {} : { apiKeyAuth: secConfig };
|
|
118
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
119
|
+
|
|
120
|
+
const context = {
|
|
121
|
+
options: client._options,
|
|
122
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
123
|
+
operationID: "v2_earn_swap_quote",
|
|
124
|
+
oAuth2Scopes: null,
|
|
125
|
+
|
|
126
|
+
resolvedSecurity: requestSecurity,
|
|
127
|
+
|
|
128
|
+
securitySource: client._options.apiKeyAuth,
|
|
129
|
+
retryConfig: options?.retries
|
|
130
|
+
|| client._options.retryConfig
|
|
131
|
+
|| { strategy: "none" },
|
|
132
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const requestRes = client._createRequest(context, {
|
|
136
|
+
security: requestSecurity,
|
|
137
|
+
method: "GET",
|
|
138
|
+
baseURL: options?.serverURL,
|
|
139
|
+
path: path,
|
|
140
|
+
headers: headers,
|
|
141
|
+
query: query,
|
|
142
|
+
body: body,
|
|
143
|
+
userAgent: client._options.userAgent,
|
|
144
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
145
|
+
}, options);
|
|
146
|
+
if (!requestRes.ok) {
|
|
147
|
+
return [requestRes, { status: "invalid" }];
|
|
148
|
+
}
|
|
149
|
+
const req = requestRes.value;
|
|
150
|
+
|
|
151
|
+
const doResult = await client._do(req, {
|
|
152
|
+
context,
|
|
153
|
+
isErrorStatusCode: (statusCode: number) =>
|
|
154
|
+
matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
|
|
155
|
+
retryConfig: context.retryConfig,
|
|
156
|
+
retryCodes: context.retryCodes,
|
|
157
|
+
});
|
|
158
|
+
if (!doResult.ok) {
|
|
159
|
+
return [doResult, { status: "request-error", request: req }];
|
|
160
|
+
}
|
|
161
|
+
const response = doResult.value;
|
|
162
|
+
|
|
163
|
+
const responseFields = {
|
|
164
|
+
HttpMeta: { Response: response, Request: req },
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const [result] = await M.match<
|
|
168
|
+
components.EarnSwapQuoteResponse,
|
|
169
|
+
| errors.HTTPValidationError
|
|
170
|
+
| CompassAPISDKError
|
|
171
|
+
| ResponseValidationError
|
|
172
|
+
| ConnectionError
|
|
173
|
+
| RequestAbortedError
|
|
174
|
+
| RequestTimeoutError
|
|
175
|
+
| InvalidRequestError
|
|
176
|
+
| UnexpectedClientError
|
|
177
|
+
| SDKValidationError
|
|
178
|
+
>(
|
|
179
|
+
M.json(200, components.EarnSwapQuoteResponse$inboundSchema),
|
|
180
|
+
M.jsonErr(422, errors.HTTPValidationError$inboundSchema),
|
|
181
|
+
M.fail("4XX"),
|
|
182
|
+
M.fail("5XX"),
|
|
183
|
+
)(response, req, { extraFields: responseFields });
|
|
184
|
+
if (!result.ok) {
|
|
185
|
+
return [result, { status: "complete", request: req, response }];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return [result, { status: "complete", request: req, response }];
|
|
189
|
+
}
|
package/src/hooks/types.ts
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -62,7 +62,7 @@ export const SDK_METADATA = {
|
|
|
62
62
|
language: "typescript",
|
|
63
63
|
openapiDocVersion: "0.0.1",
|
|
64
64
|
sdkVersion: "2.0.0",
|
|
65
|
-
genVersion: "2.
|
|
65
|
+
genVersion: "2.897.1",
|
|
66
66
|
userAgent:
|
|
67
|
-
"speakeasy-sdk/typescript 2.0.0 2.
|
|
67
|
+
"speakeasy-sdk/typescript 2.0.0 2.897.1 0.0.1 @compass-labs/api-sdk",
|
|
68
68
|
} as const;
|
package/src/lib/sdks.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
matchContentType,
|
|
24
24
|
} from "./http.js";
|
|
25
25
|
import { Logger } from "./logger.js";
|
|
26
|
+
import { combineSignals } from "./primitives.js";
|
|
26
27
|
import { retry, RetryConfig } from "./retries.js";
|
|
27
28
|
import { SecurityState } from "./security.js";
|
|
28
29
|
|
|
@@ -194,9 +195,8 @@ export class ClientSDK {
|
|
|
194
195
|
...options?.fetchOptions,
|
|
195
196
|
...options,
|
|
196
197
|
};
|
|
197
|
-
if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
|
|
198
|
-
|
|
199
|
-
fetchOptions.signal = timeoutSignal;
|
|
198
|
+
if (!fetchOptions?.signal && conf.timeoutMs != null && conf.timeoutMs > 0) {
|
|
199
|
+
context.timeoutMs = conf.timeoutMs;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
if (conf.body instanceof ReadableStream) {
|
|
@@ -243,10 +243,19 @@ export class ClientSDK {
|
|
|
243
243
|
>
|
|
244
244
|
> {
|
|
245
245
|
const { context, isErrorStatusCode } = options;
|
|
246
|
+
const timeoutMs = context.timeoutMs;
|
|
246
247
|
|
|
247
248
|
return retry(
|
|
248
249
|
async () => {
|
|
249
|
-
const
|
|
250
|
+
const cloned = request.clone();
|
|
251
|
+
let attempt = cloned;
|
|
252
|
+
if (timeoutMs != null && timeoutMs > 0) {
|
|
253
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
254
|
+
const combined = combineSignals(cloned.signal, timeoutSignal)
|
|
255
|
+
?? timeoutSignal;
|
|
256
|
+
attempt = new Request(cloned, { signal: combined });
|
|
257
|
+
}
|
|
258
|
+
const req = await this.#hooks.beforeRequest(context, attempt);
|
|
250
259
|
await logRequest(this.#logger, req).catch((e) =>
|
|
251
260
|
this.#logger?.log("Failed to log request:", e)
|
|
252
261
|
);
|
|
@@ -7,13 +7,21 @@ import { remap as remap$ } from "../../lib/primitives.js";
|
|
|
7
7
|
import { safeParse } from "../../lib/schemas.js";
|
|
8
8
|
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
9
9
|
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
10
|
+
import { ReserveInfo, ReserveInfo$inboundSchema } from "./reserveinfo.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Rate information for a token on a specific chain.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
*
|
|
17
|
+
* The top-level fields describe the canonical (highest-liquidity) reserve for this
|
|
18
|
+
* token on this chain, preserving the original single-reserve shape. `reserves`
|
|
19
|
+
* lists every reserve for the token on this chain so clients can disambiguate
|
|
20
|
+
* cases like native USDC vs bridged USDC.e on Arbitrum.
|
|
13
21
|
*/
|
|
14
22
|
export type ChainMarketInfo = {
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
24
|
+
* Underlying token (reserve) contract address on this chain. This is Aave's canonical per-reserve identifier.
|
|
17
25
|
*/
|
|
18
26
|
address: string;
|
|
19
27
|
/**
|
|
@@ -48,6 +56,10 @@ export type ChainMarketInfo = {
|
|
|
48
56
|
* Percentage of supplied tokens that are currently borrowed (e.g., 85.0 means 85%).
|
|
49
57
|
*/
|
|
50
58
|
utilizationRate: string;
|
|
59
|
+
/**
|
|
60
|
+
* Every Aave reserve for this token on this chain, ordered by liquidity (highest first). Identified by underlying `address`. For most tokens this has a single entry equal to the canonical reserve above; where a chain has multiple reserves for one symbol (e.g. Arbitrum native USDC and bridged USDC.e), all are listed with their individual rates.
|
|
61
|
+
*/
|
|
62
|
+
reserves?: Array<ReserveInfo> | undefined;
|
|
51
63
|
};
|
|
52
64
|
|
|
53
65
|
/** @internal */
|
|
@@ -65,6 +77,7 @@ export const ChainMarketInfo$inboundSchema: z.ZodType<
|
|
|
65
77
|
total_borrowed: z.string(),
|
|
66
78
|
available_liquidity: z.string(),
|
|
67
79
|
utilization_rate: z.string(),
|
|
80
|
+
reserves: z.array(ReserveInfo$inboundSchema).optional(),
|
|
68
81
|
}).transform((v) => {
|
|
69
82
|
return remap$(v, {
|
|
70
83
|
"a_token_address": "aTokenAddress",
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
* Estimated output of a read-only swap quote.
|
|
13
|
+
*/
|
|
14
|
+
export type EarnSwapQuoteResponse = {
|
|
15
|
+
/**
|
|
16
|
+
* Estimated amount of `token_out` received, in human-readable units. Zero when no route / insufficient liquidity exists for the pair.
|
|
17
|
+
*/
|
|
18
|
+
amountOut: string;
|
|
19
|
+
/**
|
|
20
|
+
* The token address actually quoted as input. Usually the requested `token_in`; for Pendle (when `sy_address` is supplied) it is the resolved redeem token, which callers should use to value the input.
|
|
21
|
+
*/
|
|
22
|
+
tokenIn: string;
|
|
23
|
+
/**
|
|
24
|
+
* The token address quoted as output — what `amount_out` is denominated in (the resolved `token_out` from the request).
|
|
25
|
+
*/
|
|
26
|
+
tokenOut: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const EarnSwapQuoteResponse$inboundSchema: z.ZodType<
|
|
31
|
+
EarnSwapQuoteResponse,
|
|
32
|
+
z.ZodTypeDef,
|
|
33
|
+
unknown
|
|
34
|
+
> = z.object({
|
|
35
|
+
amount_out: z.string(),
|
|
36
|
+
token_in: z.string(),
|
|
37
|
+
token_out: z.string(),
|
|
38
|
+
}).transform((v) => {
|
|
39
|
+
return remap$(v, {
|
|
40
|
+
"amount_out": "amountOut",
|
|
41
|
+
"token_in": "tokenIn",
|
|
42
|
+
"token_out": "tokenOut",
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export function earnSwapQuoteResponseFromJSON(
|
|
47
|
+
jsonString: string,
|
|
48
|
+
): SafeParseResult<EarnSwapQuoteResponse, SDKValidationError> {
|
|
49
|
+
return safeParse(
|
|
50
|
+
jsonString,
|
|
51
|
+
(x) => EarnSwapQuoteResponse$inboundSchema.parse(JSON.parse(x)),
|
|
52
|
+
`Failed to parse 'EarnSwapQuoteResponse' from JSON`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -124,6 +124,7 @@ export * from "./earnmanageresponse.js";
|
|
|
124
124
|
export * from "./earnpositionsallresponse.js";
|
|
125
125
|
export * from "./earnpositionsresponse.js";
|
|
126
126
|
export * from "./earnswapparams.js";
|
|
127
|
+
export * from "./earnswapquoteresponse.js";
|
|
127
128
|
export * from "./earnswaprequest.js";
|
|
128
129
|
export * from "./earnswapresponse.js";
|
|
129
130
|
export * from "./earntransferfromeoaparams.js";
|
|
@@ -251,6 +252,7 @@ export * from "./quote.js";
|
|
|
251
252
|
export * from "./quotefee.js";
|
|
252
253
|
export * from "./repay.js";
|
|
253
254
|
export * from "./reserve.js";
|
|
255
|
+
export * from "./reserveinfo.js";
|
|
254
256
|
export * from "./safemessageeip712response.js";
|
|
255
257
|
export * from "./safemessageeip712types.js";
|
|
256
258
|
export * from "./safemessagefield.js";
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
* Rate and liquidity information for a single Aave reserve on a chain.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
*
|
|
16
|
+
* A reserve is identified by its underlying token `address` — Aave's canonical
|
|
17
|
+
* reserve identifier. The same token symbol can map to more than one reserve on a
|
|
18
|
+
* chain (e.g. native USDC and bridged USDC.e on Arbitrum), each with its own rates
|
|
19
|
+
* and liquidity.
|
|
20
|
+
*/
|
|
21
|
+
export type ReserveInfo = {
|
|
22
|
+
/**
|
|
23
|
+
* Underlying token (reserve) contract address on this chain. This is Aave's canonical per-reserve identifier.
|
|
24
|
+
*/
|
|
25
|
+
address: string;
|
|
26
|
+
/**
|
|
27
|
+
* Aave aToken contract address on this chain. This is the interest-bearing token that represents the supply position.
|
|
28
|
+
*/
|
|
29
|
+
aTokenAddress: string;
|
|
30
|
+
/**
|
|
31
|
+
* Variable rate APY for deposits, in percentage (e.g., 4.5 means 4.5%).
|
|
32
|
+
*/
|
|
33
|
+
supplyApy: string;
|
|
34
|
+
/**
|
|
35
|
+
* Variable rate APY for loans, in percentage (e.g., 6.2 means 6.2%).
|
|
36
|
+
*/
|
|
37
|
+
borrowApy: string;
|
|
38
|
+
/**
|
|
39
|
+
* Variable rate APY for deposits averaged over the `days` window in the request (default 30 days), in percentage. Computed the same way as the v1 `/v1/aave/avg_rate` endpoint.
|
|
40
|
+
*/
|
|
41
|
+
supplyApyAvg: string;
|
|
42
|
+
/**
|
|
43
|
+
* Variable rate APY for loans averaged over the `days` window in the request (default 30 days), in percentage. Computed the same way as the v1 `/v1/aave/avg_rate` endpoint.
|
|
44
|
+
*/
|
|
45
|
+
borrowApyAvg: string;
|
|
46
|
+
/**
|
|
47
|
+
* Total amount currently borrowed from this market, in token units (e.g., 1234567.89 USDC).
|
|
48
|
+
*/
|
|
49
|
+
totalBorrowed: string;
|
|
50
|
+
/**
|
|
51
|
+
* Amount of tokens available to borrow, in token units. Equals total supplied minus total borrowed.
|
|
52
|
+
*/
|
|
53
|
+
availableLiquidity: string;
|
|
54
|
+
/**
|
|
55
|
+
* Percentage of supplied tokens that are currently borrowed (e.g., 85.0 means 85%).
|
|
56
|
+
*/
|
|
57
|
+
utilizationRate: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** @internal */
|
|
61
|
+
export const ReserveInfo$inboundSchema: z.ZodType<
|
|
62
|
+
ReserveInfo,
|
|
63
|
+
z.ZodTypeDef,
|
|
64
|
+
unknown
|
|
65
|
+
> = z.object({
|
|
66
|
+
address: z.string(),
|
|
67
|
+
a_token_address: z.string(),
|
|
68
|
+
supply_apy: z.string(),
|
|
69
|
+
borrow_apy: z.string(),
|
|
70
|
+
supply_apy_avg: z.string(),
|
|
71
|
+
borrow_apy_avg: z.string(),
|
|
72
|
+
total_borrowed: z.string(),
|
|
73
|
+
available_liquidity: z.string(),
|
|
74
|
+
utilization_rate: z.string(),
|
|
75
|
+
}).transform((v) => {
|
|
76
|
+
return remap$(v, {
|
|
77
|
+
"a_token_address": "aTokenAddress",
|
|
78
|
+
"supply_apy": "supplyApy",
|
|
79
|
+
"borrow_apy": "borrowApy",
|
|
80
|
+
"supply_apy_avg": "supplyApyAvg",
|
|
81
|
+
"borrow_apy_avg": "borrowApyAvg",
|
|
82
|
+
"total_borrowed": "totalBorrowed",
|
|
83
|
+
"available_liquidity": "availableLiquidity",
|
|
84
|
+
"utilization_rate": "utilizationRate",
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export function reserveInfoFromJSON(
|
|
89
|
+
jsonString: string,
|
|
90
|
+
): SafeParseResult<ReserveInfo, SDKValidationError> {
|
|
91
|
+
return safeParse(
|
|
92
|
+
jsonString,
|
|
93
|
+
(x) => ReserveInfo$inboundSchema.parse(JSON.parse(x)),
|
|
94
|
+
`Failed to parse 'ReserveInfo' from JSON`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -48,6 +48,7 @@ export * from "./v2earnbalances.js";
|
|
|
48
48
|
export * from "./v2earnpendlemarkets.js";
|
|
49
49
|
export * from "./v2earnpositions.js";
|
|
50
50
|
export * from "./v2earnpositionsall.js";
|
|
51
|
+
export * from "./v2earnswapquote.js";
|
|
51
52
|
export * from "./v2earnvaults.js";
|
|
52
53
|
export * from "./v2globalmarketsperpsactivity.js";
|
|
53
54
|
export * from "./v2globalmarketsperpscandles.js";
|
|
@@ -42,7 +42,7 @@ export type V1UniswapQuoteSellExactlyFeeEnum = ClosedEnum<
|
|
|
42
42
|
/**
|
|
43
43
|
* The amount of the token to swap from
|
|
44
44
|
*/
|
|
45
|
-
export type
|
|
45
|
+
export type V1UniswapQuoteSellExactlyAmountIn = number | string;
|
|
46
46
|
|
|
47
47
|
export type V1UniswapQuoteSellExactlyRequest = {
|
|
48
48
|
chain: V1UniswapQuoteSellExactlyChain;
|
|
@@ -75,17 +75,23 @@ export const V1UniswapQuoteSellExactlyFeeEnum$outboundSchema: z.ZodNativeEnum<
|
|
|
75
75
|
> = z.nativeEnum(V1UniswapQuoteSellExactlyFeeEnum);
|
|
76
76
|
|
|
77
77
|
/** @internal */
|
|
78
|
-
export type
|
|
78
|
+
export type V1UniswapQuoteSellExactlyAmountIn$Outbound = number | string;
|
|
79
79
|
|
|
80
80
|
/** @internal */
|
|
81
|
-
export const
|
|
82
|
-
|
|
81
|
+
export const V1UniswapQuoteSellExactlyAmountIn$outboundSchema: z.ZodType<
|
|
82
|
+
V1UniswapQuoteSellExactlyAmountIn$Outbound,
|
|
83
83
|
z.ZodTypeDef,
|
|
84
|
-
|
|
84
|
+
V1UniswapQuoteSellExactlyAmountIn
|
|
85
85
|
> = z.union([z.number(), z.string()]);
|
|
86
86
|
|
|
87
|
-
export function
|
|
88
|
-
|
|
87
|
+
export function v1UniswapQuoteSellExactlyAmountInToJSON(
|
|
88
|
+
v1UniswapQuoteSellExactlyAmountIn: V1UniswapQuoteSellExactlyAmountIn,
|
|
89
|
+
): string {
|
|
90
|
+
return JSON.stringify(
|
|
91
|
+
V1UniswapQuoteSellExactlyAmountIn$outboundSchema.parse(
|
|
92
|
+
v1UniswapQuoteSellExactlyAmountIn,
|
|
93
|
+
),
|
|
94
|
+
);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
/** @internal */
|
|
@@ -0,0 +1,135 @@
|
|
|
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 { ClosedEnum } from "../../types/enums.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The chain to use.
|
|
11
|
+
*/
|
|
12
|
+
export const V2EarnSwapQuoteChain = {
|
|
13
|
+
Base: "base",
|
|
14
|
+
Ethereum: "ethereum",
|
|
15
|
+
Arbitrum: "arbitrum",
|
|
16
|
+
Hyperevm: "hyperevm",
|
|
17
|
+
Tempo: "tempo",
|
|
18
|
+
} as const;
|
|
19
|
+
/**
|
|
20
|
+
* The chain to use.
|
|
21
|
+
*/
|
|
22
|
+
export type V2EarnSwapQuoteChain = ClosedEnum<typeof V2EarnSwapQuoteChain>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Human-readable amount of `token_in` to quote (token units, not wei).
|
|
26
|
+
*/
|
|
27
|
+
export type V2EarnSwapQuoteAmountIn = number | string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Maximum slippage tolerance as a percentage (e.g., 1 = 1%).
|
|
31
|
+
*/
|
|
32
|
+
export type Slippage = number | string;
|
|
33
|
+
|
|
34
|
+
export type V2EarnSwapQuoteRequest = {
|
|
35
|
+
/**
|
|
36
|
+
* Target blockchain network.
|
|
37
|
+
*/
|
|
38
|
+
chain: V2EarnSwapQuoteChain;
|
|
39
|
+
/**
|
|
40
|
+
* Token to sell (input). A token symbol (e.g. 'WETH') or any token address.
|
|
41
|
+
*/
|
|
42
|
+
tokenIn: string;
|
|
43
|
+
/**
|
|
44
|
+
* Token to buy (output). A token symbol (e.g. 'USDC') or any token address.
|
|
45
|
+
*/
|
|
46
|
+
tokenOut?: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Optional Pendle SY (Standardized Yield) address. When provided, `token_in` is overridden with the token the PT actually redeems into on withdrawal (the SY asset if it is a valid token-out, else the SY yield token) — use this to gauge a Pendle position's real exit liquidity rather than the reported underlying.
|
|
49
|
+
*/
|
|
50
|
+
syAddress?: string | null | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Human-readable amount of `token_in` to quote (token units, not wei).
|
|
53
|
+
*/
|
|
54
|
+
amountIn: number | string;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum slippage tolerance as a percentage (e.g., 1 = 1%).
|
|
57
|
+
*/
|
|
58
|
+
slippage?: number | string | undefined;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** @internal */
|
|
62
|
+
export const V2EarnSwapQuoteChain$outboundSchema: z.ZodNativeEnum<
|
|
63
|
+
typeof V2EarnSwapQuoteChain
|
|
64
|
+
> = z.nativeEnum(V2EarnSwapQuoteChain);
|
|
65
|
+
|
|
66
|
+
/** @internal */
|
|
67
|
+
export type V2EarnSwapQuoteAmountIn$Outbound = number | string;
|
|
68
|
+
|
|
69
|
+
/** @internal */
|
|
70
|
+
export const V2EarnSwapQuoteAmountIn$outboundSchema: z.ZodType<
|
|
71
|
+
V2EarnSwapQuoteAmountIn$Outbound,
|
|
72
|
+
z.ZodTypeDef,
|
|
73
|
+
V2EarnSwapQuoteAmountIn
|
|
74
|
+
> = z.union([z.number(), z.string()]);
|
|
75
|
+
|
|
76
|
+
export function v2EarnSwapQuoteAmountInToJSON(
|
|
77
|
+
v2EarnSwapQuoteAmountIn: V2EarnSwapQuoteAmountIn,
|
|
78
|
+
): string {
|
|
79
|
+
return JSON.stringify(
|
|
80
|
+
V2EarnSwapQuoteAmountIn$outboundSchema.parse(v2EarnSwapQuoteAmountIn),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @internal */
|
|
85
|
+
export type Slippage$Outbound = number | string;
|
|
86
|
+
|
|
87
|
+
/** @internal */
|
|
88
|
+
export const Slippage$outboundSchema: z.ZodType<
|
|
89
|
+
Slippage$Outbound,
|
|
90
|
+
z.ZodTypeDef,
|
|
91
|
+
Slippage
|
|
92
|
+
> = z.union([z.number(), z.string()]);
|
|
93
|
+
|
|
94
|
+
export function slippageToJSON(slippage: Slippage): string {
|
|
95
|
+
return JSON.stringify(Slippage$outboundSchema.parse(slippage));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @internal */
|
|
99
|
+
export type V2EarnSwapQuoteRequest$Outbound = {
|
|
100
|
+
chain: string;
|
|
101
|
+
token_in: string;
|
|
102
|
+
token_out?: string | undefined;
|
|
103
|
+
sy_address?: string | null | undefined;
|
|
104
|
+
amount_in: number | string;
|
|
105
|
+
slippage?: number | string | undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** @internal */
|
|
109
|
+
export const V2EarnSwapQuoteRequest$outboundSchema: z.ZodType<
|
|
110
|
+
V2EarnSwapQuoteRequest$Outbound,
|
|
111
|
+
z.ZodTypeDef,
|
|
112
|
+
V2EarnSwapQuoteRequest
|
|
113
|
+
> = z.object({
|
|
114
|
+
chain: V2EarnSwapQuoteChain$outboundSchema,
|
|
115
|
+
tokenIn: z.string(),
|
|
116
|
+
tokenOut: z.string().optional(),
|
|
117
|
+
syAddress: z.nullable(z.string()).optional(),
|
|
118
|
+
amountIn: z.union([z.number(), z.string()]),
|
|
119
|
+
slippage: z.union([z.number(), z.string()]).optional(),
|
|
120
|
+
}).transform((v) => {
|
|
121
|
+
return remap$(v, {
|
|
122
|
+
tokenIn: "token_in",
|
|
123
|
+
tokenOut: "token_out",
|
|
124
|
+
syAddress: "sy_address",
|
|
125
|
+
amountIn: "amount_in",
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export function v2EarnSwapQuoteRequestToJSON(
|
|
130
|
+
v2EarnSwapQuoteRequest: V2EarnSwapQuoteRequest,
|
|
131
|
+
): string {
|
|
132
|
+
return JSON.stringify(
|
|
133
|
+
V2EarnSwapQuoteRequest$outboundSchema.parse(v2EarnSwapQuoteRequest),
|
|
134
|
+
);
|
|
135
|
+
}
|
package/src/sdk/earn.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { earnEarnPendleMarkets } from "../funcs/earnEarnPendleMarkets.js";
|
|
|
11
11
|
import { earnEarnPositions } from "../funcs/earnEarnPositions.js";
|
|
12
12
|
import { earnEarnPositionsAll } from "../funcs/earnEarnPositionsAll.js";
|
|
13
13
|
import { earnEarnSwap } from "../funcs/earnEarnSwap.js";
|
|
14
|
+
import { earnEarnSwapQuote } from "../funcs/earnEarnSwapQuote.js";
|
|
14
15
|
import { earnEarnTransfer } from "../funcs/earnEarnTransfer.js";
|
|
15
16
|
import { earnEarnVaults } from "../funcs/earnEarnVaults.js";
|
|
16
17
|
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
|
|
@@ -139,6 +140,31 @@ export class Earn extends ClientSDK {
|
|
|
139
140
|
));
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Quote a swap (read-only)
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* Estimate the output of a swap without building a transaction.
|
|
148
|
+
*
|
|
149
|
+
* Returns the expected amount of `token_out` received for selling `amount_in`
|
|
150
|
+
* of `token_in`, routed via 1inch. This is read-only: it does not build a
|
|
151
|
+
* transaction, require an account, or check balances.
|
|
152
|
+
*
|
|
153
|
+
* Use it to gauge exit liquidity and price impact for a token before entering
|
|
154
|
+
* a position — for example, to warn when a market's underlying asset cannot be
|
|
155
|
+
* swapped back to a stablecoin without large slippage.
|
|
156
|
+
*/
|
|
157
|
+
async earnSwapQuote(
|
|
158
|
+
request: operations.V2EarnSwapQuoteRequest,
|
|
159
|
+
options?: RequestOptions,
|
|
160
|
+
): Promise<components.EarnSwapQuoteResponse> {
|
|
161
|
+
return unwrapAsync(earnEarnSwapQuote(
|
|
162
|
+
this,
|
|
163
|
+
request,
|
|
164
|
+
options,
|
|
165
|
+
));
|
|
166
|
+
}
|
|
167
|
+
|
|
142
168
|
/**
|
|
143
169
|
* Get token balances
|
|
144
170
|
*
|