@morpho-dev/router 0.3.0 → 0.4.1

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 (40) hide show
  1. package/README.md +67 -71
  2. package/dist/cli.js +3209 -1252
  3. package/dist/drizzle/migrations/0017_dusty_the_hunter.sql +1 -0
  4. package/dist/drizzle/migrations/0018_add_chain_collector_constraints.sql +3 -0
  5. package/dist/drizzle/migrations/0019_add-obligation-units-shares.sql +2 -0
  6. package/dist/drizzle/migrations/0020_add-session.sql +1 -0
  7. package/dist/drizzle/migrations/0021_drop_chain_collector_epoch_indexes.sql +2 -0
  8. package/dist/drizzle/migrations/0021_migrate-rate-to-price.sql +15 -0
  9. package/dist/drizzle/migrations/0022_consolidate-price.sql +15 -0
  10. package/dist/drizzle/migrations/meta/0017_snapshot.json +1525 -0
  11. package/dist/drizzle/migrations/meta/0018_snapshot.json +1572 -0
  12. package/dist/drizzle/migrations/meta/0019_snapshot.json +1586 -0
  13. package/dist/drizzle/migrations/meta/_journal.json +42 -0
  14. package/dist/evm/bytecode/erc20.txt +1 -0
  15. package/dist/evm/bytecode/factory.txt +1 -0
  16. package/dist/evm/bytecode/mempool.txt +1 -0
  17. package/dist/evm/bytecode/morpho.txt +1 -0
  18. package/dist/evm/bytecode/multicall3.txt +1 -0
  19. package/dist/evm/bytecode/oracle.txt +1 -0
  20. package/dist/evm/bytecode/terms.txt +1 -0
  21. package/dist/evm/bytecode/vault.txt +1 -0
  22. package/dist/evm/bytecode/vaultV1.txt +1 -0
  23. package/dist/index.browser.d.mts +1327 -816
  24. package/dist/index.browser.d.mts.map +1 -1
  25. package/dist/index.browser.d.ts +1358 -847
  26. package/dist/index.browser.d.ts.map +1 -1
  27. package/dist/index.browser.js +2209 -1668
  28. package/dist/index.browser.js.map +1 -1
  29. package/dist/index.browser.mjs +2173 -1632
  30. package/dist/index.browser.mjs.map +1 -1
  31. package/dist/index.node.d.mts +1885 -1222
  32. package/dist/index.node.d.mts.map +1 -1
  33. package/dist/index.node.d.ts +1885 -1222
  34. package/dist/index.node.d.ts.map +1 -1
  35. package/dist/index.node.js +1984 -1016
  36. package/dist/index.node.js.map +1 -1
  37. package/dist/index.node.mjs +1963 -1014
  38. package/dist/index.node.mjs.map +1 -1
  39. package/docs/integrator.md +78 -0
  40. package/package.json +11 -5
@@ -275,7 +275,7 @@ declare const Morpho: readonly [{
275
275
  readonly stateMutability: "view";
276
276
  }];
277
277
  declare namespace Callback_d_exports {
278
- export { BuyVaultV1CallbackData, CallbackType, SellERC20CallbackData, decode$3 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$3 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
278
+ export { BuyVaultV1CallbackData, CallbackType, SellERC20CallbackData, decode$2 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$2 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
279
279
  }
280
280
  declare enum CallbackType {
281
281
  BuyWithEmptyCallback = "buy_with_empty_callback",
@@ -283,7 +283,7 @@ declare enum CallbackType {
283
283
  SellERC20Callback = "sell_erc20_callback",
284
284
  }
285
285
  declare const isEmptyCallback: (offer: Offer) => boolean;
286
- declare function decode$3(type: CallbackType, data: Hex): {
286
+ declare function decode$2(type: CallbackType, data: Hex): {
287
287
  contract: Address;
288
288
  amount: bigint;
289
289
  }[];
@@ -295,8 +295,8 @@ type SellERC20CallbackData = {
295
295
  collaterals: Address[];
296
296
  amounts: bigint[];
297
297
  };
298
- declare function encode$3(type: CallbackType.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;
299
- declare function encode$3(type: CallbackType.SellERC20Callback, data: SellERC20CallbackData): Hex;
298
+ declare function encode$2(type: CallbackType.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;
299
+ declare function encode$2(type: CallbackType.SellERC20Callback, data: SellERC20CallbackData): Hex;
300
300
  declare function decodeBuyVaultV1Callback(data: Hex): Array<{
301
301
  contract: Address;
302
302
  amount: bigint;
@@ -348,7 +348,7 @@ declare class ReorgError extends BaseError {
348
348
  declare namespace Chain_d_exports {
349
349
  export { Chain$1 as Chain, ChainId, Id, InvalidBatchSizeError, InvalidBlockRangeError, InvalidBlockWindowError, MissingBlockNumberError, Name$1 as Name, chainIds, chainNames, chains$2 as chains, getChain, getWhitelistedChains, streamLogs };
350
350
  }
351
- type Chain$1 = Compute<Chain<ChainFormatters, {
351
+ type Chain$1 = Compute<Omit<Chain<ChainFormatters, {
352
352
  morpho: ChainContract;
353
353
  morphoBlue: ChainContract;
354
354
  mempool: ChainContract;
@@ -358,9 +358,20 @@ type Chain$1 = Compute<Chain<ChainFormatters, {
358
358
  v1_1: ChainContract;
359
359
  };
360
360
  };
361
- }> & {
361
+ }>, "custom"> & {
362
362
  id: Id;
363
363
  name: Name$1;
364
+ custom: {
365
+ morpho: ChainContract;
366
+ morphoBlue: ChainContract;
367
+ mempool: ChainContract;
368
+ vaults: {
369
+ factories: {
370
+ v1_0: ChainContract;
371
+ v1_1: ChainContract;
372
+ };
373
+ };
374
+ };
364
375
  }>;
365
376
  declare const ChainId: {
366
377
  readonly ETHEREUM: 1;
@@ -406,6 +417,14 @@ declare class MissingBlockNumberError extends BaseError {
406
417
  name: string;
407
418
  constructor();
408
419
  }
420
+ declare namespace ChainRegistry_d_exports {
421
+ export { ChainRegistry, create$6 as create };
422
+ }
423
+ type ChainRegistry = {
424
+ getById: (chainId: Id) => Chain$1 | undefined;
425
+ list: () => Chain$1[];
426
+ };
427
+ declare function create$6(chains: Chain$1[]): ChainRegistry;
409
428
  //#endregion
410
429
  //#region src/core/types.d.ts
411
430
  /** Combines members of an intersection into a readable type. */
@@ -415,7 +434,7 @@ type Brand<in out ID extends string | symbol> = {
415
434
  readonly [BrandTypeId]: { readonly [id in ID]: ID };
416
435
  };
417
436
  declare namespace LLTV_d_exports {
418
- export { InvalidLLTVError, InvalidOptionError$1 as InvalidOptionError, LLTV, LLTVSchema, Options, from$15 as from };
437
+ export { InvalidLLTVError, InvalidOptionError$1 as InvalidOptionError, LLTV, LLTVSchema, Options, from$16 as from };
419
438
  }
420
439
  type LLTV = bigint & Brand<"LLTV">;
421
440
  declare const Options: readonly [0.385, 0.5, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965, 0.98];
@@ -425,8 +444,8 @@ type Options = (typeof Options)[number];
425
444
  * @param lltv - The LLTV option or the scaled LLTV.
426
445
  * @returns The LLTV.
427
446
  */
428
- declare function from$15(lltv: Options | bigint): LLTV;
429
- declare namespace from$15 {
447
+ declare function from$16(lltv: Options | bigint): LLTV;
448
+ declare namespace from$16 {
430
449
  type ErrorType = InvalidOptionError$1 | InvalidLLTVError;
431
450
  }
432
451
  declare class InvalidOptionError$1 extends BaseError {
@@ -439,7 +458,7 @@ declare class InvalidLLTVError extends BaseError {
439
458
  }
440
459
  declare const LLTVSchema: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
441
460
  declare namespace Collateral_d_exports {
442
- export { Collateral, CollateralSchema, CollateralsSchema, from$14 as from, random$3 as random };
461
+ export { Collateral, CollateralSchema, CollateralsSchema, from$15 as from, random$3 as random };
443
462
  }
444
463
  type Collateral = {
445
464
  /** Asset being used as collateral. */
@@ -459,8 +478,8 @@ declare const CollateralsSchema: z$1.ZodArray<z$1.ZodObject<{
459
478
  oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
460
479
  lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
461
480
  }, z$1.core.$strip>>;
462
- declare const from$14: (parameters: from$14.Parameters) => from$14.ReturnType;
463
- declare namespace from$14 {
481
+ declare const from$15: (parameters: from$15.Parameters) => from$15.ReturnType;
482
+ declare namespace from$15 {
464
483
  type Parameters = {
465
484
  asset: Address;
466
485
  lltv: Options | bigint;
@@ -569,35 +588,127 @@ declare class DenominatorIsZeroError extends BaseError {
569
588
  readonly name = "ERC4626.DenominatorIsZeroError";
570
589
  constructor();
571
590
  }
572
- declare namespace Format_d_exports {
573
- export { Snake, fromSnakeCase$3 as fromSnakeCase, stringifyBigint, toSnakeCase$1 as toSnakeCase };
591
+ declare namespace Liquidity_d_exports {
592
+ export { LiquidityLink, LiquidityPool, OfferLiquidityPool, calculateMaxDebt, generateAllowancePoolId, generateBalancePoolId, generateBuyVaultCallbackPoolId, generateDebtPoolId, generateMarketLiquidityPoolId, generateObligationCollateralPoolId, generateSellERC20CallbackPoolId, generateUserVaultPositionPoolId, generateVaultPositionPoolId };
574
593
  }
575
- /** The snake case representation of a type with bigint values stringified. */
576
- type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;
577
- /** Make arrays/tuples and object props mutable, deeply. */
578
- 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;
579
- /** Stringifies bigint values to strings and preserves branded primitives. */
580
- 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;
581
- /** Key remapping that also preserves branded primitives. */
582
- 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;
583
- 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;
584
594
  /**
585
- * Formats object keys to snake case.
586
- * Preserves ethereum addresses as is.
587
- * Converts ethereum addresses to checksummed if used as values.
588
- * Stringifies bigint values to strings.
595
+ * Represents a liquidity pool with a unique ID and amount.
589
596
  */
590
- declare function toSnakeCase$1<T>(obj: T): Snake<T>;
597
+ type LiquidityPool = {
598
+ id: string;
599
+ amount: bigint;
600
+ };
591
601
  /**
592
- * Formats a snake case object to its camel case type.
593
- * Preserves ethereum addresses as is.
594
- * Converts checksummed ethereum addresses to lowercase if used as values.
595
- * @warning Does not unstringify bigint values.
602
+ * Represents a hierarchical relationship between two liquidity pools.
596
603
  */
597
- declare function fromSnakeCase$3<T>(obj: Snake<T>): T;
598
- declare function stringifyBigint<T>(value: T): StringifiedBigint<T>;
604
+ type LiquidityLink = {
605
+ parentPoolId: string;
606
+ childPoolId: string;
607
+ priority: number;
608
+ };
609
+ /**
610
+ * Represents the connection between an offer and its liquidity pools.
611
+ */
612
+ type OfferLiquidityPool = {
613
+ offerHash: Hex;
614
+ poolId: string;
615
+ /**
616
+ * The available capacity/liquidity from this pool for this offer.
617
+ * Meaning varies by pool type:
618
+ * - BuyWithEmptyCallback: Matches allowance amount from pool bellow
619
+ * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)
620
+ * - SellERC20Callback: Existing debt as negative value (reduces available capacity)
621
+ */
622
+ amount: bigint;
623
+ };
624
+ /**
625
+ * Calculate maximum debt capacity from collateral amount.
626
+ * @param amount - Collateral amount
627
+ * @param oraclePrice - Oracle price (scaled to 36 decimals)
628
+ * @param lltv - Loan-to-value ratio (scaled to 18 decimals)
629
+ * @returns Maximum debt capacity
630
+ */
631
+ declare function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint;
632
+ /**
633
+ * Generate pool ID for balance pools.
634
+ */
635
+ declare function generateBalancePoolId(parameters: {
636
+ user: Address;
637
+ chainId: Id;
638
+ token: Address;
639
+ }): string;
640
+ /**
641
+ * Generate pool ID for allowance pools.
642
+ */
643
+ declare function generateAllowancePoolId(parameters: {
644
+ user: Address;
645
+ chainId: Id;
646
+ token: Address;
647
+ }): string;
648
+ /**
649
+ * Generate pool ID for sell ERC20 callback pools.
650
+ * Each offer has its own callback pool to prevent liquidity conflicts.
651
+ */
652
+ declare function generateSellERC20CallbackPoolId(parameters: {
653
+ user: Address;
654
+ chainId: Id;
655
+ obligationId: Hex;
656
+ token: Address;
657
+ offerHash: Hex;
658
+ }): string;
659
+ /**
660
+ * Generate pool ID for obligation collateral pools.
661
+ * Obligation collateral pools represent collateral already deposited in the obligation.
662
+ * These pools are shared across all offers with the same obligation.
663
+ */
664
+ declare function generateObligationCollateralPoolId(parameters: {
665
+ user: Address;
666
+ chainId: Id;
667
+ obligationId: Hex;
668
+ token: Address;
669
+ }): string;
670
+ /**
671
+ * Generate pool ID for buy vault callback pools.
672
+ */
673
+ declare function generateBuyVaultCallbackPoolId(parameters: {
674
+ user: Address;
675
+ chainId: Id;
676
+ vault: Address;
677
+ offerHash: Hex;
678
+ }): string;
679
+ /**
680
+ * Generate pool ID for debt pools.
681
+ */
682
+ declare function generateDebtPoolId(parameters: {
683
+ user: Address;
684
+ chainId: Id;
685
+ obligationId: Hex;
686
+ }): string;
687
+ /**
688
+ * Generate pool ID for user position in a vault.
689
+ */
690
+ declare function generateUserVaultPositionPoolId(parameters: {
691
+ user: Address;
692
+ chainId: Id;
693
+ vault: Address;
694
+ }): string;
695
+ /**
696
+ * Generate pool ID for vault position in a market.
697
+ */
698
+ declare function generateVaultPositionPoolId(parameters: {
699
+ vault: Address;
700
+ chainId: Id;
701
+ marketId: string;
702
+ }): string;
703
+ /**
704
+ * Generate pool ID for market total liquidity.
705
+ */
706
+ declare function generateMarketLiquidityPoolId(parameters: {
707
+ chainId: Id;
708
+ marketId: string;
709
+ }): string;
599
710
  declare namespace Maturity_d_exports {
600
- export { InvalidDateError, InvalidFormatError, InvalidOptionError, Maturity, MaturityOptions, MaturitySchema, MaturityType, from$13 as from };
711
+ export { InvalidDateError, InvalidFormatError, InvalidOptionError, Maturity, MaturityOptions, MaturitySchema, MaturityType, from$14 as from };
601
712
  }
602
713
  /**
603
714
  * Maturity is a number that represents a date in seconds.
@@ -627,8 +738,8 @@ type MaturityOptions = keyof typeof MaturityOptions;
627
738
  * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.
628
739
  * @throws {InvalidOptionError} If the maturity is not a valid option.
629
740
  */
630
- declare function from$13(ts: from$13.Parameters): Maturity;
631
- declare namespace from$13 {
741
+ declare function from$14(ts: from$14.Parameters): Maturity;
742
+ declare namespace from$14 {
632
743
  type Parameters = number | MaturityOptions;
633
744
  type ErrorType = InvalidFormatError | InvalidDateError | InvalidOptionError;
634
745
  }
@@ -644,72 +755,47 @@ declare class InvalidOptionError extends BaseError {
644
755
  readonly name = "Maturity.InvalidOptionError";
645
756
  constructor(input: string);
646
757
  }
647
- declare namespace Offer_d_exports {
648
- export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferHashSchema, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$2 as decode, domain, encode$2 as encode, from$12 as from, fromSnakeCase$2 as fromSnakeCase, hash, obligationId, random$2 as random, serialize, sign, signatureMsg, toSnakeCase, types };
758
+ declare namespace Format_d_exports {
759
+ export { Snake, fromSnakeCase$3 as fromSnakeCase, stringifyBigint, toSnakeCase$1 as toSnakeCase };
649
760
  }
650
- type Offer = {
651
- /** The address that made the offer. */
652
- readonly offering: Address;
653
- /** The amount of assets offered. */
654
- readonly assets: bigint;
655
- /**
656
- * The amount of assets that can be taken from the offer. takeable = min(max - consumed, available)
657
- * Where available is the total amount of assets retrievable from offering positions.
658
- */
659
- readonly takeable: bigint;
660
- /** The interest rate (with 18 decimals). */
661
- readonly rate: bigint;
662
- /** The date at which all interests will be paid. */
663
- readonly maturity: Maturity;
664
- /** The date at which the offer will expire. */
665
- readonly expiry: number;
666
- /** The date at which the offer will start. */
667
- readonly start: number;
668
- /** The nonce. Used for OCO (One-Cancelled-Other) mechanism. */
669
- readonly nonce: bigint;
670
- /** The side of the offer. `true` for buy, `false` for sell. */
671
- readonly buy: boolean;
672
- /** The chain id where the liquidity for this offer is located. */
673
- readonly chainId: Id;
674
- /** The token that is being borrowed. */
675
- readonly loanToken: Address;
676
- /** The exact set of collaterals required to borrow the loan token. */
677
- readonly collaterals: readonly Collateral[];
678
- /** The optional callback data to retrieve the maker funds. */
679
- readonly callback: {
680
- readonly address: Address;
681
- readonly data: Hex;
682
- readonly gasLimit: bigint;
683
- };
684
- /** The amount of assets consumed from the offer. */
685
- consumed: bigint;
686
- /** The hash of the offer. */
687
- readonly hash: Hex;
688
- /** The block number at which the offer was created. */
689
- readonly blockNumber: number;
690
- /** The signature of the offer. */
691
- signature?: Hex;
692
- };
693
- declare enum Status {
694
- VALID = "VALID",
695
- SIMULATION_ERROR = "SIMULATION_ERROR",
761
+ /** The snake case representation of a type with bigint values stringified. */
762
+ type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;
763
+ /** Make arrays/tuples and object props mutable, deeply. */
764
+ 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;
765
+ /** Stringifies bigint values to strings and preserves branded primitives. */
766
+ 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;
767
+ /** Key remapping that also preserves branded primitives. */
768
+ 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;
769
+ 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;
770
+ /**
771
+ * Formats object keys to snake case.
772
+ * Preserves ethereum addresses as is.
773
+ * Converts ethereum addresses to checksummed if used as values.
774
+ * Stringifies bigint values to strings.
775
+ */
776
+ declare function toSnakeCase$1<T>(obj: T): Snake<T>;
777
+ /**
778
+ * Formats a snake case object to its camel case type.
779
+ * Preserves ethereum addresses as is.
780
+ * Converts checksummed ethereum addresses to lowercase if used as values.
781
+ * @warning Does not unstringify bigint values.
782
+ */
783
+ declare function fromSnakeCase$3<T>(obj: Snake<T>): T;
784
+ declare function stringifyBigint<T>(value: T): StringifiedBigint<T>;
785
+ declare namespace Obligation_d_exports {
786
+ export { CollateralsAreNotSortedError, InvalidObligationError, Obligation, ObligationSchema, from$13 as from, fromSnakeCase$2 as fromSnakeCase, id, random$2 as random };
696
787
  }
697
- type Validation = {
698
- offerHash: Hex;
699
- status: Status;
788
+ type Obligation = {
789
+ /** The chain id where the liquidity for this obligation is located. */
790
+ chainId: Id;
791
+ /** The token that is being borrowed for this obligation. */
792
+ loanToken: Address;
793
+ /** The exact set of collaterals required to borrow the loan token. */
794
+ collaterals: Collateral[];
795
+ /** The maturity of the obligation. */
796
+ maturity: Maturity;
700
797
  };
701
- declare const OfferHashSchema: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
702
- declare const OfferSchema: (parameters?: {
703
- omitHash?: boolean;
704
- }) => z$1.ZodObject<{
705
- offering: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
706
- assets: z$1.ZodBigInt;
707
- rate: z$1.ZodBigInt;
708
- maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
709
- expiry: z$1.ZodNumber;
710
- start: z$1.ZodNumber;
711
- nonce: z$1.ZodBigInt;
712
- buy: z$1.ZodBoolean;
798
+ declare const ObligationSchema: z$1.ZodObject<{
713
799
  chainId: z$1.ZodNumber;
714
800
  loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
715
801
  collaterals: z$1.ZodArray<z$1.ZodObject<{
@@ -717,36 +803,220 @@ declare const OfferSchema: (parameters?: {
717
803
  oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
718
804
  lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
719
805
  }, z$1.core.$strip>>;
720
- callback: z$1.ZodObject<{
721
- address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
722
- data: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
723
- gasLimit: z$1.ZodBigInt;
724
- }, z$1.core.$strip>;
725
- signature: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
726
- consumed: z$1.ZodOptional<z$1.ZodBigInt>;
727
- takeable: z$1.ZodOptional<z$1.ZodBigInt>;
728
- blockNumber: z$1.ZodOptional<z$1.ZodNumber>;
806
+ maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
729
807
  }, z$1.core.$strip>;
730
808
  /**
731
- * Creates an offer from a plain object.
732
- * @throws {InvalidOfferError} If the offer is invalid.
733
- * @param input - The offer to create.
734
- * @returns The created offer with its hash.
809
+ * Creates an obligation from the given parameters.
810
+ * @constructor
811
+ * @param parameters - {@link from.Parameters}
812
+ * @returns The created obligation. {@link Obligation}
813
+ * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
814
+ *
815
+ * @example
816
+ * ```ts
817
+ * const obligation = Obligation.from({
818
+ * chainId: 1,
819
+ * loanToken: privateKeyToAccount(generatePrivateKey()).address,
820
+ * collaterals: [
821
+ * Collateral.from({
822
+ * asset: privateKeyToAccount(generatePrivateKey()).address,
823
+ * oracle: privateKeyToAccount(generatePrivateKey()).address,
824
+ * lltv: 0.965
825
+ * }),
826
+ * ],
827
+ * maturity: Maturity.from("end_of_next_quarter"),
828
+ * });
829
+ * ```
735
830
  */
736
- declare function from$12(input: Compute<Omit<Offer, "chainId" | "hash"> & {
737
- chainId: number;
738
- }>): Offer;
739
- declare namespace from$12 {
740
- type ErrorType = InvalidOfferError;
831
+ declare function from$13(parameters: from$13.Parameters): from$13.ReturnType;
832
+ declare namespace from$13 {
833
+ type Parameters = {
834
+ /** The chain id where the liquidity for this obligation is located. */
835
+ chainId: number;
836
+ /** The token that is being borrowed for this obligation. */
837
+ loanToken: Address;
838
+ /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */
839
+ collaterals: from$15.Parameters[] | readonly from$15.Parameters[];
840
+ /** The maturity of the obligation. */
841
+ maturity: from$14.Parameters;
842
+ };
843
+ type ReturnType = Obligation;
844
+ type ErrorType = InvalidObligationError;
845
+ }
846
+ /**
847
+ * Creates an obligation from a snake case object.
848
+ * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}
849
+ * @param input - {@link fromSnakeCase.Parameters}
850
+ * @returns The created obligation. {@link fromSnakeCase.ReturnType}
851
+ */
852
+ declare function fromSnakeCase$2(input: fromSnakeCase$2.Parameters): fromSnakeCase$2.ReturnType;
853
+ declare namespace fromSnakeCase$2 {
854
+ type Parameters = Snake<Omit<Obligation, "chainId"> & {
855
+ chainId: number;
856
+ }>;
857
+ type ReturnType = Obligation;
858
+ type ErrorType = InvalidObligationError;
859
+ }
860
+ /**
861
+ * Calculates the obligation id based on the smart contract's Obligation struct.
862
+ * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).
863
+ * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
864
+ * @param parameters - {@link id.Parameters}
865
+ * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}
866
+ *
867
+ * @example
868
+ * ```ts
869
+ * const obligation = Obligation.random();
870
+ * const id = Obligation.id(obligation);
871
+ * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234
872
+ * ```
873
+ */
874
+ declare function id(parameters: id.Parameters): id.ReturnType;
875
+ declare namespace id {
876
+ type Parameters = {
877
+ chainId: number;
878
+ loanToken: Address;
879
+ collaterals: {
880
+ asset: Address;
881
+ lltv: bigint;
882
+ oracle: Address;
883
+ }[];
884
+ maturity: number;
885
+ };
886
+ type ReturnType = Hex;
887
+ type ErrorType = CollateralsAreNotSortedError;
888
+ }
889
+ /**
890
+ * Generates a random obligation.
891
+ * @returns A randomly generated obligation. {@link random.ReturnType}
892
+ *
893
+ * @example
894
+ * ```ts
895
+ * const obligation = Obligation.random();
896
+ * ```
897
+ */
898
+ declare function random$2(): random$2.ReturnType;
899
+ declare namespace random$2 {
900
+ type ReturnType = Obligation;
901
+ }
902
+ declare class InvalidObligationError extends BaseError<z$1.ZodError | Error> {
903
+ readonly name = "Obligation.InvalidObligationError";
904
+ constructor(error: z$1.ZodError | Error);
905
+ }
906
+ declare class CollateralsAreNotSortedError extends BaseError {
907
+ readonly name = "Obligation.CollateralsAreNotSortedError";
908
+ constructor();
909
+ }
910
+ declare namespace Offer_d_exports {
911
+ export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferInput, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$1 as decode, domain, encode$1 as encode, from$12 as from, fromSnakeCase$1 as fromSnakeCase, hash, obligationId, random$1 as random, serialize, sign, signatureMsg, toSnakeCase, types };
912
+ }
913
+ type Offer = {
914
+ /** The address that made the offer. */
915
+ readonly maker: Address;
916
+ /** The amount of assets offered. Mutually exclusive with obligationUnits and obligationShares. */
917
+ readonly assets: bigint;
918
+ /** The max debt units to trade. Mutually exclusive with assets and obligationShares. */
919
+ readonly obligationUnits: bigint;
920
+ /** The max lending shares to trade. Mutually exclusive with assets and obligationUnits. */
921
+ readonly obligationShares: bigint;
922
+ /** The price (18 decimals). */
923
+ readonly price: bigint;
924
+ /** The date at which all interests will be paid. */
925
+ readonly maturity: Maturity;
926
+ /** The date at which the offer will expire. */
927
+ readonly expiry: number;
928
+ /** The date at which the offer will start. */
929
+ readonly start: number;
930
+ /** The group. Used for OCO (One-Cancelled-Other) mechanism. */
931
+ readonly group: Hex;
932
+ /** The session. Used for session-based offer management. */
933
+ readonly session: Hex;
934
+ /** The side of the offer. `true` for buy, `false` for sell. */
935
+ readonly buy: boolean;
936
+ /** The chain id where the liquidity for this offer is located. */
937
+ readonly chainId: Id;
938
+ /** The token that is being borrowed. */
939
+ readonly loanToken: Address;
940
+ /** The exact set of collaterals required to borrow the loan token. */
941
+ readonly collaterals: readonly Collateral[];
942
+ /** The optional callback data to retrieve the maker funds. */
943
+ readonly callback: {
944
+ readonly address: Address;
945
+ readonly data: Hex;
946
+ };
947
+ };
948
+ declare enum Status {
949
+ VALID = "VALID",
950
+ SIMULATION_ERROR = "SIMULATION_ERROR",
951
+ }
952
+ type Validation = {
953
+ offerHash: Hex;
954
+ status: Status;
955
+ };
956
+ declare const OfferSchema: () => z$1.ZodObject<{
957
+ maker: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
958
+ assets: z$1.ZodBigInt;
959
+ obligationUnits: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBigInt>>;
960
+ obligationShares: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBigInt>>;
961
+ price: z$1.ZodBigInt;
962
+ maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
963
+ expiry: z$1.ZodNumber;
964
+ start: z$1.ZodNumber;
965
+ 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>>;
966
+ 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>>;
967
+ buy: z$1.ZodBoolean;
968
+ chainId: z$1.ZodNumber;
969
+ loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
970
+ collaterals: z$1.ZodArray<z$1.ZodObject<{
971
+ asset: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
972
+ oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
973
+ lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
974
+ }, z$1.core.$strip>>;
975
+ callback: z$1.ZodObject<{
976
+ address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
977
+ data: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
978
+ }, z$1.core.$strip>;
979
+ }, z$1.core.$strip>;
980
+ /**
981
+ * Input type for creating offers. Accepts flexible group types that will be coerced to Hex.
982
+ *
983
+ * The `group` field accepts multiple input formats:
984
+ * - **Hex string** (`0x...`): Padded to 32 bytes if needed
985
+ * - **Numeric string**: Converted to hex (e.g., `"123"` -> `"0x...7b"`)
986
+ * - **Number**: Non-negative safe integer, converted to hex
987
+ * - **BigInt**: Non-negative, must fit in bytes32
988
+ *
989
+ * All values validated to be non-negative and within bytes32 range.
990
+ */
991
+ type OfferInput = Compute<Omit<Offer, "chainId" | "group" | "session" | "obligationUnits" | "obligationShares"> & {
992
+ chainId: number;
993
+ group: Hex | bigint | number | string;
994
+ /** Optional: defaults to zero bytes32. */
995
+ session?: Hex | bigint | number | string;
996
+ /** Optional: defaults to 0n. Mutually exclusive with assets and obligationShares. */
997
+ obligationUnits?: bigint;
998
+ /** Optional: defaults to 0n. Mutually exclusive with assets and obligationUnits. */
999
+ obligationShares?: bigint;
1000
+ }>;
1001
+ /**
1002
+ * Creates an offer from a plain object.
1003
+ * @throws {InvalidOfferError} If the offer is invalid.
1004
+ * @param input - The offer to create.
1005
+ * @returns The created offer.
1006
+ */
1007
+ declare function from$12(input: OfferInput): Offer;
1008
+ declare namespace from$12 {
1009
+ type ErrorType = InvalidOfferError;
741
1010
  }
742
1011
  /**
743
1012
  * Creates an offer from a snake case object.
744
1013
  * @throws {InvalidOfferError} If the offer is invalid.
745
1014
  * @param input - The offer to create.
746
- * @returns The created offer with its hash.
1015
+ * @returns The created offer.
747
1016
  */
748
- declare function fromSnakeCase$2(input: Snake<Omit<Offer, "chainId" | "hash"> & {
1017
+ declare function fromSnakeCase$1(input: Snake<Omit<Offer, "chainId" | "session"> & {
749
1018
  chainId: number;
1019
+ session: string;
750
1020
  }>): Offer;
751
1021
  /**
752
1022
  * Converts an offer to a snake case object.
@@ -762,13 +1032,16 @@ declare function toSnakeCase(offer: Offer): Snake<Offer>;
762
1032
  * @returns JSON-serializable offer object
763
1033
  */
764
1034
  declare const serialize: (offer: Offer) => {
765
- offering: `0x${string}`;
1035
+ maker: `0x${string}`;
766
1036
  assets: string;
767
- rate: string;
1037
+ obligationUnits: string;
1038
+ obligationShares: string;
1039
+ price: string;
768
1040
  maturity: number;
769
1041
  expiry: number;
770
1042
  start: number;
771
- nonce: string;
1043
+ group: `0x${string}`;
1044
+ session: `0x${string}`;
772
1045
  buy: boolean;
773
1046
  chainId: Id;
774
1047
  loanToken: `0x${string}`;
@@ -780,9 +1053,7 @@ declare const serialize: (offer: Offer) => {
780
1053
  callback: {
781
1054
  address: `0x${string}`;
782
1055
  data: `0x${string}`;
783
- gasLimit: string;
784
1056
  };
785
- signature: `0x${string}` | undefined;
786
1057
  hash: `0x${string}`;
787
1058
  };
788
1059
  type RandomConfig = {
@@ -792,22 +1063,20 @@ type RandomConfig = {
792
1063
  assetsDecimals?: Record<Address, number>;
793
1064
  buy?: boolean;
794
1065
  assets?: bigint;
795
- consumed?: bigint;
796
- takeable?: bigint;
797
- offering?: Address;
1066
+ obligationUnits?: bigint;
1067
+ obligationShares?: bigint;
1068
+ maker?: Address;
798
1069
  maturity?: Maturity;
799
1070
  start?: number;
800
1071
  expiry?: number;
801
- nonce?: bigint;
802
- rate?: bigint;
1072
+ group?: Hex | bigint | number | string;
1073
+ session?: Hex | bigint | number | string;
1074
+ price?: bigint;
803
1075
  callback?: {
804
1076
  address: Address;
805
1077
  data: Hex;
806
- gasLimit: bigint;
807
1078
  };
808
1079
  collaterals?: readonly Collateral[];
809
- signature?: Hex;
810
- blockNumber?: number;
811
1080
  };
812
1081
  /**
813
1082
  * Generates a random Offer.
@@ -815,7 +1084,7 @@ type RandomConfig = {
815
1084
  * @warning The generated Offer should not be used for production usage.
816
1085
  * @returns {Offer} A randomly generated Offer object.
817
1086
  */
818
- declare function random$2(config?: RandomConfig): Offer;
1087
+ declare function random$1(config?: RandomConfig): Offer;
819
1088
  /**
820
1089
  * Creates an EIP-712 domain object.
821
1090
  * @param chainId - The chain ID.
@@ -839,13 +1108,19 @@ declare const types: {
839
1108
  readonly type: "address";
840
1109
  }];
841
1110
  readonly Offer: readonly [{
842
- readonly name: "offering";
1111
+ readonly name: "maker";
843
1112
  readonly type: "address";
844
1113
  }, {
845
1114
  readonly name: "assets";
846
1115
  readonly type: "uint256";
847
1116
  }, {
848
- readonly name: "rate";
1117
+ readonly name: "obligationUnits";
1118
+ readonly type: "uint256";
1119
+ }, {
1120
+ readonly name: "obligationShares";
1121
+ readonly type: "uint256";
1122
+ }, {
1123
+ readonly name: "price";
849
1124
  readonly type: "uint256";
850
1125
  }, {
851
1126
  readonly name: "maturity";
@@ -854,8 +1129,11 @@ declare const types: {
854
1129
  readonly name: "expiry";
855
1130
  readonly type: "uint256";
856
1131
  }, {
857
- readonly name: "nonce";
858
- readonly type: "uint256";
1132
+ readonly name: "group";
1133
+ readonly type: "bytes32";
1134
+ }, {
1135
+ readonly name: "session";
1136
+ readonly type: "bytes32";
859
1137
  }, {
860
1138
  readonly name: "buy";
861
1139
  readonly type: "bool";
@@ -885,9 +1163,6 @@ declare const types: {
885
1163
  }, {
886
1164
  readonly name: "data";
887
1165
  readonly type: "bytes";
888
- }, {
889
- readonly name: "gasLimit";
890
- readonly type: "uint256";
891
1166
  }];
892
1167
  };
893
1168
  /**
@@ -899,7 +1174,7 @@ declare const types: {
899
1174
  */
900
1175
  declare function sign(offers: Offer[], wallet: WalletClient): Promise<Hex>;
901
1176
  declare function signatureMsg(offers: Offer[]): Hex;
902
- declare function hash(offer: Omit<Offer, "hash">): Hex;
1177
+ declare function hash(offer: Offer): Hex;
903
1178
  /**
904
1179
  * Calculates the obligation id for an offer based on the smart contract's Obligation struct.
905
1180
  * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals (sorted by token address), maturity)).
@@ -907,32 +1182,32 @@ declare function hash(offer: Omit<Offer, "hash">): Hex;
907
1182
  * @returns The obligation id as a 32-byte hex string.
908
1183
  */
909
1184
  declare function obligationId(offer: Offer): Hex;
910
- declare function encode$2(offer: Offer): `0x${string}`;
911
- declare function decode$2(data: Hex, blockNumber: number | bigint): Offer;
1185
+ declare function encode$1(offer: Offer): `0x${string}`;
1186
+ declare function decode$1(data: Hex): Offer;
912
1187
  type OfferConsumed = {
913
1188
  id: string;
914
1189
  chainId: Id;
915
- offering: Address;
916
- nonce: bigint;
1190
+ maker: Address;
1191
+ group: Hex;
917
1192
  amount: bigint;
918
1193
  blockNumber: number;
919
1194
  };
920
1195
  /**
921
- * ABI for the Consumed event emitted by the Obligation contract.
1196
+ * ABI for the Consume event emitted by the Obligation contract.
922
1197
  */
923
1198
  declare const consumedEvent: {
924
1199
  readonly type: "event";
925
- readonly name: "Consumed";
1200
+ readonly name: "Consume";
926
1201
  readonly inputs: readonly [{
927
1202
  readonly name: "user";
928
1203
  readonly type: "address";
929
1204
  readonly indexed: true;
930
1205
  readonly internalType: "address";
931
1206
  }, {
932
- readonly name: "nonce";
933
- readonly type: "uint256";
1207
+ readonly name: "group";
1208
+ readonly type: "bytes32";
934
1209
  readonly indexed: true;
935
- readonly internalType: "uint256";
1210
+ readonly internalType: "bytes32";
936
1211
  }, {
937
1212
  readonly name: "amount";
938
1213
  readonly type: "uint256";
@@ -960,463 +1235,228 @@ declare class AccountNotSetError extends BaseError {
960
1235
  readonly name = "Offer.AccountNotSetError";
961
1236
  constructor();
962
1237
  }
963
- declare namespace Liquidity_d_exports {
964
- export { LiquidityLink, LiquidityPool, OfferLiquidityPool, calculateMaxDebt, generateAllowancePoolId, generateBalancePoolId, generateBuyVaultCallbackPoolId, generateDebtPoolId, generateMarketLiquidityPoolId, generateObligationCollateralPoolId, generateSellERC20CallbackPoolId, generateUserVaultPositionPoolId, generateVaultPositionPoolId };
1238
+ declare namespace Oracle_d_exports {
1239
+ export { Conversion, Oracle, from$11 as from };
965
1240
  }
966
1241
  /**
967
- * Represents a liquidity pool with a unique ID and amount.
1242
+ * An oracle contract that provides price information for assets.
968
1243
  */
969
- type LiquidityPool = {
970
- id: string;
971
- amount: bigint;
1244
+ type Oracle = {
1245
+ /** The chain id where the oracle is deployed. */
1246
+ readonly chainId: Id;
1247
+ /** The address of the oracle contract. */
1248
+ readonly address: Address;
1249
+ /** The price returned by the oracle (in the oracle's native units), null if no price available. */
1250
+ readonly price: bigint | null;
1251
+ /** The block number at which the price was fetched. */
1252
+ readonly blockNumber: number;
972
1253
  };
973
1254
  /**
974
- * Represents a hierarchical relationship between two liquidity pools.
1255
+ * Create an Oracle from a plain object.
1256
+ * @param data - The data to create the oracle from.
1257
+ * @returns The created oracle.
975
1258
  */
976
- type LiquidityLink = {
977
- parentPoolId: string;
978
- childPoolId: string;
979
- priority: number;
980
- };
1259
+ declare function from$11(data: from$11.Parameters): from$11.ReturnType;
1260
+ declare namespace from$11 {
1261
+ type Parameters = {
1262
+ chainId: Id;
1263
+ address: Address;
1264
+ price: string | null;
1265
+ blockNumber: number;
1266
+ };
1267
+ type ReturnType = Oracle;
1268
+ }
981
1269
  /**
982
- * Represents the connection between an offer and its liquidity pools.
1270
+ * Conversion utilities for converting between collateral and loan token amounts
1271
+ * using oracle prices and LLTV
983
1272
  */
984
- type OfferLiquidityPool = {
985
- offerHash: Offer["hash"];
986
- poolId: string;
1273
+ declare namespace Conversion {
987
1274
  /**
988
- * The available capacity/liquidity from this pool for this offer.
989
- * Meaning varies by pool type:
990
- * - BuyWithEmptyCallback: Matches allowance amount from pool bellow
991
- * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)
992
- * - SellERC20Callback: Existing debt as negative value (reduces available capacity)
1275
+ * Converts a collateral amount to loan token
1276
+ * Uses the formula: (amount * price / 10^36) * lltv / 10^18
1277
+ *
1278
+ * @param amount - The collateral amount to convert
1279
+ * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)
1280
+ * @returns The equivalent loan token amount
993
1281
  */
994
- amount: bigint;
1282
+ function collateralToLoan(amount: bigint, params: {
1283
+ price: bigint;
1284
+ lltv: bigint;
1285
+ }): bigint;
1286
+ /**
1287
+ * Converts a loan token amount to collateral
1288
+ * Uses the inverse formula: (amount * 10^36 / price) * 10^18 / lltv
1289
+ * Returns 0n if price or lltv is zero (invalid conversion).
1290
+ *
1291
+ * @param amount - The loan token amount to convert
1292
+ * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)
1293
+ * @returns The equivalent collateral amount, or 0n if conversion is invalid
1294
+ */
1295
+ function loanToCollateral(amount: bigint, params: {
1296
+ price: bigint;
1297
+ lltv: bigint;
1298
+ }): bigint;
1299
+ }
1300
+ declare namespace Position_d_exports {
1301
+ export { Position, Type, from$10 as from };
1302
+ }
1303
+ type Position = {
1304
+ /** The chain id. */
1305
+ chainId: Id;
1306
+ /** The contract address from which the position is called.
1307
+ * While balances are obviously tracked on ERC20 contracts, we prefer to track which contract is called to know the balance.
1308
+ * For example, when depositing into a vault, we would specify the vault contract address as the contract not the underlying vault's ERC20 token address.
1309
+ */
1310
+ contract: Address;
1311
+ /** The user address. */
1312
+ user: Address;
1313
+ /** The type of position. */
1314
+ type: Type;
1315
+ /** The balance of the position. */
1316
+ balance?: bigint;
1317
+ /** The underlying asset of the position.
1318
+ * For ERC20 positions, this equals the contract address.
1319
+ * For vault positions, this is the vault's underlying asset.
1320
+ */
1321
+ asset?: Address;
1322
+ /** The block number at which the position was last updated. */
1323
+ blockNumber: number;
995
1324
  };
1325
+ declare enum Type {
1326
+ ERC20 = "erc20",
1327
+ VAULT_V1 = "vault_v1",
1328
+ }
996
1329
  /**
997
- * Calculate maximum debt capacity from collateral amount.
998
- * @param amount - Collateral amount
999
- * @param oraclePrice - Oracle price (scaled to 36 decimals)
1000
- * @param lltv - Loan-to-value ratio (scaled to 18 decimals)
1001
- * @returns Maximum debt capacity
1002
- */
1003
- declare function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint;
1004
- /**
1005
- * Generate pool ID for balance pools.
1330
+ * @constructor
1331
+ * Creates a Position.
1332
+ * @param parameters - {@link from.Parameters}
1333
+ * @returns The created Position. {@link from.ReturnType}
1006
1334
  */
1007
- declare function generateBalancePoolId(parameters: {
1008
- user: Address;
1009
- chainId: Id;
1010
- token: Address;
1011
- }): string;
1012
- /**
1013
- * Generate pool ID for allowance pools.
1014
- */
1015
- declare function generateAllowancePoolId(parameters: {
1016
- user: Address;
1017
- chainId: Id;
1018
- token: Address;
1019
- }): string;
1020
- /**
1021
- * Generate pool ID for sell ERC20 callback pools.
1022
- * Each offer has its own callback pool to prevent liquidity conflicts.
1023
- */
1024
- declare function generateSellERC20CallbackPoolId(parameters: {
1025
- user: Address;
1026
- chainId: Id;
1027
- obligationId: Hex;
1028
- token: Address;
1029
- offerHash: Hex;
1030
- }): string;
1031
- /**
1032
- * Generate pool ID for obligation collateral pools.
1033
- * Obligation collateral pools represent collateral already deposited in the obligation.
1034
- * These pools are shared across all offers with the same obligation.
1035
- */
1036
- declare function generateObligationCollateralPoolId(parameters: {
1037
- user: Address;
1038
- chainId: Id;
1039
- obligationId: Hex;
1040
- token: Address;
1041
- }): string;
1042
- /**
1043
- * Generate pool ID for buy vault callback pools.
1044
- */
1045
- declare function generateBuyVaultCallbackPoolId(parameters: {
1046
- user: Address;
1047
- chainId: Id;
1048
- vault: Address;
1049
- offerHash: Hex;
1050
- }): string;
1051
- /**
1052
- * Generate pool ID for debt pools.
1053
- */
1054
- declare function generateDebtPoolId(parameters: {
1055
- user: Address;
1056
- chainId: Id;
1057
- obligationId: Hex;
1058
- }): string;
1059
- /**
1060
- * Generate pool ID for user position in a vault.
1061
- */
1062
- declare function generateUserVaultPositionPoolId(parameters: {
1063
- user: Address;
1064
- chainId: Id;
1065
- vault: Address;
1066
- }): string;
1067
- /**
1068
- * Generate pool ID for vault position in a market.
1069
- */
1070
- declare function generateVaultPositionPoolId(parameters: {
1071
- vault: Address;
1072
- chainId: Id;
1073
- marketId: string;
1074
- }): string;
1075
- /**
1076
- * Generate pool ID for market total liquidity.
1077
- */
1078
- declare function generateMarketLiquidityPoolId(parameters: {
1079
- chainId: Id;
1080
- marketId: string;
1081
- }): string;
1082
- declare namespace Obligation_d_exports {
1083
- export { CollateralsAreNotSortedError, InvalidObligationError, Obligation, ObligationSchema, from$11 as from, fromSnakeCase$1 as fromSnakeCase, id, random$1 as random };
1335
+ declare function from$10(parameters: from$10.Parameters): from$10.ReturnType;
1336
+ declare namespace from$10 {
1337
+ type Parameters = {
1338
+ chainId: Id;
1339
+ contract: Address;
1340
+ user: Address;
1341
+ type: Type;
1342
+ balance?: bigint;
1343
+ asset?: Address;
1344
+ blockNumber: number;
1345
+ };
1346
+ type ReturnType = Position;
1084
1347
  }
1085
- type Obligation = {
1086
- /** The chain id where the liquidity for this obligation is located. */
1087
- chainId: Id;
1088
- /** The token that is being borrowed for this obligation. */
1089
- loanToken: Address;
1090
- /** The exact set of collaterals required to borrow the loan token. */
1091
- collaterals: Collateral[];
1092
- /** The maturity of the obligation. */
1093
- maturity: Maturity;
1348
+ declare namespace Quote_d_exports {
1349
+ export { InvalidQuoteError, Quote, QuoteSchema, from$9 as from, fromSnakeCase, random };
1350
+ }
1351
+ type Quote = {
1352
+ /** The obligation id. */
1353
+ obligationId: Hex;
1354
+ ask: {
1355
+ /** The ask price for the obligation. (18 decimals). */
1356
+ price: bigint;
1357
+ };
1358
+ bid: {
1359
+ /** The bid price for the obligation. (18 decimals). */
1360
+ price: bigint;
1361
+ };
1094
1362
  };
1095
- declare const ObligationSchema: z$1.ZodObject<{
1096
- chainId: z$1.ZodNumber;
1097
- loanToken: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1098
- collaterals: z$1.ZodArray<z$1.ZodObject<{
1099
- asset: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1100
- oracle: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1101
- lltv: z$1.ZodPipe<z$1.ZodBigInt, z$1.ZodTransform<LLTV, bigint>>;
1102
- }, z$1.core.$strip>>;
1103
- maturity: z$1.ZodPipe<z$1.ZodNumber, z$1.ZodTransform<Maturity, number>>;
1363
+ declare const QuoteSchema: z$1.ZodObject<{
1364
+ obligationId: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1365
+ ask: z$1.ZodObject<{
1366
+ price: z$1.ZodBigInt;
1367
+ }, z$1.core.$strip>;
1368
+ bid: z$1.ZodObject<{
1369
+ price: z$1.ZodBigInt;
1370
+ }, z$1.core.$strip>;
1104
1371
  }, z$1.core.$strip>;
1105
1372
  /**
1106
- * Creates an obligation from the given parameters.
1373
+ * Creates a quote for a given obligation.
1107
1374
  * @constructor
1108
1375
  * @param parameters - {@link from.Parameters}
1109
- * @returns The created obligation. {@link Obligation}
1110
- * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
1376
+ * @returns The created quote. {@link Quote}
1377
+ * @throws If the quote is invalid. {@link InvalidQuoteError}
1111
1378
  *
1112
1379
  * @example
1113
1380
  * ```ts
1114
- * const obligation = Obligation.from({
1115
- * chainId: 1,
1116
- * loanToken: privateKeyToAccount(generatePrivateKey()).address,
1117
- * collaterals: [
1118
- * Collateral.from({
1119
- * asset: privateKeyToAccount(generatePrivateKey()).address,
1120
- * oracle: privateKeyToAccount(generatePrivateKey()).address,
1121
- * lltv: 0.965
1122
- * }),
1123
- * ],
1124
- * maturity: Maturity.from("end_of_next_quarter"),
1125
- * });
1381
+ * const quote = Quote.from({ obligationId: "0x123", ask: { price: 100n }, bid: { price: 100n } });
1126
1382
  * ```
1127
1383
  */
1128
- declare function from$11(parameters: from$11.Parameters): from$11.ReturnType;
1129
- declare namespace from$11 {
1130
- type Parameters = {
1131
- /** The chain id where the liquidity for this obligation is located. */
1132
- chainId: number;
1133
- /** The token that is being borrowed for this obligation. */
1134
- loanToken: Address;
1135
- /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */
1136
- collaterals: from$14.Parameters[] | readonly from$14.Parameters[];
1137
- /** The maturity of the obligation. */
1138
- maturity: from$13.Parameters;
1139
- };
1140
- type ReturnType = Obligation;
1141
- type ErrorType = InvalidObligationError;
1142
- }
1143
- /**
1144
- * Creates an obligation from a snake case object.
1145
- * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}
1146
- * @param input - {@link fromSnakeCase.Parameters}
1147
- * @returns The created obligation. {@link fromSnakeCase.ReturnType}
1148
- */
1149
- declare function fromSnakeCase$1(input: fromSnakeCase$1.Parameters): fromSnakeCase$1.ReturnType;
1150
- declare namespace fromSnakeCase$1 {
1151
- type Parameters = Snake<Omit<Obligation, "chainId"> & {
1152
- chainId: number;
1153
- }>;
1154
- type ReturnType = Obligation;
1155
- type ErrorType = InvalidObligationError;
1384
+ declare function from$9(parameters: from$9.Parameters): from$9.ReturnType;
1385
+ declare namespace from$9 {
1386
+ type Parameters = Quote;
1387
+ type ReturnType = Quote;
1388
+ type ErrorType = InvalidQuoteError;
1156
1389
  }
1157
1390
  /**
1158
- * Calculates the obligation id based on the smart contract's Obligation struct.
1159
- * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).
1160
- * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}
1161
- * @param obligation - {@link id.Parameters}
1162
- * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}
1163
- *
1164
- * @example
1165
- * ```ts
1166
- * const obligation = Obligation.random();
1167
- * const id = Obligation.id(obligation);
1168
- * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234
1169
- * ```
1391
+ * Creates a quote from a snake case object.
1392
+ * @throws If the quote is invalid. {@link InvalidQuoteError}
1393
+ * @param snake - {@link fromSnakeCase.Parameters}
1394
+ * @returns The created quote. {@link fromSnakeCase.ReturnType}
1170
1395
  */
1171
- declare function id(obligation: id.Parameters): id.ReturnType;
1172
- declare namespace id {
1173
- type Parameters = Obligation;
1174
- type ReturnType = Hex;
1175
- type ErrorType = CollateralsAreNotSortedError;
1396
+ declare function fromSnakeCase(snake: fromSnakeCase.Parameters): fromSnakeCase.ReturnType;
1397
+ declare namespace fromSnakeCase {
1398
+ type Parameters = Snake<Quote>;
1399
+ type ReturnType = Quote;
1400
+ type ErrorType = from$9.ErrorType;
1176
1401
  }
1177
1402
  /**
1178
- * Generates a random obligation.
1179
- * @returns A randomly generated obligation. {@link random.ReturnType}
1403
+ * Generates a random quote.
1404
+ * @returns A randomly generated quote. {@link random.ReturnType}
1180
1405
  *
1181
1406
  * @example
1182
1407
  * ```ts
1183
- * const obligation = Obligation.random();
1408
+ * const quote = Quote.random();
1184
1409
  * ```
1185
1410
  */
1186
- declare function random$1(): random$1.ReturnType;
1187
- declare namespace random$1 {
1188
- type ReturnType = Obligation;
1411
+ declare function random(): random.ReturnType;
1412
+ declare namespace random {
1413
+ type Parameters = never;
1414
+ type ReturnType = Quote;
1415
+ type ErrorType = from$9.ErrorType;
1189
1416
  }
1190
- declare class InvalidObligationError extends BaseError<z$1.ZodError | Error> {
1191
- readonly name = "Obligation.InvalidObligationError";
1417
+ declare class InvalidQuoteError extends BaseError<z$1.ZodError | Error> {
1418
+ readonly name = "Quote.InvalidQuoteError";
1192
1419
  constructor(error: z$1.ZodError | Error);
1193
1420
  }
1194
- declare class CollateralsAreNotSortedError extends BaseError {
1195
- readonly name = "Obligation.CollateralsAreNotSortedError";
1196
- constructor();
1197
- }
1198
- declare namespace Oracle_d_exports {
1199
- export { Conversion, Oracle, from$10 as from };
1421
+ declare namespace Transfer_d_exports {
1422
+ export { Transfer, from$8 as from };
1200
1423
  }
1201
- /**
1202
- * An oracle contract that provides price information for assets.
1203
- */
1204
- type Oracle = {
1205
- /** The chain id where the oracle is deployed. */
1206
- readonly chainId: Id;
1207
- /** The address of the oracle contract. */
1208
- readonly address: Address;
1209
- /** The price returned by the oracle (in the oracle's native units), null if no price available. */
1210
- readonly price: bigint | null;
1211
- /** The block number at which the price was fetched. */
1212
- readonly blockNumber: number;
1424
+ type Transfer = {
1425
+ id: string;
1426
+ chainId: Id;
1427
+ contract: Address;
1428
+ from: Address;
1429
+ to: Address;
1430
+ value: bigint;
1431
+ blockNumber: number;
1213
1432
  };
1214
1433
  /**
1215
- * Create an Oracle from a plain object.
1216
- * @param data - The data to create the oracle from.
1217
- * @returns The created oracle.
1434
+ * @constructor
1435
+ *
1436
+ * Creates a {@link Transfer}.
1437
+ * @param parameters - {@link from.Parameters}
1438
+ * @returns The created Transfer. {@link from.ReturnType}
1439
+ *
1440
+ * @example
1441
+ * ```ts
1442
+ * const transfer = Transfer.from({ id: "1", chainId: 1, contract: "0x123", from: "0x456", to: "0x789", value: 100n, blockNumber: 100n });
1443
+ * ```
1218
1444
  */
1219
- declare function from$10(data: from$10.Parameters): from$10.ReturnType;
1220
- declare namespace from$10 {
1445
+ declare function from$8(parameters: from$8.Parameters): from$8.ReturnType;
1446
+ declare namespace from$8 {
1221
1447
  type Parameters = {
1448
+ id: string;
1222
1449
  chainId: Id;
1223
- address: Address;
1224
- price: string | null;
1450
+ contract: Address;
1451
+ from: Address;
1452
+ to: Address;
1453
+ value: bigint;
1225
1454
  blockNumber: number;
1226
1455
  };
1227
- type ReturnType = Oracle;
1228
- }
1229
- /**
1230
- * Conversion utilities for converting between collateral and loan token amounts
1231
- * using oracle prices and LLTV
1232
- */
1233
- declare namespace Conversion {
1234
- /**
1235
- * Converts a collateral amount to loan token
1236
- * Uses the formula: (amount * price / 10^36) * lltv / 10^18
1237
- *
1238
- * @param amount - The collateral amount to convert
1239
- * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)
1240
- * @returns The equivalent loan token amount
1241
- */
1242
- function collateralToLoan(amount: bigint, params: {
1243
- price: bigint;
1244
- lltv: bigint;
1245
- }): bigint;
1246
- /**
1247
- * Converts a loan token amount to collateral
1248
- * Uses the inverse formula: (amount * 10^36 / price) * 10^18 / lltv
1249
- * Returns 0n if price or lltv is zero (invalid conversion).
1250
- *
1251
- * @param amount - The loan token amount to convert
1252
- * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)
1253
- * @returns The equivalent collateral amount, or 0n if conversion is invalid
1254
- */
1255
- function loanToCollateral(amount: bigint, params: {
1256
- price: bigint;
1257
- lltv: bigint;
1258
- }): bigint;
1259
- }
1260
- declare namespace Position_d_exports {
1261
- export { Position, Type, from$9 as from };
1262
- }
1263
- type Position = {
1264
- /** The chain id. */
1265
- chainId: Id;
1266
- /** The contract address from which the position is called.
1267
- * While balances are obviously tracked on ERC20 contracts, we prefer to track which contract is called to know the balance.
1268
- * For example, when depositing into a vault, we would specify the vault contract address as the contract not the underlying vault's ERC20 token address.
1269
- */
1270
- contract: Address;
1271
- /** The user address. */
1272
- user: Address;
1273
- /** The type of position. */
1274
- type: Type;
1275
- /** The balance of the position. */
1276
- balance?: bigint;
1277
- /** The underlying asset of the position.
1278
- * For ERC20 positions, this equals the contract address.
1279
- * For vault positions, this is the vault's underlying asset.
1280
- */
1281
- asset?: Address;
1282
- /** The block number at which the position was last updated. */
1283
- blockNumber: number;
1284
- };
1285
- declare enum Type {
1286
- ERC20 = "erc20",
1287
- VAULT_V1 = "vault_v1",
1288
- }
1289
- /**
1290
- * @constructor
1291
- * Creates a Position.
1292
- * @param parameters - {@link from.Parameters}
1293
- * @returns The created Position. {@link from.ReturnType}
1294
- */
1295
- declare function from$9(parameters: from$9.Parameters): from$9.ReturnType;
1296
- declare namespace from$9 {
1297
- type Parameters = {
1298
- chainId: Id;
1299
- contract: Address;
1300
- user: Address;
1301
- type: Type;
1302
- balance?: bigint;
1303
- asset?: Address;
1304
- blockNumber: number;
1305
- };
1306
- type ReturnType = Position;
1307
- }
1308
- declare namespace Quote_d_exports {
1309
- export { InvalidQuoteError, Quote, QuoteSchema, from$8 as from, fromSnakeCase, random };
1310
- }
1311
- type Quote = {
1312
- /** The obligation id. */
1313
- obligationId: Hex;
1314
- ask: {
1315
- /** The highest interest rate the seller will accept to pay for the obligation. (18 decimals). */
1316
- rate: bigint;
1317
- };
1318
- bid: {
1319
- /** The lowest interest rate a buyer is willing to be paid for the obligation. (18 decimals). */
1320
- rate: bigint;
1321
- };
1322
- };
1323
- declare const QuoteSchema: z$1.ZodObject<{
1324
- obligationId: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
1325
- ask: z$1.ZodObject<{
1326
- rate: z$1.ZodBigInt;
1327
- }, z$1.core.$strip>;
1328
- bid: z$1.ZodObject<{
1329
- rate: z$1.ZodBigInt;
1330
- }, z$1.core.$strip>;
1331
- }, z$1.core.$strip>;
1332
- /**
1333
- * Creates a quote for a given obligation.
1334
- * @constructor
1335
- * @param parameters - {@link from.Parameters}
1336
- * @returns The created quote. {@link Quote}
1337
- * @throws If the quote is invalid. {@link InvalidQuoteError}
1338
- *
1339
- * @example
1340
- * ```ts
1341
- * const quote = Quote.from({ obligationId: "0x123", ask: { assets: 100n, rate: 100n }, bid: { assets: 100n, rate: 100n } });
1342
- * ```
1343
- */
1344
- declare function from$8(parameters: from$8.Parameters): from$8.ReturnType;
1345
- declare namespace from$8 {
1346
- type Parameters = Quote;
1347
- type ReturnType = Quote;
1348
- type ErrorType = InvalidQuoteError;
1349
- }
1350
- /**
1351
- * Creates a quote from a snake case object.
1352
- * @throws If the quote is invalid. {@link InvalidQuoteError}
1353
- * @param snake - {@link fromSnakeCase.Parameters}
1354
- * @returns The created quote. {@link fromSnakeCase.ReturnType}
1355
- */
1356
- declare function fromSnakeCase(snake: fromSnakeCase.Parameters): fromSnakeCase.ReturnType;
1357
- declare namespace fromSnakeCase {
1358
- type Parameters = Snake<Quote>;
1359
- type ReturnType = Quote;
1360
- type ErrorType = from$8.ErrorType;
1361
- }
1362
- /**
1363
- * Generates a random quote.
1364
- * @returns A randomly generated quote. {@link random.ReturnType}
1365
- *
1366
- * @example
1367
- * ```ts
1368
- * const quote = Quote.random();
1369
- * ```
1370
- */
1371
- declare function random(): random.ReturnType;
1372
- declare namespace random {
1373
- type Parameters = never;
1374
- type ReturnType = Quote;
1375
- type ErrorType = from$8.ErrorType;
1376
- }
1377
- declare class InvalidQuoteError extends BaseError<z$1.ZodError | Error> {
1378
- readonly name = "Quote.InvalidQuoteError";
1379
- constructor(error: z$1.ZodError | Error);
1380
- }
1381
- declare namespace Transfer_d_exports {
1382
- export { Transfer, from$7 as from };
1383
- }
1384
- type Transfer = {
1385
- id: string;
1386
- chainId: Id;
1387
- contract: Address;
1388
- from: Address;
1389
- to: Address;
1390
- value: bigint;
1391
- blockNumber: number;
1392
- };
1393
- /**
1394
- * @constructor
1395
- *
1396
- * Creates a {@link Transfer}.
1397
- * @param parameters - {@link from.Parameters}
1398
- * @returns The created Transfer. {@link from.ReturnType}
1399
- *
1400
- * @example
1401
- * ```ts
1402
- * const transfer = Transfer.from({ id: "1", chainId: 1, contract: "0x123", from: "0x456", to: "0x789", value: 100n, blockNumber: 100n });
1403
- * ```
1404
- */
1405
- declare function from$7(parameters: from$7.Parameters): from$7.ReturnType;
1406
- declare namespace from$7 {
1407
- type Parameters = {
1408
- id: string;
1409
- chainId: Id;
1410
- contract: Address;
1411
- from: Address;
1412
- to: Address;
1413
- value: bigint;
1414
- blockNumber: number;
1415
- };
1416
- type ReturnType = Transfer;
1417
- }
1418
- declare namespace Tree_d_exports {
1419
- export { DecodeError, EncodeError, Proof, Tree, TreeError, VERSION$1 as VERSION, decode$1 as decode, encode$1 as encode, encodeUnsigned, from$6 as from, proofs };
1456
+ type ReturnType = Transfer;
1457
+ }
1458
+ declare namespace Tree_d_exports {
1459
+ export { DecodeError, EncodeError, Proof, Tree, TreeError, VERSION$1 as VERSION, decode, encode, encodeUnsigned, from$7 as from, proofs };
1420
1460
  }
1421
1461
  /**
1422
1462
  * A merkle tree of offers built from offer hashes.
@@ -1446,7 +1486,7 @@ declare const VERSION$1 = 1;
1446
1486
  * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.
1447
1487
  * @throws {TreeError} If tree building fails due to offer inconsistencies.
1448
1488
  */
1449
- declare const from$6: (offers: Offer[]) => Tree;
1489
+ declare const from$7: (offers: Offer[]) => Tree;
1450
1490
  /**
1451
1491
  * Generates merkle proofs for all offers in a tree.
1452
1492
  *
@@ -1491,7 +1531,7 @@ declare const proofs: (tree: Tree) => Proof[];
1491
1531
  * @returns Hex-encoded calldata ready for onchain broadcast
1492
1532
  * @throws {EncodeError} If signature verification fails or root mismatch
1493
1533
  */
1494
- declare const encode$1: (tree: Tree, signature: Hex) => Promise<Hex>;
1534
+ declare const encode: (tree: Tree, signature: Hex) => Promise<Hex>;
1495
1535
  /**
1496
1536
  * Encodes a merkle tree without a signature into hex payload for client-side signing.
1497
1537
  *
@@ -1529,7 +1569,7 @@ declare const encodeUnsigned: (tree: Tree) => Hex;
1529
1569
  * @returns Validated tree, signature, and recovered signer address
1530
1570
  * @throws {DecodeError} If version invalid, signature invalid, or root mismatch
1531
1571
  */
1532
- declare const decode$1: (encoded: Hex) => Promise<{
1572
+ declare const decode: (encoded: Hex) => Promise<{
1533
1573
  tree: Tree;
1534
1574
  signature: Hex;
1535
1575
  signer: Address;
@@ -1543,380 +1583,266 @@ declare class TreeError extends BaseError {
1543
1583
  constructor(reason: string);
1544
1584
  }
1545
1585
  /**
1546
- * Error thrown during tree encoding.
1547
- * Indicates validation failures (signature, root mismatch, mixed makers).
1548
- */
1549
- declare class EncodeError extends BaseError {
1550
- name: string;
1551
- constructor(reason: string);
1552
- }
1553
- /**
1554
- * Error thrown during tree decoding.
1555
- * Indicates payload corruption, version mismatch, or validation failures.
1556
- */
1557
- declare class DecodeError extends BaseError {
1558
- name: string;
1559
- constructor(reason: string);
1560
- }
1561
- declare namespace Logger_d_exports {
1562
- export { LogEntry, LogFn, LogLevel, LogLevelValues, Logger, defaultLogger, getLogger, runWithLogger, silentLogger };
1563
- }
1564
- declare const LogLevelValues: readonly ["trace", "debug", "info", "warn", "error", "fatal", "silent"];
1565
- type LogLevel = (typeof LogLevelValues)[number];
1566
- type LogEntry = Compute<{
1567
- msg: string;
1568
- } & Record<string, unknown>>;
1569
- type LogFn = (entry: LogEntry) => void;
1570
- type Logger = {
1571
- trace: LogFn;
1572
- debug: LogFn;
1573
- info: LogFn;
1574
- warn: LogFn;
1575
- error: LogFn;
1576
- fatal: LogFn;
1577
- };
1578
- declare function defaultLogger(minLevel?: LogLevel, pretty?: boolean): Logger;
1579
- declare function silentLogger(): Logger;
1580
- declare function runWithLogger<T>(logger: Logger, fn: () => Promise<T>): Promise<T>;
1581
- declare function getLogger(): Logger;
1582
- //#endregion
1583
- //#region src/database/domains/Book.d.ts
1584
- type BookDomain = {
1585
- /** Get aggregated book levels for a given obligation side. */
1586
- get: (parameters: get$4.Parameters) => Promise<get$4.ReturnType>;
1587
- /** Get all offers for a given obligation side with cross-invalidation. */
1588
- getOffers: (parameters: getOffers$2.Parameters) => Promise<getOffers$2.ReturnType>;
1589
- };
1590
- declare namespace get$4 {
1591
- type Parameters = {
1592
- /** The side of the offer. */
1593
- side: "buy" | "sell";
1594
- /** The obligationId of the offer. */
1595
- obligationId: Hex;
1596
- /** Cursor string returned by a previous call, for pagination */
1597
- cursor?: string;
1598
- /** Page size; defaults to {@link DEFAULT_LIMIT} */
1599
- limit?: number;
1600
- };
1601
- type Level = {
1602
- /** The interest rate for this level */
1603
- rate: bigint;
1604
- /** Sum of takeable amounts at this rate */
1605
- assets: bigint;
1606
- /** Number of offers at this rate */
1607
- count: number;
1608
- };
1609
- type ReturnType = {
1610
- levels: Level[];
1611
- nextCursor: string | null;
1612
- };
1613
- }
1614
- declare namespace getOffers$2 {
1615
- type Parameters = {
1616
- /** The side of the offer. */
1617
- side: "buy" | "sell";
1618
- /** The obligationId of the offer. */
1619
- obligationId: Hex;
1620
- /** Cursor string returned by a previous call, for pagination */
1621
- cursor?: string;
1622
- /** Page size; defaults to {@link DEFAULT_LIMIT} */
1623
- limit?: number;
1624
- };
1625
- type ReturnType = {
1626
- offers: Offer[];
1627
- nextCursor: string | null;
1628
- };
1629
- }
1630
- //#endregion
1631
- //#region src/database/domains/Chains.d.ts
1632
- type ChainsDomain = {
1633
- /** Get the latest block number processed by a given chain alongside its epoch. */
1634
- getBlockNumber: (chainId: Id) => Promise<{
1635
- blockNumber: number;
1636
- epoch: bigint;
1637
- }>;
1638
- /** Get the latest block number processed for all chains, optionally filtered by chain id. */
1639
- getBlockNumbers: (parameters?: {
1640
- chainId?: Id;
1641
- }) => Promise<Array<{
1642
- chainId: Id;
1643
- blockNumber: number;
1644
- epoch: bigint;
1645
- updatedAt: Date;
1646
- }>>;
1647
- /** Save the latest block number processed for a given chain alongside its epoch.*/
1648
- saveBlockNumber: (parameters: {
1649
- chainId: Id;
1650
- blockNumber: number;
1651
- epoch: bigint;
1652
- }) => Promise<void>;
1653
- };
1654
- //#endregion
1655
- //#region src/indexer/collectors/Collector.d.ts
1656
- declare const names: readonly ["offers", "consumed_events", "positions", "prices"];
1657
- type Name = (typeof names)[number];
1658
- /** A general collector interface. */
1659
- type Collector<name extends Name = Name, chain extends Chain$1 = Chain$1> = {
1660
- /** The name of the collector. */
1661
- readonly name: name;
1662
- /** The chain the collector is running on. */
1663
- readonly chain: chain;
1664
- /** Start collecting data from external sources.
1665
- * @yields The last block number processed by the collector.
1666
- */
1667
- collect: () => AsyncGenerator<number, void, void>;
1668
- };
1669
- declare namespace Gate_d_exports {
1670
- export { Batch, Issue, Result, Rule, RuleNames, Single, batch$1 as batch, run, single };
1671
- }
1672
- /**
1673
- * A validation rule.
1674
- */
1675
- type Rule<T, Name$2 extends string = string> = {
1676
- kind: "single";
1677
- name: Name$2;
1678
- description: string;
1679
- run: Single<T, Name$2>;
1680
- } | {
1681
- kind: "batch";
1682
- name: Name$2;
1683
- description: string;
1684
- run: Batch<T, Name$2>;
1685
- };
1686
- type RuleNames<Rules$1 extends readonly {
1687
- name: string;
1688
- }[]> = Rules$1[number]["name"];
1689
- /**
1690
- * A single item validation rule.
1691
- * @param item - The item to validate.
1692
- * @returns The issue that was found. If the item is valid, this will be undefined.
1693
- */
1694
- type Single<T, RuleName extends string> = (item: T) => Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined | Promise<Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>;
1695
- /**
1696
- * A batch item validation rule.
1697
- * @param items - The items to validate.
1698
- * @returns A map of the items to the issue that was found.
1699
- */
1700
- type Batch<T, RuleName extends string> = (items: T[]) => Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined> | Promise<Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>>;
1701
- /**
1702
- * Create a validation rule iterating over a single item at a time.
1703
- * @param name - The name of the rule.
1704
- * @param description - A human-readable description of the rule.
1705
- * @param run - The function that validates the rule.
1706
- * @returns The created rule.
1707
- */
1708
- declare function single<Name$2 extends string, T>(name: Name$2, description: string, run: Single<T, Name$2>): Rule<T, Name$2>;
1709
- /**
1710
- * Create a validation rule iterating over a batch of items at a time.
1711
- * @param name - The name of the rule.
1712
- * @param description - A human-readable description of the rule.
1713
- * @param run - The function that validates the rule.
1714
- * @returns The created rule.
1715
- */
1716
- declare function batch$1<Name$2 extends string, T>(name: Name$2, description: string, run: Batch<T, Name$2>): Rule<T, Name$2>;
1717
- /**
1718
- * A validation issue.
1719
- */
1720
- type Issue<T, RuleName extends string = string> = {
1721
- /** The name of the rule that caused the issue. */
1722
- ruleName: RuleName;
1723
- /** The message of the issue. */
1724
- message: string;
1725
- /** The item that was not valid. */
1726
- item: T;
1727
- };
1728
- /**
1729
- * The result of a validation.
1730
- */
1731
- type Result<T, RuleName extends string = string> = {
1732
- /** The items that were valid. */
1733
- valid: T[];
1734
- /** The reports of the failed validations. */
1735
- issues: Issue<T, RuleName>[];
1736
- };
1737
- declare function run<T, Name$2 extends string, Rules$1 extends readonly Rule<T, Name$2>[]>(parameters: {
1738
- items: T[];
1739
- rules: Rules$1;
1740
- chunkSize?: number;
1741
- }): Promise<Result<T, RuleNames<Rules$1>>>;
1742
- declare namespace Gatekeeper_d_exports {
1743
- export { Gatekeeper, Rules, create$5 as create };
1744
- }
1745
- type Rules = readonly Rule<Offer, string>[];
1746
- type Gatekeeper = {
1747
- rules: Rules;
1748
- isAllowed: (offers: Offer[]) => Promise<Result<Offer, string>>;
1749
- };
1750
- type GatekeeperParameters = {
1751
- rules: Rules;
1752
- };
1753
- declare function create$5(parameters: GatekeeperParameters): Gatekeeper;
1754
- declare namespace GateConfig_d_exports {
1755
- export { CallbackConfig, GateConfig, assets$1 as assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
1756
- }
1757
- type GateConfig = {
1758
- callbacks?: CallbackConfig[];
1759
- maturities?: MaturityType[];
1760
- };
1761
- type CallbackConfig = {
1762
- type: CallbackType.BuyVaultV1Callback;
1763
- addresses: Address[];
1764
- vaultFactories: Address[];
1765
- } | {
1766
- type: CallbackType.SellERC20Callback;
1767
- addresses: Address[];
1768
- } | {
1769
- type: CallbackType.BuyWithEmptyCallback;
1770
- };
1771
- declare function getCallback(chain: Name$1, type: CallbackType.BuyVaultV1Callback): Extract<CallbackConfig, {
1772
- type: CallbackType.BuyVaultV1Callback;
1773
- }> | undefined;
1774
- declare function getCallback(chain: Name$1, type: CallbackType.SellERC20Callback): Extract<CallbackConfig, {
1775
- type: CallbackType.SellERC20Callback;
1776
- }> | undefined;
1777
- declare function getCallback(chain: Name$1, type: CallbackType.BuyWithEmptyCallback): Extract<CallbackConfig, {
1778
- type: CallbackType.BuyWithEmptyCallback;
1779
- }> | undefined;
1780
- declare function getCallback(chain: Name$1, type: CallbackType): CallbackConfig | undefined;
1781
- /**
1782
- * Attempts to infer the configured callback type from a callback address on a chain.
1783
- * Skips the empty callback type as it does not carry addresses.
1784
- *
1785
- * @param chain - Chain name for which to infer the callback type
1786
- * @param address - Callback contract address
1787
- * @returns The callback type when found, otherwise undefined
1788
- */
1789
- declare function getCallbackType(chain: Name$1, address: Address): CallbackType | undefined;
1790
- /**
1791
- * Returns the callback addresses for a given chain and callback type, if it exists.
1792
- * @param chain - Chain name for which to read the validation configuration
1793
- * @param type - Callback type to retrieve
1794
- * @returns The matching callback addresses or an empty array if not configured
1795
- */
1796
- declare function getCallbackTypeAddresses(chain: Name$1, type: CallbackType): Address[];
1797
- /**
1798
- * Returns the list of allowed non-empty callback addresses for a chain.
1799
- *
1800
- * @param chain - Chain name
1801
- * @returns Array of allowed callback addresses (lowercased). Empty when none configured
1802
- */
1803
- declare const getCallbackAddresses: (chain: Name$1) => Address[];
1804
- declare const assets$1: Record<string, Address[]>;
1805
- declare const configs: Record<Name$1, GateConfig>;
1806
- //#endregion
1807
- //#region src/gatekeeper/morphoRules.d.ts
1808
- declare const morphoRules: (chains: Chain$1[]) => (Rule<Offer, "chain_ids"> | Rule<Offer, "maturity"> | Rule<Offer, "callback"> | Rule<Offer, "token"> | Rule<Offer, "mixed_maker">)[];
1809
- declare namespace Rules_d_exports {
1810
- export { ValidityParameters, callback, chains$1 as chains, maturity, sameMaker, token, validity };
1811
- }
1812
- type ValidityParameters = {
1813
- client: PublicClient<Transport, Chain$1>;
1814
- };
1815
- /**
1816
- * set of rules to validate offers.
1817
- *
1818
- * @param parameters - Validity parameters with chain and client
1819
- * @returns Array of validation rules to evaluate against offers
1820
- */
1821
- declare function validity(parameters: ValidityParameters): (Rule<Offer, "expiry"> | Rule<Offer, "sell_erc20_callback_invalid"> | Rule<Offer, "buy_offers_callback_vault_invalid">)[];
1822
- declare const chains$1: ({
1823
- chains: chains$1
1824
- }: {
1825
- chains: Chain$1[];
1826
- }) => Rule<Offer, "chain_ids">;
1827
- declare const maturity: ({
1828
- maturities
1829
- }: {
1830
- maturities: MaturityType[];
1831
- }) => Rule<Offer, "maturity">;
1832
- declare const callback: ({
1833
- callbacks,
1834
- allowedAddresses
1835
- }: {
1836
- callbacks: CallbackType[];
1837
- allowedAddresses: Address[];
1838
- }) => Rule<Offer, "callback">;
1839
- /**
1840
- * A validation rule that checks if the offer's token is allowed.
1841
- * @param offer - The offer to validate.
1842
- * @returns The issue that was found. If the offer is valid, this will be undefined.
1586
+ * Error thrown during tree encoding.
1587
+ * Indicates validation failures (signature, root mismatch, mixed makers).
1843
1588
  */
1844
- declare const token: ({
1845
- assets
1846
- }: {
1847
- assets: Address[];
1848
- }) => Rule<Offer, "token">;
1589
+ declare class EncodeError extends BaseError {
1590
+ name: string;
1591
+ constructor(reason: string);
1592
+ }
1849
1593
  /**
1850
- * A batch validation rule that ensures all offers in a tree have the same maker (offering address).
1851
- * Returns an issue only for the first non-conforming offer.
1852
- * This rule is signing-agnostic; signer verification is handled at the collector level.
1594
+ * Error thrown during tree decoding.
1595
+ * Indicates payload corruption, version mismatch, or validation failures.
1853
1596
  */
1854
- declare const sameMaker: () => Rule<Offer, "mixed_maker">;
1855
- declare namespace Indexer_d_exports {
1856
- export { Indexer, IndexerConfig, create$4 as create, from$5 as from };
1597
+ declare class DecodeError extends BaseError {
1598
+ name: string;
1599
+ constructor(reason: string);
1857
1600
  }
1858
- type Indexer = {
1859
- start: () => () => void;
1860
- next: () => Promise<void>;
1861
- return: () => Promise<void>;
1862
- };
1863
- type IndexerConfig<client extends PublicClient<Transport, Chain$1, Account | undefined>> = {
1864
- client: client;
1865
- db: Database;
1866
- gatekeeper: Gatekeeper;
1867
- interval?: number;
1868
- maxBatchSize?: number;
1869
- maxBlockNumber?: number;
1870
- blockWindow?: number;
1871
- retryAttempts?: number;
1872
- retryDelayMs?: number;
1601
+ //#endregion
1602
+ //#region src/indexer/collectors/Collector.d.ts
1603
+ declare const names: readonly ["offers", "consumed_events", "positions", "prices"];
1604
+ type Name = (typeof names)[number];
1605
+ /** A general collector interface. */
1606
+ type Collector<name extends Name = Name, client extends PublicClient<Transport, Chain$1> = PublicClient<Transport, Chain$1>> = {
1607
+ /** The name of the collector. */
1608
+ readonly name: name;
1609
+ /** The chain the collector is running on. */
1610
+ readonly chain: client["chain"];
1611
+ /** The public client used to query chain head. */
1612
+ readonly client: client;
1613
+ /** The database connection for collector metadata. */
1614
+ readonly db: Database;
1615
+ /** The normal polling interval (ms) for this collector. */
1616
+ readonly interval: number;
1617
+ /** Start collecting data from external sources.
1618
+ * @yields The last block number processed by the collector.
1619
+ */
1620
+ collect: () => AsyncGenerator<number, void, void>;
1873
1621
  };
1874
- declare function from$5<client extends PublicClient<Transport, Chain$1, Account | undefined>>(config: IndexerConfig<client>): Indexer;
1875
- declare function create$4<client extends PublicClient<Transport, Chain$1, Account | undefined>>(params: {
1876
- db: Database;
1877
- collectors: Collector[];
1878
- client: client;
1879
- interval: number;
1880
- }): Indexer;
1881
1622
  //#endregion
1882
- //#region src/database/domains/Collectors.d.ts
1883
- type CollectorsDomain = {
1884
- /** Get the latest block number processed by a collector for a given chain alongside the epoch. */
1885
- getBlockNumber: (parameters: {
1886
- collectorName: Name;
1887
- chainId: Id;
1888
- }) => Promise<{
1889
- blockNumber: number;
1890
- epoch: bigint;
1623
+ //#region src/database/domains/Blocks.d.ts
1624
+ type ChainState = {
1625
+ chainId: Id;
1626
+ blockNumber: number;
1627
+ epoch: bigint;
1628
+ };
1629
+ type CollectorState = {
1630
+ collectorName: Name;
1631
+ chainId: Id;
1632
+ blockNumber: number;
1633
+ epoch: bigint;
1634
+ };
1635
+ type ChainSnapshot = ChainState & {
1636
+ updatedAt: Date;
1637
+ };
1638
+ type CollectorSnapshot = CollectorState & {
1639
+ updatedAt: Date;
1640
+ };
1641
+ type InitParameters = {
1642
+ chainId: Id;
1643
+ collectorName: Name;
1644
+ };
1645
+ type AdvanceChainParameters = {
1646
+ chainId: Id;
1647
+ blockNumber: number;
1648
+ epoch: bigint;
1649
+ };
1650
+ type AdvanceCollectorParameters = {
1651
+ collectorName: Name;
1652
+ chainId: Id;
1653
+ blockNumber: number;
1654
+ epoch: bigint;
1655
+ };
1656
+ type HandleReorgParameters = {
1657
+ chainId: Id;
1658
+ blockNumber: number;
1659
+ epoch: bigint;
1660
+ collectorNames?: Name[];
1661
+ };
1662
+ type BlocksDomain = {
1663
+ /** Initialize and return chain + collector state, seeding rows when missing. */
1664
+ init: (parameters: InitParameters) => Promise<{
1665
+ chain: ChainState;
1666
+ collector: CollectorState;
1891
1667
  }>;
1892
- /**
1893
- * Get the latest block number processed by all collectors.
1894
- * When a chainId is provided the result is filtered, otherwise all records are returned.
1895
- */
1896
- getBlockNumbers: (parameters?: {
1897
- chainId?: Id;
1898
- }) => Promise<Array<{
1899
- collectorName: Name;
1668
+ /** Return chain state, failing if it has not been initialized yet. */
1669
+ getChain: (chainId: Id) => Promise<ChainState>;
1670
+ /** Return collector state, failing if it has not been initialized yet. */
1671
+ getCollector: (parameters: {
1900
1672
  chainId: Id;
1901
- blockNumber: number;
1902
- epoch: bigint;
1903
- updatedAt: Date;
1904
- }>>;
1905
- /** Save the latest block number processed by a collector for a given chain.*/
1906
- saveBlockNumber: (parameters: {
1907
1673
  collectorName: Name;
1674
+ }) => Promise<CollectorState>;
1675
+ /** Return chain state rows, optionally filtered by chain id. */
1676
+ getChains: (parameters?: {
1677
+ chainId?: Id;
1678
+ }) => Promise<ChainSnapshot[]>;
1679
+ /** Return collector state rows, optionally filtered by chain id. */
1680
+ getCollectors: (parameters?: {
1681
+ chainId?: Id;
1682
+ }) => Promise<CollectorSnapshot[]>;
1683
+ /** Persist chain block state updates. */
1684
+ advanceChain: (parameters: AdvanceChainParameters) => Promise<void>;
1685
+ /** Persist collector block state updates and enforce invariants via storage CAS. */
1686
+ advanceCollector: (parameters: AdvanceCollectorParameters) => Promise<void>;
1687
+ /** Apply a reorg by advancing the chain epoch and fencing collectors. */
1688
+ handleReorg: (parameters: HandleReorgParameters) => Promise<void>;
1689
+ };
1690
+ declare namespace Logger_d_exports {
1691
+ export { LogEntry, LogFn, LogLevel, LogLevelValues, Logger, defaultLogger, getLogger, runWithLogger, silentLogger };
1692
+ }
1693
+ declare const LogLevelValues: readonly ["trace", "debug", "info", "warn", "error", "fatal", "silent"];
1694
+ type LogLevel = (typeof LogLevelValues)[number];
1695
+ type LogEntry = Compute<{
1696
+ msg: string;
1697
+ } & Record<string, unknown>>;
1698
+ type LogFn = (entry: LogEntry) => void;
1699
+ type Logger = {
1700
+ trace: LogFn;
1701
+ debug: LogFn;
1702
+ info: LogFn;
1703
+ warn: LogFn;
1704
+ error: LogFn;
1705
+ fatal: LogFn;
1706
+ };
1707
+ declare function defaultLogger(minLevel?: LogLevel, pretty?: boolean): Logger;
1708
+ declare function silentLogger(): Logger;
1709
+ declare function runWithLogger<T>(logger: Logger, fn: () => Promise<T>): Promise<T>;
1710
+ declare function getLogger(): Logger;
1711
+ //#endregion
1712
+ //#region src/database/domains/Offers.d.ts
1713
+ type CreateBatch = Readonly<{
1714
+ blockNumber: number;
1715
+ offers: Offer[];
1716
+ }>;
1717
+ /**
1718
+ * Raw row returned by database queries.
1719
+ * Built from primitives; no domain constructors in the DB layer.
1720
+ */
1721
+ type Row = {
1722
+ hash: Hex;
1723
+ maker: Address;
1724
+ assets: bigint;
1725
+ obligationUnits: bigint;
1726
+ obligationShares: bigint;
1727
+ price: bigint;
1728
+ maturity: Maturity;
1729
+ expiry: number;
1730
+ start: number;
1731
+ group: Hex;
1732
+ session: Hex;
1733
+ buy: boolean;
1734
+ chainId: Id;
1735
+ loanToken: Address;
1736
+ collaterals: Collateral[];
1737
+ callback: {
1738
+ address: Address;
1739
+ data: Hex;
1740
+ };
1741
+ consumed: bigint;
1742
+ available: bigint;
1743
+ takeable: bigint;
1744
+ blockNumber: number;
1745
+ };
1746
+ type OffersDomain = {
1747
+ /** Create multiple offers. */
1748
+ create: (batches: CreateBatch[]) => Promise<Hex[]>;
1749
+ /** Delete multiple offers by hashes or block number greater than or equal to the given value on a given chain.
1750
+ * @returns the number of offers deleted.
1751
+ */
1752
+ delete: (parameters: {
1753
+ hashes: Hex[];
1754
+ } | {
1755
+ blockNumberGte: number;
1908
1756
  chainId: Id;
1909
- blockNumber: number;
1910
- epoch: bigint;
1911
- }) => Promise<void>;
1757
+ }) => Promise<number>;
1758
+ /** Get all offers. */
1759
+ get: (parameters?: GetOffersParams) => Promise<{
1760
+ rows: Row[];
1761
+ nextCursor: string | null;
1762
+ }>;
1763
+ /** Get obligations */
1764
+ getObligations: (parameters?: {
1765
+ ids?: Hex[];
1766
+ chainId?: Id;
1767
+ loanToken?: Address;
1768
+ collateralToken?: Address;
1769
+ maturity?: number;
1770
+ cursor?: string;
1771
+ limit?: number;
1772
+ }) => Promise<{
1773
+ obligations: Obligation[];
1774
+ nextCursor: string | null;
1775
+ }>;
1776
+ /** Get quotes for given obligations. */
1777
+ getQuotes: (parameters: {
1778
+ obligationIds: Hex[];
1779
+ }) => Promise<Quote[]>;
1780
+ };
1781
+ type PaginationParams$1 = {
1782
+ /** Cursor string returned by a previous call, for pagination */
1783
+ cursor?: string;
1784
+ /** Page size; defaults to {@link DEFAULT_LIMIT} */
1785
+ limit?: number;
1786
+ };
1787
+ type GetOffersParams = {
1788
+ /** Filter by maker address */
1789
+ maker?: Address;
1790
+ } & PaginationParams$1;
1791
+ //#endregion
1792
+ //#region src/database/domains/Book.d.ts
1793
+ type BookDomain = {
1794
+ /** Get aggregated book levels for a given obligation side. */
1795
+ get: (parameters: get$4.Parameters) => Promise<get$4.ReturnType>;
1796
+ /** Get all offers for a given obligation side with cross-invalidation. */
1797
+ getOffers: (parameters: getOffers$2.Parameters) => Promise<getOffers$2.ReturnType>;
1912
1798
  };
1799
+ declare namespace get$4 {
1800
+ type Parameters = {
1801
+ /** The side of the offer. */
1802
+ side: "buy" | "sell";
1803
+ /** The obligationId of the offer. */
1804
+ obligationId: Hex;
1805
+ /** Cursor string returned by a previous call, for pagination */
1806
+ cursor?: string;
1807
+ /** Page size; defaults to {@link DEFAULT_LIMIT} */
1808
+ limit?: number;
1809
+ };
1810
+ type Level = {
1811
+ /** The computed price for this level (interpolated at query time) */
1812
+ price: bigint;
1813
+ /** Sum of takeable amounts at this price */
1814
+ assets: bigint;
1815
+ /** Number of offers at this price */
1816
+ count: number;
1817
+ };
1818
+ type ReturnType = {
1819
+ levels: Level[];
1820
+ nextCursor: string | null;
1821
+ };
1822
+ }
1823
+ declare namespace getOffers$2 {
1824
+ type Parameters = {
1825
+ /** The side of the offer. */
1826
+ side: "buy" | "sell";
1827
+ /** The obligationId of the offer. */
1828
+ obligationId: Hex;
1829
+ /** Cursor string returned by a previous call, for pagination */
1830
+ cursor?: string;
1831
+ /** Page size; defaults to {@link DEFAULT_LIMIT} */
1832
+ limit?: number;
1833
+ };
1834
+ type ReturnType = {
1835
+ rows: Row[];
1836
+ nextCursor: string | null;
1837
+ };
1838
+ }
1913
1839
  //#endregion
1914
1840
  //#region src/database/domains/Consumed.d.ts
1915
1841
  type Event = {
1916
1842
  id: string;
1917
1843
  chainId: Id;
1918
1844
  maker: Address;
1919
- group: bigint;
1845
+ group: Hex;
1920
1846
  amount: bigint;
1921
1847
  blockNumber: number;
1922
1848
  };
@@ -1946,13 +1872,13 @@ type LotsDomain = {
1946
1872
  * For each (position, group), keeps only the biggest offer by assets.
1947
1873
  * If lot exists and new offer is bigger, grows the lot and shifts higher lots.
1948
1874
  */
1949
- create: (parameters: create$3.Parameters) => Promise<void>;
1875
+ create: (parameters: create$5.Parameters) => Promise<void>;
1950
1876
  /**
1951
1877
  * Get lots with optional filtering.
1952
1878
  */
1953
1879
  get: (parameters?: get$3.Parameters) => Promise<Lot[]>;
1954
1880
  };
1955
- declare namespace create$3 {
1881
+ declare namespace create$5 {
1956
1882
  type OfferLotInfo = {
1957
1883
  positionChainId: Id;
1958
1884
  positionContract: Address;
@@ -1961,62 +1887,18 @@ declare namespace create$3 {
1961
1887
  size: bigint;
1962
1888
  };
1963
1889
  type Parameters = OfferLotInfo[];
1964
- type ReturnType = undefined;
1965
- }
1966
- declare namespace get$3 {
1967
- type Parameters = {
1968
- chainId?: Id;
1969
- user?: Address;
1970
- contract?: Address;
1971
- group?: string;
1972
- };
1973
- type ReturnType = Lot[];
1974
- }
1975
- declare function create$3(db: Core): LotsDomain;
1976
- //#endregion
1977
- //#region src/database/domains/Offers.d.ts
1978
- type OffersDomain = {
1979
- /** Create multiple offer. */
1980
- create: (offers: Offer[]) => Promise<Hex[]>;
1981
- /** Delete multiple offers by hashes or block number greater than or equal to the given value on a given chain.
1982
- * @returns the number of offers deleted.
1983
- */
1984
- delete: (parameters: {
1985
- hashes: Hex[];
1986
- } | {
1987
- blockNumberGte: number;
1988
- chainId: Id;
1989
- }) => Promise<number>;
1990
- /** Get all offers. */
1991
- get: (parameters?: GetOffersParams) => Promise<{
1992
- offers: Offer[];
1993
- nextCursor: string | null;
1994
- }>;
1995
- /** Get obligations */
1996
- getObligations: (parameters?: {
1997
- ids?: Hex[];
1998
- chainId?: Id;
1999
- cursor?: string;
2000
- limit?: number;
2001
- }) => Promise<{
2002
- obligations: Obligation[];
2003
- nextCursor: string | null;
2004
- }>;
2005
- /** Get quotes for given obligations. */
2006
- getQuotes: (parameters: {
2007
- obligationIds: Hex[];
2008
- }) => Promise<Quote[]>;
2009
- };
2010
- type PaginationParams$1 = {
2011
- /** Cursor string returned by a previous call, for pagination */
2012
- cursor?: string;
2013
- /** Page size; defaults to {@link DEFAULT_LIMIT} */
2014
- limit?: number;
2015
- };
2016
- type GetOffersParams = {
2017
- /** Filter by offering address */
2018
- offering?: Address;
2019
- } & PaginationParams$1;
1890
+ type ReturnType = undefined;
1891
+ }
1892
+ declare namespace get$3 {
1893
+ type Parameters = {
1894
+ chainId?: Id;
1895
+ user?: Address;
1896
+ contract?: Address;
1897
+ group?: string;
1898
+ };
1899
+ type ReturnType = Lot[];
1900
+ }
1901
+ declare function create$5(db: Core): LotsDomain;
2020
1902
  //#endregion
2021
1903
  //#region src/database/domains/Offsets.d.ts
2022
1904
  type Offset = {
@@ -2082,6 +1964,12 @@ type PositionsDomain = {
2082
1964
  * @returns The positions. {@link get.ReturnType}
2083
1965
  */
2084
1966
  get: (parameters?: get$1.Parameters) => Promise<get$1.ReturnType>;
1967
+ /**
1968
+ * Returns positions for a specific user with remaining balance calculation.
1969
+ * @param parameters - {@link getByUser.Parameters}
1970
+ * @returns The user's positions with remaining balances. {@link getByUser.ReturnType}
1971
+ */
1972
+ getByUser: (parameters: getByUser.Parameters) => Promise<getByUser.ReturnType>;
2085
1973
  /**
2086
1974
  * Set all positions to empty after a given block number (inclusive), deletes all transfers linked to the positions.
2087
1975
  * @param parameters - {@link setEmptyAfter.Parameters}
@@ -2107,6 +1995,24 @@ declare namespace get$1 {
2107
1995
  nextCursor: string | null;
2108
1996
  };
2109
1997
  }
1998
+ declare namespace getByUser {
1999
+ type Parameters = PaginationParams & {
2000
+ /** The user address to get positions for. */
2001
+ user: Address;
2002
+ };
2003
+ type PositionWithReserved = {
2004
+ chainId: Id;
2005
+ contract: Address;
2006
+ user: Address;
2007
+ blockNumber: number;
2008
+ /** The amount reserved by active offers: max(lot.upper) - offset - consumed */
2009
+ reserved: bigint;
2010
+ };
2011
+ type ReturnType = {
2012
+ positions: PositionWithReserved[];
2013
+ nextCursor: string | null;
2014
+ };
2015
+ }
2110
2016
  declare namespace setEmptyAfter {
2111
2017
  type Parameters = {
2112
2018
  /** The chain id . */
@@ -2124,108 +2030,324 @@ type TransfersDomain = {
2124
2030
  * @param transfers - {@link create.Parameters}
2125
2031
  * @returns The number of transfers created. {@link create.ReturnType}
2126
2032
  */
2127
- create: (transfers: create$2.Parameters) => Promise<create$2.ReturnType>;
2033
+ create: (transfers: create$4.Parameters) => Promise<create$4.ReturnType>;
2128
2034
  };
2129
- declare namespace create$2 {
2035
+ declare namespace create$4 {
2130
2036
  type Parameters = Transfer[];
2131
2037
  type ReturnType = number;
2132
2038
  }
2133
- declare const create$2: (db: Core) => TransfersDomain;
2039
+ declare const create$4: (db: Core) => TransfersDomain;
2134
2040
  //#endregion
2135
2041
  //#region src/database/domains/Trees.d.ts
2136
2042
  /**
2137
- * Attestation data for a single offer, containing the merkle root, signature, and proof.
2043
+ * Attestation data for a single offer, containing the merkle root, signature, and proof.
2044
+ */
2045
+ type Attestation = {
2046
+ root: Hex;
2047
+ signature: Hex;
2048
+ proof: Hex[];
2049
+ };
2050
+ /**
2051
+ * Input for creating trees with their signatures.
2052
+ */
2053
+ type CreateInput = {
2054
+ tree: Tree;
2055
+ signature: Hex;
2056
+ blockNumber: number;
2057
+ };
2058
+ type TreesDomain = {
2059
+ /**
2060
+ * Creates trees, offers, and attestation links in a single transaction.
2061
+ *
2062
+ * @param trees - Array of decoded trees with signatures (batch insertion)
2063
+ * @returns Array of tree roots that were created/upserted
2064
+ */
2065
+ create: (trees: CreateInput[]) => Promise<Hex[]>;
2066
+ /**
2067
+ * Retrieves merkle attestations for execution flow.
2068
+ *
2069
+ * @param hashes - Array of offer hashes to look up
2070
+ * @returns Map of offer hash to attestation (only entries with attestations are included)
2071
+ */
2072
+ getAttestations: (hashes: Hex[]) => Promise<Map<Hex, Attestation>>;
2073
+ };
2074
+ //#endregion
2075
+ //#region src/database/domains/Validations.d.ts
2076
+ type GetParams = {
2077
+ status?: Status;
2078
+ cursor?: string;
2079
+ limit?: number;
2080
+ };
2081
+ type ValidationsDomain = {
2082
+ /**
2083
+ * Get validation statuses with optional filtering and pagination.
2084
+ *
2085
+ * @param params - Optional parameters for filtering and pagination
2086
+ * @returns Array of validation statuses and next cursor for pagination
2087
+ */
2088
+ get: (params?: GetParams) => Promise<{
2089
+ validations: Validation[];
2090
+ nextCursor: string | null;
2091
+ }>;
2092
+ /**
2093
+ * Upsert validations
2094
+ *
2095
+ * @param validations - Array of validations to upsert
2096
+ */
2097
+ upsert: (validations: Validation[]) => Promise<void>;
2098
+ };
2099
+ declare namespace Database_d_exports {
2100
+ export { Core, Database, Driver, WithDomains, connect$2 as connect };
2101
+ }
2102
+ type Driver = ReturnType<typeof drizzle> | ReturnType<typeof drizzle$1>;
2103
+ type Domains = {
2104
+ book: BookDomain;
2105
+ blocks: BlocksDomain;
2106
+ offers: OffersDomain;
2107
+ consumed: ConsumedDomain;
2108
+ lots: LotsDomain;
2109
+ offsets: OffsetsDomain;
2110
+ oracles: OraclesDomain;
2111
+ trees: TreesDomain;
2112
+ validations: ValidationsDomain;
2113
+ positions: PositionsDomain;
2114
+ transfers: TransfersDomain;
2115
+ };
2116
+ type WithDomains<D extends Driver> = D & Domains;
2117
+ type Core = Omit<WithDomains<Driver>, "transaction"> & {
2118
+ transaction<T>(fn: (tx: WithDomains<Driver>) => Promise<T>): Promise<T>;
2119
+ };
2120
+ type Database = Core & {
2121
+ name: "pg" | "pglite";
2122
+ pool: Pool | PGlite;
2123
+ applyMigrations: (folderPath: string) => Promise<void>;
2124
+ clean: () => Promise<void>;
2125
+ };
2126
+ /**
2127
+ * Connect to the database.
2128
+ * @notice If no connection string is provided, an in-process PGLite database is created.
2129
+ * @param {string=} [connectionString] - The optional connection string for the Postgres database.
2130
+ * @returns The database client {@link connect.ReturnType}
2131
+ */
2132
+ declare function connect$2(chainRegistry: ChainRegistry, connectionString?: string): Database;
2133
+ declare namespace Gate_d_exports {
2134
+ export { Batch, Issue, Result, Rule, RuleNames, Single, batch$1 as batch, run, single };
2135
+ }
2136
+ /**
2137
+ * A validation rule.
2138
+ */
2139
+ type Rule<T, Name$2 extends string = string> = {
2140
+ kind: "single";
2141
+ name: Name$2;
2142
+ description: string;
2143
+ run: Single<T, Name$2>;
2144
+ } | {
2145
+ kind: "batch";
2146
+ name: Name$2;
2147
+ description: string;
2148
+ run: Batch<T, Name$2>;
2149
+ };
2150
+ type RuleNames<Rules$1 extends readonly {
2151
+ name: string;
2152
+ }[]> = Rules$1[number]["name"];
2153
+ /**
2154
+ * A single item validation rule.
2155
+ * @param item - The item to validate.
2156
+ * @returns The issue that was found. If the item is valid, this will be undefined.
2157
+ */
2158
+ type Single<T, RuleName extends string> = (item: T) => Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined | Promise<Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>;
2159
+ /**
2160
+ * A batch item validation rule.
2161
+ * @param items - The items to validate.
2162
+ * @returns A map of the items to the issue that was found.
2163
+ */
2164
+ type Batch<T, RuleName extends string> = (items: T[]) => Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined> | Promise<Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>>;
2165
+ /**
2166
+ * Create a validation rule iterating over a single item at a time.
2167
+ * @param name - The name of the rule.
2168
+ * @param description - A human-readable description of the rule.
2169
+ * @param run - The function that validates the rule.
2170
+ * @returns The created rule.
2171
+ */
2172
+ declare function single<Name$2 extends string, T>(name: Name$2, description: string, run: Single<T, Name$2>): Rule<T, Name$2>;
2173
+ /**
2174
+ * Create a validation rule iterating over a batch of items at a time.
2175
+ * @param name - The name of the rule.
2176
+ * @param description - A human-readable description of the rule.
2177
+ * @param run - The function that validates the rule.
2178
+ * @returns The created rule.
2179
+ */
2180
+ declare function batch$1<Name$2 extends string, T>(name: Name$2, description: string, run: Batch<T, Name$2>): Rule<T, Name$2>;
2181
+ /**
2182
+ * A validation issue.
2183
+ */
2184
+ type Issue<T, RuleName extends string = string> = {
2185
+ /** The name of the rule that caused the issue. */
2186
+ ruleName: RuleName;
2187
+ /** The message of the issue. */
2188
+ message: string;
2189
+ /** The item that was not valid. */
2190
+ item: T;
2191
+ };
2192
+ /**
2193
+ * The result of a validation.
2194
+ */
2195
+ type Result<T, RuleName extends string = string> = {
2196
+ /** The items that were valid. */
2197
+ valid: T[];
2198
+ /** The reports of the failed validations. */
2199
+ issues: Issue<T, RuleName>[];
2200
+ };
2201
+ declare function run<T, Name$2 extends string, Rules$1 extends readonly Rule<T, Name$2>[]>(parameters: {
2202
+ items: T[];
2203
+ rules: Rules$1;
2204
+ chunkSize?: number;
2205
+ }): Promise<Result<T, RuleNames<Rules$1>>>;
2206
+ declare namespace Gatekeeper_d_exports {
2207
+ export { Gatekeeper, Rules, create$3 as create };
2208
+ }
2209
+ type Rules = readonly Rule<Offer, string>[];
2210
+ type Gatekeeper = {
2211
+ rules: Rules;
2212
+ isAllowed: (offers: Offer[]) => Promise<Result<Offer, string>>;
2213
+ };
2214
+ type GatekeeperParameters = {
2215
+ rules: Rules;
2216
+ };
2217
+ declare function create$3(parameters: GatekeeperParameters): Gatekeeper;
2218
+ declare namespace GateConfig_d_exports {
2219
+ export { CallbackConfig, GateConfig, assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
2220
+ }
2221
+ type GateConfig = {
2222
+ callbacks?: CallbackConfig[];
2223
+ maturities?: MaturityType[];
2224
+ };
2225
+ type CallbackConfig = {
2226
+ type: CallbackType.BuyVaultV1Callback;
2227
+ addresses: Address[];
2228
+ vaultFactories: Address[];
2229
+ } | {
2230
+ type: CallbackType.SellERC20Callback;
2231
+ addresses: Address[];
2232
+ } | {
2233
+ type: CallbackType.BuyWithEmptyCallback;
2234
+ };
2235
+ declare function getCallback(chain: Name$1, type: CallbackType.BuyVaultV1Callback): Extract<CallbackConfig, {
2236
+ type: CallbackType.BuyVaultV1Callback;
2237
+ }> | undefined;
2238
+ declare function getCallback(chain: Name$1, type: CallbackType.SellERC20Callback): Extract<CallbackConfig, {
2239
+ type: CallbackType.SellERC20Callback;
2240
+ }> | undefined;
2241
+ declare function getCallback(chain: Name$1, type: CallbackType.BuyWithEmptyCallback): Extract<CallbackConfig, {
2242
+ type: CallbackType.BuyWithEmptyCallback;
2243
+ }> | undefined;
2244
+ declare function getCallback(chain: Name$1, type: CallbackType): CallbackConfig | undefined;
2245
+ /**
2246
+ * Attempts to infer the configured callback type from a callback address on a chain.
2247
+ * Skips the empty callback type as it does not carry addresses.
2248
+ *
2249
+ * @param chain - Chain name for which to infer the callback type
2250
+ * @param address - Callback contract address
2251
+ * @returns The callback type when found, otherwise undefined
2252
+ */
2253
+ declare function getCallbackType(chain: Name$1, address: Address): CallbackType | undefined;
2254
+ /**
2255
+ * Returns the callback addresses for a given chain and callback type, if it exists.
2256
+ * @param chain - Chain name for which to read the validation configuration
2257
+ * @param type - Callback type to retrieve
2258
+ * @returns The matching callback addresses or an empty array if not configured
2259
+ */
2260
+ declare function getCallbackTypeAddresses(chain: Name$1, type: CallbackType): Address[];
2261
+ /**
2262
+ * Returns the list of allowed non-empty callback addresses for a chain.
2263
+ *
2264
+ * @param chain - Chain name
2265
+ * @returns Array of allowed callback addresses (lowercased). Empty when none configured
2266
+ */
2267
+ declare const getCallbackAddresses: (chain: Name$1) => Address[];
2268
+ declare const assets: Record<string, Address[]>;
2269
+ declare const configs: Record<Name$1, GateConfig>;
2270
+ //#endregion
2271
+ //#region src/gatekeeper/morphoRules.d.ts
2272
+ 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">)[];
2273
+ declare namespace Rules_d_exports {
2274
+ export { ValidityParameters, amountMutualExclusivity, callback, chains$1 as chains, maturity, sameMaker, token, validity };
2275
+ }
2276
+ type ValidityParameters = {
2277
+ client: PublicClient<Transport, Chain$1>;
2278
+ };
2279
+ /**
2280
+ * set of rules to validate offers.
2281
+ *
2282
+ * @param parameters - Validity parameters with chain and client
2283
+ * @returns Array of validation rules to evaluate against offers
2284
+ */
2285
+ declare function validity(parameters: ValidityParameters): (Rule<Offer, "expiry"> | Rule<Offer, "sell_erc20_callback_invalid"> | Rule<Offer, "buy_offers_callback_vault_invalid">)[];
2286
+ declare const chains$1: ({
2287
+ chains: chains$1
2288
+ }: {
2289
+ chains: Chain$1[];
2290
+ }) => Rule<Offer, "chain_ids">;
2291
+ declare const maturity: ({
2292
+ maturities
2293
+ }: {
2294
+ maturities: MaturityType[];
2295
+ }) => Rule<Offer, "maturity">;
2296
+ declare const callback: ({
2297
+ callbacks,
2298
+ allowedAddresses
2299
+ }: {
2300
+ callbacks: CallbackType[];
2301
+ allowedAddresses: Address[];
2302
+ }) => Rule<Offer, "callback">;
2303
+ /**
2304
+ * A validation rule that checks if the offer's tokens are allowed for its chain.
2305
+ * @param assetsByChainId - Allowed assets indexed by chain id.
2306
+ * @returns The issue that was found. If the offer is valid, this will be undefined.
2138
2307
  */
2139
- type Attestation = {
2140
- root: Hex;
2141
- signature: Hex;
2142
- proof: Hex[];
2143
- };
2308
+ declare const token: ({
2309
+ assetsByChainId
2310
+ }: {
2311
+ assetsByChainId: Partial<Record<Id, Address[]>>;
2312
+ }) => Rule<Offer, "token">;
2144
2313
  /**
2145
- * Input for creating trees with their signatures.
2314
+ * A batch validation rule that ensures all offers in a tree have the same maker address.
2315
+ * Returns an issue only for the first non-conforming offer.
2316
+ * This rule is signing-agnostic; signer verification is handled at the collector level.
2146
2317
  */
2147
- type CreateInput = {
2148
- tree: Tree;
2149
- signature: Hex;
2150
- };
2151
- type TreesDomain = {
2152
- /**
2153
- * Creates trees, offers, and attestation links in a single transaction.
2154
- *
2155
- * @param trees - Array of decoded trees with signatures (batch insertion)
2156
- * @returns Array of tree roots that were created/upserted
2157
- */
2158
- create: (trees: CreateInput[]) => Promise<Hex[]>;
2159
- /**
2160
- * Retrieves merkle attestations for execution flow.
2161
- *
2162
- * @param hashes - Array of offer hashes to look up
2163
- * @returns Map of offer hash to attestation (only entries with attestations are included)
2164
- */
2165
- getAttestations: (hashes: Hex[]) => Promise<Map<Hex, Attestation>>;
2166
- };
2167
- //#endregion
2168
- //#region src/database/domains/Validations.d.ts
2169
- type GetParams = {
2170
- status?: Status;
2171
- cursor?: string;
2172
- limit?: number;
2173
- };
2174
- type ValidationsDomain = {
2175
- /**
2176
- * Get validation statuses with optional filtering and pagination.
2177
- *
2178
- * @param params - Optional parameters for filtering and pagination
2179
- * @returns Array of validation statuses and next cursor for pagination
2180
- */
2181
- get: (params?: GetParams) => Promise<{
2182
- validations: Validation[];
2183
- nextCursor: string | null;
2184
- }>;
2185
- /**
2186
- * Upsert validations
2187
- *
2188
- * @param validations - Array of validations to upsert
2189
- */
2190
- upsert: (validations: Validation[]) => Promise<void>;
2191
- };
2192
- declare namespace Database_d_exports {
2193
- export { Core, Database, Driver, WithDomains, connect$2 as connect };
2318
+ declare const sameMaker: () => Rule<Offer, "mixed_maker">;
2319
+ /**
2320
+ * A validation rule that ensures mutual exclusivity of offer amount fields.
2321
+ * At most one of (assets, obligationUnits, obligationShares) can be non-zero.
2322
+ * Matches contract requirement: `atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)`.
2323
+ */
2324
+ declare const amountMutualExclusivity: () => Rule<Offer, "amount_mutual_exclusivity">;
2325
+ declare namespace Indexer_d_exports {
2326
+ export { Indexer, IndexerConfig, create$2 as create, from$6 as from };
2194
2327
  }
2195
- type Driver = ReturnType<typeof drizzle> | ReturnType<typeof drizzle$1>;
2196
- type Domains = {
2197
- book: BookDomain;
2198
- collectors: CollectorsDomain;
2199
- offers: OffersDomain;
2200
- chains: ChainsDomain;
2201
- consumed: ConsumedDomain;
2202
- lots: LotsDomain;
2203
- offsets: OffsetsDomain;
2204
- oracles: OraclesDomain;
2205
- trees: TreesDomain;
2206
- validations: ValidationsDomain;
2207
- positions: PositionsDomain;
2208
- transfers: TransfersDomain;
2209
- };
2210
- type WithDomains<D extends Driver> = D & Domains;
2211
- type Core = Omit<WithDomains<Driver>, "transaction"> & {
2212
- transaction<T>(fn: (tx: WithDomains<Driver>) => Promise<T>): Promise<T>;
2328
+ type Indexer = {
2329
+ start: () => () => void;
2330
+ next: () => Promise<void>;
2331
+ return: () => Promise<void>;
2213
2332
  };
2214
- type Database = Core & {
2215
- name: "pg" | "pglite";
2216
- pool: Pool | PGlite;
2217
- applyMigrations: (folderPath: string) => Promise<void>;
2218
- clean: () => Promise<void>;
2333
+ type IndexerConfig<client extends PublicClient<Transport, Chain$1, Account | undefined>> = {
2334
+ client: client;
2335
+ db: Database;
2336
+ gatekeeper: Gatekeeper;
2337
+ interval?: number;
2338
+ maxBatchSize?: number;
2339
+ maxBlockNumber?: number;
2340
+ blockWindow?: number;
2341
+ retryAttempts?: number;
2342
+ retryDelayMs?: number;
2219
2343
  };
2220
- /**
2221
- * Connect to the database.
2222
- * @notice If no connection string is provided, an in-process PGLite database is created.
2223
- * @param {string=} [connectionString] - The optional connection string for the Postgres database.
2224
- * @returns The database client {@link connect.ReturnType}
2225
- */
2226
- declare function connect$2(connectionString?: string): Database;
2344
+ declare function from$6<client extends PublicClient<Transport, Chain$1, Account | undefined>>(config: IndexerConfig<client>): Indexer;
2345
+ declare function create$2<client extends PublicClient<Transport, Chain$1, Account | undefined>>(params: {
2346
+ collectors: Collector[];
2347
+ client: client;
2348
+ }): Indexer;
2227
2349
  declare namespace Health_d_exports {
2228
- export { ChainHealth$1 as ChainHealth, CollectorHealth$1 as CollectorHealth, CollectorHealthStatus, HealthService, HealthServiceParameters, RouterStatus, create$1 as create };
2350
+ export { ChainHealth$1 as ChainHealth, CollectorHealth$1 as CollectorHealth, CollectorHealthStatus, HealthService, HealthServiceParameters, MissingCollector, RouterHealth, RouterStatus, create$1 as create };
2229
2351
  }
2230
2352
  type CollectorHealthStatus = "live" | "lagging" | "unknown";
2231
2353
  type RouterStatus = "live" | "syncing";
@@ -2236,16 +2358,29 @@ type CollectorHealth$1 = {
2236
2358
  updatedAt: string | null;
2237
2359
  lag: number | null;
2238
2360
  status: CollectorHealthStatus;
2361
+ initialized: boolean;
2239
2362
  };
2240
2363
  type ChainHealth$1 = {
2241
2364
  chainId: Id;
2242
- localBlockNumber: number;
2365
+ localBlockNumber: number | null;
2243
2366
  remoteBlockNumber: number | null;
2244
- epoch: string;
2245
- updatedAt: string;
2367
+ epoch: string | null;
2368
+ updatedAt: string | null;
2369
+ initialized: boolean;
2370
+ };
2371
+ type MissingCollector = {
2372
+ chainId: Id;
2373
+ name: Name;
2374
+ };
2375
+ type RouterHealth = {
2376
+ status: RouterStatus;
2377
+ initialized: boolean;
2378
+ missingChains: Id[];
2379
+ missingCollectors: MissingCollector[];
2246
2380
  };
2247
2381
  type HealthService = {
2248
- getStatus: () => Promise<RouterStatus>;
2382
+ getSnapshot: () => Promise<Snapshot>;
2383
+ getStatus: () => Promise<RouterHealth>;
2249
2384
  getCollectors: () => Promise<CollectorHealth$1[]>;
2250
2385
  getChains: () => Promise<ChainHealth$1[]>;
2251
2386
  };
@@ -2255,6 +2390,16 @@ type HealthServiceParameters = {
2255
2390
  maxAllowedLag?: number;
2256
2391
  /** Map of chainId to client for fetching remote block numbers. */
2257
2392
  healthClients?: Map<Id, Client>;
2393
+ /** Chain registry for deriving expected initialization state. */
2394
+ chainRegistry?: ChainRegistry;
2395
+ };
2396
+ type Snapshot = {
2397
+ status: RouterStatus;
2398
+ initialized: boolean;
2399
+ missingChains: Id[];
2400
+ missingCollectors: MissingCollector[];
2401
+ collectors: CollectorHealth$1[];
2402
+ chains: ChainHealth$1[];
2258
2403
  };
2259
2404
  /**
2260
2405
  * Create a health service that exposes collector and chain block numbers.
@@ -2269,24 +2414,26 @@ type ApiConfig = {
2269
2414
  db: Database;
2270
2415
  gatekeeper: Gatekeeper;
2271
2416
  port: number;
2417
+ chainRegistry: ChainRegistry;
2272
2418
  };
2273
- declare function from$4(config: ApiConfig): RouterApi;
2419
+ declare function from$5(config: ApiConfig): RouterApi;
2274
2420
  type CreateParameters = {
2275
2421
  db: Database;
2276
2422
  gatekeeper: Gatekeeper;
2277
2423
  port: number;
2424
+ chainRegistry: ChainRegistry;
2278
2425
  };
2279
2426
  declare function create(params: CreateParameters): RouterApi;
2280
2427
  declare namespace BookResponse_d_exports {
2281
- export { BookLevelResponse, from$3 as from };
2428
+ export { BookLevelResponse, from$4 as from };
2282
2429
  }
2283
2430
  type BookLevelResponse = {
2284
- rate: string;
2431
+ price: string;
2285
2432
  assets: string;
2286
2433
  count: number;
2287
2434
  };
2288
- declare function from$3(level: {
2289
- rate: bigint;
2435
+ declare function from$4(level: {
2436
+ price: bigint;
2290
2437
  assets: bigint;
2291
2438
  count: number;
2292
2439
  }): BookLevelResponse;
@@ -2303,6 +2450,7 @@ declare const CollectorHealth: z.ZodObject<{
2303
2450
  live: "live";
2304
2451
  lagging: "lagging";
2305
2452
  }>;
2453
+ initialized: z.ZodBoolean;
2306
2454
  }, z.core.$strip>;
2307
2455
  declare const CollectorsHealthResponse: z.ZodArray<z.ZodObject<{
2308
2456
  name: z.ZodString;
@@ -2315,24 +2463,33 @@ declare const CollectorsHealthResponse: z.ZodArray<z.ZodObject<{
2315
2463
  live: "live";
2316
2464
  lagging: "lagging";
2317
2465
  }>;
2466
+ initialized: z.ZodBoolean;
2318
2467
  }, z.core.$strip>>;
2319
2468
  declare const ChainHealth: z.ZodObject<{
2320
2469
  chain_id: z.ZodNumber;
2321
- local_block_number: z.ZodNumber;
2470
+ local_block_number: z.ZodNullable<z.ZodNumber>;
2322
2471
  remote_block_number: z.ZodNullable<z.ZodNumber>;
2323
- updated_at: z.ZodString;
2472
+ updated_at: z.ZodNullable<z.ZodString>;
2473
+ initialized: z.ZodBoolean;
2324
2474
  }, z.core.$strip>;
2325
2475
  declare const ChainsHealthResponse: z.ZodArray<z.ZodObject<{
2326
2476
  chain_id: z.ZodNumber;
2327
- local_block_number: z.ZodNumber;
2477
+ local_block_number: z.ZodNullable<z.ZodNumber>;
2328
2478
  remote_block_number: z.ZodNullable<z.ZodNumber>;
2329
- updated_at: z.ZodString;
2479
+ updated_at: z.ZodNullable<z.ZodString>;
2480
+ initialized: z.ZodBoolean;
2330
2481
  }, z.core.$strip>>;
2331
2482
  declare const RouterStatusResponse: z.ZodObject<{
2332
2483
  status: z.ZodEnum<{
2333
2484
  live: "live";
2334
2485
  syncing: "syncing";
2335
2486
  }>;
2487
+ initialized: z.ZodBoolean;
2488
+ missing_chains: z.ZodArray<z.ZodNumber>;
2489
+ missing_collectors: z.ZodArray<z.ZodObject<{
2490
+ chain_id: z.ZodNumber;
2491
+ name: z.ZodString;
2492
+ }, z.core.$strip>>;
2336
2493
  }, z.core.$strip>;
2337
2494
  type CollectorsHealthResponse = z.infer<typeof CollectorsHealthResponse>;
2338
2495
  type ChainsHealthResponse = z.infer<typeof ChainsHealthResponse>;
@@ -2354,13 +2511,13 @@ interface paths {
2354
2511
  };
2355
2512
  /**
2356
2513
  * Get aggregated book
2357
- * @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).
2514
+ * @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).
2358
2515
  */
2359
2516
  get: {
2360
2517
  parameters: {
2361
2518
  query?: {
2362
2519
  /**
2363
- * @description Maximum number of rate levels to return.
2520
+ * @description Maximum number of price levels to return.
2364
2521
  * @example 10
2365
2522
  */
2366
2523
  limit?: number;
@@ -2371,7 +2528,18 @@ interface paths {
2371
2528
  cursor?: string;
2372
2529
  };
2373
2530
  header?: never;
2374
- path?: never;
2531
+ path: {
2532
+ /**
2533
+ * @description Book side (buy or sell).
2534
+ * @example buy
2535
+ */
2536
+ side: "buy" | "sell";
2537
+ /**
2538
+ * @description Obligation id.
2539
+ * @example 0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67
2540
+ */
2541
+ obligationId: string;
2542
+ };
2375
2543
  cookie?: never;
2376
2544
  };
2377
2545
  requestBody?: never;
@@ -2404,6 +2572,45 @@ interface paths {
2404
2572
  patch?: never;
2405
2573
  trace?: never;
2406
2574
  };
2575
+ "/v1/config": {
2576
+ parameters: {
2577
+ query?: never;
2578
+ header?: never;
2579
+ path?: never;
2580
+ cookie?: never;
2581
+ };
2582
+ /**
2583
+ * Get router configuration
2584
+ * @description Returns chain configurations including contract addresses and supported maturity timestamps.
2585
+ */
2586
+ get: {
2587
+ parameters: {
2588
+ query?: never;
2589
+ header?: never;
2590
+ path?: never;
2591
+ cookie?: never;
2592
+ };
2593
+ requestBody?: never;
2594
+ responses: {
2595
+ /** @description Success */
2596
+ 200: {
2597
+ headers: {
2598
+ [name: string]: unknown;
2599
+ };
2600
+ content: {
2601
+ "application/json": components["schemas"]["ConfigSuccessResponse"];
2602
+ };
2603
+ };
2604
+ };
2605
+ };
2606
+ put?: never;
2607
+ post?: never;
2608
+ delete?: never;
2609
+ options?: never;
2610
+ head?: never;
2611
+ patch?: never;
2612
+ trace?: never;
2613
+ };
2407
2614
  "/v1/offers": {
2408
2615
  parameters: {
2409
2616
  query?: never;
@@ -2413,7 +2620,7 @@ interface paths {
2413
2620
  };
2414
2621
  /**
2415
2622
  * List all offers
2416
- * @description Returns offers. Provide either `obligation_id` + `side` (order book) or `offering` (by maker).
2623
+ * @description Returns offers. Provide either `obligation_id` + `side` (order book) or `maker` (by maker address).
2417
2624
  */
2418
2625
  get: {
2419
2626
  parameters: {
@@ -2432,9 +2639,9 @@ interface paths {
2432
2639
  * @description Maker address to filter offers by. Alternative to obligation_id + side.
2433
2640
  * @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401
2434
2641
  */
2435
- offering?: string;
2642
+ maker?: string;
2436
2643
  /**
2437
- * @description Obligation id used to filter offers. Required when not using offering.
2644
+ * @description Obligation id used to filter offers. Required when not using maker.
2438
2645
  * @example 0x1234567890123456789012345678901234567890123456789012345678901234
2439
2646
  */
2440
2647
  obligation_id?: string;
@@ -2492,9 +2699,35 @@ interface paths {
2492
2699
  get: {
2493
2700
  parameters: {
2494
2701
  query?: {
2495
- /** @example 10 */
2702
+ /**
2703
+ * @description Filter by exact maturity timestamp (unix seconds).
2704
+ * @example 1761922800
2705
+ */
2706
+ maturity?: number;
2707
+ /**
2708
+ * @description Filter by collateral token (matches any collateral in the obligation).
2709
+ * @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751
2710
+ */
2711
+ collateral_token?: string;
2712
+ /**
2713
+ * @description Filter by loan token address.
2714
+ * @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078
2715
+ */
2716
+ loan_token?: string;
2717
+ /**
2718
+ * @description Filter by chain ID.
2719
+ * @example 1
2720
+ */
2721
+ chain?: number;
2722
+ /**
2723
+ * @description Maximum number of obligations to return.
2724
+ * @example 10
2725
+ */
2496
2726
  limit?: number;
2497
- /** @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc */
2727
+ /**
2728
+ * @description Obligation id cursor for pagination.
2729
+ * @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc
2730
+ */
2498
2731
  cursor?: string;
2499
2732
  };
2500
2733
  header?: never;
@@ -2546,7 +2779,13 @@ interface paths {
2546
2779
  parameters: {
2547
2780
  query?: never;
2548
2781
  header?: never;
2549
- path?: never;
2782
+ path: {
2783
+ /**
2784
+ * @description Obligation id.
2785
+ * @example 0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67
2786
+ */
2787
+ obligationId: string;
2788
+ };
2550
2789
  cookie?: never;
2551
2790
  };
2552
2791
  requestBody?: never;
@@ -2592,7 +2831,13 @@ interface paths {
2592
2831
  */
2593
2832
  get: {
2594
2833
  parameters: {
2595
- query?: never;
2834
+ query?: {
2835
+ /**
2836
+ * @description Fail the request if initialization is incomplete.
2837
+ * @example true
2838
+ */
2839
+ strict?: boolean;
2840
+ };
2596
2841
  header?: never;
2597
2842
  path?: never;
2598
2843
  cookie?: never;
@@ -2631,7 +2876,13 @@ interface paths {
2631
2876
  */
2632
2877
  get: {
2633
2878
  parameters: {
2634
- query?: never;
2879
+ query?: {
2880
+ /**
2881
+ * @description Fail the request if initialization is incomplete.
2882
+ * @example true
2883
+ */
2884
+ strict?: boolean;
2885
+ };
2635
2886
  header?: never;
2636
2887
  path?: never;
2637
2888
  cookie?: never;
@@ -2670,9 +2921,71 @@ interface paths {
2670
2921
  */
2671
2922
  get: {
2672
2923
  parameters: {
2673
- query?: never;
2924
+ query?: {
2925
+ /**
2926
+ * @description Fail the request if initialization is incomplete.
2927
+ * @example true
2928
+ */
2929
+ strict?: boolean;
2930
+ };
2931
+ header?: never;
2932
+ path?: never;
2933
+ cookie?: never;
2934
+ };
2935
+ requestBody?: never;
2936
+ responses: {
2937
+ /** @description Success */
2938
+ 200: {
2939
+ headers: {
2940
+ [name: string]: unknown;
2941
+ };
2942
+ content: {
2943
+ "application/json": components["schemas"]["ChainsHealthSuccessResponse"];
2944
+ };
2945
+ };
2946
+ };
2947
+ };
2948
+ put?: never;
2949
+ post?: never;
2950
+ delete?: never;
2951
+ options?: never;
2952
+ head?: never;
2953
+ patch?: never;
2954
+ trace?: never;
2955
+ };
2956
+ "/v1/users/{userAddress}/positions": {
2957
+ parameters: {
2958
+ query?: never;
2959
+ header?: never;
2960
+ path?: never;
2961
+ cookie?: never;
2962
+ };
2963
+ /**
2964
+ * Get user positions
2965
+ * @description Returns positions for a user with reserved balance. The reserved balance is the amount locked by active offers (max lot upper - offset - consumed).
2966
+ */
2967
+ get: {
2968
+ parameters: {
2969
+ query?: {
2970
+ /**
2971
+ * @description Maximum number of positions to return.
2972
+ * @example 10
2973
+ */
2974
+ limit?: number;
2975
+ /**
2976
+ * @description Pagination cursor in base64url-encoded format.
2977
+ * @example eyJvZmZzZXQiOjEwMH0
2978
+ */
2979
+ cursor?: string;
2980
+ };
2674
2981
  header?: never;
2675
- path?: never;
2982
+ path: {
2983
+ /**
2984
+ * @description User address to get positions for.
2985
+ * @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401
2986
+ */
2987
+ userAddress: string;
2988
+ };
2676
2989
  cookie?: never;
2677
2990
  };
2678
2991
  requestBody?: never;
@@ -2683,7 +2996,16 @@ interface paths {
2683
2996
  [name: string]: unknown;
2684
2997
  };
2685
2998
  content: {
2686
- "application/json": components["schemas"]["ChainsHealthSuccessResponse"];
2999
+ "application/json": components["schemas"]["PositionListResponse"];
3000
+ };
3001
+ };
3002
+ /** @description Bad Request */
3003
+ 400: {
3004
+ headers: {
3005
+ [name: string]: unknown;
3006
+ };
3007
+ content: {
3008
+ "application/json": components["schemas"]["BadRequestResponse"];
2687
3009
  };
2688
3010
  };
2689
3011
  };
@@ -2711,11 +3033,12 @@ interface paths {
2711
3033
  *
2712
3034
  * **Available validation rules:**
2713
3035
  * - **parse_error**: Returns when an offer fails to parse due to invalid format or missing required fields
2714
- * - **mixed_maker**: Validates that all offers in a batch have the same maker (offering address)
3036
+ * - **mixed_maker**: Validates that all offers in a batch have the same maker address
3037
+ * - **amount_mutual_exclusivity**: Validates that at most one of (assets, obligationUnits, obligationShares) is non-zero
2715
3038
  * - **chain_ids**: Validates that offer chain is one of: [109111114]
2716
3039
  * - **maturity**: Validates that offer maturity is one of: [end_of_month, end_of_next_month]
2717
3040
  * - **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]
2718
- * - **token**: Validates that offer loan token and collateral tokens are in the allowed assets list
3041
+ * - **token**: Validates that offer loan token and collateral tokens are in the allowed assets list for the offer chain
2719
3042
  */
2720
3043
  post: {
2721
3044
  parameters: {
@@ -2763,7 +3086,7 @@ interface components {
2763
3086
  meta: components["schemas"]["Meta"];
2764
3087
  /** @example eyJvZmZzZXQiOjEwMH0 */
2765
3088
  cursor: string | null;
2766
- /** @description Aggregated book levels grouped by rate. */
3089
+ /** @description Aggregated book levels grouped by computed price. */
2767
3090
  data: components["schemas"]["BookLevelResponse"][];
2768
3091
  };
2769
3092
  Meta: {
@@ -2772,7 +3095,7 @@ interface components {
2772
3095
  };
2773
3096
  BookLevelResponse: {
2774
3097
  /** @example 2750000000000000000 */
2775
- rate: string;
3098
+ price: string;
2776
3099
  /** @example 369216000000000000000000 */
2777
3100
  assets: string;
2778
3101
  /** @example 5 */
@@ -2800,6 +3123,56 @@ interface components {
2800
3123
  */
2801
3124
  details: Record<string, never>;
2802
3125
  };
3126
+ ConfigSuccessResponse: {
3127
+ meta: components["schemas"]["Meta"];
3128
+ /** @example null */
3129
+ cursor: string | null;
3130
+ /**
3131
+ * @description Array of chain configurations for all indexed chains.
3132
+ * @example [
3133
+ * {
3134
+ * "chain_id": 505050505,
3135
+ * "contracts": {
3136
+ * "mempool": "0xD946246695A9259F3B33a78629026F61B3Ab40aF"
3137
+ * },
3138
+ * "maturities": {
3139
+ * "end_of_month": 1738335600,
3140
+ * "end_of_next_month": 1740754800
3141
+ * }
3142
+ * }
3143
+ * ]
3144
+ */
3145
+ data: components["schemas"]["ConfigDataResponse"][];
3146
+ };
3147
+ ConfigDataResponse: {
3148
+ /** @example 505050505 */
3149
+ chain_id: number;
3150
+ contracts: components["schemas"]["ConfigContractsResponse"];
3151
+ /**
3152
+ * @description Supported maturity timestamps. Offers must use one of these values.
3153
+ * @example {
3154
+ * "end_of_month": 1738335600,
3155
+ * "end_of_next_month": 1740754800
3156
+ * }
3157
+ */
3158
+ maturities: components["schemas"]["MaturitiesResponse"];
3159
+ };
3160
+ ConfigContractsResponse: {
3161
+ /** @example 0xD946246695A9259F3B33a78629026F61B3Ab40aF */
3162
+ mempool: string;
3163
+ };
3164
+ MaturitiesResponse: {
3165
+ /**
3166
+ * @description Unix timestamp for end of current month maturity (last Friday 15:00 UTC).
3167
+ * @example 1738335600
3168
+ */
3169
+ end_of_month: number;
3170
+ /**
3171
+ * @description Unix timestamp for end of next month maturity (last Friday 15:00 UTC).
3172
+ * @example 1740754800
3173
+ */
3174
+ end_of_next_month: number;
3175
+ };
2803
3176
  OfferListResponse: {
2804
3177
  meta: components["schemas"]["Meta"];
2805
3178
  /** @example eyJvZmZzZXQiOjEwMH0 */
@@ -2808,29 +3181,34 @@ interface components {
2808
3181
  * @description Offers matching the provided filters.
2809
3182
  * @example [
2810
3183
  * {
2811
- * "hash": "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
2812
- * "offering": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
2813
- * "assets": "369216000000000000000000",
2814
- * "rate": "2750000000000000000",
2815
- * "maturity": 1761922799,
2816
- * "expiry": 1761922799,
2817
- * "start": 1761922790,
2818
- * "nonce": "571380",
2819
- * "buy": false,
2820
- * "chain_id": 1,
2821
- * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
2822
- * "collaterals": [
2823
- * {
2824
- * "asset": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2825
- * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401",
2826
- * "lltv": "860000000000000000"
2827
- * }
2828
- * ],
2829
- * "callback": {
2830
- * "address": "0x1111111111111111111111111111111111111111",
2831
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
2832
- * "gas_limit": "500000"
3184
+ * "offer": {
3185
+ * "obligation": {
3186
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3187
+ * "collaterals": [
3188
+ * {
3189
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3190
+ * "lltv": "860000000000000000",
3191
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
3192
+ * }
3193
+ * ],
3194
+ * "maturity": 1761922799
3195
+ * },
3196
+ * "buy": false,
3197
+ * "maker": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
3198
+ * "assets": "369216000000000000000000",
3199
+ * "obligation_units": "0",
3200
+ * "obligation_shares": "0",
3201
+ * "start": 1761922790,
3202
+ * "expiry": 1761922799,
3203
+ * "price": "2750000000000000000",
3204
+ * "group": "0x000000000000000000000000000000000000000000000000000000000008b8f4",
3205
+ * "session": "0x0000000000000000000000000000000000000000000000000000000000000000",
3206
+ * "callback": "0x1111111111111111111111111111111111111111",
3207
+ * "callback_data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
2833
3208
  * },
3209
+ * "offer_hash": "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
3210
+ * "obligation_id": "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
3211
+ * "chain_id": 1,
2834
3212
  * "consumed": "0",
2835
3213
  * "takeable": "369216000000000000000000",
2836
3214
  * "block_number": 2942933377146801,
@@ -2846,50 +3224,44 @@ interface components {
2846
3224
  data: components["schemas"]["OfferListItemResponse"][];
2847
3225
  };
2848
3226
  OfferListItemResponse: {
2849
- /** @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427 */
2850
- hash: string;
2851
- /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
2852
- offering: string;
2853
- /** @example 369216000000000000000000 */
2854
- assets: string;
2855
- /** @example 2750000000000000000 */
2856
- rate: string;
2857
- /** @example 1761922799 */
2858
- maturity: number;
2859
- /** @example 1761922799 */
2860
- expiry: number;
2861
- /** @example 1761922790 */
2862
- start: number;
2863
- /** @example 571380 */
2864
- nonce: string;
2865
- /** @example false */
2866
- buy: boolean;
2867
- /** @example 1 */
2868
- chain_id: number;
2869
- /** @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078 */
2870
- loan_token: string;
2871
- /**
2872
- * @example [
2873
- * {
2874
- * "asset": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
2875
- * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401",
2876
- * "lltv": "860000000000000000"
2877
- * }
2878
- * ]
2879
- */
2880
- collaterals: components["schemas"]["CollateralResponse"][];
2881
3227
  /**
2882
3228
  * @example {
2883
- * "address": "0x1111111111111111111111111111111111111111",
2884
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
2885
- * "gas_limit": "500000"
3229
+ * "obligation": {
3230
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3231
+ * "collaterals": [
3232
+ * {
3233
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3234
+ * "lltv": "860000000000000000",
3235
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
3236
+ * }
3237
+ * ],
3238
+ * "maturity": 1761922799
3239
+ * },
3240
+ * "buy": false,
3241
+ * "maker": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
3242
+ * "assets": "369216000000000000000000",
3243
+ * "obligation_units": "0",
3244
+ * "obligation_shares": "0",
3245
+ * "start": 1761922790,
3246
+ * "expiry": 1761922799,
3247
+ * "price": "2750000000000000000",
3248
+ * "group": "0x000000000000000000000000000000000000000000000000000000000008b8f4",
3249
+ * "session": "0x0000000000000000000000000000000000000000000000000000000000000000",
3250
+ * "callback": "0x1111111111111111111111111111111111111111",
3251
+ * "callback_data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
2886
3252
  * }
2887
3253
  */
2888
- callback: components["schemas"]["OfferCallbackResponse"];
2889
- /** @example 369216000000000000000000 */
2890
- takeable: string;
3254
+ offer: components["schemas"]["OfferDataResponse"];
3255
+ /** @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427 */
3256
+ offer_hash: string;
3257
+ /** @example 0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc */
3258
+ obligation_id: string;
3259
+ /** @example 1 */
3260
+ chain_id: number;
2891
3261
  /** @example 0 */
2892
3262
  consumed: string;
3263
+ /** @example 369216000000000000000000 */
3264
+ takeable: string;
2893
3265
  /** @example 2942933377146801 */
2894
3266
  block_number: number;
2895
3267
  /** @example 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef */
@@ -2904,21 +3276,69 @@ interface components {
2904
3276
  /** @example 0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400 */
2905
3277
  signature: string | null;
2906
3278
  };
3279
+ OfferDataResponse: {
3280
+ /**
3281
+ * @example {
3282
+ * "loan_token": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3283
+ * "collaterals": [
3284
+ * {
3285
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3286
+ * "lltv": "860000000000000000",
3287
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
3288
+ * }
3289
+ * ],
3290
+ * "maturity": 1761922799
3291
+ * }
3292
+ */
3293
+ obligation: components["schemas"]["ObligationOfferResponse"];
3294
+ /** @example false */
3295
+ buy: boolean;
3296
+ /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
3297
+ maker: string;
3298
+ /** @example 369216000000000000000000 */
3299
+ assets: string;
3300
+ /** @example 0 */
3301
+ obligation_units: string;
3302
+ /** @example 0 */
3303
+ obligation_shares: string;
3304
+ /** @example 1761922790 */
3305
+ start: number;
3306
+ /** @example 1761922799 */
3307
+ expiry: number;
3308
+ /** @example 2750000000000000000 */
3309
+ price: string;
3310
+ /** @example 0x000000000000000000000000000000000000000000000000000000000008b8f4 */
3311
+ group: string;
3312
+ /** @example 0x0000000000000000000000000000000000000000000000000000000000000000 */
3313
+ session: string;
3314
+ /** @example 0x1111111111111111111111111111111111111111 */
3315
+ callback: string;
3316
+ /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
3317
+ callback_data: string;
3318
+ };
3319
+ ObligationOfferResponse: {
3320
+ /** @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078 */
3321
+ loan_token: string;
3322
+ /**
3323
+ * @example [
3324
+ * {
3325
+ * "token": "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3326
+ * "lltv": "860000000000000000",
3327
+ * "oracle": "0x45093658BE7f90B63D7c359e8f408e503c2D9401"
3328
+ * }
3329
+ * ]
3330
+ */
3331
+ collaterals: components["schemas"]["CollateralResponse"][];
3332
+ /** @example 1761922799 */
3333
+ maturity: number;
3334
+ };
2907
3335
  CollateralResponse: {
2908
3336
  /** @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751 */
2909
- asset: string;
2910
- /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
2911
- oracle: string;
3337
+ token: string;
2912
3338
  /** @example 860000000000000000 */
2913
3339
  lltv: string;
2914
- };
2915
- OfferCallbackResponse: {
2916
- /** @example 0x1111111111111111111111111111111111111111 */
2917
- address: string;
2918
- /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
2919
- data: string;
2920
- /** @example 500000 */
2921
- gas_limit: string;
3340
+ /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
3341
+ oracle: string;
2922
3342
  };
2923
3343
  ObligationListResponse: {
2924
3344
  meta: components["schemas"]["Meta"];
@@ -2942,11 +3362,11 @@ interface components {
2942
3362
  };
2943
3363
  AskResponse: {
2944
3364
  /** @example 1000000000000000000 */
2945
- rate: string;
3365
+ price: string;
2946
3366
  };
2947
3367
  BidResponse: {
2948
3368
  /** @example 1000000000000000000 */
2949
- rate: string;
3369
+ price: string;
2950
3370
  };
2951
3371
  ObligationSingleSuccessResponse: {
2952
3372
  meta: components["schemas"]["Meta"];
@@ -2960,7 +3380,10 @@ interface components {
2960
3380
  /**
2961
3381
  * @description Aggregated router status.
2962
3382
  * @example {
2963
- * "status": "live"
3383
+ * "status": "live",
3384
+ * "initialized": true,
3385
+ * "missing_chains": [],
3386
+ * "missing_collectors": []
2964
3387
  * }
2965
3388
  */
2966
3389
  data: components["schemas"]["RouterStatusDataResponse"];
@@ -2971,6 +3394,24 @@ interface components {
2971
3394
  * @enum {string}
2972
3395
  */
2973
3396
  status: "live" | "syncing";
3397
+ /** @example true */
3398
+ initialized: boolean;
3399
+ /**
3400
+ * @description Configured chain ids missing initialization rows.
3401
+ * @example []
3402
+ */
3403
+ missing_chains: number[];
3404
+ /**
3405
+ * @description Collectors missing initialization rows.
3406
+ * @example []
3407
+ */
3408
+ missing_collectors: components["schemas"]["MissingCollectorResponse"][];
3409
+ };
3410
+ MissingCollectorResponse: {
3411
+ /** @example 1 */
3412
+ chain_id: number;
3413
+ /** @example offers */
3414
+ name: string;
2974
3415
  };
2975
3416
  CollectorsHealthSuccessResponse: {
2976
3417
  meta: components["schemas"]["Meta"];
@@ -2983,7 +3424,8 @@ interface components {
2983
3424
  * "block_number": 21345678,
2984
3425
  * "updated_at": "2024-01-01T12:00:00.000Z",
2985
3426
  * "lag": 0,
2986
- * "status": "live"
3427
+ * "status": "live",
3428
+ * "initialized": true
2987
3429
  * }
2988
3430
  * ]
2989
3431
  */
@@ -3005,6 +3447,8 @@ interface components {
3005
3447
  * @enum {string}
3006
3448
  */
3007
3449
  status: "live" | "lagging" | "unknown";
3450
+ /** @example true */
3451
+ initialized: boolean;
3008
3452
  };
3009
3453
  ChainsHealthSuccessResponse: {
3010
3454
  meta: components["schemas"]["Meta"];
@@ -3015,7 +3459,8 @@ interface components {
3015
3459
  * "chain_id": 1,
3016
3460
  * "local_block_number": 21345678,
3017
3461
  * "remote_block_number": 21345690,
3018
- * "updated_at": "2024-01-01T12:00:00.000Z"
3462
+ * "updated_at": "2024-01-01T12:00:00.000Z",
3463
+ * "initialized": true
3019
3464
  * }
3020
3465
  * ]
3021
3466
  */
@@ -3025,11 +3470,43 @@ interface components {
3025
3470
  /** @example 1 */
3026
3471
  chain_id: number;
3027
3472
  /** @example 21345678 */
3028
- local_block_number: number;
3473
+ local_block_number: number | null;
3029
3474
  /** @example 21345690 */
3030
3475
  remote_block_number: number | null;
3031
3476
  /** @example 2024-01-01T12:00:00.000Z */
3032
- updated_at: string;
3477
+ updated_at: string | null;
3478
+ /** @example true */
3479
+ initialized: boolean;
3480
+ };
3481
+ PositionListResponse: {
3482
+ meta: components["schemas"]["Meta"];
3483
+ /** @example eyJvZmZzZXQiOjEwMH0 */
3484
+ cursor: string | null;
3485
+ /**
3486
+ * @description User positions with reserved balances from active offers.
3487
+ * @example [
3488
+ * {
3489
+ * "chain_id": 1,
3490
+ * "contract": "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3491
+ * "user": "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
3492
+ * "reserved": "200000000000000000000",
3493
+ * "block_number": 21345678
3494
+ * }
3495
+ * ]
3496
+ */
3497
+ data: components["schemas"]["PositionListItemResponse"][];
3498
+ };
3499
+ PositionListItemResponse: {
3500
+ /** @example 1 */
3501
+ chain_id: number;
3502
+ /** @example 0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078 */
3503
+ contract: string;
3504
+ /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
3505
+ user: string;
3506
+ /** @example 200000000000000000000 */
3507
+ reserved: string;
3508
+ /** @example 21345678 */
3509
+ block_number: number;
3033
3510
  };
3034
3511
  ValidateOffersRequest: {
3035
3512
  /** @description Array of offers in snake_case format. Required, non-empty. */
@@ -3037,19 +3514,25 @@ interface components {
3037
3514
  };
3038
3515
  ValidateOfferRequest: {
3039
3516
  /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
3040
- offering: string;
3517
+ maker: string;
3041
3518
  /** @example 369216000000000000000000 */
3042
3519
  assets: string;
3520
+ /** @example 0 */
3521
+ obligation_units?: string;
3522
+ /** @example 0 */
3523
+ obligation_shares?: string;
3043
3524
  /** @example 2750000000000000000 */
3044
- rate: string;
3525
+ price: string;
3045
3526
  /** @example 1761922799 */
3046
3527
  maturity: number;
3047
3528
  /** @example 1761922799 */
3048
3529
  expiry: number;
3049
3530
  /** @example 1761922790 */
3050
3531
  start: number;
3051
- /** @example 571380 */
3052
- nonce: string;
3532
+ /** @example 0x000000000000000000000000000000000000000000000000000000000008b8f4 */
3533
+ group: string;
3534
+ /** @example 0x0000000000000000000000000000000000000000000000000000000000000000 */
3535
+ session: string;
3053
3536
  /** @example false */
3054
3537
  buy: boolean;
3055
3538
  /** @example 1 */
@@ -3065,15 +3548,28 @@ interface components {
3065
3548
  * }
3066
3549
  * ]
3067
3550
  */
3068
- collaterals: components["schemas"]["CollateralResponse"][];
3551
+ collaterals: components["schemas"]["ValidateCollateralRequest"][];
3069
3552
  /**
3070
3553
  * @example {
3071
3554
  * "address": "0x1111111111111111111111111111111111111111",
3072
- * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
3073
- * "gas_limit": "500000"
3555
+ * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000"
3074
3556
  * }
3075
3557
  */
3076
- callback: components["schemas"]["OfferCallbackResponse"];
3558
+ callback: components["schemas"]["ValidateCallbackRequest"];
3559
+ };
3560
+ ValidateCollateralRequest: {
3561
+ /** @example 0x34Cf890dB685FC536E05652FB41f02090c3fb751 */
3562
+ asset: string;
3563
+ /** @example 0x45093658BE7f90B63D7c359e8f408e503c2D9401 */
3564
+ oracle: string;
3565
+ /** @example 860000000000000000 */
3566
+ lltv: string;
3567
+ };
3568
+ ValidateCallbackRequest: {
3569
+ /** @example 0x1111111111111111111111111111111111111111 */
3570
+ address: string;
3571
+ /** @example 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000 */
3572
+ data: string;
3077
3573
  };
3078
3574
  ValidationSuccessResponse: {
3079
3575
  meta: components["schemas"]["Meta"];
@@ -3102,7 +3598,7 @@ interface components {
3102
3598
  pathItems: never;
3103
3599
  }
3104
3600
  declare namespace ObligationResponse_d_exports {
3105
- export { ObligationResponse, from$2 as from };
3601
+ export { ObligationResponse, from$3 as from };
3106
3602
  }
3107
3603
  type ObligationResponse = paths["/v1/obligations"]["get"]["responses"]["200"]["content"]["application/json"]["data"][number];
3108
3604
  /**
@@ -3111,19 +3607,49 @@ type ObligationResponse = paths["/v1/obligations"]["get"]["responses"]["200"]["c
3111
3607
  * @param obligation - {@link Obligation}
3112
3608
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
3113
3609
  */
3114
- declare function from$2(obligation: Obligation, quote: Quote): ObligationResponse;
3610
+ declare function from$3(obligation: Obligation, quote: Quote): ObligationResponse;
3115
3611
  declare namespace OfferResponse_d_exports {
3116
- export { OfferResponse, from$1 as from };
3612
+ export { Input, OfferResponse, from$2 as from };
3117
3613
  }
3118
3614
  type OfferResponse = paths["/v1/offers"]["get"]["responses"]["200"]["content"]["application/json"]["data"][number];
3615
+ type Input = Readonly<{
3616
+ hash: Hex;
3617
+ maker: Address;
3618
+ assets: bigint;
3619
+ obligationUnits: bigint;
3620
+ obligationShares: bigint;
3621
+ price: bigint;
3622
+ maturity: number;
3623
+ expiry: number;
3624
+ start: number;
3625
+ group: Hex;
3626
+ session: Hex;
3627
+ buy: boolean;
3628
+ chainId: number;
3629
+ loanToken: Address;
3630
+ collaterals: Readonly<{
3631
+ asset: Address;
3632
+ lltv: bigint;
3633
+ oracle: Address;
3634
+ }[]>;
3635
+ callback: {
3636
+ address: Address;
3637
+ data: Hex;
3638
+ };
3639
+ root?: Hex | undefined;
3640
+ proof?: Hex[] | undefined;
3641
+ signature?: Hex | undefined;
3642
+ consumed: bigint;
3643
+ takeable: bigint;
3644
+ blockNumber: number;
3645
+ }>;
3119
3646
  /**
3120
- * Creates an `OfferResponse` from an `Offer`.
3647
+ * Creates an `OfferResponse` matching the Solidity Offer struct layout.
3121
3648
  * @constructor
3122
- * @param offer - {@link Offer}
3123
- * @param attestation - {@link Attestation}
3649
+ * @param input - {@link Input}
3124
3650
  * @returns The created `OfferResponse`. {@link OfferResponse}
3125
3651
  */
3126
- declare function from$1(offer: Offer, attestation?: Attestation): OfferResponse;
3652
+ declare function from$2(input: Input): OfferResponse;
3127
3653
  //#endregion
3128
3654
  //#region src/api/Schema/openapi.d.ts
3129
3655
  declare class BooksController {
@@ -3140,10 +3666,16 @@ declare class HealthController {
3140
3666
  getCollectorsHealth(): Promise<void>;
3141
3667
  getChainsHealth(): Promise<void>;
3142
3668
  }
3669
+ declare class ConfigController {
3670
+ getConfig(): Promise<void>;
3671
+ }
3143
3672
  declare class ObligationsController {
3144
3673
  getObligations(): Promise<void>;
3145
3674
  getObligation(): Promise<void>;
3146
3675
  }
3676
+ declare class UsersController {
3677
+ getUserPositions(): Promise<void>;
3678
+ }
3147
3679
  type RuleInfo = {
3148
3680
  name: string;
3149
3681
  description: string;
@@ -3152,21 +3684,66 @@ type OpenApiOptions = {
3152
3684
  rules?: RuleInfo[];
3153
3685
  };
3154
3686
  declare const OpenApi: (options?: OpenApiOptions) => Promise<OpenAPIDocument>;
3687
+ declare namespace PositionResponse_d_exports {
3688
+ export { PositionResponse, PositionWithReserved$1 as PositionWithReserved, from$1 as from };
3689
+ }
3690
+ type PositionResponse = {
3691
+ chain_id: Id;
3692
+ contract: Address;
3693
+ user: Address;
3694
+ reserved: string;
3695
+ block_number: number;
3696
+ };
3697
+ type PositionWithReserved$1 = getByUser.PositionWithReserved;
3698
+ /**
3699
+ * Creates a `PositionResponse` from a `PositionWithReserved`.
3700
+ * @param position - {@link PositionWithReserved}
3701
+ * @returns The created `PositionResponse`. {@link PositionResponse}
3702
+ */
3703
+ declare function from$1(position: PositionWithReserved$1): PositionResponse;
3155
3704
  //#endregion
3156
3705
  //#region src/api/Schema/requests.d.ts
3157
3706
  declare const schemas: {
3707
+ readonly get_health: z$1.ZodObject<{
3708
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
3709
+ 0: "0";
3710
+ 1: "1";
3711
+ true: "true";
3712
+ false: "false";
3713
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
3714
+ }, z$1.core.$strip>;
3715
+ readonly get_health_collectors: z$1.ZodObject<{
3716
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
3717
+ 0: "0";
3718
+ 1: "1";
3719
+ true: "true";
3720
+ false: "false";
3721
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
3722
+ }, z$1.core.$strip>;
3723
+ readonly get_health_chains: z$1.ZodObject<{
3724
+ strict: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodEnum<{
3725
+ 0: "0";
3726
+ 1: "1";
3727
+ true: "true";
3728
+ false: "false";
3729
+ }>, z$1.ZodTransform<boolean, "0" | "1" | "true" | "false">>>;
3730
+ }, z$1.core.$strip>;
3158
3731
  readonly get_offers: z$1.ZodObject<{
3159
3732
  side: z$1.ZodOptional<z$1.ZodEnum<{
3160
3733
  buy: "buy";
3161
3734
  sell: "sell";
3162
3735
  }>>;
3163
3736
  obligation_id: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
3164
- offering: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
3737
+ maker: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
3165
3738
  cursor: z$1.ZodOptional<z$1.ZodString>;
3166
3739
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
3167
3740
  }, z$1.core.$strip>;
3168
3741
  readonly get_obligations: z$1.ZodObject<{
3169
3742
  cursor: z$1.ZodOptional<z$1.ZodString>;
3743
+ chain: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>>;
3744
+ loan_token: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
3745
+ collateral_token: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>>;
3746
+ maturity: z$1.ZodOptional<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>>;
3170
3747
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
3171
3748
  }, z$1.core.$strip>;
3172
3749
  readonly get_obligation: z$1.ZodObject<{
@@ -3184,6 +3761,11 @@ declare const schemas: {
3184
3761
  readonly validate_offers: z$1.ZodObject<{
3185
3762
  offers: z$1.ZodArray<z$1.ZodUnknown>;
3186
3763
  }, z$1.core.$strict>;
3764
+ readonly get_user_positions: z$1.ZodObject<{
3765
+ user_address: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<`0x${string}`, string>>;
3766
+ cursor: z$1.ZodOptional<z$1.ZodString>;
3767
+ limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
3768
+ }, z$1.core.$strip>;
3187
3769
  };
3188
3770
  type Action = keyof typeof schemas;
3189
3771
  declare function parse<A extends Action>(action: A, query: unknown): z$1.infer<(typeof schemas)[A]>;
@@ -3226,6 +3808,25 @@ type Payload<T> = SuccessPayload<T> | ErrorPayload;
3226
3808
  //#region src/api/Controllers/getBook.d.ts
3227
3809
  declare function getBook(params: object, db: Database): Promise<Payload<BookLevelResponse[]>>;
3228
3810
  //#endregion
3811
+ //#region src/api/Controllers/getConfig.d.ts
3812
+ type MaturitiesConfig = {
3813
+ end_of_month: number;
3814
+ end_of_next_month: number;
3815
+ };
3816
+ type ChainConfig = {
3817
+ chain_id: Id;
3818
+ contracts: {
3819
+ mempool: string;
3820
+ };
3821
+ maturities: MaturitiesConfig;
3822
+ };
3823
+ /**
3824
+ * Returns the configuration for all chains the router is indexing.
3825
+ * @param chainRegistry - The chain registry instance. {@link ChainRegistry.ChainRegistry}
3826
+ * @returns The configuration for all chains the router is indexing. {@link ApiPayload.Payload<ChainConfig[]>}
3827
+ */
3828
+ declare function getConfig(chainRegistry: ChainRegistry): Promise<Payload<ChainConfig[]>>;
3829
+ //#endregion
3229
3830
  //#region src/api/Controllers/getDocs.d.ts
3230
3831
  declare function getSwaggerJson({
3231
3832
  gatekeeper
@@ -3237,11 +3838,16 @@ declare function getDocsHtml({
3237
3838
  }: {
3238
3839
  gatekeeper: Gatekeeper;
3239
3840
  }): Promise<string>;
3841
+ /**
3842
+ * Renders the integrator documentation as HTML.
3843
+ * @returns HTML page with the rendered markdown documentation.
3844
+ */
3845
+ declare function getIntegratorDocsHtml(): Promise<string>;
3240
3846
  //#endregion
3241
3847
  //#region src/api/Controllers/getHealth.d.ts
3242
- declare function getHealth(db: Database): Promise<Payload<paths["/v1/health"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3243
- declare function getHealthChains(db: Database, healthClients?: Map<Id, Client>): Promise<Payload<paths["/v1/health/chains"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3244
- declare function getHealthCollectors(db: Database): Promise<Payload<paths["/v1/health/collectors"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3848
+ declare function getHealth(query: unknown, db: Database, chainRegistry?: ChainRegistry): Promise<Payload<paths["/v1/health"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3849
+ declare function getHealthChains(query: unknown, db: Database, healthClients?: Map<Id, Client>, chainRegistry?: ChainRegistry): Promise<Payload<paths["/v1/health/chains"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3850
+ declare function getHealthCollectors(query: unknown, db: Database, chainRegistry?: ChainRegistry): Promise<Payload<paths["/v1/health/collectors"]["get"]["responses"]["200"]["content"]["application/json"]["data"]>>;
3245
3851
  //#endregion
3246
3852
  //#region src/api/Controllers/getObligation.d.ts
3247
3853
  declare function getObligation(params: object, db: Database): Promise<Payload<ObligationResponse>>;
@@ -3252,6 +3858,15 @@ declare function getObligations$1(queryParameters: object, db: Database): Promis
3252
3858
  //#region src/api/Controllers/getOffers.d.ts
3253
3859
  declare function getOffers$1(queryParameters: object, db: Database): Promise<Payload<OfferResponse[]>>;
3254
3860
  //#endregion
3861
+ //#region src/api/Controllers/getUserPositions.d.ts
3862
+ /**
3863
+ * Get positions for a user with remaining balance calculation.
3864
+ * @param queryParameters - Request parameters including user address and pagination.
3865
+ * @param db - Database instance.
3866
+ * @returns Paginated list of positions with remaining balances.
3867
+ */
3868
+ declare function getUserPositions(queryParameters: object, db: Database): Promise<Payload<PositionResponse[]>>;
3869
+ //#endregion
3255
3870
  //#region src/api/Controllers/validateOffers.d.ts
3256
3871
  type ValidationIssue = {
3257
3872
  index: number;
@@ -3268,10 +3883,10 @@ type ValidateOffersIssuesPayload = SuccessPayload<{
3268
3883
  type ValidateOffersResponse = ValidateOffersSuccessPayload | ValidateOffersIssuesPayload;
3269
3884
  declare function validateOffers(body: object, gatekeeper: Gatekeeper): Promise<ValidateOffersResponse | ErrorPayload>;
3270
3885
  declare namespace index_d_exports$4 {
3271
- export { ValidationIssue, getBook, getDocsHtml, getHealth, getHealthChains, getHealthCollectors, getObligation, getObligations$1 as getObligations, getOffers$1 as getOffers, getSwaggerJson, validateOffers };
3886
+ export { ChainConfig, MaturitiesConfig, ValidationIssue, getBook, getConfig, getDocsHtml, getHealth, getHealthChains, getHealthCollectors, getIntegratorDocsHtml, getObligation, getObligations$1 as getObligations, getOffers$1 as getOffers, getSwaggerJson, getUserPositions, validateOffers };
3272
3887
  }
3273
3888
  declare namespace RouterApi_d_exports {
3274
- export { ApiConfig, BookResponse_d_exports as BookResponse, BooksController, ChainHealth, ChainsHealthResponse, CollectorHealth, CollectorsHealthResponse, index_d_exports$4 as Controllers, HealthController, ObligationResponse_d_exports as ObligationResponse, ObligationsController, OfferResponse_d_exports as OfferResponse, OffersController, OpenApi, OpenApiOptions, RouterApi, RouterStatusResponse, RuleInfo, ValidateController, create, from$4 as from, parse, safeParse };
3889
+ export { ApiConfig, BookResponse_d_exports as BookResponse, BooksController, ChainHealth, ChainsHealthResponse, CollectorHealth, CollectorsHealthResponse, ConfigController, index_d_exports$4 as Controllers, HealthController, ObligationResponse_d_exports as ObligationResponse, ObligationsController, OfferResponse_d_exports as OfferResponse, OffersController, OpenApi, OpenApiOptions, PositionResponse_d_exports as PositionResponse, RouterApi, RouterStatusResponse, RuleInfo, UsersController, ValidateController, create, from$5 as from, parse, safeParse };
3275
3890
  }
3276
3891
  declare namespace Client_d_exports {
3277
3892
  export { Client$3 as Client, ConnectOptions, HttpForbiddenError, HttpGetApiFailedError, HttpRateLimitError, HttpUnauthorizedError, InvalidUrlError, connect$1 as connect, getObligations, getOffers };
@@ -3353,10 +3968,17 @@ declare namespace getOffers {
3353
3968
  };
3354
3969
  type ReturnType = {
3355
3970
  offers: Compute<Offer & {
3971
+ hash: Hex;
3972
+ blockNumber: number;
3973
+ consumed: bigint;
3974
+ takeable: bigint;
3975
+ } & {
3356
3976
  /** 32-byte merkle root. */
3357
3977
  root?: Hex;
3358
3978
  /** Sibling hashes for the merkle proof. */
3359
3979
  proof?: Hex[];
3980
+ /** Offer signature from the Merkle tree. */
3981
+ signature?: Hex;
3360
3982
  }>[];
3361
3983
  /** The pagination cursor. */
3362
3984
  cursor: string | null;
@@ -3370,6 +3992,14 @@ declare namespace getObligations {
3370
3992
  cursor?: Hex;
3371
3993
  /** Maximum number of obligations to return. @default 20 */
3372
3994
  limit?: number;
3995
+ /** Filter by chain ID. */
3996
+ chainId?: number;
3997
+ /** Filter by loan token address. */
3998
+ loanToken?: Address;
3999
+ /** Filter by collateral token (matches any collateral in the obligation). */
4000
+ collateralToken?: Address;
4001
+ /** Filter by exact maturity timestamp (unix seconds). */
4002
+ maturity?: number;
3373
4003
  };
3374
4004
  type ReturnType = {
3375
4005
  obligations: Compute<{
@@ -4053,8 +4683,42 @@ declare const offers: drizzle_orm_pg_core0.PgTableWithColumns<{
4053
4683
  identity: undefined;
4054
4684
  generated: undefined;
4055
4685
  }, {}, {}>;
4056
- rate: drizzle_orm_pg_core0.PgColumn<{
4057
- name: "rate";
4686
+ obligationUnits: drizzle_orm_pg_core0.PgColumn<{
4687
+ name: "obligation_units";
4688
+ tableName: EnumTableName.OFFERS;
4689
+ dataType: "string";
4690
+ columnType: "PgNumeric";
4691
+ data: string;
4692
+ driverParam: string;
4693
+ notNull: true;
4694
+ hasDefault: true;
4695
+ isPrimaryKey: false;
4696
+ isAutoincrement: false;
4697
+ hasRuntimeDefault: false;
4698
+ enumValues: undefined;
4699
+ baseColumn: never;
4700
+ identity: undefined;
4701
+ generated: undefined;
4702
+ }, {}, {}>;
4703
+ obligationShares: drizzle_orm_pg_core0.PgColumn<{
4704
+ name: "obligation_shares";
4705
+ tableName: EnumTableName.OFFERS;
4706
+ dataType: "string";
4707
+ columnType: "PgNumeric";
4708
+ data: string;
4709
+ driverParam: string;
4710
+ notNull: true;
4711
+ hasDefault: true;
4712
+ isPrimaryKey: false;
4713
+ isAutoincrement: false;
4714
+ hasRuntimeDefault: false;
4715
+ enumValues: undefined;
4716
+ baseColumn: never;
4717
+ identity: undefined;
4718
+ generated: undefined;
4719
+ }, {}, {}>;
4720
+ price: drizzle_orm_pg_core0.PgColumn<{
4721
+ name: "price";
4058
4722
  tableName: EnumTableName.OFFERS;
4059
4723
  dataType: "string";
4060
4724
  columnType: "PgNumeric";
@@ -4178,8 +4842,8 @@ declare const offers: drizzle_orm_pg_core0.PgTableWithColumns<{
4178
4842
  }, {}, {
4179
4843
  length: 66;
4180
4844
  }>;
4181
- nonce: drizzle_orm_pg_core0.PgColumn<{
4182
- name: "nonce";
4845
+ session: drizzle_orm_pg_core0.PgColumn<{
4846
+ name: "session";
4183
4847
  tableName: EnumTableName.OFFERS;
4184
4848
  dataType: "string";
4185
4849
  columnType: "PgVarchar";
@@ -5414,22 +6078,6 @@ declare const merklePaths: drizzle_orm_pg_core0.PgTableWithColumns<{
5414
6078
  declare namespace index_d_exports$2 {
5415
6079
  export { PositionTypes, StatusCode, TABLE_NAMES, TableName, VERSION, VERSIONED_TABLE_NAMES, VersionedTableName, callbacks$1 as callbacks, chains, collectors, consumedEvents, groups, lots, merklePaths, obligationCollateralsV2, obligations, offers, offersCallbacks, offsets, oracles, positionTypes, positions, status, transfers, trees, validations };
5416
6080
  }
5417
- declare namespace Cursor_d_exports {
5418
- export { Cursor, decode, encode, validate };
5419
- }
5420
- type Cursor = {
5421
- sort: "rate" | "maturity" | "expiry" | "amount";
5422
- dir: "asc" | "desc";
5423
- rate?: string;
5424
- maturity?: number;
5425
- expiry?: number;
5426
- assets?: string;
5427
- hash: string;
5428
- page?: number;
5429
- };
5430
- declare function validate(cursor: unknown): cursor is Cursor;
5431
- declare function encode(c: Cursor): string;
5432
- declare function decode(token?: string): Cursor | null;
5433
6081
  //#endregion
5434
6082
  //#region src/mempool/MempoolEVMClient.d.ts
5435
6083
  type MempoolEVMClientConfig = {
@@ -5482,7 +6130,7 @@ declare class ChainIdMismatchError extends BaseError {
5482
6130
  }
5483
6131
  //#endregion
5484
6132
  //#region src/mempool/MempoolClient.d.ts
5485
- type AddParameters = Compute<Omit<Offer, "hash" | "createdAt">[]>;
6133
+ type AddParameters = Compute<Omit<Offer, "createdAt">[]>;
5486
6134
  type GetParameters = {
5487
6135
  /** The block number to get offers from. */
5488
6136
  blockNumberGte?: number;
@@ -5540,6 +6188,12 @@ declare namespace index_d_exports$1 {
5540
6188
  //#region src/utils/BigMath.d.ts
5541
6189
  declare function max$1(a: bigint, b: bigint): bigint;
5542
6190
  declare function min(a: bigint, b: bigint): bigint;
6191
+ /**
6192
+ * Checks if at most one of the given values is non-zero.
6193
+ * @param values - The bigint values to check.
6194
+ * @returns True if zero or one value is non-zero, false if two or more are non-zero.
6195
+ */
6196
+ declare function atMostOneNonZero(...values: bigint[]): boolean;
5543
6197
  //#endregion
5544
6198
  //#region src/utils/batch.d.ts
5545
6199
  /**
@@ -5577,6 +6231,15 @@ declare function batchMulticall<TResult>(parameters: {
5577
6231
  retryDelayMs: number;
5578
6232
  blockNumber?: bigint;
5579
6233
  }): Promise<TResult[]>;
6234
+ declare namespace Group_d_exports {
6235
+ export { fromNumber };
6236
+ }
6237
+ /**
6238
+ * Creates a bytes32 group identifier from a number.
6239
+ * @param n - A non-negative integer.
6240
+ * @throws {Error} If n is negative or not an integer.
6241
+ */
6242
+ declare const fromNumber: (n: number) => Hex;
5580
6243
  //#endregion
5581
6244
  //#region src/utils/lazy.d.ts
5582
6245
  /**
@@ -5651,8 +6314,8 @@ declare function max(): number;
5651
6314
  //#region src/utils/wait.d.ts
5652
6315
  declare function wait(time: number): Promise<unknown>;
5653
6316
  declare namespace index_d_exports$3 {
5654
- export { BaseError, GlobalErrorType, Random_d_exports as Random, 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 };
6317
+ 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 };
5655
6318
  }
5656
6319
  //#endregion
5657
- export { index_d_exports as Abi, BookResponse_d_exports as BookResponse, BooksController, Brand, BrandTypeId, Callback_d_exports as Callback, Chain_d_exports as Chain, ChainHealth, ChainsHealthResponse, Collateral_d_exports as Collateral, CollectorHealth, CollectorsHealthResponse, Compute, Cursor_d_exports as Cursor, Database_d_exports as Database, 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, Health_d_exports as Health, HealthController, Indexer_d_exports as Indexer, LLTV_d_exports as LLTV, Liquidity_d_exports as Liquidity, Logger_d_exports as Logger, Maturity_d_exports as Maturity, index_d_exports$1 as Mempool, Obligation_d_exports as Obligation, ObligationResponse_d_exports as ObligationResponse, ObligationsController, Offer_d_exports as Offer, OfferResponse_d_exports as OfferResponse, OffersController, index_d_exports$2 as OffersSchema, OpenApi, OpenApiOptions, Oracle_d_exports as Oracle, Position_d_exports as Position, Quote_d_exports as Quote, RouterApi_d_exports as RouterApi, Client_d_exports as RouterClient, RouterStatusResponse, RuleInfo, Rules_d_exports as Rules, time_d_exports as Time, Transfer_d_exports as Transfer, Tree_d_exports as Tree, index_d_exports$3 as Utils, ValidateController, Gate_d_exports as Validation, morphoRules, parse, safeParse };
6320
+ export { index_d_exports as Abi, BookResponse_d_exports as BookResponse, BooksController, Brand, BrandTypeId, Callback_d_exports as Callback, Chain_d_exports as Chain, ChainHealth, ChainRegistry_d_exports as ChainRegistry, ChainsHealthResponse, Collateral_d_exports as Collateral, CollectorHealth, CollectorsHealthResponse, Compute, ConfigController, Database_d_exports as Database, 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, Health_d_exports as Health, HealthController, Indexer_d_exports as Indexer, LLTV_d_exports as LLTV, Liquidity_d_exports as Liquidity, Logger_d_exports as Logger, Maturity_d_exports as Maturity, index_d_exports$1 as Mempool, Obligation_d_exports as Obligation, ObligationResponse_d_exports as ObligationResponse, ObligationsController, Offer_d_exports as Offer, OfferResponse_d_exports as OfferResponse, OffersController, index_d_exports$2 as OffersSchema, OpenApi, OpenApiOptions, Oracle_d_exports as Oracle, Position_d_exports as Position, PositionResponse_d_exports as PositionResponse, Quote_d_exports as Quote, RouterApi_d_exports as RouterApi, Client_d_exports as RouterClient, RouterStatusResponse, RuleInfo, Rules_d_exports as Rules, time_d_exports as Time, Transfer_d_exports as Transfer, Tree_d_exports as Tree, UsersController, index_d_exports$3 as Utils, ValidateController, Gate_d_exports as Validation, morphoRules, parse, safeParse };
5658
6321
  //# sourceMappingURL=index.node.d.ts.map