@aegis-engine/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +109 -4
  2. package/THIRD_PARTY_NOTICES.md +211 -0
  3. package/dist/actions/kyberSwap.d.ts +3 -2
  4. package/dist/address.d.ts +3 -1
  5. package/dist/aegis-core.js +8421 -5279
  6. package/dist/backendAdapters.d.ts +25 -1
  7. package/dist/config/constants.d.ts +4 -0
  8. package/dist/config/types.d.ts +5 -0
  9. package/dist/contract/backendClient.d.ts +16 -6
  10. package/dist/contract/generated/aegis-swap.d.ts +2682 -96
  11. package/dist/contract/schemas.d.ts +27 -20
  12. package/dist/engine/actions.d.ts +56 -0
  13. package/dist/engine/borrowCostProjection.d.ts +1 -0
  14. package/dist/engine/dataSource.d.ts +63 -0
  15. package/dist/engine/index.d.ts +7 -0
  16. package/dist/engine/marketAdapter.d.ts +8 -0
  17. package/dist/engine/quotes.d.ts +8 -0
  18. package/dist/engine/reads.d.ts +41 -0
  19. package/dist/engine/registry.d.ts +27 -0
  20. package/dist/engine/restSchemas.d.ts +409 -0
  21. package/dist/engine/sdk.d.ts +1 -0
  22. package/dist/engine/sdkRuntime.d.ts +1 -0
  23. package/dist/engine/types.d.ts +992 -0
  24. package/dist/errors.d.ts +10 -0
  25. package/dist/historicalPrices.d.ts +78 -0
  26. package/dist/index.d.ts +13 -8
  27. package/dist/internal/requestSignal.d.ts +9 -0
  28. package/dist/internal/ttlCache.d.ts +19 -0
  29. package/dist/metadata.d.ts +4 -0
  30. package/dist/permit.d.ts +1 -0
  31. package/dist/quote/aggregatedSwapQuote.d.ts +12 -0
  32. package/dist/quote/kyberCalldata.d.ts +211 -0
  33. package/dist/quote.d.ts +1 -0
  34. package/dist/sdkRuntime-CCRVvSwD.js +16052 -0
  35. package/dist/services/kyberSwap.d.ts +22 -2
  36. package/dist/swap/receiptWait.d.ts +17 -0
  37. package/dist/swap/sendSwapTransaction.d.ts +40 -6
  38. package/dist/swap/settlement.d.ts +15 -0
  39. package/dist/transactionProgress.d.ts +8 -1
  40. package/dist/types/aggregatedSwap.d.ts +18 -0
  41. package/package.json +15 -7
@@ -0,0 +1,992 @@
1
+ import type { Address, Hex, PublicClient, TransactionReceipt } from 'viem';
2
+ import type { AegisSwapChainConfig, AegisSwapToken } from '../config/index.js';
3
+ import type { SignedPermitBatch } from '../encoding.js';
4
+ import type { WalletSession } from '../swap/types.js';
5
+ export type AegisEngineMode = 'lend' | 'borrow' | 'positions';
6
+ export type AegisEngineMarketSource = 'rest' | 'static';
7
+ export type AegisEngineMarketStatus = 'enabled' | 'disabled' | 'hidden' | 'malformed';
8
+ export type AegisEngineToken = AegisSwapToken;
9
+ export type AegisEngineMarketMetrics = {
10
+ tvlUsd?: number | null;
11
+ suppliedUsd?: number | null;
12
+ borrowedUsd?: number | null;
13
+ availableToBorrowUsd?: number | null;
14
+ utilizationPct?: number | null;
15
+ borrowAprPct?: number | null;
16
+ lendApyPct?: number | null;
17
+ activeDebtVaultCount?: number | null;
18
+ sharePriceWad?: string | null;
19
+ ratePerSecondWad?: string | null;
20
+ fullUtilizationRate?: string | null;
21
+ rateSource?: string | null;
22
+ totalLendShares?: string | null;
23
+ baseFeePpm?: number | null;
24
+ activeFeePpm?: number | null;
25
+ surgeFeePpm?: number | null;
26
+ surgeActive?: boolean | null;
27
+ inCapEvent?: boolean | null;
28
+ manualOverride?: boolean | null;
29
+ perSwapMode?: boolean | null;
30
+ feeSource?: string | null;
31
+ computedAt?: string | null;
32
+ updatedAt?: string | null;
33
+ engineUpdatedAt?: string | null;
34
+ rateUpdatedAt?: string | null;
35
+ feeUpdatedAt?: string | null;
36
+ };
37
+ export type AegisEngineMarketFreshness = {
38
+ source: 'canopy';
39
+ updatedAt?: string | null;
40
+ engineUpdatedAt?: string | null;
41
+ rateUpdatedAt?: string | null;
42
+ feeUpdatedAt?: string | null;
43
+ blockNumber?: number | null;
44
+ blockTimestamp?: number | null;
45
+ };
46
+ export type AegisEngineDisabledReasons = {
47
+ borrow: string[];
48
+ lend: string[];
49
+ };
50
+ export type AegisEngineMarket = {
51
+ id: string;
52
+ chainId: number;
53
+ source: AegisEngineMarketSource;
54
+ status: AegisEngineMarketStatus;
55
+ displayName: string;
56
+ poolId: Hex;
57
+ token0: AegisEngineToken;
58
+ token1: AegisEngineToken;
59
+ poolKey: {
60
+ currency0: Address;
61
+ currency1: Address;
62
+ fee: number;
63
+ tickSpacing: number;
64
+ hooks: Address;
65
+ };
66
+ engine?: Address;
67
+ stateView?: Address;
68
+ v4StateView?: Address;
69
+ v4Quoter?: Address;
70
+ router?: Address;
71
+ permit2?: Address;
72
+ vaultRegistry?: Address;
73
+ borrowEnabled: boolean;
74
+ lendEnabled: boolean;
75
+ canBorrow?: boolean | null;
76
+ canLend?: boolean | null;
77
+ maxLtvPips?: number | null;
78
+ hardLtvPips?: number | null;
79
+ warnings: string[];
80
+ disabledReasons?: AegisEngineDisabledReasons;
81
+ metrics?: AegisEngineMarketMetrics;
82
+ /** Coherent backend read frame. Static host fixtures may omit it. */
83
+ freshness?: AegisEngineMarketFreshness;
84
+ };
85
+ export type AegisEngineHistoryWindow = '7d' | '30d' | '60d';
86
+ export type AegisEngineHistoryStatus = 'ready' | 'warming_up' | 'no_data';
87
+ export type AegisEngineMetricPoint = {
88
+ /** Start of the 12-hour UTC bucket, in Unix seconds. */
89
+ t: number;
90
+ observedAt: string;
91
+ blockNumber: number;
92
+ utilizationPct: number | null;
93
+ borrowAprPct: number | null;
94
+ lendApyPct: number | null;
95
+ ratePerSecondWad: string | null;
96
+ rateSource: string | null;
97
+ fullUtilizationRate: string | null;
98
+ sharePriceWad: string | null;
99
+ suppliedUsd: number | null;
100
+ borrowedUsd: number | null;
101
+ availableToBorrowUsd: number | null;
102
+ baseFeePpm: number | null;
103
+ activeFeePpm: number | null;
104
+ surgeFeePpm: number | null;
105
+ feeSource: string | null;
106
+ surgeActive: boolean | null;
107
+ inCapEvent: boolean | null;
108
+ manualOverride: boolean | null;
109
+ perSwapMode: boolean | null;
110
+ warnings: string[];
111
+ };
112
+ export type AegisEngineMetricHistory = {
113
+ marketId: string;
114
+ resolution: '12h';
115
+ window: AegisEngineHistoryWindow;
116
+ status: AegisEngineHistoryStatus;
117
+ pointCount: number;
118
+ points: AegisEngineMetricPoint[];
119
+ updatedAt: string | null;
120
+ };
121
+ export type AegisEnginePositionTokenAmount = {
122
+ raw: string;
123
+ formatted: string;
124
+ valueUsd?: number | null;
125
+ };
126
+ export type AegisEnginePositionDebt = {
127
+ principalRaw: string;
128
+ borrowIndexWadAtLastDebt?: string | null;
129
+ };
130
+ export type AegisEnginePositionLtv = {
131
+ /** Subgraph-indexed value captured when the vault was last locked. It is
132
+ * not a live health measurement; current LTV requires a StateView read. */
133
+ lastLockedPips?: number | null;
134
+ lastLockedPct?: number | null;
135
+ maxLtvPips?: number | null;
136
+ hardLtvPips?: number | null;
137
+ };
138
+ export type AegisEnginePositionNft = {
139
+ id?: string | null;
140
+ kind?: string | null;
141
+ tokenId?: string | null;
142
+ liquidityRaw?: string | null;
143
+ };
144
+ export type AegisEnginePosition = {
145
+ id: string;
146
+ chainId: number;
147
+ account: Address;
148
+ vaultId: string;
149
+ status: 'open' | 'debt' | 'collateral' | 'empty';
150
+ marketId?: string | null;
151
+ marketName?: string | null;
152
+ poolId: Hex;
153
+ token0?: AegisEngineToken | null;
154
+ token1?: AegisEngineToken | null;
155
+ amount0: AegisEnginePositionTokenAmount;
156
+ amount1: AegisEnginePositionTokenAmount;
157
+ collateralValueUsd?: number | null;
158
+ debt: AegisEnginePositionDebt;
159
+ ltv: AegisEnginePositionLtv;
160
+ nfts: {
161
+ count: number;
162
+ items: AegisEnginePositionNft[];
163
+ };
164
+ createdAt?: string | null;
165
+ createdBlockNumber?: number | null;
166
+ updatedAt?: string | null;
167
+ warnings: string[];
168
+ };
169
+ export type AegisEngineLendSharesPosition = {
170
+ kind: 'lend_shares';
171
+ id: string;
172
+ chainId: number;
173
+ account: Address;
174
+ marketId: string | null;
175
+ marketName: string | null;
176
+ poolId: Hex;
177
+ token0: AegisEngineToken | null;
178
+ token1: AegisEngineToken | null;
179
+ /** Indexed lender balance in raw Engine share units (bigint decimal string).
180
+ * Not a token amount — value it with a current share price. */
181
+ indexedBalanceRaw: string;
182
+ warnings: string[];
183
+ freshness: {
184
+ source: 'subgraph';
185
+ indexedBlockNumber: number | null;
186
+ };
187
+ };
188
+ export type AegisEnginePositionsSnapshot = {
189
+ schemaVersion: '1' | '2';
190
+ chainId: number;
191
+ account: Address;
192
+ positions: AegisEnginePosition[];
193
+ /** Lender-share positions. Every loader emits an array (empty for v1
194
+ * responses and when v2 is unavailable), so consumers read it
195
+ * unconditionally. */
196
+ lendPositions: AegisEngineLendSharesPosition[];
197
+ totals: {
198
+ collateralValueUsd?: number | null;
199
+ positionCount: number;
200
+ /** Number of borrow-vault rows in `positions`. */
201
+ borrowVaultCount: number;
202
+ /** Number of lender-share rows in `lendPositions`. */
203
+ lendPositionCount: number;
204
+ };
205
+ freshness: {
206
+ source: 'subgraph' | 'static';
207
+ blockNumber?: number | null;
208
+ positionCount: number;
209
+ };
210
+ };
211
+ export type AegisEngineActivityActionBase = {
212
+ /** Stable subgraph row id. */
213
+ id: string;
214
+ /** Event block time in Unix seconds. */
215
+ timestamp: number;
216
+ blockNumber: number;
217
+ transactionIndex: number;
218
+ txHash: Hex;
219
+ logIndex: number;
220
+ };
221
+ export type AegisEngineVaultLedgerAction = (AegisEngineActivityActionBase & {
222
+ kind: 'vault_created';
223
+ owner: Address;
224
+ }) | (AegisEngineActivityActionBase & {
225
+ kind: 'vault_burned';
226
+ /** Executor/periphery address, not necessarily the vault owner. */
227
+ caller: Address;
228
+ }) | (AegisEngineActivityActionBase & {
229
+ kind: 'vault_locked';
230
+ /** Historical LTV at this lock; null is unknown, not zero. */
231
+ ltvPips: number | null;
232
+ }) | (AegisEngineActivityActionBase & {
233
+ kind: 'debt_modified';
234
+ principalDeltaRequestedRaw: string;
235
+ principalDeltaActualRaw: string;
236
+ borrowIndexWad: string;
237
+ deltaIdle0Raw: string;
238
+ deltaIdle1Raw: string;
239
+ }) | (AegisEngineActivityActionBase & {
240
+ kind: 'idle_modified';
241
+ deltaAmount0Raw: string;
242
+ deltaAmount1Raw: string;
243
+ }) | (AegisEngineActivityActionBase & {
244
+ kind: 'vault_micro_liquidated';
245
+ caller: Address;
246
+ zeroForOne: boolean;
247
+ swapDelta0Raw: string;
248
+ swapDelta1Raw: string;
249
+ debtRepaidRlRaw: string;
250
+ idleDelta0Raw: string;
251
+ idleDelta1Raw: string;
252
+ keeperFee0Raw: string;
253
+ keeperFee1Raw: string;
254
+ initialLtvPips: number | null;
255
+ });
256
+ export type AegisEngineLendLedgerAction = (AegisEngineActivityActionBase & {
257
+ kind: 'deposit' | 'withdraw';
258
+ deltaSharesRaw: string;
259
+ deltaAmount0Raw: string;
260
+ deltaAmount1Raw: string;
261
+ }) | (AegisEngineActivityActionBase & {
262
+ kind: 'transfer_in' | 'transfer_out';
263
+ sharesRaw: string;
264
+ counterparty: Address;
265
+ });
266
+ export type AegisEngineActivityMarketState = {
267
+ marketId: string | null;
268
+ marketName: string | null;
269
+ poolId: Hex;
270
+ borrowIndexWad: string | null;
271
+ lastAccrueTimestamp: number | null;
272
+ ratePerSecondWad: string | null;
273
+ rateUpdatedAt: string | null;
274
+ totalRlBorrowed: string | null;
275
+ shareTotalSupply: string | null;
276
+ warnings: string[];
277
+ };
278
+ export type AegisEnginePositionVaultActivity = {
279
+ vaultId: string;
280
+ poolId: Hex;
281
+ marketId: string | null;
282
+ marketName: string | null;
283
+ createdAt: string | null;
284
+ burnedAt: string | null;
285
+ /** Oldest-first on-chain execution order. */
286
+ actions: AegisEngineVaultLedgerAction[];
287
+ };
288
+ export type AegisEnginePositionLendActivity = {
289
+ poolId: Hex;
290
+ marketId: string | null;
291
+ marketName: string | null;
292
+ /** Oldest-first on-chain execution order. */
293
+ actions: AegisEngineLendLedgerAction[];
294
+ };
295
+ /** Wallet-scoped action ledger returned by GET /v1/engine/positions/activity.
296
+ * Raw amount strings preserve the backend's exact signed bigint wire values;
297
+ * this endpoint does not synthesize USD values. */
298
+ export type AegisEnginePositionActivitySnapshot = {
299
+ schemaVersion: '1';
300
+ chainId: number;
301
+ account: Address;
302
+ marketState: AegisEngineActivityMarketState[];
303
+ /** Newest-first by numeric vault id; burned vaults remain present. */
304
+ vaults: AegisEnginePositionVaultActivity[];
305
+ /** Ascending by pool id. */
306
+ lend: AegisEnginePositionLendActivity[];
307
+ totals: {
308
+ vaultCount: number;
309
+ lendMarketCount: number;
310
+ vaultActionCount: number;
311
+ lendActionCount: number;
312
+ };
313
+ freshness: {
314
+ source: 'subgraph';
315
+ /** Oldest indexed block across all pages; null when any page omitted it. */
316
+ blockNumber: number | null;
317
+ };
318
+ };
319
+ export type AegisEngineBorrowPositionHydration = {
320
+ positionId: string;
321
+ vaultId: bigint;
322
+ } & ({
323
+ status: 'ok';
324
+ vault: {
325
+ poolId: Hex;
326
+ owner: Address;
327
+ /** Principal debt in rL units. */
328
+ rL: bigint;
329
+ /** Accrued debt in L units at this hydration frame. */
330
+ debtLLatest: bigint;
331
+ idle0: bigint;
332
+ idle1: bigint;
333
+ /** Null when the vault has no debt, never a synthetic zero. */
334
+ ltvPipsLatest: bigint | null;
335
+ maxLtvPips: number;
336
+ hardLtvPips: number;
337
+ };
338
+ } | {
339
+ status: 'failed';
340
+ reason: 'read-error' | 'owner-mismatch' | 'vault-burned';
341
+ detail?: string;
342
+ });
343
+ export type AegisEngineLendPositionHydration = {
344
+ positionId: string;
345
+ account: Address;
346
+ poolId: Hex;
347
+ } & ({
348
+ status: 'ok';
349
+ shareBalance: bigint;
350
+ totalShares: bigint;
351
+ sharePriceWad: bigint;
352
+ equityLWad: bigint;
353
+ } | {
354
+ status: 'failed';
355
+ reason: 'read-error';
356
+ detail?: string;
357
+ });
358
+ export type AegisEnginePositionsHydration = {
359
+ /** One block-pinned frame shared by every borrow and lend result. */
360
+ frame: AegisEngineReadFrame;
361
+ borrowPositions: AegisEngineBorrowPositionHydration[];
362
+ lendPositions: AegisEngineLendPositionHydration[];
363
+ };
364
+ export type AegisEnginePositionsHydrationInput = {
365
+ publicClient: PublicClient;
366
+ chainId: number;
367
+ expectedAccount: Address;
368
+ positions: readonly AegisEnginePosition[];
369
+ lendPositions: readonly AegisEngineLendSharesPosition[];
370
+ signal?: AbortSignal;
371
+ };
372
+ export type AegisEngineRestSource = {
373
+ kind: 'rest';
374
+ baseUrl: string;
375
+ headers?: Record<string, string>;
376
+ /**
377
+ * Maximum time for a shared REST request, including response-body parsing.
378
+ * Consumer abort signals remain isolated from the shared request. Defaults
379
+ * to 10 seconds.
380
+ */
381
+ timeoutMs?: number;
382
+ };
383
+ /**
384
+ * Markets supplied inline by the host. No network call is made — the source is
385
+ * returned as-is (filtered to the active chain). Useful for offline demos,
386
+ * deterministic tests/screenshots, and partners who already hold market
387
+ * metadata and only want the widget to own quoting/execution.
388
+ */
389
+ export type AegisEngineStaticSource = {
390
+ kind: 'static';
391
+ markets: AegisEngineMarket[];
392
+ positions?: AegisEnginePosition[];
393
+ lendPositions?: AegisEngineLendSharesPosition[];
394
+ };
395
+ export type AegisEngineDataSource = AegisEngineRestSource | AegisEngineStaticSource;
396
+ export type AegisEngineMarketReadInput = {
397
+ publicClient: PublicClient;
398
+ market: AegisEngineMarket;
399
+ };
400
+ /** Public, SDK-independent snapshot facts used by Core's lend quote path. */
401
+ export type AegisEngineProtocolMarket = {
402
+ poolId: Hex;
403
+ poolKey: AegisEngineMarket['poolKey'];
404
+ initialized: boolean;
405
+ maxLtvPips: number;
406
+ hardLtvPips: number;
407
+ borrowIndexWad: bigint;
408
+ equityLWad: bigint;
409
+ borrowedLWad: bigint;
410
+ };
411
+ export type AegisEnginePoolState = {
412
+ sqrtPriceX96: bigint;
413
+ tick: number;
414
+ protocolFee: number;
415
+ lpFee: number;
416
+ liquidity: bigint;
417
+ };
418
+ export type AegisEngineMarketSnapshot = {
419
+ market: AegisEngineProtocolMarket;
420
+ poolState: AegisEnginePoolState;
421
+ sharePriceWadLatest: bigint;
422
+ thresholds: {
423
+ maxLtvPips: number;
424
+ hardLtvPips: number;
425
+ };
426
+ };
427
+ export type AegisEngineReadFrame = {
428
+ blockNumber: bigint;
429
+ blockTimestamp: bigint;
430
+ /** Local wall-clock time when the frame was assembled, in Unix milliseconds. */
431
+ observedAt: number;
432
+ };
433
+ export type AegisEngineVersion = 'v0.4.0' | 'v1.0.2';
434
+ export type AegisEngineBorrowMarketContext = {
435
+ poolId: Hex;
436
+ poolKey: AegisEngineMarket['poolKey'];
437
+ sqrtPriceX96: bigint;
438
+ tickCurrent: number;
439
+ tickSpacing: number;
440
+ inRangeLiquidity: bigint;
441
+ borrowIndexWad: bigint;
442
+ equityLWad: bigint;
443
+ borrowedLWad: bigint;
444
+ maxLtvPips: number;
445
+ hardLtvPips: number;
446
+ currentRatePerSecWad: bigint;
447
+ decimals0: number;
448
+ decimals1: number;
449
+ };
450
+ /**
451
+ * In-frame authorization evidence read alongside the borrow context when it
452
+ * is hydrated with an owner. Structural mirror of the SDK's
453
+ * `BorrowExecutionEvidence`; quotes pass it back verbatim so the SDK can
454
+ * gate its guarded call against the same block.
455
+ */
456
+ export type AegisEngineBorrowExecutionEvidence = {
457
+ owner: Address;
458
+ vaultId: bigint | null;
459
+ chainId: number;
460
+ permit2: Address;
461
+ ownerOnChain: Address | null;
462
+ vaultPoolId: Hex | null;
463
+ routerApproved: boolean;
464
+ router: Address;
465
+ vaultRegistry: Address;
466
+ blockNumber: bigint;
467
+ };
468
+ export type AegisEngineBorrowQuoteContext = {
469
+ chainId: number;
470
+ version: AegisEngineVersion;
471
+ poolId: Hex;
472
+ market: AegisEngineBorrowMarketContext;
473
+ aprProjection: {
474
+ chainId: number;
475
+ version: AegisEngineVersion;
476
+ rateOracleAddress: Address;
477
+ fullUtilRate: bigint;
478
+ };
479
+ frame: AegisEngineReadFrame;
480
+ /** Present only when the context read was asked to hydrate evidence. */
481
+ execution: AegisEngineBorrowExecutionEvidence | null;
482
+ };
483
+ export type AegisEngineQuoteBase = {
484
+ publicClient: PublicClient;
485
+ market: AegisEngineMarket;
486
+ owner: Address;
487
+ inputIsToken0: boolean;
488
+ slippageBps: number;
489
+ deadline?: bigint;
490
+ quoteTtlSeconds?: bigint;
491
+ signal?: AbortSignal;
492
+ permit?: AegisEngineSignedPermitBatch | null;
493
+ };
494
+ export type AegisEngineDepositQuoteInput = AegisEngineQuoteBase & {
495
+ amountIn: bigint;
496
+ };
497
+ /**
498
+ * Live snapshot of an already-open borrow vault, in the pool's real token
499
+ * orientation. Passing it to a borrow quote sizes the new debt against the
500
+ * vault's existing idle and debt and encodes the recipe on the same `vaultId`
501
+ * (a `modifyVault`) instead of minting a fresh vault. Mirrors the SDK's
502
+ * `BorrowVaultContext`.
503
+ */
504
+ export type AegisEngineBorrowVaultContext = {
505
+ vaultId: bigint;
506
+ poolId: Hex;
507
+ owner: Address;
508
+ /** Idle balance of currency0 (token wei). */
509
+ x0: bigint;
510
+ /** Idle balance of currency1 (token wei). */
511
+ y0: bigint;
512
+ /** Existing debt principal in rL units. */
513
+ rL0: bigint;
514
+ };
515
+ export type AegisEngineBorrowQuoteInput = AegisEngineQuoteBase & {
516
+ collateralIn: bigint;
517
+ borrowOut: bigint;
518
+ tauPips?: number;
519
+ /**
520
+ * Target LTV as a percentage of the live market maximum. Core resolves this
521
+ * only after reading the block-pinned market context, so stale REST
522
+ * thresholds cannot turn a conservative percentage into the live maximum.
523
+ */
524
+ tauPercentOfMaxLtv?: number;
525
+ comfortCapLtvPips?: number;
526
+ /**
527
+ * When present, borrow into this existing vault instead of opening a new one.
528
+ * Core validates its pool/owner against the market before sizing.
529
+ */
530
+ vault?: AegisEngineBorrowVaultContext | null;
531
+ /**
532
+ * Hydrate in-frame authorization evidence for `owner` and request the SDK's
533
+ * guarded call. Submit paths set this; indicative display quotes omit it and
534
+ * receive `tx: null` (`executable` stays false — an unproven quote never
535
+ * labels itself executable).
536
+ */
537
+ withExecutionEvidence?: boolean;
538
+ };
539
+ export type AegisEngineBorrowCapacityInput = Omit<AegisEngineQuoteBase, 'owner' | 'deadline' | 'permit'> & {
540
+ collateralIn: bigint;
541
+ /** Optional output-first target. When supplied, the result includes the
542
+ * collateral floor for the deterministic no-swap path. */
543
+ borrowOut?: bigint;
544
+ tauPips?: number;
545
+ /** See `AegisEngineBorrowQuoteInput.tauPercentOfMaxLtv`. */
546
+ tauPercentOfMaxLtv?: number;
547
+ /** Existing vault to size headroom against; see `AegisEngineBorrowQuoteInput.vault`. */
548
+ vault?: AegisEngineBorrowVaultContext | null;
549
+ };
550
+ export type AegisEngineDepositQuoteResult = {
551
+ feasible: boolean;
552
+ executable: boolean;
553
+ infeasibleReason?: 'invalid-input' | 'quote-unavailable' | 'insufficient-output' | 'zero-liquidity' | 'builder-error';
554
+ /** SDK recipe input retained for diagnostics. Use `tx` on the enclosing
555
+ * Core quote for execution instead of encoding this value downstream. */
556
+ encodeInput: unknown | null;
557
+ call: {
558
+ calldata: Hex;
559
+ value: bigint;
560
+ } | null;
561
+ swap: {
562
+ needed: boolean;
563
+ amountIn: bigint;
564
+ isToken0: boolean;
565
+ amountOut: bigint;
566
+ minAmountOut: bigint;
567
+ } | null;
568
+ deposit: {
569
+ amount0: bigint;
570
+ amount1: bigint;
571
+ liquidityDelta: bigint;
572
+ expectedShares: bigint;
573
+ minDeltaShares: bigint;
574
+ expectedSharePriceWad: bigint;
575
+ amount0Max: bigint;
576
+ amount1Max: bigint;
577
+ } | null;
578
+ expectedSharePriceWad: bigint;
579
+ routeSummary: string | null;
580
+ priceImpactBps: number | null;
581
+ approvalPlan: {
582
+ approvalType: string;
583
+ token: Address;
584
+ amount: bigint;
585
+ required: boolean;
586
+ nativeValue: bigint;
587
+ spender?: Address;
588
+ };
589
+ gateFailures: readonly AegisEngineLifecycleGateFailure[];
590
+ display: {
591
+ lendAprPct: number | null;
592
+ lendApyPct: number | null;
593
+ };
594
+ apyEstimate: unknown | null;
595
+ postDeposit: {
596
+ basis: 'projected-post-deposit';
597
+ aprPct: number | null;
598
+ apyPct: number | null;
599
+ unavailableReason: string | null;
600
+ assumptions: readonly string[];
601
+ } | null;
602
+ frame: AegisEngineReadFrame | null;
603
+ warnings: string[];
604
+ expiresAt: bigint;
605
+ quoteCount: number;
606
+ };
607
+ export type AegisEngineDepositQuote = {
608
+ kind: 'lend';
609
+ market: AegisEngineMarket;
610
+ inputToken: AegisEngineToken;
611
+ quote: AegisEngineDepositQuoteResult;
612
+ tx: AegisEnginePreparedTransaction | null;
613
+ };
614
+ export type AegisEngineBorrowRecipeEncodeInput = {
615
+ maxLtvPips: number;
616
+ };
617
+ /** Days until liquidation, or `'INF'` when the position never drifts in. */
618
+ export type AegisEngineDaysToLiquidation = number | 'INF';
619
+ export type AegisEngineBorrowQuoteResult = {
620
+ feasible: boolean;
621
+ executable: boolean;
622
+ /** Failed execution gates; `[]` when no evidence was supplied. */
623
+ gateFailures: readonly AegisEngineLifecycleGateFailure[];
624
+ infeasibleReason?: string;
625
+ encodeInput: AegisEngineBorrowRecipeEncodeInput | null;
626
+ call: {
627
+ calldata: Hex;
628
+ value: bigint;
629
+ } | null;
630
+ recipe: {
631
+ encodeInput: AegisEngineBorrowRecipeEncodeInput | null;
632
+ };
633
+ swap: {
634
+ needed: boolean;
635
+ amountIn: bigint;
636
+ isToken0: boolean;
637
+ minAmountOut: bigint;
638
+ } | null;
639
+ finalVault: {
640
+ xV: bigint;
641
+ yV: bigint;
642
+ gammaTotalLTarget: bigint;
643
+ gammaNewLTarget: bigint;
644
+ rL0Post: bigint;
645
+ gammaTotalLPostRounded: bigint;
646
+ } | null;
647
+ display: {
648
+ postBorrowLtvPips: number | null;
649
+ preBorrowAprPct: number | null;
650
+ postBorrowAprPct: number | null;
651
+ postBorrowUtilPips: bigint | null;
652
+ /**
653
+ * Days until LTV drifts into the liquidation threshold at the CURRENT
654
+ * per-second rate. Engine LTV is `γ_L / √(x·y)` — both terms are liquidity
655
+ * amounts, so it carries no price and only interest accrual moves it
656
+ * toward the threshold. Time, not price, is this protocol's liquidation
657
+ * axis, and this is the only horizon the SDK will state.
658
+ * `'INF'` = the rate is zero and the position never drifts in; null = the
659
+ * market's rate is unavailable (non-canonical oracle), never a fabricated
660
+ * horizon.
661
+ */
662
+ daysToLiquidationAtCurrentApr: AegisEngineDaysToLiquidation | null;
663
+ /** Same horizon at the projected post-borrow APR; null unless the rate
664
+ * projection resolved. */
665
+ postBorrowDaysToLiquidation: AegisEngineDaysToLiquidation | null;
666
+ };
667
+ frame: AegisEngineReadFrame | null;
668
+ expiresAt: bigint | null;
669
+ };
670
+ export type AegisEngineBorrowQuote = {
671
+ kind: 'borrow';
672
+ market: AegisEngineMarket;
673
+ collateralToken: AegisEngineToken;
674
+ borrowToken: AegisEngineToken;
675
+ /** Thresholds read in the same live frame used to build the quote. */
676
+ thresholds: {
677
+ maxLtvPips: number;
678
+ hardLtvPips: number;
679
+ };
680
+ quote: AegisEngineBorrowQuoteResult;
681
+ costProjection: AegisEngineBorrowCostProjection;
682
+ tx: AegisEnginePreparedTransaction | null;
683
+ };
684
+ export type AegisEnginePositionActionKind = 'repay' | 'close' | 'withdraw' | 'redeem';
685
+ export type AegisEngineBorrowPositionTarget = {
686
+ kind: 'borrow_vault';
687
+ positionId: string;
688
+ chainId: number;
689
+ marketId: string | null;
690
+ poolId: Hex;
691
+ vaultId: bigint;
692
+ };
693
+ export type AegisEngineLendPositionTarget = {
694
+ kind: 'lend_shares';
695
+ positionId: string;
696
+ chainId: number;
697
+ marketId: string | null;
698
+ poolId: Hex;
699
+ };
700
+ /**
701
+ * Stable identity for an already-open Engine position. Keeping this distinct
702
+ * from the new Borrow/Lend draft prevents a manage action from silently
703
+ * falling back to `vault: null` (open a new vault).
704
+ */
705
+ export type AegisEnginePositionTarget = AegisEngineBorrowPositionTarget | AegisEngineLendPositionTarget;
706
+ export type AegisEngineLifecycleGateFailure = {
707
+ gate: string;
708
+ [key: string]: unknown;
709
+ };
710
+ export type AegisEngineLifecycleApprovalPlan = {
711
+ approvalType: 'permit2';
712
+ token: Address;
713
+ amount: bigint;
714
+ required: boolean;
715
+ nativeValue: bigint;
716
+ spender?: Address;
717
+ };
718
+ export type AegisEnginePositionActionQuote = {
719
+ kind: AegisEnginePositionActionKind;
720
+ market: AegisEngineMarket;
721
+ target: AegisEnginePositionTarget;
722
+ feasible: boolean;
723
+ executable: boolean;
724
+ infeasibleReason: string | null;
725
+ gateFailures: readonly AegisEngineLifecycleGateFailure[];
726
+ approvals: readonly AegisEngineLifecycleApprovalPlan[];
727
+ /** Wallet token top-ups required by repay/close. */
728
+ fromWallet0: bigint;
729
+ fromWallet1: bigint;
730
+ /** Expected two-token output for close/redeem, when the quote can price it. */
731
+ expected: {
732
+ amount0: bigint;
733
+ amount1: bigint;
734
+ } | null;
735
+ /** Encoded output protection for redeem. Close has no encodable minimum. */
736
+ minimum: {
737
+ amount0: bigint;
738
+ amount1: bigint;
739
+ } | null;
740
+ /** Borrow principal affected by repay/close, in rL units. */
741
+ principalDeltaRl: bigint | null;
742
+ /** Exact idle token amounts requested by withdraw. */
743
+ withdraw: {
744
+ amount0: bigint;
745
+ amount1: bigint;
746
+ } | null;
747
+ /** Engine shares affected by redeem. */
748
+ sharesDelta: bigint | null;
749
+ shareBalance: bigint | null;
750
+ postShareBalance: bigint | null;
751
+ /**
752
+ * Live, block-pinned lend exit capacity. Present only for redeem quotes
753
+ * requested with `shares: "available"`.
754
+ */
755
+ redeemAvailability?: {
756
+ /** Whether the live frame can return the whole position or only part. */
757
+ mode: 'full' | 'partial';
758
+ /** Exact shares encoded by this quote. */
759
+ redeemableShares: bigint;
760
+ /** Owner balance observed in the same frame. */
761
+ shareBalance: bigint;
762
+ /** Shares that remain deposited after this quote executes. */
763
+ remainingShares: bigint;
764
+ };
765
+ expiresAt: bigint;
766
+ warnings: readonly string[];
767
+ tx: AegisEnginePreparedTransaction | null;
768
+ };
769
+ type AegisEnginePositionActionQuoteBase = {
770
+ publicClient: PublicClient;
771
+ market: AegisEngineMarket;
772
+ owner: Address;
773
+ target: AegisEnginePositionTarget;
774
+ deadline?: bigint;
775
+ quoteTtlSeconds?: bigint;
776
+ signal?: AbortSignal;
777
+ };
778
+ export type AegisEngineRepayQuoteInput = AegisEnginePositionActionQuoteBase & {
779
+ target: AegisEngineBorrowPositionTarget;
780
+ repayRl?: bigint | 'full';
781
+ slippageBps: number;
782
+ };
783
+ export type AegisEngineCloseQuoteInput = AegisEnginePositionActionQuoteBase & {
784
+ target: AegisEngineBorrowPositionTarget;
785
+ };
786
+ export type AegisEngineIdleWithdrawQuoteInput = AegisEnginePositionActionQuoteBase & {
787
+ target: AegisEngineBorrowPositionTarget;
788
+ withdraw?: 'all' | {
789
+ amount0: bigint;
790
+ amount1: bigint;
791
+ };
792
+ };
793
+ export type AegisEngineRedeemQuoteInput = AegisEnginePositionActionQuoteBase & {
794
+ target: AegisEngineLendPositionTarget;
795
+ /**
796
+ * `available` quotes the full balance when possible, otherwise the exact
797
+ * maximum currently supported by unborrowed market equity.
798
+ */
799
+ shares?: bigint | 'all' | 'available';
800
+ slippageBps: number;
801
+ };
802
+ export type AegisEngineBorrowRateBasis = 'projected-post-borrow';
803
+ /** Which rate the liquidation horizon was projected at. */
804
+ export type AegisEngineLiquidationHorizonBasis = 'projected-post-borrow' | 'current-apr';
805
+ export type AegisEngineBorrowCostMissingInput = 'rounded-debt-frame' | 'debt-valuation' | 'usd-valuation-basis' | 'borrow-apr';
806
+ export type AegisEngineBorrowCostLimitation = 'constant-rate-estimate' | 'gas-not-included' | 'collateral-opportunity-cost-not-included' | 'liquidation-risk-not-modeled' | 'repay-quote-not-modeled';
807
+ /**
808
+ * One SDK `computeVaultStateSnapshot` expressed in the two pool-token
809
+ * denominations plus the quote's explicit USD basis. "Collateral" here is
810
+ * the vault's live idle-token value; it intentionally does not invent a value
811
+ * for attached NFT/LP collateral the SDK snapshot does not expose.
812
+ */
813
+ export type AegisEngineBorrowVaultValueSnapshot = {
814
+ collateralValueToken0: number | null;
815
+ collateralValueToken1: number | null;
816
+ collateralValueUsd: number | null;
817
+ debtValueToken0: number | null;
818
+ debtValueToken1: number | null;
819
+ debtValueUsd: number | null;
820
+ };
821
+ /**
822
+ * Display-only economics derived from the exact rounded post-quote debt
823
+ * frame. This is not an executable repay quote and must never authorize a
824
+ * transaction.
825
+ */
826
+ export type AegisEngineBorrowCostProjection = {
827
+ gammaTotalLPostRounded: bigint | null;
828
+ /**
829
+ * Authoritative money comparison from SDK vault-state snapshots. `before`
830
+ * is null for a first loan (or when an existing vault could not be valued);
831
+ * `after` is null when the quote did not return a valid final vault.
832
+ */
833
+ vaultValues: {
834
+ before: AegisEngineBorrowVaultValueSnapshot | null;
835
+ after: AegisEngineBorrowVaultValueSnapshot | null;
836
+ };
837
+ /** @deprecated Read `vaultValues.after.debtValueToken0`. */
838
+ debtValueToken0: number | null;
839
+ /** @deprecated Read `vaultValues.after.debtValueToken1`. */
840
+ debtValueToken1: number | null;
841
+ /** @deprecated Read `vaultValues.after.debtValueUsd`. */
842
+ debtValueUsd: number | null;
843
+ usdValuationBasis: 'token0' | 'token1' | null;
844
+ rate: {
845
+ aprPct: number | null;
846
+ basis: AegisEngineBorrowRateBasis | null;
847
+ };
848
+ /**
849
+ * Days until interest accrual drifts LTV into the liquidation threshold.
850
+ * Engine LTV is `γ_L / √(x·y)` — both terms are liquidity amounts — so price
851
+ * does not move it and accrual is the only clock. This protocol therefore
852
+ * has no liquidation PRICE; time is the whole risk axis.
853
+ *
854
+ * Feasibility-gated like {@link AegisEngineBorrowCostProjection.rate}: an
855
+ * infeasible quote can retain display math, and a retained horizon presented
856
+ * as a liquidation countdown is the worst claim this panel can make.
857
+ */
858
+ liquidationHorizon: {
859
+ days: AegisEngineDaysToLiquidation | null;
860
+ basis: AegisEngineLiquidationHorizonBasis | null;
861
+ };
862
+ constantRateMonthlyCarryUsd: number | null;
863
+ missingInputs: AegisEngineBorrowCostMissingInput[];
864
+ limitations: AegisEngineBorrowCostLimitation[];
865
+ };
866
+ export type AegisEngineVaultActivityKind = 'borrow' | 'repay' | 'add-collateral' | 'withdraw-collateral' | 'vault-activity' | 'deposit' | 'withdraw';
867
+ /** One transaction's effect on a position, replayed from the Engine
868
+ * subgraph's action ledger. Deltas are signed token base units. `received*`
869
+ * is the requested-token amount delivered to the wallet on a borrow,
870
+ * identified from the trace's single-token idle withdrawal; null when
871
+ * ambiguous. Lend entries ('deposit'/'withdraw') reuse the collateral-delta
872
+ * slots for the token amounts moved, with no principal or received leg. */
873
+ export type AegisEngineVaultActivityEntry = {
874
+ txHash: `0x${string}`;
875
+ /** Unix seconds. */
876
+ timestamp: number;
877
+ kind: AegisEngineVaultActivityKind;
878
+ /** Signed debt principal change in RL units (no cross-market unit). */
879
+ principalDeltaRl: bigint;
880
+ /** Net collateral movement, excluding the identified borrow delivery. */
881
+ collateralDelta0: bigint;
882
+ collateralDelta1: bigint;
883
+ receivedRaw: bigint | null;
884
+ receivedIsToken0: boolean | null;
885
+ };
886
+ export type AegisEngineBorrowCapacity = {
887
+ kind: 'borrow-capacity';
888
+ market: AegisEngineMarket;
889
+ collateralToken: AegisEngineToken;
890
+ borrowToken: AegisEngineToken;
891
+ /** Thresholds read in the same live frame used for capacity math. */
892
+ thresholds: {
893
+ maxLtvPips: number;
894
+ hardLtvPips: number;
895
+ };
896
+ tauPips: number;
897
+ /** Echoes percentage-based sizing; null for an absolute/default tau. */
898
+ tauPercentOfMaxLtv: number | null;
899
+ /** Echoed output target used to derive `minimumNoSwapCollateralIn`. */
900
+ borrowOut: bigint | null;
901
+ /** Minimum fresh-vault deposit that crosses the SDK's integer no-swap
902
+ * boundary. Null when no output target was supplied, no closed-form
903
+ * no-swap solution exists, or the market is utilization-capped. */
904
+ minimumNoSwapCollateralIn: bigint | null;
905
+ /** Equals `capacity.utilizationPre >= capacity.utilizationCap` at quote
906
+ * time. Named (rather than derived by consumers) because the SDK's stage
907
+ * classifier can mask a cap block behind preserve-vs-allow reachability
908
+ * (`preserve-collateral-blocked`), so `bindingConstraint`/quote reasons
909
+ * can't be trusted for it. When true no borrow executes for any deposit
910
+ * and no collateral floor is published. */
911
+ utilizationCapped: boolean;
912
+ capacity: {
913
+ yMaxLtv: bigint;
914
+ yMaxFromUtilization: bigint | null;
915
+ yMaxNoDebt: bigint;
916
+ yMaxBorrow: bigint;
917
+ yMaxEffective: bigint;
918
+ yMaxNoDebtAtHaircut: bigint;
919
+ yMaxBorrowAtHaircut: bigint;
920
+ /** Haircut-aware maximum borrow output in receive-token base units. */
921
+ yMaxEffectiveAtHaircut: bigint;
922
+ quoteHaircutBpsApplied: number;
923
+ collateralPolicyApplied: 'allow-collateral-swap' | 'preserve-collateral';
924
+ yKnee: bigint | null;
925
+ utilizationPre: number;
926
+ utilizationCap: number;
927
+ minDebtFloorRl: bigint;
928
+ bindingConstraint: 'idle' | 'ltv-no-new-borrow' | 'zero-debt-swap' | 'ltv' | 'utilization' | 'regime-b' | 'min-debt' | 'unknown';
929
+ bindingConstraintAtHaircut?: 'idle' | 'ltv-no-new-borrow' | 'zero-debt-swap' | 'ltv' | 'utilization' | 'regime-b' | 'min-debt' | 'unknown';
930
+ dMinNoSwap: bigint | null;
931
+ gammaNewLAtEffectiveMax: bigint | null;
932
+ deltaLWadAtEffectiveMax: bigint | null;
933
+ };
934
+ };
935
+ export type AegisEnginePreparedTransaction = {
936
+ to: Address;
937
+ data: Hex;
938
+ value: bigint;
939
+ };
940
+ export type AegisEngineSignedPermitBatch = SignedPermitBatch;
941
+ export type AegisEngineWalletSession = WalletSession;
942
+ export type AegisEngineActionCallbacks = {
943
+ onStatus?: (status: 'approving' | 'signing' | 'submitting' | 'success' | 'idle') => void;
944
+ onTxHash?: (hash: Hex | null) => void;
945
+ onSubmitted?: (hash: Hex) => void;
946
+ };
947
+ export type AegisEngineTransactionResult = {
948
+ hash: Hex;
949
+ explorerUrl: string;
950
+ receipt: TransactionReceipt;
951
+ summary: {
952
+ transactionHash: Hex;
953
+ blockNumber: bigint;
954
+ gasUsed: bigint;
955
+ effectiveGasPrice: bigint;
956
+ feeWei: bigint;
957
+ };
958
+ };
959
+ export type AegisEngineApprovalInput = {
960
+ wallet: AegisEngineWalletSession;
961
+ publicClient: PublicClient;
962
+ activeChain: AegisSwapChainConfig;
963
+ token: AegisEngineToken;
964
+ permit2: Address;
965
+ router: Address;
966
+ amount: bigint;
967
+ approvalMode?: 'exact' | 'max';
968
+ permit2AuthorizationMode?: 'signature' | 'spending-cap';
969
+ onStatus?: AegisEngineActionCallbacks['onStatus'];
970
+ };
971
+ export type AegisEngineSendInput = {
972
+ wallet: AegisEngineWalletSession;
973
+ publicClient: PublicClient;
974
+ activeChain: AegisSwapChainConfig;
975
+ tx: AegisEnginePreparedTransaction;
976
+ /**
977
+ * Absolute Unix timestamp encoded into the prepared Engine transaction.
978
+ * When present, the send boundary refuses to open the wallet if too little
979
+ * validity remains.
980
+ */
981
+ expiresAt?: bigint;
982
+ /** Required validity remaining before a wallet request may be opened. */
983
+ minimumValiditySeconds?: bigint;
984
+ permit2Context?: {
985
+ token: AegisEngineToken;
986
+ permit2: Address;
987
+ router: Address;
988
+ amount: bigint;
989
+ inlinePermit: boolean;
990
+ };
991
+ } & AegisEngineActionCallbacks;
992
+ export {};