@morpho-dev/router 0.2.1 → 0.4.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 (44) hide show
  1. package/README.md +67 -71
  2. package/dist/cli.js +4224 -1627
  3. package/dist/drizzle/migrations/0015_add-lots-table.sql +12 -0
  4. package/dist/drizzle/migrations/0016_merkle-metadata.sql +26 -0
  5. package/dist/drizzle/migrations/0017_dusty_the_hunter.sql +1 -0
  6. package/dist/drizzle/migrations/0018_add_chain_collector_constraints.sql +3 -0
  7. package/dist/drizzle/migrations/0019_add-obligation-units-shares.sql +2 -0
  8. package/dist/drizzle/migrations/0020_add-session.sql +1 -0
  9. package/dist/drizzle/migrations/0021_drop_chain_collector_epoch_indexes.sql +2 -0
  10. package/dist/drizzle/migrations/0021_migrate-rate-to-price.sql +15 -0
  11. package/dist/drizzle/migrations/0022_consolidate-price.sql +15 -0
  12. package/dist/drizzle/migrations/meta/0015_snapshot.json +1365 -0
  13. package/dist/drizzle/migrations/meta/0016_snapshot.json +1531 -0
  14. package/dist/drizzle/migrations/meta/0017_snapshot.json +1525 -0
  15. package/dist/drizzle/migrations/meta/0018_snapshot.json +1572 -0
  16. package/dist/drizzle/migrations/meta/0019_snapshot.json +1586 -0
  17. package/dist/drizzle/migrations/meta/_journal.json +56 -0
  18. package/dist/evm/bytecode/erc20.txt +1 -0
  19. package/dist/evm/bytecode/factory.txt +1 -0
  20. package/dist/evm/bytecode/mempool.txt +1 -0
  21. package/dist/evm/bytecode/morpho.txt +1 -0
  22. package/dist/evm/bytecode/multicall3.txt +1 -0
  23. package/dist/evm/bytecode/oracle.txt +1 -0
  24. package/dist/evm/bytecode/terms.txt +1 -0
  25. package/dist/evm/bytecode/vault.txt +1 -0
  26. package/dist/evm/bytecode/vaultV1.txt +1 -0
  27. package/dist/index.browser.d.mts +1376 -651
  28. package/dist/index.browser.d.mts.map +1 -1
  29. package/dist/index.browser.d.ts +1375 -654
  30. package/dist/index.browser.d.ts.map +1 -1
  31. package/dist/index.browser.js +2398 -1526
  32. package/dist/index.browser.js.map +1 -1
  33. package/dist/index.browser.mjs +2394 -1522
  34. package/dist/index.browser.mjs.map +1 -1
  35. package/dist/index.node.d.mts +2372 -1039
  36. package/dist/index.node.d.mts.map +1 -1
  37. package/dist/index.node.d.ts +2372 -1039
  38. package/dist/index.node.d.ts.map +1 -1
  39. package/dist/index.node.js +3094 -1399
  40. package/dist/index.node.js.map +1 -1
  41. package/dist/index.node.mjs +3075 -1399
  42. package/dist/index.node.mjs.map +1 -1
  43. package/docs/integrator.md +78 -0
  44. package/package.json +11 -6
@@ -1,23 +1,27 @@
1
1
  import { z } from "zod/v4";
2
2
  import { AbiEvent, Address, ChainContract, ChainFormatters, GetLogsReturnType, Hex, MulticallParameters, PublicClient, Transport, WalletClient } from "viem";
3
+ import { Chain } from "viem/chains";
4
+ import * as z$1 from "zod";
5
+ import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
3
6
  import "reflect-metadata";
4
7
  import { OpenAPIDocument } from "openapi-metadata";
5
- import * as z$1 from "zod";
6
8
  import { Client } from "openapi-fetch";
7
- import { Chain } from "viem/chains";
8
- import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
9
+ import "@electric-sql/pglite";
10
+ import "drizzle-orm/node-postgres";
11
+ import "drizzle-orm/pglite";
12
+ import "pg";
9
13
 
10
14
  //#region src/api/Schema/BookResponse.d.ts
11
15
  declare namespace BookResponse_d_exports {
12
- export { BookLevelResponse, from$13 as from };
16
+ export { BookLevelResponse, from$14 as from };
13
17
  }
14
18
  type BookLevelResponse = {
15
- rate: string;
19
+ price: string;
16
20
  assets: string;
17
21
  count: number;
18
22
  };
19
- declare function from$13(level: {
20
- rate: bigint;
23
+ declare function from$14(level: {
24
+ price: bigint;
21
25
  assets: bigint;
22
26
  count: number;
23
27
  }): BookLevelResponse;
@@ -30,10 +34,11 @@ declare const CollectorHealth: z.ZodObject<{
30
34
  updated_at: z.ZodNullable<z.ZodString>;
31
35
  lag: z.ZodNullable<z.ZodNumber>;
32
36
  status: z.ZodEnum<{
37
+ unknown: "unknown";
33
38
  live: "live";
34
39
  lagging: "lagging";
35
- unknown: "unknown";
36
40
  }>;
41
+ initialized: z.ZodBoolean;
37
42
  }, z.core.$strip>;
38
43
  declare const CollectorsHealthResponse: z.ZodArray<z.ZodObject<{
39
44
  name: z.ZodString;
@@ -42,28 +47,37 @@ declare const CollectorsHealthResponse: z.ZodArray<z.ZodObject<{
42
47
  updated_at: z.ZodNullable<z.ZodString>;
43
48
  lag: z.ZodNullable<z.ZodNumber>;
44
49
  status: z.ZodEnum<{
50
+ unknown: "unknown";
45
51
  live: "live";
46
52
  lagging: "lagging";
47
- unknown: "unknown";
48
53
  }>;
54
+ initialized: z.ZodBoolean;
49
55
  }, z.core.$strip>>;
50
56
  declare const ChainHealth: z.ZodObject<{
51
57
  chain_id: z.ZodNumber;
52
- local_block_number: z.ZodNumber;
58
+ local_block_number: z.ZodNullable<z.ZodNumber>;
53
59
  remote_block_number: z.ZodNullable<z.ZodNumber>;
54
- updated_at: z.ZodString;
60
+ updated_at: z.ZodNullable<z.ZodString>;
61
+ initialized: z.ZodBoolean;
55
62
  }, z.core.$strip>;
56
63
  declare const ChainsHealthResponse: z.ZodArray<z.ZodObject<{
57
64
  chain_id: z.ZodNumber;
58
- local_block_number: z.ZodNumber;
65
+ local_block_number: z.ZodNullable<z.ZodNumber>;
59
66
  remote_block_number: z.ZodNullable<z.ZodNumber>;
60
- updated_at: z.ZodString;
67
+ updated_at: z.ZodNullable<z.ZodString>;
68
+ initialized: z.ZodBoolean;
61
69
  }, z.core.$strip>>;
62
70
  declare const RouterStatusResponse: z.ZodObject<{
63
71
  status: z.ZodEnum<{
64
72
  live: "live";
65
73
  syncing: "syncing";
66
74
  }>;
75
+ initialized: z.ZodBoolean;
76
+ missing_chains: z.ZodArray<z.ZodNumber>;
77
+ missing_collectors: z.ZodArray<z.ZodObject<{
78
+ chain_id: z.ZodNumber;
79
+ name: z.ZodString;
80
+ }, z.core.$strip>>;
67
81
  }, z.core.$strip>;
68
82
  type CollectorsHealthResponse = z.infer<typeof CollectorsHealthResponse>;
69
83
  type ChainsHealthResponse = z.infer<typeof ChainsHealthResponse>;
@@ -331,7 +345,7 @@ declare const Morpho: readonly [{
331
345
  readonly stateMutability: "view";
332
346
  }];
333
347
  declare namespace Callback_d_exports {
334
- export { CallbackType, decode$3 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$3 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
348
+ export { BuyVaultV1CallbackData, CallbackType, SellERC20CallbackData, decode$2 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$2 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
335
349
  }
336
350
  declare enum CallbackType {
337
351
  BuyWithEmptyCallback = "buy_with_empty_callback",
@@ -339,11 +353,20 @@ declare enum CallbackType {
339
353
  SellERC20Callback = "sell_erc20_callback",
340
354
  }
341
355
  declare const isEmptyCallback: (offer: Offer) => boolean;
342
- declare function decode$3(type: CallbackType, data: Hex): {
356
+ declare function decode$2(type: CallbackType, data: Hex): {
343
357
  contract: Address;
344
358
  amount: bigint;
345
359
  }[];
346
- declare function encode$3(type: CallbackType, data: any): Hex;
360
+ type BuyVaultV1CallbackData = {
361
+ vaults: Address[];
362
+ amounts: bigint[];
363
+ };
364
+ type SellERC20CallbackData = {
365
+ collaterals: Address[];
366
+ amounts: bigint[];
367
+ };
368
+ declare function encode$2(type: CallbackType.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;
369
+ declare function encode$2(type: CallbackType.SellERC20Callback, data: SellERC20CallbackData): Hex;
347
370
  declare function decodeBuyVaultV1Callback(data: Hex): Array<{
348
371
  contract: Address;
349
372
  amount: bigint;
@@ -395,7 +418,7 @@ declare class ReorgError extends BaseError {
395
418
  declare namespace Chain_d_exports {
396
419
  export { Chain$1 as Chain, ChainId, Id, InvalidBatchSizeError, InvalidBlockRangeError, InvalidBlockWindowError, MissingBlockNumberError, Name, chainIds, chainNames, chains$1 as chains, getChain, getWhitelistedChains, streamLogs };
397
420
  }
398
- type Chain$1 = Compute<Chain<ChainFormatters, {
421
+ type Chain$1 = Compute<Omit<Chain<ChainFormatters, {
399
422
  morpho: ChainContract;
400
423
  morphoBlue: ChainContract;
401
424
  mempool: ChainContract;
@@ -405,9 +428,20 @@ type Chain$1 = Compute<Chain<ChainFormatters, {
405
428
  v1_1: ChainContract;
406
429
  };
407
430
  };
408
- }> & {
431
+ }>, "custom"> & {
409
432
  id: Id;
410
433
  name: Name;
434
+ custom: {
435
+ morpho: ChainContract;
436
+ morphoBlue: ChainContract;
437
+ mempool: ChainContract;
438
+ vaults: {
439
+ factories: {
440
+ v1_0: ChainContract;
441
+ v1_1: ChainContract;
442
+ };
443
+ };
444
+ };
411
445
  }>;
412
446
  declare const ChainId: {
413
447
  readonly ETHEREUM: 1;
@@ -453,6 +487,14 @@ declare class MissingBlockNumberError extends BaseError {
453
487
  name: string;
454
488
  constructor();
455
489
  }
490
+ declare namespace ChainRegistry_d_exports {
491
+ export { ChainRegistry, create$1 as create };
492
+ }
493
+ type ChainRegistry = {
494
+ getById: (chainId: Id) => Chain$1 | undefined;
495
+ list: () => Chain$1[];
496
+ };
497
+ declare function create$1(chains: Chain$1[]): ChainRegistry;
456
498
  //#endregion
457
499
  //#region src/core/types.d.ts
458
500
  /** Combines members of an intersection into a readable type. */
@@ -462,7 +504,7 @@ type Brand<in out ID extends string | symbol> = {
462
504
  readonly [BrandTypeId]: { readonly [id in ID]: ID };
463
505
  };
464
506
  declare namespace LLTV_d_exports {
465
- export { InvalidLLTVError, InvalidOptionError$1 as InvalidOptionError, LLTV, LLTVSchema, Options, from$12 as from };
507
+ export { InvalidLLTVError, InvalidOptionError$1 as InvalidOptionError, LLTV, LLTVSchema, Options, from$13 as from };
466
508
  }
467
509
  type LLTV = bigint & Brand<"LLTV">;
468
510
  declare const Options: readonly [0.385, 0.5, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965, 0.98];
@@ -472,8 +514,8 @@ type Options = (typeof Options)[number];
472
514
  * @param lltv - The LLTV option or the scaled LLTV.
473
515
  * @returns The LLTV.
474
516
  */
475
- declare function from$12(lltv: Options | bigint): LLTV;
476
- declare namespace from$12 {
517
+ declare function from$13(lltv: Options | bigint): LLTV;
518
+ declare namespace from$13 {
477
519
  type ErrorType = InvalidOptionError$1 | InvalidLLTVError;
478
520
  }
479
521
  declare class InvalidOptionError$1 extends BaseError {
@@ -486,7 +528,7 @@ declare class InvalidLLTVError extends BaseError {
486
528
  }
487
529
  declare const LLTVSchema: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
488
530
  declare namespace Collateral_d_exports {
489
- export { Collateral, CollateralSchema, CollateralsSchema, from$11 as from, random$3 as random };
531
+ export { Collateral, CollateralSchema, CollateralsSchema, from$12 as from, random$3 as random };
490
532
  }
491
533
  type Collateral = {
492
534
  /** Asset being used as collateral. */
@@ -506,8 +548,8 @@ declare const CollateralsSchema: z$1.ZodArray<z$1.ZodObject<{
506
548
  oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
507
549
  lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
508
550
  }, z$1.core.$strip>>;
509
- declare const from$11: (parameters: from$11.Parameters) => from$11.ReturnType;
510
- declare namespace from$11 {
551
+ declare const from$12: (parameters: from$12.Parameters) => from$12.ReturnType;
552
+ declare namespace from$12 {
511
553
  type Parameters = {
512
554
  asset: Address;
513
555
  lltv: Options | bigint;
@@ -616,35 +658,127 @@ declare class DenominatorIsZeroError extends BaseError {
616
658
  readonly name = "ERC4626.DenominatorIsZeroError";
617
659
  constructor();
618
660
  }
619
- declare namespace Format_d_exports {
620
- export { Snake, fromSnakeCase$3 as fromSnakeCase, stringifyBigint, toSnakeCase$1 as toSnakeCase };
661
+ declare namespace Liquidity_d_exports {
662
+ export { LiquidityLink, LiquidityPool, OfferLiquidityPool, calculateMaxDebt, generateAllowancePoolId, generateBalancePoolId, generateBuyVaultCallbackPoolId, generateDebtPoolId, generateMarketLiquidityPoolId, generateObligationCollateralPoolId, generateSellERC20CallbackPoolId, generateUserVaultPositionPoolId, generateVaultPositionPoolId };
621
663
  }
622
- /** The snake case representation of a type with bigint values stringified. */
623
- type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;
624
- /** Make arrays/tuples and object props mutable, deeply. */
625
- type DeepMutable<T> = T extends ((...args: unknown[]) => unknown) ? T : T extends number | string | boolean | symbol | bigint | null | undefined ? T : T extends readonly [...infer R] ? { -readonly [K in keyof R]: DeepMutable<R[K]> } : T extends ReadonlyArray<infer U> ? Array<DeepMutable<U>> : T extends object ? { -readonly [K in keyof T]: DeepMutable<T[K]> } : T;
626
- /** Stringifies bigint values to strings and preserves branded primitives. */
627
- type StringifiedBigint<T> = [T] extends [bigint] ? string : [T] extends [`0x${string}`] ? string : T extends number ? T : T extends string ? T : T extends boolean ? T : T extends symbol ? T : T extends null | undefined ? T : T extends readonly (infer U)[] ? readonly StringifiedBigint<U>[] : T extends object ? { [K in keyof T]: StringifiedBigint<T[K]> } : T;
628
- /** Key remapping that also preserves branded primitives. */
629
- type SnakeKeys<T> = T extends readonly (infer U)[] ? readonly SnakeKeys<U>[] : T extends number | string | boolean | symbol | null | undefined ? T : T extends object ? { [K in keyof T as ToSnakeCase<Extract<K, string>>]: SnakeKeys<T[K]> } : T;
630
- type ToSnakeCase<S extends string> = S extends `${infer Head}${infer Tail}` ? Tail extends Uncapitalize<Tail> ? `${Lowercase<Head>}${ToSnakeCase<Tail>}` : `${Lowercase<Head>}_${ToSnakeCase<Uncapitalize<Tail>>}` : S;
631
664
  /**
632
- * Formats object keys to snake case.
633
- * Preserves ethereum addresses as is.
634
- * Converts ethereum addresses to checksummed if used as values.
635
- * Stringifies bigint values to strings.
665
+ * Represents a liquidity pool with a unique ID and amount.
636
666
  */
637
- declare function toSnakeCase$1<T>(obj: T): Snake<T>;
667
+ type LiquidityPool = {
668
+ id: string;
669
+ amount: bigint;
670
+ };
638
671
  /**
639
- * Formats a snake case object to its camel case type.
640
- * Preserves ethereum addresses as is.
641
- * Converts checksummed ethereum addresses to lowercase if used as values.
642
- * @warning Does not unstringify bigint values.
672
+ * Represents a hierarchical relationship between two liquidity pools.
643
673
  */
644
- declare function fromSnakeCase$3<T>(obj: Snake<T>): T;
645
- declare function stringifyBigint<T>(value: T): StringifiedBigint<T>;
674
+ type LiquidityLink = {
675
+ parentPoolId: string;
676
+ childPoolId: string;
677
+ priority: number;
678
+ };
679
+ /**
680
+ * Represents the connection between an offer and its liquidity pools.
681
+ */
682
+ type OfferLiquidityPool = {
683
+ offerHash: Hex;
684
+ poolId: string;
685
+ /**
686
+ * The available capacity/liquidity from this pool for this offer.
687
+ * Meaning varies by pool type:
688
+ * - BuyWithEmptyCallback: Matches allowance amount from pool bellow
689
+ * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)
690
+ * - SellERC20Callback: Existing debt as negative value (reduces available capacity)
691
+ */
692
+ amount: bigint;
693
+ };
694
+ /**
695
+ * Calculate maximum debt capacity from collateral amount.
696
+ * @param amount - Collateral amount
697
+ * @param oraclePrice - Oracle price (scaled to 36 decimals)
698
+ * @param lltv - Loan-to-value ratio (scaled to 18 decimals)
699
+ * @returns Maximum debt capacity
700
+ */
701
+ declare function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint;
702
+ /**
703
+ * Generate pool ID for balance pools.
704
+ */
705
+ declare function generateBalancePoolId(parameters: {
706
+ user: Address;
707
+ chainId: Id;
708
+ token: Address;
709
+ }): string;
710
+ /**
711
+ * Generate pool ID for allowance pools.
712
+ */
713
+ declare function generateAllowancePoolId(parameters: {
714
+ user: Address;
715
+ chainId: Id;
716
+ token: Address;
717
+ }): string;
718
+ /**
719
+ * Generate pool ID for sell ERC20 callback pools.
720
+ * Each offer has its own callback pool to prevent liquidity conflicts.
721
+ */
722
+ declare function generateSellERC20CallbackPoolId(parameters: {
723
+ user: Address;
724
+ chainId: Id;
725
+ obligationId: Hex;
726
+ token: Address;
727
+ offerHash: Hex;
728
+ }): string;
729
+ /**
730
+ * Generate pool ID for obligation collateral pools.
731
+ * Obligation collateral pools represent collateral already deposited in the obligation.
732
+ * These pools are shared across all offers with the same obligation.
733
+ */
734
+ declare function generateObligationCollateralPoolId(parameters: {
735
+ user: Address;
736
+ chainId: Id;
737
+ obligationId: Hex;
738
+ token: Address;
739
+ }): string;
740
+ /**
741
+ * Generate pool ID for buy vault callback pools.
742
+ */
743
+ declare function generateBuyVaultCallbackPoolId(parameters: {
744
+ user: Address;
745
+ chainId: Id;
746
+ vault: Address;
747
+ offerHash: Hex;
748
+ }): string;
749
+ /**
750
+ * Generate pool ID for debt pools.
751
+ */
752
+ declare function generateDebtPoolId(parameters: {
753
+ user: Address;
754
+ chainId: Id;
755
+ obligationId: Hex;
756
+ }): string;
757
+ /**
758
+ * Generate pool ID for user position in a vault.
759
+ */
760
+ declare function generateUserVaultPositionPoolId(parameters: {
761
+ user: Address;
762
+ chainId: Id;
763
+ vault: Address;
764
+ }): string;
765
+ /**
766
+ * Generate pool ID for vault position in a market.
767
+ */
768
+ declare function generateVaultPositionPoolId(parameters: {
769
+ vault: Address;
770
+ chainId: Id;
771
+ marketId: string;
772
+ }): string;
773
+ /**
774
+ * Generate pool ID for market total liquidity.
775
+ */
776
+ declare function generateMarketLiquidityPoolId(parameters: {
777
+ chainId: Id;
778
+ marketId: string;
779
+ }): string;
646
780
  declare namespace Maturity_d_exports {
647
- export { InvalidDateError, InvalidFormatError, InvalidOptionError, Maturity, MaturityOptions, MaturitySchema, MaturityType, from$10 as from };
781
+ export { InvalidDateError, InvalidFormatError, InvalidOptionError, Maturity, MaturityOptions, MaturitySchema, MaturityType, from$11 as from };
648
782
  }
649
783
  /**
650
784
  * Maturity is a number that represents a date in seconds.
@@ -674,8 +808,8 @@ type MaturityOptions = keyof typeof MaturityOptions;
674
808
  * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.
675
809
  * @throws {InvalidOptionError} If the maturity is not a valid option.
676
810
  */
677
- declare function from$10(ts: from$10.Parameters): Maturity;
678
- declare namespace from$10 {
811
+ declare function from$11(ts: from$11.Parameters): Maturity;
812
+ declare namespace from$11 {
679
813
  type Parameters = number | MaturityOptions;
680
814
  type ErrorType = InvalidFormatError | InvalidDateError | InvalidOptionError;
681
815
  }
@@ -691,72 +825,47 @@ declare class InvalidOptionError extends BaseError {
691
825
  readonly name = "Maturity.InvalidOptionError";
692
826
  constructor(input: string);
693
827
  }
694
- declare namespace Offer_d_exports {
695
- export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferHashSchema, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$2 as decode, domain, encode$2 as encode, from$9 as from, fromSnakeCase$2 as fromSnakeCase, hash, obligationId, random$2 as random, sign, signatureMsg, toSnakeCase, types };
828
+ declare namespace Format_d_exports {
829
+ export { Snake, fromSnakeCase$3 as fromSnakeCase, stringifyBigint, toSnakeCase$1 as toSnakeCase };
696
830
  }
697
- type Offer = {
698
- /** The address that made the offer. */
699
- readonly offering: Address;
700
- /** The amount of assets offered. */
701
- readonly assets: bigint;
702
- /**
703
- * The amount of assets that can be taken from the offer. takeable = min(max - consumed, available)
704
- * Where available is the total amount of assets retrievable from offering positions.
705
- */
706
- readonly takeable: bigint;
707
- /** The interest rate (with 18 decimals). */
708
- readonly rate: bigint;
709
- /** The date at which all interests will be paid. */
710
- readonly maturity: Maturity;
711
- /** The date at which the offer will expire. */
712
- readonly expiry: number;
713
- /** The date at which the offer will start. */
714
- readonly start: number;
715
- /** The nonce. Used for OCO (One-Cancelled-Other) mechanism. */
716
- readonly nonce: bigint;
717
- /** The side of the offer. `true` for buy, `false` for sell. */
718
- readonly buy: boolean;
719
- /** The chain id where the liquidity for this offer is located. */
720
- readonly chainId: Id;
721
- /** The token that is being borrowed. */
722
- readonly loanToken: Address;
723
- /** The exact set of collaterals required to borrow the loan token. */
724
- readonly collaterals: readonly Collateral[];
725
- /** The optional callback data to retrieve the maker funds. */
726
- readonly callback: {
727
- readonly address: Address;
728
- readonly data: Hex;
729
- readonly gasLimit: bigint;
730
- };
731
- /** The amount of assets consumed from the offer. */
732
- consumed: bigint;
733
- /** The hash of the offer. */
734
- readonly hash: Hex;
735
- /** The block number at which the offer was created. */
736
- readonly blockNumber: number;
737
- /** The signature of the offer. */
738
- signature?: Hex;
739
- };
740
- declare enum Status {
741
- VALID = "VALID",
742
- SIMULATION_ERROR = "SIMULATION_ERROR",
831
+ /** The snake case representation of a type with bigint values stringified. */
832
+ type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;
833
+ /** Make arrays/tuples and object props mutable, deeply. */
834
+ type DeepMutable<T> = T extends ((...args: unknown[]) => unknown) ? T : T extends number | string | boolean | symbol | bigint | null | undefined ? T : T extends readonly [...infer R] ? { -readonly [K in keyof R]: DeepMutable<R[K]> } : T extends ReadonlyArray<infer U> ? Array<DeepMutable<U>> : T extends object ? { -readonly [K in keyof T]: DeepMutable<T[K]> } : T;
835
+ /** Stringifies bigint values to strings and preserves branded primitives. */
836
+ type StringifiedBigint<T> = [T] extends [bigint] ? string : [T] extends [`0x${string}`] ? string : T extends number ? T : T extends string ? T : T extends boolean ? T : T extends symbol ? T : T extends null | undefined ? T : T extends readonly (infer U)[] ? readonly StringifiedBigint<U>[] : T extends object ? { [K in keyof T]: StringifiedBigint<T[K]> } : T;
837
+ /** Key remapping that also preserves branded primitives. */
838
+ type SnakeKeys<T> = T extends readonly (infer U)[] ? readonly SnakeKeys<U>[] : T extends number | string | boolean | symbol | null | undefined ? T : T extends object ? { [K in keyof T as ToSnakeCase<Extract<K, string>>]: SnakeKeys<T[K]> } : T;
839
+ type ToSnakeCase<S extends string> = S extends `${infer Head}${infer Tail}` ? Tail extends Uncapitalize<Tail> ? `${Lowercase<Head>}${ToSnakeCase<Tail>}` : `${Lowercase<Head>}_${ToSnakeCase<Uncapitalize<Tail>>}` : S;
840
+ /**
841
+ * Formats object keys to snake case.
842
+ * Preserves ethereum addresses as is.
843
+ * Converts ethereum addresses to checksummed if used as values.
844
+ * Stringifies bigint values to strings.
845
+ */
846
+ declare function toSnakeCase$1<T>(obj: T): Snake<T>;
847
+ /**
848
+ * Formats a snake case object to its camel case type.
849
+ * Preserves ethereum addresses as is.
850
+ * Converts checksummed ethereum addresses to lowercase if used as values.
851
+ * @warning Does not unstringify bigint values.
852
+ */
853
+ declare function fromSnakeCase$3<T>(obj: Snake<T>): T;
854
+ declare function stringifyBigint<T>(value: T): StringifiedBigint<T>;
855
+ declare namespace Obligation_d_exports {
856
+ export { CollateralsAreNotSortedError, InvalidObligationError, Obligation, ObligationSchema, from$10 as from, fromSnakeCase$2 as fromSnakeCase, id, random$2 as random };
743
857
  }
744
- type Validation = {
745
- offerHash: Hex;
746
- status: Status;
858
+ type Obligation = {
859
+ /** The chain id where the liquidity for this obligation is located. */
860
+ chainId: Id;
861
+ /** The token that is being borrowed for this obligation. */
862
+ loanToken: Address;
863
+ /** The exact set of collaterals required to borrow the loan token. */
864
+ collaterals: Collateral[];
865
+ /** The maturity of the obligation. */
866
+ maturity: Maturity;
747
867
  };
748
- declare const OfferHashSchema: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
749
- declare const OfferSchema: (parameters?: {
750
- omitHash?: boolean;
751
- }) => z$1.ZodObject<{
752
- offering: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
753
- assets: z$1.ZodBigInt;
754
- rate: z$1.ZodBigInt;
755
- maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
756
- expiry: z$1.ZodNumber;
757
- start: z$1.ZodNumber;
758
- nonce: z$1.ZodBigInt;
759
- buy: z$1.ZodBoolean;
868
+ declare const ObligationSchema: z$1.ZodObject<{
760
869
  chainId: z$1.ZodNumber;
761
870
  loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
762
871
  collaterals: z$1.ZodArray<z$1.ZodObject<{
@@ -764,36 +873,220 @@ declare const OfferSchema: (parameters?: {
764
873
  oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
765
874
  lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
766
875
  }, z$1.core.$strip>>;
767
- callback: z$1.ZodObject<{
768
- address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
769
- data: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
770
- gasLimit: z$1.ZodBigInt;
771
- }, z$1.core.$strip>;
772
- signature: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
773
- consumed: z$1.ZodOptional<z$1.ZodBigInt>;
774
- takeable: z$1.ZodOptional<z$1.ZodBigInt>;
775
- blockNumber: z$1.ZodOptional<z$1.ZodNumber>;
876
+ maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
776
877
  }, z$1.core.$strip>;
777
878
  /**
778
- * Creates an offer from a plain object.
779
- * @throws {InvalidOfferError} If the offer is invalid.
780
- * @param input - The offer to create.
781
- * @returns The created offer with its hash.
782
- */
783
- declare function from$9(input: Compute<Omit<Offer, "chainId" | "hash"> & {
784
- chainId: number;
785
- }>): Offer;
786
- declare namespace from$9 {
787
- type ErrorType = InvalidOfferError;
788
- }
789
- /**
790
- * Creates an offer from a snake case object.
879
+ * Creates an obligation from the given parameters.
880
+ * @constructor
881
+ * @param parameters - {@link from.Parameters}
882
+ * @returns The created obligation. {@link Obligation}
883
+ * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
884
+ *
885
+ * @example
886
+ * ```ts
887
+ * const obligation = Obligation.from({
888
+ * chainId: 1,
889
+ * loanToken: privateKeyToAccount(generatePrivateKey()).address,
890
+ * collaterals: [
891
+ * Collateral.from({
892
+ * asset: privateKeyToAccount(generatePrivateKey()).address,
893
+ * oracle: privateKeyToAccount(generatePrivateKey()).address,
894
+ * lltv: 0.965
895
+ * }),
896
+ * ],
897
+ * maturity: Maturity.from("end_of_next_quarter"),
898
+ * });
899
+ * ```
900
+ */
901
+ declare function from$10(parameters: from$10.Parameters): from$10.ReturnType;
902
+ declare namespace from$10 {
903
+ type Parameters = {
904
+ /** The chain id where the liquidity for this obligation is located. */
905
+ chainId: number;
906
+ /** The token that is being borrowed for this obligation. */
907
+ loanToken: Address;
908
+ /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */
909
+ collaterals: from$12.Parameters[] | readonly from$12.Parameters[];
910
+ /** The maturity of the obligation. */
911
+ maturity: from$11.Parameters;
912
+ };
913
+ type ReturnType = Obligation;
914
+ type ErrorType = InvalidObligationError;
915
+ }
916
+ /**
917
+ * Creates an obligation from a snake case object.
918
+ * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}
919
+ * @param input - {@link fromSnakeCase.Parameters}
920
+ * @returns The created obligation. {@link fromSnakeCase.ReturnType}
921
+ */
922
+ declare function fromSnakeCase$2(input: fromSnakeCase$2.Parameters): fromSnakeCase$2.ReturnType;
923
+ declare namespace fromSnakeCase$2 {
924
+ type Parameters = Snake<Omit<Obligation, "chainId"> & {
925
+ chainId: number;
926
+ }>;
927
+ type ReturnType = Obligation;
928
+ type ErrorType = InvalidObligationError;
929
+ }
930
+ /**
931
+ * Calculates the obligation id based on the smart contract's Obligation struct.
932
+ * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).
933
+ * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
934
+ * @param parameters - {@link id.Parameters}
935
+ * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}
936
+ *
937
+ * @example
938
+ * ```ts
939
+ * const obligation = Obligation.random();
940
+ * const id = Obligation.id(obligation);
941
+ * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234
942
+ * ```
943
+ */
944
+ declare function id(parameters: id.Parameters): id.ReturnType;
945
+ declare namespace id {
946
+ type Parameters = {
947
+ chainId: number;
948
+ loanToken: Address;
949
+ collaterals: {
950
+ asset: Address;
951
+ lltv: bigint;
952
+ oracle: Address;
953
+ }[];
954
+ maturity: number;
955
+ };
956
+ type ReturnType = Hex;
957
+ type ErrorType = CollateralsAreNotSortedError;
958
+ }
959
+ /**
960
+ * Generates a random obligation.
961
+ * @returns A randomly generated obligation. {@link random.ReturnType}
962
+ *
963
+ * @example
964
+ * ```ts
965
+ * const obligation = Obligation.random();
966
+ * ```
967
+ */
968
+ declare function random$2(): random$2.ReturnType;
969
+ declare namespace random$2 {
970
+ type ReturnType = Obligation;
971
+ }
972
+ declare class InvalidObligationError extends BaseError<z$1.ZodError | Error> {
973
+ readonly name = "Obligation.InvalidObligationError";
974
+ constructor(error: z$1.ZodError | Error);
975
+ }
976
+ declare class CollateralsAreNotSortedError extends BaseError {
977
+ readonly name = "Obligation.CollateralsAreNotSortedError";
978
+ constructor();
979
+ }
980
+ declare namespace Offer_d_exports {
981
+ export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferInput, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$1 as decode, domain, encode$1 as encode, from$9 as from, fromSnakeCase$1 as fromSnakeCase, hash, obligationId, random$1 as random, serialize, sign, signatureMsg, toSnakeCase, types };
982
+ }
983
+ type Offer = {
984
+ /** The address that made the offer. */
985
+ readonly maker: Address;
986
+ /** The amount of assets offered. Mutually exclusive with obligationUnits and obligationShares. */
987
+ readonly assets: bigint;
988
+ /** The max debt units to trade. Mutually exclusive with assets and obligationShares. */
989
+ readonly obligationUnits: bigint;
990
+ /** The max lending shares to trade. Mutually exclusive with assets and obligationUnits. */
991
+ readonly obligationShares: bigint;
992
+ /** The price (18 decimals). */
993
+ readonly price: bigint;
994
+ /** The date at which all interests will be paid. */
995
+ readonly maturity: Maturity;
996
+ /** The date at which the offer will expire. */
997
+ readonly expiry: number;
998
+ /** The date at which the offer will start. */
999
+ readonly start: number;
1000
+ /** The group. Used for OCO (One-Cancelled-Other) mechanism. */
1001
+ readonly group: Hex;
1002
+ /** The session. Used for session-based offer management. */
1003
+ readonly session: Hex;
1004
+ /** The side of the offer. `true` for buy, `false` for sell. */
1005
+ readonly buy: boolean;
1006
+ /** The chain id where the liquidity for this offer is located. */
1007
+ readonly chainId: Id;
1008
+ /** The token that is being borrowed. */
1009
+ readonly loanToken: Address;
1010
+ /** The exact set of collaterals required to borrow the loan token. */
1011
+ readonly collaterals: readonly Collateral[];
1012
+ /** The optional callback data to retrieve the maker funds. */
1013
+ readonly callback: {
1014
+ readonly address: Address;
1015
+ readonly data: Hex;
1016
+ };
1017
+ };
1018
+ declare enum Status {
1019
+ VALID = "VALID",
1020
+ SIMULATION_ERROR = "SIMULATION_ERROR",
1021
+ }
1022
+ type Validation = {
1023
+ offerHash: Hex;
1024
+ status: Status;
1025
+ };
1026
+ declare const OfferSchema: () => z$1.ZodObject<{
1027
+ maker: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1028
+ assets: z$1.ZodBigInt;
1029
+ obligationUnits: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBigInt>>;
1030
+ obligationShares: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBigInt>>;
1031
+ price: z$1.ZodBigInt;
1032
+ maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
1033
+ expiry: z$1.ZodNumber;
1034
+ start: z$1.ZodNumber;
1035
+ group: z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBigInt]>, z$1.ZodTransform<`0x${string}`, string | number | bigint>>;
1036
+ session: z$1.ZodPipe<z$1.ZodDefault<z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBigInt]>>>, z$1.ZodTransform<`0x${string}`, string | number | bigint>>;
1037
+ buy: z$1.ZodBoolean;
1038
+ chainId: z$1.ZodNumber;
1039
+ loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1040
+ collaterals: z$1.ZodArray<z$1.ZodObject<{
1041
+ asset: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1042
+ oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1043
+ lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
1044
+ }, z$1.core.$strip>>;
1045
+ callback: z$1.ZodObject<{
1046
+ address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1047
+ data: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1048
+ }, z$1.core.$strip>;
1049
+ }, z$1.core.$strip>;
1050
+ /**
1051
+ * Input type for creating offers. Accepts flexible group types that will be coerced to Hex.
1052
+ *
1053
+ * The `group` field accepts multiple input formats:
1054
+ * - **Hex string** (`0x...`): Padded to 32 bytes if needed
1055
+ * - **Numeric string**: Converted to hex (e.g., `"123"` -> `"0x...7b"`)
1056
+ * - **Number**: Non-negative safe integer, converted to hex
1057
+ * - **BigInt**: Non-negative, must fit in bytes32
1058
+ *
1059
+ * All values validated to be non-negative and within bytes32 range.
1060
+ */
1061
+ type OfferInput = Compute<Omit<Offer, "chainId" | "group" | "session" | "obligationUnits" | "obligationShares"> & {
1062
+ chainId: number;
1063
+ group: Hex | bigint | number | string;
1064
+ /** Optional: defaults to zero bytes32. */
1065
+ session?: Hex | bigint | number | string;
1066
+ /** Optional: defaults to 0n. Mutually exclusive with assets and obligationShares. */
1067
+ obligationUnits?: bigint;
1068
+ /** Optional: defaults to 0n. Mutually exclusive with assets and obligationUnits. */
1069
+ obligationShares?: bigint;
1070
+ }>;
1071
+ /**
1072
+ * Creates an offer from a plain object.
1073
+ * @throws {InvalidOfferError} If the offer is invalid.
1074
+ * @param input - The offer to create.
1075
+ * @returns The created offer.
1076
+ */
1077
+ declare function from$9(input: OfferInput): Offer;
1078
+ declare namespace from$9 {
1079
+ type ErrorType = InvalidOfferError;
1080
+ }
1081
+ /**
1082
+ * Creates an offer from a snake case object.
791
1083
  * @throws {InvalidOfferError} If the offer is invalid.
792
1084
  * @param input - The offer to create.
793
- * @returns The created offer with its hash.
1085
+ * @returns The created offer.
794
1086
  */
795
- declare function fromSnakeCase$2(input: Snake<Omit<Offer, "chainId" | "hash"> & {
1087
+ declare function fromSnakeCase$1(input: Snake<Omit<Offer, "chainId" | "session"> & {
796
1088
  chainId: number;
1089
+ session: string;
797
1090
  }>): Offer;
798
1091
  /**
799
1092
  * Converts an offer to a snake case object.
@@ -801,6 +1094,38 @@ declare function fromSnakeCase$2(input: Snake<Omit<Offer, "chainId" | "hash"> &
801
1094
  * @returns The converted offer.
802
1095
  */
803
1096
  declare function toSnakeCase(offer: Offer): Snake<Offer>;
1097
+ /**
1098
+ * Serializes an offer for merkle tree encoding.
1099
+ * Converts BigInt fields to strings for JSON compatibility.
1100
+ *
1101
+ * @param offer - Offer to serialize
1102
+ * @returns JSON-serializable offer object
1103
+ */
1104
+ declare const serialize: (offer: Offer) => {
1105
+ maker: `0x${string}`;
1106
+ assets: string;
1107
+ obligationUnits: string;
1108
+ obligationShares: string;
1109
+ price: string;
1110
+ maturity: number;
1111
+ expiry: number;
1112
+ start: number;
1113
+ group: `0x${string}`;
1114
+ session: `0x${string}`;
1115
+ buy: boolean;
1116
+ chainId: Id;
1117
+ loanToken: `0x${string}`;
1118
+ collaterals: {
1119
+ asset: `0x${string}`;
1120
+ oracle: `0x${string}`;
1121
+ lltv: string;
1122
+ }[];
1123
+ callback: {
1124
+ address: `0x${string}`;
1125
+ data: `0x${string}`;
1126
+ };
1127
+ hash: `0x${string}`;
1128
+ };
804
1129
  type RandomConfig = {
805
1130
  chains?: Chain$1[];
806
1131
  loanTokens?: Address[];
@@ -808,22 +1133,20 @@ type RandomConfig = {
808
1133
  assetsDecimals?: Record<Address, number>;
809
1134
  buy?: boolean;
810
1135
  assets?: bigint;
811
- consumed?: bigint;
812
- takeable?: bigint;
813
- offering?: Address;
1136
+ obligationUnits?: bigint;
1137
+ obligationShares?: bigint;
1138
+ maker?: Address;
814
1139
  maturity?: Maturity;
815
1140
  start?: number;
816
1141
  expiry?: number;
817
- nonce?: bigint;
818
- rate?: bigint;
1142
+ group?: Hex | bigint | number | string;
1143
+ session?: Hex | bigint | number | string;
1144
+ price?: bigint;
819
1145
  callback?: {
820
1146
  address: Address;
821
1147
  data: Hex;
822
- gasLimit: bigint;
823
1148
  };
824
1149
  collaterals?: readonly Collateral[];
825
- signature?: Hex;
826
- blockNumber?: number;
827
1150
  };
828
1151
  /**
829
1152
  * Generates a random Offer.
@@ -831,7 +1154,7 @@ type RandomConfig = {
831
1154
  * @warning The generated Offer should not be used for production usage.
832
1155
  * @returns {Offer} A randomly generated Offer object.
833
1156
  */
834
- declare function random$2(config?: RandomConfig): Offer;
1157
+ declare function random$1(config?: RandomConfig): Offer;
835
1158
  /**
836
1159
  * Creates an EIP-712 domain object.
837
1160
  * @param chainId - The chain ID.
@@ -855,13 +1178,19 @@ declare const types: {
855
1178
  readonly type: "address";
856
1179
  }];
857
1180
  readonly Offer: readonly [{
858
- readonly name: "offering";
1181
+ readonly name: "maker";
859
1182
  readonly type: "address";
860
1183
  }, {
861
1184
  readonly name: "assets";
862
1185
  readonly type: "uint256";
863
1186
  }, {
864
- readonly name: "rate";
1187
+ readonly name: "obligationUnits";
1188
+ readonly type: "uint256";
1189
+ }, {
1190
+ readonly name: "obligationShares";
1191
+ readonly type: "uint256";
1192
+ }, {
1193
+ readonly name: "price";
865
1194
  readonly type: "uint256";
866
1195
  }, {
867
1196
  readonly name: "maturity";
@@ -870,8 +1199,11 @@ declare const types: {
870
1199
  readonly name: "expiry";
871
1200
  readonly type: "uint256";
872
1201
  }, {
873
- readonly name: "nonce";
874
- readonly type: "uint256";
1202
+ readonly name: "group";
1203
+ readonly type: "bytes32";
1204
+ }, {
1205
+ readonly name: "session";
1206
+ readonly type: "bytes32";
875
1207
  }, {
876
1208
  readonly name: "buy";
877
1209
  readonly type: "bool";
@@ -899,320 +1231,82 @@ declare const types: {
899
1231
  readonly name: "address";
900
1232
  readonly type: "address";
901
1233
  }, {
902
- readonly name: "data";
903
- readonly type: "bytes";
904
- }, {
905
- readonly name: "gasLimit";
906
- readonly type: "uint256";
907
- }];
908
- };
909
- /**
910
- * Signs an array of offers.
911
- * @throws {Error} If the wallet account is not set.
912
- * @param offers - The offers to sign.
913
- * @param wallet - The wallet to sign the offers with.
914
- * @returns The signed offers.
915
- */
916
- declare function sign(offers: Offer[], wallet: WalletClient): Promise<Hex>;
917
- declare function signatureMsg(offers: Offer[]): Hex;
918
- declare function hash(offer: Omit<Offer, "hash">): Hex;
919
- /**
920
- * Calculates the obligation id for an offer based on the smart contract's Obligation struct.
921
- * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals (sorted by token address), maturity)).
922
- * @param offer - The offer to calculate the obligation id for.
923
- * @returns The obligation id as a 32-byte hex string.
924
- */
925
- declare function obligationId(offer: Offer): Hex;
926
- declare function encode$2(offer: Offer): `0x${string}`;
927
- declare function decode$2(data: Hex, blockNumber: number | bigint): Offer;
928
- type OfferConsumed = {
929
- id: string;
930
- chainId: Id;
931
- offering: Address;
932
- nonce: bigint;
933
- amount: bigint;
934
- blockNumber: number;
935
- };
936
- /**
937
- * ABI for the Consumed event emitted by the Obligation contract.
938
- */
939
- declare const consumedEvent: {
940
- readonly type: "event";
941
- readonly name: "Consumed";
942
- readonly inputs: readonly [{
943
- readonly name: "user";
944
- readonly type: "address";
945
- readonly indexed: true;
946
- readonly internalType: "address";
947
- }, {
948
- readonly name: "nonce";
949
- readonly type: "uint256";
950
- readonly indexed: true;
951
- readonly internalType: "uint256";
952
- }, {
953
- readonly name: "amount";
954
- readonly type: "uint256";
955
- readonly indexed: false;
956
- readonly internalType: "uint256";
957
- }];
958
- readonly anonymous: false;
959
- };
960
- declare class InvalidOfferError extends BaseError<z$1.ZodError | Error> {
961
- readonly name = "Offer.InvalidOfferError";
962
- constructor(error: z$1.ZodError | Error);
963
- /**
964
- * Formats ZodError issues into a human-readable string with line breaks.
965
- * @example
966
- * "- 'assets': too small, expected >= 0
967
- * - 'start': must be before expiry"
968
- */
969
- static formatDetails(error: z$1.ZodError | Error): string;
970
- /**
971
- * Returns the formatted human-readable message.
972
- */
973
- get formattedMessage(): string;
974
- }
975
- declare class AccountNotSetError extends BaseError {
976
- readonly name = "Offer.AccountNotSetError";
977
- constructor();
978
- }
979
- declare namespace Liquidity_d_exports {
980
- export { LiquidityLink, LiquidityPool, OfferLiquidityPool, calculateMaxDebt, generateAllowancePoolId, generateBalancePoolId, generateBuyVaultCallbackPoolId, generateDebtPoolId, generateMarketLiquidityPoolId, generateObligationCollateralPoolId, generateSellERC20CallbackPoolId, generateUserVaultPositionPoolId, generateVaultPositionPoolId };
981
- }
982
- /**
983
- * Represents a liquidity pool with a unique ID and amount.
984
- */
985
- type LiquidityPool = {
986
- id: string;
987
- amount: bigint;
988
- };
989
- /**
990
- * Represents a hierarchical relationship between two liquidity pools.
991
- */
992
- type LiquidityLink = {
993
- parentPoolId: string;
994
- childPoolId: string;
995
- priority: number;
996
- };
997
- /**
998
- * Represents the connection between an offer and its liquidity pools.
999
- */
1000
- type OfferLiquidityPool = {
1001
- offerHash: Offer["hash"];
1002
- poolId: string;
1003
- /**
1004
- * The available capacity/liquidity from this pool for this offer.
1005
- * Meaning varies by pool type:
1006
- * - BuyWithEmptyCallback: Matches allowance amount from pool bellow
1007
- * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)
1008
- * - SellERC20Callback: Existing debt as negative value (reduces available capacity)
1009
- */
1010
- amount: bigint;
1011
- };
1012
- /**
1013
- * Calculate maximum debt capacity from collateral amount.
1014
- * @param amount - Collateral amount
1015
- * @param oraclePrice - Oracle price (scaled to 36 decimals)
1016
- * @param lltv - Loan-to-value ratio (scaled to 18 decimals)
1017
- * @returns Maximum debt capacity
1018
- */
1019
- declare function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint;
1020
- /**
1021
- * Generate pool ID for balance pools.
1022
- */
1023
- declare function generateBalancePoolId(parameters: {
1024
- user: Address;
1025
- chainId: Id;
1026
- token: Address;
1027
- }): string;
1028
- /**
1029
- * Generate pool ID for allowance pools.
1030
- */
1031
- declare function generateAllowancePoolId(parameters: {
1032
- user: Address;
1033
- chainId: Id;
1034
- token: Address;
1035
- }): string;
1036
- /**
1037
- * Generate pool ID for sell ERC20 callback pools.
1038
- * Each offer has its own callback pool to prevent liquidity conflicts.
1039
- */
1040
- declare function generateSellERC20CallbackPoolId(parameters: {
1041
- user: Address;
1042
- chainId: Id;
1043
- obligationId: Hex;
1044
- token: Address;
1045
- offerHash: Hex;
1046
- }): string;
1047
- /**
1048
- * Generate pool ID for obligation collateral pools.
1049
- * Obligation collateral pools represent collateral already deposited in the obligation.
1050
- * These pools are shared across all offers with the same obligation.
1051
- */
1052
- declare function generateObligationCollateralPoolId(parameters: {
1053
- user: Address;
1054
- chainId: Id;
1055
- obligationId: Hex;
1056
- token: Address;
1057
- }): string;
1058
- /**
1059
- * Generate pool ID for buy vault callback pools.
1060
- */
1061
- declare function generateBuyVaultCallbackPoolId(parameters: {
1062
- user: Address;
1063
- chainId: Id;
1064
- vault: Address;
1065
- offerHash: Hex;
1066
- }): string;
1067
- /**
1068
- * Generate pool ID for debt pools.
1069
- */
1070
- declare function generateDebtPoolId(parameters: {
1071
- user: Address;
1072
- chainId: Id;
1073
- obligationId: Hex;
1074
- }): string;
1075
- /**
1076
- * Generate pool ID for user position in a vault.
1077
- */
1078
- declare function generateUserVaultPositionPoolId(parameters: {
1079
- user: Address;
1080
- chainId: Id;
1081
- vault: Address;
1082
- }): string;
1083
- /**
1084
- * Generate pool ID for vault position in a market.
1085
- */
1086
- declare function generateVaultPositionPoolId(parameters: {
1087
- vault: Address;
1088
- chainId: Id;
1089
- marketId: string;
1090
- }): string;
1091
- /**
1092
- * Generate pool ID for market total liquidity.
1093
- */
1094
- declare function generateMarketLiquidityPoolId(parameters: {
1095
- chainId: Id;
1096
- marketId: string;
1097
- }): string;
1098
- declare namespace Obligation_d_exports {
1099
- export { CollateralsAreNotSortedError, InvalidObligationError, Obligation, ObligationSchema, from$8 as from, fromSnakeCase$1 as fromSnakeCase, id, random$1 as random };
1100
- }
1101
- type Obligation = {
1102
- /** The chain id where the liquidity for this obligation is located. */
1103
- chainId: Id;
1104
- /** The token that is being borrowed for this obligation. */
1105
- loanToken: Address;
1106
- /** The exact set of collaterals required to borrow the loan token. */
1107
- collaterals: Collateral[];
1108
- /** The maturity of the obligation. */
1109
- maturity: Maturity;
1110
- };
1111
- declare const ObligationSchema: z$1.ZodObject<{
1112
- chainId: z$1.ZodNumber;
1113
- loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1114
- collaterals: z$1.ZodArray<z$1.ZodObject<{
1115
- asset: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1116
- oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1117
- lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
1118
- }, z$1.core.$strip>>;
1119
- maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
1120
- }, z$1.core.$strip>;
1121
- /**
1122
- * Creates an obligation from the given parameters.
1123
- * @constructor
1124
- * @param parameters - {@link from.Parameters}
1125
- * @returns The created obligation. {@link Obligation}
1126
- * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
1127
- *
1128
- * @example
1129
- * ```ts
1130
- * const obligation = Obligation.from({
1131
- * chainId: 1,
1132
- * loanToken: privateKeyToAccount(generatePrivateKey()).address,
1133
- * collaterals: [
1134
- * Collateral.from({
1135
- * asset: privateKeyToAccount(generatePrivateKey()).address,
1136
- * oracle: privateKeyToAccount(generatePrivateKey()).address,
1137
- * lltv: 0.965
1138
- * }),
1139
- * ],
1140
- * maturity: Maturity.from("end_of_next_quarter"),
1141
- * });
1142
- * ```
1143
- */
1144
- declare function from$8(parameters: from$8.Parameters): from$8.ReturnType;
1145
- declare namespace from$8 {
1146
- type Parameters = {
1147
- /** The chain id where the liquidity for this obligation is located. */
1148
- chainId: number;
1149
- /** The token that is being borrowed for this obligation. */
1150
- loanToken: Address;
1151
- /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */
1152
- collaterals: from$11.Parameters[] | readonly from$11.Parameters[];
1153
- /** The maturity of the obligation. */
1154
- maturity: from$10.Parameters;
1155
- };
1156
- type ReturnType = Obligation;
1157
- type ErrorType = InvalidObligationError;
1158
- }
1234
+ readonly name: "data";
1235
+ readonly type: "bytes";
1236
+ }];
1237
+ };
1159
1238
  /**
1160
- * Creates an obligation from a snake case object.
1161
- * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}
1162
- * @param input - {@link fromSnakeCase.Parameters}
1163
- * @returns The created obligation. {@link fromSnakeCase.ReturnType}
1239
+ * Signs an array of offers.
1240
+ * @throws {Error} If the wallet account is not set.
1241
+ * @param offers - The offers to sign.
1242
+ * @param wallet - The wallet to sign the offers with.
1243
+ * @returns The signed offers.
1164
1244
  */
1165
- declare function fromSnakeCase$1(input: fromSnakeCase$1.Parameters): fromSnakeCase$1.ReturnType;
1166
- declare namespace fromSnakeCase$1 {
1167
- type Parameters = Snake<Omit<Obligation, "chainId"> & {
1168
- chainId: number;
1169
- }>;
1170
- type ReturnType = Obligation;
1171
- type ErrorType = InvalidObligationError;
1172
- }
1245
+ declare function sign(offers: Offer[], wallet: WalletClient): Promise<Hex>;
1246
+ declare function signatureMsg(offers: Offer[]): Hex;
1247
+ declare function hash(offer: Offer): Hex;
1173
1248
  /**
1174
- * Calculates the obligation id based on the smart contract's Obligation struct.
1175
- * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).
1176
- * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
1177
- * @param obligation - {@link id.Parameters}
1178
- * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}
1179
- *
1180
- * @example
1181
- * ```ts
1182
- * const obligation = Obligation.random();
1183
- * const id = Obligation.id(obligation);
1184
- * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234
1185
- * ```
1249
+ * Calculates the obligation id for an offer based on the smart contract's Obligation struct.
1250
+ * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals (sorted by token address), maturity)).
1251
+ * @param offer - The offer to calculate the obligation id for.
1252
+ * @returns The obligation id as a 32-byte hex string.
1186
1253
  */
1187
- declare function id(obligation: id.Parameters): id.ReturnType;
1188
- declare namespace id {
1189
- type Parameters = Obligation;
1190
- type ReturnType = Hex;
1191
- type ErrorType = CollateralsAreNotSortedError;
1192
- }
1254
+ declare function obligationId(offer: Offer): Hex;
1255
+ declare function encode$1(offer: Offer): `0x${string}`;
1256
+ declare function decode$1(data: Hex): Offer;
1257
+ type OfferConsumed = {
1258
+ id: string;
1259
+ chainId: Id;
1260
+ maker: Address;
1261
+ group: Hex;
1262
+ amount: bigint;
1263
+ blockNumber: number;
1264
+ };
1193
1265
  /**
1194
- * Generates a random obligation.
1195
- * @returns A randomly generated obligation. {@link random.ReturnType}
1196
- *
1197
- * @example
1198
- * ```ts
1199
- * const obligation = Obligation.random();
1200
- * ```
1266
+ * ABI for the Consume event emitted by the Obligation contract.
1201
1267
  */
1202
- declare function random$1(): random$1.ReturnType;
1203
- declare namespace random$1 {
1204
- type ReturnType = Obligation;
1205
- }
1206
- declare class InvalidObligationError extends BaseError<z$1.ZodError | Error> {
1207
- readonly name = "Obligation.InvalidObligationError";
1268
+ declare const consumedEvent: {
1269
+ readonly type: "event";
1270
+ readonly name: "Consume";
1271
+ readonly inputs: readonly [{
1272
+ readonly name: "user";
1273
+ readonly type: "address";
1274
+ readonly indexed: true;
1275
+ readonly internalType: "address";
1276
+ }, {
1277
+ readonly name: "group";
1278
+ readonly type: "bytes32";
1279
+ readonly indexed: true;
1280
+ readonly internalType: "bytes32";
1281
+ }, {
1282
+ readonly name: "amount";
1283
+ readonly type: "uint256";
1284
+ readonly indexed: false;
1285
+ readonly internalType: "uint256";
1286
+ }];
1287
+ readonly anonymous: false;
1288
+ };
1289
+ declare class InvalidOfferError extends BaseError<z$1.ZodError | Error> {
1290
+ readonly name = "Offer.InvalidOfferError";
1208
1291
  constructor(error: z$1.ZodError | Error);
1292
+ /**
1293
+ * Formats ZodError issues into a human-readable string with line breaks.
1294
+ * @example
1295
+ * "- 'assets': too small, expected >= 0
1296
+ * - 'start': must be before expiry"
1297
+ */
1298
+ static formatDetails(error: z$1.ZodError | Error): string;
1299
+ /**
1300
+ * Returns the formatted human-readable message.
1301
+ */
1302
+ get formattedMessage(): string;
1209
1303
  }
1210
- declare class CollateralsAreNotSortedError extends BaseError {
1211
- readonly name = "Obligation.CollateralsAreNotSortedError";
1304
+ declare class AccountNotSetError extends BaseError {
1305
+ readonly name = "Offer.AccountNotSetError";
1212
1306
  constructor();
1213
1307
  }
1214
1308
  declare namespace Oracle_d_exports {
1215
- export { Conversion, Oracle, from$7 as from };
1309
+ export { Conversion, Oracle, from$8 as from };
1216
1310
  }
1217
1311
  /**
1218
1312
  * An oracle contract that provides price information for assets.
@@ -1232,8 +1326,8 @@ type Oracle = {
1232
1326
  * @param data - The data to create the oracle from.
1233
1327
  * @returns The created oracle.
1234
1328
  */
1235
- declare function from$7(data: from$7.Parameters): from$7.ReturnType;
1236
- declare namespace from$7 {
1329
+ declare function from$8(data: from$8.Parameters): from$8.ReturnType;
1330
+ declare namespace from$8 {
1237
1331
  type Parameters = {
1238
1332
  chainId: Id;
1239
1333
  address: Address;
@@ -1274,7 +1368,7 @@ declare namespace Conversion {
1274
1368
  }): bigint;
1275
1369
  }
1276
1370
  declare namespace Position_d_exports {
1277
- export { Position, Type, from$6 as from };
1371
+ export { Position, Type, from$7 as from };
1278
1372
  }
1279
1373
  type Position = {
1280
1374
  /** The chain id. */
@@ -1308,8 +1402,8 @@ declare enum Type {
1308
1402
  * @param parameters - {@link from.Parameters}
1309
1403
  * @returns The created Position. {@link from.ReturnType}
1310
1404
  */
1311
- declare function from$6(parameters: from$6.Parameters): from$6.ReturnType;
1312
- declare namespace from$6 {
1405
+ declare function from$7(parameters: from$7.Parameters): from$7.ReturnType;
1406
+ declare namespace from$7 {
1313
1407
  type Parameters = {
1314
1408
  chainId: Id;
1315
1409
  contract: Address;
@@ -1322,27 +1416,27 @@ declare namespace from$6 {
1322
1416
  type ReturnType = Position;
1323
1417
  }
1324
1418
  declare namespace Quote_d_exports {
1325
- export { InvalidQuoteError, Quote, QuoteSchema, from$5 as from, fromSnakeCase, random };
1419
+ export { InvalidQuoteError, Quote, QuoteSchema, from$6 as from, fromSnakeCase, random };
1326
1420
  }
1327
1421
  type Quote = {
1328
1422
  /** The obligation id. */
1329
1423
  obligationId: Hex;
1330
1424
  ask: {
1331
- /** The highest interest rate the seller will accept to pay for the obligation. (18 decimals). */
1332
- rate: bigint;
1425
+ /** The ask price for the obligation. (18 decimals). */
1426
+ price: bigint;
1333
1427
  };
1334
1428
  bid: {
1335
- /** The lowest interest rate a buyer is willing to be paid for the obligation. (18 decimals). */
1336
- rate: bigint;
1429
+ /** The bid price for the obligation. (18 decimals). */
1430
+ price: bigint;
1337
1431
  };
1338
1432
  };
1339
1433
  declare const QuoteSchema: z$1.ZodObject<{
1340
1434
  obligationId: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1341
1435
  ask: z$1.ZodObject<{
1342
- rate: z$1.ZodBigInt;
1436
+ price: z$1.ZodBigInt;
1343
1437
  }, z$1.core.$strip>;
1344
1438
  bid: z$1.ZodObject<{
1345
- rate: z$1.ZodBigInt;
1439
+ price: z$1.ZodBigInt;
1346
1440
  }, z$1.core.$strip>;
1347
1441
  }, z$1.core.$strip>;
1348
1442
  /**
@@ -1354,11 +1448,11 @@ declare const QuoteSchema: z$1.ZodObject<{
1354
1448
  *
1355
1449
  * @example
1356
1450
  * ```ts
1357
- * const quote = Quote.from({ obligationId: "0x123", ask: { assets: 100n, rate: 100n }, bid: { assets: 100n, rate: 100n } });
1451
+ * const quote = Quote.from({ obligationId: "0x123", ask: { price: 100n }, bid: { price: 100n } });
1358
1452
  * ```
1359
1453
  */
1360
- declare function from$5(parameters: from$5.Parameters): from$5.ReturnType;
1361
- declare namespace from$5 {
1454
+ declare function from$6(parameters: from$6.Parameters): from$6.ReturnType;
1455
+ declare namespace from$6 {
1362
1456
  type Parameters = Quote;
1363
1457
  type ReturnType = Quote;
1364
1458
  type ErrorType = InvalidQuoteError;
@@ -1373,7 +1467,7 @@ declare function fromSnakeCase(snake: fromSnakeCase.Parameters): fromSnakeCase.R
1373
1467
  declare namespace fromSnakeCase {
1374
1468
  type Parameters = Snake<Quote>;
1375
1469
  type ReturnType = Quote;
1376
- type ErrorType = from$5.ErrorType;
1470
+ type ErrorType = from$6.ErrorType;
1377
1471
  }
1378
1472
  /**
1379
1473
  * Generates a random quote.
@@ -1388,14 +1482,14 @@ declare function random(): random.ReturnType;
1388
1482
  declare namespace random {
1389
1483
  type Parameters = never;
1390
1484
  type ReturnType = Quote;
1391
- type ErrorType = from$5.ErrorType;
1485
+ type ErrorType = from$6.ErrorType;
1392
1486
  }
1393
1487
  declare class InvalidQuoteError extends BaseError<z$1.ZodError | Error> {
1394
1488
  readonly name = "Quote.InvalidQuoteError";
1395
1489
  constructor(error: z$1.ZodError | Error);
1396
1490
  }
1397
1491
  declare namespace Transfer_d_exports {
1398
- export { Transfer, from$4 as from };
1492
+ export { Transfer, from$5 as from };
1399
1493
  }
1400
1494
  type Transfer = {
1401
1495
  id: string;
@@ -1418,8 +1512,8 @@ type Transfer = {
1418
1512
  * const transfer = Transfer.from({ id: "1", chainId: 1, contract: "0x123", from: "0x456", to: "0x789", value: 100n, blockNumber: 100n });
1419
1513
  * ```
1420
1514
  */
1421
- declare function from$4(parameters: from$4.Parameters): from$4.ReturnType;
1422
- declare namespace from$4 {
1515
+ declare function from$5(parameters: from$5.Parameters): from$5.ReturnType;
1516
+ declare namespace from$5 {
1423
1517
  type Parameters = {
1424
1518
  id: string;
1425
1519
  chainId: Id;
@@ -1432,46 +1526,148 @@ declare namespace from$4 {
1432
1526
  type ReturnType = Transfer;
1433
1527
  }
1434
1528
  declare namespace Tree_d_exports {
1435
- export { Tree, VERSION, decode$1 as decode, encode$1 as encode, from$3 as from };
1529
+ export { DecodeError, EncodeError, Proof, Tree, TreeError, VERSION, decode, encode, encodeUnsigned, from$4 as from, proofs };
1436
1530
  }
1531
+ /**
1532
+ * A merkle tree of offers built from offer hashes.
1533
+ * Constructed via {@link from}. The tree root can be signed for onchain broadcast.
1534
+ */
1437
1535
  type Tree = Compute<StandardMerkleTree<[Hex]> & {
1536
+ /** The offers in the tree. */
1438
1537
  offers: Offer[];
1538
+ /** The root of the tree. */
1439
1539
  root: Hex;
1440
1540
  }>;
1541
+ type Proof = {
1542
+ /** The offer that the proof is for. */
1543
+ offer: Offer;
1544
+ /** The merkle proof path for the offer. */
1545
+ path: Hex[];
1546
+ };
1441
1547
  declare const VERSION = 1;
1442
1548
  /**
1443
1549
  * Builds a Merkle tree from a list of offers.
1444
1550
  *
1445
1551
  * Leaves are the offer `hash` values as `bytes32` and are deterministically
1446
- * ordered in ascending lexicographic order so that the resulting root is stable
1447
- * regardless of the input order.
1552
+ * ordered following the StandardMerkleTree leaf ordering so that the resulting
1553
+ * root is stable regardless of the input order.
1448
1554
  *
1449
1555
  * @param offers - Offers to include in the tree.
1450
1556
  * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.
1557
+ * @throws {TreeError} If tree building fails due to offer inconsistencies.
1558
+ */
1559
+ declare const from$4: (offers: Offer[]) => Tree;
1560
+ /**
1561
+ * Generates merkle proofs for all offers in a tree.
1562
+ *
1563
+ * Each proof allows independent verification that an offer is included in the tree
1564
+ * without requiring the full tree. Proofs are ordered by StandardMerkleTree leaf ordering.
1565
+ *
1566
+ * @param tree - The {@link Tree} to generate proofs for.
1567
+ * @returns Array of proofs - {@link Proof}
1568
+ */
1569
+ declare const proofs: (tree: Tree) => Proof[];
1570
+ /**
1571
+ * Encodes a merkle tree with signature into hex calldata for onchain broadcast.
1572
+ *
1573
+ * Layout: `0x{vv}{gzip([...offers])}{root}{signature}` where:
1574
+ * - `{vv}`: 1-byte version (currently 0x01)
1575
+ * - `{gzip([...offers])}`: gzipped JSON array of serialized offers
1576
+ * - `{root}`: 32-byte merkle root
1577
+ * - `{signature}`: 65-byte EIP-191 signature over raw root bytes
1578
+ *
1579
+ * Validates signature authenticity and root integrity before encoding.
1580
+ *
1581
+ * @example
1582
+ * ```typescript
1583
+ * const tree = Tree.from(offers);
1584
+ * const signature = await wallet.signMessage({ message: { raw: tree.root } });
1585
+ * const calldata = await Tree.encode(tree, signature);
1586
+ * await broadcast(calldata);
1587
+ * ```
1588
+ *
1589
+ * @example
1590
+ * Manual construction (for advanced users):
1591
+ * ```typescript
1592
+ * const tree = Tree.from(offers);
1593
+ * const compressed = gzip(JSON.stringify(tree.offers.map(Offer.serialize)));
1594
+ * const partial = `0x01${bytesToHex(compressed)}${tree.root.slice(2)}`;
1595
+ * const signature = await wallet.signMessage({ message: { raw: tree.root } });
1596
+ * const calldata = `${partial}${signature.slice(2)}`;
1597
+ * ```
1598
+ *
1599
+ * @param tree - Merkle tree of offers
1600
+ * @param signature - EIP-191 signature over raw root bytes
1601
+ * @returns Hex-encoded calldata ready for onchain broadcast
1602
+ * @throws {EncodeError} If signature verification fails or root mismatch
1451
1603
  */
1452
- declare const from$3: (offers: Offer[]) => Tree;
1604
+ declare const encode: (tree: Tree, signature: Hex) => Promise<Hex>;
1453
1605
  /**
1454
- * Encodes an `Tree` into a Hex string with a version byte prefix and gzipped payload.
1606
+ * Encodes a merkle tree without a signature into hex payload for client-side signing.
1607
+ *
1608
+ * Layout: `0x{vv}{gzip([...offers])}{root}` where:
1609
+ * - `{vv}`: 1-byte version (currently 0x01)
1610
+ * - `{gzip([...offers])}`: gzipped JSON array of serialized offers
1611
+ * - `{root}`: 32-byte merkle root
1455
1612
  *
1456
- * - Layout: `0x{vv}{zip...}` where `{vv}` is one-byte version as two hex chars.
1457
- * - Payload is gzip(JSON.stringify([root, ...offers])) with bigint stringified.
1613
+ * Validates root integrity before encoding.
1458
1614
  *
1459
- * @param tree - The offer Merkle tree to encode.
1460
- * @returns Hex string starting with `0x{vv}` followed by gzipped payload bytes.
1461
- * @throws Error if the given `root` does not match the offers.
1615
+ * @param tree - Merkle tree of offers
1616
+ * @returns Hex-encoded unsigned payload
1617
+ * @throws {EncodeError} If root mismatch
1462
1618
  */
1463
- declare const encode$1: (tree: Tree) => Hex;
1619
+ declare const encodeUnsigned: (tree: Tree) => Hex;
1464
1620
  /**
1465
- * Decodes a Hex string produced by {@link encode} back into an `Tree`.
1621
+ * Decodes hex calldata into a validated merkle tree.
1466
1622
  *
1467
- * - Ensures the first byte version matches {@link VERSION}.
1468
- * - Decompresses with gunzip, parses JSON, validates offers, and re-checks the root.
1623
+ * Validates signature before decompression for fail-fast rejection of invalid payloads.
1624
+ * Returns the tree with separately validated signature and recovered signer address.
1469
1625
  *
1470
- * @param encoded - Hex string in the form `0x{vv}{zip...}`.
1471
- * @returns A validated `Tree` rebuilt from the offers.
1472
- * @throws Error if the version is invalid or the root does not match the offers.
1626
+ * Validation order:
1627
+ * 1. Version check
1628
+ * 2. Signature verification (fail-fast, before decompression)
1629
+ * 3. Decompression (only if signature valid)
1630
+ * 4. Root verification (computed from offers vs embedded root)
1631
+ *
1632
+ * @example
1633
+ * ```typescript
1634
+ * const { tree, signature, signer } = await Tree.decode(calldata);
1635
+ * console.log(`Tree signed by ${signer} with ${tree.offers.length} offers`);
1636
+ * ```
1637
+ *
1638
+ * @param encoded - Hex calldata in format `0x{vv}{gzip}{root}{signature}`
1639
+ * @returns Validated tree, signature, and recovered signer address
1640
+ * @throws {DecodeError} If version invalid, signature invalid, or root mismatch
1641
+ */
1642
+ declare const decode: (encoded: Hex) => Promise<{
1643
+ tree: Tree;
1644
+ signature: Hex;
1645
+ signer: Address;
1646
+ }>;
1647
+ /**
1648
+ * Error thrown during tree building operations.
1649
+ * Indicates structural issues with the tree (missing offers, inconsistent state).
1650
+ */
1651
+ declare class TreeError extends BaseError {
1652
+ name: string;
1653
+ constructor(reason: string);
1654
+ }
1655
+ /**
1656
+ * Error thrown during tree encoding.
1657
+ * Indicates validation failures (signature, root mismatch, mixed makers).
1658
+ */
1659
+ declare class EncodeError extends BaseError {
1660
+ name: string;
1661
+ constructor(reason: string);
1662
+ }
1663
+ /**
1664
+ * Error thrown during tree decoding.
1665
+ * Indicates payload corruption, version mismatch, or validation failures.
1473
1666
  */
1474
- declare const decode$1: (encoded: Hex) => Tree;
1667
+ declare class DecodeError extends BaseError {
1668
+ name: string;
1669
+ constructor(reason: string);
1670
+ }
1475
1671
  //#endregion
1476
1672
  //#region src/api/Schema/generated/swagger.d.ts
1477
1673
  /**
@@ -1489,13 +1685,13 @@ interface paths {
1489
1685
  };
1490
1686
  /**
1491
1687
  * Get aggregated book
1492
- * @description Returns aggregated book data for a given obligation and side. Offers are grouped by rate with summed takeable amounts. Book levels are sorted by rate (ascending for buy side, descending for sell side).
1688
+ * @description Returns aggregated book data for a given obligation and side. Offers are grouped by computed price with summed takeable amounts. Book levels are sorted by price (ascending for buy side, descending for sell side).
1493
1689
  */
1494
1690
  get: {
1495
1691
  parameters: {
1496
1692
  query?: {
1497
1693
  /**
1498
- * @description Maximum number of rate levels to return.
1694
+ * @description Maximum number of price levels to return.
1499
1695
  * @example 10
1500
1696
  */
1501
1697
  limit?: number;
@@ -1506,7 +1702,18 @@ interface paths {
1506
1702
  cursor?: string;
1507
1703
  };
1508
1704
  header?: never;
1509
- path?: never;
1705
+ path: {
1706
+ /**
1707
+ * @description Book side (buy or sell).
1708
+ * @example buy
1709
+ */
1710
+ side: "buy" | "sell";
1711
+ /**
1712
+ * @description Obligation id.
1713
+ * @example 0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67
1714
+ */
1715
+ obligationId: string;
1716
+ };
1510
1717
  cookie?: never;
1511
1718
  };
1512
1719
  requestBody?: never;
@@ -1539,6 +1746,45 @@ interface paths {
1539
1746
  patch?: never;
1540
1747
  trace?: never;
1541
1748
  };
1749
+ "/v1/config": {
1750
+ parameters: {
1751
+ query?: never;
1752
+ header?: never;
1753
+ path?: never;
1754
+ cookie?: never;
1755
+ };
1756
+ /**
1757
+ * Get router configuration
1758
+ * @description Returns chain configurations including contract addresses and supported maturity timestamps.
1759
+ */
1760
+ get: {
1761
+ parameters: {
1762
+ query?: never;
1763
+ header?: never;
1764
+ path?: never;
1765
+ cookie?: never;
1766
+ };
1767
+ requestBody?: never;
1768
+ responses: {
1769
+ /** @description Success */
1770
+ 200: {
1771
+ headers: {
1772
+ [name: string]: unknown;
1773
+ };
1774
+ content: {
1775
+ "application/json": components["schemas"]["ConfigSuccessResponse"];
1776
+ };
1777
+ };
1778
+ };
1779
+ };
1780
+ put?: never;
1781
+ post?: never;
1782
+ delete?: never;
1783
+ options?: never;
1784
+ head?: never;
1785
+ patch?: never;
1786
+ trace?: never;
1787
+ };
1542
1788
  "/v1/offers": {
1543
1789
  parameters: {
1544
1790
  query?: never;
@@ -1548,7 +1794,7 @@ interface paths {
1548
1794
  };
1549
1795
  /**
1550
1796
  * List all offers
1551
- * @description Returns offers. Provide either `obligation_id` + `side` (order book) or `offering` (by maker).
1797
+ * @description Returns offers. Provide either `obligation_id` + `side` (order book) or `maker` (by maker address).
1552
1798
  */
1553
1799
  get: {
1554
1800
  parameters: {
@@ -1567,9 +1813,9 @@ interface paths {
1567
1813
  * @description Maker address to filter offers by. Alternative to obligation_id + side.
1568
1814
  * @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401
1569
1815
  */
1570
- offering?: string;
1816
+ maker?: string;
1571
1817
  /**
1572
- * @description Obligation id used to filter offers. Required when not using offering.
1818
+ * @description Obligation id used to filter offers. Required when not using maker.
1573
1819
  * @example 0x1234567890123456789012345678901234567890123456789012345678901234
1574
1820
  */
1575
1821
  obligation_id?: string;
@@ -1627,9 +1873,35 @@ interface paths {
1627
1873
  get: {
1628
1874
  parameters: {
1629
1875
  query?: {
1630
- /** @example 10 */
1876
+ /**
1877
+ * @description Filter by exact maturity timestamp (unix seconds).
1878
+ * @example 1761922800
1879
+ */
1880
+ maturity?: number;
1881
+ /**
1882
+ * @description Filter by collateral token (matches any collateral in the obligation).
1883
+ * @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751
1884
+ */
1885
+ collateral_token?: string;
1886
+ /**
1887
+ * @description Filter by loan token address.
1888
+ * @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078
1889
+ */
1890
+ loan_token?: string;
1891
+ /**
1892
+ * @description Filter by chain ID.
1893
+ * @example 1
1894
+ */
1895
+ chain?: number;
1896
+ /**
1897
+ * @description Maximum number of obligations to return.
1898
+ * @example 10
1899
+ */
1631
1900
  limit?: number;
1632
- /** @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc */
1901
+ /**
1902
+ * @description Obligation id cursor for pagination.
1903
+ * @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc
1904
+ */
1633
1905
  cursor?: string;
1634
1906
  };
1635
1907
  header?: never;
@@ -1681,7 +1953,13 @@ interface paths {
1681
1953
  parameters: {
1682
1954
  query?: never;
1683
1955
  header?: never;
1684
- path?: never;
1956
+ path: {
1957
+ /**
1958
+ * @description Obligation id.
1959
+ * @example 0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67
1960
+ */
1961
+ obligationId: string;
1962
+ };
1685
1963
  cookie?: never;
1686
1964
  };
1687
1965
  requestBody?: never;
@@ -1727,7 +2005,13 @@ interface paths {
1727
2005
  */
1728
2006
  get: {
1729
2007
  parameters: {
1730
- query?: never;
2008
+ query?: {
2009
+ /**
2010
+ * @description Fail the request if initialization is incomplete.
2011
+ * @example true
2012
+ */
2013
+ strict?: boolean;
2014
+ };
1731
2015
  header?: never;
1732
2016
  path?: never;
1733
2017
  cookie?: never;
@@ -1766,7 +2050,13 @@ interface paths {
1766
2050
  */
1767
2051
  get: {
1768
2052
  parameters: {
1769
- query?: never;
2053
+ query?: {
2054
+ /**
2055
+ * @description Fail the request if initialization is incomplete.
2056
+ * @example true
2057
+ */
2058
+ strict?: boolean;
2059
+ };
1770
2060
  header?: never;
1771
2061
  path?: never;
1772
2062
  cookie?: never;
@@ -1792,7 +2082,52 @@ interface paths {
1792
2082
  patch?: never;
1793
2083
  trace?: never;
1794
2084
  };
1795
- "/v1/health/chains": {
2085
+ "/v1/health/chains": {
2086
+ parameters: {
2087
+ query?: never;
2088
+ header?: never;
2089
+ path?: never;
2090
+ cookie?: never;
2091
+ };
2092
+ /**
2093
+ * Retrieve chains health
2094
+ * @description Returns the latest block that can be processed by collectors for each chain.
2095
+ */
2096
+ get: {
2097
+ parameters: {
2098
+ query?: {
2099
+ /**
2100
+ * @description Fail the request if initialization is incomplete.
2101
+ * @example true
2102
+ */
2103
+ strict?: boolean;
2104
+ };
2105
+ header?: never;
2106
+ path?: never;
2107
+ cookie?: never;
2108
+ };
2109
+ requestBody?: never;
2110
+ responses: {
2111
+ /** @description Success */
2112
+ 200: {
2113
+ headers: {
2114
+ [name: string]: unknown;
2115
+ };
2116
+ content: {
2117
+ "application/json": components["schemas"]["ChainsHealthSuccessResponse"];
2118
+ };
2119
+ };
2120
+ };
2121
+ };
2122
+ put?: never;
2123
+ post?: never;
2124
+ delete?: never;
2125
+ options?: never;
2126
+ head?: never;
2127
+ patch?: never;
2128
+ trace?: never;
2129
+ };
2130
+ "/v1/users/{userAddress}/positions": {
1796
2131
  parameters: {
1797
2132
  query?: never;
1798
2133
  header?: never;
@@ -1800,14 +2135,31 @@ interface paths {
1800
2135
  cookie?: never;
1801
2136
  };
1802
2137
  /**
1803
- * Retrieve chains health
1804
- * @description Returns the latest block that can be processed by collectors for each chain.
2138
+ * Get user positions
2139
+ * @description Returns positions for a user with reserved balance. The reserved balance is the amount locked by active offers (max lot upper - offset - consumed).
1805
2140
  */
1806
2141
  get: {
1807
2142
  parameters: {
1808
- query?: never;
2143
+ query?: {
2144
+ /**
2145
+ * @description Maximum number of positions to return.
2146
+ * @example 10
2147
+ */
2148
+ limit?: number;
2149
+ /**
2150
+ * @description Pagination cursor in base64url-encoded format.
2151
+ * @example eyJvZmZzZXQiOjEwMH0
2152
+ */
2153
+ cursor?: string;
2154
+ };
1809
2155
  header?: never;
1810
- path?: never;
2156
+ path: {
2157
+ /**
2158
+ * @description User address to get positions for.
2159
+ * @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401
2160
+ */
2161
+ userAddress: string;
2162
+ };
1811
2163
  cookie?: never;
1812
2164
  };
1813
2165
  requestBody?: never;
@@ -1818,7 +2170,16 @@ interface paths {
1818
2170
  [name: string]: unknown;
1819
2171
  };
1820
2172
  content: {
1821
- "application/json": components["schemas"]["ChainsHealthSuccessResponse"];
2173
+ "application/json": components["schemas"]["PositionListResponse"];
2174
+ };
2175
+ };
2176
+ /** @description Bad Request */
2177
+ 400: {
2178
+ headers: {
2179
+ [name: string]: unknown;
2180
+ };
2181
+ content: {
2182
+ "application/json": components["schemas"]["BadRequestResponse"];
1822
2183
  };
1823
2184
  };
1824
2185
  };
@@ -1842,14 +2203,16 @@ interface paths {
1842
2203
  put?: never;
1843
2204
  /**
1844
2205
  * Validate offers
1845
- * @description Validates offers against router validation rules. Returns validation status for each offer.
2206
+ * @description Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure.
1846
2207
  *
1847
2208
  * **Available validation rules:**
1848
2209
  * - **parse_error**: Returns when an offer fails to parse due to invalid format or missing required fields
2210
+ * - **mixed_maker**: Validates that all offers in a batch have the same maker address
2211
+ * - **amount_mutual_exclusivity**: Validates that at most one of (assets, obligationUnits, obligationShares) is non-zero
1849
2212
  * - **chain_ids**: Validates that offer chain is one of: [109111114]
1850
2213
  * - **maturity**: Validates that offer maturity is one of: [end_of_month, end_of_next_month]
1851
2214
  * - **callback**: Validates callbacks: buy empty callback is allowed; sell offers must use a non-empty callback; non-empty callbacks must target one of [0x3333333333333333333333333333333333333333, 0x4444444444444444444444444444444444444444, 0x1111111111111111111111111111111111111111, 0x2222222222222222222222222222222222222222]
1852
- * - **token**: Validates that offer loan token and collateral tokens are in the allowed assets list
2215
+ * - **token**: Validates that offer loan token and collateral tokens are in the allowed assets list for the offer chain
1853
2216
  */
1854
2217
  post: {
1855
2218
  parameters: {
@@ -1870,7 +2233,7 @@ interface paths {
1870
2233
  [name: string]: unknown;
1871
2234
  };
1872
2235
  content: {
1873
- "application/json": components["schemas"]["ValidateOffersListResponse"];
2236
+ "application/json": components["schemas"]["ValidationSuccessResponse"];
1874
2237
  };
1875
2238
  };
1876
2239
  /** @description Bad Request */
@@ -1897,7 +2260,7 @@ interface components {
1897
2260
  meta: components["schemas"]["Meta"];
1898
2261
  /** @example eyJvZmZzZXQiOjEwMH0 */
1899
2262
  cursor: string | null;
1900
- /** @description Aggregated book levels grouped by rate. */
2263
+ /** @description Aggregated book levels grouped by computed price. */
1901
2264
  data: components["schemas"]["BookLevelResponse"][];
1902
2265
  };
1903
2266
  Meta: {
@@ -1906,7 +2269,7 @@ interface components {
1906
2269
  };
1907
2270
  BookLevelResponse: {
1908
2271
  /** @example 2750000000000000000 */
1909
- rate: string;
2272
+ price: string;
1910
2273
  /** @example 369216000000000000000000 */
1911
2274
  assets: string;
1912
2275
  /** @example 5 */
@@ -1934,6 +2297,56 @@ interface components {
1934
2297
  */
1935
2298
  details: Record<string, never>;
1936
2299
  };
2300
+ ConfigSuccessResponse: {
2301
+ meta: components["schemas"]["Meta"];
2302
+ /** @example null */
2303
+ cursor: string | null;
2304
+ /**
2305
+ * @description Array of chain configurations for all indexed chains.
2306
+ * @example [
2307
+ * {
2308
+ * "chain_id": 505050505,
2309
+ * "contracts": {
2310
+ * "mempool": "0xD946246695A9259F3B33a78629026F61B3Ab40aF"
2311
+ * },
2312
+ * "maturities": {
2313
+ * "end_of_month": 1738335600,
2314
+ * "end_of_next_month": 1740754800
2315
+ * }
2316
+ * }
2317
+ * ]
2318
+ */
2319
+ data: components["schemas"]["ConfigDataResponse"][];
2320
+ };
2321
+ ConfigDataResponse: {
2322
+ /** @example 505050505 */
2323
+ chain_id: number;
2324
+ contracts: components["schemas"]["ConfigContractsResponse"];
2325
+ /**
2326
+ * @description Supported maturity timestamps. Offers must use one of these values.
2327
+ * @example {
2328
+ * "end_of_month": 1738335600,
2329
+ * "end_of_next_month": 1740754800
2330
+ * }
2331
+ */
2332
+ maturities: components["schemas"]["MaturitiesResponse"];
2333
+ };
2334
+ ConfigContractsResponse: {
2335
+ /** @example 0xD946246695A9259F3B33a78629026F61B3Ab40aF */
2336
+ mempool: string;
2337
+ };
2338
+ MaturitiesResponse: {
2339
+ /**
2340
+ * @description Unix timestamp for end of current month maturity (last Friday 15:00 UTC).
2341
+ * @example 1738335600
2342
+ */
2343
+ end_of_month: number;
2344
+ /**
2345
+ * @description Unix timestamp for end of next month maturity (last Friday 15:00 UTC).
2346
+ * @example 1740754800
2347
+ */
2348
+ end_of_next_month: number;
2349
+ };
1937
2350
  OfferListResponse: {
1938
2351
  meta: components["schemas"]["Meta"];
1939
2352
  /** @example eyJvZmZzZXQiOjEwMH0 */
@@ -1942,103 +2355,164 @@ interface components {
1942
2355
  * @description Offers matching the provided filters.
1943
2356
  * @example [
1944
2357
  * {
1945
- * "hash": "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
1946
- * "offering": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
1947
- * "assets": "369216000000000000000000",
1948
- * "rate": "2750000000000000000",
1949
- * "maturity": 1761922799,
1950
- * "expiry": 1761922799,
1951
- * "start": 1761922790,
1952
- * "nonce": "571380",
1953
- * "buy": false,
1954
- * "chain_id": 1,
1955
- * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
1956
- * "collaterals": [
1957
- * {
1958
- * "asset": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
1959
- * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401",
1960
- * "lltv": "860000000000000000"
1961
- * }
1962
- * ],
1963
- * "callback": {
1964
- * "address": "0x1111111111111111111111111111111111111111",
1965
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
1966
- * "gas_limit": "500000"
2358
+ * "offer": {
2359
+ * "obligation": {
2360
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
2361
+ * "collaterals": [
2362
+ * {
2363
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2364
+ * "lltv": "860000000000000000",
2365
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
2366
+ * }
2367
+ * ],
2368
+ * "maturity": 1761922799
2369
+ * },
2370
+ * "buy": false,
2371
+ * "maker": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
2372
+ * "assets": "369216000000000000000000",
2373
+ * "obligation_units": "0",
2374
+ * "obligation_shares": "0",
2375
+ * "start": 1761922790,
2376
+ * "expiry": 1761922799,
2377
+ * "price": "2750000000000000000",
2378
+ * "group": "0x000000000000000000000000000000000000000000000000000000000008b8f4",
2379
+ * "session": "0x0000000000000000000000000000000000000000000000000000000000000000",
2380
+ * "callback": "0x1111111111111111111111111111111111111111",
2381
+ * "callback_data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
1967
2382
  * },
1968
- * "signature": "0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400",
2383
+ * "offer_hash": "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
2384
+ * "obligation_id": "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
2385
+ * "chain_id": 1,
1969
2386
  * "consumed": "0",
1970
2387
  * "takeable": "369216000000000000000000",
1971
- * "block_number": 2942933377146801
2388
+ * "block_number": 2942933377146801,
2389
+ * "root": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
2390
+ * "proof": [
2391
+ * "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
2392
+ * "0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba"
2393
+ * ],
2394
+ * "signature": "0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400"
1972
2395
  * }
1973
2396
  * ]
1974
2397
  */
1975
2398
  data: components["schemas"]["OfferListItemResponse"][];
1976
2399
  };
1977
2400
  OfferListItemResponse: {
2401
+ /**
2402
+ * @example {
2403
+ * "obligation": {
2404
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
2405
+ * "collaterals": [
2406
+ * {
2407
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2408
+ * "lltv": "860000000000000000",
2409
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
2410
+ * }
2411
+ * ],
2412
+ * "maturity": 1761922799
2413
+ * },
2414
+ * "buy": false,
2415
+ * "maker": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
2416
+ * "assets": "369216000000000000000000",
2417
+ * "obligation_units": "0",
2418
+ * "obligation_shares": "0",
2419
+ * "start": 1761922790,
2420
+ * "expiry": 1761922799,
2421
+ * "price": "2750000000000000000",
2422
+ * "group": "0x000000000000000000000000000000000000000000000000000000000008b8f4",
2423
+ * "session": "0x0000000000000000000000000000000000000000000000000000000000000000",
2424
+ * "callback": "0x1111111111111111111111111111111111111111",
2425
+ * "callback_data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
2426
+ * }
2427
+ */
2428
+ offer: components["schemas"]["OfferDataResponse"];
1978
2429
  /** @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427 */
1979
- hash: string;
2430
+ offer_hash: string;
2431
+ /** @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc */
2432
+ obligation_id: string;
2433
+ /** @example 1 */
2434
+ chain_id: number;
2435
+ /** @example 0 */
2436
+ consumed: string;
2437
+ /** @example 369216000000000000000000 */
2438
+ takeable: string;
2439
+ /** @example 2942933377146801 */
2440
+ block_number: number;
2441
+ /** @example 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef */
2442
+ root: string | null;
2443
+ /**
2444
+ * @example [
2445
+ * "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
2446
+ * "0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba"
2447
+ * ]
2448
+ */
2449
+ proof: string[] | null;
2450
+ /** @example 0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400 */
2451
+ signature: string | null;
2452
+ };
2453
+ OfferDataResponse: {
2454
+ /**
2455
+ * @example {
2456
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
2457
+ * "collaterals": [
2458
+ * {
2459
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2460
+ * "lltv": "860000000000000000",
2461
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
2462
+ * }
2463
+ * ],
2464
+ * "maturity": 1761922799
2465
+ * }
2466
+ */
2467
+ obligation: components["schemas"]["ObligationOfferResponse"];
2468
+ /** @example false */
2469
+ buy: boolean;
1980
2470
  /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
1981
- offering: string;
2471
+ maker: string;
1982
2472
  /** @example 369216000000000000000000 */
1983
2473
  assets: string;
1984
- /** @example 2750000000000000000 */
1985
- rate: string;
1986
- /** @example 1761922799 */
1987
- maturity: number;
1988
- /** @example 1761922799 */
1989
- expiry: number;
2474
+ /** @example 0 */
2475
+ obligation_units: string;
2476
+ /** @example 0 */
2477
+ obligation_shares: string;
1990
2478
  /** @example 1761922790 */
1991
2479
  start: number;
1992
- /** @example 571380 */
1993
- nonce: string;
1994
- /** @example false */
1995
- buy: boolean;
1996
- /** @example 1 */
1997
- chain_id: number;
2480
+ /** @example 1761922799 */
2481
+ expiry: number;
2482
+ /** @example 2750000000000000000 */
2483
+ price: string;
2484
+ /** @example 0x000000000000000000000000000000000000000000000000000000000008b8f4 */
2485
+ group: string;
2486
+ /** @example 0x0000000000000000000000000000000000000000000000000000000000000000 */
2487
+ session: string;
2488
+ /** @example 0x1111111111111111111111111111111111111111 */
2489
+ callback: string;
2490
+ /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
2491
+ callback_data: string;
2492
+ };
2493
+ ObligationOfferResponse: {
1998
2494
  /** @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078 */
1999
2495
  loan_token: string;
2000
2496
  /**
2001
2497
  * @example [
2002
2498
  * {
2003
- * "asset": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2004
- * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401",
2005
- * "lltv": "860000000000000000"
2499
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2500
+ * "lltv": "860000000000000000",
2501
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
2006
2502
  * }
2007
2503
  * ]
2008
2504
  */
2009
2505
  collaterals: components["schemas"]["CollateralResponse"][];
2010
- /**
2011
- * @example {
2012
- * "address": "0x1111111111111111111111111111111111111111",
2013
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
2014
- * "gas_limit": "500000"
2015
- * }
2016
- */
2017
- callback: components["schemas"]["OfferCallbackResponse"];
2018
- /** @example 369216000000000000000000 */
2019
- takeable: string;
2020
- /** @example 0 */
2021
- consumed: string;
2022
- /** @example 2942933377146801 */
2023
- block_number: number;
2024
- /** @example 0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400 */
2025
- signature: string | null;
2506
+ /** @example 1761922799 */
2507
+ maturity: number;
2026
2508
  };
2027
2509
  CollateralResponse: {
2028
2510
  /** @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751 */
2029
- asset: string;
2030
- /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
2031
- oracle: string;
2511
+ token: string;
2032
2512
  /** @example 860000000000000000 */
2033
2513
  lltv: string;
2034
- };
2035
- OfferCallbackResponse: {
2036
- /** @example 0x1111111111111111111111111111111111111111 */
2037
- address: string;
2038
- /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
2039
- data: string;
2040
- /** @example 500000 */
2041
- gas_limit: string;
2514
+ /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
2515
+ oracle: string;
2042
2516
  };
2043
2517
  ObligationListResponse: {
2044
2518
  meta: components["schemas"]["Meta"];
@@ -2062,11 +2536,11 @@ interface components {
2062
2536
  };
2063
2537
  AskResponse: {
2064
2538
  /** @example 1000000000000000000 */
2065
- rate: string;
2539
+ price: string;
2066
2540
  };
2067
2541
  BidResponse: {
2068
2542
  /** @example 1000000000000000000 */
2069
- rate: string;
2543
+ price: string;
2070
2544
  };
2071
2545
  ObligationSingleSuccessResponse: {
2072
2546
  meta: components["schemas"]["Meta"];
@@ -2080,7 +2554,10 @@ interface components {
2080
2554
  /**
2081
2555
  * @description Aggregated router status.
2082
2556
  * @example {
2083
- * "status": "live"
2557
+ * "status": "live",
2558
+ * "initialized": true,
2559
+ * "missing_chains": [],
2560
+ * "missing_collectors": []
2084
2561
  * }
2085
2562
  */
2086
2563
  data: components["schemas"]["RouterStatusDataResponse"];
@@ -2091,6 +2568,24 @@ interface components {
2091
2568
  * @enum {string}
2092
2569
  */
2093
2570
  status: "live" | "syncing";
2571
+ /** @example true */
2572
+ initialized: boolean;
2573
+ /**
2574
+ * @description Configured chain ids missing initialization rows.
2575
+ * @example []
2576
+ */
2577
+ missing_chains: number[];
2578
+ /**
2579
+ * @description Collectors missing initialization rows.
2580
+ * @example []
2581
+ */
2582
+ missing_collectors: components["schemas"]["MissingCollectorResponse"][];
2583
+ };
2584
+ MissingCollectorResponse: {
2585
+ /** @example 1 */
2586
+ chain_id: number;
2587
+ /** @example offers */
2588
+ name: string;
2094
2589
  };
2095
2590
  CollectorsHealthSuccessResponse: {
2096
2591
  meta: components["schemas"]["Meta"];
@@ -2103,7 +2598,8 @@ interface components {
2103
2598
  * "block_number": 21345678,
2104
2599
  * "updated_at": "2024-01-01T12:00:00.000Z",
2105
2600
  * "lag": 0,
2106
- * "status": "live"
2601
+ * "status": "live",
2602
+ * "initialized": true
2107
2603
  * }
2108
2604
  * ]
2109
2605
  */
@@ -2125,6 +2621,8 @@ interface components {
2125
2621
  * @enum {string}
2126
2622
  */
2127
2623
  status: "live" | "lagging" | "unknown";
2624
+ /** @example true */
2625
+ initialized: boolean;
2128
2626
  };
2129
2627
  ChainsHealthSuccessResponse: {
2130
2628
  meta: components["schemas"]["Meta"];
@@ -2135,7 +2633,8 @@ interface components {
2135
2633
  * "chain_id": 1,
2136
2634
  * "local_block_number": 21345678,
2137
2635
  * "remote_block_number": 21345690,
2138
- * "updated_at": "2024-01-01T12:00:00.000Z"
2636
+ * "updated_at": "2024-01-01T12:00:00.000Z",
2637
+ * "initialized": true
2139
2638
  * }
2140
2639
  * ]
2141
2640
  */
@@ -2145,36 +2644,69 @@ interface components {
2145
2644
  /** @example 1 */
2146
2645
  chain_id: number;
2147
2646
  /** @example 21345678 */
2148
- local_block_number: number;
2647
+ local_block_number: number | null;
2149
2648
  /** @example 21345690 */
2150
2649
  remote_block_number: number | null;
2151
2650
  /** @example 2024-01-01T12:00:00.000Z */
2152
- updated_at: string;
2651
+ updated_at: string | null;
2652
+ /** @example true */
2653
+ initialized: boolean;
2153
2654
  };
2154
- ValidateOffersRequest: {
2155
- /** @description Array of offers in snake_case format. Mutually exclusive with 'calldata'. */
2156
- offers?: components["schemas"]["ValidateOfferRequest"][];
2655
+ PositionListResponse: {
2656
+ meta: components["schemas"]["Meta"];
2657
+ /** @example eyJvZmZzZXQiOjEwMH0 */
2658
+ cursor: string | null;
2157
2659
  /**
2158
- * @description Encoded tree calldata as a hex string (0x-prefixed). Mutually exclusive with 'offers'.
2159
- * @example 0x01...
2660
+ * @description User positions with reserved balances from active offers.
2661
+ * @example [
2662
+ * {
2663
+ * "chain_id": 1,
2664
+ * "contract": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
2665
+ * "user": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
2666
+ * "reserved": "200000000000000000000",
2667
+ * "block_number": 21345678
2668
+ * }
2669
+ * ]
2160
2670
  */
2161
- calldata?: string;
2671
+ data: components["schemas"]["PositionListItemResponse"][];
2672
+ };
2673
+ PositionListItemResponse: {
2674
+ /** @example 1 */
2675
+ chain_id: number;
2676
+ /** @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078 */
2677
+ contract: string;
2678
+ /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
2679
+ user: string;
2680
+ /** @example 200000000000000000000 */
2681
+ reserved: string;
2682
+ /** @example 21345678 */
2683
+ block_number: number;
2684
+ };
2685
+ ValidateOffersRequest: {
2686
+ /** @description Array of offers in snake_case format. Required, non-empty. */
2687
+ offers: components["schemas"]["ValidateOfferRequest"][];
2162
2688
  };
2163
2689
  ValidateOfferRequest: {
2164
2690
  /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
2165
- offering: string;
2691
+ maker: string;
2166
2692
  /** @example 369216000000000000000000 */
2167
2693
  assets: string;
2694
+ /** @example 0 */
2695
+ obligation_units?: string;
2696
+ /** @example 0 */
2697
+ obligation_shares?: string;
2168
2698
  /** @example 2750000000000000000 */
2169
- rate: string;
2699
+ price: string;
2170
2700
  /** @example 1761922799 */
2171
2701
  maturity: number;
2172
2702
  /** @example 1761922799 */
2173
2703
  expiry: number;
2174
2704
  /** @example 1761922790 */
2175
2705
  start: number;
2176
- /** @example 571380 */
2177
- nonce: string;
2706
+ /** @example 0x000000000000000000000000000000000000000000000000000000000008b8f4 */
2707
+ group: string;
2708
+ /** @example 0x0000000000000000000000000000000000000000000000000000000000000000 */
2709
+ session: string;
2178
2710
  /** @example false */
2179
2711
  buy: boolean;
2180
2712
  /** @example 1 */
@@ -2190,32 +2722,47 @@ interface components {
2190
2722
  * }
2191
2723
  * ]
2192
2724
  */
2193
- collaterals: components["schemas"]["CollateralResponse"][];
2725
+ collaterals: components["schemas"]["ValidateCollateralRequest"][];
2194
2726
  /**
2195
2727
  * @example {
2196
2728
  * "address": "0x1111111111111111111111111111111111111111",
2197
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
2198
- * "gas_limit": "500000"
2729
+ * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
2199
2730
  * }
2200
2731
  */
2201
- callback: components["schemas"]["OfferCallbackResponse"];
2732
+ callback: components["schemas"]["ValidateCallbackRequest"];
2733
+ };
2734
+ ValidateCollateralRequest: {
2735
+ /** @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751 */
2736
+ asset: string;
2737
+ /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
2738
+ oracle: string;
2739
+ /** @example 860000000000000000 */
2740
+ lltv: string;
2741
+ };
2742
+ ValidateCallbackRequest: {
2743
+ /** @example 0x1111111111111111111111111111111111111111 */
2744
+ address: string;
2745
+ /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
2746
+ data: string;
2202
2747
  };
2203
- ValidateOffersListResponse: {
2748
+ ValidationSuccessResponse: {
2204
2749
  meta: components["schemas"]["Meta"];
2205
2750
  /** @example null */
2206
2751
  cursor: string | null;
2207
- /** @description Validation results for each offer. */
2208
- data: components["schemas"]["ValidateOfferResultResponse"][];
2752
+ /** @description Payload and root for client-side signing. */
2753
+ data: components["schemas"]["ValidationSuccessDataResponse"];
2209
2754
  };
2210
- ValidateOfferResultResponse: {
2211
- /** @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427 */
2212
- offer_hash: string;
2213
- /** @example false */
2214
- valid: boolean;
2215
- /** @example parse_error */
2216
- rule: string | null;
2217
- /** @example Invalid offer. 'offering': invalid address */
2218
- message: string | null;
2755
+ ValidationSuccessDataResponse: {
2756
+ /**
2757
+ * @description Unsigned payload: version (1B) + gzip(offers) + root (32B).
2758
+ * @example 0x01789c...
2759
+ */
2760
+ payload: string;
2761
+ /**
2762
+ * @description Merkle tree root to sign with EIP-191.
2763
+ * @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427
2764
+ */
2765
+ root: string;
2219
2766
  };
2220
2767
  };
2221
2768
  responses: never;
@@ -2225,7 +2772,7 @@ interface components {
2225
2772
  pathItems: never;
2226
2773
  }
2227
2774
  declare namespace ObligationResponse_d_exports {
2228
- export { ObligationResponse, from$2 as from };
2775
+ export { ObligationResponse, from$3 as from };
2229
2776
  }
2230
2777
  type ObligationResponse = paths["/v1/obligations"]["get"]["responses"]["200"]["content"]["application/json"]["data"][number];
2231
2778
  /**
@@ -2234,18 +2781,49 @@ type ObligationResponse = paths["/v1/obligations"]["get"]["responses"]["200"]["c
2234
2781
  * @param obligation - {@link Obligation}
2235
2782
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
2236
2783
  */
2237
- declare function from$2(obligation: Obligation, quote: Quote): ObligationResponse;
2784
+ declare function from$3(obligation: Obligation, quote: Quote): ObligationResponse;
2238
2785
  declare namespace OfferResponse_d_exports {
2239
- export { OfferResponse, from$1 as from };
2786
+ export { Input, OfferResponse, from$2 as from };
2240
2787
  }
2241
2788
  type OfferResponse = paths["/v1/offers"]["get"]["responses"]["200"]["content"]["application/json"]["data"][number];
2789
+ type Input = Readonly<{
2790
+ hash: Hex;
2791
+ maker: Address;
2792
+ assets: bigint;
2793
+ obligationUnits: bigint;
2794
+ obligationShares: bigint;
2795
+ price: bigint;
2796
+ maturity: number;
2797
+ expiry: number;
2798
+ start: number;
2799
+ group: Hex;
2800
+ session: Hex;
2801
+ buy: boolean;
2802
+ chainId: number;
2803
+ loanToken: Address;
2804
+ collaterals: Readonly<{
2805
+ asset: Address;
2806
+ lltv: bigint;
2807
+ oracle: Address;
2808
+ }[]>;
2809
+ callback: {
2810
+ address: Address;
2811
+ data: Hex;
2812
+ };
2813
+ root?: Hex | undefined;
2814
+ proof?: Hex[] | undefined;
2815
+ signature?: Hex | undefined;
2816
+ consumed: bigint;
2817
+ takeable: bigint;
2818
+ blockNumber: number;
2819
+ }>;
2242
2820
  /**
2243
- * Creates an `OfferResponse` from an `Offer`.
2821
+ * Creates an `OfferResponse` matching the Solidity Offer struct layout.
2244
2822
  * @constructor
2245
- * @param offer - {@link Offer}
2823
+ * @param input - {@link Input}
2246
2824
  * @returns The created `OfferResponse`. {@link OfferResponse}
2247
2825
  */
2248
- declare function from$1(offer: Offer): OfferResponse;
2826
+ declare function from$2(input: Input): OfferResponse;
2249
2827
  //#endregion
2250
2828
  //#region src/api/Schema/openapi.d.ts
2251
2829
  declare class BooksController {
@@ -2262,10 +2840,16 @@ declare class HealthController {
2262
2840
  getCollectorsHealth(): Promise<void>;
2263
2841
  getChainsHealth(): Promise<void>;
2264
2842
  }
2843
+ declare class ConfigController {
2844
+ getConfig(): Promise<void>;
2845
+ }
2265
2846
  declare class ObligationsController {
2266
2847
  getObligations(): Promise<void>;
2267
2848
  getObligation(): Promise<void>;
2268
2849
  }
2850
+ declare class UsersController {
2851
+ getUserPositions(): Promise<void>;
2852
+ }
2269
2853
  type RuleInfo = {
2270
2854
  name: string;
2271
2855
  description: string;
@@ -2275,20 +2859,91 @@ type OpenApiOptions = {
2275
2859
  };
2276
2860
  declare const OpenApi: (options?: OpenApiOptions) => Promise<OpenAPIDocument>;
2277
2861
  //#endregion
2862
+ //#region src/database/domains/Positions.d.ts
2863
+ type PaginationParams = {
2864
+ /** Cursor string returned by a previous call, for pagination */
2865
+ cursor?: string;
2866
+ /** Page size; defaults to {@link DEFAULT_LIMIT} */
2867
+ limit?: number;
2868
+ };
2869
+ declare namespace getByUser {
2870
+ type Parameters = PaginationParams & {
2871
+ /** The user address to get positions for. */
2872
+ user: Address;
2873
+ };
2874
+ type PositionWithReserved = {
2875
+ chainId: Id;
2876
+ contract: Address;
2877
+ user: Address;
2878
+ blockNumber: number;
2879
+ /** The amount reserved by active offers: max(lot.upper) - offset - consumed */
2880
+ reserved: bigint;
2881
+ };
2882
+ type ReturnType = {
2883
+ positions: PositionWithReserved[];
2884
+ nextCursor: string | null;
2885
+ };
2886
+ }
2887
+ declare namespace PositionResponse_d_exports {
2888
+ export { PositionResponse, PositionWithReserved$1 as PositionWithReserved, from$1 as from };
2889
+ }
2890
+ type PositionResponse = {
2891
+ chain_id: Id;
2892
+ contract: Address;
2893
+ user: Address;
2894
+ reserved: string;
2895
+ block_number: number;
2896
+ };
2897
+ type PositionWithReserved$1 = getByUser.PositionWithReserved;
2898
+ /**
2899
+ * Creates a `PositionResponse` from a `PositionWithReserved`.
2900
+ * @param position - {@link PositionWithReserved}
2901
+ * @returns The created `PositionResponse`. {@link PositionResponse}
2902
+ */
2903
+ declare function from$1(position: PositionWithReserved$1): PositionResponse;
2904
+ //#endregion
2278
2905
  //#region src/api/Schema/requests.d.ts
2279
2906
  declare const schemas: {
2907
+ readonly get_health: z$1.ZodObject<{
2908
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
2909
+ 0: "0";
2910
+ 1: "1";
2911
+ true: "true";
2912
+ false: "false";
2913
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
2914
+ }, z$1.core.$strip>;
2915
+ readonly get_health_collectors: z$1.ZodObject<{
2916
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
2917
+ 0: "0";
2918
+ 1: "1";
2919
+ true: "true";
2920
+ false: "false";
2921
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
2922
+ }, z$1.core.$strip>;
2923
+ readonly get_health_chains: z$1.ZodObject<{
2924
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
2925
+ 0: "0";
2926
+ 1: "1";
2927
+ true: "true";
2928
+ false: "false";
2929
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
2930
+ }, z$1.core.$strip>;
2280
2931
  readonly get_offers: z$1.ZodObject<{
2281
2932
  side: z$1.ZodOptional<z$1.ZodEnum<{
2282
2933
  buy: "buy";
2283
2934
  sell: "sell";
2284
2935
  }>>;
2285
2936
  obligation_id: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
2286
- offering: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
2937
+ maker: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
2287
2938
  cursor: z$1.ZodOptional<z$1.ZodString>;
2288
2939
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
2289
2940
  }, z$1.core.$strip>;
2290
2941
  readonly get_obligations: z$1.ZodObject<{
2291
2942
  cursor: z$1.ZodOptional<z$1.ZodString>;
2943
+ chain: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>>;
2944
+ loan_token: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
2945
+ collateral_token: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
2946
+ maturity: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>>;
2292
2947
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
2293
2948
  }, z$1.core.$strip>;
2294
2949
  readonly get_obligation: z$1.ZodObject<{
@@ -2304,15 +2959,19 @@ declare const schemas: {
2304
2959
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
2305
2960
  }, z$1.core.$strip>;
2306
2961
  readonly validate_offers: z$1.ZodObject<{
2307
- offers: z$1.ZodAny;
2308
- calldata: z$1.ZodOptional<z$1.ZodString>;
2962
+ offers: z$1.ZodArray<z$1.ZodUnknown>;
2963
+ }, z$1.core.$strict>;
2964
+ readonly get_user_positions: z$1.ZodObject<{
2965
+ user_address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
2966
+ cursor: z$1.ZodOptional<z$1.ZodString>;
2967
+ limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
2309
2968
  }, z$1.core.$strip>;
2310
2969
  };
2311
2970
  type Action = keyof typeof schemas;
2312
2971
  declare function parse<A extends Action>(action: A, query: unknown): z$1.infer<(typeof schemas)[A]>;
2313
2972
  declare function safeParse<A extends Action>(action: A, query: unknown, error?: z$1.core.$ZodErrorMap<z$1.core.$ZodIssue>): z$1.ZodSafeParseResult<z$1.infer<(typeof schemas)[A]>>;
2314
2973
  declare namespace index_d_exports$1 {
2315
- export { BookResponse_d_exports as BookResponse, BooksController, ChainHealth, ChainsHealthResponse, CollectorHealth, CollectorsHealthResponse, HealthController, ObligationResponse_d_exports as ObligationResponse, ObligationsController, OfferResponse_d_exports as OfferResponse, OffersController, OpenApi, OpenApiOptions, RouterStatusResponse, RuleInfo, ValidateController, parse, safeParse };
2974
+ export { BookResponse_d_exports as BookResponse, BooksController, ChainHealth, ChainsHealthResponse, CollectorHealth, CollectorsHealthResponse, ConfigController, HealthController, ObligationResponse_d_exports as ObligationResponse, ObligationsController, OfferResponse_d_exports as OfferResponse, OffersController, OpenApi, OpenApiOptions, PositionResponse_d_exports as PositionResponse, RouterStatusResponse, RuleInfo, UsersController, ValidateController, parse, safeParse };
2316
2975
  }
2317
2976
  declare namespace Client_d_exports {
2318
2977
  export { Client$2 as Client, ConnectOptions, HttpForbiddenError, HttpGetApiFailedError, HttpRateLimitError, HttpUnauthorizedError, InvalidUrlError, connect$1 as connect, getObligations, getOffers };
@@ -2393,7 +3052,19 @@ declare namespace getOffers {
2393
3052
  limit?: number;
2394
3053
  };
2395
3054
  type ReturnType = {
2396
- offers: Offer[];
3055
+ offers: Compute<Offer & {
3056
+ hash: Hex;
3057
+ blockNumber: number;
3058
+ consumed: bigint;
3059
+ takeable: bigint;
3060
+ } & {
3061
+ /** 32-byte merkle root. */
3062
+ root?: Hex;
3063
+ /** Sibling hashes for the merkle proof. */
3064
+ proof?: Hex[];
3065
+ /** Offer signature from the Merkle tree. */
3066
+ signature?: Hex;
3067
+ }>[];
2397
3068
  /** The pagination cursor. */
2398
3069
  cursor: string | null;
2399
3070
  };
@@ -2406,6 +3077,14 @@ declare namespace getObligations {
2406
3077
  cursor?: Hex;
2407
3078
  /** Maximum number of obligations to return. @default 20 */
2408
3079
  limit?: number;
3080
+ /** Filter by chain ID. */
3081
+ chainId?: number;
3082
+ /** Filter by loan token address. */
3083
+ loanToken?: Address;
3084
+ /** Filter by collateral token (matches any collateral in the obligation). */
3085
+ collateralToken?: Address;
3086
+ /** Filter by exact maturity timestamp (unix seconds). */
3087
+ maturity?: number;
2409
3088
  };
2410
3089
  type ReturnType = {
2411
3090
  obligations: Compute<{
@@ -2442,22 +3121,6 @@ declare class HttpGetApiFailedError extends BaseError {
2442
3121
  details?: string;
2443
3122
  });
2444
3123
  }
2445
- declare namespace Cursor_d_exports {
2446
- export { Cursor, decode, encode, validate };
2447
- }
2448
- type Cursor = {
2449
- sort: "rate" | "maturity" | "expiry" | "amount";
2450
- dir: "asc" | "desc";
2451
- rate?: string;
2452
- maturity?: number;
2453
- expiry?: number;
2454
- assets?: string;
2455
- hash: string;
2456
- page?: number;
2457
- };
2458
- declare function validate(cursor: unknown): cursor is Cursor;
2459
- declare function encode(c: Cursor): string;
2460
- declare function decode(token?: string): Cursor | null;
2461
3124
  declare namespace Gate_d_exports {
2462
3125
  export { Batch, Issue, Result, Rule, RuleNames, Single, batch$1 as batch, run, single };
2463
3126
  }
@@ -2532,7 +3195,7 @@ declare function run<T, Name$1 extends string, Rules$1 extends readonly Rule<T,
2532
3195
  chunkSize?: number;
2533
3196
  }): Promise<Result<T, RuleNames<Rules$1>>>;
2534
3197
  declare namespace GateConfig_d_exports {
2535
- export { CallbackConfig, GateConfig, assets$1 as assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
3198
+ export { CallbackConfig, GateConfig, assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
2536
3199
  }
2537
3200
  type GateConfig = {
2538
3201
  callbacks?: CallbackConfig[];
@@ -2581,7 +3244,7 @@ declare function getCallbackTypeAddresses(chain: Name, type: CallbackType): Addr
2581
3244
  * @returns Array of allowed callback addresses (lowercased). Empty when none configured
2582
3245
  */
2583
3246
  declare const getCallbackAddresses: (chain: Name) => Address[];
2584
- declare const assets$1: Record<string, Address[]>;
3247
+ declare const assets: Record<string, Address[]>;
2585
3248
  declare const configs: Record<Name, GateConfig>;
2586
3249
  declare namespace Gatekeeper_d_exports {
2587
3250
  export { Gatekeeper, Rules, create };
@@ -2597,9 +3260,9 @@ type GatekeeperParameters = {
2597
3260
  declare function create(parameters: GatekeeperParameters): Gatekeeper;
2598
3261
  //#endregion
2599
3262
  //#region src/gatekeeper/morphoRules.d.ts
2600
- declare const morphoRules: (chains: Chain$1[]) => (Rule<Offer, "chain_ids"> | Rule<Offer, "maturity"> | Rule<Offer, "callback"> | Rule<Offer, "token">)[];
3263
+ declare const morphoRules: (chains: Chain$1[]) => (Rule<Offer, "chain_ids"> | Rule<Offer, "maturity"> | Rule<Offer, "callback"> | Rule<Offer, "token"> | Rule<Offer, "mixed_maker"> | Rule<Offer, "amount_mutual_exclusivity">)[];
2601
3264
  declare namespace Rules_d_exports {
2602
- export { ValidityParameters, callback, chains, maturity, token, validity };
3265
+ export { ValidityParameters, amountMutualExclusivity, callback, chains, maturity, sameMaker, token, validity };
2603
3266
  }
2604
3267
  type ValidityParameters = {
2605
3268
  client: PublicClient<Transport, Chain$1>;
@@ -2629,15 +3292,27 @@ declare const callback: ({
2629
3292
  allowedAddresses: Address[];
2630
3293
  }) => Rule<Offer, "callback">;
2631
3294
  /**
2632
- * A validation rule that checks if the offer's token is allowed.
2633
- * @param offer - The offer to validate.
3295
+ * A validation rule that checks if the offer's tokens are allowed for its chain.
3296
+ * @param assetsByChainId - Allowed assets indexed by chain id.
2634
3297
  * @returns The issue that was found. If the offer is valid, this will be undefined.
2635
3298
  */
2636
3299
  declare const token: ({
2637
- assets
3300
+ assetsByChainId
2638
3301
  }: {
2639
- assets: Address[];
3302
+ assetsByChainId: Partial<Record<Id, Address[]>>;
2640
3303
  }) => Rule<Offer, "token">;
3304
+ /**
3305
+ * A batch validation rule that ensures all offers in a tree have the same maker address.
3306
+ * Returns an issue only for the first non-conforming offer.
3307
+ * This rule is signing-agnostic; signer verification is handled at the collector level.
3308
+ */
3309
+ declare const sameMaker: () => Rule<Offer, "mixed_maker">;
3310
+ /**
3311
+ * A validation rule that ensures mutual exclusivity of offer amount fields.
3312
+ * At most one of (assets, obligationUnits, obligationShares) can be non-zero.
3313
+ * Matches contract requirement: `atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)`.
3314
+ */
3315
+ declare const amountMutualExclusivity: () => Rule<Offer, "amount_mutual_exclusivity">;
2641
3316
  //#endregion
2642
3317
  //#region src/mempool/MempoolEVMClient.d.ts
2643
3318
  declare function from(parameters: from.Parameters): from.ReturnType;
@@ -2656,7 +3331,7 @@ declare namespace from {
2656
3331
  declare namespace MempoolClient_d_exports {
2657
3332
  export { AddParameters, Client$1 as Client, GetParameters, connect };
2658
3333
  }
2659
- type AddParameters = Compute<Omit<Offer, "hash" | "createdAt">[]>;
3334
+ type AddParameters = Compute<Omit<Offer, "createdAt">[]>;
2660
3335
  type GetParameters = {
2661
3336
  /** The block number to get offers from. */
2662
3337
  blockNumberGte?: number;
@@ -2711,6 +3386,12 @@ declare namespace connect {
2711
3386
  //#region src/utils/BigMath.d.ts
2712
3387
  declare function max$1(a: bigint, b: bigint): bigint;
2713
3388
  declare function min(a: bigint, b: bigint): bigint;
3389
+ /**
3390
+ * Checks if at most one of the given values is non-zero.
3391
+ * @param values - The bigint values to check.
3392
+ * @returns True if zero or one value is non-zero, false if two or more are non-zero.
3393
+ */
3394
+ declare function atMostOneNonZero(...values: bigint[]): boolean;
2714
3395
  //#endregion
2715
3396
  //#region src/utils/batch.d.ts
2716
3397
  /**
@@ -2748,6 +3429,15 @@ declare function batchMulticall<TResult>(parameters: {
2748
3429
  retryDelayMs: number;
2749
3430
  blockNumber?: bigint;
2750
3431
  }): Promise<TResult[]>;
3432
+ declare namespace Group_d_exports {
3433
+ export { fromNumber };
3434
+ }
3435
+ /**
3436
+ * Creates a bytes32 group identifier from a number.
3437
+ * @param n - A non-negative integer.
3438
+ * @throws {Error} If n is negative or not an integer.
3439
+ */
3440
+ declare const fromNumber: (n: number) => Hex;
2751
3441
  //#endregion
2752
3442
  //#region src/utils/lazy.d.ts
2753
3443
  /**
@@ -2775,6 +3465,41 @@ declare function poll<data>(fn: ({
2775
3465
  }: {
2776
3466
  interval: () => Promise<number>;
2777
3467
  }): () => boolean;
3468
+ declare namespace Random_d_exports {
3469
+ export { address, bool, bytes, float, hex, int, seed, withSeed };
3470
+ }
3471
+ /**
3472
+ * Runs a function with a deterministic RNG derived from the given seed.
3473
+ */
3474
+ declare function withSeed<T>(seed: string, fn: () => T): T;
3475
+ /**
3476
+ * Seeds the global RNG for deterministic test runs.
3477
+ */
3478
+ declare function seed(seed: string): void;
3479
+ /**
3480
+ * Returns a deterministic random float in [0, 1).
3481
+ */
3482
+ declare function float(): number;
3483
+ /**
3484
+ * Returns a deterministic random integer in [min, maxExclusive).
3485
+ */
3486
+ declare function int(maxExclusive: number, min?: number): number;
3487
+ /**
3488
+ * Returns a deterministic random boolean.
3489
+ */
3490
+ declare function bool(probability?: number): boolean;
3491
+ /**
3492
+ * Returns deterministic random bytes.
3493
+ */
3494
+ declare function bytes(length: number): Uint8Array;
3495
+ /**
3496
+ * Returns a deterministic random hex string for the given byte length.
3497
+ */
3498
+ declare function hex(byteLength: number): Hex;
3499
+ /**
3500
+ * Returns a deterministic random address.
3501
+ */
3502
+ declare function address(): Address;
2778
3503
  //#endregion
2779
3504
  //#region src/utils/retry.d.ts
2780
3505
  declare const retry: <T>(fn: () => Promise<T>, attempts?: number, delayMs?: number) => Promise<T>;
@@ -2787,8 +3512,8 @@ declare function max(): number;
2787
3512
  //#region src/utils/wait.d.ts
2788
3513
  declare function wait(time: number): Promise<unknown>;
2789
3514
  declare namespace index_d_exports$2 {
2790
- export { BaseError, GlobalErrorType, ReorgError, Snake, time_d_exports as Time, batch, batchMulticall, fromSnakeCase$3 as fromSnakeCase, lazy, max$1 as max, min, poll, retry, stringifyBigint, toSnakeCase$1 as toSnakeCase, wait };
3515
+ export { BaseError, GlobalErrorType, Group_d_exports as Group, Random_d_exports as Random, ReorgError, Snake, time_d_exports as Time, atMostOneNonZero, batch, batchMulticall, fromSnakeCase$3 as fromSnakeCase, lazy, max$1 as max, min, poll, retry, stringifyBigint, toSnakeCase$1 as toSnakeCase, wait };
2791
3516
  }
2792
3517
  //#endregion
2793
- export { index_d_exports as Abi, Brand, BrandTypeId, Callback_d_exports as Callback, Chain_d_exports as Chain, Collateral_d_exports as Collateral, Compute, Cursor_d_exports as Cursor, ERC4626_d_exports as ERC4626, Errors_d_exports as Errors, Format_d_exports as Format, GateConfig_d_exports as GateConfig, Gatekeeper_d_exports as Gatekeeper, LLTV_d_exports as LLTV, Liquidity_d_exports as Liquidity, Maturity_d_exports as Maturity, MempoolClient_d_exports as Mempool, Obligation_d_exports as Obligation, Offer_d_exports as Offer, Oracle_d_exports as Oracle, Position_d_exports as Position, Quote_d_exports as Quote, index_d_exports$1 as RouterApi, Client_d_exports as RouterClient, Rules_d_exports as Rules, time_d_exports as Time, Transfer_d_exports as Transfer, Tree_d_exports as Tree, index_d_exports$2 as Utils, Gate_d_exports as Validation, morphoRules };
3518
+ export { index_d_exports as Abi, Brand, BrandTypeId, Callback_d_exports as Callback, Chain_d_exports as Chain, ChainRegistry_d_exports as ChainRegistry, Collateral_d_exports as Collateral, Compute, ERC4626_d_exports as ERC4626, Errors_d_exports as Errors, Format_d_exports as Format, GateConfig_d_exports as GateConfig, Gatekeeper_d_exports as Gatekeeper, LLTV_d_exports as LLTV, Liquidity_d_exports as Liquidity, Maturity_d_exports as Maturity, MempoolClient_d_exports as Mempool, Obligation_d_exports as Obligation, Offer_d_exports as Offer, Oracle_d_exports as Oracle, Position_d_exports as Position, Quote_d_exports as Quote, index_d_exports$1 as RouterApi, Client_d_exports as RouterClient, Rules_d_exports as Rules, time_d_exports as Time, Transfer_d_exports as Transfer, Tree_d_exports as Tree, index_d_exports$2 as Utils, Gate_d_exports as Validation, morphoRules };
2794
3519
  //# sourceMappingURL=index.browser.d.mts.map