@gearbox-protocol/sdk 16.0.0-next.27 → 16.0.0-next.29

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 (75) hide show
  1. package/dist/cjs/model/index.js +1 -0
  2. package/dist/cjs/model/previews.js +23 -0
  3. package/dist/cjs/onchain/accounts/intents/open-strategy.js +5 -18
  4. package/dist/cjs/onchain/accounts/intents/realize.js +77 -49
  5. package/dist/cjs/onchain/accounts/intents/testing/market.js +1 -0
  6. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +28 -5
  7. package/dist/cjs/onchain/index.js +6 -0
  8. package/dist/cjs/onchain/market/credit/creditOperationMarket.js +32 -0
  9. package/dist/cjs/onchain/market/credit/index.js +3 -0
  10. package/dist/cjs/onchain/market/index.js +5 -0
  11. package/dist/cjs/onchain/market/oracle/collateralPriceInUnderlying.js +27 -0
  12. package/dist/cjs/onchain/market/oracle/index.js +2 -0
  13. package/dist/cjs/onchain/positions/PositionsService.js +94 -0
  14. package/dist/cjs/onchain/positions/calcLiquidationPrice.js +14 -4
  15. package/dist/cjs/onchain/positions/index.js +1 -0
  16. package/dist/cjs/preview/index.js +6 -6
  17. package/dist/cjs/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +8 -27
  18. package/dist/cjs/preview/preview/index.js +6 -6
  19. package/dist/cjs/preview/preview/{previewAdjustCreditAccount.js → previewAdjustStrategyVerify.js} +6 -24
  20. package/dist/cjs/preview/preview/{previewCloseOrRepayCreditAccount.js → previewExitOrRepayStrategyVerify.js} +6 -7
  21. package/dist/cjs/preview/preview/{previewPoolOperation.js → previewLpVerify.js} +3 -3
  22. package/dist/cjs/preview/preview/{previewOpenCreditAccount.js → previewOpenStrategyVerify.js} +6 -26
  23. package/dist/cjs/preview/preview/previewOperation.js +13 -12
  24. package/dist/cjs/preview/validate/checkOperation.js +13 -9
  25. package/dist/esm/model/index.js +2 -2
  26. package/dist/esm/model/previews.js +23 -1
  27. package/dist/esm/onchain/accounts/intents/open-strategy.js +5 -18
  28. package/dist/esm/onchain/accounts/intents/realize.js +77 -49
  29. package/dist/esm/onchain/accounts/intents/testing/market.js +1 -0
  30. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +27 -6
  31. package/dist/esm/onchain/index.js +4 -2
  32. package/dist/esm/onchain/market/credit/creditOperationMarket.js +30 -0
  33. package/dist/esm/onchain/market/credit/index.js +2 -1
  34. package/dist/esm/onchain/market/index.js +3 -1
  35. package/dist/esm/onchain/market/oracle/collateralPriceInUnderlying.js +26 -0
  36. package/dist/esm/onchain/market/oracle/index.js +2 -1
  37. package/dist/esm/onchain/positions/PositionsService.js +95 -1
  38. package/dist/esm/onchain/positions/calcLiquidationPrice.js +14 -5
  39. package/dist/esm/onchain/positions/index.js +2 -2
  40. package/dist/esm/preview/index.js +4 -4
  41. package/dist/esm/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +9 -28
  42. package/dist/esm/preview/preview/index.js +4 -4
  43. package/dist/esm/preview/preview/{previewAdjustCreditAccount.js → previewAdjustStrategyVerify.js} +7 -25
  44. package/dist/esm/preview/preview/{previewCloseOrRepayCreditAccount.js → previewExitOrRepayStrategyVerify.js} +6 -7
  45. package/dist/esm/preview/preview/{previewPoolOperation.js → previewLpVerify.js} +3 -3
  46. package/dist/esm/preview/preview/{previewOpenCreditAccount.js → previewOpenStrategyVerify.js} +7 -27
  47. package/dist/esm/preview/preview/previewOperation.js +13 -12
  48. package/dist/esm/preview/validate/checkOperation.js +13 -9
  49. package/dist/types/model/index.d.ts +2 -2
  50. package/dist/types/model/previews.d.ts +222 -97
  51. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +13 -7
  52. package/dist/types/onchain/accounts/intents/testing/market.d.ts +1 -0
  53. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +18 -0
  54. package/dist/types/onchain/accounts/intents/types.d.ts +12 -0
  55. package/dist/types/onchain/index.d.ts +4 -2
  56. package/dist/types/onchain/market/credit/creditOperationMarket.d.ts +23 -0
  57. package/dist/types/onchain/market/credit/index.d.ts +2 -1
  58. package/dist/types/onchain/market/index.d.ts +3 -1
  59. package/dist/types/onchain/market/oracle/collateralPriceInUnderlying.d.ts +19 -0
  60. package/dist/types/onchain/market/oracle/index.d.ts +2 -1
  61. package/dist/types/onchain/positions/PositionsService.d.ts +38 -0
  62. package/dist/types/onchain/positions/calcLiquidationPrice.d.ts +10 -1
  63. package/dist/types/onchain/positions/index.d.ts +2 -2
  64. package/dist/types/preview/index.d.ts +5 -5
  65. package/dist/types/preview/preview/{buildDelayedPreview.d.ts → buildDelayedStrategyVerify.d.ts} +4 -4
  66. package/dist/types/preview/preview/index.d.ts +4 -4
  67. package/dist/types/preview/preview/{previewAdjustCreditAccount.d.ts → previewAdjustStrategyVerify.d.ts} +4 -4
  68. package/dist/types/preview/preview/{previewCloseOrRepayCreditAccount.d.ts → previewExitOrRepayStrategyVerify.d.ts} +4 -4
  69. package/dist/types/preview/preview/previewLpVerify.d.ts +11 -0
  70. package/dist/types/preview/preview/previewOpenStrategyVerify.d.ts +12 -0
  71. package/dist/types/preview/validate/checkOperation.d.ts +12 -4
  72. package/dist/types/preview/validate/index.d.ts +2 -2
  73. package/package.json +1 -1
  74. package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +0 -12
  75. package/dist/types/preview/preview/previewPoolOperation.d.ts +0 -11
@@ -4,7 +4,7 @@ import { BorrowRateBreakdown } from "./positions.js";
4
4
  import { Address, Hex } from "viem";
5
5
  //#region src/model/previews.d.ts
6
6
  /**
7
- * ERC4626 pool operation kind, as surfaced on a {@link PoolOperationPreview}.
7
+ * ERC4626 pool operation kind, as surfaced on a {@link PreviewLpVerify}.
8
8
  **/
9
9
  type PoolOperationType = "Deposit" | "Mint" | "Withdraw" | "Redeem";
10
10
  /**
@@ -96,7 +96,12 @@ interface OperationPreviewError {
96
96
  */
97
97
  message: string;
98
98
  }
99
- interface PoolOperationPreview {
99
+ /**
100
+ * What a pool transaction that already exists would do — the counterpart of
101
+ * `prepare.deposit`, `prepare.withdraw` and `prepare.redeem`, read off calldata
102
+ * rather than planned into it.
103
+ **/
104
+ interface PreviewLpVerify {
100
105
  operation: PoolOperationType;
101
106
  /**
102
107
  * Pool address
@@ -138,18 +143,15 @@ interface PoolOperationPreview {
138
143
  error?: OperationPreviewError;
139
144
  }
140
145
  /**
141
- * A credit account as an operation leaves it, answered by both halves of the
142
- * SDK: `prepare`, which walks a request forward into the calls that realise it,
143
- * and `preview`, which decodes calls that already exist and replays them back.
144
- *
145
- * `totalDebt`, `totalValue`, `leverage` and `healthFactor` mean here exactly
146
- * what they mean on a {@link StrategyPosition}, down to the token an amount
147
- * names — an RWA market reports USDC, not the dcUSDC wrapper the pool holds.
146
+ * The market a credit operation acts on, reported the same way by every half of
147
+ * the SDK: the calldata previews, the intents engine's projections and the
148
+ * open-strategy walk all carry it, so a screen naming the market needs nothing
149
+ * beside the result it already holds.
148
150
  **/
149
- interface AccountProjection {
151
+ interface CreditOperationMarket {
150
152
  /**
151
- * Credit manager the account belongs to. Carried on the projection itself so
152
- * a caller weighing one — `checkSimulation` among them — needs nothing beside
153
+ * Credit manager the account belongs to. Carried on the result itself so a
154
+ * caller weighing one — `checkSimulation` among them — needs nothing beside
153
155
  * it to find the market.
154
156
  */
155
157
  creditManager: Address;
@@ -157,6 +159,67 @@ interface AccountProjection {
157
159
  * Human-readable credit manager name.
158
160
  */
159
161
  name: string;
162
+ /**
163
+ * Market configurator of the market {@link creditManager} belongs to — the
164
+ * on-chain identity of the curator, which is what a curator link and a
165
+ * curator name resolve from. Not a personal wallet.
166
+ */
167
+ curator: Address;
168
+ /**
169
+ * What a liquidation takes off the account, in basis points: the premium the
170
+ * liquidator keeps plus the protocol's own fee.
171
+ *
172
+ * Not the credit manager's `liquidationDiscount`, which is the complement of
173
+ * the premium alone (`100% - liquidationPremium`) and says what share of the
174
+ * collateral repays the debt. This is the figure a position screen labels
175
+ * "Liquidation Discount": `liquidationPremium + feeLiquidation`.
176
+ */
177
+ liquidationDiscount: Bps;
178
+ }
179
+ /**
180
+ * What an account is worth and what it is made of, once an operation has run.
181
+ *
182
+ * The measured half of a {@link AccountProjection}: read off the balances the
183
+ * walk arrived at, without a formula between them and the answer.
184
+ **/
185
+ interface AccountHoldings {
186
+ /**
187
+ * Everything the account holds, denominated in the market's underlying.
188
+ **/
189
+ totalValue: TokenAmount;
190
+ /**
191
+ * What it would take to settle the loan: principal plus accrued interest and
192
+ * fees, in the market's underlying.
193
+ **/
194
+ totalDebt: TokenAmount;
195
+ /**
196
+ * Own funds in the position: `totalValue` less `totalDebt`, in the market's
197
+ * underlying. The read model leaves a strategy caller to subtract these two
198
+ * itself; a projection reports the figure so an "own funds" row reads the
199
+ * same on every screen that shows one.
200
+ **/
201
+ netValue: TokenAmount;
202
+ /**
203
+ * What the account holds, token by token.
204
+ **/
205
+ assets: TokenAmount[];
206
+ /**
207
+ * Quota bought for each collateral, denominated in the market's underlying
208
+ * rather than in the collateral token — the same convention as
209
+ * {@link PositionCollateral.quota}. A token the account leaves unquoted is
210
+ * absent rather than present at zero.
211
+ **/
212
+ quotas: TokenAmount[];
213
+ }
214
+ /**
215
+ * The risk and cost of an account, derived from what it holds.
216
+ *
217
+ * The computed half of a {@link AccountProjection}, and the reason it is a type
218
+ * of its own: every one of these is a formula over the same
219
+ * {@link AccountSnapshot}, so both halves of the SDK get them from one place —
220
+ * `sdk.positions.metrics` — and cannot drift into two answers for one account.
221
+ **/
222
+ interface AccountMetrics {
160
223
  /**
161
224
  * Health factor in basis points: below `10000` the account is liquidatable.
162
225
  *
@@ -168,16 +231,20 @@ interface AccountProjection {
168
231
  * token's main and reserve oracle feeds, which is what the credit manager
169
232
  * switches to for a call that hands funds over.
170
233
  *
171
- * Absent only where the walk had no reason to weigh it: the intents engine
172
- * computes it for an operation that hands funds over, which is the one the
173
- * credit manager holds to safe prices on-chain. Both preview builders and
174
- * `openNewStrategy` always report it.
234
+ * Always reported, whether or not the operation in question hands anything
235
+ * over: which of the two factors decides a transaction is a property of the
236
+ * call the caller ends up sending, and a screen showing the account is
237
+ * entitled to both.
175
238
  *
176
239
  * @example `11800` where `healthFactor` is `12500`
177
240
  **/
178
- safeHealthFactor?: Bps;
241
+ safeHealthFactor: Bps;
179
242
  /**
180
243
  * Cost of the debt, broken down by source.
244
+ *
245
+ * Half of the breakdown rests on the debt and the quotas alone (`base`,
246
+ * `totalOnDebt`) and half on the position's value (`total`, `quotas[].rate`),
247
+ * which is why it counts as a {@link RoutedField}.
181
248
  **/
182
249
  borrowRate: BorrowRateBreakdown;
183
250
  /**
@@ -197,39 +264,114 @@ interface AccountProjection {
197
264
  * unleveraged; `0` if underwater.
198
265
  **/
199
266
  leverage: Leverage;
267
+ }
268
+ /**
269
+ * A credit account as an operation leaves it, answered by both halves of the
270
+ * SDK: `prepare`, which walks a request forward into the calls that realise it,
271
+ * and `preview`, which decodes calls that already exist and replays them back.
272
+ *
273
+ * Both answer in this same vocabulary, and from the same builder
274
+ * (`sdk.positions.projection`), so the two descriptions of one operation can be
275
+ * compared field by field — which is what
276
+ * `previewMatchesPrepare.test.ts` does.
277
+ *
278
+ * This shape is the expected branch of a routed leg, which is what `prepare`
279
+ * reports; `preview` sees only the floor and answers with an
280
+ * {@link EstimatedProjection}, the same fields with the routed ones marked
281
+ * `est`. Where nothing routes the two coincide exactly.
282
+ *
283
+ * `totalDebt`, `totalValue`, `leverage` and `healthFactor` mean here exactly
284
+ * what they mean on a {@link StrategyPosition}, down to the token an amount
285
+ * names — an RWA market reports USDC, not the dcUSDC wrapper the pool holds.
286
+ **/
287
+ interface AccountProjection extends CreditOperationMarket, AccountHoldings, AccountMetrics {}
288
+ /**
289
+ * The fields of an {@link AccountProjection} a routed leg's outcome decides.
290
+ *
291
+ * A swap is quoted twice: the amount the pathfinder expects to return, and the
292
+ * floor it is willing to guarantee once slippage is allowed for. `prepare` has
293
+ * both and reports the expected one — that is where the position lands.
294
+ * `preview` reads a transaction that already exists, and calldata carries only
295
+ * the floor, so its answer is the worst case the same operation can settle at.
296
+ *
297
+ * Everything not listed here is the same number on either branch: the debt and
298
+ * the quotas are named by the calls themselves.
299
+ *
300
+ * The borrow rate is listed despite being half made of those two. `base` and
301
+ * `totalOnDebt` are branch-independent — the pool's rate at the projected
302
+ * utilization, and the quota rates over the debt — but `total` and the per-token
303
+ * `quotas[].rate` normalize against `totalValue`, so a floor-branch breakdown
304
+ * quotes the same cost against a smaller position and comes out higher. One
305
+ * field cannot be half prefixed, and the half that moves is the half a screen
306
+ * shows, so the whole breakdown carries the marker.
307
+ **/
308
+ type RoutedField = "totalValue" | "netValue" | "assets" | "healthFactor" | "safeHealthFactor" | "borrowRate" | "timeToLiquidation" | "liquidationPrice" | "leverage";
309
+ /**
310
+ * `x` becomes `estX`, for a projection assembled from the guaranteed floor.
311
+ *
312
+ * The prefix is not decoration: an `estHealthFactor` and a `healthFactor` are
313
+ * answers to different questions, and naming them alike would invite a screen
314
+ * to show one as the other or a test to hold them equal.
315
+ **/
316
+ type Estimated<T> = { [K in keyof T as `est${Capitalize<string & K>}`]: T[K]; };
317
+ /**
318
+ * A projection as `preview` can answer it: the branch-independent half under the
319
+ * shared names, and everything a route decides marked `est`.
320
+ *
321
+ * Same builder, same formulas, same units as an {@link AccountProjection} — only
322
+ * the snapshot underneath is the floor rather than the expected outcome.
323
+ **/
324
+ type EstimatedProjection = Omit<AccountProjection, RoutedField> & Estimated<Pick<AccountProjection, RoutedField>>;
325
+ /**
326
+ * Renames a projection's routed fields, for a caller that built one from floor
327
+ * balances.
328
+ *
329
+ * Lives beside the type so the two cannot drift: a field added to
330
+ * {@link RoutedField} fails to compile until it is renamed here too.
331
+ **/
332
+ declare function asEstimated(p: AccountProjection): EstimatedProjection;
333
+ /**
334
+ * What an operation moved, as opposed to where it left the account.
335
+ *
336
+ * Only `preview` reports these: it is handed both sides of the transaction and
337
+ * diffs them, while `prepare` is asked to reach a state and answers with the
338
+ * calls that get there. Split out so the two halves agree on the names for the
339
+ * day prepare reports deltas too.
340
+ **/
341
+ interface AccountStateChange {
200
342
  /**
201
- * Everything the account holds, denominated in the market's underlying.
202
- **/
203
- totalValue: TokenAmount;
204
- /**
205
- * What it would take to settle the loan: principal plus accrued interest and
206
- * fees, in the market's underlying.
207
- **/
208
- totalDebt: TokenAmount;
209
- /**
210
- * Own funds in the position: `totalValue` less `totalDebt`, in the market's
211
- * underlying. The read model leaves a strategy caller to subtract these two
212
- * itself; a projection reports the figure so an "own funds" row reads the
213
- * same on every screen that shows one.
214
- **/
215
- netValue: TokenAmount;
343
+ * Debt after minus debt before. A repayment settles interest and fees
344
+ * before principal, so this is the payment itself rather than the part of
345
+ * it the principal happened to absorb.
346
+ */
347
+ totalDebtChange: TokenAmount;
216
348
  /**
217
- * What the account holds, token by token.
218
- **/
219
- assets: TokenAmount[];
349
+ * Quotas after minus quotas before. Denominated in the market's underlying
350
+ * like {@link AccountHoldings.quotas}, so `token` names the collateral the
351
+ * quota applies to rather than the amount's own unit.
352
+ */
353
+ quotasChange: TokenAmount[];
220
354
  /**
221
- * Quota bought for each collateral, denominated in the market's underlying
222
- * rather than in the collateral token — the same convention as
223
- * {@link PositionCollateral.quota}. A token the account leaves unquoted is
224
- * absent rather than present at zero.
225
- **/
226
- quotas: TokenAmount[];
355
+ * Assets after minus assets before.
356
+ *
357
+ * Unprefixed despite resting on the same floor balances as
358
+ * {@link EstimatedProjection.estAssets}: `prepare` reports no deltas at all,
359
+ * so there is no expected-branch figure of this name to be mistaken for.
360
+ */
361
+ assetsChange: TokenAmount[];
227
362
  }
228
- interface OpenCreditAccountPreview extends AccountProjection {
363
+ /**
364
+ * What an account-opening transaction that already exists would do — the
365
+ * counterpart of `prepare.openNewStrategy`, read off calldata rather than
366
+ * planned into it.
367
+ **/
368
+ interface PreviewOpenStrategyVerify extends EstimatedProjection {
229
369
  operation: "OpenCreditAccount" | "RWAOpenCreditAccount";
230
370
  /**
231
371
  * Collateral token this position is a strategy in: the first quoted token,
232
- * with its balance taken from `assets`. Undefined when nothing is quoted.
372
+ * with its balance taken from `estAssets` so, like them, the floor the
373
+ * route guarantees rather than what it expects to return.
374
+ * Undefined when nothing is quoted.
233
375
  */
234
376
  targetCollateral?: TokenAmount;
235
377
  /**
@@ -242,12 +384,18 @@ interface OpenCreditAccountPreview extends AccountProjection {
242
384
  collateralAdded: TokenAmount[];
243
385
  /**
244
386
  * Set when preview encountered non-fatal errors, all fields are
245
- * still computed best-effort, but derived fields (`assets`,
246
- * `targetCollateral`, `netValue`) may be unreliable in that case.
387
+ * still computed best-effort, but derived fields (`estAssets`,
388
+ * `targetCollateral`, `estNetValue`) may be unreliable in that case.
247
389
  */
248
390
  error?: OperationPreviewError;
249
391
  }
250
- interface AdjustCreditAccountPreview extends AccountProjection {
392
+ /**
393
+ * What a transaction on an existing account would do — the counterpart of the
394
+ * `prepare` flows that adjust one (`depositStrategy`, `withdrawStrategy`,
395
+ * `addCollateral`, `withdrawCollateral`, `adjustLeverage`), read off calldata
396
+ * rather than planned into it.
397
+ **/
398
+ interface PreviewAdjustStrategyVerify extends EstimatedProjection, AccountStateChange {
251
399
  operation: "AdjustCreditAccount";
252
400
  /**
253
401
  * Credit account that is being adjusted
@@ -265,22 +413,6 @@ interface AdjustCreditAccountPreview extends AccountProjection {
265
413
  * Tokens that were withdrawn as collateral during account adjustment.
266
414
  */
267
415
  collateralWithdrawn: TokenAmount[];
268
- /**
269
- * Debt after minus debt before. A repayment settles interest and fees
270
- * before principal, so this is the payment itself rather than the part of
271
- * it the principal happened to absorb.
272
- */
273
- totalDebtChange: TokenAmount;
274
- /**
275
- * Quotas after minus quotas before. Denominated in the market's underlying
276
- * like {@link AccountProjection.quotas}, so `token` names the collateral the
277
- * quota applies to rather than the amount's own unit.
278
- */
279
- quotasChange: TokenAmount[];
280
- /**
281
- * Assets after minus assets before
282
- */
283
- assetsChange: TokenAmount[];
284
416
  /**
285
417
  * Intent of the delayed withdrawal this transaction claims; set when the
286
418
  * multicall claims a delayed withdrawal
@@ -288,12 +420,21 @@ interface AdjustCreditAccountPreview extends AccountProjection {
288
420
  intent?: DelayedIntent;
289
421
  /**
290
422
  * Set when preview encountered non-fatal errors, all fields are
291
- * still computed best-effort, but derived fields (`assets`, `assetsChange`,
292
- * `totalValue`) may be unreliable in that case.
423
+ * still computed best-effort, but derived fields (`estAssets`, `assetsChange`,
424
+ * `estTotalValue`) may be unreliable in that case.
293
425
  */
294
426
  error?: OperationPreviewError;
295
427
  }
296
- interface CloseCreditAccountPreview {
428
+ /**
429
+ * What an exit transaction that already exists would do — the counterpart of
430
+ * `prepare.withdrawStrategy` asked for everything, read off calldata rather
431
+ * than planned into it.
432
+ *
433
+ * Carries no {@link AccountProjection}: the account it describes ends up empty,
434
+ * so there is no position left to weigh — what a caller wants to know is the
435
+ * payout. The market it happened in is still named, as everywhere else.
436
+ **/
437
+ interface PreviewExitStrategyVerify extends CreditOperationMarket {
297
438
  operation: "CloseCreditAccount";
298
439
  /**
299
440
  * True when the account is closed permanently (facade `closeCreditAccount`
@@ -301,14 +442,6 @@ interface CloseCreditAccountPreview {
301
442
  * (plain multicall).
302
443
  */
303
444
  permanent: boolean;
304
- /**
305
- * Credit manager the account belongs to
306
- */
307
- creditManager: Address;
308
- /**
309
- * Human-readable credit manager name
310
- */
311
- name: string;
312
445
  /**
313
446
  * Credit account that is being closed
314
447
  */
@@ -333,7 +466,15 @@ interface CloseCreditAccountPreview {
333
466
  */
334
467
  error?: OperationPreviewError;
335
468
  }
336
- interface RepayCreditAccountPreview {
469
+ /**
470
+ * What a settling repayment that already exists would do — the counterpart of
471
+ * `prepare.repayStrategy` asked for the whole debt, read off calldata rather
472
+ * than planned into it.
473
+ *
474
+ * Carries no {@link AccountProjection} for the same reason the exit does not:
475
+ * the loan ends here, so the risk metrics have nothing left to describe.
476
+ **/
477
+ interface PreviewRepayStrategyVerify extends CreditOperationMarket {
337
478
  operation: "RepayCreditAccount";
338
479
  /**
339
480
  * True when the account is closed permanently (facade `closeCreditAccount`
@@ -341,14 +482,6 @@ interface RepayCreditAccountPreview {
341
482
  * (plain multicall).
342
483
  */
343
484
  permanent: boolean;
344
- /**
345
- * Credit manager the account belongs to
346
- */
347
- creditManager: Address;
348
- /**
349
- * Human-readable credit manager name
350
- */
351
- name: string;
352
485
  /**
353
486
  * Credit account that is being repaid
354
487
  */
@@ -369,7 +502,7 @@ interface RepayCreditAccountPreview {
369
502
  /**
370
503
  * Total debt repaid: principal + accrued interest + fees, in underlying.
371
504
  *
372
- * The same quantity an {@link AdjustCreditAccountPreview} reports as
505
+ * The same quantity a {@link PreviewAdjustStrategyVerify} reports as
373
506
  * `totalDebtChange`, with the sign a repayment screen reads: positive for
374
507
  * what the wallet parted with.
375
508
  */
@@ -391,27 +524,19 @@ interface RepayCreditAccountPreview {
391
524
  * account: what the transaction does in the same block, before any delayed
392
525
  * withdrawal is claimed.
393
526
  */
394
- type InstantOperationPreview = AdjustCreditAccountPreview | CloseCreditAccountPreview | RepayCreditAccountPreview;
527
+ type PreviewInstantStrategyVerify = PreviewAdjustStrategyVerify | PreviewExitStrategyVerify | PreviewRepayStrategyVerify;
395
528
  /**
396
529
  * Preview of a multicall that requests a delayed withdrawal (e.g. Securitize
397
530
  * redemption): the source token is spent now and a withdrawal phantom token is received;
398
531
  * the actual claim token materializes later, when the withdrawal is claimed and
399
532
  * the recorded (if any) is resumed
400
533
  */
401
- interface DelayedCreditAccountOperationPreview {
534
+ interface PreviewDelayedStrategyVerify extends CreditOperationMarket {
402
535
  operation: "DelayedCreditAccountOperation";
403
536
  /**
404
537
  * Credit account the operation is performed on
405
538
  */
406
539
  creditAccount: Address;
407
- /**
408
- * Credit manager the account belongs to
409
- */
410
- creditManager: Address;
411
- /**
412
- * Human-readable credit manager name
413
- */
414
- name: string;
415
540
  /**
416
541
  * Decoded from the withdrawal request's extraData; undefined when the
417
542
  * request carries no intent (e.g. Mellow)
@@ -421,19 +546,19 @@ interface DelayedCreditAccountOperationPreview {
421
546
  * What this transaction does right now: the delayed withdrawal is
422
547
  * represented by the phantom token among the account's assets
423
548
  */
424
- instantPreview: InstantOperationPreview;
549
+ instantPreview: PreviewInstantStrategyVerify;
425
550
  /**
426
551
  * Best-effort state after the withdrawal is claimed and the intent is
427
552
  * resumed; claim-only (phantom burned, claim token received) when
428
553
  * `intent` is undefined
429
554
  */
430
- delayedPreview: InstantOperationPreview;
555
+ delayedPreview: PreviewInstantStrategyVerify;
431
556
  }
432
557
  /**
433
558
  * Result of previewing a raw operation calldata: currently pool operations and
434
559
  * credit account opening, adjustment, closure, repayment and delayed
435
560
  * withdrawal operations are supported.
436
561
  */
437
- type OperationPreview = PoolOperationPreview | OpenCreditAccountPreview | AdjustCreditAccountPreview | CloseCreditAccountPreview | RepayCreditAccountPreview | DelayedCreditAccountOperationPreview;
562
+ type OperationPreview = PreviewLpVerify | PreviewOpenStrategyVerify | PreviewAdjustStrategyVerify | PreviewExitStrategyVerify | PreviewRepayStrategyVerify | PreviewDelayedStrategyVerify;
438
563
  //#endregion
439
- export { AccountProjection, AdjustCreditAccountPreview, CloseCreditAccountPreview, DelayedCreditAccountOperationPreview, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, InstantOperationPreview, OpenCreditAccountPreview, OperationPreview, OperationPreviewError, PoolOperationPreview, PoolOperationType, PreviewOperationInput, PreviewOperationOptions, RepayCreditAccountPreview };
564
+ export { AccountHoldings, AccountMetrics, AccountProjection, AccountStateChange, CreditOperationMarket, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, Estimated, EstimatedProjection, OperationPreview, OperationPreviewError, PoolOperationType, PreviewAdjustStrategyVerify, PreviewDelayedStrategyVerify, PreviewExitStrategyVerify, PreviewInstantStrategyVerify, PreviewLpVerify, PreviewOpenStrategyVerify, PreviewOperationInput, PreviewOperationOptions, PreviewRepayStrategyVerify, RoutedField, asEstimated };
@@ -1,4 +1,4 @@
1
- import { Bps, TokenAmount } from "../../../model/primitives.js";
1
+ import { TokenAmount } from "../../../model/primitives.js";
2
2
  import { AccountProjection } from "../../../model/previews.js";
3
3
  import "../../../model/index.js";
4
4
  import { Asset } from "../../base/types.js";
@@ -33,14 +33,20 @@ interface OpenStrategyProps {
33
33
  * both `minQuota` and `averageQuota`, so there is nothing to gain by dropping one.
34
34
  */
35
35
  interface OpenStrategyPreview extends Omit<AccountProjection, "assets" | "quotas"> {
36
- /**
37
- * The same factor with collateral valued at safe prices, which is what the
38
- * credit manager weighs an opening at on-chain. Always reported here: an
39
- * opening always hands the pool's funds over.
40
- **/
41
- safeHealthFactor: Bps;
42
36
  /** What the routed leg lost to market depth; `undefined` if not measured. */
43
37
  priceImpact: PathLossRate | undefined;
38
+ /**
39
+ * What the position's collateral costs in the market underlying right now, in
40
+ * the oracle's 8-decimal fixed point — the same scale and the same pair as
41
+ * {@link liquidationPrice}, so a screen showing both reads them as one pair.
42
+ *
43
+ * `null` where there is no pair to quote: an account holding zero or several
44
+ * non-underlying assets, or one whose collateral the oracle cannot price.
45
+ *
46
+ * Simulations only. A calldata preview is not asked for it: it reports what a
47
+ * transaction does, not what the market costs while a form is open.
48
+ */
49
+ currentPrice: bigint | null;
44
50
  /** Expected post-open balances. */
45
51
  averageAssets: TokenAmount[];
46
52
  /** Floor post-open balances after slippage. */
@@ -74,6 +74,7 @@ interface MarketSdkExtras {
74
74
  forbiddenTokens?: Address[];
75
75
  /** What a routed swap returns; linear when omitted. */
76
76
  routeQuote?: (amount: bigint) => bigint;
77
+ routeFloor?: (amount: bigint) => bigint;
77
78
  }
78
79
  /** Mock SDK on the shared fixture market. */
79
80
  declare function buildMarketSdk(extras?: MarketSdkExtras): OnchainSDK;
@@ -13,6 +13,17 @@ import { Address } from "viem";
13
13
  * from their inputs, so `result.calls` pins down which ops reached the
14
14
  * assembler and in which order.
15
15
  */
16
+ /** Market configurator the mock market is governed by — the curator's address. */
17
+ declare const MOCK_MARKET_CONFIGURATOR: Address;
18
+ /**
19
+ * Liquidation fees of the mock suite: a 3% premium (the manager reports its
20
+ * complement) on top of a 1.5% protocol fee, so the discount a screen shows is
21
+ * 450bps.
22
+ */
23
+ declare const MOCK_LIQUIDATION_FEES: {
24
+ feeLiquidation: number;
25
+ liquidationDiscount: number;
26
+ };
16
27
  /** Recognizable router call embedded in routed leg results. */
17
28
  declare const MOCK_ROUTER_CALL: MultiCall;
18
29
  /** Router call of the many-to-one leg an exit routes. */
@@ -121,6 +132,13 @@ interface BuildMockSdkArgs {
121
132
  * same proportion.
122
133
  */
123
134
  routeQuote?: (amount: bigint) => bigint;
135
+ /**
136
+ * The floor a route guarantees, from what it expects to return. The default
137
+ * quotes no slippage at all — floor and expectation coincide — which is what
138
+ * every case that is not about the difference between the two wants, since it
139
+ * keeps the projected state and the amounts in the calls one number.
140
+ */
141
+ routeFloor?: (amount: bigint) => bigint;
124
142
  }
125
143
  /** One redemption venue of the mock compressor. */
126
144
  interface MockDelayedVenue {
@@ -41,6 +41,18 @@ interface OperationState extends AccountProjection {
41
41
  * routed or nothing could be measured — never a manufactured zero.
42
42
  */
43
43
  priceImpact: PathLossRate | undefined;
44
+ /**
45
+ * What the position's collateral costs in the market underlying right now, in
46
+ * the oracle's 8-decimal fixed point — the same scale and the same pair as
47
+ * {@link liquidationPrice}, so a screen showing both reads them as one pair.
48
+ *
49
+ * `null` where there is no pair to quote: an account holding zero or several
50
+ * non-underlying assets, or one whose collateral the oracle cannot price.
51
+ *
52
+ * Simulations only. A calldata preview is not asked for it: it reports what a
53
+ * transaction does, not what the market costs while a form is open.
54
+ */
55
+ currentPrice: bigint | null;
44
56
  }
45
57
  /**
46
58
  * What a preview yields: the operation chain, the state it projects, and the