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