@zerodev/smart-recipes 0.2.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 +17 -0
- package/dist/index.cjs +300 -0
- package/dist/index.d.cts +625 -0
- package/dist/index.d.ts +625 -0
- package/dist/index.js +274 -0
- package/package.json +38 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { Address, Hex } from 'viem';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vault discovery query types. The data source is vaults.fyi (server-side); the SDK speaks in
|
|
5
|
+
* `Vault` (see `contract.ts`). `listOpportunities` is a thin alias of `listVaults` kept for
|
|
6
|
+
* back-compat — both return `Vault[]`.
|
|
7
|
+
*/
|
|
8
|
+
type ChainId = number;
|
|
9
|
+
/**
|
|
10
|
+
* Vault category discriminator. vaults.fyi serves yield/lending vaults today (mapped to `lend`);
|
|
11
|
+
* `liquid-staking` / `fixed-yield` remain in the union so future upstream categories slot in.
|
|
12
|
+
*/
|
|
13
|
+
type VaultCategory = 'lend' | 'liquid-staking' | 'fixed-yield';
|
|
14
|
+
/** Discovery filter for `listOpportunities` / `listVaults`. All fields optional. */
|
|
15
|
+
interface OpportunitiesQuery {
|
|
16
|
+
category?: VaultCategory;
|
|
17
|
+
chainId?: ChainId;
|
|
18
|
+
/** Minimum TVL in USD. */
|
|
19
|
+
minTvl?: number;
|
|
20
|
+
/** Minimum APY (percentage, e.g. `5` for 5%). */
|
|
21
|
+
minApy?: number;
|
|
22
|
+
}
|
|
23
|
+
interface ListOpportunitiesArgs extends OpportunitiesQuery {
|
|
24
|
+
/** Filter to a single protocol (e.g. `aave`, `fluid`). */
|
|
25
|
+
protocol?: string;
|
|
26
|
+
}
|
|
27
|
+
/** SDK-facing alias of {@link ListOpportunitiesArgs}. */
|
|
28
|
+
type ListOpportunitiesParams = ListOpportunitiesArgs;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The full HTTP wire contract between the Smart Recipes server and the SDK.
|
|
32
|
+
*
|
|
33
|
+
* Every amount is a base-10 `string` (uint256 serialized) — JSON has no bigint, so the wire is
|
|
34
|
+
* the single source of truth and the SDK returns it verbatim. Callers parse to `bigint` themselves.
|
|
35
|
+
*/
|
|
36
|
+
/** A single on-chain call. `value` is a decimal `string` (bigint-safe over the wire). */
|
|
37
|
+
interface OnChainCall {
|
|
38
|
+
to: Address;
|
|
39
|
+
data: Hex;
|
|
40
|
+
value: string;
|
|
41
|
+
}
|
|
42
|
+
/** Legacy alias of {@link OnChainCall}; kept for server importers mid-rebuild. */
|
|
43
|
+
type OnChainCallWire = OnChainCall;
|
|
44
|
+
/**
|
|
45
|
+
* ERC-4337 intent, callData-only. The server encodes a Kernel v3 / ERC-7579
|
|
46
|
+
* `executeBatch(calls)` into `callData`; the consumer's kernel client fills
|
|
47
|
+
* sender / nonce / gas / signature. No bundler dependency server-side.
|
|
48
|
+
*/
|
|
49
|
+
interface UserOpIntent {
|
|
50
|
+
callData: Hex;
|
|
51
|
+
calls: OnChainCall[];
|
|
52
|
+
chainId: number;
|
|
53
|
+
}
|
|
54
|
+
/** Src-chain transaction intent: a batch of calls on one chain. */
|
|
55
|
+
interface QuoteTransaction {
|
|
56
|
+
chainId: number;
|
|
57
|
+
calls: OnChainCall[];
|
|
58
|
+
}
|
|
59
|
+
interface QuoteFeeBreakdown {
|
|
60
|
+
totalFeeUsd: string;
|
|
61
|
+
perChain: {
|
|
62
|
+
chainId: number;
|
|
63
|
+
feeUsd: string;
|
|
64
|
+
}[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolved deposit flow for a quote. The four cross-chain quadrants derive from
|
|
68
|
+
* `requiresSrcSwap` × `requiresDestSwap`; same-chain quotes set `sameChain: true`
|
|
69
|
+
* (no bridge, `bridgeTokenType: null`). Lets the UI surface which flow a deposit takes.
|
|
70
|
+
*/
|
|
71
|
+
interface QuoteRoute {
|
|
72
|
+
/** SRA bridge token type; `null` for same-chain (no bridge). */
|
|
73
|
+
bridgeTokenType: string | null;
|
|
74
|
+
/** Bridge token address on the src chain (cross-chain only). */
|
|
75
|
+
bridgeTokenSrc?: Address;
|
|
76
|
+
/** Bridge token address on the dest chain (cross-chain only). */
|
|
77
|
+
bridgeTokenDest?: Address;
|
|
78
|
+
/** Funding token swapped to the bridge token on the src chain. */
|
|
79
|
+
requiresSrcSwap: boolean;
|
|
80
|
+
/** Bridged token swapped to the vault asset on the dest chain. */
|
|
81
|
+
requiresDestSwap: boolean;
|
|
82
|
+
/** True when src == dest chain (no bridge step). */
|
|
83
|
+
sameChain: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* True when a same-chain deposit swaps the funding token into the vault asset before
|
|
86
|
+
* depositing (no bridge; plain owner-signed swap + deposit). `sameChain` is also true.
|
|
87
|
+
*/
|
|
88
|
+
sameChainSwap?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** Unified return type for all recipes. Same-chain quotes have `sra: null`. */
|
|
91
|
+
interface Quote {
|
|
92
|
+
quoteId: string;
|
|
93
|
+
expiresAt: string;
|
|
94
|
+
sra: Address | null;
|
|
95
|
+
transaction: QuoteTransaction;
|
|
96
|
+
userOp: UserOpIntent;
|
|
97
|
+
srcTransactions?: QuoteTransaction[];
|
|
98
|
+
estimatedFees: QuoteFeeBreakdown;
|
|
99
|
+
estimatedReceiveAmount: string;
|
|
100
|
+
estimatedShares?: string;
|
|
101
|
+
vaultApy?: number;
|
|
102
|
+
swapMinOutput?: string;
|
|
103
|
+
/** Resolved deposit flow (bridge token + src/dest swap flags). */
|
|
104
|
+
route?: QuoteRoute;
|
|
105
|
+
recipeVersion: number;
|
|
106
|
+
/** Server diagnostics — present only in debug builds. */
|
|
107
|
+
debug?: QuoteDebug;
|
|
108
|
+
}
|
|
109
|
+
/** Body for `POST /recipes/deposit-into-vault` and `/recipes/bridge-and-deposit`. */
|
|
110
|
+
interface DepositRecipeRequest {
|
|
111
|
+
owner: Address;
|
|
112
|
+
amount: number | string;
|
|
113
|
+
/** Funding token: symbol (e.g. `USDC`) or raw address. */
|
|
114
|
+
token: string;
|
|
115
|
+
srcChainId: number;
|
|
116
|
+
destChainId: number;
|
|
117
|
+
/** Multi-vault facades: vault id (from `listVaults`) or raw ERC-4626 address. */
|
|
118
|
+
into?: string;
|
|
119
|
+
/** bps; default 100. */
|
|
120
|
+
slippage?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Required protocol selector — picks the adapter that builds the deposit calldata
|
|
123
|
+
* (`aave` | `morpho` | `fluid` | `yearn` | `erc4626`). Unknown → UNKNOWN_PROTOCOL.
|
|
124
|
+
*/
|
|
125
|
+
protocol: string;
|
|
126
|
+
}
|
|
127
|
+
/** Body for `POST /recipes/bridge-and-swap`. */
|
|
128
|
+
interface BridgeAndSwapRequest {
|
|
129
|
+
owner: Address;
|
|
130
|
+
amount: number | string;
|
|
131
|
+
token: string;
|
|
132
|
+
/** Destination token to swap into. */
|
|
133
|
+
toToken: string;
|
|
134
|
+
srcChainId: number;
|
|
135
|
+
destChainId: number;
|
|
136
|
+
slippage?: number;
|
|
137
|
+
}
|
|
138
|
+
interface DepositIntoVaultRequest {
|
|
139
|
+
owner: Address;
|
|
140
|
+
destChainId: number;
|
|
141
|
+
amount: string;
|
|
142
|
+
vaultId: string;
|
|
143
|
+
category?: VaultCategory;
|
|
144
|
+
slippageBps?: number;
|
|
145
|
+
}
|
|
146
|
+
interface DepositIntoVaultResponse {
|
|
147
|
+
quoteId: `0x${string}`;
|
|
148
|
+
sra: null;
|
|
149
|
+
transaction: {
|
|
150
|
+
chainId: number;
|
|
151
|
+
calls: OnChainCallWire[];
|
|
152
|
+
};
|
|
153
|
+
estimatedReceiveAmount: string | null;
|
|
154
|
+
estimatedGas: string;
|
|
155
|
+
canExecute: boolean;
|
|
156
|
+
expiresAt: string;
|
|
157
|
+
}
|
|
158
|
+
interface BridgeDepositRequest {
|
|
159
|
+
owner: Address;
|
|
160
|
+
srcChainId: number;
|
|
161
|
+
destChainId: number;
|
|
162
|
+
srcToken: Address;
|
|
163
|
+
amount: string;
|
|
164
|
+
vaultId: Address;
|
|
165
|
+
slippageBps?: number;
|
|
166
|
+
}
|
|
167
|
+
interface RouteInfoWire {
|
|
168
|
+
bridgeTokenType: string;
|
|
169
|
+
requiresSrcSwap: boolean;
|
|
170
|
+
requiresDestSwap: boolean;
|
|
171
|
+
}
|
|
172
|
+
interface BridgeDepositResponse {
|
|
173
|
+
quoteId: `0x${string}`;
|
|
174
|
+
route: RouteInfoWire;
|
|
175
|
+
sra: Address;
|
|
176
|
+
transaction: {
|
|
177
|
+
chainId: number;
|
|
178
|
+
calls: OnChainCallWire[];
|
|
179
|
+
};
|
|
180
|
+
srcTransactions: {
|
|
181
|
+
chainId: number;
|
|
182
|
+
calls: OnChainCallWire[];
|
|
183
|
+
}[] | null;
|
|
184
|
+
estimatedReceiveAmount: string;
|
|
185
|
+
estimatedFees: unknown;
|
|
186
|
+
canExecute: boolean;
|
|
187
|
+
expiresAt: string;
|
|
188
|
+
swapMinOutput: string | null;
|
|
189
|
+
debug?: QuoteDebug;
|
|
190
|
+
}
|
|
191
|
+
/** Full decoded call map for a bridge-deposit quote — src tx + dest SRA action + fallback. */
|
|
192
|
+
interface QuoteDebug {
|
|
193
|
+
route: {
|
|
194
|
+
bridgeTokenType: string;
|
|
195
|
+
bridgeTokenSrc: Address;
|
|
196
|
+
bridgeTokenDest: Address;
|
|
197
|
+
requiresSrcSwap: boolean;
|
|
198
|
+
requiresDestSwap: boolean;
|
|
199
|
+
};
|
|
200
|
+
amounts: {
|
|
201
|
+
input: string;
|
|
202
|
+
bridgeInput: string;
|
|
203
|
+
minAmountOut: string;
|
|
204
|
+
swapMinOutput: string | null;
|
|
205
|
+
estimatedReceive: string;
|
|
206
|
+
};
|
|
207
|
+
/** Calls signed by the owner on the src chain (approve? + swap? + transfer-to-SRA). */
|
|
208
|
+
srcCalls: DebugCall[];
|
|
209
|
+
/** What the SRA runs on the dest chain once bridged funds land. */
|
|
210
|
+
destAction: {
|
|
211
|
+
/** 2-call batch: [transfer(FLEX) -> executor], [executor.executeComposable(steps)]. */
|
|
212
|
+
calls: DebugCall[];
|
|
213
|
+
/** Decoded composable recipe steps run inside the SmartRecipeExecutor. */
|
|
214
|
+
steps: DebugStep[];
|
|
215
|
+
};
|
|
216
|
+
/** Refund path if the dest action reverts: transfer(FLEX) -> owner. */
|
|
217
|
+
fallBack: DebugCall[];
|
|
218
|
+
}
|
|
219
|
+
interface DebugCall {
|
|
220
|
+
to: Address | string;
|
|
221
|
+
selector: string;
|
|
222
|
+
fn: string;
|
|
223
|
+
value: string;
|
|
224
|
+
dataBytes: number;
|
|
225
|
+
note?: string;
|
|
226
|
+
}
|
|
227
|
+
interface DebugStep {
|
|
228
|
+
index: number;
|
|
229
|
+
fn: string;
|
|
230
|
+
selector: string;
|
|
231
|
+
inputs: string[];
|
|
232
|
+
}
|
|
233
|
+
/** Alias of {@link DepositIntoVaultResponse}. */
|
|
234
|
+
type DepositIntoVaultQuote = DepositIntoVaultResponse;
|
|
235
|
+
/** Alias of {@link BridgeDepositResponse}. */
|
|
236
|
+
type BridgeDepositQuote = BridgeDepositResponse;
|
|
237
|
+
interface PreflightParams {
|
|
238
|
+
owner: Address;
|
|
239
|
+
destChainId: number;
|
|
240
|
+
vaultId: Address;
|
|
241
|
+
amount: string;
|
|
242
|
+
srcChainId?: number;
|
|
243
|
+
srcToken?: Address;
|
|
244
|
+
}
|
|
245
|
+
interface PreflightResult {
|
|
246
|
+
asset: Address;
|
|
247
|
+
/** ERC-4626 `maxDeposit(owner)`; `null` for kinds with no per-owner pool cap (e.g. Aave). */
|
|
248
|
+
maxDeposit: string | null;
|
|
249
|
+
route: {
|
|
250
|
+
bridgeTokenType: string;
|
|
251
|
+
requiresSrcSwap: boolean;
|
|
252
|
+
requiresDestSwap: boolean;
|
|
253
|
+
} | null;
|
|
254
|
+
vaultEntry: {
|
|
255
|
+
symbol: string;
|
|
256
|
+
protocol: string;
|
|
257
|
+
asset: Address;
|
|
258
|
+
tokenType: string;
|
|
259
|
+
decimals: number;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
interface BalancesParams {
|
|
263
|
+
chainId: number;
|
|
264
|
+
owner: Address;
|
|
265
|
+
tokens: Address[];
|
|
266
|
+
}
|
|
267
|
+
interface TokenBalance {
|
|
268
|
+
token: Address;
|
|
269
|
+
balance: string;
|
|
270
|
+
decimals: number;
|
|
271
|
+
}
|
|
272
|
+
interface BalancesResult {
|
|
273
|
+
balances: TokenBalance[];
|
|
274
|
+
}
|
|
275
|
+
interface SraStatusParams {
|
|
276
|
+
sra: Address;
|
|
277
|
+
page?: number;
|
|
278
|
+
pageSize?: number;
|
|
279
|
+
}
|
|
280
|
+
interface DepositInfo {
|
|
281
|
+
chainId: number;
|
|
282
|
+
token: Address;
|
|
283
|
+
amount: string;
|
|
284
|
+
blockNumber: string;
|
|
285
|
+
transactionHash: Hex;
|
|
286
|
+
}
|
|
287
|
+
interface BridgeInfo {
|
|
288
|
+
blockNumber: string;
|
|
289
|
+
transactionHash: Hex;
|
|
290
|
+
}
|
|
291
|
+
interface ExecutionInfo {
|
|
292
|
+
blockNumber: string;
|
|
293
|
+
chainId: number | null;
|
|
294
|
+
outputToken: Address;
|
|
295
|
+
transactionHash: Hex;
|
|
296
|
+
outputAmount: string;
|
|
297
|
+
}
|
|
298
|
+
interface DepositedToken {
|
|
299
|
+
deposit: DepositInfo;
|
|
300
|
+
bridge: BridgeInfo | null;
|
|
301
|
+
execution: ExecutionInfo | null;
|
|
302
|
+
}
|
|
303
|
+
interface SraStatusResult {
|
|
304
|
+
deposits: DepositedToken[];
|
|
305
|
+
totalCount: number;
|
|
306
|
+
nextPage: number | null;
|
|
307
|
+
totalPages: number;
|
|
308
|
+
}
|
|
309
|
+
interface SraInfoParams {
|
|
310
|
+
sra: Address;
|
|
311
|
+
}
|
|
312
|
+
interface SraInfoResult {
|
|
313
|
+
executionChainId: number;
|
|
314
|
+
owner: Address;
|
|
315
|
+
smartRoutingAddress: Address;
|
|
316
|
+
smartRoutingAddressManager: Address;
|
|
317
|
+
slippage: number;
|
|
318
|
+
srcTokens: {
|
|
319
|
+
token: Address;
|
|
320
|
+
chainId: number;
|
|
321
|
+
minAmount: string;
|
|
322
|
+
}[];
|
|
323
|
+
actions: {
|
|
324
|
+
asset: Address;
|
|
325
|
+
isNative: boolean;
|
|
326
|
+
calls: {
|
|
327
|
+
target: Address;
|
|
328
|
+
data: Hex;
|
|
329
|
+
value: string;
|
|
330
|
+
}[];
|
|
331
|
+
fallBack: {
|
|
332
|
+
target: Address;
|
|
333
|
+
data: Hex;
|
|
334
|
+
value: string;
|
|
335
|
+
}[];
|
|
336
|
+
}[];
|
|
337
|
+
createdAt: string;
|
|
338
|
+
updatedAt: string;
|
|
339
|
+
}
|
|
340
|
+
interface WithdrawCallsParams {
|
|
341
|
+
sra: Address;
|
|
342
|
+
tokens: {
|
|
343
|
+
chainId: number;
|
|
344
|
+
token: Address;
|
|
345
|
+
}[];
|
|
346
|
+
}
|
|
347
|
+
interface WithdrawCallsResult {
|
|
348
|
+
data: {
|
|
349
|
+
chainId: number;
|
|
350
|
+
calls: unknown[];
|
|
351
|
+
}[];
|
|
352
|
+
receiver: Address;
|
|
353
|
+
}
|
|
354
|
+
interface SraFeeEstimatesParams {
|
|
355
|
+
sra: Address;
|
|
356
|
+
}
|
|
357
|
+
interface EstimatedFeeData {
|
|
358
|
+
token: Address;
|
|
359
|
+
name: string;
|
|
360
|
+
decimal: number;
|
|
361
|
+
fee: Hex;
|
|
362
|
+
minDeposit: Hex;
|
|
363
|
+
maxDeposit?: Hex;
|
|
364
|
+
}
|
|
365
|
+
interface EstimatedFee {
|
|
366
|
+
chainId: number;
|
|
367
|
+
data: EstimatedFeeData[];
|
|
368
|
+
}
|
|
369
|
+
interface SraFeeEstimatesResult {
|
|
370
|
+
estimatedFees: EstimatedFee[];
|
|
371
|
+
}
|
|
372
|
+
interface DepositStatusParams {
|
|
373
|
+
sra: Address;
|
|
374
|
+
owner: Address;
|
|
375
|
+
destChainId: number;
|
|
376
|
+
vaultId: Address;
|
|
377
|
+
}
|
|
378
|
+
type DepositPhase = 'pending' | 'bridging' | 'deposited' | 'failed';
|
|
379
|
+
interface DepositStatusResult {
|
|
380
|
+
phase: DepositPhase;
|
|
381
|
+
deposits: DepositedToken[];
|
|
382
|
+
vaultBalance: string | null;
|
|
383
|
+
}
|
|
384
|
+
interface ChainInfo {
|
|
385
|
+
id: number;
|
|
386
|
+
nativeTokenSupported: boolean;
|
|
387
|
+
}
|
|
388
|
+
interface TokenInfo {
|
|
389
|
+
chainId: number;
|
|
390
|
+
tokenType: string;
|
|
391
|
+
address: Address;
|
|
392
|
+
decimals: number;
|
|
393
|
+
}
|
|
394
|
+
interface VaultInfo {
|
|
395
|
+
chainId: number;
|
|
396
|
+
address: Address;
|
|
397
|
+
symbol: string;
|
|
398
|
+
protocol: string;
|
|
399
|
+
asset: Address;
|
|
400
|
+
tokenType: string;
|
|
401
|
+
decimals: number;
|
|
402
|
+
}
|
|
403
|
+
interface VaultAsset {
|
|
404
|
+
symbol: string;
|
|
405
|
+
address: Address;
|
|
406
|
+
decimals: number;
|
|
407
|
+
}
|
|
408
|
+
/** Fields shared by every vault category. Slim projection of a vaults.fyi detailed vault. */
|
|
409
|
+
interface VaultCommon {
|
|
410
|
+
/** Server vault id — what `into` keys on. */
|
|
411
|
+
id: string;
|
|
412
|
+
/** Vault contract (its `asset()` is the deposit target). */
|
|
413
|
+
address: Address;
|
|
414
|
+
chainId: number;
|
|
415
|
+
protocol: string;
|
|
416
|
+
asset: VaultAsset;
|
|
417
|
+
apy: number | null;
|
|
418
|
+
tvlUsd: number | null;
|
|
419
|
+
name?: string;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Discriminated union on `category` — `maturity` is reachable only after narrowing
|
|
423
|
+
* on `category === 'fixed-yield'`.
|
|
424
|
+
*/
|
|
425
|
+
type Vault = (VaultCommon & {
|
|
426
|
+
category: 'lend';
|
|
427
|
+
}) | (VaultCommon & {
|
|
428
|
+
category: 'liquid-staking';
|
|
429
|
+
}) | (VaultCommon & {
|
|
430
|
+
category: 'fixed-yield';
|
|
431
|
+
maturity: string;
|
|
432
|
+
});
|
|
433
|
+
interface VaultDetailsExtra {
|
|
434
|
+
apyBreakdown?: {
|
|
435
|
+
base?: number;
|
|
436
|
+
reward?: number;
|
|
437
|
+
total?: number;
|
|
438
|
+
};
|
|
439
|
+
apy7day?: number;
|
|
440
|
+
apy30day?: number;
|
|
441
|
+
description?: string;
|
|
442
|
+
}
|
|
443
|
+
/** Detail view returned by `getVault(id)`; still `into`-compatible. */
|
|
444
|
+
type VaultDetails = Vault & VaultDetailsExtra;
|
|
445
|
+
type RecipeState = 'PENDING' | 'BRIDGING' | 'EXECUTING' | 'COMPLETED' | 'FAILED';
|
|
446
|
+
interface RecipeStatus {
|
|
447
|
+
sra: Address;
|
|
448
|
+
state: RecipeState;
|
|
449
|
+
deposits: DepositedToken[];
|
|
450
|
+
totalCount: number;
|
|
451
|
+
}
|
|
452
|
+
interface ErrorResponse {
|
|
453
|
+
error: {
|
|
454
|
+
code: string;
|
|
455
|
+
message: string;
|
|
456
|
+
details: unknown;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Canonical funding-token symbols. A `token` param accepts a `TokenSymbol` (resolved by the server
|
|
462
|
+
* to the canonical per-chain address) or a raw `Address` (to disambiguate variants like USDC.e or
|
|
463
|
+
* to use an arbitrary token). Aligned to the server's `TokenType` (`apps/server/src/lib/token-type.ts`),
|
|
464
|
+
* minus `WRAPPED_NATIVE` which is an internal routing type, not a public funding symbol.
|
|
465
|
+
*/
|
|
466
|
+
declare const TOKENS: {
|
|
467
|
+
readonly USDC: "USDC";
|
|
468
|
+
readonly USDT: "USDT";
|
|
469
|
+
readonly DAI: "DAI";
|
|
470
|
+
readonly WETH: "WETH";
|
|
471
|
+
readonly WBTC: "WBTC";
|
|
472
|
+
readonly EURC: "EURC";
|
|
473
|
+
readonly NATIVE: "NATIVE";
|
|
474
|
+
};
|
|
475
|
+
type TokenSymbol = (typeof TOKENS)[keyof typeof TOKENS];
|
|
476
|
+
/** Runtime guard: is `value` a known funding-token symbol? */
|
|
477
|
+
declare function isTokenSymbol(value: string): value is TokenSymbol;
|
|
478
|
+
|
|
479
|
+
/** A funding token: a canonical symbol or a raw address. */
|
|
480
|
+
type TokenInput = TokenSymbol | Address;
|
|
481
|
+
/** Where a multi-vault deposit goes: a vault id / address (string), or a `Vault` from `listVaults()`. */
|
|
482
|
+
type DepositTarget = string | Vault;
|
|
483
|
+
/**
|
|
484
|
+
* Core deposit shape (SMART_RECIPES_SDK.md § Shared param vocabulary). Facades narrow it:
|
|
485
|
+
* Aave drops `into`; Morpho/Fluid/Yearn require it.
|
|
486
|
+
*/
|
|
487
|
+
interface DepositParams {
|
|
488
|
+
/** Funds + signs + receives shares + gets refunds (single role). */
|
|
489
|
+
owner: Address;
|
|
490
|
+
/** Display units; server scales by token decimals (string math, no float). */
|
|
491
|
+
amount: number | string;
|
|
492
|
+
/** Source funding token; symbol → canonical per-chain address, or raw address. */
|
|
493
|
+
token: TokenInput;
|
|
494
|
+
/** Chain the user funds from. */
|
|
495
|
+
srcChainId: number;
|
|
496
|
+
/**
|
|
497
|
+
* Chain the recipe executes on. `srcChainId === destChainId` ⇒ same-chain (no bridge).
|
|
498
|
+
* Optional when `into` is a `Vault` object — derived from `vault.chainId`. Required
|
|
499
|
+
* otherwise (Aave, or `into` given as a string id/address).
|
|
500
|
+
*/
|
|
501
|
+
destChainId?: number;
|
|
502
|
+
/** Multi-vault facades only: raw address or a `Vault` from `listVaults()`. */
|
|
503
|
+
into?: DepositTarget;
|
|
504
|
+
/** Slippage in bps; default 100 (1%). */
|
|
505
|
+
slippage?: number;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Aave V3 supply. `destChainId` required (pool implied by `destChainId`). `into` OPTIONAL: pass an
|
|
509
|
+
* Aave Earn listing (id or `Vault` from `listVaults({ protocol: 'aave' })`) to pick WHICH reserve to
|
|
510
|
+
* supply — the funding `token` then bridges + dest-swaps into that reserve. Omit `into` to supply the
|
|
511
|
+
* funding token's own reserve directly.
|
|
512
|
+
*/
|
|
513
|
+
type AaveDepositParams = Omit<DepositParams, 'destChainId'> & {
|
|
514
|
+
destChainId: number;
|
|
515
|
+
};
|
|
516
|
+
/** Morpho / Fluid / Yearn / generic 4626: `into` is required. */
|
|
517
|
+
type VaultDepositParams = DepositParams & {
|
|
518
|
+
into: DepositTarget;
|
|
519
|
+
};
|
|
520
|
+
/** Params for `sr.bridgeAndSwap`. */
|
|
521
|
+
interface BridgeAndSwapParams {
|
|
522
|
+
owner: Address;
|
|
523
|
+
amount: number | string;
|
|
524
|
+
/** Source funding token. */
|
|
525
|
+
token: TokenInput;
|
|
526
|
+
/** Destination token to swap into. */
|
|
527
|
+
toToken: TokenInput;
|
|
528
|
+
srcChainId: number;
|
|
529
|
+
destChainId: number;
|
|
530
|
+
slippage?: number;
|
|
531
|
+
}
|
|
532
|
+
/** Discovery filter for `sr.listVaults`. */
|
|
533
|
+
interface ListVaultsParams {
|
|
534
|
+
asset?: TokenInput;
|
|
535
|
+
chains?: number[];
|
|
536
|
+
protocol?: string;
|
|
537
|
+
}
|
|
538
|
+
/** Options for `sr.watchStatus`. */
|
|
539
|
+
interface WatchStatusOptions {
|
|
540
|
+
/** Poll interval in ms; default 4000. */
|
|
541
|
+
interval?: number;
|
|
542
|
+
onStatusChange: (status: RecipeStatus) => void;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
interface SmartRecipesConfig {
|
|
546
|
+
serverUrl: string;
|
|
547
|
+
projectId: string;
|
|
548
|
+
fetch?: typeof globalThis.fetch;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Smart Recipes client (SMART_RECIPES_SDK.md). Protocol facades (`sr.aave`, `sr.morpho`, …) bind a
|
|
552
|
+
* mechanism and pick the same-chain vs cross-chain endpoint; the server does friendly→wire
|
|
553
|
+
* resolution (token symbols, decimal scaling). All amounts in responses stay as wire `string`s.
|
|
554
|
+
*/
|
|
555
|
+
declare function createSmartRecipes(config: SmartRecipesConfig): {
|
|
556
|
+
aave: {
|
|
557
|
+
/** Aave V3 supply. Optional `into` = an Aave Earn listing selecting the reserve to supply. */
|
|
558
|
+
deposit: (p: AaveDepositParams) => Promise<Quote>;
|
|
559
|
+
};
|
|
560
|
+
morpho: {
|
|
561
|
+
deposit: (p: VaultDepositParams) => Promise<Quote>;
|
|
562
|
+
};
|
|
563
|
+
fluid: {
|
|
564
|
+
deposit: (p: VaultDepositParams) => Promise<Quote>;
|
|
565
|
+
};
|
|
566
|
+
yearn: {
|
|
567
|
+
deposit: (p: VaultDepositParams) => Promise<Quote>;
|
|
568
|
+
};
|
|
569
|
+
erc4626: {
|
|
570
|
+
deposit: (p: VaultDepositParams) => Promise<Quote>;
|
|
571
|
+
};
|
|
572
|
+
depositIntoVault: (p: VaultDepositParams & {
|
|
573
|
+
protocol: string;
|
|
574
|
+
}) => Promise<Quote>;
|
|
575
|
+
bridgeAndSwap: (p: BridgeAndSwapParams) => Promise<Quote>;
|
|
576
|
+
listVaults: (params?: ListVaultsParams) => Promise<Vault[]>;
|
|
577
|
+
getVault: (vaultId: string) => Promise<VaultDetails>;
|
|
578
|
+
getStatus: (sra: string) => Promise<RecipeStatus>;
|
|
579
|
+
watchStatus: (sra: string, opts: WatchStatusOptions) => () => void;
|
|
580
|
+
getSraInfo: (params: SraInfoParams) => Promise<SraInfoResult>;
|
|
581
|
+
getWithdrawCalls: (params: WithdrawCallsParams) => Promise<WithdrawCallsResult>;
|
|
582
|
+
getSraFeeEstimates: (params: SraFeeEstimatesParams) => Promise<SraFeeEstimatesResult>;
|
|
583
|
+
getDepositStatus: (params: DepositStatusParams) => Promise<DepositStatusResult>;
|
|
584
|
+
preflight: (params: PreflightParams) => Promise<PreflightResult>;
|
|
585
|
+
getBalances: (params: BalancesParams) => Promise<BalancesResult>;
|
|
586
|
+
getChains: () => Promise<ChainInfo[]>;
|
|
587
|
+
getTokens: (params?: {
|
|
588
|
+
chainId?: number;
|
|
589
|
+
}) => Promise<TokenInfo[]>;
|
|
590
|
+
listOpportunities: (params?: ListOpportunitiesParams) => Promise<Vault[]>;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
declare class SmartRecipeError extends Error {
|
|
594
|
+
readonly code: string;
|
|
595
|
+
readonly details?: unknown | undefined;
|
|
596
|
+
constructor(code: string, message: string, details?: unknown | undefined);
|
|
597
|
+
}
|
|
598
|
+
type SmartRecipeErrorCtor = new (message: string, details?: unknown) => SmartRecipeError;
|
|
599
|
+
declare const InvalidRequestError: SmartRecipeErrorCtor;
|
|
600
|
+
declare const ServiceUnavailableError: SmartRecipeErrorCtor;
|
|
601
|
+
declare const InternalError: SmartRecipeErrorCtor;
|
|
602
|
+
declare const SraNotFoundError: SmartRecipeErrorCtor;
|
|
603
|
+
declare const SraUnavailableError: SmartRecipeErrorCtor;
|
|
604
|
+
declare const ChainNotSupportedError: SmartRecipeErrorCtor;
|
|
605
|
+
declare const VaultCapExceededError: SmartRecipeErrorCtor;
|
|
606
|
+
declare const AssetMismatchError: SmartRecipeErrorCtor;
|
|
607
|
+
declare const UnknownProtocolError: SmartRecipeErrorCtor;
|
|
608
|
+
declare const VaultTypeMismatchError: SmartRecipeErrorCtor;
|
|
609
|
+
declare const RpcUnavailableError: SmartRecipeErrorCtor;
|
|
610
|
+
declare const QuoterUnavailableError: SmartRecipeErrorCtor;
|
|
611
|
+
declare const UnsupportedTokenError: SmartRecipeErrorCtor;
|
|
612
|
+
declare const InsufficientAmountError: SmartRecipeErrorCtor;
|
|
613
|
+
declare const SwapRouteNotFoundError: SmartRecipeErrorCtor;
|
|
614
|
+
declare const QuoteExpiredError: SmartRecipeErrorCtor;
|
|
615
|
+
declare const SanctionedAddressError: SmartRecipeErrorCtor;
|
|
616
|
+
declare const VaultBlockedError: SmartRecipeErrorCtor;
|
|
617
|
+
declare function mapErrorCode(code: string, message: string, details?: unknown): SmartRecipeError;
|
|
618
|
+
|
|
619
|
+
/** Every error `code` the server can put on the wire. Single source of truth for server + SDK. */
|
|
620
|
+
declare const ERROR_CODES: readonly ["INVALID_REQUEST", "SERVICE_UNAVAILABLE", "QUOTER_UNAVAILABLE", "SRA_UNAVAILABLE", "SRA_NOT_FOUND", "VAULT_NOT_ALLOWLISTED", "CHAIN_NOT_SUPPORTED", "VAULT_CAP_EXCEEDED", "ASSET_MISMATCH", "UNKNOWN_PROTOCOL", "VAULT_TYPE_MISMATCH", "RPC_UNAVAILABLE", "INTERNAL_ERROR", "UNSUPPORTED_TOKEN", "INSUFFICIENT_AMOUNT", "SWAP_ROUTE_NOT_FOUND", "QUOTE_EXPIRED", "SANCTIONED_ADDRESS", "VAULT_BLOCKED"];
|
|
621
|
+
type ErrorCode = (typeof ERROR_CODES)[number];
|
|
622
|
+
/** Runtime guard: is `code` one of the known wire error codes? */
|
|
623
|
+
declare function isErrorCode(code: string): code is ErrorCode;
|
|
624
|
+
|
|
625
|
+
export { type AaveDepositParams, AssetMismatchError, type BalancesParams, type BalancesResult, type BridgeAndSwapParams, type BridgeAndSwapRequest, type BridgeDepositQuote, type BridgeDepositRequest, type BridgeDepositResponse, type BridgeInfo, type ChainId, type ChainInfo, ChainNotSupportedError, type DebugCall, type DebugStep, type DepositInfo, type DepositIntoVaultQuote, type DepositIntoVaultRequest, type DepositIntoVaultResponse, type DepositParams, type DepositPhase, type DepositRecipeRequest, type DepositStatusParams, type DepositStatusResult, type DepositTarget, type DepositedToken, ERROR_CODES, type ErrorCode, type ErrorResponse, type EstimatedFee, type EstimatedFeeData, type ExecutionInfo, InsufficientAmountError, InternalError, InvalidRequestError, type ListOpportunitiesArgs, type ListOpportunitiesParams, type ListVaultsParams, type OnChainCall, type OnChainCallWire, type OpportunitiesQuery, type PreflightParams, type PreflightResult, type Quote, type QuoteDebug, QuoteExpiredError, type QuoteFeeBreakdown, type QuoteRoute, type QuoteTransaction, QuoterUnavailableError, type RecipeState, type RecipeStatus, type RouteInfoWire, RpcUnavailableError, SanctionedAddressError, ServiceUnavailableError, SmartRecipeError, type SmartRecipesConfig, type SraFeeEstimatesParams, type SraFeeEstimatesResult, type SraInfoParams, type SraInfoResult, SraNotFoundError, type SraStatusParams, type SraStatusResult, SraUnavailableError, SwapRouteNotFoundError, TOKENS, type TokenBalance, type TokenInfo, type TokenInput, type TokenSymbol, UnknownProtocolError, UnsupportedTokenError, type UserOpIntent, type Vault, type VaultAsset, VaultBlockedError, VaultCapExceededError, type VaultCategory, type VaultCommon, type VaultDepositParams, type VaultDetails, type VaultDetailsExtra, type VaultInfo, VaultTypeMismatchError, type WatchStatusOptions, type WithdrawCallsParams, type WithdrawCallsResult, createSmartRecipes, isErrorCode, isTokenSymbol, mapErrorCode };
|