@morpho-dev/router 0.4.2 → 0.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.mjs","names":["from","from","decode","encode","max","chainNameLookup: Map<Id, Name>","chains","chains: Record<Lowercase<Name>, Chain>","viemEthereum","viemBase","viemAnvil","DEFAULT_BATCH_SIZE","BigMath.min","BigMath.max","Errors.BaseError","create","chains","currentRng: Rng","hash","seed","min","z","from","InvalidOptionError","Errors.BaseError","z","z","LLTV.LLTVSchema","from","LLTV.from","random","Random.address","Errors.BaseError","token","obligationId","z","maturity","from","now","endOfMonth","Errors.BaseError","toSnakeCase","fromSnakeCase","out: Record<string, unknown>","z","Collateral.CollateralsSchema","Maturity.MaturitySchema","from","Maturity.from","error: unknown","fromSnakeCase","Format.fromSnakeCase","random","Random.address","Collateral.random","Errors.BaseError","hash","from","Offer.hash","encode","Offer.serialize","decode","bytes","decoded: string","rawOffers: unknown[]","Offer.OfferSchema","Errors.BaseError","z","Maturity.MaturitySchema","Collateral.CollateralsSchema","from","error: unknown","fromSnakeCase","Format.fromSnakeCase","Format.toSnakeCase","random","Random.int","Random.address","maturity","Maturity.from","LLTV.from","Random.bool","pricePairs: ReadonlyArray<readonly [bigint, number]>","Callback.encodeSellERC20Callback","Random.hex","Collateral.random","Random.float","Tree.from","Obligation.id","Obligation.from","decoded: DecodeAbiParametersReturnType<typeof OfferAbi>","Collateral.from","Errors.BaseError","from","from","z","from","error: unknown","Format.fromSnakeCase","Obligation.id","Obligation.random","Random.int","Errors.BaseError","from","from","base","Obligation.id","Payload.API_ERROR_CODES","BooksController","ValidateController","OffersController","HealthController","ConfigController","ObligationsController","UsersController","from","z","connect","config: RouterClientConfig","parameters","Offer.fromSnakeCase","Maturity.from","Obligation.fromSnakeCase","Obligation.id","Quote.fromSnakeCase","Errors.BaseError","batch","issues: Issue<T, RuleNames<Rules>>[]","validItems: T[]","indicesToRemove: Set<number>","address","assets: Record<string, Address[]>","configs: Record<Chain.Name, GateConfig>","Gate.run","GateConfig.getCallbackType","Callback.decode","batch","Callback.decodeBuyVaultV1Callback","GateConfig.getCallback","Abi.ERC4626","Abi.MetaMorphoFactory","vaultsWithIssues: Array<{ vaultAddress: Address; failureReasons: string }>","failureReasons: string[]","chains","id","Maturity.from","Callback.isEmptyCallback","BigMath.atMostOneNonZero","assetsByChainId: Partial<Record<Chain.Id, Address[]>>","chains","GateConfig.assets","Rules.sameMaker","Rules.amountMutualExclusivity","Rules.chains","Rules.maturity","Rules.callback","GateConfig.getCallbackAddresses","Rules.token","config: MempoolEVMClientConfig","parameters","Tree.from","Offer.from","Offer.sign","Tree.encode","Chain.streamLogs","offers: Offer.Offer[]","Tree.decode","Errors.BaseError","EVMClient.from","lastErr: unknown","results: TResult[]","resolveNext: (() => void) | null","queue: T[]","wait","unpoll: (() => boolean) | null"],"sources":["../src/api/Schema/BookResponse.ts","../src/api/Schema/health.ts","../src/api/Schema/ObligationResponse.ts","../src/core/Abi/MetaMorpho.ts","../src/core/Abi/MetaMorphoFactory.ts","../src/core/Abi/index.ts","../src/core/Callback.ts","../src/utils/BigMath.ts","../src/utils/batch.ts","../src/utils/Errors.ts","../src/core/Chain.ts","../src/core/ChainRegistry.ts","../src/utils/Random.ts","../src/utils/zod.ts","../src/core/LLTV.ts","../src/core/Collateral.ts","../src/core/ERC4626.ts","../src/core/Liquidity.ts","../src/core/Maturity.ts","../src/utils/Format.ts","../src/core/Obligation.ts","../src/core/Tree.ts","../src/core/Offer.ts","../src/core/Oracle.ts","../src/core/Position.ts","../src/core/Quote.ts","../src/core/Transfer.ts","../src/core/types.ts","../src/api/Schema/OfferResponse.ts","../src/api/Controllers/Payload.ts","../src/api/Schema/openapi.ts","../src/api/Schema/PositionResponse.ts","../src/api/Schema/requests.ts","../src/api/Schema/index.ts","../src/client/Client.ts","../src/gatekeeper/Gate.ts","../src/gatekeeper/GateConfig.ts","../src/gatekeeper/Gatekeeper.ts","../src/gatekeeper/Rules.ts","../src/gatekeeper/morphoRules.ts","../src/mempool/MempoolEVMClient.ts","../src/mempool/MempoolClient.ts","../src/utils/retry.ts","../src/utils/batchMulticall.ts","../src/utils/Group.ts","../src/utils/lazy.ts","../src/utils/wait.ts","../src/utils/poll.ts","../src/utils/time.ts","../src/utils/index.ts"],"sourcesContent":["export type BookLevelResponse = {\n price: string;\n assets: string;\n count: number;\n};\n\nexport function from(level: { price: bigint; assets: bigint; count: number }): BookLevelResponse {\n return {\n price: level.price.toString(),\n assets: level.assets.toString(),\n count: level.count,\n };\n}\n","import { z } from \"zod/v4\";\n\nexport const CollectorHealth = z.object({\n name: z.string(),\n chain_id: z.number(),\n block_number: z.number().nullable(),\n updated_at: z.string().nullable(),\n lag: z.number().nullable(),\n status: z.enum([\"live\", \"lagging\", \"unknown\"]),\n initialized: z.boolean(),\n});\n\nexport const CollectorsHealthResponse = z.array(CollectorHealth);\n\nexport const ChainHealth = z.object({\n chain_id: z.number(),\n local_block_number: z.number().nullable(),\n remote_block_number: z.number().nullable(),\n updated_at: z.string().nullable(),\n initialized: z.boolean(),\n});\n\nexport const ChainsHealthResponse = z.array(ChainHealth);\n\nexport const RouterStatusResponse = z.object({\n status: z.enum([\"live\", \"syncing\"]),\n initialized: z.boolean(),\n missing_chains: z.array(z.number()),\n missing_collectors: z.array(\n z.object({\n chain_id: z.number(),\n name: z.string(),\n }),\n ),\n});\n\nexport type CollectorsHealthResponse = z.infer<typeof CollectorsHealthResponse>;\nexport type ChainsHealthResponse = z.infer<typeof ChainsHealthResponse>;\nexport type RouterStatusResponse = z.infer<typeof RouterStatusResponse>;\n","import type { Obligation, Quote } from \"#core\";\nimport type * as OpenApiSchema from \"./generated/swagger.d.ts\";\n\nexport type ObligationResponse =\n OpenApiSchema.paths[\"/v1/obligations\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"][\"data\"][number];\n\n/**\n * Creates an `ObligationResponse` from a `Obligation`.\n * @constructor\n * @param obligation - {@link Obligation}\n * @returns The created `ObligationResponse`. {@link ObligationResponse}\n */\nexport function from(obligation: Obligation.Obligation, quote: Quote.Quote): ObligationResponse {\n return {\n id: quote.obligationId,\n chain_id: obligation.chainId,\n loan_token: obligation.loanToken,\n collaterals: obligation.collaterals.map((c) => ({\n token: c.asset,\n lltv: c.lltv.toString(),\n oracle: c.oracle,\n })),\n maturity: obligation.maturity,\n ask: { price: quote.ask.price.toString() },\n bid: { price: quote.bid.price.toString() },\n };\n}\n","import { parseAbi } from \"viem\";\n\nexport const MetaMorpho = parseAbi([\n \"function balanceOf(address account) view returns (uint256)\",\n \"function DECIMALS_OFFSET() view returns (uint8)\",\n \"function totalAssets() view returns (uint256)\",\n \"function totalSupply() view returns (uint256)\",\n \"function maxWithdraw(address owner) view returns (uint256 assets)\",\n \"function asset() view returns (address)\",\n \"event Transfer(address indexed from, address indexed to, uint256 value)\",\n \"function withdrawQueue(uint256 index) view returns (bytes32)\",\n \"function withdrawQueueLength() view returns (uint256)\",\n]);\nexport type MetaMorpho = typeof MetaMorpho;\n","import { parseAbi } from \"viem\";\n\nexport const MetaMorphoFactory = parseAbi([\n \"event CreateMetaMorpho(address indexed metaMorpho,address indexed caller,address initialOwner,uint256 initialTimelock,address indexed asset,string name,string symbol,bytes32 salt)\",\n \"function isMetaMorpho(address) view returns (bool)\",\n]);\nexport type MetaMorphoFactory = typeof MetaMorphoFactory;\n","export * from \"./MetaMorpho.ts\";\nexport * from \"./MetaMorphoFactory.ts\";\n\nexport const Oracle = [\n {\n type: \"function\",\n name: \"price\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport const ERC4626 = [\n {\n type: \"function\",\n name: \"asset\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport const Morpho = [\n {\n type: \"function\",\n name: \"collateralOf\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"debtOf\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"market\",\n inputs: [\n {\n name: \"id\",\n type: \"bytes32\",\n internalType: \"Id\",\n },\n ],\n outputs: [\n {\n name: \"totalSupplyAssets\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalSupplyShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalBorrowAssets\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalBorrowShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"lastUpdate\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"fee\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"position\",\n inputs: [\n {\n name: \"id\",\n type: \"bytes32\",\n internalType: \"Id\",\n },\n {\n name: \"user\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"supplyShares\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"borrowShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"collateral\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n ],\n stateMutability: \"view\",\n },\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { decodeAbiParameters, encodeAbiParameters } from \"viem\";\nimport type { Offer } from \"./index.ts\";\n\nexport enum CallbackType {\n BuyWithEmptyCallback = \"buy_with_empty_callback\",\n BuyVaultV1Callback = \"buy_vault_v1_callback\",\n SellERC20Callback = \"sell_erc20_callback\",\n}\n\nexport const isEmptyCallback = (offer: Offer.Offer): boolean => offer.callback.data === \"0x\";\n\nexport function decode(type: CallbackType, data: Hex): { contract: Address; amount: bigint }[] {\n switch (type) {\n case CallbackType.BuyVaultV1Callback:\n return decodeBuyVaultV1Callback(data);\n case CallbackType.SellERC20Callback:\n return decodeSellERC20Callback(data);\n default:\n throw new Error(\"Invalid callback type\");\n }\n}\n\nexport type BuyVaultV1CallbackData = {\n vaults: Address[];\n amounts: bigint[];\n};\n\nexport type SellERC20CallbackData = {\n collaterals: Address[];\n amounts: bigint[];\n};\n\nexport function encode(type: CallbackType.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;\nexport function encode(type: CallbackType.SellERC20Callback, data: SellERC20CallbackData): Hex;\nexport function encode(\n type: CallbackType,\n data: BuyVaultV1CallbackData | SellERC20CallbackData,\n): Hex {\n switch (type) {\n case CallbackType.BuyVaultV1Callback:\n if (!(\"vaults\" in data)) throw new Error(\"Invalid callback data\");\n return encodeBuyVaultV1Callback(data);\n case CallbackType.SellERC20Callback:\n if (!(\"collaterals\" in data)) throw new Error(\"Invalid callback data\");\n return encodeSellERC20Callback(data);\n default:\n throw new Error(\"Invalid callback type\");\n }\n}\n\nexport function decodeBuyVaultV1Callback(data: Hex): Array<{\n contract: Address;\n amount: bigint;\n}> {\n if (!data || data === \"0x\") throw new Error(\"Empty callback data\");\n try {\n const [vaults, amounts] = decodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n data,\n ) as [Address[], bigint[]];\n if (vaults.length !== amounts.length) {\n throw new Error(\"Mismatched array lengths\");\n }\n return vaults.map((v, i) => ({ contract: v, amount: amounts[i]! }));\n } catch (_) {\n throw new Error(\"Invalid BuyVaultV1Callback callback data\");\n }\n}\n\nexport function decodeSellERC20Callback(data: Hex): Array<{\n contract: Address;\n amount: bigint;\n}> {\n if (!data || data === \"0x\") throw new Error(\"Empty callback data\");\n try {\n const [collaterals, amounts] = decodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n data,\n ) as [Address[], bigint[]];\n if (collaterals.length !== amounts.length) {\n throw new Error(\"Mismatched array lengths\");\n }\n return collaterals.map((c, i) => ({ contract: c, amount: amounts[i]! }));\n } catch (_) {\n throw new Error(\"Invalid SellERC20Callback callback data\");\n }\n}\n\nexport function encodeBuyVaultV1Callback(parameters: {\n vaults: Address[];\n amounts: bigint[];\n}): Hex {\n return encodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n [parameters.vaults, parameters.amounts],\n );\n}\n\nexport function encodeSellERC20Callback(parameters: {\n collaterals: Address[];\n amounts: bigint[];\n}): Hex {\n return encodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n [parameters.collaterals, parameters.amounts],\n );\n}\n","export function max(a: bigint, b: bigint): bigint {\n return a > b ? a : b;\n}\n\nexport function min(a: bigint, b: bigint): bigint {\n return a < b ? a : b;\n}\n\n/**\n * Checks if at most one of the given values is non-zero.\n * @param values - The bigint values to check.\n * @returns True if zero or one value is non-zero, false if two or more are non-zero.\n */\nexport function atMostOneNonZero(...values: bigint[]): boolean {\n let nonZeroCount = 0;\n for (const value of values) {\n if (value !== 0n) {\n nonZeroCount++;\n if (nonZeroCount > 1) return false;\n }\n }\n return true;\n}\n","/**\n * Splits an array into batches of a specified size.\n * @param array The array to split.\n * @param batchSize The size of each batch.\n * @returns An iterator that yields each batch.\n * @example\n * ```typescript\n * const array = [1, 2, 3, 4, 5];\n * for (const batch of batch(array, 2)) {\n * console.log(batch);\n * }\n * // Output:\n * // [1, 2]\n * // [3, 4]\n * // [5]\n * ```\n */\nexport function* batch<T>(\n array: T[] | readonly T[],\n batchSize: number,\n): Generator<T[], void, unknown> {\n for (let i = 0; i < array.length; i += batchSize) {\n yield array.slice(i, i + batchSize);\n }\n}\n","export type GlobalErrorType<name extends string = \"Error\"> = Error & {\n name: name;\n};\n\n/**\n * Base error class inherited by all errors thrown by mempool.\n *\n * @example\n * ```ts\n * import { Errors } from 'mempool'\n * throw new Errors.BaseError('An error occurred')\n * ```\n */\nexport class BaseError<cause extends Error | undefined = undefined> extends Error {\n details: string;\n shortMessage: string;\n\n override cause: cause;\n override name = \"BaseError\";\n\n constructor(\n shortMessage: string,\n options: {\n cause?: cause | undefined;\n details?: string | undefined;\n metaMessages?: (string | undefined)[] | undefined;\n } = {},\n ) {\n const details = (() => {\n if (options.cause instanceof BaseError) {\n if (options.cause.details) return options.cause.details;\n if (options.cause.shortMessage) return options.cause.shortMessage;\n }\n if (options.cause && \"details\" in options.cause && typeof options.cause.details === \"string\")\n return options.cause.details;\n if (options.cause?.message) return options.cause.message;\n return options.details!;\n })();\n\n const message = [\n shortMessage || \"An error occurred.\",\n ...(options.metaMessages ? [\"\", ...options.metaMessages] : []),\n ...(details ? [\"\", details ? `Details: ${details}` : undefined] : []),\n ]\n .filter((x) => typeof x === \"string\")\n .join(\"\\n\");\n\n super(message, options.cause ? { cause: options.cause } : undefined);\n\n this.cause = options.cause as cause;\n this.details = details;\n this.shortMessage = shortMessage;\n }\n\n walk(): Error;\n walk(fn: (err: unknown) => boolean): Error | null;\n walk(fn?: ((err: unknown) => boolean) | undefined): unknown {\n return walk(this, fn);\n }\n}\n\n/** @internal */\nfunction walk(err: unknown, fn?: ((err: unknown) => boolean) | undefined): unknown {\n if (fn?.(err)) return err;\n if (err && typeof err === \"object\" && \"cause\" in err && err.cause) return walk(err.cause, fn);\n return fn ? null : err;\n}\n\nexport class ReorgError extends BaseError {\n override name = \"ReorgError\";\n constructor(blockNumber: number) {\n super(`Reorg detected at block number ${blockNumber}`);\n }\n}\n","import type {\n AbiEvent,\n Address,\n ChainContract,\n ChainFormatters,\n GetLogsReturnType,\n PublicClient,\n} from \"viem\";\nimport { getBlock, getLogs } from \"viem/actions\";\nimport {\n type Chain as ViemChain,\n anvil as viemAnvil,\n base as viemBase,\n mainnet as viemEthereum,\n} from \"viem/chains\";\nimport type { Compute } from \"#core\";\nimport * as BigMath from \"#utils/BigMath.ts\";\nimport { batch } from \"#utils/batch.ts\";\nimport * as Errors from \"#utils/Errors.ts\";\n\nexport type Chain = Compute<\n Omit<\n ViemChain<\n ChainFormatters,\n {\n morpho: ChainContract;\n morphoBlue: ChainContract;\n mempool: ChainContract;\n vaults: { factories: { v1_0: ChainContract; v1_1: ChainContract } };\n }\n >,\n \"custom\"\n > & {\n id: Id;\n name: Name;\n custom: {\n morpho: ChainContract;\n morphoBlue: ChainContract;\n mempool: ChainContract;\n vaults: { factories: { v1_0: ChainContract; v1_1: ChainContract } };\n };\n }\n>;\n\nexport const ChainId = {\n ETHEREUM: 1,\n BASE: 8453,\n \"ETHEREUM-VIRTUAL-TESTNET\": 109111114,\n ANVIL: 505050505, // random id to not clash with other chains\n} as const;\n\nexport type Name = Lowercase<keyof typeof ChainId>;\nexport const chainNames = Object.keys(ChainId).map((key) => key.toLowerCase()) as readonly Name[];\n\nexport type Id = (typeof ChainId)[Uppercase<Name>];\nexport const chainIds = Object.values(ChainId) as readonly Id[];\n\nconst chainNameLookup: Map<Id, Name> = new Map(\n Object.entries(ChainId).map(([key, value]) => [value, key.toLowerCase() as Name]),\n);\n\nexport function getChain(chainId: Id): Chain | undefined {\n const chainName = chainNameLookup.get(chainId);\n if (!chainName) return undefined;\n return chains[chainName];\n}\n\nexport const getWhitelistedChains = (): Chain[] => {\n return [chains.ethereum, chains.base, chains[\"ethereum-virtual-testnet\"], chains.anvil];\n};\n\nexport const chains: Record<Lowercase<Name>, Chain> = {\n ethereum: {\n ...viemEthereum,\n id: ChainId.ETHEREUM,\n name: \"ethereum\",\n custom: {\n morpho: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 },\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 23347674,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\",\n blockCreated: 18925584,\n },\n v1_1: {\n address: \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\",\n blockCreated: 21439510,\n },\n },\n },\n },\n },\n base: {\n ...viemBase,\n id: ChainId.BASE,\n name: \"base\",\n custom: {\n morpho: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 },\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 35449942,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\",\n blockCreated: 13978134,\n },\n v1_1: {\n address: \"0xFf62A7c278C62eD665133147129245053Bbf5918\",\n blockCreated: 23928808,\n },\n },\n },\n },\n },\n \"ethereum-virtual-testnet\": {\n ...viemEthereum,\n id: ChainId[\"ETHEREUM-VIRTUAL-TESTNET\"],\n name: \"ethereum-virtual-testnet\",\n custom: {\n morpho: { address: \"0x11a002d45db720ed47a80d2f3489cba5b833eaf5\", blockCreated: 0 }, // @TODO: This is mock Consumed contract, update with Terms once stable\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x5b06224f736a57635b5bcb50b8ef178b189107cb\",\n blockCreated: 23224302,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n blockCreated: 18925584,\n },\n v1_1: {\n address: \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n blockCreated: 21439510,\n },\n },\n },\n },\n },\n anvil: {\n ...viemAnvil,\n id: ChainId.ANVIL,\n name: \"anvil\",\n custom: {\n morpho: { address: \"0x23DFBc4B8B80C14CC5e25011B8491f268395BAd6\", blockCreated: 0 },\n morphoBlue: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 }, // Set dynamically in tests\n mempool: {\n address: \"0xD946246695A9259F3B33a78629026F61B3Ab40aF\",\n blockCreated: 23223727,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 0,\n },\n v1_1: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 0,\n },\n },\n },\n },\n },\n};\n\n// thresholds are set to align with Alchemy's thresholds\n//https://www.alchemy.com/docs/deep-dive-into-eth_getlogs#making-a-request-to-eth_getlogs\nconst MAX_BATCH_SIZE = 10_000;\nconst DEFAULT_BATCH_SIZE = 2_500;\nconst MAX_BLOCK_WINDOW = 10_000;\nconst DEFAULT_BLOCK_WINDOW = 8_000;\n\nexport async function* streamLogs<abiEvent extends AbiEvent | undefined = undefined>(parameters: {\n client: PublicClient;\n contractAddress?: Address;\n event?: abiEvent;\n blockNumberGte?: number;\n blockNumberLte?: number;\n order: \"asc\" | \"desc\";\n options: {\n maxBatchSize?: number;\n blockWindow?: number;\n };\n}): AsyncGenerator<\n { logs: GetLogsReturnType<abiEvent | undefined>; blockNumber: number },\n void,\n void\n> {\n const {\n client,\n contractAddress,\n event,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE, blockWindow = DEFAULT_BLOCK_WINDOW } = {},\n } = parameters;\n if (maxBatchSize > MAX_BATCH_SIZE) throw new InvalidBatchSizeError(maxBatchSize);\n if (blockWindow > MAX_BLOCK_WINDOW) throw new InvalidBlockWindowError(blockWindow);\n if (order === \"asc\" && blockNumberGte === undefined) throw new MissingBlockNumberError();\n\n const latestBlock = (await getBlock(client, { blockTag: \"latest\", includeTransactions: false }))\n .number;\n\n let toBlock = 0n;\n if (order === \"asc\")\n toBlock = BigMath.min(\n BigInt(blockNumberGte!) + BigInt(blockWindow),\n blockNumberLte ? BigInt(blockNumberLte!) : latestBlock,\n );\n if (order === \"desc\")\n toBlock =\n blockNumberLte === undefined\n ? latestBlock\n : BigMath.min(BigInt(blockNumberLte!), latestBlock);\n\n let fromBlock = 0n;\n if (order === \"asc\") fromBlock = BigMath.min(BigInt(blockNumberGte!), latestBlock);\n if (order === \"desc\")\n fromBlock = BigMath.max(BigInt(blockNumberGte || toBlock - BigInt(blockWindow)), 0n);\n\n if (order === \"asc\") toBlock = BigMath.min(toBlock, fromBlock + BigInt(blockWindow));\n if (order === \"desc\") fromBlock = BigMath.max(fromBlock, toBlock - BigInt(blockWindow));\n if (fromBlock > toBlock) throw new InvalidBlockRangeError(fromBlock, toBlock);\n\n let streaming = true;\n while (streaming) {\n const logs = await getLogs(client, {\n address: contractAddress,\n event,\n fromBlock,\n toBlock,\n });\n\n streaming =\n order === \"asc\"\n ? toBlock < (blockNumberLte || latestBlock)\n : fromBlock > (blockNumberGte || 0n);\n\n if (logs.length === 0 && !streaming) {\n break;\n }\n\n if (logs.length === 0 && streaming) {\n yield { logs: [], blockNumber: order === \"asc\" ? Number(toBlock) : Number(fromBlock) };\n }\n\n logs.sort((a, b) => {\n if (a.blockNumber !== b.blockNumber)\n return order === \"asc\"\n ? Number(a.blockNumber - b.blockNumber)\n : Number(b.blockNumber - a.blockNumber);\n if (a.transactionIndex !== b.transactionIndex)\n return order === \"asc\"\n ? a.transactionIndex - b.transactionIndex\n : b.transactionIndex - a.transactionIndex;\n return order === \"asc\" ? a.logIndex - b.logIndex : b.logIndex - a.logIndex;\n });\n\n for (const logBatch of batch(logs, maxBatchSize)) {\n yield {\n logs: logBatch,\n blockNumber:\n logBatch.length === maxBatchSize\n ? // if the batch is full, return the last block number, block numbers are always sorted\n Number(logBatch[logBatch.length - 1]?.blockNumber)\n : // if the batch is not full, return `toBlock` or `fromBlock` to indicate until which block the logs were fetched\n order === \"asc\"\n ? Number(toBlock)\n : Number(fromBlock),\n };\n }\n\n if (order === \"asc\") {\n const upperBound = BigInt(blockNumberLte || latestBlock);\n const nextFromBlock = BigMath.min(BigInt(toBlock) + 1n, upperBound);\n const nextToBlock = BigMath.min(toBlock + BigInt(blockWindow) + 1n, upperBound);\n fromBlock = nextFromBlock;\n toBlock = nextToBlock;\n }\n\n if (order === \"desc\") {\n const lowerBound = BigInt(blockNumberGte || 0);\n const nextToBlock = BigMath.max(fromBlock - 1n, lowerBound);\n const nextFromBlock = BigMath.max(fromBlock - BigInt(blockWindow) - 1n, lowerBound);\n toBlock = nextToBlock;\n fromBlock = nextFromBlock;\n }\n }\n\n yield { logs: [], blockNumber: order === \"asc\" ? Number(toBlock) : Number(fromBlock) };\n return;\n}\n\nexport class InvalidBlockRangeError extends Errors.BaseError {\n override name = \"Chain.InvalidBlockRangeError\";\n constructor(fromBlock: bigint, toBlock: bigint) {\n super(\n `Invalid block range while streaming data from chain. From block ${fromBlock} to block ${toBlock}.`,\n );\n }\n}\n\nexport class InvalidBlockWindowError extends Errors.BaseError {\n override name = \"Chain.InvalidBlockWindowError\";\n constructor(blockWindow: number) {\n super(\n `Invalid block window while streaming data from chain. Maximum is ${MAX_BLOCK_WINDOW}. Got ${blockWindow}.`,\n );\n }\n}\n\nexport class InvalidBatchSizeError extends Errors.BaseError {\n override name = \"Chain.InvalidBatchSizeError\";\n constructor(maxBatchSize: number) {\n super(\n `Invalid batch size while streaming data from chain. Maximum is ${MAX_BATCH_SIZE}. Got ${maxBatchSize}.`,\n );\n }\n}\n\nexport class MissingBlockNumberError extends Errors.BaseError {\n override name = \"Chain.MissingBlockNumberError\";\n constructor() {\n super(\"Missing block number when streaming data from chain in ascending order.\");\n }\n}\n","import type * as Chain from \"./Chain.ts\";\n\nexport type ChainRegistry = {\n getById: (chainId: Chain.Id) => Chain.Chain | undefined;\n list: () => Chain.Chain[];\n};\n\nexport function create(chains: Chain.Chain[]): ChainRegistry {\n const byId = new Map<Chain.Id, Chain.Chain>();\n for (const chain of chains) {\n byId.set(chain.id, chain);\n }\n\n return {\n getById: (chainId: Chain.Id) => byId.get(chainId),\n list: () => Array.from(byId.values()),\n };\n}\n","import type { Address, Hex } from \"viem\";\n\ntype Rng = () => number;\n\nlet currentRng: Rng = Math.random;\n\nconst FNV_OFFSET_BASIS = 2166136261;\nconst FNV_PRIME = 16777619;\n\nconst hashSeed = (seed: string): number => {\n let hash = FNV_OFFSET_BASIS;\n for (let i = 0; i < seed.length; i += 1) {\n hash ^= seed.charCodeAt(i);\n hash = Math.imul(hash, FNV_PRIME);\n }\n return hash >>> 0;\n};\n\nconst createSeededRng = (seed: string): Rng => {\n let state = hashSeed(seed);\n return () => {\n state += 0x6d2b79f5;\n let t = Math.imul(state ^ (state >>> 15), state | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n};\n\n/**\n * Runs a function with a deterministic RNG derived from the given seed.\n */\nexport function withSeed<T>(seed: string, fn: () => T): T {\n const previous = currentRng;\n currentRng = createSeededRng(seed);\n try {\n return fn();\n } finally {\n currentRng = previous;\n }\n}\n\n/**\n * Seeds the global RNG for deterministic test runs.\n */\nexport function seed(seed: string): void {\n currentRng = createSeededRng(seed);\n}\n\n/**\n * Returns a deterministic random float in [0, 1).\n */\nexport function float(): number {\n return currentRng();\n}\n\n/**\n * Returns a deterministic random integer in [min, maxExclusive).\n */\nexport function int(maxExclusive: number, min = 0): number {\n return Math.floor(float() * (maxExclusive - min)) + min;\n}\n\n/**\n * Returns a deterministic random boolean.\n */\nexport function bool(probability = 0.5): boolean {\n return float() < probability;\n}\n\n/**\n * Returns deterministic random bytes.\n */\nexport function bytes(length: number): Uint8Array {\n const output = new Uint8Array(length);\n for (let i = 0; i < length; i += 1) {\n output[i] = int(256);\n }\n return output;\n}\n\n/**\n * Returns a deterministic random hex string for the given byte length.\n */\nexport function hex(byteLength: number): Hex {\n const output = bytes(byteLength);\n const hexParts = Array.from(output, (byte) => byte.toString(16).padStart(2, \"0\"));\n return `0x${hexParts.join(\"\")}` as Hex;\n}\n\n/**\n * Returns a deterministic random address.\n */\nexport function address(): Address {\n return hex(20) as Address;\n}\n","import { type Address, type Hex, isAddress, isHex, numberToHex, pad } from \"viem\";\nimport * as z from \"zod\";\n\n/**\n * Converts a hex string to a padded bytes32.\n * Returns null if the value is not a valid hex string.\n */\nconst hexToBytes32 = (val: string): Hex | null => {\n if (!isHex(val)) return null;\n return pad(val as Hex, { size: 32 });\n};\n\n/**\n * Converts a numeric string to a padded bytes32.\n * @throws {Error} If parsing fails or value is negative.\n */\nconst numericStringToBytes32 = (val: string): Hex => {\n const num = BigInt(val);\n if (num < 0n) throw new Error(\"expected bigint to be >=0\");\n return pad(numberToHex(num), { size: 32 });\n};\n\n/**\n * Converts a number or bigint to a padded bytes32.\n * @throws {Error} If value is negative.\n */\nconst numericToBytes32 = (val: number | bigint): Hex => {\n const num = BigInt(val);\n if (num < 0n) throw new Error(\"expected bigint to be >=0\");\n return pad(numberToHex(num), { size: 32 });\n};\n\n/**\n * Transforms a value to a bytes32 hex string.\n * Accepts:\n * - Hex strings (0x...) - pads to 32 bytes if needed\n * - Numeric strings - converts to padded hex\n * - Numbers/bigints - converts to padded hex (must be non-negative)\n */\nexport const transformBytes32 = (val: string | number | bigint, ctx: z.RefinementCtx): Hex => {\n if (typeof val === \"string\") {\n const hexResult = hexToBytes32(val);\n if (hexResult !== null) return hexResult;\n\n try {\n return numericStringToBytes32(val);\n } catch (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Not a valid bytes32 value: ${error instanceof Error ? error.message : String(error)}`,\n });\n return z.NEVER;\n }\n }\n\n if (typeof val === \"number\" || typeof val === \"bigint\") {\n try {\n return numericToBytes32(val);\n } catch (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Too small: ${error instanceof Error ? error.message : String(error)}`,\n });\n return z.NEVER;\n }\n }\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Not a valid bytes32 value\",\n });\n\n return z.NEVER;\n};\n\nexport const transformHex = (val: string, ctx: z.RefinementCtx) => {\n if (isHex(val)) return val;\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Invalid hex\",\n });\n\n return z.NEVER;\n};\n\nexport const transformAddress = (val: string, ctx: z.RefinementCtx) => {\n if (isAddress(val.toLowerCase())) return val.toLowerCase() as Address;\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Invalid address\",\n });\n\n return z.NEVER;\n};\n","import * as z from \"zod\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type { Brand } from \"./types.ts\";\n\nexport type LLTV = bigint & Brand<\"LLTV\">;\n\nexport const Options = [0.385, 0.5, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965, 0.98] as const;\nexport type Options = (typeof Options)[number];\nconst LLTV_SCALED = Options.map((lltv) => BigInt(lltv * 10 ** 18));\n\n/**\n * Convert a LLTV option or a scaled LLTV to a LLTV.\n * @param lltv - The LLTV option or the scaled LLTV.\n * @returns The LLTV.\n */\nexport function from(lltv: Options | bigint): LLTV {\n if (typeof lltv === \"bigint\" && !LLTV_SCALED.includes(lltv)) throw new InvalidLLTVError(lltv);\n if (typeof lltv === \"bigint\") return lltv as LLTV;\n if (typeof lltv === \"number\" && !Options.includes(lltv)) throw new InvalidOptionError(lltv);\n return BigInt(lltv * 10 ** 18) as LLTV;\n}\n\nexport declare namespace from {\n type ErrorType = InvalidOptionError | InvalidLLTVError;\n}\n\nexport class InvalidOptionError extends Errors.BaseError {\n override readonly name = \"LLTV.InvalidOptionError\";\n constructor(input: number) {\n super(\n `Invalid LLTV option. Input: \"${input}\". Accepted values are: ${Options.map(\n (option) => `\"${option}\"`,\n ).join(\", \")}.`,\n );\n }\n}\n\nexport class InvalidLLTVError extends Errors.BaseError {\n override readonly name = \"LLTV.InvalidLLTVError\";\n constructor(input: bigint) {\n super(\n `Invalid LLTV. Input: \"${input}\". Accepted values are: ${LLTV_SCALED.map(\n (option) => `\"${option}\"`,\n ).join(\", \")}.`,\n );\n }\n}\n\nexport const LLTVSchema = z\n .bigint({ coerce: true })\n .refine(\n (lltv) => {\n try {\n from(lltv);\n return true;\n } catch (_) {\n return false;\n }\n },\n {\n error: () => {\n return \"Invalid LLTV: must be one of 0.385, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965 or 0.98 (scaled by 1e18)\";\n },\n },\n )\n .transform((lltv) => from(lltv));\n","import type { Address } from \"viem\";\nimport * as z from \"zod\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress } from \"#utils/zod.ts\";\nimport * as LLTV from \"./LLTV.ts\";\n\nexport type Collateral = {\n /** Asset being used as collateral. */\n asset: Address;\n /** Liquidation Loan-to-Value of the collateral. */\n lltv: LLTV.LLTV;\n /** Oracle contract used to price the collateral. */\n oracle: Address;\n};\n\nexport const CollateralSchema = z.object({\n asset: z.string().transform(transformAddress),\n oracle: z.string().transform(transformAddress),\n lltv: LLTV.LLTVSchema,\n});\n\nexport const CollateralsSchema = z\n .array(CollateralSchema)\n .min(1, { message: \"At least one collateral is required\" })\n .refine(\n (collaterals) => {\n for (let i = 1; i < collaterals.length; i++) {\n if (collaterals[i - 1]!.asset.toLowerCase() > collaterals[i]!.asset.toLowerCase()) {\n return false;\n }\n }\n return true;\n },\n {\n message: \"Collaterals must be sorted alphabetically by address\",\n },\n )\n .refine(\n (collaterals) => {\n const uniqueAssets = new Set<string>();\n for (const collateral of collaterals) {\n const assetAddress = collateral.asset.toLowerCase();\n if (uniqueAssets.has(assetAddress)) {\n return false;\n }\n uniqueAssets.add(assetAddress);\n }\n return true;\n },\n {\n message: \"Collaterals must not contain duplicate assets\",\n },\n );\n\nexport const from = (parameters: from.Parameters): from.ReturnType => {\n return {\n asset: parameters.asset.toLowerCase() as Address,\n lltv: LLTV.from(parameters.lltv),\n oracle: parameters.oracle.toLowerCase() as Address,\n };\n};\n\nexport declare namespace from {\n type Parameters = {\n asset: Address;\n lltv: LLTV.Options | bigint;\n oracle: Address;\n };\n type ReturnType = Collateral;\n}\n\n/**\n * Generates a random collateral.\n * @returns A randomly generated collateral. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const collateral = Collateral.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n asset: Random.address(),\n oracle: Random.address(),\n lltv: 0.965,\n });\n}\n\nexport declare namespace random {\n type ReturnType = Collateral;\n}\n","import * as Errors from \"#utils/Errors.ts\";\n\n/**\n * Calculate the decimals offset used by the ERC4626 implementation.\n * @param parameters - {@link decimalsOffset.Parameters}.\n * @returns The decimals offset.\n *\n * @example\n * ```ts\n * const decimalsOffset = decimalsOffset({ underlyingDecimals: 6 });\n * // decimalsOffset = 12\n * ```\n */\nexport function decimalsOffset(parameters: decimalsOffset.Parameters): number {\n return Math.max(0, 18 - parameters.underlyingDecimals);\n}\n\nexport declare namespace decimalsOffset {\n type Parameters = {\n /** The number of decimals of the underlying asset. */\n underlyingDecimals: number;\n };\n type ReturnType = number;\n}\n\n/**\n * Convert shares to assets.\n * @throws If the denominator is 0. {@link DenominatorIsZeroError}\n * @param parameters - {@link convertToAssets.Parameters}.\n * @returns The amount of assets.\n *\n * @example\n * ```ts\n * const assets = convertToAssets(100n, { totalAssets: 1000n, totalSupply: 1000n, decimalsOffset: 18 });\n * // assets = 100n\n * ```\n */\nexport function convertToAssets(\n parameters: convertToAssets.Parameters,\n): convertToAssets.ReturnType {\n const denominator = parameters.totalSupply + 10n ** BigInt(parameters.decimalsOffset);\n if (denominator === 0n) throw new DenominatorIsZeroError();\n\n return (parameters.shares * (parameters.totalAssets + 1n)) / denominator;\n}\n\nexport declare namespace convertToAssets {\n type Parameters = {\n /** The amount of shares to convert. */\n shares: bigint;\n /** Total amount of assets in the vault. */\n totalAssets: bigint;\n /** Total amount of shares in the vault. */\n totalSupply: bigint;\n /**\n * OpenZeppelin decimals offset used by the ERC4626 implementation.\n * Calculated to be `max(0, 18 - underlyingDecimals)` at construction, so the initial conversion rate maximizes\n * precision between shares and assets.\n */\n decimalsOffset: number;\n };\n type ReturnType = bigint;\n type ErrorType = DenominatorIsZeroError;\n}\n\n/**\n * Convert assets to shares.\n * @throws If the denominator is 0. {@link DenominatorIsZeroError}\n * @param parameters - {@link convertToShares.Parameters}.\n * @returns The amount of shares.\n *\n * @example\n * ```ts\n * const shares = convertToShares(100n, { totalAssets: 1000n, totalSupply: 1000n, decimalsOffset: 12 });\n * // shares = 100n\n * ```\n */\nexport function convertToShares(\n parameters: convertToShares.Parameters,\n): convertToShares.ReturnType {\n const denominator = parameters.totalAssets + 1n;\n if (denominator === 0n) throw new DenominatorIsZeroError();\n\n return (\n (parameters.assets * (parameters.totalSupply + 10n ** BigInt(parameters.decimalsOffset))) /\n denominator\n );\n}\n\nexport declare namespace convertToShares {\n type Parameters = {\n /** The amount of assets to convert. */\n assets: bigint;\n /** Total amount of assets in the vault. */\n totalAssets: bigint;\n /** Total amount of shares in the vault. */\n totalSupply: bigint;\n /**\n * OpenZeppelin decimals offset used by the ERC4626 implementation.\n * Calculated to be `max(0, 18 - underlyingDecimals)` at construction, so the initial conversion rate maximizes\n * precision between shares and assets.\n */\n decimalsOffset: number;\n };\n type ReturnType = bigint;\n type ErrorType = DenominatorIsZeroError;\n}\nexport class DenominatorIsZeroError extends Errors.BaseError {\n override readonly name = \"ERC4626.DenominatorIsZeroError\";\n constructor() {\n super(\"Denominator is 0.\");\n }\n}\n","import type { Address, Hex } from \"viem\";\nimport type { Chain } from \"#core\";\nimport { CallbackType } from \"./Callback.ts\";\n\n/**\n * Represents a liquidity pool with a unique ID and amount.\n */\nexport type LiquidityPool = {\n id: string;\n amount: bigint;\n};\n\n/**\n * Represents a hierarchical relationship between two liquidity pools.\n */\nexport type LiquidityLink = {\n parentPoolId: string;\n childPoolId: string;\n priority: number;\n};\n\n/**\n * Represents the connection between an offer and its liquidity pools.\n */\nexport type OfferLiquidityPool = {\n offerHash: Hex;\n poolId: string;\n /**\n * The available capacity/liquidity from this pool for this offer.\n * Meaning varies by pool type:\n * - BuyWithEmptyCallback: Matches allowance amount from pool bellow\n * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)\n * - SellERC20Callback: Existing debt as negative value (reduces available capacity)\n */\n amount: bigint;\n};\n\n/**\n * Calculate maximum debt capacity from collateral amount.\n * @param amount - Collateral amount\n * @param oraclePrice - Oracle price (scaled to 36 decimals)\n * @param lltv - Loan-to-value ratio (scaled to 18 decimals)\n * @returns Maximum debt capacity\n */\nexport function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint {\n const ORACLE_PRICE_SCALE = 10n ** 36n; // Oracle prices are scaled to 36 decimals\n const PRECISION = 10n ** 18n; // LLTV ratios are scaled to 18 decimals (1e18 = 100%)\n\n const collateralQuoted = (amount * oraclePrice) / ORACLE_PRICE_SCALE;\n const maxDebt = (collateralQuoted * lltv) / PRECISION;\n\n return maxDebt;\n}\n\n/**\n * Generate pool ID for balance pools.\n */\nexport function generateBalancePoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n token: Address;\n}): string {\n const { user, chainId, token } = parameters;\n return `${user}-${chainId.toString()}-${token}-balance`.toLowerCase();\n}\n\n/**\n * Generate pool ID for allowance pools.\n */\nexport function generateAllowancePoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n token: Address;\n}): string {\n const { user, chainId, token } = parameters;\n return `${user}-${chainId.toString()}-${token}-allowance`.toLowerCase();\n}\n\n/**\n * Generate pool ID for sell ERC20 callback pools.\n * Each offer has its own callback pool to prevent liquidity conflicts.\n */\nexport function generateSellERC20CallbackPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n token: Address;\n offerHash: Hex;\n}): string {\n const { user, chainId, obligationId, token, offerHash } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-${token}-${offerHash}-sell_erc20_callback`.toLowerCase();\n}\n\n/**\n * Generate pool ID for obligation collateral pools.\n * Obligation collateral pools represent collateral already deposited in the obligation.\n * These pools are shared across all offers with the same obligation.\n */\nexport function generateObligationCollateralPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n token: Address;\n}): string {\n const { user, chainId, obligationId, token } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-${token}-obligation-collateral`.toLowerCase();\n}\n\n/**\n * Generate pool ID for buy vault callback pools.\n */\nexport function generateBuyVaultCallbackPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n vault: Address;\n offerHash: Hex;\n}): string {\n const { user, chainId, vault, offerHash } = parameters;\n return `${user}-${chainId.toString()}-${vault}-${offerHash}-${CallbackType.BuyVaultV1Callback}`.toLowerCase();\n}\n\n/**\n * Generate pool ID for debt pools.\n */\nexport function generateDebtPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n}): string {\n const { user, chainId, obligationId } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-debt`.toLowerCase();\n}\n\n/**\n * Generate pool ID for user position in a vault.\n */\nexport function generateUserVaultPositionPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n vault: Address;\n}): string {\n const { user, chainId, vault } = parameters;\n return `${user}-${chainId.toString()}-${vault}-user-vault-position`.toLowerCase();\n}\n\n/**\n * Generate pool ID for vault position in a market.\n */\nexport function generateVaultPositionPoolId(parameters: {\n vault: Address;\n chainId: Chain.Id;\n marketId: string;\n}): string {\n const { vault, chainId, marketId } = parameters;\n return `${vault}-${chainId.toString()}-${marketId}-vault-position`.toLowerCase();\n}\n\n/**\n * Generate pool ID for market total liquidity.\n */\nexport function generateMarketLiquidityPoolId(parameters: {\n chainId: Chain.Id;\n marketId: string;\n}): string {\n const { chainId, marketId } = parameters;\n return `${chainId.toString()}-${marketId}-market-liquidity`.toLowerCase();\n}\n","import * as z from \"zod\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type { Brand } from \"./types.ts\";\n\n/**\n * Maturity is a number that represents a date in seconds.\n */\nexport type Maturity = number & Brand<\"Maturity\">;\n\nexport const MaturitySchema = z\n .number()\n .int()\n .refine(\n (maturity) => {\n try {\n from(maturity);\n return true;\n } catch (_e) {\n return false;\n }\n },\n {\n error: (issue) => {\n try {\n const maturityDate = new Date((issue.input as number) * 1000);\n return `The maturity is set to ${maturityDate}. It must fall on the allowed settlement cycles (Friday 15:00 UTC at the end of week/month/quarter).`;\n } catch (_) {\n return `The maturity is set to ${issue.input}. It must fall on the allowed settlement cycles (Friday 15:00 UTC at the end of week/month/quarter).`;\n }\n },\n },\n )\n .transform((maturity) => maturity as Maturity);\n\nexport enum MaturityType {\n EndOfWeek = \"end_of_week\",\n EndOfNextWeek = \"end_of_next_week\",\n EndOfMonth = \"end_of_month\",\n EndOfNextMonth = \"end_of_next_month\",\n EndOfQuarter = \"end_of_quarter\",\n EndOfNextQuarter = \"end_of_next_quarter\",\n}\n\nconst MaturityOptions = {\n end_of_week: () => endOfWeek(),\n end_of_next_week: () => endOfNextWeek(),\n end_of_month: () => endOfMonth(),\n end_of_next_month: () => endOfNextMonth(),\n end_of_quarter: () => endOfQuarter(),\n end_of_next_quarter: () => endOfNextQuarter(),\n} as const;\n\nexport type MaturityOptions = keyof typeof MaturityOptions;\n\n/**\n * Creates a maturity from a timestamp in seconds or a maturity option.\n * @throws {InvalidFormatError} If the maturity is in milliseconds.\n * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.\n * @throws {InvalidOptionError} If the maturity is not a valid option.\n */\nexport function from(ts: from.Parameters): Maturity {\n if (typeof ts === \"string\") {\n if (ts in MaturityOptions) return MaturityOptions[ts]();\n throw new InvalidOptionError(ts);\n }\n\n if (typeof ts === \"number\" && ts > 1e12) throw new InvalidFormatError();\n\n if (!Object.values(MaturityOptions).some((option) => option() === ts))\n throw new InvalidDateError(ts);\n\n return ts as Maturity;\n}\n\nexport declare namespace from {\n type Parameters = number | MaturityOptions;\n type ErrorType = InvalidFormatError | InvalidDateError | InvalidOptionError;\n}\n\n/** Returns the end of the current week (friday at 15:00:00 UTC) */\nconst endOfWeek = (): Maturity => fridayOfWeek(0);\n\n/** Returns the end of the next week (friday at 15:00:00 UTC) */\nconst endOfNextWeek = (): Maturity => fridayOfWeek(1);\n\n/** Returns the end of the current month (last friday of the month at 15:00:00 UTC)\n * Business rule: if we are after the last Friday of the month (strictly after 15:00 UTC\n * on that Friday), roll to the next month's last Friday.\n */\nconst endOfMonth = (): Maturity => {\n const now = new Date();\n const year = now.getUTCFullYear();\n const month = now.getUTCMonth();\n\n const endOfMonth = lastFridayOfMonth(year, month);\n\n // If strictly after 15:00 UTC on the last Friday, roll to next month's last Friday\n if (now.getTime() > endOfMonth * 1000) {\n return lastFridayOfMonth(year, month + 1);\n }\n\n return endOfMonth;\n};\n\n/** Returns the end of the next month (last friday of the next month at 15:00:00 UTC)\n * Business rule: if we are after the last Friday of the current month (strictly after 15:00 UTC\n * on that Friday), we consider being in the next month already, so \"next month\" becomes month+2.\n */\nconst endOfNextMonth = (): Maturity => {\n const now = new Date();\n const year = now.getUTCFullYear();\n const month = now.getUTCMonth();\n\n const endOfMonth = lastFridayOfMonth(year, month);\n\n if (now.getTime() > endOfMonth * 1000) {\n return lastFridayOfMonth(year, month + 2);\n }\n\n return lastFridayOfMonth(year, month + 1);\n};\n\n/** Returns the end of the current quarter (last friday of the quarter at 15:00:00 UTC) */\nconst endOfQuarter = (): Maturity => lastFridayOfQuarter(0);\n\n/** Returns the end of the next quarter (last friday of the next quarter at 15:00:00 UTC) */\nconst endOfNextQuarter = (): Maturity => lastFridayOfQuarter(1);\n\nconst fridayOfWeek = (weeksAhead = 0): Maturity => {\n const now = new Date();\n const today15H = new Date(\n Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 15),\n );\n\n // Days until next Friday (5). Always non-negative in [0,6]\n let daysUntilFriday = (5 - today15H.getUTCDay() + 7) % 7;\n\n // If it's Friday and we're already past 15:00 UTC, roll to next Friday\n if (daysUntilFriday === 0 && now.getTime() >= today15H.getTime()) {\n daysUntilFriday = 7;\n }\n\n const friday = new Date(today15H);\n friday.setUTCDate(friday.getUTCDate() + daysUntilFriday + weeksAhead * 7);\n return (friday.getTime() / 1000) as Maturity;\n};\n\nconst lastFridayOfMonth = (year: number, month: number): Maturity => {\n const lastDayOfMonth15H = new Date(Date.UTC(year, month + 1, 0, 15));\n\n while (lastDayOfMonth15H.getUTCDay() !== 5) {\n lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate() - 1);\n }\n\n const maturity = lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate()) / 1000;\n\n return maturity as Maturity;\n};\n\nconst lastFridayOfQuarter = (quartersAhead = 0): Maturity => {\n const now = new Date();\n const quarterIndex = Math.floor(now.getUTCMonth() / 3) + quartersAhead;\n const year = now.getUTCFullYear() + Math.floor(quarterIndex / 4);\n const quarter = quarterIndex % 4;\n const lastMonth = quarter * 3 + 2; // 0-based\n return lastFridayOfMonth(year, lastMonth);\n};\n\nexport class InvalidFormatError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidFormatError\";\n constructor() {\n super(\"Invalid maturity format. Maturity should be expressed in seconds.\");\n }\n}\n\nexport class InvalidDateError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidDateError\";\n constructor(input: number) {\n super(\n `Invalid maturity date. Input: \"${input}\". Accepted values are: ${Object.values(\n MaturityOptions,\n )\n .map((option) => `\"${option()}\"`)\n .join(\", \")}.`,\n );\n }\n}\n\nexport class InvalidOptionError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidOptionError\";\n constructor(input: string) {\n super(\n `Invalid maturity option. Input: \"${input}\". Accepted values are: ${Object.keys(\n MaturityOptions,\n )\n .map((option) => `\"${option}\"`)\n .join(\", \")}.`,\n );\n }\n}\n","import { getAddress, isAddress } from \"viem\";\n\n/** The snake case representation of a type with bigint values stringified. */\nexport type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;\n\n/** Make arrays/tuples and object props mutable, deeply. */\ntype DeepMutable<T> =\n // leave functions/primitives as-is\n T extends (...args: unknown[]) => unknown\n ? T\n : T extends number | string | boolean | symbol | bigint | null | undefined\n ? T\n : // handle tuples first (preserve length/element types)\n T extends readonly [...infer R]\n ? { -readonly [K in keyof R]: DeepMutable<R[K]> }\n : // then general readonly arrays\n T extends ReadonlyArray<infer U>\n ? Array<DeepMutable<U>>\n : // then objects: strip readonly from props and recurse\n T extends object\n ? { -readonly [K in keyof T]: DeepMutable<T[K]> }\n : T;\n\n/** Stringifies bigint values to strings and preserves branded primitives. */\ntype StringifiedBigint<T> =\n // non-distributive check so that `bigint & Brand<...>` is still caught here\n [T] extends [bigint]\n ? string\n : [T] extends [`0x${string}`]\n ? string\n : // Preserve branded primitives by matching the primitive first.\n T extends number\n ? T\n : T extends string\n ? T\n : T extends boolean\n ? T\n : T extends symbol\n ? T\n : T extends null | undefined\n ? T\n : T extends readonly (infer U)[]\n ? readonly StringifiedBigint<U>[]\n : T extends object\n ? { [K in keyof T]: StringifiedBigint<T[K]> }\n : T;\n\n/** Key remapping that also preserves branded primitives. */\ntype SnakeKeys<T> = T extends readonly (infer U)[]\n ? readonly SnakeKeys<U>[]\n : T extends number | string | boolean | symbol | null | undefined\n ? T\n : T extends object\n ? { [K in keyof T as ToSnakeCase<Extract<K, string>>]: SnakeKeys<T[K]> }\n : T;\n\ntype ToSnakeCase<S extends string> = S extends `${infer Head}${infer Tail}`\n ? Tail extends Uncapitalize<Tail>\n ? `${Lowercase<Head>}${ToSnakeCase<Tail>}`\n : `${Lowercase<Head>}_${ToSnakeCase<Uncapitalize<Tail>>}`\n : S;\n\n/**\n * Formats object keys to snake case.\n * Preserves ethereum addresses as is.\n * Converts ethereum addresses to checksummed if used as values.\n * Stringifies bigint values to strings.\n */\nexport function toSnakeCase<T>(obj: T): Snake<T> {\n return stringifyBigint(\n processObject(\n obj,\n (s: string) => s.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`),\n (value: unknown) =>\n typeof value === \"string\" && isAddress(value.toLowerCase())\n ? getAddress(value.toLowerCase())\n : value,\n ),\n ) as Snake<T>;\n}\n\n/**\n * Formats a snake case object to its camel case type.\n * Preserves ethereum addresses as is.\n * Converts checksummed ethereum addresses to lowercase if used as values.\n * @warning Does not unstringify bigint values.\n */\nexport function fromSnakeCase<T>(obj: Snake<T>): T {\n return processObject(\n obj,\n (s: string) =>\n isAddress(s.toLowerCase()) ? s : s.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),\n (value: unknown) =>\n typeof value === \"string\" && isAddress(value.toLowerCase()) ? value.toLowerCase() : value,\n ) as T;\n}\n\nfunction processObject<T>(\n obj: T,\n fnKey: (str: string) => string,\n fnValue: (value: unknown) => unknown,\n): unknown {\n if (typeof obj !== \"object\" || obj === null) return obj;\n\n if (Array.isArray(obj)) return obj.map((item) => processObject(item, fnKey, fnValue));\n\n return Object.entries(obj as Record<string, unknown>).reduce(\n (acc, [key, value]) => {\n const newKey = fnKey(key);\n acc[newKey] =\n typeof value === \"object\" && value !== null\n ? processObject(value, fnKey, fnValue)\n : fnValue(value);\n\n return acc;\n },\n {} as Record<string, unknown>,\n );\n}\n\nexport function stringifyBigint<T>(value: T): StringifiedBigint<T> {\n if (typeof value === \"bigint\") return value.toString() as StringifiedBigint<T>;\n if (Array.isArray(value)) return value.map(stringifyBigint) as StringifiedBigint<T>;\n if (value && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value)) {\n out[k] = stringifyBigint(v);\n }\n return out as StringifiedBigint<T>;\n }\n\n return value as StringifiedBigint<T>;\n}\n","import { type Address, encodeAbiParameters, type Hex, keccak256 } from \"viem\";\nimport * as z from \"zod\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress } from \"#utils/zod.ts\";\nimport type * as Chain from \"./Chain.ts\";\nimport * as Collateral from \"./Collateral.ts\";\nimport * as Maturity from \"./Maturity.ts\";\n\nexport type Obligation = {\n /** The chain id where the liquidity for this obligation is located. */\n chainId: Chain.Id;\n /** The token that is being borrowed for this obligation. */\n loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. */\n collaterals: Collateral.Collateral[];\n /** The maturity of the obligation. */\n maturity: Maturity.Maturity;\n};\n\nexport const ObligationSchema = z.object({\n chainId: z.number().min(0).max(Number.MAX_SAFE_INTEGER),\n loanToken: z.string().transform(transformAddress),\n collaterals: Collateral.CollateralsSchema,\n maturity: Maturity.MaturitySchema,\n});\n\n/**\n * Creates an obligation from the given parameters.\n * @constructor\n * @param parameters - {@link from.Parameters}\n * @returns The created obligation. {@link Obligation}\n * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}\n *\n * @example\n * ```ts\n * const obligation = Obligation.from({\n * chainId: 1,\n * loanToken: privateKeyToAccount(generatePrivateKey()).address,\n * collaterals: [\n * Collateral.from({\n * asset: privateKeyToAccount(generatePrivateKey()).address,\n * oracle: privateKeyToAccount(generatePrivateKey()).address,\n * lltv: 0.965\n * }),\n * ],\n * maturity: Maturity.from(\"end_of_next_quarter\"),\n * });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n try {\n const parsedObligation = ObligationSchema.parse({\n ...parameters,\n maturity: Maturity.from(parameters.maturity),\n });\n\n return {\n chainId: parsedObligation.chainId as Chain.Id,\n loanToken: parsedObligation.loanToken.toLowerCase() as Address,\n collaterals: parsedObligation.collaterals.sort((a, b) => a.asset.localeCompare(b.asset)),\n maturity: parsedObligation.maturity,\n };\n } catch (error: unknown) {\n throw new InvalidObligationError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n type Parameters = {\n /** The chain id where the liquidity for this obligation is located. */\n chainId: number;\n /** The token that is being borrowed for this obligation. */\n loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */\n collaterals: Collateral.from.Parameters[] | readonly Collateral.from.Parameters[];\n /** The maturity of the obligation. */\n maturity: Maturity.from.Parameters;\n };\n\n type ReturnType = Obligation;\n\n export type ErrorType = InvalidObligationError;\n}\n\n/**\n * Creates an obligation from a snake case object.\n * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}\n * @param input - {@link fromSnakeCase.Parameters}\n * @returns The created obligation. {@link fromSnakeCase.ReturnType}\n */\nexport function fromSnakeCase(input: fromSnakeCase.Parameters): fromSnakeCase.ReturnType {\n return from(Format.fromSnakeCase<Omit<Obligation, \"chainId\"> & { chainId: number }>(input));\n}\n\nexport declare namespace fromSnakeCase {\n type Parameters = Format.Snake<Omit<Obligation, \"chainId\"> & { chainId: number }>;\n type ReturnType = Obligation;\n type ErrorType = InvalidObligationError;\n}\n\n/**\n * Calculates the obligation id based on the smart contract's Obligation struct.\n * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).\n * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}\n * @param parameters - {@link id.Parameters}\n * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}\n *\n * @example\n * ```ts\n * const obligation = Obligation.random();\n * const id = Obligation.id(obligation);\n * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234\n * ```\n */\nexport function id(parameters: id.Parameters): id.ReturnType {\n let lastAsset = \"\";\n for (const collateral of parameters.collaterals) {\n const newAsset = collateral.asset.toLowerCase();\n if (newAsset.localeCompare(lastAsset) < 0) throw new CollateralsAreNotSortedError();\n lastAsset = newAsset;\n }\n\n return keccak256(\n encodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"address\" },\n {\n type: \"tuple[]\",\n components: [\n { type: \"address\", name: \"token\" },\n { type: \"uint256\", name: \"lltv\" },\n { type: \"address\", name: \"oracle\" },\n ],\n },\n { type: \"uint256\" },\n ],\n [\n BigInt(parameters.chainId),\n parameters.loanToken.toLowerCase() as Address,\n parameters.collaterals.map((c) => ({\n token: c.asset.toLowerCase() as Address,\n lltv: c.lltv,\n oracle: c.oracle.toLowerCase() as Address,\n })),\n BigInt(parameters.maturity),\n ],\n ),\n );\n}\n\nexport declare namespace id {\n type Parameters = {\n chainId: number;\n loanToken: Address;\n collaterals: {\n asset: Address;\n lltv: bigint;\n oracle: Address;\n }[];\n maturity: number;\n };\n type ReturnType = Hex;\n type ErrorType = CollateralsAreNotSortedError;\n}\n\n/**\n * Generates a random obligation.\n * @returns A randomly generated obligation. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const obligation = Obligation.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n chainId: 1,\n loanToken: Random.address(),\n collaterals: [Collateral.random()],\n maturity: Maturity.from(\"end_of_next_quarter\"),\n });\n}\n\nexport declare namespace random {\n type ReturnType = Obligation;\n}\n\nexport class InvalidObligationError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Obligation.InvalidObligationError\";\n constructor(error: z.ZodError | Error) {\n super(\"Invalid obligation.\", { cause: error });\n }\n}\n\nexport class CollateralsAreNotSortedError extends Errors.BaseError {\n override readonly name = \"Obligation.CollateralsAreNotSortedError\";\n constructor() {\n super(\"Collaterals are not sorted alphabetically by address.\");\n }\n}\n","import { StandardMerkleTree } from \"@openzeppelin/merkle-tree\";\nimport { gzip, ungzip } from \"pako\";\nimport {\n type Address,\n bytesToHex,\n type Hex,\n hashMessage,\n hexToBytes,\n isHex,\n recoverAddress,\n} from \"viem\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Offer from \"./Offer.ts\";\nimport type { Compute } from \"./types.ts\";\n\n/**\n * A merkle tree of offers built from offer hashes.\n * Constructed via {@link from}. The tree root can be signed for onchain broadcast.\n */\nexport type Tree = Compute<\n StandardMerkleTree<[Hex]> & {\n /** The offers in the tree. */\n offers: Offer.Offer[];\n /** The root of the tree. */\n root: Hex;\n }\n>;\n\nexport type Proof = {\n /** The offer that the proof is for. */\n offer: Offer.Offer;\n /** The merkle proof path for the offer. */\n path: Hex[];\n};\n\nexport const VERSION = 1;\n\nconst normalizeHash = (hash: Hex): Hex => hash.toLowerCase() as Hex;\n\n/**\n * Builds a Merkle tree from a list of offers.\n *\n * Leaves are the offer `hash` values as `bytes32` and are deterministically\n * ordered following the StandardMerkleTree leaf ordering so that the resulting\n * root is stable regardless of the input order.\n *\n * @param offers - Offers to include in the tree.\n * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.\n * @throws {TreeError} If tree building fails due to offer inconsistencies.\n */\nexport const from = (offers: Offer.Offer[]): Tree => {\n const leaves = offers.map<[Hex]>((offer) => [Offer.hash(offer)]);\n const tree = StandardMerkleTree.of<[Hex]>(leaves, [\"bytes32\"]);\n const orderedOffers = orderOffers(tree, offers);\n return Object.assign(tree, { offers: orderedOffers }) as Tree;\n};\n\nconst orderOffers = (tree: StandardMerkleTree<[Hex]>, offers: Offer.Offer[]): Offer.Offer[] => {\n const offerByHash = new Map<Hex, Offer.Offer>();\n for (const offer of offers) {\n offerByHash.set(normalizeHash(Offer.hash(offer)), offer);\n }\n\n const entries = tree.dump().values.map((value) => {\n const hash = normalizeHash(value.value[0] as Hex);\n const offer = offerByHash.get(hash);\n if (!offer) {\n throw new TreeError(`missing offer for leaf ${hash}`);\n }\n return { offer, treeIndex: value.treeIndex };\n });\n\n entries.sort((a, b) => b.treeIndex - a.treeIndex);\n return entries.map((item) => item.offer);\n};\n\n/**\n * Generates merkle proofs for all offers in a tree.\n *\n * Each proof allows independent verification that an offer is included in the tree\n * without requiring the full tree. Proofs are ordered by StandardMerkleTree leaf ordering.\n *\n * @param tree - The {@link Tree} to generate proofs for.\n * @returns Array of proofs - {@link Proof}\n */\nexport const proofs = (tree: Tree): Proof[] => {\n return tree.offers.map((offer) => {\n const path = tree.getProof([Offer.hash(offer)] as [Hex]) as Hex[];\n return { offer, path };\n });\n};\n\nconst assertHex = (value: unknown, expectedBytes: number, name: string): void => {\n if (typeof value !== \"string\" || !isHex(value)) {\n throw new DecodeError(`${name} is not a valid hex string`);\n }\n if (hexToBytes(value).length !== expectedBytes) {\n throw new DecodeError(`${name}: expected ${expectedBytes} bytes`);\n }\n};\n\nconst verifySignatureAndRecoverAddress = async (params: {\n root: Hex;\n signature: Hex;\n}): Promise<Address> => {\n const { root, signature } = params;\n assertHex(signature, 65, \"signature\");\n const hash = hashMessage({ raw: root });\n try {\n return await recoverAddress({ hash, signature });\n } catch {\n throw new DecodeError(\"signature recovery failed\");\n }\n};\n\n/**\n * Encodes a merkle tree with signature into hex calldata for onchain broadcast.\n *\n * Layout: `0x{vv}{gzip([...offers])}{root}{signature}` where:\n * - `{vv}`: 1-byte version (currently 0x01)\n * - `{gzip([...offers])}`: gzipped JSON array of serialized offers\n * - `{root}`: 32-byte merkle root\n * - `{signature}`: 65-byte EIP-191 signature over raw root bytes\n *\n * Validates signature authenticity and root integrity before encoding.\n *\n * @example\n * ```typescript\n * const tree = Tree.from(offers);\n * const signature = await wallet.signMessage({ message: { raw: tree.root } });\n * const calldata = await Tree.encode(tree, signature);\n * await broadcast(calldata);\n * ```\n *\n * @example\n * Manual construction (for advanced users):\n * ```typescript\n * const tree = Tree.from(offers);\n * const compressed = gzip(JSON.stringify(tree.offers.map(Offer.serialize)));\n * const partial = `0x01${bytesToHex(compressed)}${tree.root.slice(2)}`;\n * const signature = await wallet.signMessage({ message: { raw: tree.root } });\n * const calldata = `${partial}${signature.slice(2)}`;\n * ```\n *\n * @param tree - Merkle tree of offers\n * @param signature - EIP-191 signature over raw root bytes\n * @returns Hex-encoded calldata ready for onchain broadcast\n * @throws {EncodeError} If signature verification fails or root mismatch\n */\nexport const encode = async (tree: Tree, signature: Hex): Promise<Hex> => {\n validateTreeForEncoding(tree);\n await verifySignatureAndRecoverAddress({ root: tree.root, signature });\n\n const unsigned = encodeUnsignedBytes(tree);\n const sigBytes = hexToBytes(signature);\n const encoded = new Uint8Array(unsigned.length + sigBytes.length);\n encoded.set(unsigned, 0);\n encoded.set(sigBytes, unsigned.length);\n\n return bytesToHex(encoded);\n};\n\n/**\n * Encodes a merkle tree without a signature into hex payload for client-side signing.\n *\n * Layout: `0x{vv}{gzip([...offers])}{root}` where:\n * - `{vv}`: 1-byte version (currently 0x01)\n * - `{gzip([...offers])}`: gzipped JSON array of serialized offers\n * - `{root}`: 32-byte merkle root\n *\n * Validates root integrity before encoding.\n *\n * @param tree - Merkle tree of offers\n * @returns Hex-encoded unsigned payload\n * @throws {EncodeError} If root mismatch\n */\nexport const encodeUnsigned = (tree: Tree): Hex => {\n validateTreeForEncoding(tree);\n return bytesToHex(encodeUnsignedBytes(tree));\n};\n\nconst validateTreeForEncoding = (tree: Tree): void => {\n if (VERSION > 0xff) throw new EncodeError(`version overflow: ${VERSION} exceeds 255`);\n\n const computed = from(tree.offers);\n if (tree.root !== computed.root)\n throw new EncodeError(`root mismatch: expected ${computed.root}, got ${tree.root}`);\n};\n\nconst encodeUnsignedBytes = (tree: Tree): Uint8Array => {\n const offersPayload = tree.offers.map(Offer.serialize);\n const compressed = gzip(JSON.stringify(offersPayload));\n const rootBytes = hexToBytes(tree.root);\n const encoded = new Uint8Array(1 + compressed.length + 32);\n encoded[0] = VERSION;\n encoded.set(compressed, 1);\n encoded.set(rootBytes, 1 + compressed.length);\n return encoded;\n};\n\n/**\n * Decodes hex calldata into a validated merkle tree.\n *\n * Validates signature before decompression for fail-fast rejection of invalid payloads.\n * Returns the tree with separately validated signature and recovered signer address.\n *\n * Validation order:\n * 1. Version check\n * 2. Signature verification (fail-fast, before decompression)\n * 3. Decompression (only if signature valid)\n * 4. Root verification (computed from offers vs embedded root)\n *\n * @example\n * ```typescript\n * const { tree, signature, signer } = await Tree.decode(calldata);\n * console.log(`Tree signed by ${signer} with ${tree.offers.length} offers`);\n * ```\n *\n * @param encoded - Hex calldata in format `0x{vv}{gzip}{root}{signature}`\n * @returns Validated tree, signature, and recovered signer address\n * @throws {DecodeError} If version invalid, signature invalid, or root mismatch\n */\nexport const decode = async (\n encoded: Hex,\n): Promise<{\n tree: Tree;\n signature: Hex;\n signer: Address;\n}> => {\n const bytes = hexToBytes(encoded);\n if (bytes.length < 98) throw new DecodeError(\"payload too short\");\n\n const version = bytes[0];\n if (version !== (VERSION & 0xff))\n throw new DecodeError(`invalid version: expected ${VERSION}, got ${version ?? 0}`);\n\n // Parse from end: signature (last 65 bytes) + root (32 bytes before sig)\n const signature = bytesToHex(bytes.slice(-65));\n const root = bytesToHex(bytes.slice(-97, -65));\n assertHex(root, 32, \"root\");\n assertHex(signature, 65, \"signature\");\n\n const signer = await verifySignatureAndRecoverAddress({ root, signature });\n\n const compressed = bytes.slice(1, -97);\n let decoded: string;\n try {\n decoded = ungzip(compressed, { to: \"string\" });\n } catch {\n throw new DecodeError(\"decompression failed\");\n }\n\n let rawOffers: unknown[];\n try {\n rawOffers = JSON.parse(decoded) as unknown[];\n } catch {\n throw new DecodeError(\"JSON parse failed\");\n }\n\n const offers = rawOffers.map(\n (o: unknown) => Offer.OfferSchema().parse(o) as unknown as Offer.Offer,\n );\n\n const tree = from(offers);\n if (root !== tree.root) {\n throw new DecodeError(`root mismatch: expected ${tree.root}, got ${root}`);\n }\n\n return { tree, signature, signer };\n};\n\n/**\n * Error thrown during tree building operations.\n * Indicates structural issues with the tree (missing offers, inconsistent state).\n */\nexport class TreeError extends Errors.BaseError {\n override name = \"Tree.TreeError\";\n constructor(reason: string) {\n super(`Tree error: ${reason}`);\n }\n}\n\n/**\n * Error thrown during tree encoding.\n * Indicates validation failures (signature, root mismatch, mixed makers).\n */\nexport class EncodeError extends Errors.BaseError {\n override name = \"Tree.EncodeError\";\n constructor(reason: string) {\n super(`Failed to encode tree: ${reason}`);\n }\n}\n\n/**\n * Error thrown during tree decoding.\n * Indicates payload corruption, version mismatch, or validation failures.\n */\nexport class DecodeError extends Errors.BaseError {\n override name = \"Tree.DecodeError\";\n constructor(reason: string) {\n super(`Failed to decode tree: ${reason}`);\n }\n}\n","import {\n type Address,\n type DecodeAbiParametersReturnType,\n decodeAbiParameters,\n encodeAbiParameters,\n type Hex,\n hashTypedData,\n maxUint256,\n type WalletClient,\n zeroAddress,\n} from \"viem\";\nimport * as z from \"zod\";\nimport type { Compute } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress, transformBytes32, transformHex } from \"#utils/zod.ts\";\nimport * as Callback from \"./Callback.ts\";\nimport * as Chain from \"./Chain.ts\";\nimport * as Collateral from \"./Collateral.ts\";\nimport * as LLTV from \"./LLTV.ts\";\nimport * as Maturity from \"./Maturity.ts\";\nimport * as Obligation from \"./Obligation.ts\";\nimport * as Tree from \"./Tree.ts\";\n\n/** Internal symbol for caching the computed hash. */\nconst HASH_CACHE = Symbol(\"offer.hash\");\n\nexport type Offer = {\n /** The address that made the offer. */\n readonly maker: Address;\n /** The amount of assets offered. Mutually exclusive with obligationUnits and obligationShares. */\n readonly assets: bigint;\n /** The max debt units to trade. Mutually exclusive with assets and obligationShares. */\n readonly obligationUnits: bigint;\n /** The max lending shares to trade. Mutually exclusive with assets and obligationUnits. */\n readonly obligationShares: bigint;\n /** The price (18 decimals). */\n readonly price: bigint;\n /** The date at which all interests will be paid. */\n readonly maturity: Maturity.Maturity;\n /** The date at which the offer will expire. */\n readonly expiry: number;\n /** The date at which the offer will start. */\n readonly start: number;\n /** The group. Used for OCO (One-Cancelled-Other) mechanism. */\n readonly group: Hex;\n /** The session. Used for session-based offer management. */\n readonly session: Hex;\n /** The side of the offer. `true` for buy, `false` for sell. */\n readonly buy: boolean;\n /** The chain id where the liquidity for this offer is located. */\n readonly chainId: Chain.Id;\n /** The token that is being borrowed. */\n readonly loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. */\n readonly collaterals: readonly Collateral.Collateral[];\n /** The optional callback data to retrieve the maker funds. */\n readonly callback: {\n readonly address: Address;\n readonly data: Hex;\n };\n};\n\nexport enum Status {\n VALID = \"VALID\",\n SIMULATION_ERROR = \"SIMULATION_ERROR\",\n}\n\nexport type Validation = {\n offerHash: Hex;\n status: Status;\n};\n\nexport const OfferSchema = () => {\n return z\n .object({\n maker: z.string().transform(transformAddress),\n assets: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n obligationUnits: z.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),\n obligationShares: z.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n maturity: Maturity.MaturitySchema,\n expiry: z.number().int().max(Number.MAX_SAFE_INTEGER),\n start: z.number().int().max(Number.MAX_SAFE_INTEGER),\n group: z.union([z.string(), z.number(), z.bigint()]).transform(transformBytes32),\n session: z\n .union([z.string(), z.number(), z.bigint()])\n .optional()\n .default(\"0x0000000000000000000000000000000000000000000000000000000000000000\")\n .transform(transformBytes32),\n buy: z.boolean(),\n chainId: z.number().min(0).max(Number.MAX_SAFE_INTEGER),\n loanToken: z.string().transform(transformAddress),\n collaterals: Collateral.CollateralsSchema,\n callback: z.object({\n address: z.string().transform(transformAddress),\n data: z.string().transform(transformHex),\n }),\n })\n .refine((data) => data.start < data.expiry, {\n message: \"start must be before expiry\",\n path: [\"start\"],\n })\n .refine((data) => data.expiry <= data.maturity, {\n message: \"expiry must be before or equal to maturity\",\n path: [\"expiry\"],\n });\n};\n\n/**\n * Input type for creating offers. Accepts flexible group types that will be coerced to Hex.\n *\n * The `group` field accepts multiple input formats:\n * - **Hex string** (`0x...`): Padded to 32 bytes if needed\n * - **Numeric string**: Converted to hex (e.g., `\"123\"` -> `\"0x...7b\"`)\n * - **Number**: Non-negative safe integer, converted to hex\n * - **BigInt**: Non-negative, must fit in bytes32\n *\n * All values validated to be non-negative and within bytes32 range.\n */\nexport type OfferInput = Compute<\n Omit<Offer, \"chainId\" | \"group\" | \"session\" | \"obligationUnits\" | \"obligationShares\"> & {\n chainId: number;\n group: Hex | bigint | number | string;\n /** Optional: defaults to zero bytes32. */\n session?: Hex | bigint | number | string;\n /** Optional: defaults to 0n. Mutually exclusive with assets and obligationShares. */\n obligationUnits?: bigint;\n /** Optional: defaults to 0n. Mutually exclusive with assets and obligationUnits. */\n obligationShares?: bigint;\n }\n>;\n\n/**\n * Creates an offer from a plain object.\n * @throws {InvalidOfferError} If the offer is invalid.\n * @param input - The offer to create.\n * @returns The created offer.\n */\nexport function from(input: OfferInput): Offer {\n try {\n return OfferSchema().parse(input) as Offer;\n } catch (error: unknown) {\n throw new InvalidOfferError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n export type ErrorType = InvalidOfferError;\n}\n\n/**\n * Creates an offer from a snake case object.\n * @throws {InvalidOfferError} If the offer is invalid.\n * @param input - The offer to create.\n * @returns The created offer.\n */\nexport function fromSnakeCase(\n input: Format.Snake<Omit<Offer, \"chainId\" | \"session\"> & { chainId: number; session: string }>,\n): Offer {\n return from(\n Format.fromSnakeCase<Omit<Offer, \"chainId\" | \"session\"> & { chainId: number; session: string }>(\n input,\n ),\n );\n}\n\n/**\n * Converts an offer to a snake case object.\n * @param offer - The offer to convert.\n * @returns The converted offer.\n */\nexport function toSnakeCase(offer: Offer): Format.Snake<Offer> {\n return Format.toSnakeCase(offer);\n}\n\n/**\n * Serializes an offer for merkle tree encoding.\n * Converts BigInt fields to strings for JSON compatibility.\n *\n * @param offer - Offer to serialize\n * @returns JSON-serializable offer object\n */\nexport const serialize = (offer: Offer) => ({\n maker: offer.maker,\n assets: offer.assets.toString(),\n obligationUnits: offer.obligationUnits.toString(),\n obligationShares: offer.obligationShares.toString(),\n price: offer.price.toString(),\n maturity: Number(offer.maturity),\n expiry: Number(offer.expiry),\n start: Number(offer.start),\n group: offer.group,\n session: offer.session,\n buy: offer.buy,\n chainId: offer.chainId,\n loanToken: offer.loanToken,\n collaterals: offer.collaterals.map((c) => ({\n asset: c.asset,\n oracle: c.oracle,\n lltv: c.lltv.toString(),\n })),\n callback: {\n address: offer.callback.address,\n data: offer.callback.data,\n },\n hash: hash(offer),\n});\n\nexport type RandomConfig = {\n chains?: Chain.Chain[];\n loanTokens?: Address[];\n collateralTokens?: Address[];\n assetsDecimals?: Record<Address, number>;\n buy?: boolean;\n assets?: bigint;\n obligationUnits?: bigint;\n obligationShares?: bigint;\n maker?: Address;\n maturity?: Maturity.Maturity;\n start?: number;\n expiry?: number;\n group?: Hex | bigint | number | string;\n session?: Hex | bigint | number | string;\n price?: bigint;\n callback?: {\n address: Address;\n data: Hex;\n };\n collaterals?: readonly Collateral.Collateral[];\n};\n\n/**\n * Generates a random Offer.\n * The returned Offer contains randomly generated values.\n * @warning The generated Offer should not be used for production usage.\n * @returns {Offer} A randomly generated Offer object.\n */\nexport function random(config?: RandomConfig): Offer {\n const chain = config?.chains\n ? config.chains[Random.int(config.chains.length)]!\n : Chain.chains.ethereum;\n\n const loanToken = config?.loanTokens\n ? config.loanTokens[Random.int(config.loanTokens.length)]!\n : Random.address();\n\n const collateralCandidates = config?.collateralTokens\n ? config.collateralTokens.filter((a) => a !== loanToken)\n : [Random.address()];\n\n const collateralAsset = collateralCandidates[Random.int(collateralCandidates.length)]!;\n\n const maturityOption = weightedChoice<Maturity.MaturityOptions>([\n [\"end_of_month\", 1],\n [\"end_of_next_month\", 1],\n ]);\n\n const maturity = config?.maturity ?? Maturity.from(maturityOption);\n\n const lltv = LLTV.from(\n weightedChoice<(typeof LLTV.Options)[number]>([\n [0.385, 1],\n [0.5, 1],\n [0.625, 2],\n [0.77, 8],\n [0.86, 10],\n [0.915, 8],\n [0.945, 6],\n [0.965, 4],\n [0.98, 2],\n ]),\n );\n\n const buy = config?.buy !== undefined ? config.buy : Random.bool();\n\n // Price spread grid with step 0.25, ranges by side:\n // - Buy: [4.00, 8.00]\n // - Sell: [1.00, 4.00]\n const ONE = 1000000000000000000n; // 1e18\n const qMin = buy ? 16 : 4; // quarters (4.00 => 16, 8.00 => 32, 1.00 => 4)\n const qMax = buy ? 32 : 16;\n const len = qMax - qMin + 1;\n const pricePairs: ReadonlyArray<readonly [bigint, number]> = Array.from(\n { length: len },\n (_, idx) => {\n const q = qMin + idx; // number of quarters (0.25)\n const scaledPrice = BigInt(q) * (ONE / 4n);\n // Make best prices rarer and worse prices more common (by side):\n // - Buy best is lower price => weight increases with idx (higher price)\n // - Sell best is higher price => weight decreases with idx\n const weight = buy ? 1 + idx : 1 + (len - 1 - idx);\n return [scaledPrice, weight] as const;\n },\n );\n const price = config?.price ?? weightedChoice<bigint>(pricePairs);\n\n const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;\n const unit = BigInt(10) ** BigInt(loanTokenDecimals);\n const amountBase = BigInt(100 + Random.int(1_000_000 - 100 + 1));\n const assetsScaled = config?.assets ?? amountBase * unit;\n\n const callbackBySide = (() => {\n if (buy) return { address: zeroAddress, data: \"0x\" as Hex } as const;\n const sellCallbackAddress = \"0x3333333333333333333333333333333333333333\" as Address;\n const amount = assetsScaled * 1000000000000000000000n;\n const data = Callback.encodeSellERC20Callback({\n collaterals: [collateralAsset],\n amounts: [amount],\n });\n return { address: sellCallbackAddress, data } as const;\n })();\n\n const offer = from({\n maker: config?.maker ?? Random.address(),\n assets: assetsScaled,\n obligationUnits: config?.obligationUnits ?? 0n,\n obligationShares: config?.obligationShares ?? 0n,\n price,\n maturity: maturity,\n expiry: config?.expiry ?? maturity - 1,\n start: config?.start ?? maturity - 10,\n group: config?.group ?? Random.hex(32),\n session: config?.session ?? Random.hex(32),\n buy,\n chainId: chain.id,\n loanToken,\n collaterals:\n config?.collaterals ??\n Array.from({ length: Random.int(3) + 1 }, () => ({\n ...Collateral.random(),\n lltv,\n })).sort((a, b) => a.asset.localeCompare(b.asset)),\n callback: config?.callback ?? callbackBySide,\n });\n\n return offer;\n}\n\nconst weightedChoice = <T>(pairs: ReadonlyArray<readonly [T, number]>): T => {\n const total = pairs.reduce((sum, [, weight]) => sum + weight, 0);\n let roll = Random.float() * total;\n for (const [value, weight] of pairs) {\n roll -= weight;\n if (roll < 0) return value;\n }\n return pairs[0]![0];\n};\n\n/**\n * Creates an EIP-712 domain object.\n * @param chainId - The chain ID.\n * @returns The EIP-712 domain object.\n */\nexport const domain = (chainId: number) => ({\n chainId: BigInt(chainId),\n verifyingContract: zeroAddress,\n});\n\n/**\n * The EIP-712 types for the offer.\n * @warning The ordering of the types should NEVER be changed. The offer hash is computed based on the order of the types.\n * @returns The EIP-712 types.\n */\nexport const types = {\n EIP712Domain: [\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n ],\n Offer: [\n { name: \"maker\", type: \"address\" },\n { name: \"assets\", type: \"uint256\" },\n { name: \"obligationUnits\", type: \"uint256\" },\n { name: \"obligationShares\", type: \"uint256\" },\n { name: \"price\", type: \"uint256\" },\n { name: \"maturity\", type: \"uint256\" },\n { name: \"expiry\", type: \"uint256\" },\n { name: \"group\", type: \"bytes32\" },\n { name: \"session\", type: \"bytes32\" },\n { name: \"buy\", type: \"bool\" },\n { name: \"loanToken\", type: \"address\" },\n { name: \"collaterals\", type: \"Collateral[]\" },\n { name: \"callback\", type: \"Callback\" },\n ],\n Collateral: [\n { name: \"asset\", type: \"address\" },\n { name: \"oracle\", type: \"address\" },\n { name: \"lltv\", type: \"uint256\" },\n ],\n Callback: [\n { name: \"address\", type: \"address\" },\n { name: \"data\", type: \"bytes\" },\n ],\n} as const;\n\n/**\n * Signs an array of offers.\n * @throws {Error} If the wallet account is not set.\n * @param offers - The offers to sign.\n * @param wallet - The wallet to sign the offers with.\n * @returns The signed offers.\n */\nexport async function sign(offers: Offer[], wallet: WalletClient): Promise<Hex> {\n if (!wallet.account) throw new AccountNotSetError();\n return wallet.signMessage({\n account: wallet.account,\n message: { raw: signatureMsg(offers) },\n });\n}\n\nexport function signatureMsg(offers: Offer[]): Hex {\n return Tree.from(offers).root;\n}\n\nexport function hash(offer: Offer): Hex {\n const cached = (offer as { [HASH_CACHE]?: Hex })[HASH_CACHE];\n if (cached) return cached;\n\n const computed = hashTypedData({\n domain: domain(offer.chainId),\n message: {\n maker: offer.maker.toLowerCase() as Address,\n assets: offer.assets,\n obligationUnits: offer.obligationUnits,\n obligationShares: offer.obligationShares,\n price: offer.price,\n maturity: BigInt(offer.maturity),\n expiry: BigInt(offer.expiry),\n group: offer.group,\n session: offer.session,\n buy: offer.buy,\n loanToken: offer.loanToken.toLowerCase() as Address,\n collaterals: offer.collaterals,\n callback: {\n address: offer.callback.address.toLowerCase() as Address,\n data: offer.callback.data,\n },\n },\n primaryType: \"Offer\",\n types,\n });\n\n (offer as { [HASH_CACHE]?: Hex })[HASH_CACHE] = computed;\n return computed;\n}\n\n/**\n * Calculates the obligation id for an offer based on the smart contract's Obligation struct.\n * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals (sorted by token address), maturity)).\n * @param offer - The offer to calculate the obligation id for.\n * @returns The obligation id as a 32-byte hex string.\n */\nexport function obligationId(offer: Offer): Hex {\n return Obligation.id(\n Obligation.from({\n chainId: offer.chainId,\n loanToken: offer.loanToken,\n collaterals: offer.collaterals as Collateral.Collateral[],\n maturity: offer.maturity,\n }),\n );\n}\n\nconst OfferAbi = [\n { name: \"maker\", type: \"address\" },\n { name: \"assets\", type: \"uint256\" },\n { name: \"obligationUnits\", type: \"uint256\" },\n { name: \"obligationShares\", type: \"uint256\" },\n { name: \"price\", type: \"uint256\" },\n { name: \"maturity\", type: \"uint256\" },\n { name: \"expiry\", type: \"uint256\" },\n { name: \"group\", type: \"bytes32\" },\n { name: \"session\", type: \"bytes32\" },\n { name: \"buy\", type: \"bool\" },\n { name: \"chainId\", type: \"uint256\" },\n { name: \"loanToken\", type: \"address\" },\n { name: \"start\", type: \"uint256\" },\n {\n name: \"collaterals\",\n type: \"tuple[]\",\n components: [\n { name: \"asset\", type: \"address\" },\n { name: \"oracle\", type: \"address\" },\n { name: \"lltv\", type: \"uint256\" },\n ],\n },\n {\n name: \"callback\",\n type: \"tuple\",\n components: [\n { name: \"address\", type: \"address\" },\n { name: \"data\", type: \"bytes\" },\n ],\n },\n] as const;\n\nexport function encode(offer: Offer) {\n return encodeAbiParameters(OfferAbi, [\n offer.maker,\n offer.assets,\n offer.obligationUnits,\n offer.obligationShares,\n offer.price,\n BigInt(offer.maturity),\n BigInt(offer.expiry),\n offer.group,\n offer.session,\n offer.buy,\n BigInt(offer.chainId),\n offer.loanToken,\n BigInt(offer.start),\n offer.collaterals,\n offer.callback,\n ]);\n}\n\nexport function decode(data: Hex): Offer {\n let decoded: DecodeAbiParametersReturnType<typeof OfferAbi>;\n try {\n decoded = decodeAbiParameters(OfferAbi, data);\n } catch (error) {\n throw new InvalidOfferError(error as Error);\n }\n\n const offer = from({\n maker: decoded[0],\n assets: decoded[1],\n obligationUnits: decoded[2],\n obligationShares: decoded[3],\n price: decoded[4],\n maturity: Maturity.from(Number(decoded[5])),\n expiry: Number(decoded[6]),\n group: decoded[7],\n session: decoded[8],\n buy: decoded[9],\n chainId: Number(decoded[10]),\n loanToken: decoded[11],\n start: Number(decoded[12]),\n collaterals: decoded[13].map((c) => {\n return Collateral.from({\n asset: c.asset,\n oracle: c.oracle,\n lltv: c.lltv,\n });\n }),\n callback: {\n address: decoded[14].address,\n data: decoded[14].data,\n },\n });\n\n return offer;\n}\n\nexport type OfferConsumed = {\n id: string;\n chainId: Chain.Id;\n maker: Address;\n group: Hex;\n amount: bigint;\n blockNumber: number;\n};\n\n/**\n * ABI for the Consume event emitted by the Obligation contract.\n */\nexport const consumedEvent = {\n type: \"event\",\n name: \"Consume\",\n inputs: [\n { name: \"user\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"group\", type: \"bytes32\", indexed: true, internalType: \"bytes32\" },\n { name: \"amount\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n} as const;\n\nexport class InvalidOfferError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Offer.InvalidOfferError\";\n\n constructor(error: z.ZodError | Error) {\n super(\"Invalid offer.\", {\n cause: error,\n });\n }\n\n /**\n * Formats ZodError issues into a human-readable string with line breaks.\n * @example\n * \"- 'assets': too small, expected >= 0\n * - 'start': must be before expiry\"\n */\n static formatDetails(error: z.ZodError | Error): string {\n if (!(error instanceof z.ZodError)) {\n return error.message;\n }\n\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n const normalized = issue.message.trim();\n return `'${path}': ${normalized.toLowerCase()}`;\n })\n .join(\". \");\n }\n\n /**\n * Returns the formatted human-readable message.\n */\n get formattedMessage(): string {\n return `Invalid offer. ${InvalidOfferError.formatDetails(this.cause)}`;\n }\n}\n\nexport class AccountNotSetError extends Errors.BaseError {\n override readonly name = \"Offer.AccountNotSetError\";\n constructor() {\n super(\"Account not set.\");\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\n\n/**\n * An oracle contract that provides price information for assets.\n */\nexport type Oracle = {\n /** The chain id where the oracle is deployed. */\n readonly chainId: Chain.Id;\n /** The address of the oracle contract. */\n readonly address: Address;\n /** The price returned by the oracle (in the oracle's native units), null if no price available. */\n readonly price: bigint | null;\n /** The block number at which the price was fetched. */\n readonly blockNumber: number;\n};\n\n/**\n * Create an Oracle from a plain object.\n * @param data - The data to create the oracle from.\n * @returns The created oracle.\n */\nexport function from(data: from.Parameters): from.ReturnType {\n return {\n chainId: data.chainId,\n address: data.address.toLowerCase() as Address,\n price: data.price ? BigInt(data.price) : null,\n blockNumber: data.blockNumber,\n };\n}\n\nexport declare namespace from {\n export type Parameters = {\n chainId: Chain.Id;\n address: Address;\n price: string | null;\n blockNumber: number;\n };\n\n export type ReturnType = Oracle;\n}\n\n/**\n * Conversion utilities for converting between collateral and loan token amounts\n * using oracle prices and LLTV\n */\nexport namespace Conversion {\n /**\n * Converts a collateral amount to loan token\n * Uses the formula: (amount * price / 10^36) * lltv / 10^18\n *\n * @param amount - The collateral amount to convert\n * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)\n * @returns The equivalent loan token amount\n */\n export function collateralToLoan(\n amount: bigint,\n params: { price: bigint; lltv: bigint },\n ): bigint {\n return (((amount * params.price) / 10n ** 36n) * params.lltv) / 10n ** 18n;\n }\n\n /**\n * Converts a loan token amount to collateral\n * Uses the inverse formula: (amount * 10^36 / price) * 10^18 / lltv\n * Returns 0n if price or lltv is zero (invalid conversion).\n *\n * @param amount - The loan token amount to convert\n * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)\n * @returns The equivalent collateral amount, or 0n if conversion is invalid\n */\n export function loanToCollateral(\n amount: bigint,\n params: { price: bigint; lltv: bigint },\n ): bigint {\n if (params.price === 0n || params.lltv === 0n) return 0n;\n return (((amount * 10n ** 36n) / params.price) * 10n ** 18n) / params.lltv;\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\n\nexport type Position = {\n /** The chain id. */\n chainId: Chain.Id;\n /** The contract address from which the position is called.\n * While balances are obviously tracked on ERC20 contracts, we prefer to track which contract is called to know the balance.\n * 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.\n */\n contract: Address;\n /** The user address. */\n user: Address;\n /** The type of position. */\n type: Type;\n /** The balance of the position. */\n balance?: bigint;\n /** The underlying asset of the position.\n * For ERC20 positions, this equals the contract address.\n * For vault positions, this is the vault's underlying asset.\n */\n asset?: Address;\n /** The block number at which the position was last updated. */\n blockNumber: number;\n};\n\nexport enum Type {\n ERC20 = \"erc20\",\n VAULT_V1 = \"vault_v1\",\n}\n\n/**\n * @constructor\n * Creates a Position.\n * @param parameters - {@link from.Parameters}\n * @returns The created Position. {@link from.ReturnType}\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n return {\n chainId: parameters.chainId,\n contract: parameters.contract.toLowerCase() as Address,\n user: parameters.user.toLowerCase() as Address,\n type: parameters.type,\n balance: parameters.balance,\n ...(parameters.asset !== undefined ? { asset: parameters.asset.toLowerCase() as Address } : {}),\n blockNumber: parameters.blockNumber,\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n chainId: Chain.Id;\n contract: Address;\n user: Address;\n type: Type;\n balance?: bigint;\n asset?: Address;\n blockNumber: number;\n };\n type ReturnType = Position;\n}\n","import { type Hex, maxUint256 } from \"viem\";\nimport * as z from \"zod\";\nimport { Obligation } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformHex } from \"#utils/zod.ts\";\n\nexport type Quote = {\n /** The obligation id. */\n obligationId: Hex;\n ask: {\n /** The ask price for the obligation. (18 decimals). */\n price: bigint;\n };\n bid: {\n /** The bid price for the obligation. (18 decimals). */\n price: bigint;\n };\n};\n\nexport const QuoteSchema = z.object({\n obligationId: z.string().transform(transformHex),\n ask: z.object({\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n }),\n bid: z.object({\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n }),\n});\n\n/**\n * Creates a quote for a given obligation.\n * @constructor\n * @param parameters - {@link from.Parameters}\n * @returns The created quote. {@link Quote}\n * @throws If the quote is invalid. {@link InvalidQuoteError}\n *\n * @example\n * ```ts\n * const quote = Quote.from({ obligationId: \"0x123\", ask: { price: 100n }, bid: { price: 100n } });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n try {\n const parsedQuote = QuoteSchema.parse(parameters);\n return {\n obligationId: parsedQuote.obligationId,\n ask: parsedQuote.ask,\n bid: parsedQuote.bid,\n };\n } catch (error: unknown) {\n throw new InvalidQuoteError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n type Parameters = Quote;\n type ReturnType = Quote;\n type ErrorType = InvalidQuoteError;\n}\n\n/**\n * Creates a quote from a snake case object.\n * @throws If the quote is invalid. {@link InvalidQuoteError}\n * @param snake - {@link fromSnakeCase.Parameters}\n * @returns The created quote. {@link fromSnakeCase.ReturnType}\n */\nexport function fromSnakeCase(snake: fromSnakeCase.Parameters): fromSnakeCase.ReturnType {\n return from(Format.fromSnakeCase<Quote>(snake));\n}\n\nexport declare namespace fromSnakeCase {\n type Parameters = Format.Snake<Quote>;\n type ReturnType = Quote;\n type ErrorType = from.ErrorType;\n}\n\n/**\n * Generates a random quote.\n * @returns A randomly generated quote. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const quote = Quote.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n obligationId: Obligation.id(Obligation.random()),\n ask: {\n price: BigInt(Random.int(1_000_000)),\n },\n bid: {\n price: BigInt(Random.int(1_000_000)),\n },\n });\n}\n\nexport declare namespace random {\n type Parameters = never;\n type ReturnType = Quote;\n type ErrorType = from.ErrorType;\n}\n\nexport class InvalidQuoteError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Quote.InvalidQuoteError\";\n constructor(error: z.ZodError | Error) {\n super(\"Invalid quote.\", { cause: error });\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\n\nexport type Transfer = {\n id: string;\n chainId: Chain.Id;\n contract: Address;\n from: Address;\n to: Address;\n value: bigint;\n blockNumber: number;\n};\n\n/**\n * @constructor\n *\n * Creates a {@link Transfer}.\n * @param parameters - {@link from.Parameters}\n * @returns The created Transfer. {@link from.ReturnType}\n *\n * @example\n * ```ts\n * const transfer = Transfer.from({ id: \"1\", chainId: 1, contract: \"0x123\", from: \"0x456\", to: \"0x789\", value: 100n, blockNumber: 100n });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n return {\n id: parameters.id,\n chainId: parameters.chainId,\n contract: parameters.contract.toLowerCase() as Address,\n from: parameters.from.toLowerCase() as Address,\n to: parameters.to.toLowerCase() as Address,\n value: parameters.value,\n blockNumber: parameters.blockNumber,\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n id: string;\n chainId: Chain.Id;\n contract: Address;\n from: Address;\n to: Address;\n value: bigint;\n blockNumber: number;\n };\n\n type ReturnType = Transfer;\n}\n","/** Combines members of an intersection into a readable type. */\n// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg\nexport type Compute<type> = { [key in keyof type]: type[key] } & unknown;\n\n// https://effect.website/docs/code-style/branded-types/#generalizing-branded-types\nexport const BrandTypeId = Symbol.for(\"mempool/Brand\");\nexport type Brand<in out ID extends string | symbol> = {\n readonly [BrandTypeId]: {\n readonly [id in ID]: ID;\n };\n};\n","import type { Address, Hex } from \"viem\";\nimport { Obligation } from \"#core\";\nimport type * as OpenApiSchema from \"./generated/swagger.d.ts\";\n\nexport type OfferResponse =\n OpenApiSchema.paths[\"/v1/offers\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"][\"data\"][number];\n\nexport type Input = Readonly<{\n hash: Hex;\n maker: Address;\n assets: bigint;\n obligationUnits: bigint;\n obligationShares: bigint;\n price: bigint;\n maturity: number;\n expiry: number;\n start: number;\n group: Hex;\n session: Hex;\n buy: boolean;\n chainId: number;\n loanToken: Address;\n collaterals: Readonly<\n {\n asset: Address;\n lltv: bigint;\n oracle: Address;\n }[]\n >;\n callback: {\n address: Address;\n data: Hex;\n };\n root?: Hex | undefined;\n proof?: Hex[] | undefined;\n signature?: Hex | undefined;\n consumed: bigint;\n takeable: bigint;\n blockNumber: number;\n}>;\n\n/**\n * Creates an `OfferResponse` matching the Solidity Offer struct layout.\n * @constructor\n * @param input - {@link Input}\n * @returns The created `OfferResponse`. {@link OfferResponse}\n */\nexport function from(input: Input): OfferResponse {\n const offer = {\n obligation: {\n loan_token: input.loanToken,\n collaterals: input.collaterals.map((c) => ({\n token: c.asset,\n lltv: c.lltv.toString(),\n oracle: c.oracle,\n })),\n maturity: input.maturity,\n },\n buy: input.buy,\n maker: input.maker,\n assets: input.assets.toString(),\n obligation_units: input.obligationUnits.toString(),\n obligation_shares: input.obligationShares.toString(),\n start: input.start,\n expiry: input.expiry,\n price: input.price.toString(),\n group: input.group,\n session: input.session,\n callback: input.callback.address,\n callback_data: input.callback.data,\n };\n\n const base = {\n offer,\n offer_hash: input.hash,\n obligation_id: Obligation.id({\n chainId: input.chainId,\n loanToken: input.loanToken,\n collaterals: [...input.collaterals],\n maturity: input.maturity,\n }),\n chain_id: input.chainId,\n consumed: input.consumed.toString(),\n takeable: input.takeable.toString(),\n block_number: input.blockNumber,\n };\n\n if (!input.proof || !input.root || !input.signature) {\n return {\n ...base,\n root: null,\n proof: null,\n signature: null,\n } as OfferResponse;\n }\n\n return {\n ...base,\n root: input.root.toLowerCase(),\n proof: input.proof.map((p) => p.toLowerCase()),\n signature: input.signature.toLowerCase(),\n } as OfferResponse;\n}\n","import * as z from \"zod\";\nimport type { Compute } from \"#core\";\n\nexport const API_ERROR_CODES = [\n \"VALIDATION_ERROR\",\n \"NOT_FOUND\",\n \"INTERNAL_SERVER_ERROR\",\n \"BAD_REQUEST\",\n] as const;\n\ntype APIErrorCode = (typeof API_ERROR_CODES)[number];\n\nexport enum STATUS_CODE {\n SUCCESS = 200,\n BAD_REQUEST = 400,\n NOT_FOUND = 404,\n INTERNAL_SERVER_ERROR = 500,\n}\n\nexport class APIError<Code extends STATUS_CODE = STATUS_CODE> extends Error {\n constructor(\n public statusCode: Code,\n message: string,\n public code: APIErrorCode,\n public details?: unknown,\n ) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\nexport class ValidationError extends APIError<STATUS_CODE.BAD_REQUEST> {\n constructor(message: string, details?: unknown) {\n super(STATUS_CODE.BAD_REQUEST, message, \"VALIDATION_ERROR\", details);\n }\n}\n\nexport class NotFoundError extends APIError<STATUS_CODE.NOT_FOUND> {\n constructor(message: string) {\n super(STATUS_CODE.NOT_FOUND, message, \"NOT_FOUND\");\n }\n}\n\nexport class InternalServerError extends APIError<STATUS_CODE.INTERNAL_SERVER_ERROR> {\n constructor(message = \"Internal server error\") {\n super(STATUS_CODE.INTERNAL_SERVER_ERROR, message, \"INTERNAL_SERVER_ERROR\");\n }\n}\n\nexport class BadRequestError extends APIError<STATUS_CODE.BAD_REQUEST> {\n constructor(message = \"Invalid JSON format\", details?: unknown) {\n super(STATUS_CODE.BAD_REQUEST, message, \"BAD_REQUEST\", details);\n }\n}\n\ntype Meta = { timestamp: string };\n\ntype ErrorDetail = {\n code: APIErrorCode;\n message: string;\n details?: unknown;\n};\n\nexport type SuccessPayload<T> = Compute<{\n statusCode: STATUS_CODE.SUCCESS;\n body: {\n cursor: string | null;\n data: T;\n meta: Meta;\n };\n}>;\n\nexport type ErrorPayload<\n statusCode extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS> = Exclude<\n STATUS_CODE,\n STATUS_CODE.SUCCESS\n >,\n> = Compute<{\n statusCode: statusCode;\n body: {\n meta: Meta;\n error: ErrorDetail;\n };\n}>;\n\nexport type Payload<T> = SuccessPayload<T> | ErrorPayload;\n\nexport function success<T>(args: { data: T; cursor?: string | null }): SuccessPayload<T> {\n const { data, cursor } = args;\n return {\n statusCode: STATUS_CODE.SUCCESS as const,\n body: {\n meta: { timestamp: new Date().toISOString() },\n cursor: cursor ?? null,\n data,\n },\n };\n}\n\n/**\n * Generic failure builder. Preserves the concrete status code when the input is an APIError.\n * If not an APIError, maps to INTERNAL_SERVER_ERROR. Zod & SyntaxError are mapped to BAD_REQUEST.\n */\nexport function failure<\n Code extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS> = Exclude<\n STATUS_CODE,\n STATUS_CODE.SUCCESS\n >,\n>(err: unknown): ErrorPayload<Code> {\n if (err instanceof APIError) {\n // Capture the exact status type from the error instance\n return handleAPIError(err) as ErrorPayload<Code>;\n }\n\n if (err instanceof SyntaxError) {\n return handleAPIError(new BadRequestError(err.message)) as ErrorPayload<Code>;\n }\n\n if (err instanceof z.ZodError) {\n return handleAPIError(handleZodError(err)) as ErrorPayload<Code>;\n }\n\n return handleAPIError(new InternalServerError()) as ErrorPayload<Code>;\n}\n\nfunction handleAPIError<Code extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS>>(\n error: APIError<Code>,\n): ErrorPayload<Code> {\n return {\n statusCode: error.statusCode,\n body: {\n meta: { timestamp: new Date().toISOString() },\n error: {\n code: error.code,\n message: error.message,\n ...(error.details && typeof error.details === \"object\" ? { details: error.details } : {}),\n },\n },\n };\n}\n\nexport function handleZodError(error: z.ZodError): ValidationError {\n const formattedErrors = error.issues.map((issue) => {\n const field = issue.path.join(\".\");\n let msg = issue.message;\n\n switch (issue.code) {\n case \"invalid_type\":\n if (issue.message.includes(\"received undefined\")) {\n msg = `${field} is required`;\n }\n break;\n case \"invalid_format\":\n msg = issue.format === \"regex\" ? issue.message : `${field} has an invalid format`;\n break;\n default:\n break;\n }\n\n return { field, issue: msg };\n });\n\n return new ValidationError(\"Validation failed\", formattedErrors);\n}\n","import \"reflect-metadata\";\nimport { generateDocument, type OpenAPIDocument } from \"openapi-metadata\";\nimport {\n ApiBody,\n ApiOperation,\n ApiParam,\n ApiProperty,\n ApiQuery,\n ApiResponse,\n ApiTags,\n} from \"openapi-metadata/decorators\";\nimport type { Address, Hex } from \"viem\";\nimport * as Payload from \"../Controllers/Payload.ts\";\n\nconst timestampExample = \"2024-01-01T12:00:00.000Z\";\nconst offerCursorExample = \"eyJvZmZzZXQiOjEwMH0\";\nconst obligationCursorExample =\n \"0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc\";\n\nconst offerExample = {\n offer: {\n obligation: {\n loan_token: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n collaterals: [\n {\n token: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n lltv: \"860000000000000000\",\n oracle: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\",\n },\n ],\n maturity: 1761922799,\n },\n buy: false,\n maker: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n assets: \"369216000000000000000000\",\n obligation_units: \"0\",\n obligation_shares: \"0\",\n start: 1761922790,\n expiry: 1761922799,\n price: \"2750000000000000000\",\n group: \"0x000000000000000000000000000000000000000000000000000000000008b8f4\",\n session: \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n callback: \"0x1111111111111111111111111111111111111111\",\n callback_data:\n \"0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000\",\n },\n // Additional API fields (inlined at top level)\n offer_hash: \"0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427\",\n obligation_id: \"0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc\",\n chain_id: 1,\n consumed: \"0\",\n takeable: \"369216000000000000000000\",\n block_number: 2942933377146801,\n root: \"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\",\n proof: [\n \"0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890\",\n \"0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba\",\n ],\n signature:\n \"0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400\",\n} as const;\n\nconst collectorsHealthExample = {\n name: \"offers\",\n chain_id: 1,\n block_number: 21345678,\n updated_at: timestampExample,\n lag: 0,\n status: \"live\",\n initialized: true,\n} as const;\n\nconst chainsHealthExample = {\n chain_id: 1,\n local_block_number: 21345678,\n remote_block_number: 21345690,\n updated_at: timestampExample,\n initialized: true,\n} as const;\n\nconst missingCollectorExample = {\n chain_id: 1,\n name: \"offers\",\n} as const;\n\n// Example for validate offer request\nconst validateOfferExample = {\n maker: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n assets: \"369216000000000000000000\",\n obligation_units: \"0\",\n obligation_shares: \"0\",\n price: \"2750000000000000000\",\n maturity: 1761922799,\n expiry: 1761922799,\n start: 1761922790,\n group: \"0x000000000000000000000000000000000000000000000000000000000008b8f4\",\n session: \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n buy: false,\n chain_id: 1,\n loan_token: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n collaterals: [\n {\n asset: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n oracle: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\",\n lltv: \"860000000000000000\",\n },\n ],\n callback: {\n address: \"0x1111111111111111111111111111111111111111\",\n data: \"0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000\",\n },\n} as const;\n\nconst routerStatusExample = {\n status: \"live\",\n initialized: true,\n missing_chains: [],\n missing_collectors: [],\n} as const;\n\nclass Meta {\n @ApiProperty({ type: \"string\", example: timestampExample })\n declare timestamp: string;\n}\n\nclass SuccessResponse {\n @ApiProperty({ type: () => Meta })\n declare meta: Meta;\n}\n\nclass ErrorResponse {\n @ApiProperty({ type: \"string\", enum: Payload.API_ERROR_CODES, example: \"VALIDATION_ERROR\" })\n declare code: string;\n\n @ApiProperty({\n type: \"string\",\n example: \"Limit must be greater than 0.\",\n })\n declare message: string;\n\n @ApiProperty({\n type: \"object\",\n example: [\n {\n field: \"limit\",\n issue: \"Limit must be greater than 0.\",\n },\n ],\n })\n declare details: unknown;\n}\n\nclass BadRequestResponse {\n @ApiProperty({ type: () => ErrorResponse })\n declare error: ErrorResponse;\n\n @ApiProperty({ type: () => Meta })\n declare meta: Meta;\n}\n\nclass CollateralResponse {\n @ApiProperty({ type: \"string\", example: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\" })\n declare token: Address;\n\n @ApiProperty({ type: \"string\", example: \"860000000000000000\" })\n declare lltv: string;\n\n @ApiProperty({ type: \"string\", example: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\" })\n declare oracle: Address;\n}\n\n// Classes for validate request (input format - uses asset, not token)\nclass ValidateCollateralRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].asset })\n declare asset: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].oracle })\n declare oracle: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].lltv })\n declare lltv: string;\n}\n\nclass ValidateCallbackRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.callback.address })\n declare address: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.callback.data })\n declare data: Hex;\n}\n\nclass AskResponse {\n @ApiProperty({ type: \"string\", example: \"1000000000000000000\" })\n declare price: string;\n}\n\nclass BidResponse {\n @ApiProperty({ type: \"string\", example: \"1000000000000000000\" })\n declare price: string;\n}\n\nclass ObligationOfferResponse {\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation.loan_token })\n declare loan_token: Address;\n\n @ApiProperty({\n type: () => [CollateralResponse],\n example: offerExample.offer.obligation.collaterals,\n })\n declare collaterals: CollateralResponse[];\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.obligation.maturity })\n declare maturity: number;\n}\n\nclass OfferDataResponse {\n @ApiProperty({ type: () => ObligationOfferResponse, example: offerExample.offer.obligation })\n declare obligation: ObligationOfferResponse;\n\n @ApiProperty({ type: \"boolean\", example: offerExample.offer.buy })\n declare buy: boolean;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.maker })\n declare maker: Address;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.assets })\n declare assets: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation_units })\n declare obligation_units: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation_shares })\n declare obligation_shares: string;\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.start })\n declare start: number;\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.expiry })\n declare expiry: number;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.price })\n declare price: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.group })\n declare group: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.session })\n declare session: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.callback })\n declare callback: Address;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.callback_data })\n declare callback_data: Hex;\n}\n\nclass OfferListItemResponse {\n @ApiProperty({ type: () => OfferDataResponse, example: offerExample.offer })\n declare offer: OfferDataResponse;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer_hash })\n declare offer_hash: Hex;\n\n @ApiProperty({ type: \"string\", example: offerExample.obligation_id })\n declare obligation_id: Hex;\n\n @ApiProperty({ type: \"number\", example: offerExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: offerExample.consumed })\n declare consumed: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.takeable })\n declare takeable: string;\n\n @ApiProperty({ type: \"number\", example: offerExample.block_number })\n declare block_number: number;\n\n @ApiProperty({ type: \"string\", nullable: true, example: offerExample.root })\n declare root: Hex | null;\n\n @ApiProperty({ type: [String], nullable: true, example: offerExample.proof })\n declare proof: Hex[] | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: offerExample.signature })\n declare signature: Hex | null;\n}\n\nclass ObligationResponse {\n @ApiProperty({\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n })\n declare id: Hex;\n\n @ApiProperty({ type: \"number\", example: 1 })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\" })\n declare loan_token: Address;\n\n @ApiProperty({ type: () => [CollateralResponse] })\n declare collaterals: CollateralResponse[];\n\n @ApiProperty({ type: \"number\", example: 1761922800 })\n declare maturity: number;\n\n @ApiProperty({ type: () => AskResponse })\n declare ask: AskResponse;\n\n @ApiProperty({ type: () => BidResponse })\n declare bid: BidResponse;\n}\nclass ObligationListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: obligationCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [ObligationResponse],\n description: \"List of obligations with takable offers.\",\n })\n declare data: ObligationResponse[];\n}\n\nclass ObligationSingleSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({ type: () => ObligationResponse, description: \"Obligation details.\" })\n declare data: ObligationResponse;\n}\n\nclass OfferListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [OfferListItemResponse],\n description: \"Offers matching the provided filters.\",\n example: [offerExample],\n })\n declare data: OfferListItemResponse[];\n}\n\nclass MissingCollectorResponse {\n @ApiProperty({ type: \"number\", example: missingCollectorExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: missingCollectorExample.name })\n declare name: string;\n}\n\nclass RouterStatusDataResponse {\n @ApiProperty({ type: \"string\", enum: [\"live\", \"syncing\"], example: routerStatusExample.status })\n declare status: \"live\" | \"syncing\";\n\n @ApiProperty({ type: \"boolean\", example: routerStatusExample.initialized })\n declare initialized: boolean;\n\n @ApiProperty({\n type: () => [Number],\n example: routerStatusExample.missing_chains,\n description: \"Configured chain ids missing initialization rows.\",\n })\n declare missing_chains: number[];\n\n @ApiProperty({\n type: () => [MissingCollectorResponse],\n example: routerStatusExample.missing_collectors,\n description: \"Collectors missing initialization rows.\",\n })\n declare missing_collectors: MissingCollectorResponse[];\n}\n\nclass RouterStatusSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => RouterStatusDataResponse,\n description: \"Aggregated router status.\",\n example: routerStatusExample,\n })\n declare data: RouterStatusDataResponse;\n}\n\nclass CollectorHealthResponse {\n @ApiProperty({ type: \"string\", example: collectorsHealthExample.name })\n declare name: string;\n\n @ApiProperty({ type: \"number\", example: collectorsHealthExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"number\", nullable: true, example: collectorsHealthExample.block_number })\n declare block_number: number | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: collectorsHealthExample.updated_at })\n declare updated_at: string | null;\n\n @ApiProperty({ type: \"number\", nullable: true, example: collectorsHealthExample.lag })\n declare lag: number | null;\n\n @ApiProperty({\n type: \"string\",\n enum: [\"live\", \"lagging\", \"unknown\"],\n example: collectorsHealthExample.status,\n })\n declare status: \"live\" | \"lagging\" | \"unknown\";\n\n @ApiProperty({ type: \"boolean\", example: collectorsHealthExample.initialized })\n declare initialized: boolean;\n}\n\nclass CollectorsHealthSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => [CollectorHealthResponse],\n description: \"Collectors health details and sync status.\",\n example: [collectorsHealthExample],\n })\n declare data: CollectorHealthResponse[];\n}\n\nclass ChainHealthResponse {\n @ApiProperty({ type: \"number\", example: chainsHealthExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({\n type: \"number\",\n nullable: true,\n example: chainsHealthExample.local_block_number,\n })\n declare local_block_number: number | null;\n\n @ApiProperty({ type: \"number\", nullable: true, example: chainsHealthExample.remote_block_number })\n declare remote_block_number: number | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: chainsHealthExample.updated_at })\n declare updated_at: string | null;\n\n @ApiProperty({ type: \"boolean\", example: chainsHealthExample.initialized })\n declare initialized: boolean;\n}\n\nclass ChainsHealthSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => [ChainHealthResponse],\n description: \"Latest processed block per chain.\",\n example: [chainsHealthExample],\n })\n declare data: ChainHealthResponse[];\n}\n\nclass ValidateOfferRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.maker })\n declare maker: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.assets })\n declare assets: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.obligation_units, required: false })\n declare obligation_units: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.obligation_shares, required: false })\n declare obligation_shares: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.price })\n declare price: string;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.maturity })\n declare maturity: number;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.expiry })\n declare expiry: number;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.start })\n declare start: number;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.group })\n declare group: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.session })\n declare session: string;\n\n @ApiProperty({ type: \"boolean\", example: validateOfferExample.buy })\n declare buy: boolean;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.loan_token })\n declare loan_token: Address;\n\n @ApiProperty({\n type: () => [ValidateCollateralRequest],\n example: validateOfferExample.collaterals,\n })\n declare collaterals: ValidateCollateralRequest[];\n\n @ApiProperty({ type: () => ValidateCallbackRequest, example: validateOfferExample.callback })\n declare callback: ValidateCallbackRequest;\n}\n\nclass ValidateOffersRequest {\n @ApiProperty({\n type: () => [ValidateOfferRequest],\n description: \"Array of offers in snake_case format. Required, non-empty.\",\n required: true,\n })\n declare offers: ValidateOfferRequest[];\n}\n\nclass ValidationSuccessDataResponse {\n @ApiProperty({\n type: \"string\",\n description: \"Unsigned payload: version (1B) + gzip(offers) + root (32B).\",\n example: \"0x01789c...\",\n })\n declare payload: Hex;\n\n @ApiProperty({\n type: \"string\",\n description: \"Merkle tree root to sign with EIP-191.\",\n example: \"0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427\",\n })\n declare root: Hex;\n}\n\nclass ValidationSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => ValidationSuccessDataResponse,\n description: \"Payload and root for client-side signing.\",\n })\n declare data: ValidationSuccessDataResponse;\n}\n\nclass ValidationIssueResponse {\n @ApiProperty({\n type: \"number\",\n description: \"0-indexed position of the failed offer in the request array.\",\n example: 0,\n })\n declare index: number;\n\n @ApiProperty({\n type: \"string\",\n description: \"Gatekeeper rule name that rejected the offer.\",\n example: \"no_buy\",\n })\n declare rule: string;\n\n @ApiProperty({\n type: \"string\",\n description: \"Human-readable rejection reason.\",\n example: \"Buy offers are not supported\",\n })\n declare message: string;\n}\n\nclass ValidationFailureDataResponse {\n @ApiProperty({\n type: () => [ValidationIssueResponse],\n description: \"List of validation issues. Returned when any offer fails validation.\",\n })\n declare issues: ValidationIssueResponse[];\n}\n\nclass ValidationFailureResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => ValidationFailureDataResponse,\n description: \"List of validation issues. Returned when any offer fails validation.\",\n })\n declare data: ValidationFailureDataResponse;\n}\n\nclass BookLevelResponse {\n @ApiProperty({ type: \"string\", example: \"2750000000000000000\" })\n declare price: string;\n\n @ApiProperty({ type: \"string\", example: \"369216000000000000000000\" })\n declare assets: string;\n\n @ApiProperty({ type: \"number\", example: 5 })\n declare count: number;\n}\n\nconst positionExample = {\n chain_id: 1,\n contract: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n user: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n reserved: \"200000000000000000000\",\n block_number: 21345678,\n} as const;\n\nclass PositionListItemResponse {\n @ApiProperty({ type: \"number\", example: positionExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: positionExample.contract })\n declare contract: string;\n\n @ApiProperty({ type: \"string\", example: positionExample.user })\n declare user: string;\n\n @ApiProperty({ type: \"string\", example: positionExample.reserved })\n declare reserved: string;\n\n @ApiProperty({ type: \"number\", example: positionExample.block_number })\n declare block_number: number;\n}\n\nclass PositionListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [PositionListItemResponse],\n description: \"User positions with reserved balances from active offers.\",\n example: [positionExample],\n })\n declare data: PositionListItemResponse[];\n}\n\nclass BookListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [BookLevelResponse],\n description: \"Aggregated book levels grouped by computed price.\",\n })\n declare data: BookLevelResponse[];\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class BooksController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/books/{obligationId}/{side}\",\n summary: \"Get aggregated book\",\n description:\n \"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).\",\n })\n @ApiParam({\n name: \"obligationId\",\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n description: \"Obligation id.\",\n })\n @ApiParam({\n name: \"side\",\n type: \"string\",\n enum: [\"buy\", \"sell\"],\n example: \"buy\",\n description: \"Book side (buy or sell).\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of price levels to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: BookListResponse })\n async getBook() {}\n}\n\n@ApiTags(\"Make\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class ValidateController {\n @ApiOperation({\n methods: [\"post\"],\n path: \"/v1/validate\",\n summary: \"Validate offers\",\n description:\n \"Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure.\",\n })\n @ApiBody({ type: ValidateOffersRequest })\n @ApiResponse({ status: 200, description: \"Success\", type: ValidationSuccessResponse })\n @ApiResponse({ status: 200, description: \"Validation issues\", type: ValidationFailureResponse })\n async validateOffers() {}\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class OffersController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/offers\",\n summary: \"List all offers\",\n description:\n \"Returns offers. Provide either `obligation_id` + `side` (order book) or `maker` (by maker address).\",\n })\n @ApiQuery({\n name: \"side\",\n type: \"string\",\n required: false,\n enum: [\"buy\", \"sell\"],\n example: \"buy\",\n description: \"Side of the offer. Required when using obligation_id.\",\n })\n @ApiQuery({\n name: \"obligation_id\",\n type: \"string\",\n required: false,\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n description: \"Obligation id used to filter offers. Required when not using maker.\",\n })\n @ApiQuery({\n name: \"maker\",\n type: \"string\",\n required: false,\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n description: \"Maker address to filter offers by. Alternative to obligation_id + side.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of offers to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: OfferListResponse })\n async getOffers() {}\n}\n\n@ApiTags(\"System\")\nexport class HealthController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health\",\n summary: \"Retrieve global health\",\n description: \"Returns the aggregated status of the router.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: RouterStatusSuccessResponse })\n async getRouterStatus() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health/collectors\",\n summary: \"Retrieve collectors health\",\n description: \"Returns the latest block numbers processed by collectors and their sync status.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: CollectorsHealthSuccessResponse })\n async getCollectorsHealth() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health/chains\",\n summary: \"Retrieve chains health\",\n description: \"Returns the latest block that can be processed by collectors for each chain.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ChainsHealthSuccessResponse })\n async getChainsHealth() {}\n}\n\nconst maturitiesExample = {\n end_of_month: 1738335600,\n end_of_next_month: 1740754800,\n};\n\nconst chainConfigExample = {\n chain_id: 505050505,\n contracts: {\n mempool: \"0xD946246695A9259F3B33a78629026F61B3Ab40aF\",\n },\n maturities: maturitiesExample,\n};\n\nclass ConfigContractsResponse {\n @ApiProperty({ type: \"string\", example: chainConfigExample.contracts.mempool })\n declare mempool: string;\n}\n\nclass MaturitiesResponse {\n @ApiProperty({\n type: \"number\",\n description: \"Unix timestamp for end of current month maturity (last Friday 15:00 UTC).\",\n example: maturitiesExample.end_of_month,\n })\n declare end_of_month: number;\n\n @ApiProperty({\n type: \"number\",\n description: \"Unix timestamp for end of next month maturity (last Friday 15:00 UTC).\",\n example: maturitiesExample.end_of_next_month,\n })\n declare end_of_next_month: number;\n}\n\nclass ConfigDataResponse {\n @ApiProperty({ type: \"number\", example: chainConfigExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: () => ConfigContractsResponse })\n declare contracts: ConfigContractsResponse;\n\n @ApiProperty({\n type: () => MaturitiesResponse,\n description: \"Supported maturity timestamps. Offers must use one of these values.\",\n example: chainConfigExample.maturities,\n })\n declare maturities: MaturitiesResponse;\n}\n\nclass ConfigSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [ConfigDataResponse],\n description: \"Array of chain configurations for all indexed chains.\",\n example: [chainConfigExample],\n })\n declare data: ConfigDataResponse[];\n}\n\n@ApiTags(\"System\")\nexport class ConfigController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/config\",\n summary: \"Get router configuration\",\n description:\n \"Returns chain configurations including contract addresses and supported maturity timestamps.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ConfigSuccessResponse })\n async getConfig() {}\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class ObligationsController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/obligations\",\n summary: \"List all obligations\",\n description:\n \"Returns a list of obligations with their current best ask and bid. Obligations are sorted by their id in ascending order by default.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: obligationCursorExample,\n description: \"Obligation id cursor for pagination.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of obligations to return.\",\n })\n @ApiQuery({\n name: \"chain\",\n type: \"number\",\n required: false,\n example: 1,\n description: \"Filter by chain ID.\",\n })\n @ApiQuery({\n name: \"loan_token\",\n type: \"string\",\n required: false,\n example: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n description: \"Filter by loan token address.\",\n })\n @ApiQuery({\n name: \"collateral_token\",\n type: \"string\",\n required: false,\n example: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n description: \"Filter by collateral token (matches any collateral in the obligation).\",\n })\n @ApiQuery({\n name: \"maturity\",\n type: \"number\",\n required: false,\n example: 1761922800,\n description: \"Filter by exact maturity timestamp (unix seconds).\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ObligationListResponse })\n async getObligations() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/obligations/{obligationId}\",\n summary: \"Get an obligation\",\n description: \"Returns an obligation by its id.\",\n })\n @ApiParam({\n name: \"obligationId\",\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n description: \"Obligation id.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ObligationSingleSuccessResponse })\n async getObligation() {}\n}\n\n@ApiTags(\"Make\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class UsersController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/users/{userAddress}/positions\",\n summary: \"Get user positions\",\n description:\n \"Returns positions for a user with reserved balance. The reserved balance is the amount locked by active offers (max lot upper - offset - consumed).\",\n })\n @ApiParam({\n name: \"userAddress\",\n type: \"string\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n description: \"User address to get positions for.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of positions to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: PositionListResponse })\n async getUserPositions() {}\n}\n\nexport type RuleInfo = { name: string; description: string };\n\nexport type OpenApiOptions = {\n rules?: RuleInfo[];\n};\n\nexport const OpenApi = async (options: OpenApiOptions = {}): Promise<OpenAPIDocument> => {\n const document = await generateDocument({\n controllers: [\n BooksController,\n ConfigController,\n OffersController,\n ObligationsController,\n HealthController,\n UsersController,\n ValidateController,\n ],\n document: {\n openapi: \"3.1.0\",\n info: {\n title: \"Router API\",\n version: \"1.0.0\",\n description: \"API for the Morpho Router\",\n },\n servers: [\n {\n url: \"https://router.morpho.dev\",\n description: \"Production server\",\n },\n {\n url: \"http://localhost:7891\",\n description: \"Local development server\",\n },\n ],\n tags: [\n {\n name: \"Markets\",\n description:\n \"Read-only endpoints to discover markets, order books and fetch current offers.\",\n },\n {\n name: \"Make\",\n description: \"Utilities to ease making offers.\",\n },\n {\n name: \"System\",\n description: \"Router configuration and health monitoring.\",\n },\n ],\n },\n });\n\n if (options.rules && options.rules.length > 0) {\n const rulesDescription = options.rules\n .map((rule) => `- **${rule.name}**: ${rule.description}`)\n .join(\"\\n\");\n\n const validatePath = document.paths?.[\"/v1/validate\"];\n if (validatePath && \"post\" in validatePath && validatePath.post) {\n validatePath.post.description = `Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure.\\n\\n**Available validation rules:**\\n${rulesDescription}`;\n }\n }\n\n return document;\n};\n","import type { Address } from \"viem\";\nimport type { Chain } from \"#core\";\nimport type { getByUser } from \"#database/domains/Positions.ts\";\n\nexport type PositionResponse = {\n chain_id: Chain.Id;\n contract: Address;\n user: Address;\n reserved: string;\n block_number: number;\n};\n\nexport type PositionWithReserved = getByUser.PositionWithReserved;\n\n/**\n * Creates a `PositionResponse` from a `PositionWithReserved`.\n * @param position - {@link PositionWithReserved}\n * @returns The created `PositionResponse`. {@link PositionResponse}\n */\nexport function from(position: PositionWithReserved): PositionResponse {\n return {\n chain_id: position.chainId,\n contract: position.contract,\n user: position.user,\n reserved: position.reserved.toString(),\n block_number: position.blockNumber,\n };\n}\n","import type { Address, Hex } from \"viem\";\nimport * as z from \"zod\";\n\nconst MAX_LIMIT = 100;\nconst DEFAULT_LIMIT = 20;\n\n/** Validate cursor is a valid base64url-encoded JSON object.\n * Domain layer handles semantic validation of cursor fields. */\nfunction isValidBase64urlJson(val: string): boolean {\n try {\n const decoded = Buffer.from(val, \"base64url\").toString(\"utf8\");\n JSON.parse(decoded);\n return true;\n } catch {\n return false;\n }\n}\n\nconst PaginationQueryParams = z.object({\n cursor: z\n .string()\n .optional()\n .refine(\n (val) => {\n if (!val) return true; // Optional field\n // Accept any valid base64url-encoded JSON object\n // Domain layer handles semantic validation of cursor fields\n return isValidBase64urlJson(val);\n },\n {\n message: \"Invalid cursor format. Must be a valid base64url-encoded cursor object\",\n },\n )\n .meta({\n description: \"Pagination cursor in base64url-encoded format\",\n example:\n \"eyJzaWRlIjoic2VsbCIsImN1cnJlbnRQcmljZSI6IjEwMDAwMDAwMDAwMDAwMDAwMDAiLCJibG9ja051bWJlciI6MSwiYXNzZXRzIjoiMTAwMDAwMDAwMDAwMDAwMDAwMCIsImhhc2giOiIweGRmZDY4NTllM2UwODJkMTkzODlhMWFlYzFiZGFkN2U4ZDkyZDk2YjFhYTc5NDBkYTkxYTMxMjVkMzFlM2JlNWIiLCJ0b3RhbFJldHVybmVkIjoxMCwibm93IjoxNjAwMDAwMDAwfQ\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(MAX_LIMIT, {\n message: `Limit cannot exceed ${MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${MAX_LIMIT}. Default: ${DEFAULT_LIMIT}`,\n example: 10,\n }),\n});\n\nexport const GetOffersQueryParams = z\n .object({\n ...PaginationQueryParams.shape,\n side: z.enum([\"buy\", \"sell\"]).optional().meta({\n description: \"Side of the offer. Required when using obligation_id.\",\n example: \"buy\",\n }),\n obligation_id: z\n .string()\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .optional()\n .meta({\n description: \"Offers obligation id. Required when not using maker.\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n maker: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Maker must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .optional()\n .meta({\n description: \"Maker address to filter offers by. Alternative to obligation_id + side.\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n }),\n })\n .superRefine((val, ctx) => {\n const hasObligation = val.obligation_id !== undefined;\n const hasSide = val.side !== undefined;\n const hasMaker = val.maker !== undefined;\n\n if (hasMaker && (hasObligation || hasSide)) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Cannot use both maker and obligation_id/side parameters\",\n });\n return;\n }\n\n if (hasMaker) {\n return;\n }\n\n if (!hasObligation || !hasSide) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Must provide either maker or both obligation_id and side\",\n });\n }\n });\n\nexport const GetObligationsQueryParams = z.object({\n ...PaginationQueryParams.shape,\n cursor: z.string().optional().meta({\n description: \"Obligation id cursor\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n chain: z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Chain must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10))\n .optional()\n .meta({ description: \"Filter by chain ID\", example: \"1\" }),\n loan_token: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Loan token must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .optional()\n .meta({\n description: \"Filter by loan token address\",\n example: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n }),\n collateral_token: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Collateral token must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .optional()\n .meta({\n description: \"Filter by collateral token (matches any collateral in the obligation)\",\n example: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n }),\n maturity: z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Maturity must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10))\n .optional()\n .meta({\n description: \"Filter by exact maturity timestamp (unix seconds)\",\n example: \"1761922800\",\n }),\n});\n\nexport const GetObligationParams = z.object({\n obligation_id: z\n .string({ error: \"Obligation id is required and must be a valid 32-byte hex string\" })\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .meta({\n description: \"Obligation id\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n});\n\n/** Validate a book cursor format: {side, lastPrice, offersCursor} */\nfunction isValidBookCursor(cursorString: string): boolean {\n const isNumericString = (value: unknown): value is string =>\n typeof value === \"string\" && /^-?\\d+$/.test(value);\n\n try {\n const v = JSON.parse(Buffer.from(cursorString, \"base64url\").toString(\"utf8\"));\n return (\n (v?.side === \"buy\" || v?.side === \"sell\") &&\n isNumericString(v?.lastPrice) &&\n (v?.offersCursor === null || typeof v?.offersCursor === \"string\")\n );\n } catch {\n return false;\n }\n}\n\nconst BookPaginationQueryParams = z.object({\n cursor: z\n .string()\n .optional()\n .refine(\n (value) => {\n if (!value) return true; // Optional field\n return isValidBookCursor(value);\n },\n {\n message: \"Invalid cursor format. Must be a valid base64url-encoded book cursor object\",\n },\n )\n .meta({\n description: \"Pagination cursor in base64url-encoded format for book levels\",\n example:\n \"eyJzaWRlIjoiYnV5IiwibGFzdFJhdGUiOiIxMDAwMDAwMDAwMDAwMDAwMDAwIiwib2ZmZXJzQ3Vyc29yIjpudWxsfQ\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(MAX_LIMIT, {\n message: `Limit cannot exceed ${MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${MAX_LIMIT}. Default: ${DEFAULT_LIMIT}`,\n example: 10,\n }),\n});\n\nconst HealthQueryParams = z.object({\n strict: z\n .enum([\"true\", \"false\", \"1\", \"0\"])\n .transform((value) => value === \"true\" || value === \"1\")\n .optional()\n .meta({\n description: \"Enable strict mode to fail health checks when initialization is incomplete.\",\n example: \"true\",\n }),\n});\n\nexport const GetBookParams = z.object({\n ...BookPaginationQueryParams.shape,\n obligation_id: z\n .string({ error: \"Obligation id is required and must be a valid 32-byte hex string\" })\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .meta({\n description: \"Obligation id\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n side: z.enum([\"buy\", \"sell\"]).meta({\n description: \"Side of the book (buy or sell).\",\n example: \"buy\",\n }),\n});\n\nconst ValidateOffersBody = z\n .object({\n offers: z.array(z.unknown()).min(1, { message: \"'offers' must contain at least 1 offer\" }),\n })\n .strict();\n\nexport const GetUserPositionsParams = z.object({\n ...PaginationQueryParams.shape,\n user_address: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"User address must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .meta({\n description: \"User address to get positions for\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n }),\n});\n\nconst schemas = {\n get_health: HealthQueryParams,\n get_health_collectors: HealthQueryParams,\n get_health_chains: HealthQueryParams,\n get_offers: GetOffersQueryParams,\n get_obligations: GetObligationsQueryParams,\n get_obligation: GetObligationParams,\n get_book: GetBookParams,\n validate_offers: ValidateOffersBody,\n get_user_positions: GetUserPositionsParams,\n} as const;\n\ntype Action = keyof typeof schemas;\n\nexport function parse<A extends Action>(action: A, query: unknown): z.infer<(typeof schemas)[A]> {\n return schemas[action].parse(query) as z.infer<(typeof schemas)[A]>;\n}\n\nexport function safeParse<A extends Action>(\n action: A,\n query: unknown,\n error?: z.core.$ZodErrorMap<z.core.$ZodIssue>,\n): z.ZodSafeParseResult<z.infer<(typeof schemas)[A]>> {\n return schemas[action].safeParse(query, {\n error,\n }) as z.ZodSafeParseResult<z.infer<(typeof schemas)[A]>>;\n}\n","export * as BookResponse from \"./BookResponse.ts\";\nexport * from \"./health.ts\";\nexport * as ObligationResponse from \"./ObligationResponse.ts\";\nexport * as OfferResponse from \"./OfferResponse.ts\";\nexport * from \"./openapi.ts\";\nexport * as PositionResponse from \"./PositionResponse.ts\";\nexport { parse, safeParse } from \"./requests.ts\";\n","import createOpenApiFetchClient, { type Client as OpenApiFetchClient } from \"openapi-fetch\";\nimport type { Address, Hex } from \"viem\";\nimport { type Compute, Maturity, Obligation, Offer, Quote } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type * as GeneratedApiSchema from \"../api/Schema/generated/swagger.d.ts\";\n\ntype RouterClientConfig = {\n /** The URL of the router. */\n readonly url: URL;\n /** The default headers to use for each request. */\n readonly headers: Headers;\n};\n\nexport type Client = Compute<\n RouterClientConfig & {\n /**\n * Get offers from the router.\n * @param parameters - {@link getOffers.Parameters}\n * @returns The offers with pagination cursor. {@link getOffers.ReturnType}\n * @throws If the request fails - {@link getOffers.ErrorType}\n *\n * @example\n * ```ts\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * const { offers, cursor } = await router.getOffers({ side: \"buy\", obligationId: \"0xa1c...d2f\" });\n * console.log(offers);\n * ```\n */\n getOffers: (parameters: getOffers.Parameters) => Promise<getOffers.ReturnType>;\n\n /**\n * Get obligations from the router.\n * @param parameters - {@link getObligations.Parameters}\n * @returns The obligations with pagination cursor. {@link getObligations.ReturnType}\n * @throws If the request fails - {@link getObligations.ErrorType}\n *\n * @example\n * ```ts\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * const { obligations, cursor } = await router.getObligations();\n * console.log(obligations[0].id()); // 0x123...456\n * ```\n */\n getObligations: (parameters?: getObligations.Parameters) => Promise<getObligations.ReturnType>;\n }\n>;\n\nexport type ConnectOptions = {\n /** The URL of the router to interact with.\n * @default \"https://router.morpho.dev\"\n */\n url?: string;\n /** The API key to use for the router API. */\n apiKey?: string;\n /** The default headers to use for each request. */\n headers?: Headers;\n};\n\n/**\n * Creates an instance of a router client.\n * @constructor\n * @param parameters - {@link connect.Parameters}\n * @returns A Router Client. {@link connect.ReturnType}\n *\n * @example\n * ```typescript\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * ```\n */\nexport function connect(parameters?: connect.Parameters): connect.ReturnType {\n const u = new URL(parameters?.url || \"https://router.morpho.dev\");\n if (u.protocol !== \"http:\" && u.protocol !== \"https:\") throw new InvalidUrlError(u.toString());\n\n const headers = parameters?.headers ?? new Headers();\n headers.set(\"Content-Type\", \"application/json\");\n parameters?.apiKey !== undefined ? headers.set(\"X-API-Key\", parameters.apiKey) : null;\n\n const config: RouterClientConfig = { url: u, headers };\n\n const apiClient = createOpenApiFetchClient<GeneratedApiSchema.paths>({\n baseUrl: config.url.toString(),\n headers: config.headers,\n });\n\n return {\n ...config,\n getOffers: (parameters) => getOffers(apiClient, parameters),\n getObligations: (parameters) => getObligations(apiClient, parameters),\n };\n}\n\nexport declare namespace connect {\n export type Parameters = ConnectOptions;\n export type ReturnType = Client;\n export type ErrorType = InvalidUrlError;\n}\n\nexport async function getOffers(\n apiClient: OpenApiFetchClient<GeneratedApiSchema.paths>,\n parameters: getOffers.Parameters,\n): Promise<getOffers.ReturnType> {\n const { data, error, response } = await apiClient.GET(\"/v1/offers\", {\n params: {\n query: {\n side: parameters.side,\n obligation_id: parameters.obligationId,\n cursor: parameters.cursor,\n limit: parameters.limit,\n },\n },\n });\n\n if (error !== undefined) {\n switch (response.status) {\n case 401:\n throw new HttpUnauthorizedError();\n case 403:\n throw new HttpForbiddenError();\n case 429:\n throw new HttpRateLimitError();\n }\n throw new HttpGetApiFailedError(`GET request returned ${response.status}`, {\n details: JSON.stringify(error),\n });\n }\n\n const offers =\n data?.data.map((item) => {\n const { root, proof, signature, offer: offerData } = item;\n // Transform new API structure (with nested offer object) to Offer.fromSnakeCase format\n const offer = Offer.fromSnakeCase({\n maker: offerData.maker as Address,\n assets: offerData.assets,\n obligation_units: offerData.obligation_units,\n obligation_shares: offerData.obligation_shares,\n price: offerData.price,\n maturity: Maturity.from(offerData.obligation.maturity),\n expiry: offerData.expiry,\n start: offerData.start,\n group: offerData.group,\n session: offerData.session,\n buy: offerData.buy,\n chain_id: item.chain_id,\n loan_token: offerData.obligation.loan_token as Address,\n collaterals: offerData.obligation.collaterals.map((collateral) => ({\n asset: collateral.token as Address,\n oracle: collateral.oracle as Address,\n lltv: collateral.lltv,\n })),\n callback: {\n address: offerData.callback as Address,\n data: offerData.callback_data as Hex,\n },\n });\n\n return {\n ...offer,\n hash: item.offer_hash as Hex,\n consumed: BigInt(item.consumed),\n takeable: BigInt(item.takeable),\n blockNumber: Number(item.block_number),\n root: (root as Hex) || undefined,\n proof: (proof as Hex[]) || undefined,\n signature: signature ? (signature as Hex) : undefined,\n };\n }) ?? [];\n\n return {\n cursor: data?.cursor ?? null,\n offers,\n };\n}\n\nexport declare namespace getOffers {\n export type Parameters = {\n /** The desired side of the match: 'buy' if you want to buy, 'sell' if you want to sell */\n side: \"buy\" | \"sell\";\n /** The offers obligation id */\n obligationId: Hex;\n /** Pagination cursor in base64url-encoded format */\n cursor?: string;\n /** Maximum number of offers to return. @default 20 */\n limit?: number;\n };\n\n export type ReturnType = {\n offers: Compute<\n Offer.Offer & {\n hash: Hex;\n blockNumber: number;\n consumed: bigint;\n takeable: bigint;\n } & {\n /** 32-byte merkle root. */\n root?: Hex;\n /** Sibling hashes for the merkle proof. */\n proof?: Hex[];\n /** Offer signature from the Merkle tree. */\n signature?: Hex;\n }\n >[];\n /** The pagination cursor. */\n cursor: string | null;\n };\n\n export type ErrorType = GetApiErrorType;\n}\n\nexport async function getObligations(\n apiClient: OpenApiFetchClient<GeneratedApiSchema.paths>,\n parameters?: getObligations.Parameters,\n): Promise<getObligations.ReturnType> {\n const { data, error, response } = await apiClient.GET(\"/v1/obligations\", {\n params: {\n query: {\n cursor: parameters?.cursor,\n limit: parameters?.limit,\n chain: parameters?.chainId,\n loan_token: parameters?.loanToken,\n collateral_token: parameters?.collateralToken,\n maturity: parameters?.maturity,\n },\n },\n });\n\n if (error !== undefined) {\n switch (response.status) {\n case 401:\n throw new HttpUnauthorizedError();\n case 403:\n throw new HttpForbiddenError();\n case 429:\n throw new HttpRateLimitError();\n }\n throw new HttpGetApiFailedError(`GET request returned ${response.status}`, {\n details: JSON.stringify(error),\n });\n }\n\n const obligations =\n data?.data.map((item) => {\n const obligation = Obligation.fromSnakeCase({\n chain_id: item.chain_id,\n loan_token: item.loan_token as Address,\n collaterals: item.collaterals.map((collateral) => ({\n asset: collateral.token as Address,\n oracle: collateral.oracle as Address,\n lltv: collateral.lltv,\n })),\n maturity: Maturity.from(item.maturity),\n });\n\n const { obligationId: _, ...returned } = {\n id: () => Obligation.id(obligation),\n ...obligation,\n ...Quote.fromSnakeCase({ obligation_id: item.id as Hex, ask: item.ask, bid: item.bid }),\n };\n return returned;\n }) ?? [];\n\n return {\n cursor: data?.cursor ?? null,\n obligations,\n };\n}\n\nexport declare namespace getObligations {\n export type Parameters = {\n /** Pagination cursor is a 32-byte hex string. */\n cursor?: Hex;\n /** Maximum number of obligations to return. @default 20 */\n limit?: number;\n /** Filter by chain ID. */\n chainId?: number;\n /** Filter by loan token address. */\n loanToken?: Address;\n /** Filter by collateral token (matches any collateral in the obligation). */\n collateralToken?: Address;\n /** Filter by exact maturity timestamp (unix seconds). */\n maturity?: number;\n };\n\n export type ReturnType = {\n obligations: Compute<\n {\n /** The obligation id. Uses {@link Obligation.id} to calculate the id.*/\n id: () => Hex;\n } & Obligation.Obligation &\n Omit<Quote.Quote, \"obligationId\">\n >[];\n /** The pagination cursor. */\n cursor: string | null;\n };\n\n export type ErrorType = GetApiErrorType;\n}\n\ntype GetApiErrorType =\n | HttpGetApiFailedError\n | HttpUnauthorizedError\n | HttpForbiddenError\n | HttpRateLimitError;\n\nexport class InvalidUrlError extends Errors.BaseError {\n override name = \"Router.InvalidUrlError\";\n constructor(url: string) {\n super(`URL \"${url}\" is not http/https.`);\n }\n}\n\nexport class HttpUnauthorizedError extends Errors.BaseError {\n override name = \"Router.HttpUnauthorizedError\";\n constructor() {\n super(\"Unauthorized.\", {\n metaMessages: [\"Ensure that an API key is provided.\"],\n });\n }\n}\n\nexport class HttpForbiddenError extends Errors.BaseError {\n override name = \"Router.HttpForbiddenError\";\n constructor() {\n super(\"Forbidden.\", {\n metaMessages: [\"Ensure that the API key is valid.\"],\n });\n }\n}\n\nexport class HttpRateLimitError extends Errors.BaseError {\n override name = \"Router.HttpRateLimitError\";\n constructor() {\n super(\"Rate limit exceeded.\", {\n metaMessages: [\n \"The number of allowed requests has been exceeded. You must wait for the rate limit to reset.\",\n ],\n });\n }\n}\n\nexport class HttpGetApiFailedError extends Errors.BaseError {\n override name = \"Router.HttpGetApiFailedError\";\n constructor(message: string, { details }: { details?: string } = {}) {\n super(message, {\n metaMessages: [details],\n });\n }\n}\n","/**\n * A validation rule.\n */\nexport type Rule<T, Name extends string = string> =\n | { kind: \"single\"; name: Name; description: string; run: Single<T, Name> }\n | { kind: \"batch\"; name: Name; description: string; run: Batch<T, Name> };\n\nexport type RuleNames<Rules extends readonly { name: string }[]> = Rules[number][\"name\"];\n\n/**\n * A single item validation rule.\n * @param item - The item to validate.\n * @returns The issue that was found. If the item is valid, this will be undefined.\n */\nexport type Single<T, RuleName extends string> = (\n item: T,\n) =>\n | Omit<Issue<T, RuleName>, \"ruleName\" | \"item\">\n | undefined\n | Promise<Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>;\n\n/**\n * A batch item validation rule.\n * @param items - The items to validate.\n * @returns A map of the items to the issue that was found.\n */\nexport type Batch<T, RuleName extends string> = (\n items: T[],\n) =>\n | Map<number, Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>\n | Promise<Map<number, Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>>;\n\n/**\n * Create a validation rule iterating over a single item at a time.\n * @param name - The name of the rule.\n * @param description - A human-readable description of the rule.\n * @param run - The function that validates the rule.\n * @returns The created rule.\n */\nexport function single<Name extends string, T>(\n name: Name,\n description: string,\n run: Single<T, Name>,\n): Rule<T, Name> {\n return { kind: \"single\", name, description, run } as const satisfies Rule<T, Name>;\n}\n\n/**\n * Create a validation rule iterating over a batch of items at a time.\n * @param name - The name of the rule.\n * @param description - A human-readable description of the rule.\n * @param run - The function that validates the rule.\n * @returns The created rule.\n */\nexport function batch<Name extends string, T>(\n name: Name,\n description: string,\n run: Batch<T, Name>,\n): Rule<T, Name> {\n return { kind: \"batch\", name, description, run } as const satisfies Rule<T, Name>;\n}\n\n/**\n * A validation issue.\n */\nexport type Issue<T, RuleName extends string = string> = {\n /** The name of the rule that caused the issue. */\n ruleName: RuleName;\n /** The message of the issue. */\n message: string;\n /** The item that was not valid. */\n item: T;\n};\n\n/**\n * The result of a validation.\n */\nexport type Result<T, RuleName extends string = string> = {\n /** The items that were valid. */\n valid: T[];\n /** The reports of the failed validations. */\n issues: Issue<T, RuleName>[];\n};\n\nexport async function run<\n T,\n Name extends string,\n Rules extends readonly Rule<T, Name>[],\n>(parameters: {\n items: T[];\n rules: Rules;\n chunkSize?: number;\n}): Promise<Result<T, RuleNames<Rules>>> {\n const { items, rules, chunkSize } = parameters;\n\n const issues: Issue<T, RuleNames<Rules>>[] = [];\n let validItems: T[] = items.slice();\n\n for (const rule of rules) {\n if (validItems.length === 0) return { valid: [], issues };\n\n const indicesToRemove: Set<number> = new Set();\n if (rule.kind === \"single\") {\n for (let i = 0; i < validItems.length; i++) {\n const item = validItems[i]!;\n const issue = await rule.run(item);\n if (issue) {\n issues.push({ ...issue, ruleName: rule.name, item });\n indicesToRemove.add(i);\n }\n }\n } else if (rule.kind === \"batch\") {\n const exec = async (slice: T[], offset: number) => {\n const map = await rule.run(slice);\n for (let i = 0; i < slice.length; i++) {\n const issue = map.get(i);\n if (issue !== undefined) {\n issues.push({ ...issue, ruleName: rule.name, item: slice[i]! });\n indicesToRemove.add(offset + i);\n }\n }\n };\n\n if (!chunkSize) await exec(validItems, 0);\n else {\n for (let i = 0; i < validItems.length; i += chunkSize) {\n await exec(validItems.slice(i, i + chunkSize), i);\n }\n }\n }\n\n validItems = validItems.filter((_, i) => !indicesToRemove.has(i));\n }\n\n return {\n valid: validItems,\n issues,\n };\n}\n","import type { Address } from \"viem\";\nimport * as Callback from \"../core/Callback.ts\";\nimport * as Chain from \"../core/Chain.ts\";\nimport * as Maturity from \"../core/Maturity.ts\";\n\nexport type GateConfig = {\n callbacks?: CallbackConfig[];\n maturities?: Maturity.MaturityType[];\n};\n\nexport type CallbackConfig =\n | {\n type: Callback.CallbackType.BuyVaultV1Callback;\n addresses: Address[];\n vaultFactories: Address[];\n }\n | {\n type: Callback.CallbackType.SellERC20Callback;\n addresses: Address[];\n }\n | {\n type: Callback.CallbackType.BuyWithEmptyCallback;\n };\n\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.CallbackType.BuyVaultV1Callback,\n): Extract<CallbackConfig, { type: Callback.CallbackType.BuyVaultV1Callback }> | undefined;\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.CallbackType.SellERC20Callback,\n): Extract<CallbackConfig, { type: Callback.CallbackType.SellERC20Callback }> | undefined;\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.CallbackType.BuyWithEmptyCallback,\n): Extract<CallbackConfig, { type: Callback.CallbackType.BuyWithEmptyCallback }> | undefined;\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.CallbackType,\n): CallbackConfig | undefined;\n/**\n * Returns the callback configuration for a given chain and callback type, if it exists.\n *\n * @param chain - Chain name for which to read the validation configuration\n * @param type - Callback type to retrieve\n * @returns The matching callback configuration or undefined if not configured\n */\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.CallbackType,\n): CallbackConfig | undefined {\n return configs[chain].callbacks?.find((c) => c.type === type);\n}\n\n/**\n * Attempts to infer the configured callback type from a callback address on a chain.\n * Skips the empty callback type as it does not carry addresses.\n *\n * @param chain - Chain name for which to infer the callback type\n * @param address - Callback contract address\n * @returns The callback type when found, otherwise undefined\n */\nexport function getCallbackType(chain: Chain.Name, address: Address) {\n return configs[chain].callbacks?.find(\n (c) =>\n c.type !== Callback.CallbackType.BuyWithEmptyCallback &&\n c.addresses.includes(address?.toLowerCase() as Address),\n )?.type;\n}\n\n/**\n * Returns the callback addresses for a given chain and callback type, if it exists.\n * @param chain - Chain name for which to read the validation configuration\n * @param type - Callback type to retrieve\n * @returns The matching callback addresses or an empty array if not configured\n */\nexport function getCallbackTypeAddresses(\n chain: Chain.Name,\n type: Callback.CallbackType,\n): Address[] {\n if (type === Callback.CallbackType.BuyWithEmptyCallback) {\n return [];\n }\n const match = configs[chain].callbacks?.find((c) => c.type === type);\n return match && \"addresses\" in match ? match.addresses : [];\n}\n\n/**\n * Returns the list of allowed non-empty callback addresses for a chain.\n *\n * @param chain - Chain name\n * @returns Array of allowed callback addresses (lowercased). Empty when none configured\n */\nexport const getCallbackAddresses = (chain: Chain.Name): Address[] => {\n return (\n configs[chain].callbacks\n ?.filter((c) => c.type !== Callback.CallbackType.BuyWithEmptyCallback)\n .flatMap((c) => c.addresses) ?? []\n );\n};\n\nexport const assets: Record<string, Address[]> = {\n [Chain.ChainId.ETHEREUM.toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n [Chain.ChainId.BASE.toString()]: [\n \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\", // USDC\n \"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb\", // DAI\n \"0x4200000000000000000000000000000000000006\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n [Chain.ChainId[\"ETHEREUM-VIRTUAL-TESTNET\"].toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n \"0xce79ddb3152d52ff8fe65a4c7e058b035fcb560a\", // test token\n ],\n [Chain.ChainId.ANVIL.toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n};\n\nexport const configs: Record<Chain.Name, GateConfig> = {\n ethereum: {\n callbacks: [\n {\n type: Callback.CallbackType.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.CallbackType.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.CallbackType.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n base: {\n callbacks: [\n {\n type: Callback.CallbackType.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0xFf62A7c278C62eD665133147129245053Bbf5918\", //v1.1\n ],\n },\n {\n type: Callback.CallbackType.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.CallbackType.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n \"ethereum-virtual-testnet\": {\n callbacks: [\n {\n type: Callback.CallbackType.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.CallbackType.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.CallbackType.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n anvil: {\n callbacks: [\n {\n type: Callback.CallbackType.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.CallbackType.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.CallbackType.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n};\n","import type { Offer } from \"#core\";\nimport * as Gate from \"./Gate.ts\";\n\nexport type Rules = readonly Gate.Rule<Offer.Offer, string>[];\n\nexport type Gatekeeper = {\n rules: Rules;\n isAllowed: (offers: Offer.Offer[]) => Promise<Gate.Result<Offer.Offer, string>>;\n};\n\ntype GatekeeperParameters = {\n rules: Rules;\n};\n\nexport function create(parameters: GatekeeperParameters): Gatekeeper {\n return {\n rules: parameters.rules,\n isAllowed: async (offers: Offer.Offer[]) => {\n return await Gate.run({\n items: offers,\n rules: parameters.rules,\n });\n },\n };\n}\n","import type { Address, PublicClient, Transport } from \"viem\";\nimport { multicall } from \"viem/actions\";\nimport { Abi, Callback, type Chain, Maturity, type Offer } from \"#core\";\nimport * as BigMath from \"#utils/BigMath.ts\";\nimport type * as Validation from \"./Gate.ts\";\nimport { batch, single } from \"./Gate.ts\";\nimport * as GateConfig from \"./GateConfig.ts\";\n\nexport type ValidityParameters = {\n client: PublicClient<Transport, Chain.Chain>;\n};\n\n/**\n * set of rules to validate offers.\n *\n * @param parameters - Validity parameters with chain and client\n * @returns Array of validation rules to evaluate against offers\n */\nexport function validity(parameters: ValidityParameters) {\n const { client } = parameters;\n\n const sellErc20CallbackInvalid = single(\n \"sell_erc20_callback_invalid\",\n \"Validates that sell offers have valid ERC20 callback data matching offer collaterals\",\n (offer: Offer.Offer) => {\n const callbackType = GateConfig.getCallbackType(client.chain.name, offer.callback.address);\n if (callbackType !== Callback.CallbackType.SellERC20Callback) {\n return;\n }\n const decoded = Callback.decode(callbackType as Callback.CallbackType, offer.callback.data);\n if (decoded.length === 0) {\n return { message: \"Callback data cannot be decoded or is empty.\" };\n }\n if (callbackType === Callback.CallbackType.SellERC20Callback) {\n const offerCollaterals = new Set(\n offer.collaterals.map((c) => c.asset.toLowerCase() as Address),\n );\n if (decoded.length !== offer.collaterals.length) {\n return {\n message: `Sell callback collateral length mismatch. Expected ${offer.collaterals.length}, got ${decoded.length}.`,\n };\n }\n for (const { contract } of decoded as Array<{ contract: Address; amount: bigint }>) {\n if (!offerCollaterals.has(contract.toLowerCase() as Address)) {\n return { message: \"Sell callback collateral is not part of offer collaterals.\" };\n }\n }\n }\n },\n );\n\n const buyCallbackVaultInvalid = batch(\n \"buy_offers_callback_vault_invalid\",\n \"Validates that buy offers have valid vault callbacks registered in allowed factories with matching assets\",\n async (offers: Offer.Offer[]) => {\n const validationIssues = new Map<\n number,\n | Omit<\n Validation.Issue<Offer.Offer, \"buy_offers_callback_vault_invalid\">,\n \"ruleName\" | \"item\"\n >\n | undefined\n >();\n\n const offersByVaultAddress = new Map<string, Array<{ index: number; offer: Offer.Offer }>>();\n for (let i = 0; i < offers.length; i++) {\n const offer = offers[i]!;\n const callbackType = GateConfig.getCallbackType(client.chain.name, offer.callback.address);\n if (callbackType !== Callback.CallbackType.BuyVaultV1Callback) {\n continue;\n }\n try {\n const callbackVaults = Callback.decodeBuyVaultV1Callback(offer.callback.data);\n for (const { contract } of callbackVaults) {\n const normalizedVaultAddress = contract.toLowerCase();\n if (!offersByVaultAddress.has(normalizedVaultAddress)) {\n offersByVaultAddress.set(normalizedVaultAddress, []);\n }\n offersByVaultAddress.get(normalizedVaultAddress)!.push({ index: i, offer });\n }\n } catch (_) {\n // Skip - invalid callback data is already caught by buyCallbackDataInvalid rule\n }\n }\n\n const uniqueVaultAddresses = Array.from(offersByVaultAddress.keys());\n if (uniqueVaultAddresses.length === 0) return validationIssues;\n\n const allowedFactories = GateConfig.getCallback(\n client.chain.name,\n Callback.CallbackType.BuyVaultV1Callback,\n )?.vaultFactories!.map((f) => f.toLowerCase() as Address);\n\n if (!allowedFactories) return validationIssues;\n\n const multicallContracts = [];\n for (const vaultAddress of uniqueVaultAddresses) {\n multicallContracts.push({\n address: vaultAddress as Address,\n abi: Abi.ERC4626,\n functionName: \"asset\",\n } as const);\n\n for (const factoryAddress of allowedFactories) {\n multicallContracts.push({\n address: factoryAddress as Address,\n abi: Abi.MetaMorphoFactory,\n functionName: \"isMetaMorpho\",\n args: [vaultAddress as Address],\n } as const);\n }\n }\n\n const multicallResults = await multicall(client, {\n contracts: multicallContracts,\n allowFailure: true,\n });\n\n const vaultAssetByAddress = new Map<string, Address | null>();\n const registeredVaults = new Set<string>();\n\n const numberOfFactories = allowedFactories.length;\n\n let resultIndex = 0;\n for (const vaultAddress of uniqueVaultAddresses) {\n const assetCallResult = multicallResults[resultIndex++]!;\n const assetAddress =\n assetCallResult.status === \"success\" ? (assetCallResult.result as Address) : null;\n\n vaultAssetByAddress.set(vaultAddress, assetAddress);\n\n let isRegisteredInFactory = false;\n for (let factoryIndex = 0; factoryIndex < numberOfFactories; factoryIndex++) {\n const factoryCallResult = multicallResults[resultIndex++]!;\n\n if (factoryCallResult.status === \"success\" && factoryCallResult.result === true) {\n isRegisteredInFactory = true;\n }\n }\n\n if (isRegisteredInFactory) {\n registeredVaults.add(vaultAddress);\n }\n }\n\n const uniqueOffers = new Map<number, Offer.Offer>();\n for (const offersArray of offersByVaultAddress.values()) {\n for (const { index, offer } of offersArray) {\n uniqueOffers.set(index, offer);\n }\n }\n\n for (const [index, offer] of uniqueOffers) {\n try {\n const callbackVaults = Callback.decodeBuyVaultV1Callback(offer.callback.data);\n const vaultsWithIssues: Array<{ vaultAddress: Address; failureReasons: string }> = [];\n\n for (const { contract } of callbackVaults) {\n const normalizedVaultAddress = contract.toLowerCase();\n const assetAddress = vaultAssetByAddress.get(normalizedVaultAddress);\n const isRegistered = registeredVaults.has(normalizedVaultAddress);\n\n const failureReasons: string[] = [];\n\n if (assetAddress === null) {\n failureReasons.push(\"asset call failed\");\n } else if (\n assetAddress &&\n assetAddress.toLowerCase() !== offer.loanToken.toLowerCase()\n ) {\n failureReasons.push(\"asset mismatch\");\n }\n\n if (!isRegistered) {\n failureReasons.push(\"not registered in factory\");\n }\n\n if (failureReasons.length > 0) {\n vaultsWithIssues.push({\n vaultAddress: contract,\n failureReasons: failureReasons.join(\", \"),\n });\n }\n }\n\n if (vaultsWithIssues.length > 0) {\n const failureDetails = vaultsWithIssues\n .map((v) => `${v.vaultAddress} (${v.failureReasons})`)\n .join(\"; \");\n validationIssues.set(index, {\n message: `Buy offer callback vaults are invalid: ${failureDetails}`,\n });\n }\n } catch (_) {\n // Skip - invalid callback data is already caught by buyCallbackDataInvalid rule\n }\n }\n\n return validationIssues;\n },\n );\n\n const expiry = single(\"expiry\", \"Validates that offer has not expired\", (offer: Offer.Offer) => {\n if (offer.expiry < Math.floor(Date.now() / 1000)) {\n return { message: \"Expiry mismatch\" };\n }\n });\n\n return [expiry, sellErc20CallbackInvalid, buyCallbackVaultInvalid];\n}\n\nexport const chains = ({ chains }: { chains: Chain.Chain[] }) =>\n single(\n \"chain_ids\",\n `Validates that offer chain is one of: [${chains.map((c) => c.id).join(\", \")}]`,\n (offer: Offer.Offer) => {\n const allowedChainIds = chains.map((c) => c.id);\n if (!allowedChainIds.some((id) => id === offer.chainId)) {\n return {\n message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(\", \")})`,\n };\n }\n },\n );\n\nexport const maturity = ({ maturities }: { maturities: Maturity.MaturityType[] }) =>\n single(\n \"maturity\",\n `Validates that offer maturity is one of: [${maturities!.join(\", \")}]`,\n (offer: Offer.Offer) => {\n const allowedMaturities = maturities!.map((m) => Maturity.from(m));\n if (!allowedMaturities.includes(offer.maturity)) {\n return {\n message: `Maturity must be end of current month (${allowedMaturities[0]}) or end of next month (${allowedMaturities[1]}). Got: ${offer.maturity}`,\n };\n }\n },\n );\n\nexport const callback = ({\n callbacks,\n allowedAddresses,\n}: {\n callbacks: Callback.CallbackType[];\n allowedAddresses: Address[];\n}) =>\n single(\n \"callback\",\n `Validates callbacks: buy empty callback is ${callbacks.includes(Callback.CallbackType.BuyWithEmptyCallback) ? \"allowed\" : \"not allowed\"}; sell offers must use a non-empty callback; non-empty callbacks must target one of [${allowedAddresses.map((a) => a.toLowerCase()).join(\", \")}]`,\n (offer: Offer.Offer) => {\n if (\n Callback.isEmptyCallback(offer) &&\n offer.buy &&\n !callbacks?.find((c) => c === Callback.CallbackType.BuyWithEmptyCallback)\n ) {\n return {\n message: \"Buy offers with empty callback not allowed.\",\n };\n }\n if (Callback.isEmptyCallback(offer) && !offer.buy) {\n return {\n message: \"Sell offers require a non-empty callback.\",\n };\n }\n if (!Callback.isEmptyCallback(offer)) {\n if (!allowedAddresses.includes(offer.callback.address?.toLowerCase() as Address)) {\n return {\n message: `Callback address ${offer.callback.address} is not allowed.`,\n };\n }\n }\n },\n );\n\n/**\n * A validation rule that checks if the offer's tokens are allowed for its chain.\n * @param assetsByChainId - Allowed assets indexed by chain id.\n * @returns The issue that was found. If the offer is valid, this will be undefined.\n */\nexport const token = ({\n assetsByChainId,\n}: {\n assetsByChainId: Partial<Record<Chain.Id, Address[]>>;\n}) =>\n single(\n \"token\",\n \"Validates that offer loan token and collateral tokens are in the allowed assets list for the offer chain\",\n (offer: Offer.Offer) => {\n const allowedAssets = assetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase());\n if (!allowedAssets || allowedAssets.length === 0) {\n return { message: `No allowed assets for chain ${offer.chainId}` };\n }\n if (!allowedAssets.includes(offer.loanToken.toLowerCase())) {\n return { message: \"Loan token is not allowed\" };\n }\n if (\n offer.collaterals.some(\n (collateral) => !allowedAssets.includes(collateral.asset.toLowerCase()),\n )\n ) {\n return { message: \"Collateral is not allowed\" };\n }\n return undefined;\n },\n );\n\n/**\n * A batch validation rule that ensures all offers in a tree have the same maker address.\n * Returns an issue only for the first non-conforming offer.\n * This rule is signing-agnostic; signer verification is handled at the collector level.\n */\nexport const sameMaker = () =>\n batch(\n \"mixed_maker\",\n \"Validates that all offers in a batch have the same maker address\",\n (offers: Offer.Offer[]) => {\n const issues = new Map<\n number,\n Omit<Validation.Issue<Offer.Offer, \"mixed_maker\">, \"ruleName\" | \"item\"> | undefined\n >();\n\n if (offers.length === 0) return issues;\n\n const firstMaker = offers[0]!.maker.toLowerCase();\n\n for (let i = 1; i < offers.length; i++) {\n const offer = offers[i]!;\n if (offer.maker.toLowerCase() !== firstMaker) {\n issues.set(i, {\n message: `Offer has different maker ${offer.maker} than first offer ${offers[0]!.maker}`,\n });\n // Return only the first non-conforming offer\n // tree should be dropped entirely when only one offer is invalid\n return issues;\n }\n }\n\n return issues;\n },\n );\n\n/**\n * A validation rule that ensures mutual exclusivity of offer amount fields.\n * At most one of (assets, obligationUnits, obligationShares) can be non-zero.\n * Matches contract requirement: `atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)`.\n */\nexport const amountMutualExclusivity = () =>\n single(\n \"amount_mutual_exclusivity\",\n \"Validates that at most one of (assets, obligationUnits, obligationShares) is non-zero\",\n (offer: Offer.Offer) => {\n if (!BigMath.atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)) {\n return {\n message:\n \"Inconsistent offer input: at most one of (assets, obligationUnits, obligationShares) must be non-zero\",\n };\n }\n },\n );\n","import type { Address } from \"viem\";\nimport * as Callback from \"../core/Callback.ts\";\nimport type * as Chain from \"../core/Chain.ts\";\nimport * as Maturity from \"../core/Maturity.ts\";\nimport * as GateConfig from \"./GateConfig.ts\";\nimport * as Rules from \"./Rules.ts\";\n\nexport const morphoRules = (chains: Chain.Chain[]) => {\n const assetsByChainId: Partial<Record<Chain.Id, Address[]>> = {};\n for (const chain of chains) {\n assetsByChainId[chain.id] = GateConfig.assets[chain.id.toString()] ?? [];\n }\n\n return [\n Rules.sameMaker(),\n Rules.amountMutualExclusivity(),\n Rules.chains({ chains }),\n Rules.maturity({\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n }),\n Rules.callback({\n callbacks: [\n Callback.CallbackType.BuyWithEmptyCallback,\n Callback.CallbackType.BuyVaultV1Callback,\n Callback.CallbackType.SellERC20Callback,\n ],\n allowedAddresses: chains.flatMap((c) => GateConfig.getCallbackAddresses(c.name)),\n }),\n Rules.token({ assetsByChainId }),\n ];\n};\n","import {\n type Address,\n decodeAbiParameters,\n type Hex,\n type PublicClient,\n publicActions,\n type WalletClient as ViemClient,\n} from \"viem\";\nimport type { Compute } from \"#core\";\nimport { Chain, Offer, Tree } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type * as Client from \"./MempoolClient.ts\";\n\nconst DEFAULT_BATCH_SIZE = 100;\n\ntype MempoolEVMClientConfig = {\n readonly client: ViemClient;\n readonly mempoolAddress: Address;\n readonly blockWindow?: number;\n};\n\nexport function from(parameters: from.Parameters): from.ReturnType {\n const config: MempoolEVMClientConfig = {\n client: parameters.client,\n mempoolAddress: parameters.mempoolAddress,\n blockWindow: parameters.blockWindow,\n };\n\n return {\n add: (parameters) => add(config, parameters),\n get: (parameters) => get(config, parameters),\n stream: (parameters) => streamOffers(config, parameters),\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n /** The viem client to use. */\n client: ViemClient;\n /** The mempool address. */\n mempoolAddress: Address;\n /** The block window to use for the mempool. Defaults to 100. */\n blockWindow?: number;\n };\n\n type ReturnType = Client.Client;\n\n type ErrorType = null;\n}\n\n/**\n * Add an offer to the mempool.\n * @returns The created offer with its hash.\n * @throws WalletAccountNotSetError if the wallet account is not set.\n * @throws ViemClientError if the viem client throws an error.\n * @throws Offer.InvalidOfferError if the offer is invalid.\n */\nexport async function add(\n config: MempoolEVMClientConfig,\n offers: Client.AddParameters,\n): Promise<Hex> {\n if (!config.client.account) throw new WalletAccountNotSetError();\n\n const tree = Tree.from(offers.map((o) => Offer.from(o)));\n const chainId = await getChainId(config.client);\n for (const offer of tree.offers) {\n if (chainId !== offer.chainId) throw new ChainIdMismatchError(offer.chainId, chainId);\n }\n\n const signature = await Offer.sign(tree.offers, config.client);\n const encoded = await Tree.encode(tree, signature);\n try {\n return await config.client.sendTransaction({\n chain: config.client.chain,\n account: config.client.account!,\n to: config.mempoolAddress,\n data: encoded,\n });\n } catch (error) {\n throw new ViemClientError(error instanceof Error ? error.message : \"Unknown error\");\n }\n}\n\nexport declare namespace add {\n export type ErrorType =\n | WalletAccountNotSetError\n | ViemClientError\n | Offer.InvalidOfferError\n | ChainIdMismatchError;\n}\n\nexport async function* get(\n config: MempoolEVMClientConfig,\n parameters?: Client.GetParameters,\n): AsyncGenerator<{ offers: Offer.Offer[]; blockNumber: number }, void, void> {\n const {\n loanToken,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE } = {},\n } = parameters || {};\n\n yield* streamOffers(config, {\n loanToken,\n order,\n blockNumberGte,\n blockNumberLte,\n options: { maxBatchSize, blockWindow: config.blockWindow },\n });\n}\n\nexport declare namespace get {\n export type ErrorType = streamOffersReturnType;\n}\n\nconst chainIdCache = new Map<string, Chain.Id>();\n/**\n * Caches the chain id of a viem client.\n * @param client - The viem client.\n * @returns The chain id.\n */\nconst getChainId = async (client: ViemClient): Promise<Chain.Id> => {\n if (chainIdCache.has(client.uid)) return chainIdCache.get(client.uid)!;\n const chainId = await client.getChainId();\n chainIdCache.set(client.uid, chainId as Chain.Id);\n return chainId as Chain.Id;\n};\n\ntype streamOffersReturnType = WalletAccountNotSetError | ChainIdMismatchError;\n\nasync function* streamOffers(\n config: MempoolEVMClientConfig,\n parameters: Compute<\n Omit<Client.GetParameters, \"options\"> & {\n options: Client.GetParameters[\"options\"] & { blockWindow?: number };\n }\n >,\n): AsyncGenerator<{ offers: Offer.Offer[]; blockNumber: number }, void, void> {\n const {\n loanToken,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE, blockWindow = config.blockWindow } = {},\n } = parameters;\n\n const stream = Chain.streamLogs({\n client: config.client.extend(publicActions) as PublicClient,\n contractAddress: config.mempoolAddress,\n event: {\n type: \"event\",\n name: \"Event\",\n inputs: [{ name: \"data\", type: \"bytes\", indexed: false, internalType: \"bytes\" }],\n anonymous: false,\n } as const,\n blockNumberGte,\n blockNumberLte,\n order,\n options: { maxBatchSize, blockWindow },\n });\n\n let blockNumber = order === \"asc\" ? blockNumberGte : blockNumberLte;\n for await (const { logs, blockNumber: newBlockNumber } of stream) {\n blockNumber = newBlockNumber;\n if (logs.length === 0) continue;\n\n const offers: Offer.Offer[] = [];\n for (const log of logs) {\n if (!log) continue;\n const [payload] = decodeAbiParameters([{ type: \"bytes\" }], log.data);\n try {\n const { tree } = await Tree.decode(payload);\n for (const offer of tree.offers) {\n if (loanToken && offer.loanToken.toLowerCase() !== loanToken.toLowerCase()) continue;\n offers.push(offer);\n }\n } catch (_) {}\n }\n\n yield {\n offers,\n blockNumber,\n };\n }\n\n yield { offers: [], blockNumber: blockNumber! };\n return;\n}\n\nexport class WalletAccountNotSetError extends Errors.BaseError {\n override name = \"Mempool.WalletAccountNotSetError\";\n constructor() {\n super(\"Wallet account is not set.\");\n }\n}\n\nexport class ViemClientError extends Errors.BaseError {\n override name = \"Mempool.ViemClientError\";\n}\n\nexport class ChainIdMismatchError extends Errors.BaseError {\n override name = \"Mempool.ChainIdMismatchError\";\n constructor(expected: Chain.Id, actual: Chain.Id) {\n super(`Chain ID mismatch. Offer chain ID is ${expected}, network chain ID is ${actual}.`);\n }\n}\n","import type { Hex } from \"viem\";\nimport type { Compute, Offer } from \"#core\";\nimport * as EVMClient from \"./MempoolEVMClient.ts\";\n\nexport type AddParameters = Compute<Omit<Offer.Offer, \"createdAt\">[]>;\n\nexport type GetParameters = {\n /** The block number to get offers from. */\n blockNumberGte?: number;\n /** The block number to get offers to. */\n blockNumberLte?: number;\n /** The loan asset to get offers from. */\n loanToken?: string;\n /** The order to get offers. Defaults to \"desc\". */\n order?: \"asc\" | \"desc\";\n /** The options to get offers from. */\n options?: {\n /** The maximum number of offers to return. Defaults to 100. Maximum is 1000. */\n maxBatchSize?: number;\n };\n};\n\n/**\n * Mempool client interface.\n */\nexport type Client = {\n /**\n * Add an offer to the mempool.\n * @returns The created offer with its hash.\n */\n add: (parameters: AddParameters) => Promise<Hex>;\n /** Get offers from the mempool. */\n get: (parameters?: GetParameters) => AsyncGenerator<{\n offers: Offer.Offer[];\n /** The block number of the last processed offer. Depends on the `order` parameter, block numbers will ascend or descend. */\n blockNumber: number;\n }>;\n\n /**\n * Stream offers from the mempool.\n * @returns A generator of offers alongside the last block number processed.\n */\n stream: (\n parameters: Compute<\n Omit<GetParameters, \"options\"> & {\n options: GetParameters[\"options\"] & { blockWindow?: number };\n }\n >,\n ) => AsyncGenerator<{\n offers: Offer.Offer[];\n blockNumber: number;\n }>;\n};\n\n/**\n * Client to interact with the Mempool contract on a specific chain.\n */\nexport function connect(parameters: EVMClient.from.Parameters): Client {\n return EVMClient.from(parameters);\n}\n\nexport declare namespace connect {\n export type ErrorType = EVMClient.from.ErrorType;\n}\n","export const retry = async <T>(fn: () => Promise<T>, attempts = 3, delayMs = 50): Promise<T> => {\n let lastErr: unknown;\n for (let i = 0; i < attempts; i++) {\n try {\n return await fn();\n } catch (err) {\n lastErr = err;\n if (i < attempts - 1) await new Promise((r) => setTimeout(r, delayMs));\n }\n }\n throw lastErr;\n};\n","import type { MulticallParameters, PublicClient, Transport } from \"viem\";\nimport { multicall } from \"viem/actions\";\nimport type { Chain } from \"#core\";\nimport { batch } from \"#utils/batch.ts\";\nimport { retry } from \"#utils/retry.ts\";\n\n/**\n * Helper function to execute multicall in batches with retry logic.\n * Abstracts the common pattern of batching calls, retrying, and collecting results.\n *\n * @param parameters - Configuration for batched multicall\n * @returns Promise resolving to flattened array of results\n */\nexport async function batchMulticall<TResult>(parameters: {\n client: PublicClient<Transport, Chain.Chain>;\n calls: MulticallParameters[\"contracts\"];\n batchSize: number;\n retryAttempts: number;\n retryDelayMs: number;\n blockNumber?: bigint;\n}): Promise<TResult[]> {\n const { client, calls, batchSize, retryAttempts, retryDelayMs, blockNumber } = parameters;\n const results: TResult[] = [];\n\n for (const callsBatch of batch(calls, batchSize)) {\n const batchResults = await retry(\n () =>\n multicall(client, {\n allowFailure: false,\n contracts: callsBatch,\n ...(blockNumber ? { blockNumber } : {}),\n }),\n retryAttempts,\n retryDelayMs,\n );\n results.push(...(batchResults as TResult[]));\n }\n\n return results;\n}\n","import { type Hex, pad } from \"viem\";\n\n/**\n * Creates a bytes32 group identifier from a number.\n * @param n - A non-negative integer.\n * @throws {Error} If n is negative or not an integer.\n */\nexport const fromNumber = (n: number): Hex => {\n if (!Number.isInteger(n)) {\n throw new Error(`Group.fromNumber: expected integer, got ${n}`);\n }\n if (n < 0) {\n throw new Error(`Group.fromNumber: expected non-negative, got ${n}`);\n }\n return pad(`0x${n.toString(16)}`, { size: 32 });\n};\n","/**\n * Transform a polling function into an async generator.\n * @param fn - The polling function to transform.\n * @returns An async generator.\n */\nexport function lazy<T>(\n pollFn: (emit: (value: T) => void, { stop }: { stop: () => void }) => () => boolean,\n) {\n return () =>\n (async function* () {\n let active = true;\n let resolveNext: (() => void) | null = null;\n const queue: T[] = [];\n\n const wait = () =>\n new Promise<void>((resolve) => {\n resolveNext = resolve;\n });\n\n const emit = (item: T) => {\n queue.push(item);\n resolveNext?.();\n resolveNext = null;\n };\n\n let unpoll: (() => boolean) | null = null;\n const stop = () => {\n active = false;\n // stop the poller immediately if we already have it\n unpoll?.();\n resolveNext?.();\n resolveNext = null;\n };\n\n unpoll = pollFn(emit, { stop });\n\n try {\n while (active) {\n if (queue.length === 0) await wait();\n while (queue.length > 0 && active) yield queue.shift()!;\n }\n } finally {\n stop();\n }\n })();\n}\n","export async function wait(time: number) {\n return new Promise((res) => setTimeout(res, time));\n}\n","import { wait } from \"./wait.ts\";\n/**\n * Polls a function at a specified interval.\n * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts\n */\nexport function poll<data>(\n fn: ({ unpoll }: { unpoll: () => void }) => Promise<data | undefined>,\n { interval }: { interval: () => Promise<number> },\n) {\n let active = true;\n const unwatch = () => (active = false);\n\n const watch = async () => {\n while (active) {\n const delay = await interval();\n if (!active) break;\n await wait(delay);\n if (!active) break;\n await fn({ unpoll: unwatch });\n }\n };\n\n watch();\n\n return unwatch;\n}\n","export function now(): number {\n return Math.floor(Date.now() / 1000);\n}\n\nexport function max(): number {\n return 8640000000000000000;\n}\n","export * from \"./BigMath.ts\";\nexport * from \"./batch.ts\";\nexport * from \"./batchMulticall.ts\";\nexport * from \"./Errors.ts\";\nexport * from \"./Format.ts\";\nexport * as Group from \"./Group.ts\";\nexport * from \"./lazy.ts\";\nexport * from \"./poll.ts\";\nexport * as Random from \"./Random.ts\";\nexport * from \"./retry.ts\";\nexport * as Time from \"./time.ts\";\nexport * from \"./wait.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAMA,SAAgBA,QAAK,OAA4E;AAC/F,QAAO;EACL,OAAO,MAAM,MAAM,UAAU;EAC7B,QAAQ,MAAM,OAAO,UAAU;EAC/B,OAAO,MAAM;EACd;;;;;ACTH,MAAa,kBAAkB,EAAE,OAAO;CACtC,MAAM,EAAE,QAAQ;CAChB,UAAU,EAAE,QAAQ;CACpB,cAAc,EAAE,QAAQ,CAAC,UAAU;CACnC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,KAAK,EAAE,QAAQ,CAAC,UAAU;CAC1B,QAAQ,EAAE,KAAK;EAA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AI,MAAM;EAAW,CAAC;CACxC,iBAAiB;CAClB,CACF;AAED,MAAa,UAAU,CACrB;CACE,MAAM;CACN,MAAM;CACN,QAAQ,EAAE;CACV,SAAS,CAAC;EAAE,MAAM;EAAI,MAAM;EAAW,CAAC;CACxC,iBAAiB;CAClB,CACF;AAED,MAAa,SAAS;CACpB;EACE,MAAM;EACN,MAAM;EACN,QAAQ;GACN;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACF;EACD,SAAS,CACP;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,EACD;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS,CACP;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS;GACP;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,EACD;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS;GACP;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,M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AM,EAAE,UAAU,IAAI,EAAE;;AAIxC,MAAaC,SAAoC;UAChC,SAAS,UAAU,GAAG;EACnC;EACA;EACA;EACA;EACD;UACc,KAAK,UAAU,GAAG;EAC/B;EACA;EACA;EACA;EACD;UACc,4BAA4B,UAAU,GAAG;EACtD;EACA;EACA;EACA;EACA;EACD;UACc,MAAM,UAAU,GAAG;EAChC;EACA;EACA;EACA;EACD;CACF;AAED,MAAaC,UAA0C;CACrD,UAAU;EACR,WAAW;GACT;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACD,gBAAgB,CACd,8CACA,6CACD;IACF;GACD;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACF;GACD,EAAE,mBAA4B,sBAAsB;GACrD;EACD,YAAY,cAAuB,yBAAkC,eAAe;EACrF;CACD,MAAM;EACJ,WAAW;GACT;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACD,gBAAgB,CACd,8CACA,6CACD;IACF;GACD;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACF;GACD,EAAE,mBAA4B,sBAAsB;GACrD;EACD,YAAY,cAAuB,yBAAkC,eAAe;EACrF;CACD,4BAA4B;EAC1B,WAAW;GACT;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACD,gBAAgB,CACd,8CACA,6CACD;IACF;GACD;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACF;GACD,EAAE,mBAA4B,sBAAsB;GACrD;EACD,YAAY,cAAuB,yBAAkC,eAAe;EACrF;CACD,OAAO;EACL,WAAW;GACT;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACD,gBAAgB,CACd,8CACA,6CACD;IACF;GACD;IACE,mBAA4B;IAC5B,WAAW,CACT,8CACA,6CACD;IACF;GACD,EAAE,mBAA4B,sBAAsB;GACrD;EACD,YAAY,cAAuB,yBAAkC,eAAe;EACrF;CACF;;;;;ACpND,SAAgB,OAAO,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KAAK,KAAK;AAChB,kBAAe;AACf,iBAAc;;EAGhB,IAAIC,SAAiC;EACrC,MAAM,aAAa;AACjB,YAAS;AAET,aAAU;AACV,kBAAe;AACf,iBAAc;;AAGhB,WAAS,OAAO,MAAM,EAAE,MAAM,CAAC;AAE/B,MAAI;AACF,UAAO,QAAQ;AACb,QAAI,MAAM,WAAW,EAAG,OAAMD,QAAM;AACpC,WAAO,MAAM,SAAS,KAAK,OAAQ,OAAM,MAAM,OAAO;;YAEhD;AACR,SAAM;;KAEN;;;;;AC5CR,eAAsB,KAAK,MAAc;AACvC,QAAO,IAAI,SAAS,QAAQ,WAAW,KAAK,KAAK,CAAC;;;;;;;;;ACIpD,SAAgB,KACd,IACA,EAAE,YACF;CACA,IAAI,SAAS;CACb,MAAM,gBAAiB,SAAS;CAEhC,MAAM,QAAQ,YAAY;AACxB,SAAO,QAAQ;GACb,MAAM,QAAQ,MAAM,UAAU;AAC9B,OAAI,CAAC,OAAQ;AACb,SAAM,KAAK,MAAM;AACjB,OAAI,CAAC,OAAQ;AACb,SAAM,GAAG,EAAE,QAAQ,SAAS,CAAC;;;AAIjC,QAAO;AAEP,QAAO;;;;;;;;;ACxBT,SAAgB,MAAc;AAC5B,QAAO,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;;AAGtC,SAAgB,MAAc;AAC5B,QAAO"}
1
+ {"version":3,"file":"index.browser.mjs","names":["from","from","Type","decode","encode","max","batch","chains","viemEthereum","viemBase","viemAnvil","DEFAULT_BATCH_SIZE","BigMath.min","BigMath.max","batch","Errors.BaseError","create","z","from","InvalidOptionError","Errors.BaseError","z","z","LLTV.LLTVSchema","from","LLTV.from","random","Random.address","Errors.BaseError","z","from","Errors.BaseError","toSnakeCase","fromSnakeCase","z","Collateral.CollateralsSchema","Maturity.MaturitySchema","from","Maturity.from","fromSnakeCase","Format.fromSnakeCase","random","Random.address","Collateral.random","fromOffer","Errors.BaseError","z","Maturity.MaturitySchema","Collateral.CollateralsSchema","from","fromSnakeCase","Format.fromSnakeCase","Format.toSnakeCase","random","Random.int","Random.address","Maturity.from","LLTV.from","Random.bool","Callback.encodeSellERC20Callback","Random.hex","Collateral.random","Random.float","Obligation.id","Obligation.from","encode","decode","Collateral.from","Errors.BaseError","from","from","z","from","Format.fromSnakeCase","Obligation.id","Obligation.random","Random.int","Errors.BaseError","from","Errors.BaseError","from","from","Offer.hash","Offer.serialize","Offer.OfferSchema","Errors.BaseError","from","Obligation.id","Payload.API_ERROR_CODES","from","z","connect","Offer.fromSnakeCase","Maturity.from","Obligation.fromSnakeCase","Obligation.id","Quote.fromSnakeCase","Errors.BaseError","OfferCore.toSnakeCase","Gate.run","GateConfig.getCallbackType","Callback.decode","Callback.decodeBuyVaultV1Callback","GateConfig.getCallback","Abi.ERC4626","Abi.MetaMorphoFactory","Maturity.from","Callback.isEmptyCallback","BigMath.atMostOneNonZero","chains","GateConfig.assets","Rules.sameMaker","Rules.amountMutualExclusivity","Rules.chains","Rules.maturity","Rules.callback","GateConfig.getCallbackAddresses","Rules.token","Tree.from","Offer.from","signatureDomain","Tree.signatureDomain","Tree.signatureTypes","Tree.encode","Chain.streamLogs","Tree.decode","Errors.BaseError","Chain.getChain","EVMClient.from","batch"],"sources":["../src/api/Schema/BookResponse.ts","../src/api/Schema/health.ts","../src/api/Schema/ObligationResponse.ts","../src/core/Abi/MetaMorpho.ts","../src/core/Abi/MetaMorphoFactory.ts","../src/core/Abi/index.ts","../src/core/Callback.ts","../src/utils/BigMath.ts","../src/utils/batch.ts","../src/utils/Errors.ts","../src/core/Chain.ts","../src/core/ChainRegistry.ts","../src/utils/Random.ts","../src/utils/zod.ts","../src/core/LLTV.ts","../src/core/Collateral.ts","../src/core/ERC4626.ts","../src/core/Liquidity.ts","../src/core/Maturity.ts","../src/utils/Format.ts","../src/core/Obligation.ts","../src/core/Offer.ts","../src/core/Oracle.ts","../src/core/Position.ts","../src/core/Quote.ts","../src/core/TradingFee.ts","../src/core/Transfer.ts","../src/core/Tree.ts","../src/core/types.ts","../src/api/Schema/OfferResponse.ts","../src/api/Controllers/Payload.ts","../src/api/Schema/openapi.ts","../src/api/Schema/PositionResponse.ts","../src/api/Schema/requests.ts","../src/api/Schema/index.ts","../src/client/Client.ts","../src/gatekeeper/Client.ts","../src/gatekeeper/Gate.ts","../src/gatekeeper/Gatekeeper.ts","../src/gatekeeper/GateConfig.ts","../src/gatekeeper/Rules.ts","../src/gatekeeper/morphoRules.ts","../src/mempool/MempoolEVMClient.ts","../src/mempool/MempoolClient.ts","../src/utils/retry.ts","../src/utils/batchMulticall.ts","../src/utils/Group.ts","../src/utils/lazy.ts","../src/utils/wait.ts","../src/utils/poll.ts","../src/utils/time.ts","../src/utils/index.ts"],"sourcesContent":["export type BookLevelResponse = {\n price: string;\n assets: string;\n count: number;\n};\n\nexport function from(level: { price: bigint; assets: bigint; count: number }): BookLevelResponse {\n return {\n price: level.price.toString(),\n assets: level.assets.toString(),\n count: level.count,\n };\n}\n","import { z } from \"zod/v4\";\n\nexport const CollectorHealth = z.object({\n name: z.string(),\n chain_id: z.number(),\n block_number: z.number().nullable(),\n updated_at: z.string().nullable(),\n lag: z.number().nullable(),\n status: z.enum([\"live\", \"lagging\", \"unknown\"]),\n initialized: z.boolean(),\n});\n\nexport const CollectorsHealthResponse = z.array(CollectorHealth);\n\nexport const ChainHealth = z.object({\n chain_id: z.number(),\n local_block_number: z.number().nullable(),\n remote_block_number: z.number().nullable(),\n updated_at: z.string().nullable(),\n initialized: z.boolean(),\n});\n\nexport const ChainsHealthResponse = z.array(ChainHealth);\n\nexport const RouterStatusResponse = z.object({\n status: z.enum([\"live\", \"syncing\"]),\n initialized: z.boolean(),\n missing_chains: z.array(z.number()),\n missing_collectors: z.array(\n z.object({\n chain_id: z.number(),\n name: z.string(),\n }),\n ),\n});\n\nexport type CollectorsHealthResponse = z.infer<typeof CollectorsHealthResponse>;\nexport type ChainsHealthResponse = z.infer<typeof ChainsHealthResponse>;\nexport type RouterStatusResponse = z.infer<typeof RouterStatusResponse>;\n","import type { Obligation, Quote } from \"#core\";\nimport type * as OpenApiSchema from \"./generated/swagger.d.ts\";\n\nexport type ObligationResponse =\n OpenApiSchema.paths[\"/v1/obligations\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"][\"data\"][number];\n\n/**\n * Creates an `ObligationResponse` from a `Obligation`.\n * @constructor\n * @param obligation - {@link Obligation}\n * @returns The created `ObligationResponse`. {@link ObligationResponse}\n */\nexport function from(obligation: Obligation.Obligation, quote: Quote.Quote): ObligationResponse {\n return {\n id: quote.obligationId,\n chain_id: obligation.chainId,\n loan_token: obligation.loanToken,\n collaterals: obligation.collaterals.map((c) => ({\n token: c.asset,\n lltv: c.lltv.toString(),\n oracle: c.oracle,\n })),\n maturity: obligation.maturity,\n ask: { price: quote.ask.price.toString() },\n bid: { price: quote.bid.price.toString() },\n };\n}\n","import { parseAbi } from \"viem\";\n\nexport const MetaMorpho = parseAbi([\n \"function balanceOf(address account) view returns (uint256)\",\n \"function DECIMALS_OFFSET() view returns (uint8)\",\n \"function totalAssets() view returns (uint256)\",\n \"function totalSupply() view returns (uint256)\",\n \"function maxWithdraw(address owner) view returns (uint256 assets)\",\n \"function asset() view returns (address)\",\n \"event Transfer(address indexed from, address indexed to, uint256 value)\",\n \"function withdrawQueue(uint256 index) view returns (bytes32)\",\n \"function withdrawQueueLength() view returns (uint256)\",\n]);\nexport type MetaMorpho = typeof MetaMorpho;\n","import { parseAbi } from \"viem\";\n\nexport const MetaMorphoFactory = parseAbi([\n \"event CreateMetaMorpho(address indexed metaMorpho,address indexed caller,address initialOwner,uint256 initialTimelock,address indexed asset,string name,string symbol,bytes32 salt)\",\n \"function isMetaMorpho(address) view returns (bool)\",\n]);\nexport type MetaMorphoFactory = typeof MetaMorphoFactory;\n","export * from \"./MetaMorpho.ts\";\nexport * from \"./MetaMorphoFactory.ts\";\n\nexport const Oracle = [\n {\n type: \"function\",\n name: \"price\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport const ERC4626 = [\n {\n type: \"function\",\n name: \"asset\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport const Morpho = [\n {\n type: \"function\",\n name: \"collateralOf\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"debtOf\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"market\",\n inputs: [\n {\n name: \"id\",\n type: \"bytes32\",\n internalType: \"Id\",\n },\n ],\n outputs: [\n {\n name: \"totalSupplyAssets\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalSupplyShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalBorrowAssets\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"totalBorrowShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"lastUpdate\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"fee\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"position\",\n inputs: [\n {\n name: \"id\",\n type: \"bytes32\",\n internalType: \"Id\",\n },\n {\n name: \"user\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"supplyShares\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"borrowShares\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n {\n name: \"collateral\",\n type: \"uint128\",\n internalType: \"uint128\",\n },\n ],\n stateMutability: \"view\",\n },\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { decodeAbiParameters, encodeAbiParameters } from \"viem\";\nimport type { Offer } from \"./index.ts\";\nimport type { Brand } from \"./types.ts\";\n\n/** A position decoded from callback data. */\nexport type CallbackPosition = {\n /** The ERC20 token contract address. */\n contract: Address;\n /** The maximum amount available from this position. */\n amount: bigint;\n};\n\nexport type Callback =\n | { type: Type.BuyWithEmptyCallback }\n | (({\n /** The address of the callback contract. */\n address: Address;\n /** The ABI-encoded callback data. */\n data: Hex;\n } & {\n type: Type.BuyERC20;\n /** The decoded callback inputs. */\n inputs: {\n /** The ERC20 positions available for the callback. */\n positions: CallbackPosition[];\n };\n }) &\n Brand<\"Callback\">);\n\nexport enum Type {\n BuyWithEmptyCallback = \"buy_with_empty_callback\",\n BuyERC20 = \"buy_erc20\",\n BuyVaultV1Callback = \"buy_vault_v1_callback\",\n SellERC20Callback = \"sell_erc20_callback\",\n}\n\nexport const isEmptyCallback = (offer: Offer.Offer): boolean => offer.callback.data === \"0x\";\n\nexport function decode(type: Type, data: Hex): { contract: Address; amount: bigint }[] {\n switch (type) {\n case Type.BuyERC20:\n return decodeBuyERC20(data);\n case Type.BuyVaultV1Callback:\n return decodeBuyVaultV1Callback(data);\n case Type.SellERC20Callback:\n return decodeSellERC20Callback(data);\n default:\n throw new Error(\"Invalid callback type\");\n }\n}\n\nexport type BuyERC20Data = {\n tokens: Address[];\n amounts: bigint[];\n};\n\nexport type BuyVaultV1CallbackData = {\n vaults: Address[];\n amounts: bigint[];\n};\n\nexport type SellERC20CallbackData = {\n collaterals: Address[];\n amounts: bigint[];\n};\n\nexport function encode(type: Type.BuyERC20, data: BuyERC20Data): Hex;\nexport function encode(type: Type.BuyVaultV1Callback, data: BuyVaultV1CallbackData): Hex;\nexport function encode(type: Type.SellERC20Callback, data: SellERC20CallbackData): Hex;\nexport function encode(\n type: Type,\n data: BuyERC20Data | BuyVaultV1CallbackData | SellERC20CallbackData,\n): Hex {\n switch (type) {\n case Type.BuyERC20:\n if (!(\"tokens\" in data)) throw new Error(\"Invalid callback data\");\n return encodeBuyERC20(data);\n case Type.BuyVaultV1Callback:\n if (!(\"vaults\" in data)) throw new Error(\"Invalid callback data\");\n return encodeBuyVaultV1Callback(data);\n case Type.SellERC20Callback:\n if (!(\"collaterals\" in data)) throw new Error(\"Invalid callback data\");\n return encodeSellERC20Callback(data);\n default:\n throw new Error(\"Invalid callback type\");\n }\n}\n\n/**\n * Decodes BuyERC20 callback data into positions.\n * @param data - The ABI-encoded callback data containing token addresses and amounts.\n * @returns Array of positions with contract address and amount.\n * @throws If data is empty, malformed, or arrays have mismatched lengths.\n */\nexport function decodeBuyERC20(data: Hex): Array<{\n contract: Address;\n amount: bigint;\n}> {\n if (!data || data === \"0x\") throw new Error(\"Empty callback data\");\n\n let tokens: Address[];\n let amounts: bigint[];\n try {\n [tokens, amounts] = decodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n data,\n ) as [Address[], bigint[]];\n } catch (_) {\n throw new Error(\"Invalid BuyERC20 callback data\");\n }\n\n if (tokens.length !== amounts.length) {\n throw new Error(\"Mismatched array lengths\");\n }\n\n return tokens.map((token, index) => ({ contract: token, amount: amounts[index]! }));\n}\n\n/**\n * Encodes BuyERC20 callback parameters into ABI-encoded data.\n * @param parameters - The tokens and amounts to encode.\n * @returns ABI-encoded hex string.\n */\nexport function encodeBuyERC20(parameters: { tokens: Address[]; amounts: bigint[] }): Hex {\n return encodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n [parameters.tokens, parameters.amounts],\n );\n}\n\nexport function decodeBuyVaultV1Callback(data: Hex): Array<{\n contract: Address;\n amount: bigint;\n}> {\n if (!data || data === \"0x\") throw new Error(\"Empty callback data\");\n try {\n const [vaults, amounts] = decodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n data,\n ) as [Address[], bigint[]];\n if (vaults.length !== amounts.length) {\n throw new Error(\"Mismatched array lengths\");\n }\n return vaults.map((v, i) => ({ contract: v, amount: amounts[i]! }));\n } catch (_) {\n throw new Error(\"Invalid BuyVaultV1Callback callback data\");\n }\n}\n\nexport function decodeSellERC20Callback(data: Hex): Array<{\n contract: Address;\n amount: bigint;\n}> {\n if (!data || data === \"0x\") throw new Error(\"Empty callback data\");\n try {\n const [collaterals, amounts] = decodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n data,\n ) as [Address[], bigint[]];\n if (collaterals.length !== amounts.length) {\n throw new Error(\"Mismatched array lengths\");\n }\n return collaterals.map((c, i) => ({ contract: c, amount: amounts[i]! }));\n } catch (_) {\n throw new Error(\"Invalid SellERC20Callback callback data\");\n }\n}\n\nexport function encodeBuyVaultV1Callback(parameters: {\n vaults: Address[];\n amounts: bigint[];\n}): Hex {\n return encodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n [parameters.vaults, parameters.amounts],\n );\n}\n\nexport function encodeSellERC20Callback(parameters: {\n collaterals: Address[];\n amounts: bigint[];\n}): Hex {\n return encodeAbiParameters(\n [{ type: \"address[]\" }, { type: \"uint256[]\" }],\n [parameters.collaterals, parameters.amounts],\n );\n}\n","export function max(a: bigint, b: bigint): bigint {\n return a > b ? a : b;\n}\n\nexport function min(a: bigint, b: bigint): bigint {\n return a < b ? a : b;\n}\n\n/**\n * Checks if at most one of the given values is non-zero.\n * @param values - The bigint values to check.\n * @returns True if zero or one value is non-zero, false if two or more are non-zero.\n */\nexport function atMostOneNonZero(...values: bigint[]): boolean {\n let nonZeroCount = 0;\n for (const value of values) {\n if (value !== 0n) {\n nonZeroCount++;\n if (nonZeroCount > 1) return false;\n }\n }\n return true;\n}\n","/**\n * Splits an array into batches of a specified size.\n * @param array The array to split.\n * @param batchSize The size of each batch.\n * @returns An iterator that yields each batch.\n * @example\n * ```typescript\n * const array = [1, 2, 3, 4, 5];\n * for (const batch of batch(array, 2)) {\n * console.log(batch);\n * }\n * // Output:\n * // [1, 2]\n * // [3, 4]\n * // [5]\n * ```\n */\nexport function* batch<T>(\n array: T[] | readonly T[],\n batchSize: number,\n): Generator<T[], void, unknown> {\n for (let i = 0; i < array.length; i += batchSize) {\n yield array.slice(i, i + batchSize);\n }\n}\n","export type GlobalErrorType<name extends string = \"Error\"> = Error & {\n name: name;\n};\n\n/**\n * Base error class inherited by all errors thrown by mempool.\n *\n * @example\n * ```ts\n * import { Errors } from 'mempool'\n * throw new Errors.BaseError('An error occurred')\n * ```\n */\nexport class BaseError<cause extends Error | undefined = undefined> extends Error {\n details: string;\n shortMessage: string;\n\n override cause: cause;\n override name = \"BaseError\";\n\n constructor(\n shortMessage: string,\n options: {\n cause?: cause | undefined;\n details?: string | undefined;\n metaMessages?: (string | undefined)[] | undefined;\n } = {},\n ) {\n const details = (() => {\n if (options.cause instanceof BaseError) {\n if (options.cause.details) return options.cause.details;\n if (options.cause.shortMessage) return options.cause.shortMessage;\n }\n if (options.cause && \"details\" in options.cause && typeof options.cause.details === \"string\")\n return options.cause.details;\n if (options.cause?.message) return options.cause.message;\n return options.details!;\n })();\n\n const message = [\n shortMessage || \"An error occurred.\",\n ...(options.metaMessages ? [\"\", ...options.metaMessages] : []),\n ...(details ? [\"\", details ? `Details: ${details}` : undefined] : []),\n ]\n .filter((x) => typeof x === \"string\")\n .join(\"\\n\");\n\n super(message, options.cause ? { cause: options.cause } : undefined);\n\n this.cause = options.cause as cause;\n this.details = details;\n this.shortMessage = shortMessage;\n }\n\n walk(): Error;\n walk(fn: (err: unknown) => boolean): Error | null;\n walk(fn?: ((err: unknown) => boolean) | undefined): unknown {\n return walk(this, fn);\n }\n}\n\n/** @internal */\nfunction walk(err: unknown, fn?: ((err: unknown) => boolean) | undefined): unknown {\n if (fn?.(err)) return err;\n if (err && typeof err === \"object\" && \"cause\" in err && err.cause) return walk(err.cause, fn);\n return fn ? null : err;\n}\n\nexport class ReorgError extends BaseError {\n override name = \"ReorgError\";\n constructor(blockNumber: number) {\n super(`Reorg detected at block number ${blockNumber}`);\n }\n}\n","import type {\n AbiEvent,\n Address,\n ChainContract,\n ChainFormatters,\n GetLogsReturnType,\n PublicClient,\n} from \"viem\";\nimport { getBlock, getLogs } from \"viem/actions\";\nimport {\n type Chain as ViemChain,\n anvil as viemAnvil,\n base as viemBase,\n mainnet as viemEthereum,\n} from \"viem/chains\";\nimport type { Compute } from \"#core\";\nimport * as BigMath from \"#utils/BigMath.ts\";\nimport { batch } from \"#utils/batch.ts\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type * as Callback from \"./Callback.ts\";\n\nexport type Chain = Compute<\n Omit<\n ViemChain<\n ChainFormatters,\n {\n morpho: ChainContract;\n morphoBlue: ChainContract;\n mempool: ChainContract;\n vaults: { factories: { v1_0: ChainContract; v1_1: ChainContract } };\n callbacks: Callback.Callback[];\n }\n >,\n \"custom\"\n > & {\n id: Id;\n name: Name;\n custom: {\n morpho: ChainContract;\n morphoBlue: ChainContract;\n mempool: ChainContract;\n vaults: { factories: { v1_0: ChainContract; v1_1: ChainContract } };\n callbacks: Callback.Callback[];\n };\n }\n>;\n\nexport const ChainId = {\n ETHEREUM: 1,\n BASE: 8453,\n \"ETHEREUM-VIRTUAL-TESTNET\": 109111114,\n ANVIL: 505050505, // random id to not clash with other chains\n} as const;\n\nexport type Name = Lowercase<keyof typeof ChainId>;\nexport const chainNames = Object.keys(ChainId).map((key) => key.toLowerCase()) as readonly Name[];\n\nexport type Id = (typeof ChainId)[Uppercase<Name>];\nexport const chainIds = Object.values(ChainId) as readonly Id[];\n\nconst chainNameLookup: Map<Id, Name> = new Map(\n Object.entries(ChainId).map(([key, value]) => [value, key.toLowerCase() as Name]),\n);\n\nexport function getChain(chainId: Id): Chain | undefined {\n const chainName = chainNameLookup.get(chainId);\n if (!chainName) return undefined;\n return chains[chainName];\n}\n\nexport const getWhitelistedChains = (): Chain[] => {\n return [chains.ethereum, chains.base, chains[\"ethereum-virtual-testnet\"], chains.anvil];\n};\n\nexport const chains: Record<Lowercase<Name>, Chain> = {\n ethereum: {\n ...viemEthereum,\n id: ChainId.ETHEREUM,\n name: \"ethereum\",\n custom: {\n morpho: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 },\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 23347674,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\",\n blockCreated: 18925584,\n },\n v1_1: {\n address: \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\",\n blockCreated: 21439510,\n },\n },\n },\n callbacks: [],\n },\n },\n base: {\n ...viemBase,\n id: ChainId.BASE,\n name: \"base\",\n custom: {\n morpho: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 },\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 35449942,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\",\n blockCreated: 13978134,\n },\n v1_1: {\n address: \"0xFf62A7c278C62eD665133147129245053Bbf5918\",\n blockCreated: 23928808,\n },\n },\n },\n callbacks: [],\n },\n },\n \"ethereum-virtual-testnet\": {\n ...viemEthereum,\n id: ChainId[\"ETHEREUM-VIRTUAL-TESTNET\"],\n name: \"ethereum-virtual-testnet\",\n custom: {\n morpho: { address: \"0x11a002d45db720ed47a80d2f3489cba5b833eaf5\", blockCreated: 0 }, // @TODO: This is mock Consumed contract, update with Terms once stable\n morphoBlue: { address: \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\", blockCreated: 0 },\n mempool: {\n address: \"0x5b06224f736a57635b5bcb50b8ef178b189107cb\",\n blockCreated: 23224302,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n blockCreated: 18925584,\n },\n v1_1: {\n address: \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n blockCreated: 21439510,\n },\n },\n },\n callbacks: [],\n },\n },\n anvil: {\n ...viemAnvil,\n id: ChainId.ANVIL,\n name: \"anvil\",\n custom: {\n morpho: { address: \"0x23DFBc4B8B80C14CC5e25011B8491f268395BAd6\", blockCreated: 0 },\n morphoBlue: { address: \"0x0000000000000000000000000000000000000000\", blockCreated: 0 }, // Set dynamically in tests\n mempool: {\n address: \"0xD946246695A9259F3B33a78629026F61B3Ab40aF\",\n blockCreated: 23223727,\n },\n vaults: {\n factories: {\n v1_0: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 0,\n },\n v1_1: {\n address: \"0x0000000000000000000000000000000000000000\",\n blockCreated: 0,\n },\n },\n },\n callbacks: [],\n },\n },\n};\n\n// thresholds are set to align with Alchemy's thresholds\n//https://www.alchemy.com/docs/deep-dive-into-eth_getlogs#making-a-request-to-eth_getlogs\nconst MAX_BATCH_SIZE = 10_000;\nconst DEFAULT_BATCH_SIZE = 2_500;\nconst MAX_BLOCK_WINDOW = 10_000;\nconst DEFAULT_BLOCK_WINDOW = 8_000;\n\nexport async function* streamLogs<abiEvent extends AbiEvent | undefined = undefined>(parameters: {\n client: PublicClient;\n contractAddress?: Address;\n event?: abiEvent;\n blockNumberGte?: number;\n blockNumberLte?: number;\n order: \"asc\" | \"desc\";\n options: {\n maxBatchSize?: number;\n blockWindow?: number;\n };\n}): AsyncGenerator<\n { logs: GetLogsReturnType<abiEvent | undefined>; blockNumber: number },\n void,\n void\n> {\n const {\n client,\n contractAddress,\n event,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE, blockWindow = DEFAULT_BLOCK_WINDOW } = {},\n } = parameters;\n if (maxBatchSize > MAX_BATCH_SIZE) throw new InvalidBatchSizeError(maxBatchSize);\n if (blockWindow > MAX_BLOCK_WINDOW) throw new InvalidBlockWindowError(blockWindow);\n if (order === \"asc\" && blockNumberGte === undefined) throw new MissingBlockNumberError();\n\n const latestBlock = (await getBlock(client, { blockTag: \"latest\", includeTransactions: false }))\n .number;\n\n let toBlock = 0n;\n if (order === \"asc\")\n toBlock = BigMath.min(\n BigInt(blockNumberGte!) + BigInt(blockWindow),\n blockNumberLte ? BigInt(blockNumberLte!) : latestBlock,\n );\n if (order === \"desc\")\n toBlock =\n blockNumberLte === undefined\n ? latestBlock\n : BigMath.min(BigInt(blockNumberLte!), latestBlock);\n\n let fromBlock = 0n;\n if (order === \"asc\") fromBlock = BigMath.min(BigInt(blockNumberGte!), latestBlock);\n if (order === \"desc\")\n fromBlock = BigMath.max(BigInt(blockNumberGte || toBlock - BigInt(blockWindow)), 0n);\n\n if (order === \"asc\") toBlock = BigMath.min(toBlock, fromBlock + BigInt(blockWindow));\n if (order === \"desc\") fromBlock = BigMath.max(fromBlock, toBlock - BigInt(blockWindow));\n if (fromBlock > toBlock) throw new InvalidBlockRangeError(fromBlock, toBlock);\n\n let streaming = true;\n while (streaming) {\n const logs = await getLogs(client, {\n address: contractAddress,\n event,\n fromBlock,\n toBlock,\n });\n\n streaming =\n order === \"asc\"\n ? toBlock < (blockNumberLte || latestBlock)\n : fromBlock > (blockNumberGte || 0n);\n\n if (logs.length === 0 && !streaming) {\n break;\n }\n\n if (logs.length === 0 && streaming) {\n yield { logs: [], blockNumber: order === \"asc\" ? Number(toBlock) : Number(fromBlock) };\n }\n\n logs.sort((a, b) => {\n if (a.blockNumber !== b.blockNumber)\n return order === \"asc\"\n ? Number(a.blockNumber - b.blockNumber)\n : Number(b.blockNumber - a.blockNumber);\n if (a.transactionIndex !== b.transactionIndex)\n return order === \"asc\"\n ? a.transactionIndex - b.transactionIndex\n : b.transactionIndex - a.transactionIndex;\n return order === \"asc\" ? a.logIndex - b.logIndex : b.logIndex - a.logIndex;\n });\n\n for (const logBatch of batch(logs, maxBatchSize)) {\n yield {\n logs: logBatch,\n blockNumber:\n logBatch.length === maxBatchSize\n ? // if the batch is full, return the last block number, block numbers are always sorted\n Number(logBatch[logBatch.length - 1]?.blockNumber)\n : // if the batch is not full, return `toBlock` or `fromBlock` to indicate until which block the logs were fetched\n order === \"asc\"\n ? Number(toBlock)\n : Number(fromBlock),\n };\n }\n\n if (order === \"asc\") {\n const upperBound = BigInt(blockNumberLte || latestBlock);\n const nextFromBlock = BigMath.min(BigInt(toBlock) + 1n, upperBound);\n const nextToBlock = BigMath.min(toBlock + BigInt(blockWindow) + 1n, upperBound);\n fromBlock = nextFromBlock;\n toBlock = nextToBlock;\n }\n\n if (order === \"desc\") {\n const lowerBound = BigInt(blockNumberGte || 0);\n const nextToBlock = BigMath.max(fromBlock - 1n, lowerBound);\n const nextFromBlock = BigMath.max(fromBlock - BigInt(blockWindow) - 1n, lowerBound);\n toBlock = nextToBlock;\n fromBlock = nextFromBlock;\n }\n }\n\n yield { logs: [], blockNumber: order === \"asc\" ? Number(toBlock) : Number(fromBlock) };\n return;\n}\n\nexport class InvalidBlockRangeError extends Errors.BaseError {\n override name = \"Chain.InvalidBlockRangeError\";\n constructor(fromBlock: bigint, toBlock: bigint) {\n super(\n `Invalid block range while streaming data from chain. From block ${fromBlock} to block ${toBlock}.`,\n );\n }\n}\n\nexport class InvalidBlockWindowError extends Errors.BaseError {\n override name = \"Chain.InvalidBlockWindowError\";\n constructor(blockWindow: number) {\n super(\n `Invalid block window while streaming data from chain. Maximum is ${MAX_BLOCK_WINDOW}. Got ${blockWindow}.`,\n );\n }\n}\n\nexport class InvalidBatchSizeError extends Errors.BaseError {\n override name = \"Chain.InvalidBatchSizeError\";\n constructor(maxBatchSize: number) {\n super(\n `Invalid batch size while streaming data from chain. Maximum is ${MAX_BATCH_SIZE}. Got ${maxBatchSize}.`,\n );\n }\n}\n\nexport class MissingBlockNumberError extends Errors.BaseError {\n override name = \"Chain.MissingBlockNumberError\";\n constructor() {\n super(\"Missing block number when streaming data from chain in ascending order.\");\n }\n}\n","import type * as Chain from \"./Chain.ts\";\n\nexport type ChainRegistry = {\n getById: (chainId: Chain.Id) => Chain.Chain | undefined;\n list: () => Chain.Chain[];\n};\n\n/**\n * Creates a chain registry from a list of chains.\n * @param chains - Array of chain objects to register.\n * @returns A registry for looking up chains by ID. {@link ChainRegistry}\n */\nexport function create(chains: Chain.Chain[]): ChainRegistry {\n const byId = new Map<Chain.Id, Chain.Chain>();\n for (const chain of chains) {\n byId.set(chain.id, chain);\n }\n\n return {\n getById: (chainId: Chain.Id) => byId.get(chainId),\n list: () => Array.from(byId.values()),\n };\n}\n","import type { Address, Hex } from \"viem\";\n\ntype Rng = () => number;\n\nlet currentRng: Rng = Math.random;\n\nconst FNV_OFFSET_BASIS = 2166136261;\nconst FNV_PRIME = 16777619;\n\nconst hashSeed = (seed: string): number => {\n let hash = FNV_OFFSET_BASIS;\n for (let i = 0; i < seed.length; i += 1) {\n hash ^= seed.charCodeAt(i);\n hash = Math.imul(hash, FNV_PRIME);\n }\n return hash >>> 0;\n};\n\nconst createSeededRng = (seed: string): Rng => {\n let state = hashSeed(seed);\n return () => {\n state += 0x6d2b79f5;\n let t = Math.imul(state ^ (state >>> 15), state | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n};\n\n/**\n * Runs a function with a deterministic RNG derived from the given seed.\n */\nexport function withSeed<T>(seed: string, fn: () => T): T {\n const previous = currentRng;\n currentRng = createSeededRng(seed);\n try {\n return fn();\n } finally {\n currentRng = previous;\n }\n}\n\n/**\n * Seeds the global RNG for deterministic test runs.\n */\nexport function seed(seed: string): void {\n currentRng = createSeededRng(seed);\n}\n\n/**\n * Returns a deterministic random float in [0, 1).\n */\nexport function float(): number {\n return currentRng();\n}\n\n/**\n * Returns a deterministic random integer in [min, maxExclusive).\n */\nexport function int(maxExclusive: number, min = 0): number {\n return Math.floor(float() * (maxExclusive - min)) + min;\n}\n\n/**\n * Returns a deterministic random boolean.\n */\nexport function bool(probability = 0.5): boolean {\n return float() < probability;\n}\n\n/**\n * Returns deterministic random bytes.\n */\nexport function bytes(length: number): Uint8Array {\n const output = new Uint8Array(length);\n for (let i = 0; i < length; i += 1) {\n output[i] = int(256);\n }\n return output;\n}\n\n/**\n * Returns a deterministic random hex string for the given byte length.\n */\nexport function hex(byteLength: number): Hex {\n const output = bytes(byteLength);\n const hexParts = Array.from(output, (byte) => byte.toString(16).padStart(2, \"0\"));\n return `0x${hexParts.join(\"\")}` as Hex;\n}\n\n/**\n * Returns a deterministic random address.\n */\nexport function address(): Address {\n return hex(20) as Address;\n}\n","import { type Address, type Hex, isAddress, isHex, numberToHex, pad } from \"viem\";\nimport * as z from \"zod\";\n\n/**\n * Converts a hex string to a padded bytes32.\n * Returns null if the value is not a valid hex string.\n */\nconst hexToBytes32 = (val: string): Hex | null => {\n if (!isHex(val)) return null;\n return pad(val as Hex, { size: 32 });\n};\n\n/**\n * Converts a numeric string to a padded bytes32.\n * @throws {Error} If parsing fails or value is negative.\n */\nconst numericStringToBytes32 = (val: string): Hex => {\n const num = BigInt(val);\n if (num < 0n) throw new Error(\"expected bigint to be >=0\");\n return pad(numberToHex(num), { size: 32 });\n};\n\n/**\n * Converts a number or bigint to a padded bytes32.\n * @throws {Error} If value is negative.\n */\nconst numericToBytes32 = (val: number | bigint): Hex => {\n const num = BigInt(val);\n if (num < 0n) throw new Error(\"expected bigint to be >=0\");\n return pad(numberToHex(num), { size: 32 });\n};\n\n/**\n * Transforms a value to a bytes32 hex string.\n * Accepts:\n * - Hex strings (0x...) - pads to 32 bytes if needed\n * - Numeric strings - converts to padded hex\n * - Numbers/bigints - converts to padded hex (must be non-negative)\n */\nexport const transformBytes32 = (val: string | number | bigint, ctx: z.RefinementCtx): Hex => {\n if (typeof val === \"string\") {\n const hexResult = hexToBytes32(val);\n if (hexResult !== null) return hexResult;\n\n try {\n return numericStringToBytes32(val);\n } catch (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Not a valid bytes32 value: ${error instanceof Error ? error.message : String(error)}`,\n });\n return z.NEVER;\n }\n }\n\n if (typeof val === \"number\" || typeof val === \"bigint\") {\n try {\n return numericToBytes32(val);\n } catch (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Too small: ${error instanceof Error ? error.message : String(error)}`,\n });\n return z.NEVER;\n }\n }\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Not a valid bytes32 value\",\n });\n\n return z.NEVER;\n};\n\nexport const transformHex = (val: string, ctx: z.RefinementCtx) => {\n if (isHex(val)) return val;\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Invalid hex\",\n });\n\n return z.NEVER;\n};\n\nexport const transformAddress = (val: string, ctx: z.RefinementCtx) => {\n if (isAddress(val.toLowerCase())) return val.toLowerCase() as Address;\n\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"Invalid address\",\n });\n\n return z.NEVER;\n};\n","import * as z from \"zod\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type { Brand } from \"./types.ts\";\n\nexport type LLTV = bigint & Brand<\"LLTV\">;\n\nexport const Options = [0.385, 0.5, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965, 0.98] as const;\nexport type Options = (typeof Options)[number];\nconst LLTV_SCALED = Options.map((lltv) => BigInt(lltv * 10 ** 18));\n\n/**\n * Convert a LLTV option or a scaled LLTV to a LLTV.\n * @param lltv - The LLTV option or the scaled LLTV.\n * @returns The LLTV.\n */\nexport function from(lltv: Options | bigint): LLTV {\n if (typeof lltv === \"bigint\" && !LLTV_SCALED.includes(lltv)) throw new InvalidLLTVError(lltv);\n if (typeof lltv === \"bigint\") return lltv as LLTV;\n if (typeof lltv === \"number\" && !Options.includes(lltv)) throw new InvalidOptionError(lltv);\n return BigInt(lltv * 10 ** 18) as LLTV;\n}\n\nexport declare namespace from {\n type ErrorType = InvalidOptionError | InvalidLLTVError;\n}\n\nexport class InvalidOptionError extends Errors.BaseError {\n override readonly name = \"LLTV.InvalidOptionError\";\n constructor(input: number) {\n super(\n `Invalid LLTV option. Input: \"${input}\". Accepted values are: ${Options.map(\n (option) => `\"${option}\"`,\n ).join(\", \")}.`,\n );\n }\n}\n\nexport class InvalidLLTVError extends Errors.BaseError {\n override readonly name = \"LLTV.InvalidLLTVError\";\n constructor(input: bigint) {\n super(\n `Invalid LLTV. Input: \"${input}\". Accepted values are: ${LLTV_SCALED.map(\n (option) => `\"${option}\"`,\n ).join(\", \")}.`,\n );\n }\n}\n\nexport const LLTVSchema = z\n .bigint({ coerce: true })\n .refine(\n (lltv) => {\n try {\n from(lltv);\n return true;\n } catch (_) {\n return false;\n }\n },\n {\n error: () => {\n return \"Invalid LLTV: must be one of 0.385, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965 or 0.98 (scaled by 1e18)\";\n },\n },\n )\n .transform((lltv) => from(lltv));\n","import type { Address } from \"viem\";\nimport * as z from \"zod\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress } from \"#utils/zod.ts\";\nimport * as LLTV from \"./LLTV.ts\";\n\nexport type Collateral = {\n /** Asset being used as collateral. */\n asset: Address;\n /** Liquidation Loan-to-Value of the collateral. */\n lltv: LLTV.LLTV;\n /** Oracle contract used to price the collateral. */\n oracle: Address;\n};\n\nexport const CollateralSchema = z.object({\n asset: z.string().transform(transformAddress),\n oracle: z.string().transform(transformAddress),\n lltv: LLTV.LLTVSchema,\n});\n\nexport const CollateralsSchema = z\n .array(CollateralSchema)\n .min(1, { message: \"At least one collateral is required\" })\n .refine(\n (collaterals) => {\n for (let i = 1; i < collaterals.length; i++) {\n if (collaterals[i - 1]!.asset.toLowerCase() > collaterals[i]!.asset.toLowerCase()) {\n return false;\n }\n }\n return true;\n },\n {\n message: \"Collaterals must be sorted alphabetically by address\",\n },\n )\n .refine(\n (collaterals) => {\n const uniqueAssets = new Set<string>();\n for (const collateral of collaterals) {\n const assetAddress = collateral.asset.toLowerCase();\n if (uniqueAssets.has(assetAddress)) {\n return false;\n }\n uniqueAssets.add(assetAddress);\n }\n return true;\n },\n {\n message: \"Collaterals must not contain duplicate assets\",\n },\n );\n\nexport const from = (parameters: from.Parameters): from.ReturnType => {\n return {\n asset: parameters.asset.toLowerCase() as Address,\n lltv: LLTV.from(parameters.lltv),\n oracle: parameters.oracle.toLowerCase() as Address,\n };\n};\n\nexport declare namespace from {\n type Parameters = {\n asset: Address;\n lltv: LLTV.Options | bigint;\n oracle: Address;\n };\n type ReturnType = Collateral;\n}\n\n/**\n * Generates a random collateral.\n * @returns A randomly generated collateral. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const collateral = Collateral.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n asset: Random.address(),\n oracle: Random.address(),\n lltv: 0.965,\n });\n}\n\nexport declare namespace random {\n type ReturnType = Collateral;\n}\n","import * as Errors from \"#utils/Errors.ts\";\n\n/**\n * Calculate the decimals offset used by the ERC4626 implementation.\n * @param parameters - {@link decimalsOffset.Parameters}.\n * @returns The decimals offset.\n *\n * @example\n * ```ts\n * const decimalsOffset = decimalsOffset({ underlyingDecimals: 6 });\n * // decimalsOffset = 12\n * ```\n */\nexport function decimalsOffset(parameters: decimalsOffset.Parameters): number {\n return Math.max(0, 18 - parameters.underlyingDecimals);\n}\n\nexport declare namespace decimalsOffset {\n type Parameters = {\n /** The number of decimals of the underlying asset. */\n underlyingDecimals: number;\n };\n type ReturnType = number;\n}\n\n/**\n * Convert shares to assets.\n * @throws If the denominator is 0. {@link DenominatorIsZeroError}\n * @param parameters - {@link convertToAssets.Parameters}.\n * @returns The amount of assets.\n *\n * @example\n * ```ts\n * const assets = convertToAssets(100n, { totalAssets: 1000n, totalSupply: 1000n, decimalsOffset: 18 });\n * // assets = 100n\n * ```\n */\nexport function convertToAssets(\n parameters: convertToAssets.Parameters,\n): convertToAssets.ReturnType {\n const denominator = parameters.totalSupply + 10n ** BigInt(parameters.decimalsOffset);\n if (denominator === 0n) throw new DenominatorIsZeroError();\n\n return (parameters.shares * (parameters.totalAssets + 1n)) / denominator;\n}\n\nexport declare namespace convertToAssets {\n type Parameters = {\n /** The amount of shares to convert. */\n shares: bigint;\n /** Total amount of assets in the vault. */\n totalAssets: bigint;\n /** Total amount of shares in the vault. */\n totalSupply: bigint;\n /**\n * OpenZeppelin decimals offset used by the ERC4626 implementation.\n * Calculated to be `max(0, 18 - underlyingDecimals)` at construction, so the initial conversion rate maximizes\n * precision between shares and assets.\n */\n decimalsOffset: number;\n };\n type ReturnType = bigint;\n type ErrorType = DenominatorIsZeroError;\n}\n\n/**\n * Convert assets to shares.\n * @throws If the denominator is 0. {@link DenominatorIsZeroError}\n * @param parameters - {@link convertToShares.Parameters}.\n * @returns The amount of shares.\n *\n * @example\n * ```ts\n * const shares = convertToShares(100n, { totalAssets: 1000n, totalSupply: 1000n, decimalsOffset: 12 });\n * // shares = 100n\n * ```\n */\nexport function convertToShares(\n parameters: convertToShares.Parameters,\n): convertToShares.ReturnType {\n const denominator = parameters.totalAssets + 1n;\n if (denominator === 0n) throw new DenominatorIsZeroError();\n\n return (\n (parameters.assets * (parameters.totalSupply + 10n ** BigInt(parameters.decimalsOffset))) /\n denominator\n );\n}\n\nexport declare namespace convertToShares {\n type Parameters = {\n /** The amount of assets to convert. */\n assets: bigint;\n /** Total amount of assets in the vault. */\n totalAssets: bigint;\n /** Total amount of shares in the vault. */\n totalSupply: bigint;\n /**\n * OpenZeppelin decimals offset used by the ERC4626 implementation.\n * Calculated to be `max(0, 18 - underlyingDecimals)` at construction, so the initial conversion rate maximizes\n * precision between shares and assets.\n */\n decimalsOffset: number;\n };\n type ReturnType = bigint;\n type ErrorType = DenominatorIsZeroError;\n}\nexport class DenominatorIsZeroError extends Errors.BaseError {\n override readonly name = \"ERC4626.DenominatorIsZeroError\";\n constructor() {\n super(\"Denominator is 0.\");\n }\n}\n","import type { Address, Hex } from \"viem\";\nimport type { Chain } from \"#core\";\nimport * as Callback from \"./Callback.ts\";\n\n/**\n * Represents a liquidity pool with a unique ID and amount.\n */\nexport type LiquidityPool = {\n id: string;\n amount: bigint;\n};\n\n/**\n * Represents a hierarchical relationship between two liquidity pools.\n */\nexport type LiquidityLink = {\n parentPoolId: string;\n childPoolId: string;\n priority: number;\n};\n\n/**\n * Represents the connection between an offer and its liquidity pools.\n */\nexport type OfferLiquidityPool = {\n offerHash: Hex;\n poolId: string;\n /**\n * The available capacity/liquidity from this pool for this offer.\n * Meaning varies by pool type:\n * - BuyWithEmptyCallback: Matches allowance amount from pool bellow\n * - SellERC20Callback: Sell Callback/Predeposited -> Maximum debt capacity calculated from collateral (collateralAmount * oraclePrice * lltv)\n * - SellERC20Callback: Existing debt as negative value (reduces available capacity)\n */\n amount: bigint;\n};\n\n/**\n * Calculate maximum debt capacity from collateral amount.\n * @param amount - Collateral amount\n * @param oraclePrice - Oracle price (scaled to 36 decimals)\n * @param lltv - Loan-to-value ratio (scaled to 18 decimals)\n * @returns Maximum debt capacity\n */\nexport function calculateMaxDebt(amount: bigint, oraclePrice: bigint, lltv: bigint): bigint {\n const ORACLE_PRICE_SCALE = 10n ** 36n; // Oracle prices are scaled to 36 decimals\n const PRECISION = 10n ** 18n; // LLTV ratios are scaled to 18 decimals (1e18 = 100%)\n\n const collateralQuoted = (amount * oraclePrice) / ORACLE_PRICE_SCALE;\n const maxDebt = (collateralQuoted * lltv) / PRECISION;\n\n return maxDebt;\n}\n\n/**\n * Generate pool ID for balance pools.\n */\nexport function generateBalancePoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n token: Address;\n}): string {\n const { user, chainId, token } = parameters;\n return `${user}-${chainId.toString()}-${token}-balance`.toLowerCase();\n}\n\n/**\n * Generate pool ID for allowance pools.\n */\nexport function generateAllowancePoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n token: Address;\n}): string {\n const { user, chainId, token } = parameters;\n return `${user}-${chainId.toString()}-${token}-allowance`.toLowerCase();\n}\n\n/**\n * Generate pool ID for sell ERC20 callback pools.\n * Each offer has its own callback pool to prevent liquidity conflicts.\n */\nexport function generateSellERC20CallbackPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n token: Address;\n offerHash: Hex;\n}): string {\n const { user, chainId, obligationId, token, offerHash } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-${token}-${offerHash}-sell_erc20_callback`.toLowerCase();\n}\n\n/**\n * Generate pool ID for obligation collateral pools.\n * Obligation collateral pools represent collateral already deposited in the obligation.\n * These pools are shared across all offers with the same obligation.\n */\nexport function generateObligationCollateralPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n token: Address;\n}): string {\n const { user, chainId, obligationId, token } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-${token}-obligation-collateral`.toLowerCase();\n}\n\n/**\n * Generate pool ID for buy vault callback pools.\n */\nexport function generateBuyVaultCallbackPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n vault: Address;\n offerHash: Hex;\n}): string {\n const { user, chainId, vault, offerHash } = parameters;\n return `${user}-${chainId.toString()}-${vault}-${offerHash}-${Callback.Type.BuyVaultV1Callback}`.toLowerCase();\n}\n\n/**\n * Generate pool ID for debt pools.\n */\nexport function generateDebtPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n obligationId: Hex;\n}): string {\n const { user, chainId, obligationId } = parameters;\n return `${user}-${chainId.toString()}-${obligationId}-debt`.toLowerCase();\n}\n\n/**\n * Generate pool ID for user position in a vault.\n */\nexport function generateUserVaultPositionPoolId(parameters: {\n user: Address;\n chainId: Chain.Id;\n vault: Address;\n}): string {\n const { user, chainId, vault } = parameters;\n return `${user}-${chainId.toString()}-${vault}-user-vault-position`.toLowerCase();\n}\n\n/**\n * Generate pool ID for vault position in a market.\n */\nexport function generateVaultPositionPoolId(parameters: {\n vault: Address;\n chainId: Chain.Id;\n marketId: string;\n}): string {\n const { vault, chainId, marketId } = parameters;\n return `${vault}-${chainId.toString()}-${marketId}-vault-position`.toLowerCase();\n}\n\n/**\n * Generate pool ID for market total liquidity.\n */\nexport function generateMarketLiquidityPoolId(parameters: {\n chainId: Chain.Id;\n marketId: string;\n}): string {\n const { chainId, marketId } = parameters;\n return `${chainId.toString()}-${marketId}-market-liquidity`.toLowerCase();\n}\n","import * as z from \"zod\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type { Brand } from \"./types.ts\";\n\n/**\n * Maturity is a number that represents a date in seconds.\n */\nexport type Maturity = number & Brand<\"Maturity\">;\n\nexport const MaturitySchema = z\n .number()\n .int()\n .refine(\n (maturity) => {\n try {\n from(maturity);\n return true;\n } catch (_e) {\n return false;\n }\n },\n {\n error: (issue) => {\n try {\n const maturityDate = new Date((issue.input as number) * 1000);\n return `The maturity is set to ${maturityDate}. It must fall on the allowed settlement cycles (Friday 15:00 UTC at the end of week/month/quarter).`;\n } catch (_) {\n return `The maturity is set to ${issue.input}. It must fall on the allowed settlement cycles (Friday 15:00 UTC at the end of week/month/quarter).`;\n }\n },\n },\n )\n .transform((maturity) => maturity as Maturity);\n\nexport enum MaturityType {\n EndOfWeek = \"end_of_week\",\n EndOfNextWeek = \"end_of_next_week\",\n EndOfMonth = \"end_of_month\",\n EndOfNextMonth = \"end_of_next_month\",\n EndOfQuarter = \"end_of_quarter\",\n EndOfNextQuarter = \"end_of_next_quarter\",\n}\n\nconst MaturityOptions = {\n end_of_week: () => endOfWeek(),\n end_of_next_week: () => endOfNextWeek(),\n end_of_month: () => endOfMonth(),\n end_of_next_month: () => endOfNextMonth(),\n end_of_quarter: () => endOfQuarter(),\n end_of_next_quarter: () => endOfNextQuarter(),\n} as const;\n\nexport type MaturityOptions = keyof typeof MaturityOptions;\n\n/**\n * Creates a maturity from a timestamp in seconds or a maturity option.\n * @throws {InvalidFormatError} If the maturity is in milliseconds.\n * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.\n * @throws {InvalidOptionError} If the maturity is not a valid option.\n */\nexport function from(ts: from.Parameters): Maturity {\n if (typeof ts === \"string\") {\n if (ts in MaturityOptions) return MaturityOptions[ts]();\n throw new InvalidOptionError(ts);\n }\n\n if (typeof ts === \"number\" && ts > 1e12) throw new InvalidFormatError();\n\n if (!Object.values(MaturityOptions).some((option) => option() === ts))\n throw new InvalidDateError(ts);\n\n return ts as Maturity;\n}\n\nexport declare namespace from {\n type Parameters = number | MaturityOptions;\n type ErrorType = InvalidFormatError | InvalidDateError | InvalidOptionError;\n}\n\n/** Returns the end of the current week (friday at 15:00:00 UTC) */\nconst endOfWeek = (): Maturity => fridayOfWeek(0);\n\n/** Returns the end of the next week (friday at 15:00:00 UTC) */\nconst endOfNextWeek = (): Maturity => fridayOfWeek(1);\n\n/** Returns the end of the current month (last friday of the month at 15:00:00 UTC)\n * Business rule: if we are after the last Friday of the month (strictly after 15:00 UTC\n * on that Friday), roll to the next month's last Friday.\n */\nconst endOfMonth = (): Maturity => {\n const now = new Date();\n const year = now.getUTCFullYear();\n const month = now.getUTCMonth();\n\n const endOfMonth = lastFridayOfMonth(year, month);\n\n // If strictly after 15:00 UTC on the last Friday, roll to next month's last Friday\n if (now.getTime() > endOfMonth * 1000) {\n return lastFridayOfMonth(year, month + 1);\n }\n\n return endOfMonth;\n};\n\n/** Returns the end of the next month (last friday of the next month at 15:00:00 UTC)\n * Business rule: if we are after the last Friday of the current month (strictly after 15:00 UTC\n * on that Friday), we consider being in the next month already, so \"next month\" becomes month+2.\n */\nconst endOfNextMonth = (): Maturity => {\n const now = new Date();\n const year = now.getUTCFullYear();\n const month = now.getUTCMonth();\n\n const endOfMonth = lastFridayOfMonth(year, month);\n\n if (now.getTime() > endOfMonth * 1000) {\n return lastFridayOfMonth(year, month + 2);\n }\n\n return lastFridayOfMonth(year, month + 1);\n};\n\n/** Returns the end of the current quarter (last friday of the quarter at 15:00:00 UTC) */\nconst endOfQuarter = (): Maturity => lastFridayOfQuarter(0);\n\n/** Returns the end of the next quarter (last friday of the next quarter at 15:00:00 UTC) */\nconst endOfNextQuarter = (): Maturity => lastFridayOfQuarter(1);\n\nconst fridayOfWeek = (weeksAhead = 0): Maturity => {\n const now = new Date();\n const today15H = new Date(\n Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 15),\n );\n\n // Days until next Friday (5). Always non-negative in [0,6]\n let daysUntilFriday = (5 - today15H.getUTCDay() + 7) % 7;\n\n // If it's Friday and we're already past 15:00 UTC, roll to next Friday\n if (daysUntilFriday === 0 && now.getTime() >= today15H.getTime()) {\n daysUntilFriday = 7;\n }\n\n const friday = new Date(today15H);\n friday.setUTCDate(friday.getUTCDate() + daysUntilFriday + weeksAhead * 7);\n return (friday.getTime() / 1000) as Maturity;\n};\n\nconst lastFridayOfMonth = (year: number, month: number): Maturity => {\n const lastDayOfMonth15H = new Date(Date.UTC(year, month + 1, 0, 15));\n\n while (lastDayOfMonth15H.getUTCDay() !== 5) {\n lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate() - 1);\n }\n\n const maturity = lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate()) / 1000;\n\n return maturity as Maturity;\n};\n\nconst lastFridayOfQuarter = (quartersAhead = 0): Maturity => {\n const now = new Date();\n const quarterIndex = Math.floor(now.getUTCMonth() / 3) + quartersAhead;\n const year = now.getUTCFullYear() + Math.floor(quarterIndex / 4);\n const quarter = quarterIndex % 4;\n const lastMonth = quarter * 3 + 2; // 0-based\n return lastFridayOfMonth(year, lastMonth);\n};\n\nexport class InvalidFormatError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidFormatError\";\n constructor() {\n super(\"Invalid maturity format. Maturity should be expressed in seconds.\");\n }\n}\n\nexport class InvalidDateError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidDateError\";\n constructor(input: number) {\n super(\n `Invalid maturity date. Input: \"${input}\". Accepted values are: ${Object.values(\n MaturityOptions,\n )\n .map((option) => `\"${option()}\"`)\n .join(\", \")}.`,\n );\n }\n}\n\nexport class InvalidOptionError extends Errors.BaseError {\n override readonly name = \"Maturity.InvalidOptionError\";\n constructor(input: string) {\n super(\n `Invalid maturity option. Input: \"${input}\". Accepted values are: ${Object.keys(\n MaturityOptions,\n )\n .map((option) => `\"${option}\"`)\n .join(\", \")}.`,\n );\n }\n}\n","import { getAddress, isAddress } from \"viem\";\n\n/** The snake case representation of a type with bigint values stringified. */\nexport type Snake<T> = DeepMutable<SnakeKeys<StringifiedBigint<T>>>;\n\n/** Make arrays/tuples and object props mutable, deeply. */\ntype DeepMutable<T> =\n // leave functions/primitives as-is\n T extends (...args: unknown[]) => unknown\n ? T\n : T extends number | string | boolean | symbol | bigint | null | undefined\n ? T\n : // handle tuples first (preserve length/element types)\n T extends readonly [...infer R]\n ? { -readonly [K in keyof R]: DeepMutable<R[K]> }\n : // then general readonly arrays\n T extends ReadonlyArray<infer U>\n ? Array<DeepMutable<U>>\n : // then objects: strip readonly from props and recurse\n T extends object\n ? { -readonly [K in keyof T]: DeepMutable<T[K]> }\n : T;\n\n/** Stringifies bigint values to strings and preserves branded primitives. */\ntype StringifiedBigint<T> =\n // non-distributive check so that `bigint & Brand<...>` is still caught here\n [T] extends [bigint]\n ? string\n : [T] extends [`0x${string}`]\n ? string\n : // Preserve branded primitives by matching the primitive first.\n T extends number\n ? T\n : T extends string\n ? T\n : T extends boolean\n ? T\n : T extends symbol\n ? T\n : T extends null | undefined\n ? T\n : T extends readonly (infer U)[]\n ? readonly StringifiedBigint<U>[]\n : T extends object\n ? { [K in keyof T]: StringifiedBigint<T[K]> }\n : T;\n\n/** Key remapping that also preserves branded primitives. */\ntype SnakeKeys<T> = T extends readonly (infer U)[]\n ? readonly SnakeKeys<U>[]\n : T extends number | string | boolean | symbol | null | undefined\n ? T\n : T extends object\n ? { [K in keyof T as ToSnakeCase<Extract<K, string>>]: SnakeKeys<T[K]> }\n : T;\n\ntype ToSnakeCase<S extends string> = S extends `${infer Head}${infer Tail}`\n ? Tail extends Uncapitalize<Tail>\n ? `${Lowercase<Head>}${ToSnakeCase<Tail>}`\n : `${Lowercase<Head>}_${ToSnakeCase<Uncapitalize<Tail>>}`\n : S;\n\n/**\n * Formats object keys to snake case.\n * Preserves ethereum addresses as is.\n * Converts ethereum addresses to checksummed if used as values.\n * Stringifies bigint values to strings.\n */\nexport function toSnakeCase<T>(obj: T): Snake<T> {\n return stringifyBigint(\n processObject(\n obj,\n (s: string) => s.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`),\n (value: unknown) =>\n typeof value === \"string\" && isAddress(value.toLowerCase())\n ? getAddress(value.toLowerCase())\n : value,\n ),\n ) as Snake<T>;\n}\n\n/**\n * Formats a snake case object to its camel case type.\n * Preserves ethereum addresses as is.\n * Converts checksummed ethereum addresses to lowercase if used as values.\n * @warning Does not unstringify bigint values.\n */\nexport function fromSnakeCase<T>(obj: Snake<T>): T {\n return processObject(\n obj,\n (s: string) =>\n isAddress(s.toLowerCase()) ? s : s.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),\n (value: unknown) =>\n typeof value === \"string\" && isAddress(value.toLowerCase()) ? value.toLowerCase() : value,\n ) as T;\n}\n\nfunction processObject<T>(\n obj: T,\n fnKey: (str: string) => string,\n fnValue: (value: unknown) => unknown,\n): unknown {\n if (typeof obj !== \"object\" || obj === null) return obj;\n\n if (Array.isArray(obj)) return obj.map((item) => processObject(item, fnKey, fnValue));\n\n return Object.entries(obj as Record<string, unknown>).reduce(\n (acc, [key, value]) => {\n const newKey = fnKey(key);\n acc[newKey] =\n typeof value === \"object\" && value !== null\n ? processObject(value, fnKey, fnValue)\n : fnValue(value);\n\n return acc;\n },\n {} as Record<string, unknown>,\n );\n}\n\nexport function stringifyBigint<T>(value: T): StringifiedBigint<T> {\n if (typeof value === \"bigint\") return value.toString() as StringifiedBigint<T>;\n if (Array.isArray(value)) return value.map(stringifyBigint) as StringifiedBigint<T>;\n if (value && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value)) {\n out[k] = stringifyBigint(v);\n }\n return out as StringifiedBigint<T>;\n }\n\n return value as StringifiedBigint<T>;\n}\n","import { type Address, encodeAbiParameters, type Hex, keccak256 } from \"viem\";\nimport * as z from \"zod\";\nimport type { Offer } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress } from \"#utils/zod.ts\";\nimport type * as Chain from \"./Chain.ts\";\nimport * as Collateral from \"./Collateral.ts\";\nimport * as Maturity from \"./Maturity.ts\";\n\nexport type Obligation = {\n /** The chain id where the liquidity for this obligation is located. */\n chainId: Chain.Id;\n /** The token that is being borrowed for this obligation. */\n loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. */\n collaterals: Collateral.Collateral[];\n /** The maturity of the obligation. */\n maturity: Maturity.Maturity;\n};\n\nexport const ObligationSchema = z.object({\n chainId: z.number().min(0).max(Number.MAX_SAFE_INTEGER),\n loanToken: z.string().transform(transformAddress),\n collaterals: Collateral.CollateralsSchema,\n maturity: Maturity.MaturitySchema,\n});\n\n/**\n * Creates an obligation from the given parameters.\n * @constructor\n * @param parameters - {@link from.Parameters}\n * @returns The created obligation. {@link Obligation}\n * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}\n *\n * @example\n * ```ts\n * const obligation = Obligation.from({\n * chainId: 1,\n * loanToken: privateKeyToAccount(generatePrivateKey()).address,\n * collaterals: [\n * Collateral.from({\n * asset: privateKeyToAccount(generatePrivateKey()).address,\n * oracle: privateKeyToAccount(generatePrivateKey()).address,\n * lltv: 0.965\n * }),\n * ],\n * maturity: Maturity.from(\"end_of_next_quarter\"),\n * });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n try {\n const parsedObligation = ObligationSchema.parse({\n ...parameters,\n maturity: Maturity.from(parameters.maturity),\n });\n\n return {\n chainId: parsedObligation.chainId as Chain.Id,\n loanToken: parsedObligation.loanToken.toLowerCase() as Address,\n collaterals: parsedObligation.collaterals.sort((a, b) => a.asset.localeCompare(b.asset)),\n maturity: parsedObligation.maturity,\n };\n } catch (error: unknown) {\n throw new InvalidObligationError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n type Parameters = {\n /** The chain id where the liquidity for this obligation is located. */\n chainId: number;\n /** The token that is being borrowed for this obligation. */\n loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. Must be sorted alphabetically by address. */\n collaterals: Collateral.from.Parameters[] | readonly Collateral.from.Parameters[];\n /** The maturity of the obligation. */\n maturity: Maturity.from.Parameters;\n };\n\n type ReturnType = Obligation;\n\n export type ErrorType = InvalidObligationError;\n}\n\n/**\n * Creates an obligation from a snake case object.\n * @throws If the obligation is invalid. {@link fromSnakeCase.ErrorType}\n * @param input - {@link fromSnakeCase.Parameters}\n * @returns The created obligation. {@link fromSnakeCase.ReturnType}\n */\nexport function fromSnakeCase(input: fromSnakeCase.Parameters): fromSnakeCase.ReturnType {\n return from(Format.fromSnakeCase<Omit<Obligation, \"chainId\"> & { chainId: number }>(input));\n}\n\nexport declare namespace fromSnakeCase {\n type Parameters = Format.Snake<Omit<Obligation, \"chainId\"> & { chainId: number }>;\n type ReturnType = Obligation;\n type ErrorType = InvalidObligationError;\n}\n\n/**\n * Calculates the obligation id based on the smart contract's Obligation struct.\n * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals, maturity)).\n * @throws If the collaterals are not sorted alphabetically by address. {@link CollateralsAreNotSortedError}\n * @param parameters - {@link id.Parameters}\n * @returns The obligation id as a 32-byte hex string. {@link id.ReturnType}\n *\n * @example\n * ```ts\n * const obligation = Obligation.random();\n * const id = Obligation.id(obligation);\n * console.log(id); // 0x1234567890123456789012345678901234567890123456789012345678901234\n * ```\n */\nexport function id(parameters: id.Parameters): id.ReturnType {\n let lastAsset = \"\";\n for (const collateral of parameters.collaterals) {\n const newAsset = collateral.asset.toLowerCase();\n if (newAsset.localeCompare(lastAsset) < 0) throw new CollateralsAreNotSortedError();\n lastAsset = newAsset;\n }\n\n return keccak256(\n encodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"address\" },\n {\n type: \"tuple[]\",\n components: [\n { type: \"address\", name: \"token\" },\n { type: \"uint256\", name: \"lltv\" },\n { type: \"address\", name: \"oracle\" },\n ],\n },\n { type: \"uint256\" },\n ],\n [\n BigInt(parameters.chainId),\n parameters.loanToken.toLowerCase() as Address,\n parameters.collaterals.map((c) => ({\n token: c.asset.toLowerCase() as Address,\n lltv: c.lltv,\n oracle: c.oracle.toLowerCase() as Address,\n })),\n BigInt(parameters.maturity),\n ],\n ),\n );\n}\n\nexport declare namespace id {\n type Parameters = {\n chainId: number;\n loanToken: Address;\n collaterals: {\n asset: Address;\n lltv: bigint;\n oracle: Address;\n }[];\n maturity: number;\n };\n type ReturnType = Hex;\n type ErrorType = CollateralsAreNotSortedError;\n}\n\n/**\n * Generates a random obligation.\n * @returns A randomly generated obligation. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const obligation = Obligation.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n chainId: 1,\n loanToken: Random.address(),\n collaterals: [Collateral.random()],\n maturity: Maturity.from(\"end_of_next_quarter\"),\n });\n}\n\nexport declare namespace random {\n type ReturnType = Obligation;\n}\n\n/**\n * Creates an obligation from an offer.\n * @constructor\n *\n * @param offer - The offer to create the obligation from.\n * @returns The created obligation. {@link fromOffer.ReturnType}\n */\nexport function fromOffer(offer: Offer.Offer): fromOffer.ReturnType {\n return from({\n chainId: offer.chainId,\n loanToken: offer.loanToken,\n collaterals: offer.collaterals,\n maturity: offer.maturity,\n });\n}\n\nexport declare namespace fromOffer {\n type Parameters = Offer.Offer;\n type ReturnType = Obligation;\n}\n\nexport class InvalidObligationError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Obligation.InvalidObligationError\";\n constructor(error: z.ZodError | Error) {\n super(\"Invalid obligation.\", { cause: error });\n }\n}\n\nexport class CollateralsAreNotSortedError extends Errors.BaseError {\n override readonly name = \"Obligation.CollateralsAreNotSortedError\";\n constructor() {\n super(\"Collaterals are not sorted alphabetically by address.\");\n }\n}\n","import {\n type Address,\n type DecodeAbiParametersReturnType,\n decodeAbiParameters,\n encodeAbiParameters,\n type Hex,\n hashTypedData,\n maxUint256,\n zeroAddress,\n} from \"viem\";\nimport * as z from \"zod\";\nimport type { Compute } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformAddress, transformBytes32, transformHex } from \"#utils/zod.ts\";\nimport * as Callback from \"./Callback.ts\";\nimport * as Chain from \"./Chain.ts\";\nimport * as Collateral from \"./Collateral.ts\";\nimport * as LLTV from \"./LLTV.ts\";\nimport * as Maturity from \"./Maturity.ts\";\nimport * as Obligation from \"./Obligation.ts\";\n\n/** Internal symbol for caching the computed hash. */\nconst HASH_CACHE = Symbol(\"offer.hash\");\n\nexport type Offer = {\n /** The address that made the offer. */\n readonly maker: Address;\n /** The amount of assets offered. Mutually exclusive with obligationUnits and obligationShares. */\n readonly assets: bigint;\n /** The max debt units to trade. Mutually exclusive with assets and obligationShares. */\n readonly obligationUnits: bigint;\n /** The max lending shares to trade. Mutually exclusive with assets and obligationUnits. */\n readonly obligationShares: bigint;\n /** The price (18 decimals). */\n readonly price: bigint;\n /** The date at which all interests will be paid. */\n readonly maturity: Maturity.Maturity;\n /** The date at which the offer will expire. */\n readonly expiry: number;\n /** The date at which the offer will start. */\n readonly start: number;\n /** The group. Used for OCO (One-Cancelled-Other) mechanism. */\n readonly group: Hex;\n /** The session. Used for session-based offer management. */\n readonly session: Hex;\n /** The side of the offer. `true` for buy, `false` for sell. */\n readonly buy: boolean;\n /** The chain id where the liquidity for this offer is located. */\n readonly chainId: Chain.Id;\n /** The token that is being borrowed. */\n readonly loanToken: Address;\n /** The exact set of collaterals required to borrow the loan token. */\n readonly collaterals: readonly Collateral.Collateral[];\n /** The optional callback data to retrieve the maker funds. */\n readonly callback: {\n readonly address: Address;\n readonly data: Hex;\n };\n};\n\nexport enum Status {\n VALID = \"VALID\",\n SIMULATION_ERROR = \"SIMULATION_ERROR\",\n}\n\nexport type Validation = {\n offerHash: Hex;\n status: Status;\n};\n\nexport const OfferSchema = () => {\n return z\n .object({\n maker: z.string().transform(transformAddress),\n assets: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n obligationUnits: z.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),\n obligationShares: z.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n maturity: Maturity.MaturitySchema,\n expiry: z.number().int().max(Number.MAX_SAFE_INTEGER),\n start: z.number().int().max(Number.MAX_SAFE_INTEGER),\n group: z.union([z.string(), z.number(), z.bigint()]).transform(transformBytes32),\n session: z\n .union([z.string(), z.number(), z.bigint()])\n .optional()\n .default(\"0x0000000000000000000000000000000000000000000000000000000000000000\")\n .transform(transformBytes32),\n buy: z.boolean(),\n chainId: z.number().min(0).max(Number.MAX_SAFE_INTEGER),\n loanToken: z.string().transform(transformAddress),\n collaterals: Collateral.CollateralsSchema,\n callback: z.object({\n address: z.string().transform(transformAddress),\n data: z.string().transform(transformHex),\n }),\n })\n .refine((data) => data.start < data.expiry, {\n message: \"start must be before expiry\",\n path: [\"start\"],\n })\n .refine((data) => data.expiry <= data.maturity, {\n message: \"expiry must be before or equal to maturity\",\n path: [\"expiry\"],\n });\n};\n\n/**\n * Input type for creating offers. Accepts flexible group types that will be coerced to Hex.\n *\n * The `group` field accepts multiple input formats:\n * - **Hex string** (`0x...`): Padded to 32 bytes if needed\n * - **Numeric string**: Converted to hex (e.g., `\"123\"` -> `\"0x...7b\"`)\n * - **Number**: Non-negative safe integer, converted to hex\n * - **BigInt**: Non-negative, must fit in bytes32\n *\n * All values validated to be non-negative and within bytes32 range.\n */\nexport type OfferInput = Compute<\n Omit<Offer, \"chainId\" | \"group\" | \"session\" | \"obligationUnits\" | \"obligationShares\"> & {\n chainId: number;\n group: Hex | bigint | number | string;\n /** Optional: defaults to zero bytes32. */\n session?: Hex | bigint | number | string;\n /** Optional: defaults to 0n. Mutually exclusive with assets and obligationShares. */\n obligationUnits?: bigint;\n /** Optional: defaults to 0n. Mutually exclusive with assets and obligationUnits. */\n obligationShares?: bigint;\n }\n>;\n\n/**\n * Creates an offer from a plain object.\n * @throws {InvalidOfferError} If the offer is invalid.\n * @param input - The offer to create.\n * @returns The created offer.\n */\nexport function from(input: OfferInput): Offer {\n try {\n return OfferSchema().parse(input) as Offer;\n } catch (error: unknown) {\n throw new InvalidOfferError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n export type ErrorType = InvalidOfferError;\n}\n\n/**\n * Creates an offer from a snake case object.\n * @throws {InvalidOfferError} If the offer is invalid.\n * @param input - The offer to create.\n * @returns The created offer.\n */\nexport function fromSnakeCase(\n input: Format.Snake<Omit<Offer, \"chainId\" | \"session\"> & { chainId: number; session: string }>,\n): Offer {\n return from(\n Format.fromSnakeCase<Omit<Offer, \"chainId\" | \"session\"> & { chainId: number; session: string }>(\n input,\n ),\n );\n}\n\n/**\n * Converts an offer to a snake case object.\n * @param offer - The offer to convert.\n * @returns The converted offer.\n */\nexport function toSnakeCase(offer: Offer): Format.Snake<Offer> {\n return Format.toSnakeCase(offer);\n}\n\n/**\n * Serializes an offer for merkle tree encoding.\n * Converts BigInt fields to strings for JSON compatibility.\n *\n * @param offer - Offer to serialize\n * @returns JSON-serializable offer object\n */\nexport const serialize = (offer: Offer) => ({\n maker: offer.maker,\n assets: offer.assets.toString(),\n obligationUnits: offer.obligationUnits.toString(),\n obligationShares: offer.obligationShares.toString(),\n price: offer.price.toString(),\n maturity: Number(offer.maturity),\n expiry: Number(offer.expiry),\n start: Number(offer.start),\n group: offer.group,\n session: offer.session,\n buy: offer.buy,\n chainId: offer.chainId,\n loanToken: offer.loanToken,\n collaterals: offer.collaterals.map((c) => ({\n asset: c.asset,\n oracle: c.oracle,\n lltv: c.lltv.toString(),\n })),\n callback: {\n address: offer.callback.address,\n data: offer.callback.data,\n },\n hash: hash(offer),\n});\n\nexport type RandomConfig = {\n chains?: Chain.Chain[];\n loanTokens?: Address[];\n collateralTokens?: Address[];\n assetsDecimals?: Record<Address, number>;\n buy?: boolean;\n assets?: bigint;\n obligationUnits?: bigint;\n obligationShares?: bigint;\n maker?: Address;\n maturity?: Maturity.Maturity;\n start?: number;\n expiry?: number;\n group?: Hex | bigint | number | string;\n session?: Hex | bigint | number | string;\n price?: bigint;\n callback?: {\n address: Address;\n data: Hex;\n };\n collaterals?: readonly Collateral.Collateral[];\n};\n\n/**\n * Generates a random Offer.\n * The returned Offer contains randomly generated values.\n * @warning The generated Offer should not be used for production usage.\n * @returns {Offer} A randomly generated Offer object.\n */\nexport function random(config?: RandomConfig): Offer {\n const chain = config?.chains\n ? config.chains[Random.int(config.chains.length)]!\n : Chain.chains.ethereum;\n\n const loanToken = config?.loanTokens\n ? config.loanTokens[Random.int(config.loanTokens.length)]!\n : Random.address();\n\n const collateralCandidates = config?.collateralTokens\n ? config.collateralTokens.filter((a) => a !== loanToken)\n : [Random.address()];\n\n const collateralAsset = collateralCandidates[Random.int(collateralCandidates.length)]!;\n\n const maturityOption = weightedChoice<Maturity.MaturityOptions>([\n [\"end_of_month\", 1],\n [\"end_of_next_month\", 1],\n ]);\n\n const maturity = config?.maturity ?? Maturity.from(maturityOption);\n\n const lltv = LLTV.from(\n weightedChoice<(typeof LLTV.Options)[number]>([\n [0.385, 1],\n [0.5, 1],\n [0.625, 2],\n [0.77, 8],\n [0.86, 10],\n [0.915, 8],\n [0.945, 6],\n [0.965, 4],\n [0.98, 2],\n ]),\n );\n\n const buy = config?.buy !== undefined ? config.buy : Random.bool();\n\n // Price spread grid with step 0.25, ranges by side:\n // - Buy: [4.00, 8.00]\n // - Sell: [1.00, 4.00]\n const ONE = 1000000000000000000n; // 1e18\n const qMin = buy ? 16 : 4; // quarters (4.00 => 16, 8.00 => 32, 1.00 => 4)\n const qMax = buy ? 32 : 16;\n const len = qMax - qMin + 1;\n const pricePairs: ReadonlyArray<readonly [bigint, number]> = Array.from(\n { length: len },\n (_, idx) => {\n const q = qMin + idx; // number of quarters (0.25)\n const scaledPrice = BigInt(q) * (ONE / 4n);\n // Make best prices rarer and worse prices more common (by side):\n // - Buy best is lower price => weight increases with idx (higher price)\n // - Sell best is higher price => weight decreases with idx\n const weight = buy ? 1 + idx : 1 + (len - 1 - idx);\n return [scaledPrice, weight] as const;\n },\n );\n const price = config?.price ?? weightedChoice<bigint>(pricePairs);\n\n const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;\n const unit = BigInt(10) ** BigInt(loanTokenDecimals);\n const amountBase = BigInt(100 + Random.int(1_000_000 - 100 + 1));\n const assetsScaled = config?.assets ?? amountBase * unit;\n\n const callbackBySide = (() => {\n if (buy) return { address: zeroAddress, data: \"0x\" as Hex } as const;\n const sellCallbackAddress = \"0x3333333333333333333333333333333333333333\" as Address;\n const amount = assetsScaled * 1000000000000000000000n;\n const data = Callback.encodeSellERC20Callback({\n collaterals: [collateralAsset],\n amounts: [amount],\n });\n return { address: sellCallbackAddress, data } as const;\n })();\n\n const offer = from({\n maker: config?.maker ?? Random.address(),\n assets: assetsScaled,\n obligationUnits: config?.obligationUnits ?? 0n,\n obligationShares: config?.obligationShares ?? 0n,\n price,\n maturity: maturity,\n expiry: config?.expiry ?? maturity - 1,\n start: config?.start ?? maturity - 10,\n group: config?.group ?? Random.hex(32),\n session: config?.session ?? Random.hex(32),\n buy,\n chainId: chain.id,\n loanToken,\n collaterals:\n config?.collaterals ??\n Array.from({ length: Random.int(3) + 1 }, () => ({\n ...Collateral.random(),\n lltv,\n })).sort((a, b) => a.asset.localeCompare(b.asset)),\n callback: config?.callback ?? callbackBySide,\n });\n\n return offer;\n}\n\nconst weightedChoice = <T>(pairs: ReadonlyArray<readonly [T, number]>): T => {\n const total = pairs.reduce((sum, [, weight]) => sum + weight, 0);\n let roll = Random.float() * total;\n for (const [value, weight] of pairs) {\n roll -= weight;\n if (roll < 0) return value;\n }\n return pairs[0]![0];\n};\n\n/**\n * Creates an EIP-712 domain object.\n * @param chainId - The chain ID.\n * @returns The EIP-712 domain object.\n */\nexport const domain = (chainId: number) => ({\n chainId: BigInt(chainId),\n verifyingContract: zeroAddress,\n});\n\n/**\n * The EIP-712 types for the offer.\n * @warning The ordering of the types should NEVER be changed. The offer hash is computed based on the order of the types.\n * @returns The EIP-712 types.\n */\nexport const types = {\n EIP712Domain: [\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n ],\n Offer: [\n { name: \"maker\", type: \"address\" },\n { name: \"assets\", type: \"uint256\" },\n { name: \"obligationUnits\", type: \"uint256\" },\n { name: \"obligationShares\", type: \"uint256\" },\n { name: \"price\", type: \"uint256\" },\n { name: \"maturity\", type: \"uint256\" },\n { name: \"expiry\", type: \"uint256\" },\n { name: \"group\", type: \"bytes32\" },\n { name: \"session\", type: \"bytes32\" },\n { name: \"buy\", type: \"bool\" },\n { name: \"loanToken\", type: \"address\" },\n { name: \"collaterals\", type: \"Collateral[]\" },\n { name: \"callback\", type: \"Callback\" },\n ],\n Collateral: [\n { name: \"asset\", type: \"address\" },\n { name: \"oracle\", type: \"address\" },\n { name: \"lltv\", type: \"uint256\" },\n ],\n Callback: [\n { name: \"address\", type: \"address\" },\n { name: \"data\", type: \"bytes\" },\n ],\n} as const;\n\nexport function hash(offer: Offer): Hex {\n const cached = (offer as { [HASH_CACHE]?: Hex })[HASH_CACHE];\n if (cached) return cached;\n\n const computed = hashTypedData({\n domain: domain(offer.chainId),\n message: {\n maker: offer.maker.toLowerCase() as Address,\n assets: offer.assets,\n obligationUnits: offer.obligationUnits,\n obligationShares: offer.obligationShares,\n price: offer.price,\n maturity: BigInt(offer.maturity),\n expiry: BigInt(offer.expiry),\n group: offer.group,\n session: offer.session,\n buy: offer.buy,\n loanToken: offer.loanToken.toLowerCase() as Address,\n collaterals: offer.collaterals,\n callback: {\n address: offer.callback.address.toLowerCase() as Address,\n data: offer.callback.data,\n },\n },\n primaryType: \"Offer\",\n types,\n });\n\n (offer as { [HASH_CACHE]?: Hex })[HASH_CACHE] = computed;\n return computed;\n}\n\n/**\n * Calculates the obligation id for an offer based on the smart contract's Obligation struct.\n * The id is computed as keccak256(abi.encode(chainId, loanToken, collaterals (sorted by token address), maturity)).\n * @param offer - The offer to calculate the obligation id for.\n * @returns The obligation id as a 32-byte hex string.\n */\nexport function obligationId(offer: Offer): Hex {\n return Obligation.id(\n Obligation.from({\n chainId: offer.chainId,\n loanToken: offer.loanToken,\n collaterals: offer.collaterals as Collateral.Collateral[],\n maturity: offer.maturity,\n }),\n );\n}\n\nconst OfferAbi = [\n { name: \"maker\", type: \"address\" },\n { name: \"assets\", type: \"uint256\" },\n { name: \"obligationUnits\", type: \"uint256\" },\n { name: \"obligationShares\", type: \"uint256\" },\n { name: \"price\", type: \"uint256\" },\n { name: \"maturity\", type: \"uint256\" },\n { name: \"expiry\", type: \"uint256\" },\n { name: \"group\", type: \"bytes32\" },\n { name: \"session\", type: \"bytes32\" },\n { name: \"buy\", type: \"bool\" },\n { name: \"chainId\", type: \"uint256\" },\n { name: \"loanToken\", type: \"address\" },\n { name: \"start\", type: \"uint256\" },\n {\n name: \"collaterals\",\n type: \"tuple[]\",\n components: [\n { name: \"asset\", type: \"address\" },\n { name: \"oracle\", type: \"address\" },\n { name: \"lltv\", type: \"uint256\" },\n ],\n },\n {\n name: \"callback\",\n type: \"tuple\",\n components: [\n { name: \"address\", type: \"address\" },\n { name: \"data\", type: \"bytes\" },\n ],\n },\n] as const;\n\nexport function encode(offer: Offer) {\n return encodeAbiParameters(OfferAbi, [\n offer.maker,\n offer.assets,\n offer.obligationUnits,\n offer.obligationShares,\n offer.price,\n BigInt(offer.maturity),\n BigInt(offer.expiry),\n offer.group,\n offer.session,\n offer.buy,\n BigInt(offer.chainId),\n offer.loanToken,\n BigInt(offer.start),\n offer.collaterals,\n offer.callback,\n ]);\n}\n\nexport function decode(data: Hex): Offer {\n let decoded: DecodeAbiParametersReturnType<typeof OfferAbi>;\n try {\n decoded = decodeAbiParameters(OfferAbi, data);\n } catch (error) {\n throw new InvalidOfferError(error as Error);\n }\n\n const offer = from({\n maker: decoded[0],\n assets: decoded[1],\n obligationUnits: decoded[2],\n obligationShares: decoded[3],\n price: decoded[4],\n maturity: Maturity.from(Number(decoded[5])),\n expiry: Number(decoded[6]),\n group: decoded[7],\n session: decoded[8],\n buy: decoded[9],\n chainId: Number(decoded[10]),\n loanToken: decoded[11],\n start: Number(decoded[12]),\n collaterals: decoded[13].map((c) => {\n return Collateral.from({\n asset: c.asset,\n oracle: c.oracle,\n lltv: c.lltv,\n });\n }),\n callback: {\n address: decoded[14].address,\n data: decoded[14].data,\n },\n });\n\n return offer;\n}\n\nexport type OfferConsumed = {\n id: string;\n chainId: Chain.Id;\n maker: Address;\n group: Hex;\n amount: bigint;\n blockNumber: number;\n};\n\n/**\n * ABI for the Consume event emitted by the Obligation contract.\n */\nexport const consumedEvent = {\n type: \"event\",\n name: \"Consume\",\n inputs: [\n { name: \"user\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"group\", type: \"bytes32\", indexed: true, internalType: \"bytes32\" },\n { name: \"amount\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n} as const;\n\nexport class InvalidOfferError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Offer.InvalidOfferError\";\n\n constructor(error: z.ZodError | Error) {\n super(\"Invalid offer.\", {\n cause: error,\n });\n }\n\n /**\n * Formats ZodError issues into a human-readable string with line breaks.\n * @example\n * \"- 'assets': too small, expected >= 0\n * - 'start': must be before expiry\"\n */\n static formatDetails(error: z.ZodError | Error): string {\n if (!(error instanceof z.ZodError)) {\n return error.message;\n }\n\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n const normalized = issue.message.trim();\n return `'${path}': ${normalized.toLowerCase()}`;\n })\n .join(\". \");\n }\n\n /**\n * Returns the formatted human-readable message.\n */\n get formattedMessage(): string {\n return `Invalid offer. ${InvalidOfferError.formatDetails(this.cause)}`;\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\nimport type * as Collateral from \"./Collateral.ts\";\nimport type * as Offer from \"./Offer.ts\";\n\n/**\n * An oracle contract that provides price information for assets.\n */\nexport type Oracle = {\n /** The chain id where the oracle is deployed. */\n readonly chainId: Chain.Id;\n /** The address of the oracle contract. */\n readonly address: Address;\n /** The price returned by the oracle (in the oracle's native units), null if no price available. */\n readonly price: bigint | null;\n /** The block number at which the price was fetched. */\n readonly blockNumber: number;\n};\n\n/**\n * Create an Oracle from a plain object.\n * @param data - The data to create the oracle from.\n * @returns The created oracle.\n */\nexport function from(data: from.Parameters): from.ReturnType {\n return {\n chainId: data.chainId,\n address: data.address.toLowerCase() as Address,\n price: data.price ? BigInt(data.price) : null,\n blockNumber: data.blockNumber,\n };\n}\n\nexport declare namespace from {\n export type Parameters = {\n chainId: Chain.Id;\n address: Address;\n price: string | null;\n blockNumber: number;\n };\n\n export type ReturnType = Oracle;\n}\n\n/**\n * Creates an oracle from a collateral.\n * @constructor\n *\n * @param parameters - {@link fromCollateral.Parameters}\n * @returns The created oracle. {@link fromCollateral.ReturnType}\n */\nexport function fromCollateral(parameters: fromCollateral.Parameters): fromCollateral.ReturnType {\n const { chainId, collateral, blockNumber, price = null } = parameters;\n return {\n chainId,\n address: collateral.oracle.toLowerCase() as Address,\n price,\n blockNumber,\n };\n}\n\nexport declare namespace fromCollateral {\n export type Parameters = {\n chainId: Chain.Id;\n collateral: Collateral.Collateral;\n blockNumber: number;\n price?: bigint | null;\n };\n\n export type ReturnType = Oracle;\n}\n\n/**\n * Creates oracles from a single offer.\n * @constructor\n *\n * @param parameters - {@link fromOffer.Parameters}\n * @returns The created oracles. {@link fromOffer.ReturnType}\n */\nexport function fromOffer(parameters: fromOffer.Parameters): fromOffer.ReturnType {\n const { offer, blockNumber, price = null } = parameters;\n return fromOffers({ offers: [offer], blockNumber, price });\n}\n\nexport declare namespace fromOffer {\n export type Parameters = {\n offer: Offer.Offer;\n blockNumber: number;\n price?: bigint | null;\n };\n\n export type ReturnType = Oracle[];\n}\n\n/**\n * Creates oracles from a list of offers.\n * @constructor\n *\n * @param parameters - {@link fromOffers.Parameters}\n * @returns The created oracles. {@link fromOffers.ReturnType}\n */\nexport function fromOffers(parameters: fromOffers.Parameters): fromOffers.ReturnType {\n const { offers, blockNumber, price = null } = parameters;\n const rowsByKey = new Map<string, Oracle>();\n\n for (const offer of offers) {\n for (const collateral of offer.collaterals) {\n const key = `${offer.chainId}-${collateral.oracle}`.toLowerCase();\n if (rowsByKey.has(key)) continue;\n rowsByKey.set(\n key,\n fromCollateral({\n chainId: offer.chainId,\n collateral,\n blockNumber,\n price,\n }),\n );\n }\n }\n\n return Array.from(rowsByKey.values());\n}\n\nexport declare namespace fromOffers {\n export type Parameters = {\n offers: Offer.Offer[];\n blockNumber: number;\n price?: bigint | null;\n };\n\n export type ReturnType = Oracle[];\n}\n\n/**\n * Conversion utilities for converting between collateral and loan token amounts\n * using oracle prices and LLTV\n */\nexport namespace Conversion {\n /**\n * Converts a collateral amount to loan token\n * Uses the formula: (amount * price / 10^36) * lltv / 10^18\n *\n * @param amount - The collateral amount to convert\n * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)\n * @returns The equivalent loan token amount\n */\n export function collateralToLoan(\n amount: bigint,\n params: { price: bigint; lltv: bigint },\n ): bigint {\n return (((amount * params.price) / 10n ** 36n) * params.lltv) / 10n ** 18n;\n }\n\n /**\n * Converts a loan token amount to collateral\n * Uses the inverse formula: (amount * 10^36 / price) * 10^18 / lltv\n * Returns 0n if price or lltv is zero (invalid conversion).\n *\n * @param amount - The loan token amount to convert\n * @param params - Conversion parameters containing price (36 decimals) and lltv (18 decimals)\n * @returns The equivalent collateral amount, or 0n if conversion is invalid\n */\n export function loanToCollateral(\n amount: bigint,\n params: { price: bigint; lltv: bigint },\n ): bigint {\n if (params.price === 0n || params.lltv === 0n) return 0n;\n return (((amount * 10n ** 36n) / params.price) * 10n ** 18n) / params.lltv;\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\n\nexport type Position = {\n /** The chain id. */\n chainId: Chain.Id;\n /** The contract address from which the position is called.\n * While balances are obviously tracked on ERC20 contracts, we prefer to track which contract is called to know the balance.\n * 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.\n */\n contract: Address;\n /** The user address. */\n user: Address;\n /** The type of position. */\n type: Type;\n /** The balance of the position. */\n balance?: bigint;\n /** The underlying asset of the position.\n * For ERC20 positions, this equals the contract address.\n * For vault positions, this is the vault's underlying asset.\n */\n asset?: Address;\n /** The block number at which the position was last updated. */\n blockNumber: number;\n};\n\nexport enum Type {\n ERC20 = \"erc20\",\n VAULT_V1 = \"vault_v1\",\n}\n\n/**\n * @constructor\n * Creates a Position.\n * @param parameters - {@link from.Parameters}\n * @returns The created Position. {@link from.ReturnType}\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n return {\n chainId: parameters.chainId,\n contract: parameters.contract.toLowerCase() as Address,\n user: parameters.user.toLowerCase() as Address,\n type: parameters.type,\n balance: parameters.balance,\n ...(parameters.asset !== undefined ? { asset: parameters.asset.toLowerCase() as Address } : {}),\n blockNumber: parameters.blockNumber,\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n chainId: Chain.Id;\n contract: Address;\n user: Address;\n type: Type;\n balance?: bigint;\n asset?: Address;\n blockNumber: number;\n };\n type ReturnType = Position;\n}\n","import { type Hex, maxUint256 } from \"viem\";\nimport * as z from \"zod\";\nimport { Obligation } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Format from \"#utils/Format.ts\";\nimport * as Random from \"#utils/Random.ts\";\nimport { transformHex } from \"#utils/zod.ts\";\n\nexport type Quote = {\n /** The obligation id. */\n obligationId: Hex;\n ask: {\n /** The ask price for the obligation. (18 decimals). */\n price: bigint;\n };\n bid: {\n /** The bid price for the obligation. (18 decimals). */\n price: bigint;\n };\n};\n\nexport const QuoteSchema = z.object({\n obligationId: z.string().transform(transformHex),\n ask: z.object({\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n }),\n bid: z.object({\n price: z.bigint({ coerce: true }).min(0n).max(maxUint256),\n }),\n});\n\n/**\n * Creates a quote for a given obligation.\n * @constructor\n * @param parameters - {@link from.Parameters}\n * @returns The created quote. {@link Quote}\n * @throws If the quote is invalid. {@link InvalidQuoteError}\n *\n * @example\n * ```ts\n * const quote = Quote.from({ obligationId: \"0x123\", ask: { price: 100n }, bid: { price: 100n } });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n try {\n const parsedQuote = QuoteSchema.parse(parameters);\n return {\n obligationId: parsedQuote.obligationId,\n ask: parsedQuote.ask,\n bid: parsedQuote.bid,\n };\n } catch (error: unknown) {\n throw new InvalidQuoteError(error as z.ZodError | Error);\n }\n}\n\nexport declare namespace from {\n type Parameters = Quote;\n type ReturnType = Quote;\n type ErrorType = InvalidQuoteError;\n}\n\n/**\n * Creates a quote from a snake case object.\n * @throws If the quote is invalid. {@link InvalidQuoteError}\n * @param snake - {@link fromSnakeCase.Parameters}\n * @returns The created quote. {@link fromSnakeCase.ReturnType}\n */\nexport function fromSnakeCase(snake: fromSnakeCase.Parameters): fromSnakeCase.ReturnType {\n return from(Format.fromSnakeCase<Quote>(snake));\n}\n\nexport declare namespace fromSnakeCase {\n type Parameters = Format.Snake<Quote>;\n type ReturnType = Quote;\n type ErrorType = from.ErrorType;\n}\n\n/**\n * Generates a random quote.\n * @returns A randomly generated quote. {@link random.ReturnType}\n *\n * @example\n * ```ts\n * const quote = Quote.random();\n * ```\n */\nexport function random(): random.ReturnType {\n return from({\n obligationId: Obligation.id(Obligation.random()),\n ask: {\n price: BigInt(Random.int(1_000_000)),\n },\n bid: {\n price: BigInt(Random.int(1_000_000)),\n },\n });\n}\n\nexport declare namespace random {\n type Parameters = never;\n type ReturnType = Quote;\n type ErrorType = from.ErrorType;\n}\n\nexport class InvalidQuoteError extends Errors.BaseError<z.ZodError | Error> {\n override readonly name = \"Quote.InvalidQuoteError\";\n constructor(error: z.ZodError | Error) {\n super(\"Invalid quote.\", { cause: error });\n }\n}\n","import * as Errors from \"#utils/Errors.ts\";\nimport type { Brand } from \"./types.ts\";\n\n/**\n * Time breakpoints in seconds for piecewise linear fee interpolation.\n * Matches on-chain constants: 0d, 1d, 7d, 30d, 90d, 180d.\n */\nexport const BREAKPOINTS = [\n 0n,\n 86400n, // 1 day\n 604800n, // 7 days\n 2592000n, // 30 days\n 7776000n, // 90 days\n 15552000n, // 180 days\n] as const;\n\n/** WAD constant (1e18) for fee scaling. */\nexport const WAD = 10n ** 18n;\n\n/** Tuple type for the 6 fee values at each breakpoint. */\nexport type Fees = readonly [bigint, bigint, bigint, bigint, bigint, bigint];\n\n/**\n * TradingFee represents a piecewise linear fee curve with 6 breakpoints.\n * The internal storage mimics on-chain bitmap behavior but uses a struct for clarity.\n */\nexport type TradingFee = {\n readonly _activated: boolean;\n readonly _fees: Fees;\n} & Brand<\"TradingFee\">;\n\n/**\n * Create a TradingFee from an activation flag and 6 fee values.\n * @param activated - Whether the fee is active.\n * @param fees - Tuple of 6 fee values in WAD (one per breakpoint: 0d, 1d, 7d, 30d, 90d, 180d).\n * @returns A new TradingFee instance.\n * @throws {@link InvalidFeeError} if any fee exceeds WAD (100%).\n * @throws {@link InvalidFeesLengthError} if fees array doesn't have exactly 6 elements.\n */\nexport function from(activated: boolean, fees: Fees): TradingFee {\n if (fees.length !== 6) {\n throw new InvalidFeesLengthError(fees.length);\n }\n for (let i = 0; i < 6; i++) {\n const fee = fees[i] as bigint;\n if (fee < 0n || fee > WAD) {\n throw new InvalidFeeError(fee, i);\n }\n }\n // Defensive copy and freeze to guarantee immutability\n const frozenFees = Object.freeze([...fees]) as Fees;\n return Object.freeze({\n _activated: activated,\n _fees: frozenFees,\n }) as TradingFee;\n}\n\nexport declare namespace from {\n type ErrorType = InvalidFeeError | InvalidFeesLengthError;\n}\n\n/**\n * Compute the trading fee for a given time to maturity using piecewise linear interpolation.\n * @param tradingFee - The TradingFee instance.\n * @param timeToMaturity - Time to maturity in seconds.\n * @returns The interpolated fee in WAD. Returns 0n if not activated.\n */\nexport function compute(tradingFee: TradingFee, timeToMaturity: number): bigint {\n if (!tradingFee._activated) {\n return 0n;\n }\n\n const time = BigInt(Math.max(0, Math.floor(timeToMaturity)));\n\n // If beyond 180 days, return the 180d fee\n if (time >= BREAKPOINTS[5]) {\n return tradingFee._fees[5];\n }\n\n // Find the segment for interpolation\n const { index, start, end } = getSegment(time);\n\n const feeLower = tradingFee._fees[index] as bigint;\n const feeUpper = tradingFee._fees[index + 1] as bigint;\n\n // Linear interpolation: (feeLower * (end - t) + feeUpper * (t - start)) / (end - start)\n const segmentLength = end - start;\n return (feeLower * (end - time) + feeUpper * (time - start)) / segmentLength;\n}\n\n/**\n * Check if the trading fee is activated.\n * @param tradingFee - The TradingFee instance.\n * @returns True if activated, false otherwise.\n */\nexport function isActivated(tradingFee: TradingFee): boolean {\n return tradingFee._activated;\n}\n\n/**\n * Create a new TradingFee with activation enabled.\n * @param tradingFee - The TradingFee instance.\n * @returns A new TradingFee with activated set to true.\n */\nexport function activate(tradingFee: TradingFee): TradingFee {\n return Object.freeze({\n _activated: true,\n _fees: tradingFee._fees, // Already frozen from construction\n }) as TradingFee;\n}\n\n/**\n * Create a new TradingFee with activation disabled.\n * @param tradingFee - The TradingFee instance.\n * @returns A new TradingFee with activated set to false.\n */\nexport function deactivate(tradingFee: TradingFee): TradingFee {\n return Object.freeze({\n _activated: false,\n _fees: tradingFee._fees, // Already frozen from construction\n }) as TradingFee;\n}\n\n/**\n * Get the fee values at each breakpoint.\n * @param tradingFee - The TradingFee instance.\n * @returns The tuple of 6 fee values.\n */\nexport function getFees(tradingFee: TradingFee): Fees {\n return tradingFee._fees;\n}\n\n/**\n * Determine which segment a timeToMaturity falls into for interpolation.\n * @param timeToMaturity - Time to maturity in seconds.\n * @returns Object with index, start, and end of the segment.\n */\nfunction getSegment(timeToMaturity: bigint): { index: number; start: bigint; end: bigint } {\n if (timeToMaturity < BREAKPOINTS[1]) {\n return { index: 0, start: BREAKPOINTS[0], end: BREAKPOINTS[1] };\n }\n if (timeToMaturity < BREAKPOINTS[2]) {\n return { index: 1, start: BREAKPOINTS[1], end: BREAKPOINTS[2] };\n }\n if (timeToMaturity < BREAKPOINTS[3]) {\n return { index: 2, start: BREAKPOINTS[2], end: BREAKPOINTS[3] };\n }\n if (timeToMaturity < BREAKPOINTS[4]) {\n return { index: 3, start: BREAKPOINTS[3], end: BREAKPOINTS[4] };\n }\n return { index: 4, start: BREAKPOINTS[4], end: BREAKPOINTS[5] };\n}\n\n/** Error thrown when a fee value is invalid (negative or exceeds WAD). */\nexport class InvalidFeeError extends Errors.BaseError {\n override readonly name = \"TradingFee.InvalidFeeError\";\n constructor(fee: bigint, index: number) {\n super(`Invalid fee at index ${index}: ${fee}. Fee must be between 0 and ${WAD} (WAD).`);\n }\n}\n\n/** Error thrown when fees array doesn't have exactly 6 elements. */\nexport class InvalidFeesLengthError extends Errors.BaseError {\n override readonly name = \"TradingFee.InvalidFeesLengthError\";\n constructor(length: number) {\n super(`Invalid fees length: ${length}. Expected exactly 6 fee values.`);\n }\n}\n","import type { Address } from \"viem\";\nimport type * as Chain from \"./Chain.ts\";\n\nexport type Transfer = {\n id: string;\n chainId: Chain.Id;\n contract: Address;\n from: Address;\n to: Address;\n value: bigint;\n blockNumber: number;\n};\n\n/**\n * @constructor\n *\n * Creates a {@link Transfer}.\n * @param parameters - {@link from.Parameters}\n * @returns The created Transfer. {@link from.ReturnType}\n *\n * @example\n * ```ts\n * const transfer = Transfer.from({ id: \"1\", chainId: 1, contract: \"0x123\", from: \"0x456\", to: \"0x789\", value: 100n, blockNumber: 100n });\n * ```\n */\nexport function from(parameters: from.Parameters): from.ReturnType {\n return {\n id: parameters.id,\n chainId: parameters.chainId,\n contract: parameters.contract.toLowerCase() as Address,\n from: parameters.from.toLowerCase() as Address,\n to: parameters.to.toLowerCase() as Address,\n value: parameters.value,\n blockNumber: parameters.blockNumber,\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n id: string;\n chainId: Chain.Id;\n contract: Address;\n from: Address;\n to: Address;\n value: bigint;\n blockNumber: number;\n };\n\n type ReturnType = Transfer;\n}\n","import { StandardMerkleTree } from \"@openzeppelin/merkle-tree\";\nimport { gzip, ungzip } from \"pako\";\nimport {\n type Address,\n bytesToHex,\n type Hex,\n hashTypedData,\n hexToBytes,\n isAddress,\n isHex,\n recoverAddress,\n} from \"viem\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport * as Offer from \"./Offer.ts\";\nimport type { Compute } from \"./types.ts\";\n\n/**\n * A merkle tree of offers built from offer hashes.\n * Constructed via {@link from}. The tree root can be signed for onchain broadcast.\n */\nexport type Tree = Compute<\n StandardMerkleTree<[Hex]> & {\n /** The offers in the tree. */\n offers: Offer.Offer[];\n /** The root of the tree. */\n root: Hex;\n }\n>;\n\nexport type Proof = {\n /** The offer that the proof is for. */\n offer: Offer.Offer;\n /** The merkle proof path for the offer. */\n path: Hex[];\n};\n\nexport const VERSION = 1;\n\nexport type SignatureDomain = {\n /** Chain id used in the EIP-712 domain. */\n chainId: number | bigint;\n /** MorphoV2 contract address used as verifying contract. */\n verifyingContract: Address;\n};\n\n/** Normalized Root signature domain (BigInt chain id, lowercase address). */\nexport type NormalizedSignatureDomain = {\n chainId: bigint;\n verifyingContract: Address;\n};\n\n/**\n * EIP-712 types for signing the tree root (Root(bytes32 root)).\n */\nexport const signatureTypes = {\n EIP712Domain: [\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n ],\n Root: [{ name: \"root\", type: \"bytes32\" }],\n} as const;\n\nconst normalizeHash = (hash: Hex): Hex => hash.toLowerCase() as Hex;\n\n/**\n * Builds a Merkle tree from a list of offers.\n *\n * Leaves are the offer `hash` values as `bytes32` and are deterministically\n * ordered following the StandardMerkleTree leaf ordering so that the resulting\n * root is stable regardless of the input order.\n *\n * @param offers - Offers to include in the tree.\n * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.\n * @throws {TreeError} If tree building fails due to offer inconsistencies.\n */\nexport const from = (offers: Offer.Offer[]): Tree => {\n const leaves = offers.map<[Hex]>((offer) => [Offer.hash(offer)]);\n const tree = StandardMerkleTree.of<[Hex]>(leaves, [\"bytes32\"]);\n const orderedOffers = orderOffers(tree, offers);\n return Object.assign(tree, { offers: orderedOffers }) as Tree;\n};\n\nconst orderOffers = (tree: StandardMerkleTree<[Hex]>, offers: Offer.Offer[]): Offer.Offer[] => {\n const offerByHash = new Map<Hex, Offer.Offer>();\n for (const offer of offers) {\n offerByHash.set(normalizeHash(Offer.hash(offer)), offer);\n }\n\n const entries = tree.dump().values.map((value) => {\n const hash = normalizeHash(value.value[0] as Hex);\n const offer = offerByHash.get(hash);\n if (!offer) {\n throw new TreeError(`missing offer for leaf ${hash}`);\n }\n return { offer, treeIndex: value.treeIndex };\n });\n\n entries.sort((a, b) => b.treeIndex - a.treeIndex);\n return entries.map((item) => item.offer);\n};\n\n/**\n * Generates merkle proofs for all offers in a tree.\n *\n * Each proof allows independent verification that an offer is included in the tree\n * without requiring the full tree. Proofs are ordered by StandardMerkleTree leaf ordering.\n *\n * @param tree - The {@link Tree} to generate proofs for.\n * @returns Array of proofs - {@link Proof}\n */\nexport const proofs = (tree: Tree): Proof[] => {\n return tree.offers.map((offer) => {\n const path = tree.getProof([Offer.hash(offer)] as [Hex]) as Hex[];\n return { offer, path };\n });\n};\n\n/**\n * Normalizes a Root signature domain (BigInt chain id, lowercase address).\n * @throws {SignatureDomainError} When the domain is invalid.\n */\nexport const signatureDomain = (domain: SignatureDomain): NormalizedSignatureDomain => {\n return normalizeSignatureDomain(domain, (reason) => new SignatureDomainError(reason));\n};\n\nconst normalizeSignatureDomain = (\n domain: SignatureDomain,\n errorFactory: (reason: string) => Errors.BaseError,\n): NormalizedSignatureDomain => {\n let chainId: bigint;\n try {\n chainId = typeof domain.chainId === \"bigint\" ? domain.chainId : BigInt(domain.chainId);\n } catch {\n throw errorFactory(\"invalid chainId\");\n }\n\n if (chainId < 0n) throw errorFactory(\"invalid chainId\");\n if (!isAddress(domain.verifyingContract)) throw errorFactory(\"invalid verifyingContract\");\n\n return {\n chainId,\n verifyingContract: domain.verifyingContract.toLowerCase() as Address,\n };\n};\n\nconst assertHex = (\n value: unknown,\n expectedBytes: number,\n name: string,\n errorFactory: (reason: string) => Errors.BaseError = (reason) => new DecodeError(reason),\n): void => {\n if (typeof value !== \"string\" || !isHex(value)) {\n throw errorFactory(`${name} is not a valid hex string`);\n }\n if (hexToBytes(value).length !== expectedBytes) {\n throw errorFactory(`${name}: expected ${expectedBytes} bytes`);\n }\n};\n\nconst verifySignatureAndRecoverAddress = async (params: {\n root: Hex;\n signature: Hex;\n domain: NormalizedSignatureDomain;\n errorFactory: (reason: string) => Errors.BaseError;\n}): Promise<Address> => {\n const { root, signature, domain, errorFactory } = params;\n assertHex(root, 32, \"root\", errorFactory);\n assertHex(signature, 65, \"signature\", errorFactory);\n const hash = hashTypedData({\n domain,\n types: signatureTypes,\n primaryType: \"Root\",\n message: { root },\n });\n try {\n return await recoverAddress({ hash, signature });\n } catch {\n throw errorFactory(\"signature recovery failed\");\n }\n};\n\n/**\n * Encodes a merkle tree with signature into hex calldata for onchain broadcast.\n *\n * Layout: `0x{vv}{gzip([...offers])}{root}{signature}` where:\n * - `{vv}`: 1-byte version (currently 0x01)\n * - `{gzip([...offers])}`: gzipped JSON array of serialized offers\n * - `{root}`: 32-byte merkle root\n * - `{signature}`: 65-byte EIP-712 signature over Root(bytes32 root)\n *\n * Validates signature authenticity and root integrity before encoding.\n *\n * @example\n * ```typescript\n * const tree = Tree.from(offers);\n * const signature = await wallet.signTypedData({\n * account: wallet.account,\n * domain: Tree.signatureDomain({ chainId, verifyingContract }),\n * types: Tree.signatureTypes,\n * primaryType: \"Root\",\n * message: { root: tree.root },\n * });\n * const calldata = await Tree.encode(tree, signature, { chainId, verifyingContract });\n * await broadcast(calldata);\n * ```\n *\n * @example\n * Manual construction (for advanced users):\n * ```typescript\n * const tree = Tree.from(offers);\n * const compressed = gzip(JSON.stringify(tree.offers.map(Offer.serialize)));\n * const partial = `0x01${bytesToHex(compressed)}${tree.root.slice(2)}`;\n * const signature = await wallet.signTypedData({\n * account: wallet.account,\n * domain: Tree.signatureDomain({ chainId, verifyingContract }),\n * types: Tree.signatureTypes,\n * primaryType: \"Root\",\n * message: { root: tree.root },\n * });\n * const calldata = `${partial}${signature.slice(2)}`;\n * ```\n *\n * @param tree - Merkle tree of offers\n * @param signature - EIP-712 signature over Root(bytes32 root)\n * @param domain - EIP-712 domain with chain id and verifying contract\n * @returns Hex-encoded calldata ready for onchain broadcast\n * @throws {EncodeError} If signature verification fails or root mismatch\n */\nexport const encode = async (tree: Tree, signature: Hex, domain: SignatureDomain): Promise<Hex> => {\n const errorFactory = (reason: string) => new EncodeError(reason);\n const normalizedDomain = normalizeSignatureDomain(domain, errorFactory);\n validateTreeForEncoding(tree, normalizedDomain);\n await verifySignatureAndRecoverAddress({\n root: tree.root,\n signature,\n domain: normalizedDomain,\n errorFactory,\n });\n\n const unsigned = encodeUnsignedBytes(tree);\n const sigBytes = hexToBytes(signature);\n const encoded = new Uint8Array(unsigned.length + sigBytes.length);\n encoded.set(unsigned, 0);\n encoded.set(sigBytes, unsigned.length);\n\n return bytesToHex(encoded);\n};\n\n/**\n * Encodes a merkle tree without a signature into hex payload for client-side signing.\n *\n * Layout: `0x{vv}{gzip([...offers])}{root}` where:\n * - `{vv}`: 1-byte version (currently 0x01)\n * - `{gzip([...offers])}`: gzipped JSON array of serialized offers\n * - `{root}`: 32-byte merkle root\n *\n * Validates root integrity before encoding.\n *\n * @param tree - Merkle tree of offers\n * @returns Hex-encoded unsigned payload\n * @throws {EncodeError} If root mismatch\n */\nexport const encodeUnsigned = (tree: Tree): Hex => {\n validateTreeForEncoding(tree);\n return bytesToHex(encodeUnsignedBytes(tree));\n};\n\nconst validateTreeForEncoding = (tree: Tree, domain?: NormalizedSignatureDomain): void => {\n if (VERSION > 0xff) throw new EncodeError(`version overflow: ${VERSION} exceeds 255`);\n\n const computed = from(tree.offers);\n if (tree.root !== computed.root)\n throw new EncodeError(`root mismatch: expected ${computed.root}, got ${tree.root}`);\n\n if (domain) {\n const mismatched = tree.offers.find((offer) => BigInt(offer.chainId) !== domain.chainId);\n if (mismatched) {\n throw new EncodeError(\n `chainId mismatch: expected ${domain.chainId}, got ${mismatched.chainId}`,\n );\n }\n }\n};\n\nconst encodeUnsignedBytes = (tree: Tree): Uint8Array => {\n const offersPayload = tree.offers.map(Offer.serialize);\n const compressed = gzip(JSON.stringify(offersPayload));\n const rootBytes = hexToBytes(tree.root);\n const encoded = new Uint8Array(1 + compressed.length + 32);\n encoded[0] = VERSION;\n encoded.set(compressed, 1);\n encoded.set(rootBytes, 1 + compressed.length);\n return encoded;\n};\n\n/**\n * Decodes hex calldata into a validated merkle tree.\n *\n * Validates signature before decompression for fail-fast rejection of invalid payloads.\n * Returns the tree with separately validated signature and recovered signer address.\n *\n * Validation order:\n * 1. Version check\n * 2. Signature verification (fail-fast, before decompression)\n * 3. Decompression (only if signature valid)\n * 4. Root verification (computed from offers vs embedded root)\n *\n * @example\n * ```typescript\n * const { tree, signature, signer } = await Tree.decode(calldata, { chainId, verifyingContract });\n * console.log(`Tree signed by ${signer} with ${tree.offers.length} offers`);\n * ```\n *\n * @param encoded - Hex calldata in format `0x{vv}{gzip}{root}{signature}`\n * @param domain - EIP-712 domain with chain id and verifying contract\n * @returns Validated tree, signature, and recovered signer address\n * @throws {DecodeError} If version invalid, signature invalid, or root mismatch\n */\nexport const decode = async (\n encoded: Hex,\n domain: SignatureDomain,\n): Promise<{\n tree: Tree;\n signature: Hex;\n signer: Address;\n}> => {\n const errorFactory = (reason: string) => new DecodeError(reason);\n const normalizedDomain = normalizeSignatureDomain(domain, errorFactory);\n const bytes = hexToBytes(encoded);\n if (bytes.length < 98) throw new DecodeError(\"payload too short\");\n\n const version = bytes[0];\n if (version !== (VERSION & 0xff))\n throw new DecodeError(`invalid version: expected ${VERSION}, got ${version ?? 0}`);\n\n // Parse from end: signature (last 65 bytes) + root (32 bytes before sig)\n const signature = bytesToHex(bytes.slice(-65));\n const root = bytesToHex(bytes.slice(-97, -65));\n assertHex(root, 32, \"root\");\n assertHex(signature, 65, \"signature\");\n\n const signer = await verifySignatureAndRecoverAddress({\n root,\n signature,\n domain: normalizedDomain,\n errorFactory,\n });\n\n const compressed = bytes.slice(1, -97);\n let decoded: string;\n try {\n decoded = ungzip(compressed, { to: \"string\" });\n } catch {\n throw new DecodeError(\"decompression failed\");\n }\n\n let rawOffers: unknown[];\n try {\n rawOffers = JSON.parse(decoded) as unknown[];\n } catch {\n throw new DecodeError(\"JSON parse failed\");\n }\n\n const offers = rawOffers.map(\n (o: unknown) => Offer.OfferSchema().parse(o) as unknown as Offer.Offer,\n );\n\n const tree = from(offers);\n if (root !== tree.root) {\n throw new DecodeError(`root mismatch: expected ${tree.root}, got ${root}`);\n }\n\n const chainIdMismatch = tree.offers.find(\n (offer) => BigInt(offer.chainId) !== normalizedDomain.chainId,\n );\n if (chainIdMismatch) {\n throw new DecodeError(\n `chainId mismatch: expected ${normalizedDomain.chainId}, got ${chainIdMismatch.chainId}`,\n );\n }\n\n return { tree, signature, signer };\n};\n\n/**\n * Error thrown during tree building operations.\n * Indicates structural issues with the tree (missing offers, inconsistent state).\n */\nexport class TreeError extends Errors.BaseError {\n override name = \"Tree.TreeError\";\n constructor(reason: string) {\n super(`Tree error: ${reason}`);\n }\n}\n\n/**\n * Error thrown during tree encoding.\n * Indicates validation failures (signature, root mismatch, mixed makers).\n */\nexport class EncodeError extends Errors.BaseError {\n override name = \"Tree.EncodeError\";\n constructor(reason: string) {\n super(`Failed to encode tree: ${reason}`);\n }\n}\n\n/**\n * Error thrown during tree decoding.\n * Indicates payload corruption, version mismatch, or validation failures.\n */\nexport class DecodeError extends Errors.BaseError {\n override name = \"Tree.DecodeError\";\n constructor(reason: string) {\n super(`Failed to decode tree: ${reason}`);\n }\n}\n\n/**\n * Error thrown when an invalid signature domain is supplied.\n */\nexport class SignatureDomainError extends Errors.BaseError {\n override name = \"Tree.SignatureDomainError\";\n constructor(reason: string) {\n super(`Invalid signature domain: ${reason}`);\n }\n}\n","/** Combines members of an intersection into a readable type. */\n// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg\nexport type Compute<type> = { [key in keyof type]: type[key] } & unknown;\n\n// https://effect.website/docs/code-style/branded-types/#generalizing-branded-types\nexport const BrandTypeId = Symbol.for(\"mempool/Brand\");\nexport type Brand<in out ID extends string | symbol> = {\n readonly [BrandTypeId]: {\n readonly [id in ID]: ID;\n };\n};\n","import type { Address, Hex } from \"viem\";\nimport { Obligation } from \"#core\";\nimport type * as OpenApiSchema from \"./generated/swagger.d.ts\";\n\nexport type OfferResponse =\n OpenApiSchema.paths[\"/v1/offers\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"][\"data\"][number];\n\nexport type Input = Readonly<{\n hash: Hex;\n maker: Address;\n assets: bigint;\n obligationUnits: bigint;\n obligationShares: bigint;\n price: bigint;\n maturity: number;\n expiry: number;\n start: number;\n group: Hex;\n session: Hex;\n buy: boolean;\n chainId: number;\n loanToken: Address;\n collaterals: Readonly<\n {\n asset: Address;\n lltv: bigint;\n oracle: Address;\n }[]\n >;\n callback: {\n address: Address;\n data: Hex;\n };\n root?: Hex | undefined;\n proof?: Hex[] | undefined;\n signature?: Hex | undefined;\n consumed: bigint;\n takeable: bigint;\n blockNumber: number;\n}>;\n\n/**\n * Creates an `OfferResponse` matching the Solidity Offer struct layout.\n * @constructor\n * @param input - {@link Input}\n * @returns The created `OfferResponse`. {@link OfferResponse}\n */\nexport function from(input: Input): OfferResponse {\n const offer = {\n obligation: {\n loan_token: input.loanToken,\n collaterals: input.collaterals.map((c) => ({\n token: c.asset,\n lltv: c.lltv.toString(),\n oracle: c.oracle,\n })),\n maturity: input.maturity,\n },\n buy: input.buy,\n maker: input.maker,\n assets: input.assets.toString(),\n obligation_units: input.obligationUnits.toString(),\n obligation_shares: input.obligationShares.toString(),\n start: input.start,\n expiry: input.expiry,\n price: input.price.toString(),\n group: input.group,\n session: input.session,\n callback: input.callback.address,\n callback_data: input.callback.data,\n };\n\n const base = {\n offer,\n offer_hash: input.hash,\n obligation_id: Obligation.id({\n chainId: input.chainId,\n loanToken: input.loanToken,\n collaterals: [...input.collaterals],\n maturity: input.maturity,\n }),\n chain_id: input.chainId,\n consumed: input.consumed.toString(),\n takeable: input.takeable.toString(),\n block_number: input.blockNumber,\n };\n\n if (!input.proof || !input.root || !input.signature) {\n return {\n ...base,\n root: null,\n proof: null,\n signature: null,\n } as OfferResponse;\n }\n\n return {\n ...base,\n root: input.root.toLowerCase(),\n proof: input.proof.map((p) => p.toLowerCase()),\n signature: input.signature.toLowerCase(),\n } as OfferResponse;\n}\n","import * as z from \"zod\";\nimport type { Compute } from \"#core\";\n\nexport const API_ERROR_CODES = [\n \"VALIDATION_ERROR\",\n \"NOT_FOUND\",\n \"INTERNAL_SERVER_ERROR\",\n \"BAD_REQUEST\",\n] as const;\n\ntype APIErrorCode = (typeof API_ERROR_CODES)[number];\n\nexport enum STATUS_CODE {\n SUCCESS = 200,\n BAD_REQUEST = 400,\n NOT_FOUND = 404,\n INTERNAL_SERVER_ERROR = 500,\n}\n\nexport class APIError<Code extends STATUS_CODE = STATUS_CODE> extends Error {\n constructor(\n public statusCode: Code,\n message: string,\n public code: APIErrorCode,\n public details?: unknown,\n ) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\nexport class ValidationError extends APIError<STATUS_CODE.BAD_REQUEST> {\n constructor(message: string, details?: unknown) {\n super(STATUS_CODE.BAD_REQUEST, message, \"VALIDATION_ERROR\", details);\n }\n}\n\nexport class NotFoundError extends APIError<STATUS_CODE.NOT_FOUND> {\n constructor(message: string) {\n super(STATUS_CODE.NOT_FOUND, message, \"NOT_FOUND\");\n }\n}\n\nexport class InternalServerError extends APIError<STATUS_CODE.INTERNAL_SERVER_ERROR> {\n constructor(message = \"Internal server error\") {\n super(STATUS_CODE.INTERNAL_SERVER_ERROR, message, \"INTERNAL_SERVER_ERROR\");\n }\n}\n\nexport class BadRequestError extends APIError<STATUS_CODE.BAD_REQUEST> {\n constructor(message = \"Invalid JSON format\", details?: unknown) {\n super(STATUS_CODE.BAD_REQUEST, message, \"BAD_REQUEST\", details);\n }\n}\n\ntype Meta = {\n timestamp: string;\n checksum?: string;\n};\n\ntype ErrorDetail = {\n code: APIErrorCode;\n message: string;\n details?: unknown;\n};\n\nexport type SuccessPayload<T> = Compute<{\n statusCode: STATUS_CODE.SUCCESS;\n body: {\n cursor: string | null;\n data: T;\n meta: Meta;\n };\n}>;\n\nexport type ErrorPayload<\n statusCode extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS> = Exclude<\n STATUS_CODE,\n STATUS_CODE.SUCCESS\n >,\n> = Compute<{\n statusCode: statusCode;\n body: {\n meta: Meta;\n error: ErrorDetail;\n };\n}>;\n\nexport type Payload<T> = SuccessPayload<T> | ErrorPayload;\n\nexport function success<T>(args: { data: T; cursor?: string | null }): SuccessPayload<T> {\n const { data, cursor } = args;\n return {\n statusCode: STATUS_CODE.SUCCESS as const,\n body: {\n meta: { timestamp: new Date().toISOString() },\n cursor: cursor ?? null,\n data,\n },\n };\n}\n\n/**\n * Generic failure builder. Preserves the concrete status code when the input is an APIError.\n * If not an APIError, maps to INTERNAL_SERVER_ERROR. Zod & SyntaxError are mapped to BAD_REQUEST.\n */\nexport function failure<\n Code extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS> = Exclude<\n STATUS_CODE,\n STATUS_CODE.SUCCESS\n >,\n>(err: unknown): ErrorPayload<Code> {\n if (err instanceof APIError) {\n // Capture the exact status type from the error instance\n return handleAPIError(err) as ErrorPayload<Code>;\n }\n\n if (err instanceof SyntaxError) {\n return handleAPIError(new BadRequestError(err.message)) as ErrorPayload<Code>;\n }\n\n if (err instanceof z.ZodError) {\n return handleAPIError(handleZodError(err)) as ErrorPayload<Code>;\n }\n\n return handleAPIError(new InternalServerError()) as ErrorPayload<Code>;\n}\n\nfunction handleAPIError<Code extends Exclude<STATUS_CODE, STATUS_CODE.SUCCESS>>(\n error: APIError<Code>,\n): ErrorPayload<Code> {\n return {\n statusCode: error.statusCode,\n body: {\n meta: { timestamp: new Date().toISOString() },\n error: {\n code: error.code,\n message: error.message,\n ...(error.details && typeof error.details === \"object\" ? { details: error.details } : {}),\n },\n },\n };\n}\n\nexport function handleZodError(error: z.ZodError): ValidationError {\n const formattedErrors = error.issues.map((issue) => {\n const field = issue.path.join(\".\");\n let msg = issue.message;\n\n switch (issue.code) {\n case \"invalid_type\":\n if (issue.message.includes(\"received undefined\")) {\n msg = `${field} is required`;\n }\n break;\n case \"invalid_format\":\n msg = issue.format === \"regex\" ? issue.message : `${field} has an invalid format`;\n break;\n default:\n break;\n }\n\n return { field, issue: msg };\n });\n\n return new ValidationError(\"Validation failed\", formattedErrors);\n}\n","import \"reflect-metadata\";\nimport { generateDocument, type OpenAPIDocument } from \"openapi-metadata\";\nimport {\n ApiBody,\n ApiOperation,\n ApiParam,\n ApiProperty,\n ApiQuery,\n ApiResponse,\n ApiTags,\n} from \"openapi-metadata/decorators\";\nimport type { Address, Hex } from \"viem\";\nimport * as Payload from \"../Controllers/Payload.ts\";\n\nconst timestampExample = \"2024-01-01T12:00:00.000Z\";\nconst offerCursorExample = \"eyJvZmZzZXQiOjEwMH0\";\nconst obligationCursorExample =\n \"0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc\";\n\nconst offerExample = {\n offer: {\n obligation: {\n loan_token: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n collaterals: [\n {\n token: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n lltv: \"860000000000000000\",\n oracle: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\",\n },\n ],\n maturity: 1761922799,\n },\n buy: false,\n maker: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n assets: \"369216000000000000000000\",\n obligation_units: \"0\",\n obligation_shares: \"0\",\n start: 1761922790,\n expiry: 1761922799,\n price: \"2750000000000000000\",\n group: \"0x000000000000000000000000000000000000000000000000000000000008b8f4\",\n session: \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n callback: \"0x1111111111111111111111111111111111111111\",\n callback_data:\n \"0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000\",\n },\n // Additional API fields (inlined at top level)\n offer_hash: \"0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427\",\n obligation_id: \"0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc\",\n chain_id: 1,\n consumed: \"0\",\n takeable: \"369216000000000000000000\",\n block_number: 2942933377146801,\n root: \"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\",\n proof: [\n \"0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890\",\n \"0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba\",\n ],\n signature:\n \"0x1234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123400\",\n} as const;\n\nconst collectorsHealthExample = {\n name: \"offers\",\n chain_id: 1,\n block_number: 21345678,\n updated_at: timestampExample,\n lag: 0,\n status: \"live\",\n initialized: true,\n} as const;\n\nconst chainsHealthExample = {\n chain_id: 1,\n local_block_number: 21345678,\n remote_block_number: 21345690,\n updated_at: timestampExample,\n initialized: true,\n} as const;\n\nconst missingCollectorExample = {\n chain_id: 1,\n name: \"offers\",\n} as const;\n\n// Example for validate offer request\nconst validateOfferExample = {\n maker: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n assets: \"369216000000000000000000\",\n obligation_units: \"0\",\n obligation_shares: \"0\",\n price: \"2750000000000000000\",\n maturity: 1761922799,\n expiry: 1761922799,\n start: 1761922790,\n group: \"0x000000000000000000000000000000000000000000000000000000000008b8f4\",\n session: \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n buy: false,\n chain_id: 1,\n loan_token: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n collaterals: [\n {\n asset: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n oracle: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\",\n lltv: \"860000000000000000\",\n },\n ],\n callback: {\n address: \"0x1111111111111111111111111111111111111111\",\n data: \"0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000034cf890db685fc536e05652fb41f02090c3fb751000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000108e644e3ab01184155270aa92a00000000000\",\n },\n} as const;\n\nconst callbackTypesRequestExample = {\n callbacks: [\n {\n chain_id: 1,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x3333333333333333333333333333333333333333\",\n \"0x9999999999999999999999999999999999999999\",\n ],\n },\n ],\n} as const;\n\nconst callbackTypesResponseExample = [\n {\n chain_id: 1,\n sell_erc20_callback: [\"0x1111111111111111111111111111111111111111\"],\n buy_erc20: [\"0x5555555555555555555555555555555555555555\"],\n buy_vault_v1_callback: [\"0x3333333333333333333333333333333333333333\"],\n not_supported: [\"0x9999999999999999999999999999999999999999\"],\n },\n] as const;\n\nconst routerStatusExample = {\n status: \"live\",\n initialized: true,\n missing_chains: [],\n missing_collectors: [],\n} as const;\n\nclass Meta {\n @ApiProperty({ type: \"string\", example: timestampExample })\n declare timestamp: string;\n}\n\nclass SuccessResponse {\n @ApiProperty({ type: () => Meta })\n declare meta: Meta;\n}\n\nclass ErrorResponse {\n @ApiProperty({ type: \"string\", enum: Payload.API_ERROR_CODES, example: \"VALIDATION_ERROR\" })\n declare code: string;\n\n @ApiProperty({\n type: \"string\",\n example: \"Limit must be greater than 0.\",\n })\n declare message: string;\n\n @ApiProperty({\n type: \"object\",\n example: [\n {\n field: \"limit\",\n issue: \"Limit must be greater than 0.\",\n },\n ],\n })\n declare details: unknown;\n}\n\nclass BadRequestResponse {\n @ApiProperty({ type: () => ErrorResponse })\n declare error: ErrorResponse;\n\n @ApiProperty({ type: () => Meta })\n declare meta: Meta;\n}\n\nclass CollateralResponse {\n @ApiProperty({ type: \"string\", example: \"0x34Cf890dB685FC536E05652FB41f02090c3fb751\" })\n declare token: Address;\n\n @ApiProperty({ type: \"string\", example: \"860000000000000000\" })\n declare lltv: string;\n\n @ApiProperty({ type: \"string\", example: \"0x45093658BE7f90B63D7c359e8f408e503c2D9401\" })\n declare oracle: Address;\n}\n\n// Classes for validate request (input format - uses asset, not token)\nclass ValidateCollateralRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].asset })\n declare asset: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].oracle })\n declare oracle: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.collaterals[0].lltv })\n declare lltv: string;\n}\n\nclass ValidateCallbackRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.callback.address })\n declare address: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.callback.data })\n declare data: Hex;\n}\n\nclass CallbackTypesChainRequest {\n @ApiProperty({ type: \"number\", example: callbackTypesRequestExample.callbacks[0].chain_id })\n declare chain_id: number;\n\n @ApiProperty({\n type: () => [String],\n example: callbackTypesRequestExample.callbacks[0].addresses,\n })\n declare addresses: string[];\n}\n\nclass CallbackTypesRequest {\n @ApiProperty({\n type: () => [CallbackTypesChainRequest],\n example: callbackTypesRequestExample.callbacks,\n })\n declare callbacks: CallbackTypesChainRequest[];\n}\n\nclass CallbackTypesChainResponse {\n @ApiProperty({ type: \"number\", example: callbackTypesResponseExample[0].chain_id })\n declare chain_id: number;\n\n @ApiProperty({\n type: () => [String],\n required: false,\n example: callbackTypesResponseExample[0].buy_vault_v1_callback,\n })\n declare buy_vault_v1_callback?: string[];\n\n @ApiProperty({\n type: () => [String],\n required: false,\n example: callbackTypesResponseExample[0].sell_erc20_callback,\n })\n declare sell_erc20_callback?: string[];\n\n @ApiProperty({\n type: () => [String],\n required: false,\n example: callbackTypesResponseExample[0].buy_erc20,\n })\n declare buy_erc20?: string[];\n\n @ApiProperty({\n type: () => [String],\n example: callbackTypesResponseExample[0].not_supported,\n })\n declare not_supported: string[];\n}\n\nclass CallbackTypesSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: \"string\",\n nullable: true,\n example: \"maturity:1:1730415600:end_of_next_month\",\n })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [CallbackTypesChainResponse],\n description: \"Callback types grouped by chain.\",\n example: callbackTypesResponseExample,\n })\n declare data: CallbackTypesChainResponse[];\n}\n\nclass AskResponse {\n @ApiProperty({ type: \"string\", example: \"1000000000000000000\" })\n declare price: string;\n}\n\nclass BidResponse {\n @ApiProperty({ type: \"string\", example: \"1000000000000000000\" })\n declare price: string;\n}\n\nclass ObligationOfferResponse {\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation.loan_token })\n declare loan_token: Address;\n\n @ApiProperty({\n type: () => [CollateralResponse],\n example: offerExample.offer.obligation.collaterals,\n })\n declare collaterals: CollateralResponse[];\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.obligation.maturity })\n declare maturity: number;\n}\n\nclass OfferDataResponse {\n @ApiProperty({ type: () => ObligationOfferResponse, example: offerExample.offer.obligation })\n declare obligation: ObligationOfferResponse;\n\n @ApiProperty({ type: \"boolean\", example: offerExample.offer.buy })\n declare buy: boolean;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.maker })\n declare maker: Address;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.assets })\n declare assets: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation_units })\n declare obligation_units: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.obligation_shares })\n declare obligation_shares: string;\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.start })\n declare start: number;\n\n @ApiProperty({ type: \"number\", example: offerExample.offer.expiry })\n declare expiry: number;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.price })\n declare price: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.group })\n declare group: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.session })\n declare session: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.callback })\n declare callback: Address;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer.callback_data })\n declare callback_data: Hex;\n}\n\nclass OfferListItemResponse {\n @ApiProperty({ type: () => OfferDataResponse, example: offerExample.offer })\n declare offer: OfferDataResponse;\n\n @ApiProperty({ type: \"string\", example: offerExample.offer_hash })\n declare offer_hash: Hex;\n\n @ApiProperty({ type: \"string\", example: offerExample.obligation_id })\n declare obligation_id: Hex;\n\n @ApiProperty({ type: \"number\", example: offerExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: offerExample.consumed })\n declare consumed: string;\n\n @ApiProperty({ type: \"string\", example: offerExample.takeable })\n declare takeable: string;\n\n @ApiProperty({ type: \"number\", example: offerExample.block_number })\n declare block_number: number;\n\n @ApiProperty({ type: \"string\", nullable: true, example: offerExample.root })\n declare root: Hex | null;\n\n @ApiProperty({ type: [String], nullable: true, example: offerExample.proof })\n declare proof: Hex[] | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: offerExample.signature })\n declare signature: Hex | null;\n}\n\nclass ObligationResponse {\n @ApiProperty({\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n })\n declare id: Hex;\n\n @ApiProperty({ type: \"number\", example: 1 })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\" })\n declare loan_token: Address;\n\n @ApiProperty({ type: () => [CollateralResponse] })\n declare collaterals: CollateralResponse[];\n\n @ApiProperty({ type: \"number\", example: 1761922800 })\n declare maturity: number;\n\n @ApiProperty({ type: () => AskResponse })\n declare ask: AskResponse;\n\n @ApiProperty({ type: () => BidResponse })\n declare bid: BidResponse;\n}\nclass ObligationListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: obligationCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [ObligationResponse],\n description: \"List of obligations with takable offers.\",\n })\n declare data: ObligationResponse[];\n}\n\nclass ObligationSingleSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({ type: () => ObligationResponse, description: \"Obligation details.\" })\n declare data: ObligationResponse;\n}\n\nclass OfferListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [OfferListItemResponse],\n description: \"Offers matching the provided filters.\",\n example: [offerExample],\n })\n declare data: OfferListItemResponse[];\n}\n\nclass MissingCollectorResponse {\n @ApiProperty({ type: \"number\", example: missingCollectorExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: missingCollectorExample.name })\n declare name: string;\n}\n\nclass RouterStatusDataResponse {\n @ApiProperty({ type: \"string\", enum: [\"live\", \"syncing\"], example: routerStatusExample.status })\n declare status: \"live\" | \"syncing\";\n\n @ApiProperty({ type: \"boolean\", example: routerStatusExample.initialized })\n declare initialized: boolean;\n\n @ApiProperty({\n type: () => [Number],\n example: routerStatusExample.missing_chains,\n description: \"Configured chain ids missing initialization rows.\",\n })\n declare missing_chains: number[];\n\n @ApiProperty({\n type: () => [MissingCollectorResponse],\n example: routerStatusExample.missing_collectors,\n description: \"Collectors missing initialization rows.\",\n })\n declare missing_collectors: MissingCollectorResponse[];\n}\n\nclass RouterStatusSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => RouterStatusDataResponse,\n description: \"Aggregated router status.\",\n example: routerStatusExample,\n })\n declare data: RouterStatusDataResponse;\n}\n\nclass CollectorHealthResponse {\n @ApiProperty({ type: \"string\", example: collectorsHealthExample.name })\n declare name: string;\n\n @ApiProperty({ type: \"number\", example: collectorsHealthExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"number\", nullable: true, example: collectorsHealthExample.block_number })\n declare block_number: number | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: collectorsHealthExample.updated_at })\n declare updated_at: string | null;\n\n @ApiProperty({ type: \"number\", nullable: true, example: collectorsHealthExample.lag })\n declare lag: number | null;\n\n @ApiProperty({\n type: \"string\",\n enum: [\"live\", \"lagging\", \"unknown\"],\n example: collectorsHealthExample.status,\n })\n declare status: \"live\" | \"lagging\" | \"unknown\";\n\n @ApiProperty({ type: \"boolean\", example: collectorsHealthExample.initialized })\n declare initialized: boolean;\n}\n\nclass CollectorsHealthSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => [CollectorHealthResponse],\n description: \"Collectors health details and sync status.\",\n example: [collectorsHealthExample],\n })\n declare data: CollectorHealthResponse[];\n}\n\nclass ChainHealthResponse {\n @ApiProperty({ type: \"number\", example: chainsHealthExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({\n type: \"number\",\n nullable: true,\n example: chainsHealthExample.local_block_number,\n })\n declare local_block_number: number | null;\n\n @ApiProperty({ type: \"number\", nullable: true, example: chainsHealthExample.remote_block_number })\n declare remote_block_number: number | null;\n\n @ApiProperty({ type: \"string\", nullable: true, example: chainsHealthExample.updated_at })\n declare updated_at: string | null;\n\n @ApiProperty({ type: \"boolean\", example: chainsHealthExample.initialized })\n declare initialized: boolean;\n}\n\nclass ChainsHealthSuccessResponse extends SuccessResponse {\n @ApiProperty({\n type: () => [ChainHealthResponse],\n description: \"Latest processed block per chain.\",\n example: [chainsHealthExample],\n })\n declare data: ChainHealthResponse[];\n}\n\nclass ValidateOfferRequest {\n @ApiProperty({ type: \"string\", example: validateOfferExample.maker })\n declare maker: Address;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.assets })\n declare assets: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.obligation_units, required: false })\n declare obligation_units: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.obligation_shares, required: false })\n declare obligation_shares: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.price })\n declare price: string;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.maturity })\n declare maturity: number;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.expiry })\n declare expiry: number;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.start })\n declare start: number;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.group })\n declare group: string;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.session })\n declare session: string;\n\n @ApiProperty({ type: \"boolean\", example: validateOfferExample.buy })\n declare buy: boolean;\n\n @ApiProperty({ type: \"number\", example: validateOfferExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: validateOfferExample.loan_token })\n declare loan_token: Address;\n\n @ApiProperty({\n type: () => [ValidateCollateralRequest],\n example: validateOfferExample.collaterals,\n })\n declare collaterals: ValidateCollateralRequest[];\n\n @ApiProperty({ type: () => ValidateCallbackRequest, example: validateOfferExample.callback })\n declare callback: ValidateCallbackRequest;\n}\n\nclass ValidateOffersRequest {\n @ApiProperty({\n type: () => [ValidateOfferRequest],\n description: \"Array of offers in snake_case format. Required, non-empty.\",\n required: true,\n })\n declare offers: ValidateOfferRequest[];\n}\n\nclass ValidationSuccessDataResponse {\n @ApiProperty({\n type: \"string\",\n description: \"Unsigned payload: version (1B) + gzip(offers) + root (32B).\",\n example: \"0x01789c...\",\n })\n declare payload: Hex;\n\n @ApiProperty({\n type: \"string\",\n description: \"Merkle tree root to sign with EIP-191.\",\n example: \"0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427\",\n })\n declare root: Hex;\n}\n\nclass ValidationSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => ValidationSuccessDataResponse,\n description: \"Payload and root for client-side signing.\",\n })\n declare data: ValidationSuccessDataResponse;\n}\n\nclass ValidationIssueResponse {\n @ApiProperty({\n type: \"number\",\n description: \"0-indexed position of the failed offer in the request array.\",\n example: 0,\n })\n declare index: number;\n\n @ApiProperty({\n type: \"string\",\n description: \"Gatekeeper rule name that rejected the offer.\",\n example: \"no_buy\",\n })\n declare rule: string;\n\n @ApiProperty({\n type: \"string\",\n description: \"Human-readable rejection reason.\",\n example: \"Buy offers are not supported\",\n })\n declare message: string;\n}\n\nclass ValidationFailureDataResponse {\n @ApiProperty({\n type: () => [ValidationIssueResponse],\n description: \"List of validation issues. Returned when any offer fails validation.\",\n })\n declare issues: ValidationIssueResponse[];\n}\n\nclass ValidationFailureResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => ValidationFailureDataResponse,\n description: \"List of validation issues. Returned when any offer fails validation.\",\n })\n declare data: ValidationFailureDataResponse;\n}\n\nclass BookLevelResponse {\n @ApiProperty({ type: \"string\", example: \"2750000000000000000\" })\n declare price: string;\n\n @ApiProperty({ type: \"string\", example: \"369216000000000000000000\" })\n declare assets: string;\n\n @ApiProperty({ type: \"number\", example: 5 })\n declare count: number;\n}\n\nconst positionExample = {\n chain_id: 1,\n contract: \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n user: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n reserved: \"200000000000000000000\",\n block_number: 21345678,\n} as const;\n\nclass PositionListItemResponse {\n @ApiProperty({ type: \"number\", example: positionExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: positionExample.contract })\n declare contract: string;\n\n @ApiProperty({ type: \"string\", example: positionExample.user })\n declare user: string;\n\n @ApiProperty({ type: \"string\", example: positionExample.reserved })\n declare reserved: string;\n\n @ApiProperty({ type: \"number\", example: positionExample.block_number })\n declare block_number: number;\n}\n\nclass PositionListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [PositionListItemResponse],\n description: \"User positions with reserved balances from active offers.\",\n example: [positionExample],\n })\n declare data: PositionListItemResponse[];\n}\n\nclass BookListResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: offerCursorExample })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [BookLevelResponse],\n description: \"Aggregated book levels grouped by computed price.\",\n })\n declare data: BookLevelResponse[];\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class BooksController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/books/{obligationId}/{side}\",\n summary: \"Get aggregated book\",\n description:\n \"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).\",\n })\n @ApiParam({\n name: \"obligationId\",\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n description: \"Obligation id.\",\n })\n @ApiParam({\n name: \"side\",\n type: \"string\",\n enum: [\"buy\", \"sell\"],\n example: \"buy\",\n description: \"Book side (buy or sell).\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of price levels to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: BookListResponse })\n async getBook() {}\n}\n\n@ApiTags(\"Make\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class ValidateController {\n @ApiOperation({\n methods: [\"post\"],\n path: \"/v1/validate\",\n summary: \"Validate offers\",\n description:\n \"Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure.\",\n })\n @ApiBody({ type: ValidateOffersRequest })\n @ApiResponse({ status: 200, description: \"Success\", type: ValidationSuccessResponse })\n @ApiResponse({ status: 200, description: \"Validation issues\", type: ValidationFailureResponse })\n async validateOffers() {}\n}\n\n@ApiTags(\"Make\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class CallbacksController {\n @ApiOperation({\n methods: [\"post\"],\n path: \"/v1/callbacks\",\n summary: \"Resolve callback types\",\n description: \"Returns callback types for callback addresses grouped by chain.\",\n })\n @ApiBody({ type: CallbackTypesRequest })\n @ApiResponse({ status: 200, description: \"Success\", type: CallbackTypesSuccessResponse })\n async resolveCallbackTypes() {}\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class OffersController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/offers\",\n summary: \"List all offers\",\n description:\n \"Returns offers. Provide either `obligation_id` + `side` (order book) or `maker` (by maker address).\",\n })\n @ApiQuery({\n name: \"side\",\n type: \"string\",\n required: false,\n enum: [\"buy\", \"sell\"],\n example: \"buy\",\n description: \"Side of the offer. Required when using obligation_id.\",\n })\n @ApiQuery({\n name: \"obligation_id\",\n type: \"string\",\n required: false,\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n description: \"Obligation id used to filter offers. Required when not using maker.\",\n })\n @ApiQuery({\n name: \"maker\",\n type: \"string\",\n required: false,\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n description: \"Maker address to filter offers by. Alternative to obligation_id + side.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of offers to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: OfferListResponse })\n async getOffers() {}\n}\n\n@ApiTags(\"System\")\nexport class HealthController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health\",\n summary: \"Retrieve global health\",\n description: \"Returns the aggregated status of the router.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: RouterStatusSuccessResponse })\n async getRouterStatus() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health/collectors\",\n summary: \"Retrieve collectors health\",\n description: \"Returns the latest block numbers processed by collectors and their sync status.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: CollectorsHealthSuccessResponse })\n async getCollectorsHealth() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/health/chains\",\n summary: \"Retrieve chains health\",\n description: \"Returns the latest block that can be processed by collectors for each chain.\",\n })\n @ApiQuery({\n name: \"strict\",\n type: \"boolean\",\n required: false,\n example: true,\n description: \"Fail the request if initialization is incomplete.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ChainsHealthSuccessResponse })\n async getChainsHealth() {}\n}\n\nconst configContractsExample = {\n chain_id: 505050505,\n address: \"0xD946246695A9259F3B33a78629026F61B3Ab40aF\",\n name: \"mempool\",\n} as const;\n\nconst configContractsPayloadExample = [\n {\n chain_id: 505050505,\n address: \"0xD946246695A9259F3B33a78629026F61B3Ab40aF\",\n name: \"mempool\",\n },\n {\n chain_id: 505050505,\n address: \"0x8A409D5D6394fC197c596d4E6E2c35e5d13f8a4d\",\n name: \"multicall\",\n },\n {\n chain_id: 505050505,\n address: \"0x23DFBc4B8B80C14CC5e25011B8491f268395BAd6\",\n name: \"v2\",\n },\n] as const;\n\nconst configRulesMaturityExample = {\n type: \"maturity\",\n chain_id: 1,\n name: \"end_of_next_month\",\n timestamp: 1730415600,\n} as const;\n\nconst configRulesCallbackExample = {\n type: \"callback\",\n chain_id: 1,\n address: \"0x1111111111111111111111111111111111111111\",\n callback_type: \"sell_erc20_callback\",\n} as const;\n\nconst configRulesLoanTokenExample = {\n type: \"loan_token\",\n chain_id: 1,\n address: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n} as const;\n\nconst configRulesChecksumExample = \"f1d2d2f924e986ac86fdf7b36c94bcdf\" as const;\nconst configRulesPayloadExample = [\n configRulesMaturityExample,\n configRulesCallbackExample,\n configRulesLoanTokenExample,\n] as const;\n\nconst configContractNames = [\"mempool\", \"multicall\", \"v2\"] as const;\nconst configContractsCursorExample = \"505050505:0xd946246695a9259f3b33a78629026f61b3ab40af\";\n\nclass ConfigContractResponse {\n @ApiProperty({ type: \"number\", example: configContractsExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: configContractsExample.address })\n declare address: Address;\n\n @ApiProperty({\n type: \"string\",\n enum: configContractNames,\n example: configContractsExample.name,\n })\n declare name: (typeof configContractNames)[number];\n}\n\nclass ConfigContractsSuccessResponse extends SuccessResponse {\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [ConfigContractResponse],\n description: \"Indexer contract configuration for all indexed chains.\",\n example: configContractsPayloadExample,\n })\n declare data: ConfigContractResponse[];\n}\n\nclass ConfigRulesMeta {\n @ApiProperty({ type: \"string\", example: timestampExample })\n declare timestamp: string;\n\n @ApiProperty({ type: \"string\", example: configRulesChecksumExample })\n declare checksum: string;\n}\n\nclass ConfigRulesRuleResponse {\n @ApiProperty({ type: \"string\", example: configRulesMaturityExample.type })\n declare type: string;\n\n @ApiProperty({ type: \"number\", example: configRulesMaturityExample.chain_id })\n declare chain_id: number;\n\n @ApiProperty({ type: \"string\", example: configRulesMaturityExample.name, required: false })\n declare name?: string;\n\n @ApiProperty({ type: \"number\", example: configRulesMaturityExample.timestamp, required: false })\n declare timestamp?: number;\n\n @ApiProperty({ type: \"string\", example: configRulesCallbackExample.address, required: false })\n declare address?: Address;\n\n @ApiProperty({\n type: \"string\",\n example: configRulesCallbackExample.callback_type,\n required: false,\n })\n declare callback_type?: string;\n}\n\nclass ConfigRulesSuccessResponse {\n @ApiProperty({ type: () => ConfigRulesMeta })\n declare meta: ConfigRulesMeta;\n\n @ApiProperty({ type: \"string\", nullable: true, example: null })\n declare cursor: string | null;\n\n @ApiProperty({\n type: () => [ConfigRulesRuleResponse],\n description: \"Configured rules returned by the router API.\",\n example: configRulesPayloadExample,\n })\n declare data: ConfigRulesRuleResponse[];\n}\n\n@ApiTags(\"System\")\nexport class ConfigContractsController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/config/contracts\",\n summary: \"Get indexer contract configuration\",\n description:\n \"Returns contract addresses used by indexers (mempool, v2) and multicall for indexed chains.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n required: false,\n example: configContractsCursorExample,\n description: \"Pagination cursor in chain_id:address format (lowercase address).\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n required: false,\n example: 1000,\n description: \"Maximum number of contracts to return (max 1000).\",\n })\n @ApiQuery({\n name: \"chains\",\n type: [\"number\"],\n required: false,\n example: \"1,8453\",\n description: \"Filter by chain IDs (comma-separated).\",\n style: \"form\",\n explode: false,\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ConfigContractsSuccessResponse })\n async getConfigContracts() {}\n}\n\n@ApiTags(\"System\")\nexport class ConfigRulesController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/config/rules\",\n summary: \"Get config rules\",\n description: \"Returns configured rules for supported chains.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n required: false,\n example: \"maturity:1:1730415600:end_of_next_month\",\n description: \"Pagination cursor in type:chain_id:<value> format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n required: false,\n example: 100,\n description: \"Maximum number of rules to return (max 1000).\",\n })\n @ApiQuery({\n name: \"types\",\n type: [\"string\"],\n required: false,\n example: \"maturity,loan_token\",\n description: \"Filter by rule types (comma-separated).\",\n style: \"form\",\n explode: false,\n })\n @ApiQuery({\n name: \"chains\",\n type: [\"number\"],\n required: false,\n example: \"1,8453\",\n description: \"Filter by chain IDs (comma-separated).\",\n style: \"form\",\n explode: false,\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ConfigRulesSuccessResponse })\n async getConfigRules() {}\n}\n\n@ApiTags(\"Markets\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class ObligationsController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/obligations\",\n summary: \"List all obligations\",\n description:\n \"Returns a list of obligations with their current best ask and bid. Obligations are sorted by their id in ascending order by default.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: obligationCursorExample,\n description: \"Obligation id cursor for pagination.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of obligations to return.\",\n })\n @ApiQuery({\n name: \"chains\",\n type: [\"number\"],\n required: false,\n example: \"1,8453\",\n description: \"Filter by chain IDs (comma-separated).\",\n style: \"form\",\n explode: false,\n })\n @ApiQuery({\n name: \"loan_tokens\",\n type: [\"string\"],\n required: false,\n example:\n \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n description: \"Filter by loan token addresses (comma-separated).\",\n style: \"form\",\n explode: false,\n })\n @ApiQuery({\n name: \"collateral_tokens\",\n type: [\"string\"],\n required: false,\n example:\n \"0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n description: \"Filter by collateral tokens (comma-separated, matches any collateral).\",\n style: \"form\",\n explode: false,\n })\n @ApiQuery({\n name: \"maturities\",\n type: [\"number\"],\n required: false,\n example: \"1761922800,1764524800\",\n description: \"Filter by exact maturity timestamps (comma-separated, unix seconds).\",\n style: \"form\",\n explode: false,\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ObligationListResponse })\n async getObligations() {}\n\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/obligations/{obligationId}\",\n summary: \"Get an obligation\",\n description: \"Returns an obligation by its id.\",\n })\n @ApiParam({\n name: \"obligationId\",\n type: \"string\",\n example: \"0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67\",\n description: \"Obligation id.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: ObligationSingleSuccessResponse })\n async getObligation() {}\n}\n\n@ApiTags(\"Make\")\n@ApiResponse({ status: 400, description: \"Bad Request\", type: BadRequestResponse })\nexport class UsersController {\n @ApiOperation({\n methods: [\"get\"],\n path: \"/v1/users/{userAddress}/positions\",\n summary: \"Get user positions\",\n description:\n \"Returns positions for a user with reserved balance. The reserved balance is the amount locked by active offers (max lot upper - offset - consumed).\",\n })\n @ApiParam({\n name: \"userAddress\",\n type: \"string\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n description: \"User address to get positions for.\",\n })\n @ApiQuery({\n name: \"cursor\",\n type: \"string\",\n example: offerCursorExample,\n description: \"Pagination cursor in base64url-encoded format.\",\n })\n @ApiQuery({\n name: \"limit\",\n type: \"number\",\n example: 10,\n description: \"Maximum number of positions to return.\",\n })\n @ApiResponse({ status: 200, description: \"Success\", type: PositionListResponse })\n async getUserPositions() {}\n}\n\nexport const OpenApi = async (): Promise<OpenAPIDocument> => {\n const document = await generateDocument({\n controllers: [\n BooksController,\n ConfigContractsController,\n ConfigRulesController,\n OffersController,\n ObligationsController,\n HealthController,\n UsersController,\n ValidateController,\n CallbacksController,\n ],\n document: {\n openapi: \"3.1.0\",\n info: {\n title: \"Router API\",\n version: \"1.0.0\",\n description: \"API for the Morpho Router\",\n },\n servers: [\n {\n url: \"https://router.morpho.dev\",\n description: \"Production server\",\n },\n {\n url: \"http://localhost:7891\",\n description: \"Local development server\",\n },\n ],\n tags: [\n {\n name: \"Markets\",\n description:\n \"Read-only endpoints to discover markets, order books and fetch current offers.\",\n },\n {\n name: \"Make\",\n description: \"Utilities to ease making offers.\",\n },\n {\n name: \"System\",\n description: \"Router configuration and health monitoring.\",\n },\n ],\n },\n });\n\n return document;\n};\n","import type { Address } from \"viem\";\nimport type { Chain } from \"#core\";\nimport type { getByUser } from \"#database/domains/Positions.ts\";\n\nexport type PositionResponse = {\n chain_id: Chain.Id;\n contract: Address;\n user: Address;\n reserved: string;\n block_number: number;\n};\n\nexport type PositionWithReserved = getByUser.PositionWithReserved;\n\n/**\n * Creates a `PositionResponse` from a `PositionWithReserved`.\n * @param position - {@link PositionWithReserved}\n * @returns The created `PositionResponse`. {@link PositionResponse}\n */\nexport function from(position: PositionWithReserved): PositionResponse {\n return {\n chain_id: position.chainId,\n contract: position.contract,\n user: position.user,\n reserved: position.reserved.toString(),\n block_number: position.blockNumber,\n };\n}\n","import type { Address, Hex } from \"viem\";\nimport * as z from \"zod\";\n\nconst MAX_LIMIT = 100;\nconst DEFAULT_LIMIT = 20;\nconst CONFIG_RULES_MAX_LIMIT = 1000;\nconst CONFIG_RULES_DEFAULT_LIMIT = 100;\nconst CONFIG_CONTRACTS_MAX_LIMIT = 1000;\nconst CONFIG_CONTRACTS_DEFAULT_LIMIT = 1000;\n\n/** Validate cursor is a valid base64url-encoded JSON object.\n * Domain layer handles semantic validation of cursor fields. */\nfunction isValidBase64urlJson(val: string): boolean {\n try {\n const decoded = Buffer.from(val, \"base64url\").toString(\"utf8\");\n JSON.parse(decoded);\n return true;\n } catch {\n return false;\n }\n}\n\nconst csvArray = <T extends z.ZodTypeAny>(schema: T) =>\n z\n .preprocess((value) => {\n if (value === undefined) return undefined;\n if (Array.isArray(value)) {\n if (value.some((item) => typeof item !== \"string\")) return value;\n return value\n .flatMap((item) => item.split(\",\"))\n .map((item) => item.trim())\n .filter((item) => item.length > 0);\n }\n if (typeof value === \"string\") {\n return value\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length > 0);\n }\n return value;\n }, z.array(schema))\n .optional();\n\nconst PaginationQueryParams = z.object({\n cursor: z\n .string()\n .optional()\n .refine(\n (val) => {\n if (!val) return true; // Optional field\n // Accept any valid base64url-encoded JSON object\n // Domain layer handles semantic validation of cursor fields\n return isValidBase64urlJson(val);\n },\n {\n message: \"Invalid cursor format. Must be a valid base64url-encoded cursor object\",\n },\n )\n .meta({\n description: \"Pagination cursor in base64url-encoded format\",\n example:\n \"eyJzaWRlIjoic2VsbCIsImN1cnJlbnRQcmljZSI6IjEwMDAwMDAwMDAwMDAwMDAwMDAiLCJibG9ja051bWJlciI6MSwiYXNzZXRzIjoiMTAwMDAwMDAwMDAwMDAwMDAwMCIsImhhc2giOiIweGRmZDY4NTllM2UwODJkMTkzODlhMWFlYzFiZGFkN2U4ZDkyZDk2YjFhYTc5NDBkYTkxYTMxMjVkMzFlM2JlNWIiLCJ0b3RhbFJldHVybmVkIjoxMCwibm93IjoxNjAwMDAwMDAwfQ\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(MAX_LIMIT, {\n message: `Limit cannot exceed ${MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${MAX_LIMIT}. Default: ${DEFAULT_LIMIT}`,\n example: 10,\n }),\n});\n\nconst ConfigRuleTypes = z.enum([\"maturity\", \"callback\", \"loan_token\"]);\n\nexport const GetConfigRulesQueryParams = z.object({\n cursor: z\n .string()\n .regex(/^(maturity|callback|loan_token):[1-9]\\d*:.+$/, {\n message: \"Cursor must be in the format type:chain_id:<value>\",\n })\n .optional()\n .meta({\n description: \"Pagination cursor in type:chain_id:<value> format\",\n example: \"maturity:1:1730415600:end_of_next_month\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(CONFIG_RULES_MAX_LIMIT, {\n message: `Limit cannot exceed ${CONFIG_RULES_MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(CONFIG_RULES_DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${CONFIG_RULES_MAX_LIMIT}. Default: ${CONFIG_RULES_DEFAULT_LIMIT}`,\n example: 100,\n }),\n types: csvArray(ConfigRuleTypes).meta({\n description: \"Filter by rule types (comma-separated).\",\n example: \"maturity,loan_token\",\n }),\n chains: csvArray(\n z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Chain must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10)),\n ).meta({\n description: \"Filter by chain IDs (comma-separated).\",\n example: \"1,8453\",\n }),\n});\n\nexport const GetConfigContractsQueryParams = z.object({\n cursor: z\n .string()\n .regex(/^[1-9]\\d*:0x[a-fA-F0-9]{40}$/, {\n message: \"Cursor must be in the format chain_id:0x...\",\n })\n .optional()\n .meta({\n description: \"Pagination cursor in chain_id:address format (lowercase address).\",\n example: \"1:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(CONFIG_CONTRACTS_MAX_LIMIT, {\n message: `Limit cannot exceed ${CONFIG_CONTRACTS_MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(CONFIG_CONTRACTS_DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${CONFIG_CONTRACTS_MAX_LIMIT}. Default: ${CONFIG_CONTRACTS_DEFAULT_LIMIT}`,\n example: 1000,\n }),\n chains: csvArray(\n z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Chain must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10)),\n ).meta({\n description: \"Filter by chain IDs (comma-separated).\",\n example: \"1,8453\",\n }),\n});\n\nexport const GetOffersQueryParams = z\n .object({\n ...PaginationQueryParams.shape,\n side: z.enum([\"buy\", \"sell\"]).optional().meta({\n description: \"Side of the offer. Required when using obligation_id.\",\n example: \"buy\",\n }),\n obligation_id: z\n .string()\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .optional()\n .meta({\n description: \"Offers obligation id. Required when not using maker.\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n maker: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Maker must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .optional()\n .meta({\n description: \"Maker address to filter offers by. Alternative to obligation_id + side.\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n }),\n })\n .superRefine((val, ctx) => {\n const hasObligation = val.obligation_id !== undefined;\n const hasSide = val.side !== undefined;\n const hasMaker = val.maker !== undefined;\n\n if (hasMaker && (hasObligation || hasSide)) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Cannot use both maker and obligation_id/side parameters\",\n });\n return;\n }\n\n if (hasMaker) {\n return;\n }\n\n if (!hasObligation || !hasSide) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Must provide either maker or both obligation_id and side\",\n });\n }\n });\n\nexport const GetObligationsQueryParams = z.object({\n ...PaginationQueryParams.shape,\n cursor: z.string().optional().meta({\n description: \"Obligation id cursor\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n chains: csvArray(\n z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Chain must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10)),\n ).meta({\n description: \"Filter by chain IDs (comma-separated).\",\n example: \"1,8453\",\n }),\n loan_tokens: csvArray(\n z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Loan token must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address),\n ).meta({\n description: \"Filter by loan token addresses (comma-separated).\",\n example:\n \"0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751\",\n }),\n collateral_tokens: csvArray(\n z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"Collateral token must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address),\n ).meta({\n description: \"Filter by collateral tokens (comma-separated, matches any collateral).\",\n example:\n \"0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078\",\n }),\n maturities: csvArray(\n z\n .string()\n .regex(/^[1-9]\\d*$/, { message: \"Maturity must be a positive integer\" })\n .transform((val) => Number.parseInt(val, 10)),\n ).meta({\n description: \"Filter by exact maturity timestamps (comma-separated, unix seconds).\",\n example: \"1761922800,1764524800\",\n }),\n});\n\nexport const GetObligationParams = z.object({\n obligation_id: z\n .string({ error: \"Obligation id is required and must be a valid 32-byte hex string\" })\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .meta({\n description: \"Obligation id\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n});\n\n/** Validate a book cursor format: {side, lastPrice, offersCursor} */\nfunction isValidBookCursor(cursorString: string): boolean {\n const isNumericString = (value: unknown): value is string =>\n typeof value === \"string\" && /^-?\\d+$/.test(value);\n\n try {\n const v = JSON.parse(Buffer.from(cursorString, \"base64url\").toString(\"utf8\"));\n return (\n (v?.side === \"buy\" || v?.side === \"sell\") &&\n isNumericString(v?.lastPrice) &&\n (v?.offersCursor === null || typeof v?.offersCursor === \"string\")\n );\n } catch {\n return false;\n }\n}\n\nconst BookPaginationQueryParams = z.object({\n cursor: z\n .string()\n .optional()\n .refine(\n (value) => {\n if (!value) return true; // Optional field\n return isValidBookCursor(value);\n },\n {\n message: \"Invalid cursor format. Must be a valid base64url-encoded book cursor object\",\n },\n )\n .meta({\n description: \"Pagination cursor in base64url-encoded format for book levels\",\n example:\n \"eyJzaWRlIjoiYnV5IiwibGFzdFJhdGUiOiIxMDAwMDAwMDAwMDAwMDAwMDAwIiwib2ZmZXJzQ3Vyc29yIjpudWxsfQ\",\n }),\n limit: z\n .string()\n .regex(/^[1-9]\\d*$/, {\n message: \"Limit must be a positive integer\",\n })\n .transform((val) => Number.parseInt(val, 10))\n .pipe(\n z.number().max(MAX_LIMIT, {\n message: `Limit cannot exceed ${MAX_LIMIT}`,\n }),\n )\n .optional()\n .default(DEFAULT_LIMIT)\n .meta({\n description: `Limit maximum: ${MAX_LIMIT}. Default: ${DEFAULT_LIMIT}`,\n example: 10,\n }),\n});\n\nconst HealthQueryParams = z.object({\n strict: z\n .enum([\"true\", \"false\", \"1\", \"0\"])\n .transform((value) => value === \"true\" || value === \"1\")\n .optional()\n .meta({\n description: \"Enable strict mode to fail health checks when initialization is incomplete.\",\n example: \"true\",\n }),\n});\n\nexport const GetBookParams = z.object({\n ...BookPaginationQueryParams.shape,\n obligation_id: z\n .string({ error: \"Obligation id is required and must be a valid 32-byte hex string\" })\n .regex(/^0x[a-fA-F0-9]{64}$/, { error: \"Obligation id must be a valid 32-byte hex string\" })\n .transform<Hex>((val) => val.toLowerCase() as Hex)\n .meta({\n description: \"Obligation id\",\n example: \"0x1234567890123456789012345678901234567890123456789012345678901234\",\n }),\n side: z.enum([\"buy\", \"sell\"]).meta({\n description: \"Side of the book (buy or sell).\",\n example: \"buy\",\n }),\n});\n\nconst ValidateOffersBody = z\n .object({\n offers: z.array(z.unknown()).min(1, { message: \"'offers' must contain at least 1 offer\" }),\n })\n .strict();\n\nconst CallbackTypesBody = z\n .object({\n callbacks: z.array(\n z\n .object({\n chain_id: z.number().int().positive().meta({\n description: \"Chain id.\",\n example: 1,\n }),\n addresses: z\n .array(\n z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, {\n error: \"Callback address must be a valid 20-byte address\",\n })\n .transform<Address>((val) => val.toLowerCase() as Address),\n )\n .meta({\n description: \"Callback contract addresses.\",\n example: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x3333333333333333333333333333333333333333\",\n ],\n }),\n })\n .strict(),\n ),\n })\n .strict();\n\nexport const GetUserPositionsParams = z.object({\n ...PaginationQueryParams.shape,\n user_address: z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, { error: \"User address must be a valid 20-byte address\" })\n .transform<Address>((val) => val.toLowerCase() as Address)\n .meta({\n description: \"User address to get positions for\",\n example: \"0x7b093658BE7f90B63D7c359e8f408e503c2D9401\",\n }),\n});\n\nconst schemas = {\n get_health: HealthQueryParams,\n get_health_collectors: HealthQueryParams,\n get_health_chains: HealthQueryParams,\n get_config_contracts: GetConfigContractsQueryParams,\n get_config_rules: GetConfigRulesQueryParams,\n get_offers: GetOffersQueryParams,\n get_obligations: GetObligationsQueryParams,\n get_obligation: GetObligationParams,\n get_book: GetBookParams,\n validate_offers: ValidateOffersBody,\n callback_types: CallbackTypesBody,\n get_user_positions: GetUserPositionsParams,\n} as const;\n\ntype Action = keyof typeof schemas;\n\nexport function parse<A extends Action>(action: A, query: unknown): z.infer<(typeof schemas)[A]> {\n return schemas[action].parse(query) as z.infer<(typeof schemas)[A]>;\n}\n\nexport function safeParse<A extends Action>(\n action: A,\n query: unknown,\n error?: z.core.$ZodErrorMap<z.core.$ZodIssue>,\n): z.ZodSafeParseResult<z.infer<(typeof schemas)[A]>> {\n return schemas[action].safeParse(query, {\n error,\n }) as z.ZodSafeParseResult<z.infer<(typeof schemas)[A]>>;\n}\n","export * as BookResponse from \"./BookResponse.ts\";\nexport * from \"./health.ts\";\nexport * as ObligationResponse from \"./ObligationResponse.ts\";\nexport * as OfferResponse from \"./OfferResponse.ts\";\nexport * from \"./openapi.ts\";\nexport * as PositionResponse from \"./PositionResponse.ts\";\nexport { parse, safeParse } from \"./requests.ts\";\n","import createOpenApiFetchClient, { type Client as OpenApiFetchClient } from \"openapi-fetch\";\nimport type { Address, Hex } from \"viem\";\nimport { type Compute, Maturity, Obligation, Offer, Quote } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type * as GeneratedApiSchema from \"../api/Schema/generated/swagger.d.ts\";\n\ntype RouterClientConfig = {\n /** The URL of the router. */\n readonly url: URL;\n /** The default headers to use for each request. */\n readonly headers: Headers;\n};\n\nexport type Client = Compute<\n RouterClientConfig & {\n /**\n * Get offers from the router.\n * @param parameters - {@link getOffers.Parameters}\n * @returns The offers with pagination cursor. {@link getOffers.ReturnType}\n * @throws If the request fails - {@link getOffers.ErrorType}\n *\n * @example\n * ```ts\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * const { offers, cursor } = await router.getOffers({ side: \"buy\", obligationId: \"0xa1c...d2f\" });\n * console.log(offers);\n * ```\n */\n getOffers: (parameters: getOffers.Parameters) => Promise<getOffers.ReturnType>;\n\n /**\n * Get obligations from the router.\n * @param parameters - {@link getObligations.Parameters}\n * @returns The obligations with pagination cursor. {@link getObligations.ReturnType}\n * @throws If the request fails - {@link getObligations.ErrorType}\n *\n * @example\n * ```ts\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * const { obligations, cursor } = await router.getObligations();\n * console.log(obligations[0].id()); // 0x123...456\n * ```\n */\n getObligations: (parameters?: getObligations.Parameters) => Promise<getObligations.ReturnType>;\n }\n>;\n\nexport type ConnectOptions = {\n /** The URL of the router to interact with.\n * @default \"https://router.morpho.dev\"\n */\n url?: string;\n /** The API key to use for the router API. */\n apiKey?: string;\n /** The default headers to use for each request. */\n headers?: Headers;\n};\n\n/**\n * Creates an instance of a router client.\n * @constructor\n * @param parameters - {@link connect.Parameters}\n * @returns A Router Client. {@link connect.ReturnType}\n *\n * @example\n * ```typescript\n * const router = RouterClient.connect({ url: \"https://router.morpho.dev\" });\n * ```\n */\nexport function connect(parameters?: connect.Parameters): connect.ReturnType {\n const u = new URL(parameters?.url || \"https://router.morpho.dev\");\n if (u.protocol !== \"http:\" && u.protocol !== \"https:\") throw new InvalidUrlError(u.toString());\n\n const headers = parameters?.headers ?? new Headers();\n headers.set(\"Content-Type\", \"application/json\");\n parameters?.apiKey !== undefined ? headers.set(\"X-API-Key\", parameters.apiKey) : null;\n\n const config: RouterClientConfig = { url: u, headers };\n\n const apiClient = createOpenApiFetchClient<GeneratedApiSchema.paths>({\n baseUrl: config.url.toString(),\n headers: config.headers,\n querySerializer: { array: { style: \"form\", explode: false } },\n });\n\n return {\n ...config,\n getOffers: (parameters) => getOffers(apiClient, parameters),\n getObligations: (parameters) => getObligations(apiClient, parameters),\n };\n}\n\nexport declare namespace connect {\n export type Parameters = ConnectOptions;\n export type ReturnType = Client;\n export type ErrorType = InvalidUrlError;\n}\n\nexport async function getOffers(\n apiClient: OpenApiFetchClient<GeneratedApiSchema.paths>,\n parameters: getOffers.Parameters,\n): Promise<getOffers.ReturnType> {\n const { data, error, response } = await apiClient.GET(\"/v1/offers\", {\n params: {\n query: {\n side: parameters.side,\n obligation_id: parameters.obligationId,\n cursor: parameters.cursor,\n limit: parameters.limit,\n },\n },\n });\n\n if (error !== undefined) {\n switch (response.status) {\n case 401:\n throw new HttpUnauthorizedError();\n case 403:\n throw new HttpForbiddenError();\n case 429:\n throw new HttpRateLimitError();\n }\n throw new HttpGetApiFailedError(`GET request returned ${response.status}`, {\n details: JSON.stringify(error),\n });\n }\n\n const offers =\n data?.data.map((item) => {\n const { root, proof, signature, offer: offerData } = item;\n // Transform new API structure (with nested offer object) to Offer.fromSnakeCase format\n const offer = Offer.fromSnakeCase({\n maker: offerData.maker as Address,\n assets: offerData.assets,\n obligation_units: offerData.obligation_units,\n obligation_shares: offerData.obligation_shares,\n price: offerData.price,\n maturity: Maturity.from(offerData.obligation.maturity),\n expiry: offerData.expiry,\n start: offerData.start,\n group: offerData.group,\n session: offerData.session,\n buy: offerData.buy,\n chain_id: item.chain_id,\n loan_token: offerData.obligation.loan_token as Address,\n collaterals: offerData.obligation.collaterals.map((collateral) => ({\n asset: collateral.token as Address,\n oracle: collateral.oracle as Address,\n lltv: collateral.lltv,\n })),\n callback: {\n address: offerData.callback as Address,\n data: offerData.callback_data as Hex,\n },\n });\n\n return {\n ...offer,\n hash: item.offer_hash as Hex,\n consumed: BigInt(item.consumed),\n takeable: BigInt(item.takeable),\n blockNumber: Number(item.block_number),\n root: (root as Hex) || undefined,\n proof: (proof as Hex[]) || undefined,\n signature: signature ? (signature as Hex) : undefined,\n };\n }) ?? [];\n\n return {\n cursor: data?.cursor ?? null,\n offers,\n };\n}\n\nexport declare namespace getOffers {\n export type Parameters = {\n /** The desired side of the match: 'buy' if you want to buy, 'sell' if you want to sell */\n side: \"buy\" | \"sell\";\n /** The offers obligation id */\n obligationId: Hex;\n /** Pagination cursor in base64url-encoded format */\n cursor?: string;\n /** Maximum number of offers to return. @default 20 */\n limit?: number;\n };\n\n export type ReturnType = {\n offers: Compute<\n Offer.Offer & {\n hash: Hex;\n blockNumber: number;\n consumed: bigint;\n takeable: bigint;\n } & {\n /** 32-byte merkle root. */\n root?: Hex;\n /** Sibling hashes for the merkle proof. */\n proof?: Hex[];\n /** Offer signature from the Merkle tree. */\n signature?: Hex;\n }\n >[];\n /** The pagination cursor. */\n cursor: string | null;\n };\n\n export type ErrorType = GetApiErrorType;\n}\n\nexport async function getObligations(\n apiClient: OpenApiFetchClient<GeneratedApiSchema.paths>,\n parameters?: getObligations.Parameters,\n): Promise<getObligations.ReturnType> {\n const { data, error, response } = await apiClient.GET(\"/v1/obligations\", {\n params: {\n query: {\n cursor: parameters?.cursor,\n limit: parameters?.limit,\n chains: parameters?.chainIds,\n loan_tokens: parameters?.loanTokens,\n collateral_tokens: parameters?.collateralTokens,\n maturities: parameters?.maturities,\n },\n },\n });\n\n if (error !== undefined) {\n switch (response.status) {\n case 401:\n throw new HttpUnauthorizedError();\n case 403:\n throw new HttpForbiddenError();\n case 429:\n throw new HttpRateLimitError();\n }\n throw new HttpGetApiFailedError(`GET request returned ${response.status}`, {\n details: JSON.stringify(error),\n });\n }\n\n const obligations =\n data?.data.map((item) => {\n const obligation = Obligation.fromSnakeCase({\n chain_id: item.chain_id,\n loan_token: item.loan_token as Address,\n collaterals: item.collaterals.map((collateral) => ({\n asset: collateral.token as Address,\n oracle: collateral.oracle as Address,\n lltv: collateral.lltv,\n })),\n maturity: Maturity.from(item.maturity),\n });\n\n const { obligationId: _, ...returned } = {\n id: () => Obligation.id(obligation),\n ...obligation,\n ...Quote.fromSnakeCase({ obligation_id: item.id as Hex, ask: item.ask, bid: item.bid }),\n };\n return returned;\n }) ?? [];\n\n return {\n cursor: data?.cursor ?? null,\n obligations,\n };\n}\n\nexport declare namespace getObligations {\n export type Parameters = {\n /** Pagination cursor is a 32-byte hex string. */\n cursor?: Hex;\n /** Maximum number of obligations to return. @default 20 */\n limit?: number;\n /** Filter by chain IDs (comma-separated). */\n chainIds?: number[];\n /** Filter by loan token addresses (comma-separated). */\n loanTokens?: Address[];\n /** Filter by collateral tokens (comma-separated, matches any collateral). */\n collateralTokens?: Address[];\n /** Filter by exact maturity timestamps (comma-separated, unix seconds). */\n maturities?: number[];\n };\n\n export type ReturnType = {\n obligations: Compute<\n {\n /** The obligation id. Uses {@link Obligation.id} to calculate the id.*/\n id: () => Hex;\n } & Obligation.Obligation &\n Omit<Quote.Quote, \"obligationId\">\n >[];\n /** The pagination cursor. */\n cursor: string | null;\n };\n\n export type ErrorType = GetApiErrorType;\n}\n\ntype GetApiErrorType =\n | HttpGetApiFailedError\n | HttpUnauthorizedError\n | HttpForbiddenError\n | HttpRateLimitError;\n\nexport class InvalidUrlError extends Errors.BaseError {\n override name = \"Router.InvalidUrlError\";\n constructor(url: string) {\n super(`URL \"${url}\" is not http/https.`);\n }\n}\n\nexport class HttpUnauthorizedError extends Errors.BaseError {\n override name = \"Router.HttpUnauthorizedError\";\n constructor() {\n super(\"Unauthorized.\", {\n metaMessages: [\"Ensure that an API key is provided.\"],\n });\n }\n}\n\nexport class HttpForbiddenError extends Errors.BaseError {\n override name = \"Router.HttpForbiddenError\";\n constructor() {\n super(\"Forbidden.\", {\n metaMessages: [\"Ensure that the API key is valid.\"],\n });\n }\n}\n\nexport class HttpRateLimitError extends Errors.BaseError {\n override name = \"Router.HttpRateLimitError\";\n constructor() {\n super(\"Rate limit exceeded.\", {\n metaMessages: [\n \"The number of allowed requests has been exceeded. You must wait for the rate limit to reset.\",\n ],\n });\n }\n}\n\nexport class HttpGetApiFailedError extends Errors.BaseError {\n override name = \"Router.HttpGetApiFailedError\";\n constructor(message: string, { details }: { details?: string } = {}) {\n super(message, {\n metaMessages: [details],\n });\n }\n}\n","import type { Offer } from \"#core\";\nimport * as OfferCore from \"#core/Offer.ts\";\nimport type * as Gate from \"./Gate.ts\";\nimport type {\n CallbackTypesRequest,\n CallbackTypesResponse,\n ConfigRule,\n ConfigRulesPayload,\n ErrorPayload,\n SuccessPayload,\n ValidateOffersData,\n} from \"./types.ts\";\n\nexport type GatekeeperClient = {\n /** Validate offers and return the raw response payload. */\n validate: (body: unknown) => Promise<{ statusCode: number; body: unknown }>;\n /** Get configured rules for supported chains. */\n getConfigRules: (query?: {\n cursor?: string;\n limit?: number | string;\n types?: Array<ConfigRule[\"type\"]> | ConfigRule[\"type\"];\n }) => Promise<{ statusCode: number; body: ConfigRulesPayload }>;\n /** Validate offers and return decision results. */\n isAllowed: (offers: Offer.Offer[]) => Promise<Gate.Result<Offer.Offer, string>>;\n /** Resolve callback types for callback addresses. */\n getCallbackTypes: (request: CallbackTypesRequest) => Promise<CallbackTypesResponse>;\n /** Base URL for the gatekeeper service. */\n baseUrl: string;\n};\n\nexport type ClientConfig = {\n baseUrl: string;\n timeoutMs?: number;\n fetchFn?: typeof fetch;\n originSecret?: string;\n};\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\n/**\n * Create an HTTP client for a gatekeeper service.\n * @param config - Gatekeeper client configuration. {@link ClientConfig}\n * @returns An HTTP-backed gatekeeper client. {@link GatekeeperClient}\n */\nexport function createHttpClient(config: ClientConfig): GatekeeperClient {\n const fetchFn = config.fetchFn ?? fetch;\n const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const baseUrl = normalizeBaseUrl(config.baseUrl);\n const baseHeaders = config.originSecret ? { \"x-origin-verify\": config.originSecret } : undefined;\n\n const request = async (path: string, init: RequestInit): Promise<Response> => {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n try {\n return await fetchFn(`${baseUrl}${path}`, {\n ...init,\n headers: mergeHeaders(baseHeaders, init.headers),\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timeout);\n }\n };\n\n const validate = async (body: unknown): Promise<{ statusCode: number; body: unknown }> => {\n const response = await request(\"/v1/validate\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n const json = (await response.json()) as unknown;\n return { statusCode: response.status, body: json };\n };\n\n const getConfigRules = async (query?: {\n cursor?: string;\n limit?: number | string;\n types?: Array<ConfigRule[\"type\"]> | ConfigRule[\"type\"];\n }): Promise<{ statusCode: number; body: ConfigRulesPayload }> => {\n const params = new URLSearchParams();\n if (query?.cursor) params.set(\"cursor\", query.cursor);\n if (query?.limit !== undefined) params.set(\"limit\", query.limit.toString());\n if (query?.types !== undefined) {\n const typesValue = Array.isArray(query.types) ? query.types.join(\",\") : query.types;\n if (typesValue.length > 0) params.set(\"types\", typesValue);\n }\n const path = params.size > 0 ? `/v1/config/rules?${params.toString()}` : \"/v1/config/rules\";\n const response = await request(path, { method: \"GET\" });\n const json = (await response.json()) as ConfigRulesPayload;\n return { statusCode: response.status, body: json };\n };\n\n const isAllowed = async (offers: Offer.Offer[]): Promise<Gate.Result<Offer.Offer, string>> => {\n const payload = {\n offers: offers.map((offer) => OfferCore.toSnakeCase(offer)),\n };\n\n const { statusCode, body } = await validate(payload);\n if (statusCode !== 200) {\n const errorMessage = extractErrorMessage(body);\n throw new Error(`Gatekeeper validation failed: ${errorMessage ?? `status ${statusCode}`}`);\n }\n\n const data = (body as SuccessPayload<ValidateOffersData>).data;\n if (!data || typeof data !== \"object\") {\n throw new Error(\"Gatekeeper validation response is invalid.\");\n }\n\n if (\"issues\" in data) {\n const issues = data.issues.map((issue) => ({\n ruleName: issue.rule,\n message: issue.message,\n item: offers[issue.index]!,\n }));\n const invalidIndices = new Set(data.issues.map((issue) => issue.index));\n const valid = offers.filter((_, index) => !invalidIndices.has(index));\n\n return { valid, issues };\n }\n\n if (!(\"payload\" in data) || !(\"root\" in data)) {\n throw new Error(\"Gatekeeper validation response is missing payload data.\");\n }\n\n return { valid: offers.slice(), issues: [] };\n };\n\n const getCallbackTypes = async (\n requestPayload: CallbackTypesRequest,\n ): Promise<CallbackTypesResponse> => {\n const response = await request(\"/v1/callbacks\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(requestPayload),\n });\n const json = (await response.json()) as SuccessPayload<CallbackTypesResponse> | ErrorPayload;\n if (!response.ok) {\n throw new Error(\n `Gatekeeper callbacks request failed: ${extractErrorMessage(json) ?? response.statusText}`,\n );\n }\n if (!(\"data\" in json) || !Array.isArray(json.data)) {\n throw new Error(\"Gatekeeper callbacks response is invalid.\");\n }\n return json.data;\n };\n\n return {\n baseUrl,\n validate,\n getConfigRules,\n isAllowed,\n getCallbackTypes,\n };\n}\n\nfunction mergeHeaders(\n base: RequestInit[\"headers\"] | undefined,\n extra: RequestInit[\"headers\"] | undefined,\n): RequestInit[\"headers\"] | undefined {\n if (!base && !extra) return undefined;\n const merged = new Headers(base ?? undefined);\n if (extra) {\n for (const [key, value] of new Headers(extra).entries()) {\n merged.set(key, value);\n }\n }\n return merged;\n}\n\nfunction normalizeBaseUrl(url: string): string {\n const trimmed = url.trim().replace(/\\/+$/, \"\");\n return trimmed;\n}\n\nfunction extractErrorMessage(payload: unknown): string | undefined {\n if (!payload || typeof payload !== \"object\") return undefined;\n const error = (payload as ErrorPayload).error;\n if (!error || typeof error !== \"object\") return undefined;\n return typeof error.message === \"string\" ? error.message : undefined;\n}\n","/**\n * A validation rule.\n */\nexport type Rule<T, Name extends string = string> =\n | { kind: \"single\"; name: Name; description: string; run: Single<T, Name> }\n | { kind: \"batch\"; name: Name; description: string; run: Batch<T, Name> };\n\nexport type RuleNames<Rules extends readonly { name: string }[]> = Rules[number][\"name\"];\n\n/**\n * A single item validation rule.\n * @param item - The item to validate.\n * @returns The issue that was found. If the item is valid, this will be undefined.\n */\nexport type Single<T, RuleName extends string> = (\n item: T,\n) =>\n | Omit<Issue<T, RuleName>, \"ruleName\" | \"item\">\n | undefined\n | Promise<Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>;\n\n/**\n * A batch item validation rule.\n * @param items - The items to validate.\n * @returns A map of the items to the issue that was found.\n */\nexport type Batch<T, RuleName extends string> = (\n items: T[],\n) =>\n | Map<number, Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>\n | Promise<Map<number, Omit<Issue<T, RuleName>, \"ruleName\" | \"item\"> | undefined>>;\n\n/**\n * Create a validation rule iterating over a single item at a time.\n * @param name - The name of the rule.\n * @param description - A human-readable description of the rule.\n * @param run - The function that validates the rule.\n * @returns The created rule.\n */\nexport function single<Name extends string, T>(\n name: Name,\n description: string,\n run: Single<T, Name>,\n): Rule<T, Name> {\n return { kind: \"single\", name, description, run } as const satisfies Rule<T, Name>;\n}\n\n/**\n * Create a validation rule iterating over a batch of items at a time.\n * @param name - The name of the rule.\n * @param description - A human-readable description of the rule.\n * @param run - The function that validates the rule.\n * @returns The created rule.\n */\nexport function batch<Name extends string, T>(\n name: Name,\n description: string,\n run: Batch<T, Name>,\n): Rule<T, Name> {\n return { kind: \"batch\", name, description, run } as const satisfies Rule<T, Name>;\n}\n\n/**\n * A validation issue.\n */\nexport type Issue<T, RuleName extends string = string> = {\n /** The name of the rule that caused the issue. */\n ruleName: RuleName;\n /** The message of the issue. */\n message: string;\n /** The item that was not valid. */\n item: T;\n};\n\n/**\n * The result of a validation.\n */\nexport type Result<T, RuleName extends string = string> = {\n /** The items that were valid. */\n valid: T[];\n /** The reports of the failed validations. */\n issues: Issue<T, RuleName>[];\n};\n\nexport async function run<\n T,\n Name extends string,\n Rules extends readonly Rule<T, Name>[],\n>(parameters: {\n items: T[];\n rules: Rules;\n chunkSize?: number;\n}): Promise<Result<T, RuleNames<Rules>>> {\n const { items, rules, chunkSize } = parameters;\n\n const issues: Issue<T, RuleNames<Rules>>[] = [];\n let validItems: T[] = items.slice();\n\n for (const rule of rules) {\n if (validItems.length === 0) return { valid: [], issues };\n\n const indicesToRemove: Set<number> = new Set();\n if (rule.kind === \"single\") {\n for (let i = 0; i < validItems.length; i++) {\n const item = validItems[i]!;\n const issue = await rule.run(item);\n if (issue) {\n issues.push({ ...issue, ruleName: rule.name, item });\n indicesToRemove.add(i);\n }\n }\n } else if (rule.kind === \"batch\") {\n const exec = async (slice: T[], offset: number) => {\n const map = await rule.run(slice);\n for (let i = 0; i < slice.length; i++) {\n const issue = map.get(i);\n if (issue !== undefined) {\n issues.push({ ...issue, ruleName: rule.name, item: slice[i]! });\n indicesToRemove.add(offset + i);\n }\n }\n };\n\n if (!chunkSize) await exec(validItems, 0);\n else {\n for (let i = 0; i < validItems.length; i += chunkSize) {\n await exec(validItems.slice(i, i + chunkSize), i);\n }\n }\n }\n\n validItems = validItems.filter((_, i) => !indicesToRemove.has(i));\n }\n\n return {\n valid: validItems,\n issues,\n };\n}\n","import type { Offer } from \"#core\";\nimport * as Gate from \"./Gate.ts\";\n\nexport type Rules = readonly Gate.Rule<Offer.Offer, string>[];\n\nexport type Gatekeeper = {\n isAllowed: (offers: Offer.Offer[]) => Promise<Gate.Result<Offer.Offer, string>>;\n};\n\ntype GatekeeperParameters = {\n rules: Rules;\n};\n\n/**\n * Create a gatekeeper instance with the provided rules.\n * @param parameters - Gatekeeper parameters. {@link GatekeeperParameters}\n * @returns Gatekeeper instance. {@link Gatekeeper}\n */\nexport function create(parameters: GatekeeperParameters): Gatekeeper {\n const { rules } = parameters;\n return {\n isAllowed: async (offers: Offer.Offer[]) => {\n return await Gate.run({\n items: offers,\n rules,\n });\n },\n };\n}\n","import type { Address } from \"viem\";\nimport * as Callback from \"../core/Callback.ts\";\nimport * as Chain from \"../core/Chain.ts\";\nimport * as Maturity from \"../core/Maturity.ts\";\n\nexport type GateConfig = {\n callbacks?: CallbackConfig[];\n maturities?: Maturity.MaturityType[];\n};\n\nexport type CallbackConfig =\n | {\n type: Callback.Type.BuyVaultV1Callback;\n addresses: Address[];\n vaultFactories: Address[];\n }\n | {\n type: Callback.Type.SellERC20Callback;\n addresses: Address[];\n }\n | {\n type: Callback.Type.BuyWithEmptyCallback;\n };\n\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.Type.BuyVaultV1Callback,\n): Extract<CallbackConfig, { type: Callback.Type.BuyVaultV1Callback }> | undefined;\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.Type.SellERC20Callback,\n): Extract<CallbackConfig, { type: Callback.Type.SellERC20Callback }> | undefined;\nexport function getCallback(\n chain: Chain.Name,\n type: Callback.Type.BuyWithEmptyCallback,\n): Extract<CallbackConfig, { type: Callback.Type.BuyWithEmptyCallback }> | undefined;\nexport function getCallback(chain: Chain.Name, type: Callback.Type): CallbackConfig | undefined;\n/**\n * Returns the callback configuration for a given chain and callback type, if it exists.\n *\n * @param chain - Chain name for which to read the validation configuration\n * @param type - Callback type to retrieve\n * @returns The matching callback configuration or undefined if not configured\n */\nexport function getCallback(chain: Chain.Name, type: Callback.Type): CallbackConfig | undefined {\n return configs[chain].callbacks?.find((c) => c.type === type);\n}\n\n/**\n * Attempts to infer the configured callback type from a callback address on a chain.\n * Skips the empty callback type as it does not carry addresses.\n *\n * @param chain - Chain name for which to infer the callback type\n * @param address - Callback contract address\n * @returns The callback type when found, otherwise undefined\n */\nexport function getCallbackType(chain: Chain.Name, address: Address) {\n return configs[chain].callbacks?.find(\n (c) =>\n c.type !== Callback.Type.BuyWithEmptyCallback &&\n c.addresses.includes(address?.toLowerCase() as Address),\n )?.type;\n}\n\n/**\n * Returns the callback addresses for a given chain and callback type, if it exists.\n * @param chain - Chain name for which to read the validation configuration\n * @param type - Callback type to retrieve\n * @returns The matching callback addresses or an empty array if not configured\n */\nexport function getCallbackTypeAddresses(chain: Chain.Name, type: Callback.Type): Address[] {\n if (type === Callback.Type.BuyWithEmptyCallback) {\n return [];\n }\n const match = configs[chain].callbacks?.find((c) => c.type === type);\n return match && \"addresses\" in match ? match.addresses : [];\n}\n\n/**\n * Returns the list of allowed non-empty callback addresses for a chain.\n *\n * @param chain - Chain name\n * @returns Array of allowed callback addresses (lowercased). Empty when none configured\n */\nexport const getCallbackAddresses = (chain: Chain.Name): Address[] => {\n return (\n configs[chain].callbacks\n ?.filter((c) => c.type !== Callback.Type.BuyWithEmptyCallback)\n .flatMap((c) => c.addresses) ?? []\n );\n};\n\nexport const assets: Record<string, Address[]> = {\n [Chain.ChainId.ETHEREUM.toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n [Chain.ChainId.BASE.toString()]: [\n \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\", // USDC\n \"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb\", // DAI\n \"0x4200000000000000000000000000000000000006\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n [Chain.ChainId[\"ETHEREUM-VIRTUAL-TESTNET\"].toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n \"0xce79ddb3152d52ff8fe65a4c7e058b035fcb560a\", // test token\n ],\n [Chain.ChainId.ANVIL.toString()]: [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", // USDC\n \"0x6B175474E89094C44Da98b954EedeAC495271d0F\", // DAI\n \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", // WETH\n \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", // WBTC\n ],\n};\n\nexport const configs: Record<Chain.Name, GateConfig> = {\n ethereum: {\n callbacks: [\n {\n type: Callback.Type.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.Type.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.Type.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n base: {\n callbacks: [\n {\n type: Callback.Type.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0xFf62A7c278C62eD665133147129245053Bbf5918\", //v1.1\n ],\n },\n {\n type: Callback.Type.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.Type.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n \"ethereum-virtual-testnet\": {\n callbacks: [\n {\n type: Callback.Type.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.Type.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.Type.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n anvil: {\n callbacks: [\n {\n type: Callback.Type.BuyVaultV1Callback,\n addresses: [\n \"0x3333333333333333333333333333333333333333\",\n \"0x4444444444444444444444444444444444444444\",\n ],\n vaultFactories: [\n \"0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101\", //v1.0\n \"0x1897A8997241C1cD4bD0698647e4EB7213535c24\", //v1.1\n ],\n },\n {\n type: Callback.Type.SellERC20Callback,\n addresses: [\n \"0x1111111111111111111111111111111111111111\",\n \"0x2222222222222222222222222222222222222222\",\n ],\n },\n { type: Callback.Type.BuyWithEmptyCallback },\n ],\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n },\n};\n","import type { Address, PublicClient, Transport } from \"viem\";\nimport { multicall } from \"viem/actions\";\nimport { Abi, Callback, type Chain, Maturity, type Offer } from \"#core\";\nimport * as BigMath from \"#utils/BigMath.ts\";\nimport type * as Validation from \"./Gate.ts\";\nimport { batch, single } from \"./Gate.ts\";\nimport * as GateConfig from \"./GateConfig.ts\";\n\nexport type ValidityParameters = {\n client: PublicClient<Transport, Chain.Chain>;\n};\n\n/**\n * set of rules to validate offers.\n *\n * @param parameters - Validity parameters with chain and client\n * @returns Array of validation rules to evaluate against offers\n */\nexport function validity(parameters: ValidityParameters) {\n const { client } = parameters;\n\n const sellErc20CallbackInvalid = single(\n \"sell_erc20_callback_invalid\",\n \"Validates that sell offers have valid ERC20 callback data matching offer collaterals\",\n (offer: Offer.Offer) => {\n const callbackType = GateConfig.getCallbackType(client.chain.name, offer.callback.address);\n if (callbackType !== Callback.Type.SellERC20Callback) {\n return;\n }\n const decoded = Callback.decode(callbackType as Callback.Type, offer.callback.data);\n if (decoded.length === 0) {\n return { message: \"Callback data cannot be decoded or is empty.\" };\n }\n if (callbackType === Callback.Type.SellERC20Callback) {\n const offerCollaterals = new Set(\n offer.collaterals.map((c) => c.asset.toLowerCase() as Address),\n );\n if (decoded.length !== offer.collaterals.length) {\n return {\n message: `Sell callback collateral length mismatch. Expected ${offer.collaterals.length}, got ${decoded.length}.`,\n };\n }\n for (const { contract } of decoded as Array<{ contract: Address; amount: bigint }>) {\n if (!offerCollaterals.has(contract.toLowerCase() as Address)) {\n return { message: \"Sell callback collateral is not part of offer collaterals.\" };\n }\n }\n }\n },\n );\n\n const buyCallbackVaultInvalid = batch(\n \"buy_offers_callback_vault_invalid\",\n \"Validates that buy offers have valid vault callbacks registered in allowed factories with matching assets\",\n async (offers: Offer.Offer[]) => {\n const validationIssues = new Map<\n number,\n | Omit<\n Validation.Issue<Offer.Offer, \"buy_offers_callback_vault_invalid\">,\n \"ruleName\" | \"item\"\n >\n | undefined\n >();\n\n const offersByVaultAddress = new Map<string, Array<{ index: number; offer: Offer.Offer }>>();\n for (let i = 0; i < offers.length; i++) {\n const offer = offers[i]!;\n const callbackType = GateConfig.getCallbackType(client.chain.name, offer.callback.address);\n if (callbackType !== Callback.Type.BuyVaultV1Callback) {\n continue;\n }\n try {\n const callbackVaults = Callback.decodeBuyVaultV1Callback(offer.callback.data);\n for (const { contract } of callbackVaults) {\n const normalizedVaultAddress = contract.toLowerCase();\n if (!offersByVaultAddress.has(normalizedVaultAddress)) {\n offersByVaultAddress.set(normalizedVaultAddress, []);\n }\n offersByVaultAddress.get(normalizedVaultAddress)!.push({ index: i, offer });\n }\n } catch (_) {\n // Skip - invalid callback data is already caught by buyCallbackDataInvalid rule\n }\n }\n\n const uniqueVaultAddresses = Array.from(offersByVaultAddress.keys());\n if (uniqueVaultAddresses.length === 0) return validationIssues;\n\n const allowedFactories = GateConfig.getCallback(\n client.chain.name,\n Callback.Type.BuyVaultV1Callback,\n )?.vaultFactories.map((f) => f.toLowerCase() as Address);\n\n if (!allowedFactories) return validationIssues;\n\n const multicallContracts = [];\n for (const vaultAddress of uniqueVaultAddresses) {\n multicallContracts.push({\n address: vaultAddress as Address,\n abi: Abi.ERC4626,\n functionName: \"asset\",\n } as const);\n\n for (const factoryAddress of allowedFactories) {\n multicallContracts.push({\n address: factoryAddress as Address,\n abi: Abi.MetaMorphoFactory,\n functionName: \"isMetaMorpho\",\n args: [vaultAddress as Address],\n } as const);\n }\n }\n\n const multicallResults = await multicall(client, {\n contracts: multicallContracts,\n allowFailure: true,\n });\n\n const vaultAssetByAddress = new Map<string, Address | null>();\n const registeredVaults = new Set<string>();\n\n const numberOfFactories = allowedFactories.length;\n\n let resultIndex = 0;\n for (const vaultAddress of uniqueVaultAddresses) {\n const assetCallResult = multicallResults[resultIndex++]!;\n const assetAddress =\n assetCallResult.status === \"success\" ? (assetCallResult.result as Address) : null;\n\n vaultAssetByAddress.set(vaultAddress, assetAddress);\n\n let isRegisteredInFactory = false;\n for (let factoryIndex = 0; factoryIndex < numberOfFactories; factoryIndex++) {\n const factoryCallResult = multicallResults[resultIndex++]!;\n\n if (factoryCallResult.status === \"success\" && factoryCallResult.result === true) {\n isRegisteredInFactory = true;\n }\n }\n\n if (isRegisteredInFactory) {\n registeredVaults.add(vaultAddress);\n }\n }\n\n const uniqueOffers = new Map<number, Offer.Offer>();\n for (const offersArray of offersByVaultAddress.values()) {\n for (const { index, offer } of offersArray) {\n uniqueOffers.set(index, offer);\n }\n }\n\n for (const [index, offer] of uniqueOffers) {\n try {\n const callbackVaults = Callback.decodeBuyVaultV1Callback(offer.callback.data);\n const vaultsWithIssues: Array<{ vaultAddress: Address; failureReasons: string }> = [];\n\n for (const { contract } of callbackVaults) {\n const normalizedVaultAddress = contract.toLowerCase();\n const assetAddress = vaultAssetByAddress.get(normalizedVaultAddress);\n const isRegistered = registeredVaults.has(normalizedVaultAddress);\n\n const failureReasons: string[] = [];\n\n if (assetAddress === null) {\n failureReasons.push(\"asset call failed\");\n } else if (\n assetAddress &&\n assetAddress.toLowerCase() !== offer.loanToken.toLowerCase()\n ) {\n failureReasons.push(\"asset mismatch\");\n }\n\n if (!isRegistered) {\n failureReasons.push(\"not registered in factory\");\n }\n\n if (failureReasons.length > 0) {\n vaultsWithIssues.push({\n vaultAddress: contract,\n failureReasons: failureReasons.join(\", \"),\n });\n }\n }\n\n if (vaultsWithIssues.length > 0) {\n const failureDetails = vaultsWithIssues\n .map((v) => `${v.vaultAddress} (${v.failureReasons})`)\n .join(\"; \");\n validationIssues.set(index, {\n message: `Buy offer callback vaults are invalid: ${failureDetails}`,\n });\n }\n } catch (_) {\n // Skip - invalid callback data is already caught by buyCallbackDataInvalid rule\n }\n }\n\n return validationIssues;\n },\n );\n\n const expiry = single(\"expiry\", \"Validates that offer has not expired\", (offer: Offer.Offer) => {\n if (offer.expiry < Math.floor(Date.now() / 1000)) {\n return { message: \"Expiry mismatch\" };\n }\n });\n\n return [expiry, sellErc20CallbackInvalid, buyCallbackVaultInvalid];\n}\n\nexport const chains = ({ chains }: { chains: Chain.Chain[] }) =>\n single(\n \"chain_ids\",\n `Validates that offer chain is one of: [${chains.map((c) => c.id).join(\", \")}]`,\n (offer: Offer.Offer) => {\n const allowedChainIds = chains.map((c) => c.id);\n if (!allowedChainIds.some((id) => id === offer.chainId)) {\n return {\n message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(\", \")})`,\n };\n }\n },\n );\n\nexport const maturity = ({ maturities }: { maturities: Maturity.MaturityType[] }) =>\n single(\n \"maturity\",\n `Validates that offer maturity is one of: [${maturities!.join(\", \")}]`,\n (offer: Offer.Offer) => {\n const allowedMaturities = maturities!.map((m) => Maturity.from(m));\n if (!allowedMaturities.includes(offer.maturity)) {\n return {\n message: `Maturity must be end of current month (${allowedMaturities[0]}) or end of next month (${allowedMaturities[1]}). Got: ${offer.maturity}`,\n };\n }\n },\n );\n\nexport const callback = ({\n callbacks,\n allowedAddresses,\n}: {\n callbacks: Callback.Type[];\n allowedAddresses: Address[];\n}) =>\n single(\n \"callback\",\n `Validates callbacks: buy empty callback is ${callbacks.includes(Callback.Type.BuyWithEmptyCallback) ? \"allowed\" : \"not allowed\"}; sell offers must use a non-empty callback; non-empty callbacks must target one of [${allowedAddresses.map((a) => a.toLowerCase()).join(\", \")}]`,\n (offer: Offer.Offer) => {\n if (\n Callback.isEmptyCallback(offer) &&\n offer.buy &&\n !callbacks?.find((c) => c === Callback.Type.BuyWithEmptyCallback)\n ) {\n return {\n message: \"Buy offers with empty callback not allowed.\",\n };\n }\n if (Callback.isEmptyCallback(offer) && !offer.buy) {\n return {\n message: \"Sell offers require a non-empty callback.\",\n };\n }\n if (!Callback.isEmptyCallback(offer)) {\n if (!allowedAddresses.includes(offer.callback.address?.toLowerCase() as Address)) {\n return {\n message: `Callback address ${offer.callback.address} is not allowed.`,\n };\n }\n }\n },\n );\n\n/**\n * A validation rule that checks if the offer's tokens are allowed for its chain.\n * @param assetsByChainId - Allowed assets indexed by chain id.\n * @returns The issue that was found. If the offer is valid, this will be undefined.\n */\nexport const token = ({\n assetsByChainId,\n}: {\n assetsByChainId: Partial<Record<Chain.Id, Address[]>>;\n}) =>\n single(\n \"token\",\n \"Validates that offer loan token and collateral tokens are in the allowed assets list for the offer chain\",\n (offer: Offer.Offer) => {\n const allowedAssets = assetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase());\n if (!allowedAssets || allowedAssets.length === 0) {\n return { message: `No allowed assets for chain ${offer.chainId}` };\n }\n if (!allowedAssets.includes(offer.loanToken.toLowerCase())) {\n return { message: \"Loan token is not allowed\" };\n }\n if (\n offer.collaterals.some(\n (collateral) => !allowedAssets.includes(collateral.asset.toLowerCase()),\n )\n ) {\n return { message: \"Collateral is not allowed\" };\n }\n return undefined;\n },\n );\n\n/**\n * A batch validation rule that ensures all offers in a tree have the same maker address.\n * Returns an issue only for the first non-conforming offer.\n * This rule is signing-agnostic; signer verification is handled at the collector level.\n */\nexport const sameMaker = () =>\n batch(\n \"mixed_maker\",\n \"Validates that all offers in a batch have the same maker address\",\n (offers: Offer.Offer[]) => {\n const issues = new Map<\n number,\n Omit<Validation.Issue<Offer.Offer, \"mixed_maker\">, \"ruleName\" | \"item\"> | undefined\n >();\n\n if (offers.length === 0) return issues;\n\n const firstMaker = offers[0]!.maker.toLowerCase();\n\n for (let i = 1; i < offers.length; i++) {\n const offer = offers[i]!;\n if (offer.maker.toLowerCase() !== firstMaker) {\n issues.set(i, {\n message: `Offer has different maker ${offer.maker} than first offer ${offers[0]!.maker}`,\n });\n // Return only the first non-conforming offer\n // tree should be dropped entirely when only one offer is invalid\n return issues;\n }\n }\n\n return issues;\n },\n );\n\n/**\n * A validation rule that ensures mutual exclusivity of offer amount fields.\n * At most one of (assets, obligationUnits, obligationShares) can be non-zero.\n * Matches contract requirement: `atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)`.\n */\nexport const amountMutualExclusivity = () =>\n single(\n \"amount_mutual_exclusivity\",\n \"Validates that at most one of (assets, obligationUnits, obligationShares) is non-zero\",\n (offer: Offer.Offer) => {\n if (!BigMath.atMostOneNonZero(offer.assets, offer.obligationUnits, offer.obligationShares)) {\n return {\n message:\n \"Inconsistent offer input: at most one of (assets, obligationUnits, obligationShares) must be non-zero\",\n };\n }\n },\n );\n","import type { Address } from \"viem\";\nimport * as Callback from \"../core/Callback.ts\";\nimport type * as Chain from \"../core/Chain.ts\";\nimport * as Maturity from \"../core/Maturity.ts\";\nimport * as GateConfig from \"./GateConfig.ts\";\nimport * as Rules from \"./Rules.ts\";\n\nexport const morphoRules = (chains: Chain.Chain[]) => {\n const assetsByChainId: Partial<Record<Chain.Id, Address[]>> = {};\n for (const chain of chains) {\n assetsByChainId[chain.id] = GateConfig.assets[chain.id.toString()] ?? [];\n }\n\n return [\n Rules.sameMaker(),\n Rules.amountMutualExclusivity(),\n Rules.chains({ chains }),\n Rules.maturity({\n maturities: [Maturity.MaturityType.EndOfMonth, Maturity.MaturityType.EndOfNextMonth],\n }),\n Rules.callback({\n callbacks: [\n Callback.Type.BuyWithEmptyCallback,\n Callback.Type.BuyVaultV1Callback,\n Callback.Type.SellERC20Callback,\n ],\n allowedAddresses: chains.flatMap((c) => GateConfig.getCallbackAddresses(c.name)),\n }),\n Rules.token({ assetsByChainId }),\n ];\n};\n","import {\n type Address,\n decodeAbiParameters,\n type Hex,\n type PublicClient,\n publicActions,\n type WalletClient as ViemClient,\n zeroAddress,\n} from \"viem\";\nimport type { Compute } from \"#core\";\nimport { Chain, Offer, Tree } from \"#core\";\nimport * as Errors from \"#utils/Errors.ts\";\nimport type * as Client from \"./MempoolClient.ts\";\n\nconst DEFAULT_BATCH_SIZE = 100;\n\ntype MempoolEVMClientConfig = {\n readonly client: ViemClient;\n readonly mempoolAddress: Address;\n readonly morphoAddress?: Address;\n readonly blockWindow?: number;\n};\n\nexport function from(parameters: from.Parameters): from.ReturnType {\n const config: MempoolEVMClientConfig = {\n client: parameters.client,\n mempoolAddress: parameters.mempoolAddress,\n morphoAddress: parameters.morphoAddress,\n blockWindow: parameters.blockWindow,\n };\n\n return {\n add: (parameters) => add(config, parameters),\n get: (parameters) => get(config, parameters),\n stream: (parameters) => streamOffers(config, parameters),\n };\n}\n\nexport declare namespace from {\n type Parameters = {\n /** The viem client to use. */\n client: ViemClient;\n /** The mempool address. */\n mempoolAddress: Address;\n /** The MorphoV2 contract address used for signature verification. */\n morphoAddress?: Address;\n /** The block window to use for the mempool. Defaults to 100. */\n blockWindow?: number;\n };\n\n type ReturnType = Client.Client;\n\n type ErrorType = null;\n}\n\n/**\n * Add an offer to the mempool.\n * @returns The created offer with its hash.\n * @throws WalletAccountNotSetError if the wallet account is not set.\n * @throws ViemClientError if the viem client throws an error.\n * @throws Offer.InvalidOfferError if the offer is invalid.\n */\nexport async function add(\n config: MempoolEVMClientConfig,\n offers: Client.AddParameters,\n): Promise<Hex> {\n if (!config.client.account) throw new WalletAccountNotSetError();\n\n const tree = Tree.from(offers.map((o) => Offer.from(o)));\n const chainId = await getChainId(config.client);\n for (const offer of tree.offers) {\n if (chainId !== offer.chainId) throw new ChainIdMismatchError(offer.chainId, chainId);\n }\n\n const signatureDomain = resolveSignatureDomain(config, chainId);\n const signature = await config.client.signTypedData({\n account: config.client.account,\n domain: Tree.signatureDomain(signatureDomain),\n types: Tree.signatureTypes,\n primaryType: \"Root\",\n message: { root: tree.root },\n });\n const encoded = await Tree.encode(tree, signature, signatureDomain);\n try {\n return await config.client.sendTransaction({\n chain: config.client.chain,\n account: config.client.account!,\n to: config.mempoolAddress,\n data: encoded,\n });\n } catch (error) {\n throw new ViemClientError(error instanceof Error ? error.message : \"Unknown error\");\n }\n}\n\nexport declare namespace add {\n export type ErrorType =\n | WalletAccountNotSetError\n | ViemClientError\n | Offer.InvalidOfferError\n | ChainIdMismatchError\n | MissingMorphoAddressError;\n}\n\nexport async function* get(\n config: MempoolEVMClientConfig,\n parameters?: Client.GetParameters,\n): AsyncGenerator<{ offers: Offer.Offer[]; blockNumber: number }, void, void> {\n const {\n loanToken,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE } = {},\n } = parameters || {};\n\n yield* streamOffers(config, {\n loanToken,\n order,\n blockNumberGte,\n blockNumberLte,\n options: { maxBatchSize, blockWindow: config.blockWindow },\n });\n}\n\nexport declare namespace get {\n export type ErrorType = streamOffersReturnType;\n}\n\nconst chainIdCache = new Map<string, Chain.Id>();\n/**\n * Caches the chain id of a viem client.\n * @param client - The viem client.\n * @returns The chain id.\n */\nconst getChainId = async (client: ViemClient): Promise<Chain.Id> => {\n if (chainIdCache.has(client.uid)) return chainIdCache.get(client.uid)!;\n const chainId = await client.getChainId();\n chainIdCache.set(client.uid, chainId as Chain.Id);\n return chainId as Chain.Id;\n};\n\ntype streamOffersReturnType =\n | WalletAccountNotSetError\n | ChainIdMismatchError\n | MissingMorphoAddressError;\n\nasync function* streamOffers(\n config: MempoolEVMClientConfig,\n parameters: Compute<\n Omit<Client.GetParameters, \"options\"> & {\n options: Client.GetParameters[\"options\"] & { blockWindow?: number };\n }\n >,\n): AsyncGenerator<{ offers: Offer.Offer[]; blockNumber: number }, void, void> {\n const {\n loanToken,\n blockNumberGte,\n blockNumberLte,\n order = \"desc\",\n options: { maxBatchSize = DEFAULT_BATCH_SIZE, blockWindow = config.blockWindow } = {},\n } = parameters;\n\n const signatureDomain = resolveSignatureDomain(config, await getChainId(config.client));\n\n const stream = Chain.streamLogs({\n client: config.client.extend(publicActions) as PublicClient,\n contractAddress: config.mempoolAddress,\n event: {\n type: \"event\",\n name: \"Event\",\n inputs: [{ name: \"data\", type: \"bytes\", indexed: false, internalType: \"bytes\" }],\n anonymous: false,\n } as const,\n blockNumberGte,\n blockNumberLte,\n order,\n options: { maxBatchSize, blockWindow },\n });\n\n let blockNumber = order === \"asc\" ? blockNumberGte : blockNumberLte;\n for await (const { logs, blockNumber: newBlockNumber } of stream) {\n blockNumber = newBlockNumber;\n if (logs.length === 0) continue;\n\n const offers: Offer.Offer[] = [];\n for (const log of logs) {\n if (!log) continue;\n const [payload] = decodeAbiParameters([{ type: \"bytes\" }], log.data);\n try {\n const { tree } = await Tree.decode(payload, signatureDomain);\n for (const offer of tree.offers) {\n if (loanToken && offer.loanToken.toLowerCase() !== loanToken.toLowerCase()) continue;\n offers.push(offer);\n }\n } catch (_) {}\n }\n\n yield {\n offers,\n blockNumber,\n };\n }\n\n yield { offers: [], blockNumber: blockNumber! };\n return;\n}\n\nexport class WalletAccountNotSetError extends Errors.BaseError {\n override name = \"Mempool.WalletAccountNotSetError\";\n constructor() {\n super(\"Wallet account is not set.\");\n }\n}\n\nexport class ViemClientError extends Errors.BaseError {\n override name = \"Mempool.ViemClientError\";\n}\n\nexport class ChainIdMismatchError extends Errors.BaseError {\n override name = \"Mempool.ChainIdMismatchError\";\n constructor(expected: Chain.Id, actual: Chain.Id) {\n super(`Chain ID mismatch. Offer chain ID is ${expected}, network chain ID is ${actual}.`);\n }\n}\n\nconst resolveSignatureDomain = (\n config: MempoolEVMClientConfig,\n chainId: Chain.Id,\n): Tree.SignatureDomain => {\n const chain = config.client.chain as Chain.Chain | undefined;\n const verifyingContract =\n config.morphoAddress ??\n chain?.custom?.morpho?.address ??\n Chain.getChain(chainId)?.custom.morpho.address;\n if (!verifyingContract || verifyingContract.toLowerCase() === zeroAddress) {\n throw new MissingMorphoAddressError();\n }\n return { chainId, verifyingContract };\n};\n\nexport class MissingMorphoAddressError extends Errors.BaseError {\n override name = \"Mempool.MissingMorphoAddressError\";\n constructor() {\n super(\"Morpho address is required to verify root signatures (zero address is invalid).\");\n }\n}\n","import type { Hex } from \"viem\";\nimport type { Compute, Offer } from \"#core\";\nimport * as EVMClient from \"./MempoolEVMClient.ts\";\n\nexport type AddParameters = Compute<Omit<Offer.Offer, \"createdAt\">[]>;\n\nexport type GetParameters = {\n /** The block number to get offers from. */\n blockNumberGte?: number;\n /** The block number to get offers to. */\n blockNumberLte?: number;\n /** The loan asset to get offers from. */\n loanToken?: string;\n /** The order to get offers. Defaults to \"desc\". */\n order?: \"asc\" | \"desc\";\n /** The options to get offers from. */\n options?: {\n /** The maximum number of offers to return. Defaults to 100. Maximum is 1000. */\n maxBatchSize?: number;\n };\n};\n\n/**\n * Mempool client interface.\n */\nexport type Client = {\n /**\n * Add an offer to the mempool.\n * @returns The created offer with its hash.\n */\n add: (parameters: AddParameters) => Promise<Hex>;\n /** Get offers from the mempool. */\n get: (parameters?: GetParameters) => AsyncGenerator<{\n offers: Offer.Offer[];\n /** The block number of the last processed offer. Depends on the `order` parameter, block numbers will ascend or descend. */\n blockNumber: number;\n }>;\n\n /**\n * Stream offers from the mempool.\n * @returns A generator of offers alongside the last block number processed.\n */\n stream: (\n parameters: Compute<\n Omit<GetParameters, \"options\"> & {\n options: GetParameters[\"options\"] & { blockWindow?: number };\n }\n >,\n ) => AsyncGenerator<{\n offers: Offer.Offer[];\n blockNumber: number;\n }>;\n};\n\n/**\n * Client to interact with the Mempool contract on a specific chain.\n */\nexport function connect(parameters: EVMClient.from.Parameters): Client {\n return EVMClient.from(parameters);\n}\n\nexport declare namespace connect {\n export type ErrorType = EVMClient.from.ErrorType;\n}\n","export const retry = async <T>(fn: () => Promise<T>, attempts = 3, delayMs = 50): Promise<T> => {\n let lastErr: unknown;\n for (let i = 0; i < attempts; i++) {\n try {\n return await fn();\n } catch (err) {\n lastErr = err;\n if (i < attempts - 1) await new Promise((r) => setTimeout(r, delayMs));\n }\n }\n throw lastErr;\n};\n","import type { MulticallParameters, PublicClient, Transport } from \"viem\";\nimport { multicall } from \"viem/actions\";\nimport type { Chain } from \"#core\";\nimport { batch } from \"#utils/batch.ts\";\nimport { retry } from \"#utils/retry.ts\";\n\n/**\n * Helper function to execute multicall in batches with retry logic.\n * Abstracts the common pattern of batching calls, retrying, and collecting results.\n *\n * @param parameters - Configuration for batched multicall\n * @returns Promise resolving to flattened array of results\n */\nexport async function batchMulticall<TResult>(parameters: {\n client: PublicClient<Transport, Chain.Chain>;\n calls: MulticallParameters[\"contracts\"];\n batchSize: number;\n retryAttempts: number;\n retryDelayMs: number;\n blockNumber?: bigint;\n}): Promise<TResult[]> {\n const { client, calls, batchSize, retryAttempts, retryDelayMs, blockNumber } = parameters;\n const results: TResult[] = [];\n\n for (const callsBatch of batch(calls, batchSize)) {\n const batchResults = await retry(\n () =>\n multicall(client, {\n allowFailure: false,\n contracts: callsBatch,\n ...(blockNumber ? { blockNumber } : {}),\n }),\n retryAttempts,\n retryDelayMs,\n );\n results.push(...(batchResults as TResult[]));\n }\n\n return results;\n}\n","import { type Hex, pad } from \"viem\";\n\n/**\n * Creates a bytes32 group identifier from a number.\n * @param n - A non-negative integer.\n * @throws {Error} If n is negative or not an integer.\n */\nexport const fromNumber = (n: number): Hex => {\n if (!Number.isInteger(n)) {\n throw new Error(`Group.fromNumber: expected integer, got ${n}`);\n }\n if (n < 0) {\n throw new Error(`Group.fromNumber: expected non-negative, got ${n}`);\n }\n return pad(`0x${n.toString(16)}`, { size: 32 });\n};\n","/**\n * Transform a polling function into an async generator.\n * @param fn - The polling function to transform.\n * @returns An async generator.\n */\nexport function lazy<T>(\n pollFn: (emit: (value: T) => void, { stop }: { stop: () => void }) => () => boolean,\n) {\n return () =>\n (async function* () {\n let active = true;\n let resolveNext: (() => void) | null = null;\n const queue: T[] = [];\n\n const wait = () =>\n new Promise<void>((resolve) => {\n resolveNext = resolve;\n });\n\n const emit = (item: T) => {\n queue.push(item);\n resolveNext?.();\n resolveNext = null;\n };\n\n let unpoll: (() => boolean) | null = null;\n const stop = () => {\n active = false;\n // stop the poller immediately if we already have it\n unpoll?.();\n resolveNext?.();\n resolveNext = null;\n };\n\n unpoll = pollFn(emit, { stop });\n\n try {\n while (active) {\n if (queue.length === 0) await wait();\n while (queue.length > 0 && active) yield queue.shift()!;\n }\n } finally {\n stop();\n }\n })();\n}\n","export async function wait(time: number) {\n return new Promise((res) => setTimeout(res, time));\n}\n","import { wait } from \"./wait.ts\";\n/**\n * Polls a function at a specified interval.\n * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts\n */\nexport function poll<data>(\n fn: ({ unpoll }: { unpoll: () => void }) => Promise<data | undefined>,\n { interval }: { interval: () => Promise<number> },\n) {\n let active = true;\n const unwatch = () => (active = false);\n\n const watch = async () => {\n while (active) {\n const delay = await interval();\n if (!active) break;\n await wait(delay);\n if (!active) break;\n await fn({ unpoll: unwatch });\n }\n };\n\n watch();\n\n return unwatch;\n}\n","export function now(): number {\n return Math.floor(Date.now() / 1000);\n}\n\nexport function max(): number {\n return 8640000000000000000;\n}\n","export * from \"./BigMath.ts\";\nexport * from \"./batch.ts\";\nexport * from \"./batchMulticall.ts\";\nexport * from \"./Errors.ts\";\nexport * from \"./Format.ts\";\nexport * as Group from \"./Group.ts\";\nexport * from \"./lazy.ts\";\nexport * from \"./poll.ts\";\nexport * as Random from \"./Random.ts\";\nexport * from \"./retry.ts\";\nexport * as Time from \"./time.ts\";\nexport * from \"./wait.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAMA,SAAgBA,QAAK,OAA4E;AAC/F,QAAO;EACL,OAAO,MAAM,MAAM,UAAU;EAC7B,QAAQ,MAAM,OAAO,UAAU;EAC/B,OAAO,MAAM;EACd;;;;;ACTH,MAAa,kBAAkB,EAAE,OAAO;CACtC,MAAM,EAAE,QAAQ;CAChB,UAAU,EAAE,QAAQ;CACpB,cAAc,EAAE,QAAQ,CAAC,UAAU;CACnC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,KAAK,EAAE,QAAQ,CAAC,UAAU;CAC1B,QAAQ,EAAE,KAAK;EAAC;EAAQ;EAAW;EAAU,CAAC;CAC9C,aAAa,EAAE,SAAS;CACzB,CAAC;AAEF,MAAa,2BAA2B,EAAE,MAAM,gBAAgB;AAEhE,MAAa,cAAc,EAAE,OAAO;CAClC,UAAU,EAAE,QAAQ;CACpB,oBAAoB,EAAE,QAAQ,CAAC,UAAU;CACzC,qBAAqB,EAAE,QAAQ,CAAC,UAAU;CAC1C,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,aAAa,EAAE,SAAS;C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,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACF;EACD,SAAS,CACP;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,EACD;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS,CACP;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS;GACP;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACF;EACD,iBAAiB;EAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,EACD;GACE,MAAM;GACN,MAAM;GACN,cAAc;GACf,CACF;EACD,SAAS;GACP;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACD;IACE,MAAM;IACN,MAAM;IACN,cAAc;IACf;GACF;EACD,iBAAiB;EAClB;CACF;;;;;;;;;;;;;;;;AC7HD,IAAYC,wCAAL;AACL;AACA;AACA;AACA;;;AAGF,MAAa,mBAAmB,UAAgC,MAAM,SAAS,SAAS;AAExF,SAAgBC,SAAO,MAAY,MAAoD;AACrF,SAAQ,MAAR;EACE,KAAKD,OAAK,SACR,QAAO,eAAe,KAAK;EAC7B,KAAKA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