@morpho-org/midnight-sdk 1.6.0 → 1.7.0-next.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 (43) hide show
  1. package/lib/cjs/api/MidnightApi.d.ts +16 -14
  2. package/lib/cjs/api/MidnightApi.js +26 -16
  3. package/lib/cjs/api/helpers.d.ts +14 -2
  4. package/lib/cjs/api/helpers.js +71 -11
  5. package/lib/cjs/api/index.d.ts +1 -1
  6. package/lib/cjs/api/index.js +2 -1
  7. package/lib/cjs/api/types.d.ts +1 -1
  8. package/lib/cjs/api/version.generated.d.ts +1 -1
  9. package/lib/cjs/api/version.generated.js +1 -1
  10. package/lib/cjs/errors.d.ts +13 -0
  11. package/lib/cjs/errors.js +18 -1
  12. package/lib/cjs/market/Market.d.ts +6 -30
  13. package/lib/cjs/market/Market.js +7 -31
  14. package/lib/cjs/market/MarketUtils.d.ts +14 -0
  15. package/lib/cjs/market/MarketUtils.js +17 -1
  16. package/lib/cjs/offers/Offer.d.ts +1 -1
  17. package/lib/cjs/offers/Offer.js +1 -1
  18. package/lib/cjs/offers/OfferChainUtils.d.ts +6 -2
  19. package/lib/cjs/offers/OfferChainUtils.js +6 -2
  20. package/lib/cjs/position/Position.d.ts +5 -25
  21. package/lib/cjs/position/Position.js +5 -25
  22. package/lib/esm/api/MidnightApi.d.ts +16 -14
  23. package/lib/esm/api/MidnightApi.js +28 -18
  24. package/lib/esm/api/helpers.d.ts +14 -2
  25. package/lib/esm/api/helpers.js +71 -12
  26. package/lib/esm/api/index.d.ts +1 -1
  27. package/lib/esm/api/index.js +1 -1
  28. package/lib/esm/api/types.d.ts +1 -1
  29. package/lib/esm/api/version.generated.d.ts +1 -1
  30. package/lib/esm/api/version.generated.js +1 -1
  31. package/lib/esm/errors.d.ts +13 -0
  32. package/lib/esm/errors.js +16 -0
  33. package/lib/esm/market/Market.d.ts +6 -30
  34. package/lib/esm/market/Market.js +7 -31
  35. package/lib/esm/market/MarketUtils.d.ts +14 -0
  36. package/lib/esm/market/MarketUtils.js +18 -2
  37. package/lib/esm/offers/Offer.d.ts +1 -1
  38. package/lib/esm/offers/Offer.js +1 -1
  39. package/lib/esm/offers/OfferChainUtils.d.ts +6 -2
  40. package/lib/esm/offers/OfferChainUtils.js +6 -2
  41. package/lib/esm/position/Position.d.ts +5 -25
  42. package/lib/esm/position/Position.js +5 -25
  43. package/package.json +3 -6
@@ -135,7 +135,7 @@ class MarketParams {
135
135
  }
136
136
  seenCollateralTokens.add(token);
137
137
  }
138
- this.collateralParams = collateralParams.sort((a, b) => a.token.toLowerCase() < b.token.toLowerCase() ? -1 : 1);
138
+ this.collateralParams = collateralParams.sort(MarketUtils_js_1.MarketUtils.compareCollateralTokens);
139
139
  this.maturity = BigInt(params.maturity);
140
140
  this.rcfThreshold = BigInt(params.rcfThreshold);
141
141
  this.enterGate = params.enterGate;
@@ -191,11 +191,7 @@ exports.MarketParams = MarketParams;
191
191
  * registerCustomAddresses({
192
192
  * addresses: {
193
193
  * 31337: {
194
- * morpho: "0x0000000000000000000000000000000000000001",
195
- * bundler3: {
196
- * bundler3: "0x0000000000000000000000000000000000000002",
197
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
198
- * },
194
+ * blue: "0x0000000000000000000000000000000000000001",
199
195
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
200
196
  * midnight: "0x0000000000000000000000000000000000001000",
201
197
  * },
@@ -324,11 +320,7 @@ class Market {
324
320
  * registerCustomAddresses({
325
321
  * addresses: {
326
322
  * 31337: {
327
- * morpho: "0x0000000000000000000000000000000000000001",
328
- * bundler3: {
329
- * bundler3: "0x0000000000000000000000000000000000000002",
330
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
331
- * },
323
+ * blue: "0x0000000000000000000000000000000000000001",
332
324
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
333
325
  * midnight: "0x0000000000000000000000000000000000001000",
334
326
  * },
@@ -385,11 +377,7 @@ class Market {
385
377
  * registerCustomAddresses({
386
378
  * addresses: {
387
379
  * 31337: {
388
- * morpho: "0x0000000000000000000000000000000000000001",
389
- * bundler3: {
390
- * bundler3: "0x0000000000000000000000000000000000000002",
391
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
392
- * },
380
+ * blue: "0x0000000000000000000000000000000000000001",
393
381
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
394
382
  * midnight: "0x0000000000000000000000000000000000001000",
395
383
  * },
@@ -445,11 +433,7 @@ class Market {
445
433
  * registerCustomAddresses({
446
434
  * addresses: {
447
435
  * 31337: {
448
- * morpho: "0x0000000000000000000000000000000000000001",
449
- * bundler3: {
450
- * bundler3: "0x0000000000000000000000000000000000000002",
451
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
452
- * },
436
+ * blue: "0x0000000000000000000000000000000000000001",
453
437
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
454
438
  * midnight: "0x0000000000000000000000000000000000001000",
455
439
  * },
@@ -502,11 +486,7 @@ class Market {
502
486
  * registerCustomAddresses({
503
487
  * addresses: {
504
488
  * 31337: {
505
- * morpho: "0x0000000000000000000000000000000000000001",
506
- * bundler3: {
507
- * bundler3: "0x0000000000000000000000000000000000000002",
508
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
509
- * },
489
+ * blue: "0x0000000000000000000000000000000000000001",
510
490
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
511
491
  * midnight: "0x0000000000000000000000000000000000001000",
512
492
  * },
@@ -562,11 +542,7 @@ class Market {
562
542
  * registerCustomAddresses({
563
543
  * addresses: {
564
544
  * 31337: {
565
- * morpho: "0x0000000000000000000000000000000000000001",
566
- * bundler3: {
567
- * bundler3: "0x0000000000000000000000000000000000000002",
568
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
569
- * },
545
+ * blue: "0x0000000000000000000000000000000000000001",
570
546
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
571
547
  * midnight: "0x0000000000000000000000000000000000001000",
572
548
  * },
@@ -1,4 +1,5 @@
1
1
  import { type BigIntish } from "@morpho-org/morpho-ts";
2
+ import { type Address } from "viem";
2
3
  import { type CollateralParams, type ICollateralParams, type MarketInput, MarketParams, type SettlementFeeCbps } from "./Market.js";
3
4
  type CollateralParamsInput = ICollateralParams | CollateralParams;
4
5
  /**
@@ -12,6 +13,19 @@ type CollateralParamsInput = ICollateralParams | CollateralParams;
12
13
  * ```
13
14
  */
14
15
  export declare namespace MarketUtils {
16
+ /**
17
+ * @internal Orders collaterals by token address, case-insensitively, matching the protocol's
18
+ * canonical `collateralIndex` order used by `MarketParams` and `MarketUtils.hash`.
19
+ *
20
+ * @param a - First collateral.
21
+ * @param b - Second collateral.
22
+ * @returns Negative when `a` sorts before `b`, positive when after, `0` when tokens are equal.
23
+ */
24
+ function compareCollateralTokens(a: {
25
+ readonly token: Address;
26
+ }, b: {
27
+ readonly token: Address;
28
+ }): -1 | 0 | 1;
15
29
  /**
16
30
  * Converts collateral params from a plain input or ABI tuple.
17
31
  *
@@ -59,6 +59,22 @@ const marketParamsAbiParameter = {
59
59
  */
60
60
  var MarketUtils;
61
61
  (function (MarketUtils) {
62
+ /**
63
+ * @internal Orders collaterals by token address, case-insensitively, matching the protocol's
64
+ * canonical `collateralIndex` order used by `MarketParams` and `MarketUtils.hash`.
65
+ *
66
+ * @param a - First collateral.
67
+ * @param b - Second collateral.
68
+ * @returns Negative when `a` sorts before `b`, positive when after, `0` when tokens are equal.
69
+ */
70
+ function compareCollateralTokens(a, b) {
71
+ const tokenA = a.token.toLowerCase();
72
+ const tokenB = b.token.toLowerCase();
73
+ if (tokenA === tokenB)
74
+ return 0;
75
+ return tokenA < tokenB ? -1 : 1;
76
+ }
77
+ MarketUtils.compareCollateralTokens = compareCollateralTokens;
62
78
  /**
63
79
  * Converts collateral params from a plain input or ABI tuple.
64
80
  *
@@ -302,7 +318,7 @@ var MarketUtils;
302
318
  const marketParams = "params" in market ? market.params : market;
303
319
  const collateralParams = marketParams.collateralParams.length === 0
304
320
  ? marketParams.collateralParams
305
- : [...marketParams.collateralParams].sort((a, b) => a.token.toLowerCase() < b.token.toLowerCase() ? -1 : 1);
321
+ : [...marketParams.collateralParams].sort(compareCollateralTokens);
306
322
  const collateralParamHashes = collateralParams.map((params) => (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)(collateralParamsHashParams, [
307
323
  constants_js_1.COLLATERAL_PARAMS_TYPEHASH,
308
324
  params.token,
@@ -526,7 +526,7 @@ export declare class Offer {
526
526
  * @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
527
527
  * @param params.maxUnits - Optional unit cap; defaults to zero.
528
528
  * @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
529
- * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `MAX_CONTINUOUS_FEE`.
529
+ * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `0n` (fail-closed: no market continuous fee accepted unless set explicitly).
530
530
  * @param params.start - Optional offer start timestamp; defaults to zero.
531
531
  * @param params.expiry - Offer expiry timestamp.
532
532
  * @param params.callback - Optional callback address; defaults to the zero address.
@@ -479,7 +479,7 @@ class Offer {
479
479
  * @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
480
480
  * @param params.maxUnits - Optional unit cap; defaults to zero.
481
481
  * @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
482
- * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `MAX_CONTINUOUS_FEE`.
482
+ * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `0n` (fail-closed: no market continuous fee accepted unless set explicitly).
483
483
  * @param params.start - Optional offer start timestamp; defaults to zero.
484
484
  * @param params.expiry - Offer expiry timestamp.
485
485
  * @param params.callback - Optional callback address; defaults to the zero address.
@@ -67,7 +67,8 @@ export declare namespace OfferChainUtils {
67
67
  * Use before a make-borrow or supply-collateral-and-make-borrow flow when a
68
68
  * borrower wants one displayed fixed borrow rate across a longer window. Map
69
69
  * the returned legs to `Offer.create({ buy: false, ... })`, then group and
70
- * submit them through the maker flow.
70
+ * submit them through the maker flow. Pass the same market tick spacing to
71
+ * `Offer.create` so leg validation uses the chain's grid.
71
72
  *
72
73
  * Borrow chains read their target rate at each leg's expiry edge. If a leg
73
74
  * would need to extend past `chainEndTimestamp`, it is dropped rather than
@@ -97,6 +98,7 @@ export declare namespace OfferChainUtils {
97
98
  * ...baseOffer,
98
99
  * buy: false,
99
100
  * tick: leg.tick,
101
+ * tickSpacing: market.tickSpacing,
100
102
  * start: leg.startTimestamp,
101
103
  * expiry: leg.expiryTimestamp,
102
104
  * }),
@@ -110,7 +112,8 @@ export declare namespace OfferChainUtils {
110
112
  * Use before a make-lend flow when a lender wants one displayed fixed lend
111
113
  * rate across a longer window. Map the returned legs to
112
114
  * `Offer.create({ buy: true, ... })`, then group and submit them through the
113
- * maker flow.
115
+ * maker flow. Pass the same market tick spacing to `Offer.create` so leg
116
+ * validation uses the chain's grid.
114
117
  *
115
118
  * Lend chains read their target rate at each leg's start edge. The first leg
116
119
  * may start before `chainStartTimestamp`; clamping that edge would move the
@@ -140,6 +143,7 @@ export declare namespace OfferChainUtils {
140
143
  * ...baseOffer,
141
144
  * buy: true,
142
145
  * tick: leg.tick,
146
+ * tickSpacing: market.tickSpacing,
143
147
  * start: leg.startTimestamp,
144
148
  * expiry: leg.expiryTimestamp,
145
149
  * }),
@@ -58,7 +58,8 @@ var OfferChainUtils;
58
58
  * Use before a make-borrow or supply-collateral-and-make-borrow flow when a
59
59
  * borrower wants one displayed fixed borrow rate across a longer window. Map
60
60
  * the returned legs to `Offer.create({ buy: false, ... })`, then group and
61
- * submit them through the maker flow.
61
+ * submit them through the maker flow. Pass the same market tick spacing to
62
+ * `Offer.create` so leg validation uses the chain's grid.
62
63
  *
63
64
  * Borrow chains read their target rate at each leg's expiry edge. If a leg
64
65
  * would need to extend past `chainEndTimestamp`, it is dropped rather than
@@ -88,6 +89,7 @@ var OfferChainUtils;
88
89
  * ...baseOffer,
89
90
  * buy: false,
90
91
  * tick: leg.tick,
92
+ * tickSpacing: market.tickSpacing,
91
93
  * start: leg.startTimestamp,
92
94
  * expiry: leg.expiryTimestamp,
93
95
  * }),
@@ -204,7 +206,8 @@ var OfferChainUtils;
204
206
  * Use before a make-lend flow when a lender wants one displayed fixed lend
205
207
  * rate across a longer window. Map the returned legs to
206
208
  * `Offer.create({ buy: true, ... })`, then group and submit them through the
207
- * maker flow.
209
+ * maker flow. Pass the same market tick spacing to `Offer.create` so leg
210
+ * validation uses the chain's grid.
208
211
  *
209
212
  * Lend chains read their target rate at each leg's start edge. The first leg
210
213
  * may start before `chainStartTimestamp`; clamping that edge would move the
@@ -234,6 +237,7 @@ var OfferChainUtils;
234
237
  * ...baseOffer,
235
238
  * buy: true,
236
239
  * tick: leg.tick,
240
+ * tickSpacing: market.tickSpacing,
237
241
  * start: leg.startTimestamp,
238
242
  * expiry: leg.expiryTimestamp,
239
243
  * }),
@@ -120,11 +120,7 @@ export interface IAccrualPosition extends Omit<IPosition, "marketId"> {
120
120
  * registerCustomAddresses({
121
121
  * addresses: {
122
122
  * 31337: {
123
- * morpho: "0x0000000000000000000000000000000000000001",
124
- * bundler3: {
125
- * bundler3: "0x0000000000000000000000000000000000000002",
126
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
127
- * },
123
+ * blue: "0x0000000000000000000000000000000000000001",
128
124
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
129
125
  * midnight: "0x0000000000000000000000000000000000001000",
130
126
  * },
@@ -244,11 +240,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
244
240
  * registerCustomAddresses({
245
241
  * addresses: {
246
242
  * 31337: {
247
- * morpho: "0x0000000000000000000000000000000000000001",
248
- * bundler3: {
249
- * bundler3: "0x0000000000000000000000000000000000000002",
250
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
251
- * },
243
+ * blue: "0x0000000000000000000000000000000000000001",
252
244
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
253
245
  * midnight: "0x0000000000000000000000000000000000001000",
254
246
  * },
@@ -311,11 +303,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
311
303
  * registerCustomAddresses({
312
304
  * addresses: {
313
305
  * 31337: {
314
- * morpho: "0x0000000000000000000000000000000000000001",
315
- * bundler3: {
316
- * bundler3: "0x0000000000000000000000000000000000000002",
317
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
318
- * },
306
+ * blue: "0x0000000000000000000000000000000000000001",
319
307
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
320
308
  * midnight: "0x0000000000000000000000000000000000001000",
321
309
  * },
@@ -379,11 +367,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
379
367
  * registerCustomAddresses({
380
368
  * addresses: {
381
369
  * 31337: {
382
- * morpho: "0x0000000000000000000000000000000000000001",
383
- * bundler3: {
384
- * bundler3: "0x0000000000000000000000000000000000000002",
385
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
386
- * },
370
+ * blue: "0x0000000000000000000000000000000000000001",
387
371
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
388
372
  * midnight: "0x0000000000000000000000000000000000001000",
389
373
  * },
@@ -449,11 +433,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
449
433
  * registerCustomAddresses({
450
434
  * addresses: {
451
435
  * 31337: {
452
- * morpho: "0x0000000000000000000000000000000000000001",
453
- * bundler3: {
454
- * bundler3: "0x0000000000000000000000000000000000000002",
455
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
456
- * },
436
+ * blue: "0x0000000000000000000000000000000000000001",
457
437
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
458
438
  * midnight: "0x0000000000000000000000000000000000001000",
459
439
  * },
@@ -94,11 +94,7 @@ exports.Position = Position;
94
94
  * registerCustomAddresses({
95
95
  * addresses: {
96
96
  * 31337: {
97
- * morpho: "0x0000000000000000000000000000000000000001",
98
- * bundler3: {
99
- * bundler3: "0x0000000000000000000000000000000000000002",
100
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
101
- * },
97
+ * blue: "0x0000000000000000000000000000000000000001",
102
98
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
103
99
  * midnight: "0x0000000000000000000000000000000000001000",
104
100
  * },
@@ -229,11 +225,7 @@ class AccrualPosition extends Position {
229
225
  * registerCustomAddresses({
230
226
  * addresses: {
231
227
  * 31337: {
232
- * morpho: "0x0000000000000000000000000000000000000001",
233
- * bundler3: {
234
- * bundler3: "0x0000000000000000000000000000000000000002",
235
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
236
- * },
228
+ * blue: "0x0000000000000000000000000000000000000001",
237
229
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
238
230
  * midnight: "0x0000000000000000000000000000000000001000",
239
231
  * },
@@ -301,11 +293,7 @@ class AccrualPosition extends Position {
301
293
  * registerCustomAddresses({
302
294
  * addresses: {
303
295
  * 31337: {
304
- * morpho: "0x0000000000000000000000000000000000000001",
305
- * bundler3: {
306
- * bundler3: "0x0000000000000000000000000000000000000002",
307
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
308
- * },
296
+ * blue: "0x0000000000000000000000000000000000000001",
309
297
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
310
298
  * midnight: "0x0000000000000000000000000000000000001000",
311
299
  * },
@@ -372,11 +360,7 @@ class AccrualPosition extends Position {
372
360
  * registerCustomAddresses({
373
361
  * addresses: {
374
362
  * 31337: {
375
- * morpho: "0x0000000000000000000000000000000000000001",
376
- * bundler3: {
377
- * bundler3: "0x0000000000000000000000000000000000000002",
378
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
379
- * },
363
+ * blue: "0x0000000000000000000000000000000000000001",
380
364
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
381
365
  * midnight: "0x0000000000000000000000000000000000001000",
382
366
  * },
@@ -444,11 +428,7 @@ class AccrualPosition extends Position {
444
428
  * registerCustomAddresses({
445
429
  * addresses: {
446
430
  * 31337: {
447
- * morpho: "0x0000000000000000000000000000000000000001",
448
- * bundler3: {
449
- * bundler3: "0x0000000000000000000000000000000000000002",
450
- * generalAdapter1: "0x0000000000000000000000000000000000000003",
451
- * },
431
+ * blue: "0x0000000000000000000000000000000000000001",
452
432
  * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
453
433
  * midnight: "0x0000000000000000000000000000000000001000",
454
434
  * },
@@ -65,9 +65,9 @@ export declare class MidnightApi {
65
65
  * @param params.baseUrl - Optional Midnight API base URL override.
66
66
  * @param params.fetch - Optional fetch implementation override.
67
67
  * @param params.request - Optional fetch options forwarded to this request.
68
- * @returns Paginated books mapped to SDK camelCase fields.
68
+ * @returns Paginated books mapped to SDK camelCase fields, with each book's price levels sorted best first (asks ascending tick, bids descending tick).
69
69
  * @throws {MidnightApiError} when the API returns a non-2xx response.
70
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned book's `market_id` does not match, or cannot be derived from, its own market params, or when a returned book falls outside the supplied `marketIds` filter.
70
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned book's `market_id` does not match, or cannot be derived from, its own market params, or when a returned book falls outside the supplied `marketIds`, `chainIds`, `loanTokens`, `collateralTokens`, or `maturities` filters.
71
71
  * @example
72
72
  * ```ts
73
73
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -90,7 +90,7 @@ export declare class MidnightApi {
90
90
  * @param params.baseUrl - Optional Midnight API base URL override.
91
91
  * @param params.fetch - Optional fetch implementation override.
92
92
  * @param params.request - Optional fetch options forwarded to this request.
93
- * @returns Book snapshot mapped to SDK camelCase fields.
93
+ * @returns Book snapshot mapped to SDK camelCase fields, with price levels sorted best first (asks ascending tick, bids descending tick).
94
94
  * @throws {MidnightApiError} when the API returns a non-2xx response.
95
95
  * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when the returned book's `market_id` does not match, or cannot be derived from, its own market params, or when it differs from the requested `marketId`.
96
96
  * @example
@@ -115,7 +115,7 @@ export declare class MidnightApi {
115
115
  * @param params.baseUrl - Optional Midnight API base URL override.
116
116
  * @param params.fetch - Optional fetch implementation override.
117
117
  * @param params.request - Optional fetch options forwarded to this request.
118
- * @returns Price levels mapped to SDK camelCase fields.
118
+ * @returns Price levels mapped to SDK camelCase fields, sorted best first (asks ascending tick, bids descending tick).
119
119
  * @throws {MidnightApiError} when the API returns a non-2xx response.
120
120
  * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
121
121
  * @example
@@ -142,7 +142,7 @@ export declare class MidnightApi {
142
142
  * @param params.request - Optional fetch options forwarded to this request.
143
143
  * @returns ABI-ready take objects mapped from the API response.
144
144
  * @throws {MidnightApiError} when the API returns a non-2xx response.
145
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
145
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, or when its caps or buy-side receiver are not executable.
146
146
  * @example
147
147
  * ```ts
148
148
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -171,9 +171,10 @@ export declare class MidnightApi {
171
171
  * @param params.fetch - Optional fetch implementation override.
172
172
  * @param params.request - Optional fetch options forwarded to this request.
173
173
  * @returns Quote and signed ABI-ready take caps mapped from the API response.
174
+ * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
174
175
  * @throws {NegativeValueError} when `settlementFee` is negative.
175
176
  * @throws {MidnightApiError} when the API returns a non-2xx response.
176
- * @throws {InvalidMidnightApiResponseError} when the API returns a malformed success response or the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
177
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
177
178
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
178
179
  * @example
179
180
  * ```ts
@@ -204,7 +205,7 @@ export declare class MidnightApi {
204
205
  * @param params.request - Optional fetch options forwarded to this request.
205
206
  * @returns Paginated ABI-ready take objects mapped from the API response.
206
207
  * @throws {MidnightApiError} when the API returns a non-2xx response.
207
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
208
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, or when its caps or buy-side receiver are not executable.
208
209
  * @example
209
210
  * ```ts
210
211
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -321,9 +322,9 @@ export declare class MidnightApi {
321
322
  * @param params.marketIds - Optional market id filters.
322
323
  * @param params.limit - Optional maximum number of books to return.
323
324
  * @param params.cursor - Optional opaque pagination cursor from a previous response.
324
- * @returns Paginated books mapped to SDK camelCase fields.
325
+ * @returns Paginated books mapped to SDK camelCase fields, with each book's price levels sorted best first (asks ascending tick, bids descending tick).
325
326
  * @throws {MidnightApiError} when the API returns a non-2xx response.
326
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned book's `market_id` does not match, or cannot be derived from, its own market params, or when a returned book falls outside the supplied `marketIds` filter.
327
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned book's `market_id` does not match, or cannot be derived from, its own market params, or when a returned book falls outside the supplied `marketIds`, `chainIds`, `loanTokens`, `collateralTokens`, or `maturities` filters.
327
328
  * @example
328
329
  * ```ts
329
330
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -341,7 +342,7 @@ export declare class MidnightApi {
341
342
  *
342
343
  * @param params.marketId - Market id whose book to read.
343
344
  * @param params.depth - Optional maximum levels returned per side.
344
- * @returns Book snapshot mapped to SDK camelCase fields.
345
+ * @returns Book snapshot mapped to SDK camelCase fields, with price levels sorted best first (asks ascending tick, bids descending tick).
345
346
  * @throws {MidnightApiError} when the API returns a non-2xx response.
346
347
  * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when the returned book's `market_id` does not match, or cannot be derived from, its own market params, or when it differs from the requested `marketId`.
347
348
  * @example
@@ -364,7 +365,7 @@ export declare class MidnightApi {
364
365
  * @param params.marketId - Market id whose book side to read.
365
366
  * @param params.side - Book side to query.
366
367
  * @param params.depth - Optional maximum levels returned.
367
- * @returns Price levels mapped to SDK camelCase fields.
368
+ * @returns Price levels mapped to SDK camelCase fields, sorted best first (asks ascending tick, bids descending tick).
368
369
  * @throws {MidnightApiError} when the API returns a non-2xx response.
369
370
  * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
370
371
  * @example
@@ -389,7 +390,7 @@ export declare class MidnightApi {
389
390
  * @param params.side - Book side to query.
390
391
  * @returns ABI-ready take objects mapped from the API response.
391
392
  * @throws {MidnightApiError} when the API returns a non-2xx response.
392
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
393
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, or when its caps or buy-side receiver are not executable.
393
394
  * @example
394
395
  * ```ts
395
396
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -416,9 +417,10 @@ export declare class MidnightApi {
416
417
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
417
418
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
418
419
  * @returns Quote and signed ABI-ready take caps mapped from the API response.
420
+ * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
419
421
  * @throws {NegativeValueError} when `settlementFee` is negative.
420
422
  * @throws {MidnightApiError} when the API returns a non-2xx response.
421
- * @throws {InvalidMidnightApiResponseError} when the API returns a malformed success response or the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
423
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
422
424
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
423
425
  * @example
424
426
  * ```ts
@@ -446,7 +448,7 @@ export declare class MidnightApi {
446
448
  * @param params.cursor - Optional opaque pagination cursor from a previous response.
447
449
  * @returns Paginated ABI-ready take objects mapped from the API response.
448
450
  * @throws {MidnightApiError} when the API returns a non-2xx response.
449
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
451
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, or when its caps or buy-side receiver are not executable.
450
452
  * @example
451
453
  * ```ts
452
454
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";