@morpho-dev/router 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -330,7 +330,7 @@ declare const Morpho: readonly [{
330
330
  readonly stateMutability: "view";
331
331
  }];
332
332
  declare namespace Callback_d_exports {
333
- export { CallbackType, decode$3 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$3 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
333
+ export { BuyVaultV1CallbackData, CallbackType, SellERC20CallbackData, decode$3 as decode, decodeBuyVaultV1Callback, decodeSellERC20Callback, encode$3 as encode, encodeBuyVaultV1Callback, encodeSellERC20Callback, isEmptyCallback };
334
334
  }
335
335
  declare enum CallbackType {
336
336
  BuyWithEmptyCallback = "buy_with_empty_callback",
@@ -342,7 +342,16 @@ declare function decode$3(type: CallbackType, data: Hex): {
342
342
  contract: Address;
343
343
  amount: bigint;
344
344
  }[];
345
- declare function encode$3(type: CallbackType, data: any): Hex;
345
+ type BuyVaultV1CallbackData = {
346
+ vaults: Address[];
347
+ amounts: bigint[];
348
+ };
349
+ type SellERC20CallbackData = {
350
+ collaterals: Address[];
351
+ amounts: bigint[];
352
+ };
353
+ declare function encode$3(type: CallbackType.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;
354
+ declare function encode$3(type: CallbackType.SellERC20Callback, data: SellERC20CallbackData): Hex;
346
355
  declare function decodeBuyVaultV1Callback(data: Hex): Array<{
347
356
  contract: Address;
348
357
  amount: bigint;
@@ -691,7 +700,7 @@ declare class InvalidOptionError extends BaseError {
691
700
  constructor(input: string);
692
701
  }
693
702
  declare namespace Offer_d_exports {
694
- export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferHashSchema, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$2 as decode, domain, encode$2 as encode, from$9 as from, fromSnakeCase$2 as fromSnakeCase, hash, obligationId, random$2 as random, sign, signatureMsg, toSnakeCase, types };
703
+ export { AccountNotSetError, InvalidOfferError, Offer, OfferConsumed, OfferHashSchema, OfferSchema, RandomConfig, Status, Validation, consumedEvent, decode$2 as decode, domain, encode$2 as encode, from$9 as from, fromSnakeCase$2 as fromSnakeCase, hash, obligationId, random$2 as random, serialize, sign, signatureMsg, toSnakeCase, types };
695
704
  }
696
705
  type Offer = {
697
706
  /** The address that made the offer. */
@@ -800,6 +809,37 @@ declare function fromSnakeCase$2(input: Snake<Omit<Offer, "chainId" | "hash"> &
800
809
  * @returns The converted offer.
801
810
  */
802
811
  declare function toSnakeCase(offer: Offer): Snake<Offer>;
812
+ /**
813
+ * Serializes an offer for merkle tree encoding.
814
+ * Converts BigInt fields to strings for JSON compatibility.
815
+ *
816
+ * @param offer - Offer to serialize
817
+ * @returns JSON-serializable offer object
818
+ */
819
+ declare const serialize: (offer: Offer) => {
820
+ offering: `0x${string}`;
821
+ assets: string;
822
+ rate: string;
823
+ maturity: number;
824
+ expiry: number;
825
+ start: number;
826
+ nonce: string;
827
+ buy: boolean;
828
+ chainId: Id;
829
+ loanToken: `0x${string}`;
830
+ collaterals: {
831
+ asset: `0x${string}`;
832
+ oracle: `0x${string}`;
833
+ lltv: string;
834
+ }[];
835
+ callback: {
836
+ address: `0x${string}`;
837
+ data: `0x${string}`;
838
+ gasLimit: string;
839
+ };
840
+ signature: `0x${string}` | undefined;
841
+ hash: `0x${string}`;
842
+ };
803
843
  type RandomConfig = {
804
844
  chains?: Chain$1[];
805
845
  loanTokens?: Address[];
@@ -1431,46 +1471,148 @@ declare namespace from$4 {
1431
1471
  type ReturnType = Transfer;
1432
1472
  }
1433
1473
  declare namespace Tree_d_exports {
1434
- export { Tree, VERSION, decode$1 as decode, encode$1 as encode, from$3 as from };
1474
+ export { DecodeError, EncodeError, Proof, Tree, TreeError, VERSION, decode$1 as decode, encode$1 as encode, encodeUnsigned, from$3 as from, proofs };
1435
1475
  }
1476
+ /**
1477
+ * A merkle tree of offers built from offer hashes.
1478
+ * Constructed via {@link from}. The tree root can be signed for onchain broadcast.
1479
+ */
1436
1480
  type Tree = Compute<StandardMerkleTree<[Hex]> & {
1481
+ /** The offers in the tree. */
1437
1482
  offers: Offer[];
1483
+ /** The root of the tree. */
1438
1484
  root: Hex;
1439
1485
  }>;
1486
+ type Proof = {
1487
+ /** The offer that the proof is for. */
1488
+ offer: Offer;
1489
+ /** The merkle proof path for the offer. */
1490
+ path: Hex[];
1491
+ };
1440
1492
  declare const VERSION = 1;
1441
1493
  /**
1442
1494
  * Builds a Merkle tree from a list of offers.
1443
1495
  *
1444
1496
  * Leaves are the offer `hash` values as `bytes32` and are deterministically
1445
- * ordered in ascending lexicographic order so that the resulting root is stable
1446
- * regardless of the input order.
1497
+ * ordered following the StandardMerkleTree leaf ordering so that the resulting
1498
+ * root is stable regardless of the input order.
1447
1499
  *
1448
1500
  * @param offers - Offers to include in the tree.
1449
1501
  * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.
1502
+ * @throws {TreeError} If tree building fails due to offer inconsistencies.
1450
1503
  */
1451
1504
  declare const from$3: (offers: Offer[]) => Tree;
1452
1505
  /**
1453
- * Encodes an `Tree` into a Hex string with a version byte prefix and gzipped payload.
1506
+ * Generates merkle proofs for all offers in a tree.
1507
+ *
1508
+ * Each proof allows independent verification that an offer is included in the tree
1509
+ * without requiring the full tree. Proofs are ordered by StandardMerkleTree leaf ordering.
1510
+ *
1511
+ * @param tree - The {@link Tree} to generate proofs for.
1512
+ * @returns Array of proofs - {@link Proof}
1513
+ */
1514
+ declare const proofs: (tree: Tree) => Proof[];
1515
+ /**
1516
+ * Encodes a merkle tree with signature into hex calldata for onchain broadcast.
1517
+ *
1518
+ * Layout: `0x{vv}{gzip([...offers])}{root}{signature}` where:
1519
+ * - `{vv}`: 1-byte version (currently 0x01)
1520
+ * - `{gzip([...offers])}`: gzipped JSON array of serialized offers
1521
+ * - `{root}`: 32-byte merkle root
1522
+ * - `{signature}`: 65-byte EIP-191 signature over raw root bytes
1523
+ *
1524
+ * Validates signature authenticity and root integrity before encoding.
1525
+ *
1526
+ * @example
1527
+ * ```typescript
1528
+ * const tree = Tree.from(offers);
1529
+ * const signature = await wallet.signMessage({ message: { raw: tree.root } });
1530
+ * const calldata = await Tree.encode(tree, signature);
1531
+ * await broadcast(calldata);
1532
+ * ```
1533
+ *
1534
+ * @example
1535
+ * Manual construction (for advanced users):
1536
+ * ```typescript
1537
+ * const tree = Tree.from(offers);
1538
+ * const compressed = gzip(JSON.stringify(tree.offers.map(Offer.serialize)));
1539
+ * const partial = `0x01${bytesToHex(compressed)}${tree.root.slice(2)}`;
1540
+ * const signature = await wallet.signMessage({ message: { raw: tree.root } });
1541
+ * const calldata = `${partial}${signature.slice(2)}`;
1542
+ * ```
1543
+ *
1544
+ * @param tree - Merkle tree of offers
1545
+ * @param signature - EIP-191 signature over raw root bytes
1546
+ * @returns Hex-encoded calldata ready for onchain broadcast
1547
+ * @throws {EncodeError} If signature verification fails or root mismatch
1548
+ */
1549
+ declare const encode$1: (tree: Tree, signature: Hex) => Promise<Hex>;
1550
+ /**
1551
+ * Encodes a merkle tree without a signature into hex payload for client-side signing.
1552
+ *
1553
+ * Layout: `0x{vv}{gzip([...offers])}{root}` where:
1554
+ * - `{vv}`: 1-byte version (currently 0x01)
1555
+ * - `{gzip([...offers])}`: gzipped JSON array of serialized offers
1556
+ * - `{root}`: 32-byte merkle root
1454
1557
  *
1455
- * - Layout: `0x{vv}{zip...}` where `{vv}` is one-byte version as two hex chars.
1456
- * - Payload is gzip(JSON.stringify([root, ...offers])) with bigint stringified.
1558
+ * Validates root integrity before encoding.
1457
1559
  *
1458
- * @param tree - The offer Merkle tree to encode.
1459
- * @returns Hex string starting with `0x{vv}` followed by gzipped payload bytes.
1460
- * @throws Error if the given `root` does not match the offers.
1560
+ * @param tree - Merkle tree of offers
1561
+ * @returns Hex-encoded unsigned payload
1562
+ * @throws {EncodeError} If root mismatch
1461
1563
  */
1462
- declare const encode$1: (tree: Tree) => Hex;
1564
+ declare const encodeUnsigned: (tree: Tree) => Hex;
1463
1565
  /**
1464
- * Decodes a Hex string produced by {@link encode} back into an `Tree`.
1566
+ * Decodes hex calldata into a validated merkle tree.
1465
1567
  *
1466
- * - Ensures the first byte version matches {@link VERSION}.
1467
- * - Decompresses with gunzip, parses JSON, validates offers, and re-checks the root.
1568
+ * Validates signature before decompression for fail-fast rejection of invalid payloads.
1569
+ * Returns the tree with separately validated signature and recovered signer address.
1468
1570
  *
1469
- * @param encoded - Hex string in the form `0x{vv}{zip...}`.
1470
- * @returns A validated `Tree` rebuilt from the offers.
1471
- * @throws Error if the version is invalid or the root does not match the offers.
1571
+ * Validation order:
1572
+ * 1. Version check
1573
+ * 2. Signature verification (fail-fast, before decompression)
1574
+ * 3. Decompression (only if signature valid)
1575
+ * 4. Root verification (computed from offers vs embedded root)
1576
+ *
1577
+ * @example
1578
+ * ```typescript
1579
+ * const { tree, signature, signer } = await Tree.decode(calldata);
1580
+ * console.log(`Tree signed by ${signer} with ${tree.offers.length} offers`);
1581
+ * ```
1582
+ *
1583
+ * @param encoded - Hex calldata in format `0x{vv}{gzip}{root}{signature}`
1584
+ * @returns Validated tree, signature, and recovered signer address
1585
+ * @throws {DecodeError} If version invalid, signature invalid, or root mismatch
1586
+ */
1587
+ declare const decode$1: (encoded: Hex) => Promise<{
1588
+ tree: Tree;
1589
+ signature: Hex;
1590
+ signer: Address;
1591
+ }>;
1592
+ /**
1593
+ * Error thrown during tree building operations.
1594
+ * Indicates structural issues with the tree (missing offers, inconsistent state).
1472
1595
  */
1473
- declare const decode$1: (encoded: Hex) => Tree;
1596
+ declare class TreeError extends BaseError {
1597
+ name: string;
1598
+ constructor(reason: string);
1599
+ }
1600
+ /**
1601
+ * Error thrown during tree encoding.
1602
+ * Indicates validation failures (signature, root mismatch, mixed makers).
1603
+ */
1604
+ declare class EncodeError extends BaseError {
1605
+ name: string;
1606
+ constructor(reason: string);
1607
+ }
1608
+ /**
1609
+ * Error thrown during tree decoding.
1610
+ * Indicates payload corruption, version mismatch, or validation failures.
1611
+ */
1612
+ declare class DecodeError extends BaseError {
1613
+ name: string;
1614
+ constructor(reason: string);
1615
+ }
1474
1616
  //#endregion
1475
1617
  //#region src/api/Schema/generated/swagger.d.ts
1476
1618
  /**
@@ -1841,10 +1983,11 @@ interface paths {
1841
1983
  put?: never;
1842
1984
  /**
1843
1985
  * Validate offers
1844
- * @description Validates offers against router validation rules. Returns validation status for each offer.
1986
+ * @description Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure.
1845
1987
  *
1846
1988
  * **Available validation rules:**
1847
1989
  * - **parse_error**: Returns when an offer fails to parse due to invalid format or missing required fields
1990
+ * - **mixed_maker**: Validates that all offers in a batch have the same maker (offering address)
1848
1991
  * - **chain_ids**: Validates that offer chain is one of: [109111114]
1849
1992
  * - **maturity**: Validates that offer maturity is one of: [end_of_month, end_of_next_month]
1850
1993
  * - **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]
@@ -1869,7 +2012,7 @@ interface paths {
1869
2012
  [name: string]: unknown;
1870
2013
  };
1871
2014
  content: {
1872
- "application/json": components["schemas"]["ValidateOffersListResponse"];
2015
+ "application/json": components["schemas"]["ValidationSuccessResponse"];
1873
2016
  };
1874
2017
  };
1875
2018
  /** @description Bad Request */
@@ -1964,10 +2107,15 @@ interface components {
1964
2107
  * "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000",
1965
2108
  * "gas_limit": "500000"
1966
2109
  * },
1967
- * "signature": "0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400",
1968
2110
  * "consumed": "0",
1969
2111
  * "takeable": "369216000000000000000000",
1970
- * "block_number": 2942933377146801
2112
+ * "block_number": 2942933377146801,
2113
+ * "root": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
2114
+ * "proof": [
2115
+ * "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
2116
+ * "0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba"
2117
+ * ],
2118
+ * "signature": "0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400"
1971
2119
  * }
1972
2120
  * ]
1973
2121
  */
@@ -2020,6 +2168,15 @@ interface components {
2020
2168
  consumed: string;
2021
2169
  /** @example 2942933377146801 */
2022
2170
  block_number: number;
2171
+ /** @example 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef */
2172
+ root: string | null;
2173
+ /**
2174
+ * @example [
2175
+ * "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
2176
+ * "0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba"
2177
+ * ]
2178
+ */
2179
+ proof: string[] | null;
2023
2180
  /** @example 0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400 */
2024
2181
  signature: string | null;
2025
2182
  };
@@ -2151,13 +2308,8 @@ interface components {
2151
2308
  updated_at: string;
2152
2309
  };
2153
2310
  ValidateOffersRequest: {
2154
- /** @description Array of offers in snake_case format. Mutually exclusive with 'calldata'. */
2155
- offers?: components["schemas"]["ValidateOfferRequest"][];
2156
- /**
2157
- * @description Encoded tree calldata as a hex string (0x-prefixed). Mutually exclusive with 'offers'.
2158
- * @example 0x01...
2159
- */
2160
- calldata?: string;
2311
+ /** @description Array of offers in snake_case format. Required, non-empty. */
2312
+ offers: components["schemas"]["ValidateOfferRequest"][];
2161
2313
  };
2162
2314
  ValidateOfferRequest: {
2163
2315
  /** @example 0x7b093658BE7f90B63D7c359e8f408e503c2D9401 */
@@ -2199,22 +2351,24 @@ interface components {
2199
2351
  */
2200
2352
  callback: components["schemas"]["OfferCallbackResponse"];
2201
2353
  };
2202
- ValidateOffersListResponse: {
2354
+ ValidationSuccessResponse: {
2203
2355
  meta: components["schemas"]["Meta"];
2204
2356
  /** @example null */
2205
2357
  cursor: string | null;
2206
- /** @description Validation results for each offer. */
2207
- data: components["schemas"]["ValidateOfferResultResponse"][];
2358
+ /** @description Payload and root for client-side signing. */
2359
+ data: components["schemas"]["ValidationSuccessDataResponse"];
2208
2360
  };
2209
- ValidateOfferResultResponse: {
2210
- /** @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427 */
2211
- offer_hash: string;
2212
- /** @example false */
2213
- valid: boolean;
2214
- /** @example parse_error */
2215
- rule: string | null;
2216
- /** @example Invalid offer. 'offering': invalid address */
2217
- message: string | null;
2361
+ ValidationSuccessDataResponse: {
2362
+ /**
2363
+ * @description Unsigned payload: version (1B) + gzip(offers) + root (32B).
2364
+ * @example 0x01789c...
2365
+ */
2366
+ payload: string;
2367
+ /**
2368
+ * @description Merkle tree root to sign with EIP-191.
2369
+ * @example 0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427
2370
+ */
2371
+ root: string;
2218
2372
  };
2219
2373
  };
2220
2374
  responses: never;
@@ -2234,6 +2388,202 @@ type ObligationResponse = paths["/v1/obligations"]["get"]["responses"]["200"]["c
2234
2388
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
2235
2389
  */
2236
2390
  declare function from$2(obligation: Obligation, quote: Quote): ObligationResponse;
2391
+ declare namespace Gate_d_exports {
2392
+ export { Batch, Issue, Result, Rule, RuleNames, Single, batch$1 as batch, run, single };
2393
+ }
2394
+ /**
2395
+ * A validation rule.
2396
+ */
2397
+ type Rule<T, Name$1 extends string = string> = {
2398
+ kind: "single";
2399
+ name: Name$1;
2400
+ description: string;
2401
+ run: Single<T, Name$1>;
2402
+ } | {
2403
+ kind: "batch";
2404
+ name: Name$1;
2405
+ description: string;
2406
+ run: Batch<T, Name$1>;
2407
+ };
2408
+ type RuleNames<Rules$1 extends readonly {
2409
+ name: string;
2410
+ }[]> = Rules$1[number]["name"];
2411
+ /**
2412
+ * A single item validation rule.
2413
+ * @param item - The item to validate.
2414
+ * @returns The issue that was found. If the item is valid, this will be undefined.
2415
+ */
2416
+ type Single<T, RuleName extends string> = (item: T) => Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined | Promise<Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>;
2417
+ /**
2418
+ * A batch item validation rule.
2419
+ * @param items - The items to validate.
2420
+ * @returns A map of the items to the issue that was found.
2421
+ */
2422
+ 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>>;
2423
+ /**
2424
+ * Create a validation rule iterating over a single item at a time.
2425
+ * @param name - The name of the rule.
2426
+ * @param description - A human-readable description of the rule.
2427
+ * @param run - The function that validates the rule.
2428
+ * @returns The created rule.
2429
+ */
2430
+ declare function single<Name$1 extends string, T>(name: Name$1, description: string, run: Single<T, Name$1>): Rule<T, Name$1>;
2431
+ /**
2432
+ * Create a validation rule iterating over a batch of items at a time.
2433
+ * @param name - The name of the rule.
2434
+ * @param description - A human-readable description of the rule.
2435
+ * @param run - The function that validates the rule.
2436
+ * @returns The created rule.
2437
+ */
2438
+ declare function batch$1<Name$1 extends string, T>(name: Name$1, description: string, run: Batch<T, Name$1>): Rule<T, Name$1>;
2439
+ /**
2440
+ * A validation issue.
2441
+ */
2442
+ type Issue<T, RuleName extends string = string> = {
2443
+ /** The name of the rule that caused the issue. */
2444
+ ruleName: RuleName;
2445
+ /** The message of the issue. */
2446
+ message: string;
2447
+ /** The item that was not valid. */
2448
+ item: T;
2449
+ };
2450
+ /**
2451
+ * The result of a validation.
2452
+ */
2453
+ type Result<T, RuleName extends string = string> = {
2454
+ /** The items that were valid. */
2455
+ valid: T[];
2456
+ /** The reports of the failed validations. */
2457
+ issues: Issue<T, RuleName>[];
2458
+ };
2459
+ declare function run<T, Name$1 extends string, Rules$1 extends readonly Rule<T, Name$1>[]>(parameters: {
2460
+ items: T[];
2461
+ rules: Rules$1;
2462
+ chunkSize?: number;
2463
+ }): Promise<Result<T, RuleNames<Rules$1>>>;
2464
+ declare namespace Gatekeeper_d_exports {
2465
+ export { Gatekeeper, Rules, create };
2466
+ }
2467
+ type Rules = readonly Rule<Offer, string>[];
2468
+ type Gatekeeper = {
2469
+ rules: Rules;
2470
+ isAllowed: (offers: Offer[]) => Promise<Result<Offer, string>>;
2471
+ };
2472
+ type GatekeeperParameters = {
2473
+ rules: Rules;
2474
+ };
2475
+ declare function create(parameters: GatekeeperParameters): Gatekeeper;
2476
+ declare namespace GateConfig_d_exports {
2477
+ export { CallbackConfig, GateConfig, assets$1 as assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
2478
+ }
2479
+ type GateConfig = {
2480
+ callbacks?: CallbackConfig[];
2481
+ maturities?: MaturityType[];
2482
+ };
2483
+ type CallbackConfig = {
2484
+ type: CallbackType.BuyVaultV1Callback;
2485
+ addresses: Address[];
2486
+ vaultFactories: Address[];
2487
+ } | {
2488
+ type: CallbackType.SellERC20Callback;
2489
+ addresses: Address[];
2490
+ } | {
2491
+ type: CallbackType.BuyWithEmptyCallback;
2492
+ };
2493
+ declare function getCallback(chain: Name, type: CallbackType.BuyVaultV1Callback): Extract<CallbackConfig, {
2494
+ type: CallbackType.BuyVaultV1Callback;
2495
+ }> | undefined;
2496
+ declare function getCallback(chain: Name, type: CallbackType.SellERC20Callback): Extract<CallbackConfig, {
2497
+ type: CallbackType.SellERC20Callback;
2498
+ }> | undefined;
2499
+ declare function getCallback(chain: Name, type: CallbackType.BuyWithEmptyCallback): Extract<CallbackConfig, {
2500
+ type: CallbackType.BuyWithEmptyCallback;
2501
+ }> | undefined;
2502
+ declare function getCallback(chain: Name, type: CallbackType): CallbackConfig | undefined;
2503
+ /**
2504
+ * Attempts to infer the configured callback type from a callback address on a chain.
2505
+ * Skips the empty callback type as it does not carry addresses.
2506
+ *
2507
+ * @param chain - Chain name for which to infer the callback type
2508
+ * @param address - Callback contract address
2509
+ * @returns The callback type when found, otherwise undefined
2510
+ */
2511
+ declare function getCallbackType(chain: Name, address: Address): CallbackType | undefined;
2512
+ /**
2513
+ * Returns the callback addresses for a given chain and callback type, if it exists.
2514
+ * @param chain - Chain name for which to read the validation configuration
2515
+ * @param type - Callback type to retrieve
2516
+ * @returns The matching callback addresses or an empty array if not configured
2517
+ */
2518
+ declare function getCallbackTypeAddresses(chain: Name, type: CallbackType): Address[];
2519
+ /**
2520
+ * Returns the list of allowed non-empty callback addresses for a chain.
2521
+ *
2522
+ * @param chain - Chain name
2523
+ * @returns Array of allowed callback addresses (lowercased). Empty when none configured
2524
+ */
2525
+ declare const getCallbackAddresses: (chain: Name) => Address[];
2526
+ declare const assets$1: Record<string, Address[]>;
2527
+ declare const configs: Record<Name, GateConfig>;
2528
+ //#endregion
2529
+ //#region src/gatekeeper/morphoRules.d.ts
2530
+ declare const morphoRules: (chains: Chain$1[]) => (Rule<Offer, "mixed_maker"> | Rule<Offer, "chain_ids"> | Rule<Offer, "maturity"> | Rule<Offer, "callback"> | Rule<Offer, "token">)[];
2531
+ declare namespace Rules_d_exports {
2532
+ export { ValidityParameters, callback, chains, maturity, sameMaker, token, validity };
2533
+ }
2534
+ type ValidityParameters = {
2535
+ client: PublicClient<Transport, Chain$1>;
2536
+ };
2537
+ /**
2538
+ * set of rules to validate offers.
2539
+ *
2540
+ * @param parameters - Validity parameters with chain and client
2541
+ * @returns Array of validation rules to evaluate against offers
2542
+ */
2543
+ declare function validity(parameters: ValidityParameters): (Rule<Offer, "expiry"> | Rule<Offer, "sell_erc20_callback_invalid"> | Rule<Offer, "buy_offers_callback_vault_invalid">)[];
2544
+ declare const chains: ({
2545
+ chains
2546
+ }: {
2547
+ chains: Chain$1[];
2548
+ }) => Rule<Offer, "chain_ids">;
2549
+ declare const maturity: ({
2550
+ maturities
2551
+ }: {
2552
+ maturities: MaturityType[];
2553
+ }) => Rule<Offer, "maturity">;
2554
+ declare const callback: ({
2555
+ callbacks,
2556
+ allowedAddresses
2557
+ }: {
2558
+ callbacks: CallbackType[];
2559
+ allowedAddresses: Address[];
2560
+ }) => Rule<Offer, "callback">;
2561
+ /**
2562
+ * A validation rule that checks if the offer's token is allowed.
2563
+ * @param offer - The offer to validate.
2564
+ * @returns The issue that was found. If the offer is valid, this will be undefined.
2565
+ */
2566
+ declare const token: ({
2567
+ assets
2568
+ }: {
2569
+ assets: Address[];
2570
+ }) => Rule<Offer, "token">;
2571
+ /**
2572
+ * A batch validation rule that ensures all offers in a tree have the same maker (offering address).
2573
+ * Returns an issue only for the first non-conforming offer.
2574
+ * This rule is signing-agnostic; signer verification is handled at the collector level.
2575
+ */
2576
+ declare const sameMaker: () => Rule<Offer, "mixed_maker">;
2577
+ //#endregion
2578
+ //#region src/database/domains/Trees.d.ts
2579
+ /**
2580
+ * Attestation data for a single offer, containing the merkle root, signature, and proof.
2581
+ */
2582
+ type Attestation = {
2583
+ root: Hex;
2584
+ signature: Hex;
2585
+ proof: Hex[];
2586
+ };
2237
2587
  declare namespace OfferResponse_d_exports {
2238
2588
  export { OfferResponse, from$1 as from };
2239
2589
  }
@@ -2242,9 +2592,10 @@ type OfferResponse = paths["/v1/offers"]["get"]["responses"]["200"]["content"]["
2242
2592
  * Creates an `OfferResponse` from an `Offer`.
2243
2593
  * @constructor
2244
2594
  * @param offer - {@link Offer}
2595
+ * @param attestation - {@link Attestation}
2245
2596
  * @returns The created `OfferResponse`. {@link OfferResponse}
2246
2597
  */
2247
- declare function from$1(offer: Offer): OfferResponse;
2598
+ declare function from$1(offer: Offer, attestation?: Attestation): OfferResponse;
2248
2599
  //#endregion
2249
2600
  //#region src/api/Schema/openapi.d.ts
2250
2601
  declare class BooksController {
@@ -2303,9 +2654,8 @@ declare const schemas: {
2303
2654
  limit: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodPipe<z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<number, string>>, z$1.ZodNumber>>>;
2304
2655
  }, z$1.core.$strip>;
2305
2656
  readonly validate_offers: z$1.ZodObject<{
2306
- offers: z$1.ZodAny;
2307
- calldata: z$1.ZodOptional<z$1.ZodString>;
2308
- }, z$1.core.$strip>;
2657
+ offers: z$1.ZodArray<z$1.ZodUnknown>;
2658
+ }, z$1.core.$strict>;
2309
2659
  };
2310
2660
  type Action = keyof typeof schemas;
2311
2661
  declare function parse<A extends Action>(action: A, query: unknown): z$1.infer<(typeof schemas)[A]>;
@@ -2392,7 +2742,12 @@ declare namespace getOffers {
2392
2742
  limit?: number;
2393
2743
  };
2394
2744
  type ReturnType = {
2395
- offers: Offer[];
2745
+ offers: Compute<Offer & {
2746
+ /** 32-byte merkle root. */
2747
+ root?: Hex;
2748
+ /** Sibling hashes for the merkle proof. */
2749
+ proof?: Hex[];
2750
+ }>[];
2396
2751
  /** The pagination cursor. */
2397
2752
  cursor: string | null;
2398
2753
  };
@@ -2457,186 +2812,6 @@ type Cursor = {
2457
2812
  declare function validate(cursor: unknown): cursor is Cursor;
2458
2813
  declare function encode(c: Cursor): string;
2459
2814
  declare function decode(token?: string): Cursor | null;
2460
- declare namespace Gate_d_exports {
2461
- export { Batch, Issue, Result, Rule, RuleNames, Single, batch$1 as batch, run, single };
2462
- }
2463
- /**
2464
- * A validation rule.
2465
- */
2466
- type Rule<T, Name$1 extends string = string> = {
2467
- kind: "single";
2468
- name: Name$1;
2469
- description: string;
2470
- run: Single<T, Name$1>;
2471
- } | {
2472
- kind: "batch";
2473
- name: Name$1;
2474
- description: string;
2475
- run: Batch<T, Name$1>;
2476
- };
2477
- type RuleNames<Rules$1 extends readonly {
2478
- name: string;
2479
- }[]> = Rules$1[number]["name"];
2480
- /**
2481
- * A single item validation rule.
2482
- * @param item - The item to validate.
2483
- * @returns The issue that was found. If the item is valid, this will be undefined.
2484
- */
2485
- type Single<T, RuleName extends string> = (item: T) => Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined | Promise<Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>;
2486
- /**
2487
- * A batch item validation rule.
2488
- * @param items - The items to validate.
2489
- * @returns A map of the items to the issue that was found.
2490
- */
2491
- 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>>;
2492
- /**
2493
- * Create a validation rule iterating over a single item at a time.
2494
- * @param name - The name of the rule.
2495
- * @param description - A human-readable description of the rule.
2496
- * @param run - The function that validates the rule.
2497
- * @returns The created rule.
2498
- */
2499
- declare function single<Name$1 extends string, T>(name: Name$1, description: string, run: Single<T, Name$1>): Rule<T, Name$1>;
2500
- /**
2501
- * Create a validation rule iterating over a batch of items at a time.
2502
- * @param name - The name of the rule.
2503
- * @param description - A human-readable description of the rule.
2504
- * @param run - The function that validates the rule.
2505
- * @returns The created rule.
2506
- */
2507
- declare function batch$1<Name$1 extends string, T>(name: Name$1, description: string, run: Batch<T, Name$1>): Rule<T, Name$1>;
2508
- /**
2509
- * A validation issue.
2510
- */
2511
- type Issue<T, RuleName extends string = string> = {
2512
- /** The name of the rule that caused the issue. */
2513
- ruleName: RuleName;
2514
- /** The message of the issue. */
2515
- message: string;
2516
- /** The item that was not valid. */
2517
- item: T;
2518
- };
2519
- /**
2520
- * The result of a validation.
2521
- */
2522
- type Result<T, RuleName extends string = string> = {
2523
- /** The items that were valid. */
2524
- valid: T[];
2525
- /** The reports of the failed validations. */
2526
- issues: Issue<T, RuleName>[];
2527
- };
2528
- declare function run<T, Name$1 extends string, Rules$1 extends readonly Rule<T, Name$1>[]>(parameters: {
2529
- items: T[];
2530
- rules: Rules$1;
2531
- chunkSize?: number;
2532
- }): Promise<Result<T, RuleNames<Rules$1>>>;
2533
- declare namespace GateConfig_d_exports {
2534
- export { CallbackConfig, GateConfig, assets$1 as assets, configs, getCallback, getCallbackAddresses, getCallbackType, getCallbackTypeAddresses };
2535
- }
2536
- type GateConfig = {
2537
- callbacks?: CallbackConfig[];
2538
- maturities?: MaturityType[];
2539
- };
2540
- type CallbackConfig = {
2541
- type: CallbackType.BuyVaultV1Callback;
2542
- addresses: Address[];
2543
- vaultFactories: Address[];
2544
- } | {
2545
- type: CallbackType.SellERC20Callback;
2546
- addresses: Address[];
2547
- } | {
2548
- type: CallbackType.BuyWithEmptyCallback;
2549
- };
2550
- declare function getCallback(chain: Name, type: CallbackType.BuyVaultV1Callback): Extract<CallbackConfig, {
2551
- type: CallbackType.BuyVaultV1Callback;
2552
- }> | undefined;
2553
- declare function getCallback(chain: Name, type: CallbackType.SellERC20Callback): Extract<CallbackConfig, {
2554
- type: CallbackType.SellERC20Callback;
2555
- }> | undefined;
2556
- declare function getCallback(chain: Name, type: CallbackType.BuyWithEmptyCallback): Extract<CallbackConfig, {
2557
- type: CallbackType.BuyWithEmptyCallback;
2558
- }> | undefined;
2559
- declare function getCallback(chain: Name, type: CallbackType): CallbackConfig | undefined;
2560
- /**
2561
- * Attempts to infer the configured callback type from a callback address on a chain.
2562
- * Skips the empty callback type as it does not carry addresses.
2563
- *
2564
- * @param chain - Chain name for which to infer the callback type
2565
- * @param address - Callback contract address
2566
- * @returns The callback type when found, otherwise undefined
2567
- */
2568
- declare function getCallbackType(chain: Name, address: Address): CallbackType | undefined;
2569
- /**
2570
- * Returns the callback addresses for a given chain and callback type, if it exists.
2571
- * @param chain - Chain name for which to read the validation configuration
2572
- * @param type - Callback type to retrieve
2573
- * @returns The matching callback addresses or an empty array if not configured
2574
- */
2575
- declare function getCallbackTypeAddresses(chain: Name, type: CallbackType): Address[];
2576
- /**
2577
- * Returns the list of allowed non-empty callback addresses for a chain.
2578
- *
2579
- * @param chain - Chain name
2580
- * @returns Array of allowed callback addresses (lowercased). Empty when none configured
2581
- */
2582
- declare const getCallbackAddresses: (chain: Name) => Address[];
2583
- declare const assets$1: Record<string, Address[]>;
2584
- declare const configs: Record<Name, GateConfig>;
2585
- declare namespace Gatekeeper_d_exports {
2586
- export { Gatekeeper, Rules, create };
2587
- }
2588
- type Rules = readonly Rule<Offer, string>[];
2589
- type Gatekeeper = {
2590
- rules: Rules;
2591
- isAllowed: (offers: Offer[]) => Promise<Result<Offer, string>>;
2592
- };
2593
- type GatekeeperParameters = {
2594
- rules: Rules;
2595
- };
2596
- declare function create(parameters: GatekeeperParameters): Gatekeeper;
2597
- //#endregion
2598
- //#region src/gatekeeper/morphoRules.d.ts
2599
- declare const morphoRules: (chains: Chain$1[]) => (Rule<Offer, "chain_ids"> | Rule<Offer, "maturity"> | Rule<Offer, "callback"> | Rule<Offer, "token">)[];
2600
- declare namespace Rules_d_exports {
2601
- export { ValidityParameters, callback, chains, maturity, token, validity };
2602
- }
2603
- type ValidityParameters = {
2604
- client: PublicClient<Transport, Chain$1>;
2605
- };
2606
- /**
2607
- * set of rules to validate offers.
2608
- *
2609
- * @param parameters - Validity parameters with chain and client
2610
- * @returns Array of validation rules to evaluate against offers
2611
- */
2612
- declare function validity(parameters: ValidityParameters): (Rule<Offer, "expiry"> | Rule<Offer, "sell_erc20_callback_invalid"> | Rule<Offer, "buy_offers_callback_vault_invalid">)[];
2613
- declare const chains: ({
2614
- chains
2615
- }: {
2616
- chains: Chain$1[];
2617
- }) => Rule<Offer, "chain_ids">;
2618
- declare const maturity: ({
2619
- maturities
2620
- }: {
2621
- maturities: MaturityType[];
2622
- }) => Rule<Offer, "maturity">;
2623
- declare const callback: ({
2624
- callbacks,
2625
- allowedAddresses
2626
- }: {
2627
- callbacks: CallbackType[];
2628
- allowedAddresses: Address[];
2629
- }) => Rule<Offer, "callback">;
2630
- /**
2631
- * A validation rule that checks if the offer's token is allowed.
2632
- * @param offer - The offer to validate.
2633
- * @returns The issue that was found. If the offer is valid, this will be undefined.
2634
- */
2635
- declare const token: ({
2636
- assets
2637
- }: {
2638
- assets: Address[];
2639
- }) => Rule<Offer, "token">;
2640
2815
  //#endregion
2641
2816
  //#region src/mempool/MempoolEVMClient.d.ts
2642
2817
  declare function from(parameters: from.Parameters): from.ReturnType;
@@ -2774,6 +2949,41 @@ declare function poll<data>(fn: ({
2774
2949
  }: {
2775
2950
  interval: () => Promise<number>;
2776
2951
  }): () => boolean;
2952
+ declare namespace Random_d_exports {
2953
+ export { address, bool, bytes, float, hex, int, seed, withSeed };
2954
+ }
2955
+ /**
2956
+ * Runs a function with a deterministic RNG derived from the given seed.
2957
+ */
2958
+ declare function withSeed<T>(seed: string, fn: () => T): T;
2959
+ /**
2960
+ * Seeds the global RNG for deterministic test runs.
2961
+ */
2962
+ declare function seed(seed: string): void;
2963
+ /**
2964
+ * Returns a deterministic random float in [0, 1).
2965
+ */
2966
+ declare function float(): number;
2967
+ /**
2968
+ * Returns a deterministic random integer in [min, maxExclusive).
2969
+ */
2970
+ declare function int(maxExclusive: number, min?: number): number;
2971
+ /**
2972
+ * Returns a deterministic random boolean.
2973
+ */
2974
+ declare function bool(probability?: number): boolean;
2975
+ /**
2976
+ * Returns deterministic random bytes.
2977
+ */
2978
+ declare function bytes(length: number): Uint8Array;
2979
+ /**
2980
+ * Returns a deterministic random hex string for the given byte length.
2981
+ */
2982
+ declare function hex(byteLength: number): Hex;
2983
+ /**
2984
+ * Returns a deterministic random address.
2985
+ */
2986
+ declare function address(): Address;
2777
2987
  //#endregion
2778
2988
  //#region src/utils/retry.d.ts
2779
2989
  declare const retry: <T>(fn: () => Promise<T>, attempts?: number, delayMs?: number) => Promise<T>;
@@ -2786,7 +2996,7 @@ declare function max(): number;
2786
2996
  //#region src/utils/wait.d.ts
2787
2997
  declare function wait(time: number): Promise<unknown>;
2788
2998
  declare namespace index_d_exports$2 {
2789
- export { BaseError, GlobalErrorType, ReorgError, Snake, time_d_exports as Time, batch, batchMulticall, fromSnakeCase$3 as fromSnakeCase, lazy, max$1 as max, min, poll, retry, stringifyBigint, toSnakeCase$1 as toSnakeCase, wait };
2999
+ 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 };
2790
3000
  }
2791
3001
  //#endregion
2792
3002
  export { index_d_exports as Abi, Brand, BrandTypeId, Callback_d_exports as Callback, Chain_d_exports as Chain, Collateral_d_exports as Collateral, Compute, Cursor_d_exports as Cursor, ERC4626_d_exports as ERC4626, Errors_d_exports as Errors, Format_d_exports as Format, GateConfig_d_exports as GateConfig, Gatekeeper_d_exports as Gatekeeper, LLTV_d_exports as LLTV, Liquidity_d_exports as Liquidity, Maturity_d_exports as Maturity, MempoolClient_d_exports as Mempool, Obligation_d_exports as Obligation, Offer_d_exports as Offer, Oracle_d_exports as Oracle, Position_d_exports as Position, Quote_d_exports as Quote, index_d_exports$1 as RouterApi, Client_d_exports as RouterClient, Rules_d_exports as Rules, time_d_exports as Time, Transfer_d_exports as Transfer, Tree_d_exports as Tree, index_d_exports$2 as Utils, Gate_d_exports as Validation, morphoRules };