@morpho-dev/router 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +15 -0
  2. package/dist/drizzle/0000_add-offers-table.sql +37 -0
  3. package/dist/drizzle/0001_create_offer_status_relation.sql +10 -0
  4. package/dist/drizzle/0002_add_created_at_in_offer_status_relation.sql +3 -0
  5. package/dist/drizzle/0003_add-cursor-indices-to-offers.sql +6 -0
  6. package/dist/drizzle/0004_offer-start.sql +1 -0
  7. package/dist/drizzle/0005_rename-price-token-buy.sql +8 -0
  8. package/dist/drizzle/0006_rename-buy.sql +3 -0
  9. package/dist/drizzle/0007_rename-offering.sql +3 -0
  10. package/dist/drizzle/meta/0000_snapshot.json +344 -0
  11. package/dist/drizzle/meta/0001_snapshot.json +426 -0
  12. package/dist/drizzle/meta/0002_snapshot.json +439 -0
  13. package/dist/drizzle/meta/0003_snapshot.json +553 -0
  14. package/dist/drizzle/meta/0004_snapshot.json +559 -0
  15. package/dist/drizzle/meta/0005_snapshot.json +559 -0
  16. package/dist/drizzle/meta/0006_snapshot.json +559 -0
  17. package/dist/drizzle/meta/0007_snapshot.json +559 -0
  18. package/dist/drizzle/meta/_journal.json +62 -0
  19. package/dist/{index.d.cts → index.browser.d.cts} +34 -90
  20. package/dist/{index.d.ts → index.browser.d.ts} +34 -90
  21. package/dist/index.browser.js +1172 -0
  22. package/dist/index.browser.js.map +1 -0
  23. package/dist/index.browser.mjs +1154 -0
  24. package/dist/index.browser.mjs.map +1 -0
  25. package/dist/index.node.d.cts +1342 -0
  26. package/dist/index.node.d.ts +1342 -0
  27. package/dist/{index.js → index.node.js} +2119 -4773
  28. package/dist/index.node.js.map +1 -0
  29. package/dist/{index.mjs → index.node.mjs} +2111 -4774
  30. package/dist/index.node.mjs.map +1 -0
  31. package/package.json +33 -11
  32. package/dist/index.js.map +0 -1
  33. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,1342 @@
1
+ import { Offer, Errors } from '@morpho-dev/mempool';
2
+ export * from '@morpho-dev/mempool';
3
+ import * as viem from 'viem';
4
+ import { Address, Account, Hex, PublicClient } from 'viem';
5
+ import { Chain as Chain$2 } from 'viem/chains';
6
+ import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
7
+ import { z } from 'zod/v4';
8
+ import { PGlite } from '@electric-sql/pglite';
9
+ import { drizzle } from 'drizzle-orm/node-postgres';
10
+ import { drizzle as drizzle$1 } from 'drizzle-orm/pglite';
11
+ import { Pool } from 'pg';
12
+ export * from 'drizzle-orm';
13
+ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
14
+
15
+ type Compute<type> = {
16
+ [key in keyof type]: type[key];
17
+ } & unknown;
18
+
19
+ declare const chainNames: readonly ["ethereum", "base"];
20
+ type ChainName = (typeof chainNames)[number];
21
+ declare const ChainId: {
22
+ ETHEREUM: bigint;
23
+ BASE: bigint;
24
+ };
25
+ type ChainId = (typeof ChainId)[keyof typeof ChainId];
26
+ declare const chainIds: Set<bigint>;
27
+ type Chain = Compute<Omit<Chain$2, "id" | "name"> & {
28
+ id: ChainId;
29
+ name: ChainName;
30
+ whitelistedAssets: Set<Address>;
31
+ morpho: Address;
32
+ }>;
33
+ declare function getChain(chainId: ChainId): Chain | undefined;
34
+ declare const chains: Record<ChainName, Chain>;
35
+
36
+ type Chain$1_Chain = Chain;
37
+ type Chain$1_ChainId = ChainId;
38
+ type Chain$1_ChainName = ChainName;
39
+ declare const Chain$1_chainIds: typeof chainIds;
40
+ declare const Chain$1_chainNames: typeof chainNames;
41
+ declare const Chain$1_chains: typeof chains;
42
+ declare const Chain$1_getChain: typeof getChain;
43
+ declare namespace Chain$1 {
44
+ export { type Chain$1_Chain as Chain, type Chain$1_ChainId as ChainId, type Chain$1_ChainName as ChainName, Chain$1_chainIds as chainIds, Chain$1_chainNames as chainNames, Chain$1_chains as chains, Chain$1_getChain as getChain };
45
+ }
46
+
47
+ declare const OpenApi: node_modules_zod_openapi_dist_components_DkyUTLcs_js.OpenAPIObject;
48
+
49
+ declare const schemas: {
50
+ readonly get_offers: z.ZodObject<{
51
+ creators: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
52
+ side: z.ZodOptional<z.ZodEnum<{
53
+ buy: "buy";
54
+ sell: "sell";
55
+ }>>;
56
+ chains: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<number[], string>>>;
57
+ loan_tokens: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
58
+ status: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<("valid" | "callback_not_supported" | "callback_error" | "unverified")[], string>>>;
59
+ callback_addresses: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
60
+ min_amount: z.ZodOptional<z.ZodBigInt>;
61
+ max_amount: z.ZodOptional<z.ZodBigInt>;
62
+ min_rate: z.ZodOptional<z.ZodBigInt>;
63
+ max_rate: z.ZodOptional<z.ZodBigInt>;
64
+ min_maturity: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
65
+ max_maturity: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
66
+ min_expiry: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
67
+ max_expiry: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
68
+ collateral_assets: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
69
+ collateral_oracles: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
70
+ collateral_tuple: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<{
71
+ asset: string;
72
+ oracle: string | undefined;
73
+ lltv: number | undefined;
74
+ }[], string>>>;
75
+ min_lltv: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>;
76
+ max_lltv: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>;
77
+ sort_by: z.ZodOptional<z.ZodEnum<{
78
+ rate: "rate";
79
+ maturity: "maturity";
80
+ expiry: "expiry";
81
+ amount: "amount";
82
+ }>>;
83
+ sort_order: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
84
+ asc: "asc";
85
+ desc: "desc";
86
+ }>>>;
87
+ cursor: z.ZodOptional<z.ZodString>;
88
+ limit: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>>;
89
+ }, z.core.$strip>;
90
+ readonly match_offers: z.ZodObject<{
91
+ side: z.ZodEnum<{
92
+ buy: "buy";
93
+ sell: "sell";
94
+ }>;
95
+ chain_id: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>;
96
+ rate: z.ZodOptional<z.ZodBigInt>;
97
+ collaterals: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<{
98
+ asset: string;
99
+ oracle: string;
100
+ lltv: bigint;
101
+ }[], string>>>;
102
+ maturity: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
103
+ min_maturity: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
104
+ max_maturity: z.ZodPipe<z.ZodOptional<z.ZodBigInt>, z.ZodTransform<number | undefined, bigint | undefined>>;
105
+ loan_token: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
106
+ creator: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
107
+ status: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<("valid" | "callback_not_supported" | "callback_error" | "unverified")[], string>>>;
108
+ cursor: z.ZodOptional<z.ZodString>;
109
+ limit: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>>;
110
+ }, z.core.$strip>;
111
+ };
112
+ type Action = keyof typeof schemas;
113
+ declare function parse<A extends Action>(action: A, query: unknown): z.infer<(typeof schemas)[A]>;
114
+ declare function safeParse<A extends Action>(action: A, query: unknown): z.ZodSafeParseResult<z.infer<(typeof schemas)[A]>>;
115
+
116
+ declare const index$1_OpenApi: typeof OpenApi;
117
+ declare const index$1_parse: typeof parse;
118
+ declare const index$1_safeParse: typeof safeParse;
119
+ declare namespace index$1 {
120
+ export { index$1_OpenApi as OpenApi, index$1_parse as parse, index$1_safeParse as safeParse };
121
+ }
122
+
123
+ declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
124
+ type OfferStatus = (typeof OfferStatusValues)[number];
125
+ type OfferMetadata = {
126
+ issue: string;
127
+ };
128
+ type RouterOffer = Offer.Offer & {
129
+ status: OfferStatus;
130
+ metadata?: OfferMetadata;
131
+ };
132
+
133
+ type RouterOffer$1_OfferMetadata = OfferMetadata;
134
+ type RouterOffer$1_OfferStatus = OfferStatus;
135
+ declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
136
+ type RouterOffer$1_RouterOffer = RouterOffer;
137
+ declare namespace RouterOffer$1 {
138
+ export { type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer };
139
+ }
140
+
141
+ type GetParameters = {
142
+ /** Filter by multiple creator addresses (comma-separated) */
143
+ creators?: string[];
144
+ /** Filter by offer type: buy offers or sell offers */
145
+ side?: "buy" | "sell";
146
+ /** Filter by multiple blockchain networks (comma-separated chain IDs) */
147
+ chains?: number[];
148
+ /** Filter by multiple loan assets (comma-separated) */
149
+ loanTokens?: string[];
150
+ /** Filter by multiple statuses (comma-separated) */
151
+ status?: OfferStatus[];
152
+ /** Filter by multiple callback addresses (comma-separated) */
153
+ callbackAddresses?: string[];
154
+ /** Minimum amount of assets in the offer */
155
+ minAmount?: bigint;
156
+ /** Maximum amount of assets in the offer */
157
+ maxAmount?: bigint;
158
+ /** Minimum rate per asset (in wei) */
159
+ minRate?: bigint;
160
+ /** Maximum rate per asset (in wei) */
161
+ maxRate?: bigint;
162
+ /** Minimum maturity timestamp (Unix timestamp in seconds) */
163
+ minMaturity?: number;
164
+ /** Maximum maturity timestamp (Unix timestamp in seconds) */
165
+ maxMaturity?: number;
166
+ /** Minimum expiry timestamp (Unix timestamp in seconds) */
167
+ minExpiry?: number;
168
+ /** Maximum expiry timestamp (Unix timestamp in seconds) */
169
+ maxExpiry?: number;
170
+ /** Filter by multiple collateral assets (comma-separated) */
171
+ collateralAssets?: string[];
172
+ /** Filter by multiple rate oracles (comma-separated) */
173
+ collateralOracles?: string[];
174
+ /** Filter by collateral combinations */
175
+ collateralTuple?: Array<{
176
+ asset: string;
177
+ oracle?: string;
178
+ lltv?: number;
179
+ }>;
180
+ /** Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
181
+ minLltv?: number;
182
+ /** Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
183
+ maxLltv?: number;
184
+ /** Field to sort results by */
185
+ sortBy?: "rate" | "maturity" | "expiry" | "amount";
186
+ /** Sort direction: asc (ascending) or desc (descending, default) */
187
+ sortOrder?: "asc" | "desc";
188
+ /** Pagination cursor in base64url-encoded format */
189
+ cursor?: string;
190
+ /** Maximum number of offers to return. Defaults to 20. Maximum is 100. */
191
+ limit?: number;
192
+ };
193
+ type MatchParameters = {
194
+ /** The desired side of the match: 'buy' if you want to buy, 'sell' if you want to sell */
195
+ side: "buy" | "sell";
196
+ /** The blockchain network chain ID */
197
+ chainId: number;
198
+ /** Rate per asset (in wei) for matching offers */
199
+ rate?: bigint;
200
+ /** Collateral requirements */
201
+ collaterals?: Array<{
202
+ asset: string;
203
+ oracle: string;
204
+ lltv: bigint;
205
+ }>;
206
+ /** Exact maturity timestamp (Unix timestamp in seconds) */
207
+ maturity?: number;
208
+ /** Minimum maturity timestamp (Unix timestamp in seconds, inclusive) */
209
+ minMaturity?: number;
210
+ /** Maximum maturity timestamp (Unix timestamp in seconds, inclusive) */
211
+ maxMaturity?: number;
212
+ /** The loan asset address to match against */
213
+ loanToken?: string;
214
+ /** Filter by a specific offer creator address */
215
+ creator?: string;
216
+ /** Filter by multiple statuses (comma-separated) */
217
+ status?: OfferStatus[];
218
+ /** Pagination cursor in base64url-encoded format */
219
+ cursor?: string;
220
+ /** Maximum number of offers to return. Defaults to 20. Maximum is 100. */
221
+ limit?: number;
222
+ };
223
+ type RouterClientConfig = {
224
+ readonly url: URL;
225
+ readonly headers: Headers;
226
+ };
227
+ type Client = Compute<RouterClientConfig & {
228
+ get: (parameters: GetParameters) => Promise<{
229
+ cursor: string | null;
230
+ offers: RouterOffer[];
231
+ }>;
232
+ match: (parameters: MatchParameters) => Promise<{
233
+ cursor: string | null;
234
+ offers: RouterOffer[];
235
+ }>;
236
+ }>;
237
+ declare function connect(opts?: {
238
+ url?: string;
239
+ apiKey?: string;
240
+ }): Client;
241
+ declare namespace connect {
242
+ type ErrorType = InvalidUrlError;
243
+ }
244
+ /**
245
+ * Get offers from the router.
246
+ * @returns The offers with pagination cursor.
247
+ */
248
+ declare function get(config: RouterClientConfig, parameters: GetParameters): Promise<{
249
+ cursor: string | null;
250
+ offers: RouterOffer[];
251
+ }>;
252
+ declare namespace get {
253
+ type ErrorType = GetApiErrorType;
254
+ }
255
+ /**
256
+ * Match offers from the router.
257
+ * @returns The matched offers with pagination cursor.
258
+ */
259
+ declare function match(config: RouterClientConfig, parameters: MatchParameters): Promise<{
260
+ cursor: string | null;
261
+ offers: RouterOffer[];
262
+ }>;
263
+ declare namespace match {
264
+ type ErrorType = GetApiErrorType;
265
+ }
266
+ type GetApiErrorType = HttpGetOffersFailedError | HttpUnauthorizedError | HttpForbiddenError | HttpRateLimitError;
267
+ declare class InvalidUrlError extends Errors.BaseError {
268
+ name: string;
269
+ constructor(url: string);
270
+ }
271
+ declare class HttpUnauthorizedError extends Errors.BaseError {
272
+ name: string;
273
+ constructor();
274
+ }
275
+ declare class HttpForbiddenError extends Errors.BaseError {
276
+ name: string;
277
+ constructor();
278
+ }
279
+ declare class HttpRateLimitError extends Errors.BaseError {
280
+ name: string;
281
+ constructor();
282
+ }
283
+ declare class HttpGetOffersFailedError extends Errors.BaseError {
284
+ name: string;
285
+ constructor(message: string, { details }?: {
286
+ details?: string;
287
+ });
288
+ }
289
+
290
+ type PgDB = ReturnType<typeof drizzle> & {
291
+ name: "pg";
292
+ pool: Pool;
293
+ };
294
+ type PGLiteDB = ReturnType<typeof drizzle$1> & {
295
+ name: "pglite";
296
+ pool: PGlite;
297
+ };
298
+ type DB = PgDB | PGLiteDB;
299
+ declare function create$1({ type, endpoint, }: {
300
+ type?: "pg" | "pglite";
301
+ endpoint?: string;
302
+ }): DB;
303
+ declare function applyMigrations(db: DB): Promise<void>;
304
+ declare function applyMigrationsPostgres(db: DB): Promise<void>;
305
+ declare function clean(db: DB): Promise<void>;
306
+
307
+ type OfferDB_DB = DB;
308
+ declare const OfferDB_applyMigrations: typeof applyMigrations;
309
+ declare const OfferDB_applyMigrationsPostgres: typeof applyMigrationsPostgres;
310
+ declare const OfferDB_clean: typeof clean;
311
+ declare namespace OfferDB {
312
+ export { type OfferDB_DB as DB, OfferDB_applyMigrations as applyMigrations, OfferDB_applyMigrationsPostgres as applyMigrationsPostgres, OfferDB_clean as clean, create$1 as create };
313
+ }
314
+
315
+ type GetOffersFilters = {
316
+ creators?: string[];
317
+ side?: "buy" | "sell";
318
+ chains?: number[];
319
+ loanTokens?: string[];
320
+ status?: OfferStatus[];
321
+ callbackAddresses?: string[];
322
+ minAmount?: bigint;
323
+ maxAmount?: bigint;
324
+ minRate?: bigint;
325
+ maxRate?: bigint;
326
+ minMaturity?: number;
327
+ maxMaturity?: number;
328
+ minExpiry?: number;
329
+ maxExpiry?: number;
330
+ collateralAssets?: string[];
331
+ collateralOracles?: string[];
332
+ collateralTuple?: Array<{
333
+ asset: string;
334
+ oracle?: string;
335
+ lltv?: number;
336
+ }>;
337
+ minLltv?: number;
338
+ maxLltv?: number;
339
+ sortBy?: "rate" | "maturity" | "expiry" | "amount";
340
+ sortOrder?: "asc" | "desc";
341
+ cursor?: string;
342
+ limit?: number;
343
+ };
344
+ interface FindMatchingOffersParams {
345
+ side: "buy" | "sell";
346
+ chainId: number;
347
+ rate?: bigint;
348
+ collaterals?: Array<{
349
+ asset: string;
350
+ oracle: string;
351
+ lltv: bigint;
352
+ }>;
353
+ maturity?: number;
354
+ minMaturity?: number;
355
+ maxMaturity?: number;
356
+ loanToken?: string;
357
+ creator?: string;
358
+ /** Filter by offer status; if omitted defaults to ["valid"] */
359
+ status?: OfferStatus[];
360
+ /** Cursor string returned by a previous call, for pagination */
361
+ cursor?: string;
362
+ /** Page size; defaults to 20 */
363
+ limit?: number;
364
+ }
365
+ interface GetAllParams {
366
+ query?: GetOffersFilters;
367
+ }
368
+ type OfferRepositoryConfig = {
369
+ /** The database instance to use for operations. */
370
+ db: DB;
371
+ };
372
+ /**
373
+ * The `OfferRepository` is responsible for managing offer data in the database.
374
+ */
375
+ type OfferRepository = {
376
+ /** Create a single offer in the database. */
377
+ create: (parameters: {
378
+ offer: Offer.Offer;
379
+ status: OfferStatus;
380
+ metadata?: OfferMetadata;
381
+ }) => Promise<string>;
382
+ /** Create multiple offers in the database. */
383
+ createMany: (parameters: {
384
+ offer: Offer.Offer;
385
+ status: OfferStatus;
386
+ metadata?: OfferMetadata;
387
+ }[]) => Promise<string[]>;
388
+ /** Get all offers from the database with optional filtering, sorting, and pagination. */
389
+ getAll: (params?: GetAllParams) => Promise<{
390
+ offers: RouterOffer[];
391
+ nextCursor: string | null;
392
+ }>;
393
+ /** Find offers that match the specified parameters, with cursor pagination. */
394
+ findMatchingOffers: (params: FindMatchingOffersParams) => Promise<{
395
+ offers: RouterOffer[];
396
+ nextCursor: string | null;
397
+ }>;
398
+ /** Delete an offer and its associated collaterals by hash. */
399
+ delete: (hash: Offer.Offer["hash"]) => Promise<boolean>;
400
+ /** Delete multiple offers and their associated collaterals by hashes. */
401
+ deleteMany: (hashes: Offer.Offer["hash"][]) => Promise<number>;
402
+ /** Update the status of an offer. */
403
+ updateStatus: (parameters: {
404
+ offerHash: Offer.Offer["hash"];
405
+ status: OfferStatus;
406
+ metadata?: OfferMetadata;
407
+ }) => Promise<void>;
408
+ };
409
+ /**
410
+ * Creates a new OfferRepository instance.
411
+ */
412
+ declare function create(config: OfferRepositoryConfig): OfferRepository;
413
+ type TestOfferRepository = OfferRepository;
414
+ declare function createTest(): TestOfferRepository;
415
+
416
+ type OfferRepository$1_FindMatchingOffersParams = FindMatchingOffersParams;
417
+ type OfferRepository$1_GetAllParams = GetAllParams;
418
+ type OfferRepository$1_GetOffersFilters = GetOffersFilters;
419
+ type OfferRepository$1_OfferRepository = OfferRepository;
420
+ type OfferRepository$1_OfferRepositoryConfig = OfferRepositoryConfig;
421
+ type OfferRepository$1_TestOfferRepository = TestOfferRepository;
422
+ declare const OfferRepository$1_create: typeof create;
423
+ declare const OfferRepository$1_createTest: typeof createTest;
424
+ declare namespace OfferRepository$1 {
425
+ export { type OfferRepository$1_FindMatchingOffersParams as FindMatchingOffersParams, type OfferRepository$1_GetAllParams as GetAllParams, type OfferRepository$1_GetOffersFilters as GetOffersFilters, type OfferRepository$1_OfferRepository as OfferRepository, type OfferRepository$1_OfferRepositoryConfig as OfferRepositoryConfig, type OfferRepository$1_TestOfferRepository as TestOfferRepository, OfferRepository$1_create as create, OfferRepository$1_createTest as createTest };
426
+ }
427
+
428
+ declare const offers: drizzle_orm_pg_core.PgTableWithColumns<{
429
+ name: "offers";
430
+ schema: undefined;
431
+ columns: {
432
+ hash: drizzle_orm_pg_core.PgColumn<{
433
+ name: "hash";
434
+ tableName: "offers";
435
+ dataType: "string";
436
+ columnType: "PgVarchar";
437
+ data: string;
438
+ driverParam: string;
439
+ notNull: true;
440
+ hasDefault: false;
441
+ isPrimaryKey: true;
442
+ isAutoincrement: false;
443
+ hasRuntimeDefault: false;
444
+ enumValues: [string, ...string[]];
445
+ baseColumn: never;
446
+ identity: undefined;
447
+ generated: undefined;
448
+ }, {}, {
449
+ length: 66;
450
+ }>;
451
+ offering: drizzle_orm_pg_core.PgColumn<{
452
+ name: "offering";
453
+ tableName: "offers";
454
+ dataType: "string";
455
+ columnType: "PgVarchar";
456
+ data: string;
457
+ driverParam: string;
458
+ notNull: true;
459
+ hasDefault: false;
460
+ isPrimaryKey: false;
461
+ isAutoincrement: false;
462
+ hasRuntimeDefault: false;
463
+ enumValues: [string, ...string[]];
464
+ baseColumn: never;
465
+ identity: undefined;
466
+ generated: undefined;
467
+ }, {}, {
468
+ length: 42;
469
+ }>;
470
+ assets: drizzle_orm_pg_core.PgColumn<{
471
+ name: "assets";
472
+ tableName: "offers";
473
+ dataType: "bigint";
474
+ columnType: "PgBigInt64";
475
+ data: bigint;
476
+ driverParam: string;
477
+ notNull: true;
478
+ hasDefault: false;
479
+ isPrimaryKey: false;
480
+ isAutoincrement: false;
481
+ hasRuntimeDefault: false;
482
+ enumValues: undefined;
483
+ baseColumn: never;
484
+ identity: undefined;
485
+ generated: undefined;
486
+ }, {}, {}>;
487
+ rate: drizzle_orm_pg_core.PgColumn<{
488
+ name: "rate";
489
+ tableName: "offers";
490
+ dataType: "bigint";
491
+ columnType: "PgBigInt64";
492
+ data: bigint;
493
+ driverParam: string;
494
+ notNull: true;
495
+ hasDefault: false;
496
+ isPrimaryKey: false;
497
+ isAutoincrement: false;
498
+ hasRuntimeDefault: false;
499
+ enumValues: undefined;
500
+ baseColumn: never;
501
+ identity: undefined;
502
+ generated: undefined;
503
+ }, {}, {}>;
504
+ maturity: drizzle_orm_pg_core.PgColumn<{
505
+ name: "maturity";
506
+ tableName: "offers";
507
+ dataType: "number";
508
+ columnType: "PgInteger";
509
+ data: number;
510
+ driverParam: string | number;
511
+ notNull: true;
512
+ hasDefault: false;
513
+ isPrimaryKey: false;
514
+ isAutoincrement: false;
515
+ hasRuntimeDefault: false;
516
+ enumValues: undefined;
517
+ baseColumn: never;
518
+ identity: undefined;
519
+ generated: undefined;
520
+ }, {}, {}>;
521
+ expiry: drizzle_orm_pg_core.PgColumn<{
522
+ name: "expiry";
523
+ tableName: "offers";
524
+ dataType: "number";
525
+ columnType: "PgInteger";
526
+ data: number;
527
+ driverParam: string | number;
528
+ notNull: true;
529
+ hasDefault: false;
530
+ isPrimaryKey: false;
531
+ isAutoincrement: false;
532
+ hasRuntimeDefault: false;
533
+ enumValues: undefined;
534
+ baseColumn: never;
535
+ identity: undefined;
536
+ generated: undefined;
537
+ }, {}, {}>;
538
+ start: drizzle_orm_pg_core.PgColumn<{
539
+ name: "start";
540
+ tableName: "offers";
541
+ dataType: "number";
542
+ columnType: "PgInteger";
543
+ data: number;
544
+ driverParam: string | number;
545
+ notNull: true;
546
+ hasDefault: false;
547
+ isPrimaryKey: false;
548
+ isAutoincrement: false;
549
+ hasRuntimeDefault: false;
550
+ enumValues: undefined;
551
+ baseColumn: never;
552
+ identity: undefined;
553
+ generated: undefined;
554
+ }, {}, {}>;
555
+ nonce: drizzle_orm_pg_core.PgColumn<{
556
+ name: "nonce";
557
+ tableName: "offers";
558
+ dataType: "bigint";
559
+ columnType: "PgBigInt64";
560
+ data: bigint;
561
+ driverParam: string;
562
+ notNull: true;
563
+ hasDefault: false;
564
+ isPrimaryKey: false;
565
+ isAutoincrement: false;
566
+ hasRuntimeDefault: false;
567
+ enumValues: undefined;
568
+ baseColumn: never;
569
+ identity: undefined;
570
+ generated: undefined;
571
+ }, {}, {}>;
572
+ buy: drizzle_orm_pg_core.PgColumn<{
573
+ name: "buy";
574
+ tableName: "offers";
575
+ dataType: "boolean";
576
+ columnType: "PgBoolean";
577
+ data: boolean;
578
+ driverParam: boolean;
579
+ notNull: true;
580
+ hasDefault: false;
581
+ isPrimaryKey: false;
582
+ isAutoincrement: false;
583
+ hasRuntimeDefault: false;
584
+ enumValues: undefined;
585
+ baseColumn: never;
586
+ identity: undefined;
587
+ generated: undefined;
588
+ }, {}, {}>;
589
+ chainId: drizzle_orm_pg_core.PgColumn<{
590
+ name: "chain_id";
591
+ tableName: "offers";
592
+ dataType: "bigint";
593
+ columnType: "PgBigInt64";
594
+ data: bigint;
595
+ driverParam: string;
596
+ notNull: true;
597
+ hasDefault: false;
598
+ isPrimaryKey: false;
599
+ isAutoincrement: false;
600
+ hasRuntimeDefault: false;
601
+ enumValues: undefined;
602
+ baseColumn: never;
603
+ identity: undefined;
604
+ generated: undefined;
605
+ }, {}, {}>;
606
+ loanToken: drizzle_orm_pg_core.PgColumn<{
607
+ name: "loan_token";
608
+ tableName: "offers";
609
+ dataType: "string";
610
+ columnType: "PgVarchar";
611
+ data: string;
612
+ driverParam: string;
613
+ notNull: true;
614
+ hasDefault: false;
615
+ isPrimaryKey: false;
616
+ isAutoincrement: false;
617
+ hasRuntimeDefault: false;
618
+ enumValues: [string, ...string[]];
619
+ baseColumn: never;
620
+ identity: undefined;
621
+ generated: undefined;
622
+ }, {}, {
623
+ length: 42;
624
+ }>;
625
+ callbackAddress: drizzle_orm_pg_core.PgColumn<{
626
+ name: "callback_address";
627
+ tableName: "offers";
628
+ dataType: "string";
629
+ columnType: "PgVarchar";
630
+ data: string;
631
+ driverParam: string;
632
+ notNull: true;
633
+ hasDefault: false;
634
+ isPrimaryKey: false;
635
+ isAutoincrement: false;
636
+ hasRuntimeDefault: false;
637
+ enumValues: [string, ...string[]];
638
+ baseColumn: never;
639
+ identity: undefined;
640
+ generated: undefined;
641
+ }, {}, {
642
+ length: 42;
643
+ }>;
644
+ callbackData: drizzle_orm_pg_core.PgColumn<{
645
+ name: "callback_data";
646
+ tableName: "offers";
647
+ dataType: "string";
648
+ columnType: "PgText";
649
+ data: string;
650
+ driverParam: string;
651
+ notNull: true;
652
+ hasDefault: false;
653
+ isPrimaryKey: false;
654
+ isAutoincrement: false;
655
+ hasRuntimeDefault: false;
656
+ enumValues: [string, ...string[]];
657
+ baseColumn: never;
658
+ identity: undefined;
659
+ generated: undefined;
660
+ }, {}, {}>;
661
+ callbackGasLimit: drizzle_orm_pg_core.PgColumn<{
662
+ name: "callback_gas_limit";
663
+ tableName: "offers";
664
+ dataType: "bigint";
665
+ columnType: "PgBigInt64";
666
+ data: bigint;
667
+ driverParam: string;
668
+ notNull: true;
669
+ hasDefault: false;
670
+ isPrimaryKey: false;
671
+ isAutoincrement: false;
672
+ hasRuntimeDefault: false;
673
+ enumValues: undefined;
674
+ baseColumn: never;
675
+ identity: undefined;
676
+ generated: undefined;
677
+ }, {}, {}>;
678
+ signature: drizzle_orm_pg_core.PgColumn<{
679
+ name: "signature";
680
+ tableName: "offers";
681
+ dataType: "string";
682
+ columnType: "PgVarchar";
683
+ data: string;
684
+ driverParam: string;
685
+ notNull: false;
686
+ hasDefault: false;
687
+ isPrimaryKey: false;
688
+ isAutoincrement: false;
689
+ hasRuntimeDefault: false;
690
+ enumValues: [string, ...string[]];
691
+ baseColumn: never;
692
+ identity: undefined;
693
+ generated: undefined;
694
+ }, {}, {
695
+ length: 132;
696
+ }>;
697
+ createdAt: drizzle_orm_pg_core.PgColumn<{
698
+ name: "created_at";
699
+ tableName: "offers";
700
+ dataType: "date";
701
+ columnType: "PgTimestamp";
702
+ data: Date;
703
+ driverParam: string;
704
+ notNull: true;
705
+ hasDefault: true;
706
+ isPrimaryKey: false;
707
+ isAutoincrement: false;
708
+ hasRuntimeDefault: false;
709
+ enumValues: undefined;
710
+ baseColumn: never;
711
+ identity: undefined;
712
+ generated: undefined;
713
+ }, {}, {}>;
714
+ };
715
+ dialect: "pg";
716
+ }>;
717
+ declare const offerCollaterals: drizzle_orm_pg_core.PgTableWithColumns<{
718
+ name: "offer_collaterals";
719
+ schema: undefined;
720
+ columns: {
721
+ id: drizzle_orm_pg_core.PgColumn<{
722
+ name: "id";
723
+ tableName: "offer_collaterals";
724
+ dataType: "number";
725
+ columnType: "PgSerial";
726
+ data: number;
727
+ driverParam: number;
728
+ notNull: true;
729
+ hasDefault: true;
730
+ isPrimaryKey: true;
731
+ isAutoincrement: false;
732
+ hasRuntimeDefault: false;
733
+ enumValues: undefined;
734
+ baseColumn: never;
735
+ identity: undefined;
736
+ generated: undefined;
737
+ }, {}, {}>;
738
+ offerHash: drizzle_orm_pg_core.PgColumn<{
739
+ name: "offer_hash";
740
+ tableName: "offer_collaterals";
741
+ dataType: "string";
742
+ columnType: "PgVarchar";
743
+ data: string;
744
+ driverParam: string;
745
+ notNull: true;
746
+ hasDefault: false;
747
+ isPrimaryKey: false;
748
+ isAutoincrement: false;
749
+ hasRuntimeDefault: false;
750
+ enumValues: [string, ...string[]];
751
+ baseColumn: never;
752
+ identity: undefined;
753
+ generated: undefined;
754
+ }, {}, {
755
+ length: 66;
756
+ }>;
757
+ asset: drizzle_orm_pg_core.PgColumn<{
758
+ name: "asset";
759
+ tableName: "offer_collaterals";
760
+ dataType: "string";
761
+ columnType: "PgVarchar";
762
+ data: string;
763
+ driverParam: string;
764
+ notNull: true;
765
+ hasDefault: false;
766
+ isPrimaryKey: false;
767
+ isAutoincrement: false;
768
+ hasRuntimeDefault: false;
769
+ enumValues: [string, ...string[]];
770
+ baseColumn: never;
771
+ identity: undefined;
772
+ generated: undefined;
773
+ }, {}, {
774
+ length: 42;
775
+ }>;
776
+ oracle: drizzle_orm_pg_core.PgColumn<{
777
+ name: "oracle";
778
+ tableName: "offer_collaterals";
779
+ dataType: "string";
780
+ columnType: "PgVarchar";
781
+ data: string;
782
+ driverParam: string;
783
+ notNull: true;
784
+ hasDefault: false;
785
+ isPrimaryKey: false;
786
+ isAutoincrement: false;
787
+ hasRuntimeDefault: false;
788
+ enumValues: [string, ...string[]];
789
+ baseColumn: never;
790
+ identity: undefined;
791
+ generated: undefined;
792
+ }, {}, {
793
+ length: 42;
794
+ }>;
795
+ lltv: drizzle_orm_pg_core.PgColumn<{
796
+ name: "lltv";
797
+ tableName: "offer_collaterals";
798
+ dataType: "bigint";
799
+ columnType: "PgBigInt64";
800
+ data: bigint;
801
+ driverParam: string;
802
+ notNull: true;
803
+ hasDefault: false;
804
+ isPrimaryKey: false;
805
+ isAutoincrement: false;
806
+ hasRuntimeDefault: false;
807
+ enumValues: undefined;
808
+ baseColumn: never;
809
+ identity: undefined;
810
+ generated: undefined;
811
+ }, {}, {}>;
812
+ };
813
+ dialect: "pg";
814
+ }>;
815
+ declare const offerStatus: drizzle_orm_pg_core.PgTableWithColumns<{
816
+ name: "offer_status";
817
+ schema: undefined;
818
+ columns: {
819
+ id: drizzle_orm_pg_core.PgColumn<{
820
+ name: "id";
821
+ tableName: "offer_status";
822
+ dataType: "number";
823
+ columnType: "PgSerial";
824
+ data: number;
825
+ driverParam: number;
826
+ notNull: true;
827
+ hasDefault: true;
828
+ isPrimaryKey: true;
829
+ isAutoincrement: false;
830
+ hasRuntimeDefault: false;
831
+ enumValues: undefined;
832
+ baseColumn: never;
833
+ identity: undefined;
834
+ generated: undefined;
835
+ }, {}, {}>;
836
+ offerHash: drizzle_orm_pg_core.PgColumn<{
837
+ name: "offer_hash";
838
+ tableName: "offer_status";
839
+ dataType: "string";
840
+ columnType: "PgVarchar";
841
+ data: string;
842
+ driverParam: string;
843
+ notNull: true;
844
+ hasDefault: false;
845
+ isPrimaryKey: false;
846
+ isAutoincrement: false;
847
+ hasRuntimeDefault: false;
848
+ enumValues: [string, ...string[]];
849
+ baseColumn: never;
850
+ identity: undefined;
851
+ generated: undefined;
852
+ }, {}, {
853
+ length: 66;
854
+ }>;
855
+ status: drizzle_orm_pg_core.PgColumn<{
856
+ name: "status";
857
+ tableName: "offer_status";
858
+ dataType: "string";
859
+ columnType: "PgText";
860
+ data: "valid" | "callback_not_supported" | "callback_error" | "unverified";
861
+ driverParam: string;
862
+ notNull: true;
863
+ hasDefault: false;
864
+ isPrimaryKey: false;
865
+ isAutoincrement: false;
866
+ hasRuntimeDefault: false;
867
+ enumValues: [string, ...string[]];
868
+ baseColumn: never;
869
+ identity: undefined;
870
+ generated: undefined;
871
+ }, {}, {
872
+ $type: "valid" | "callback_not_supported" | "callback_error" | "unverified";
873
+ }>;
874
+ metadata: drizzle_orm_pg_core.PgColumn<{
875
+ name: "metadata";
876
+ tableName: "offer_status";
877
+ dataType: "json";
878
+ columnType: "PgJsonb";
879
+ data: unknown;
880
+ driverParam: unknown;
881
+ notNull: false;
882
+ hasDefault: false;
883
+ isPrimaryKey: false;
884
+ isAutoincrement: false;
885
+ hasRuntimeDefault: false;
886
+ enumValues: undefined;
887
+ baseColumn: never;
888
+ identity: undefined;
889
+ generated: undefined;
890
+ }, {}, {}>;
891
+ createdAt: drizzle_orm_pg_core.PgColumn<{
892
+ name: "created_at";
893
+ tableName: "offer_status";
894
+ dataType: "date";
895
+ columnType: "PgTimestamp";
896
+ data: Date;
897
+ driverParam: string;
898
+ notNull: true;
899
+ hasDefault: true;
900
+ isPrimaryKey: false;
901
+ isAutoincrement: false;
902
+ hasRuntimeDefault: false;
903
+ enumValues: undefined;
904
+ baseColumn: never;
905
+ identity: undefined;
906
+ generated: undefined;
907
+ }, {}, {}>;
908
+ };
909
+ dialect: "pg";
910
+ }>;
911
+
912
+ /**
913
+ * Start a local router server.
914
+ * @example
915
+ * ```ts
916
+ * import { Router } from "@morpho-dev/router";
917
+ * await Router.serve(); // local router server running on http://localhost:8081
918
+ * ```
919
+ */
920
+ declare function serve(parameters: {
921
+ port: number;
922
+ store?: OfferRepository;
923
+ }): Promise<void>;
924
+
925
+ type index_Client = Client;
926
+ type index_GetParameters = GetParameters;
927
+ type index_HttpForbiddenError = HttpForbiddenError;
928
+ declare const index_HttpForbiddenError: typeof HttpForbiddenError;
929
+ type index_HttpGetOffersFailedError = HttpGetOffersFailedError;
930
+ declare const index_HttpGetOffersFailedError: typeof HttpGetOffersFailedError;
931
+ type index_HttpRateLimitError = HttpRateLimitError;
932
+ declare const index_HttpRateLimitError: typeof HttpRateLimitError;
933
+ type index_HttpUnauthorizedError = HttpUnauthorizedError;
934
+ declare const index_HttpUnauthorizedError: typeof HttpUnauthorizedError;
935
+ type index_InvalidUrlError = InvalidUrlError;
936
+ declare const index_InvalidUrlError: typeof InvalidUrlError;
937
+ type index_MatchParameters = MatchParameters;
938
+ type index_RouterClientConfig = RouterClientConfig;
939
+ declare const index_connect: typeof connect;
940
+ declare const index_get: typeof get;
941
+ declare const index_match: typeof match;
942
+ declare const index_serve: typeof serve;
943
+ declare namespace index {
944
+ export { type index_Client as Client, type index_GetParameters as GetParameters, index_HttpForbiddenError as HttpForbiddenError, index_HttpGetOffersFailedError as HttpGetOffersFailedError, index_HttpRateLimitError as HttpRateLimitError, index_HttpUnauthorizedError as HttpUnauthorizedError, index_InvalidUrlError as InvalidUrlError, type index_MatchParameters as MatchParameters, type index_RouterClientConfig as RouterClientConfig, index_connect as connect, index_get as get, index_match as match, index_serve as serve };
945
+ }
946
+
947
+ declare const users: Account[];
948
+ declare const assetList: readonly ["USDC", "DAI"];
949
+ declare const mockAddress: (asset: (typeof assetList)[number]) => `0x${string}`;
950
+ declare const assetMethods: readonly ["balanceOf", "allowance"];
951
+ type AssetMethod = (typeof assetMethods)[number];
952
+ type MethodParameters = {
953
+ balanceOf: {
954
+ address: Address;
955
+ value: bigint;
956
+ };
957
+ allowance: {
958
+ owner: Address;
959
+ spender: Address;
960
+ value: bigint;
961
+ };
962
+ };
963
+ type MockedAsset = {
964
+ address: Address;
965
+ set: (slot: Hex | AssetMethod, parameters: Hex | bigint | MethodParameters[AssetMethod]) => Promise<void>;
966
+ };
967
+ type Mocked = {
968
+ name: string;
969
+ publicClient: PublicClient;
970
+ } & Record<(typeof assetList)[number], MockedAsset>;
971
+ declare function mock(name: string): Promise<Mocked>;
972
+
973
+ type EVM_AssetMethod = AssetMethod;
974
+ type EVM_MethodParameters = MethodParameters;
975
+ type EVM_Mocked = Mocked;
976
+ type EVM_MockedAsset = MockedAsset;
977
+ declare const EVM_assetList: typeof assetList;
978
+ declare const EVM_assetMethods: typeof assetMethods;
979
+ declare const EVM_mock: typeof mock;
980
+ declare const EVM_mockAddress: typeof mockAddress;
981
+ declare const EVM_users: typeof users;
982
+ declare namespace EVM {
983
+ export { type EVM_AssetMethod as AssetMethod, type EVM_MethodParameters as MethodParameters, type EVM_Mocked as Mocked, type EVM_MockedAsset as MockedAsset, EVM_assetList as assetList, EVM_assetMethods as assetMethods, EVM_mock as mock, EVM_mockAddress as mockAddress, EVM_users as users };
984
+ }
985
+
986
+ declare const LogLevelValues: readonly ["silent", "trace", "debug", "info", "warn", "error", "fatal"];
987
+ type LogLevel = (typeof LogLevelValues)[number];
988
+ type LogFn = {
989
+ <T extends object>(obj: T, msg?: string, ...args: unknown[]): void;
990
+ (obj: unknown, msg?: string, ...args: unknown[]): void;
991
+ (msg: string, ...args: unknown[]): void;
992
+ };
993
+ type Logger = {
994
+ trace: LogFn;
995
+ debug: LogFn;
996
+ info: LogFn;
997
+ warn: LogFn;
998
+ error: LogFn;
999
+ fatal: LogFn;
1000
+ };
1001
+ declare function defaultLogger(): Logger;
1002
+ declare function runWithLogger<T>(logger: Logger, fn: () => Promise<T>): Promise<T>;
1003
+ declare function getLogger(): Logger;
1004
+
1005
+ type Logger$1_LogFn = LogFn;
1006
+ type Logger$1_LogLevel = LogLevel;
1007
+ declare const Logger$1_LogLevelValues: typeof LogLevelValues;
1008
+ type Logger$1_Logger = Logger;
1009
+ declare const Logger$1_defaultLogger: typeof defaultLogger;
1010
+ declare const Logger$1_getLogger: typeof getLogger;
1011
+ declare const Logger$1_runWithLogger: typeof runWithLogger;
1012
+ declare namespace Logger$1 {
1013
+ export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger };
1014
+ }
1015
+
1016
+ declare const types: readonly ["offer_created", "offer_matched", "offer_validation"];
1017
+ type Type = (typeof types)[number];
1018
+ type EventPayload = {
1019
+ offer_created: {
1020
+ readonly offer: RouterOffer;
1021
+ };
1022
+ offer_matched: {
1023
+ readonly offer: RouterOffer;
1024
+ };
1025
+ offer_validation: {
1026
+ readonly offer: RouterOffer;
1027
+ };
1028
+ };
1029
+ type BaseEvent<T extends Type> = {
1030
+ readonly id: string;
1031
+ readonly type: T;
1032
+ };
1033
+ type RouterEvent = Compute<{
1034
+ [K in keyof EventPayload]: BaseEvent<K> & EventPayload[K];
1035
+ }[keyof EventPayload]>;
1036
+ /**
1037
+ * Builds a deterministic event id based on the event type.
1038
+ * For `offer_created` it returns `offer_created:${offer.hash.toLowerCase()}`.
1039
+ * For `offer_matched` it returns `offer_matched:${offer.hash.toLowerCase()}`.
1040
+ */
1041
+ declare function buildId(event: Omit<RouterEvent, "id">): string;
1042
+
1043
+ type RouterEvent$1_RouterEvent = RouterEvent;
1044
+ type RouterEvent$1_Type = Type;
1045
+ declare const RouterEvent$1_buildId: typeof buildId;
1046
+ declare const RouterEvent$1_types: typeof types;
1047
+ declare namespace RouterEvent$1 {
1048
+ export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_buildId as buildId, RouterEvent$1_types as types };
1049
+ }
1050
+
1051
+ /**
1052
+ * Splits an array into batches of a specified size.
1053
+ * @param array The array to split.
1054
+ * @param batchSize The size of each batch.
1055
+ * @returns An iterator that yields each batch.
1056
+ * @example
1057
+ * ```typescript
1058
+ * const array = [1, 2, 3, 4, 5];
1059
+ * for (const batch of batch(array, 2)) {
1060
+ * console.log(batch);
1061
+ * }
1062
+ * // Output:
1063
+ * // [1, 2]
1064
+ * // [3, 4]
1065
+ * // [5]
1066
+ * ```
1067
+ */
1068
+ declare function batch$1<T>(array: Array<T>, batchSize: number): Generator<T[], void, unknown>;
1069
+
1070
+ type Cursor = {
1071
+ sort: "rate" | "maturity" | "expiry" | "amount";
1072
+ dir: "asc" | "desc";
1073
+ rate?: string;
1074
+ maturity?: number;
1075
+ expiry?: number;
1076
+ assets?: string;
1077
+ hash: string;
1078
+ };
1079
+ declare function validateCursor(cursor: unknown): cursor is Cursor;
1080
+ declare function encodeCursor(c: Cursor): string;
1081
+ declare function decodeCursor(token?: string): Cursor | null;
1082
+
1083
+ /**
1084
+ * Polls a function at a specified interval.
1085
+ * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts
1086
+ */
1087
+ declare function poll<data>(fn: ({ unpoll }: {
1088
+ unpoll: () => void;
1089
+ }) => Promise<data | undefined>, { interval }: {
1090
+ interval: number;
1091
+ }): () => boolean;
1092
+
1093
+ declare function wait(time: number): Promise<unknown>;
1094
+
1095
+ /**
1096
+ * A validation rule.
1097
+ */
1098
+ type Rule<T, Name extends string = string, Ctx = void> = {
1099
+ kind: "single";
1100
+ name: Name;
1101
+ run: Single<T, Name, Ctx>;
1102
+ } | {
1103
+ kind: "batch";
1104
+ name: Name;
1105
+ run: Batch<T, Name, Ctx>;
1106
+ };
1107
+ type RuleNames<Rules extends readonly {
1108
+ name: string;
1109
+ }[]> = Rules[number]["name"];
1110
+ /**
1111
+ * A single item validation rule.
1112
+ * @param item - The item to validate.
1113
+ * @param ctx - The context of the validation.
1114
+ * @returns The issue that was found. If the item is valid, this will be undefined.
1115
+ */
1116
+ type Single<T, RuleName extends string, Ctx = void> = (item: T, ctx: Ctx) => Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined | Promise<Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>;
1117
+ /**
1118
+ * A batch item validation rule.
1119
+ * @param items - The items to validate.
1120
+ * @param ctx - The context of the validation.
1121
+ * @returns A map of the items to the issue that was found.
1122
+ */
1123
+ type Batch<T, RuleName extends string, Ctx = void> = (items: T[], ctx: Ctx) => Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined> | Promise<Map<number, Omit<Issue<T, RuleName>, "ruleName" | "item"> | undefined>>;
1124
+ /**
1125
+ * Create a validation rule iterating over a single item at a time.
1126
+ * @param name - The name of the rule.
1127
+ * @param run - The function that validates the rule.
1128
+ * @returns The created rule.
1129
+ */
1130
+ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Single<T, Name, Ctx>): Rule<T, Name, Ctx>;
1131
+ /**
1132
+ * Create a validation rule iterating over a batch of items at a time.
1133
+ * @param name - The name of the rule.
1134
+ * @param run - The function that validates the rule.
1135
+ * @returns The created rule.
1136
+ */
1137
+ declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
1138
+ type MorphoContext = {
1139
+ publicClients: Partial<Record<ChainName, PublicClient>>;
1140
+ };
1141
+ declare function morpho(parameters: {
1142
+ whitelistedChains: Chain[];
1143
+ }): (Rule<{
1144
+ readonly offering: Address;
1145
+ readonly assets: bigint;
1146
+ readonly rate: bigint;
1147
+ readonly maturity: number;
1148
+ readonly expiry: number;
1149
+ readonly nonce: bigint;
1150
+ readonly buy: boolean;
1151
+ readonly chainId: bigint;
1152
+ readonly loanToken: Address;
1153
+ readonly start: number;
1154
+ readonly collaterals: readonly {
1155
+ asset: Address;
1156
+ oracle: Address;
1157
+ lltv: bigint;
1158
+ }[];
1159
+ readonly callback: {
1160
+ readonly address: Address;
1161
+ readonly data: viem.Hex;
1162
+ readonly gasLimit: bigint;
1163
+ };
1164
+ readonly hash: viem.Hex;
1165
+ signature?: viem.Hex;
1166
+ createdAt?: number;
1167
+ }, "chain_id", MorphoContext> | Rule<{
1168
+ readonly offering: Address;
1169
+ readonly assets: bigint;
1170
+ readonly rate: bigint;
1171
+ readonly maturity: number;
1172
+ readonly expiry: number;
1173
+ readonly nonce: bigint;
1174
+ readonly buy: boolean;
1175
+ readonly chainId: bigint;
1176
+ readonly loanToken: Address;
1177
+ readonly start: number;
1178
+ readonly collaterals: readonly {
1179
+ asset: Address;
1180
+ oracle: Address;
1181
+ lltv: bigint;
1182
+ }[];
1183
+ readonly callback: {
1184
+ readonly address: Address;
1185
+ readonly data: viem.Hex;
1186
+ readonly gasLimit: bigint;
1187
+ };
1188
+ readonly hash: viem.Hex;
1189
+ signature?: viem.Hex;
1190
+ createdAt?: number;
1191
+ }, "loan_token", MorphoContext> | Rule<{
1192
+ readonly offering: Address;
1193
+ readonly assets: bigint;
1194
+ readonly rate: bigint;
1195
+ readonly maturity: number;
1196
+ readonly expiry: number;
1197
+ readonly nonce: bigint;
1198
+ readonly buy: boolean;
1199
+ readonly chainId: bigint;
1200
+ readonly loanToken: Address;
1201
+ readonly start: number;
1202
+ readonly collaterals: readonly {
1203
+ asset: Address;
1204
+ oracle: Address;
1205
+ lltv: bigint;
1206
+ }[];
1207
+ readonly callback: {
1208
+ readonly address: Address;
1209
+ readonly data: viem.Hex;
1210
+ readonly gasLimit: bigint;
1211
+ };
1212
+ readonly hash: viem.Hex;
1213
+ signature?: viem.Hex;
1214
+ createdAt?: number;
1215
+ }, "expiry", MorphoContext> | Rule<{
1216
+ readonly offering: Address;
1217
+ readonly assets: bigint;
1218
+ readonly rate: bigint;
1219
+ readonly maturity: number;
1220
+ readonly expiry: number;
1221
+ readonly nonce: bigint;
1222
+ readonly buy: boolean;
1223
+ readonly chainId: bigint;
1224
+ readonly loanToken: Address;
1225
+ readonly start: number;
1226
+ readonly collaterals: readonly {
1227
+ asset: Address;
1228
+ oracle: Address;
1229
+ lltv: bigint;
1230
+ }[];
1231
+ readonly callback: {
1232
+ readonly address: Address;
1233
+ readonly data: viem.Hex;
1234
+ readonly gasLimit: bigint;
1235
+ };
1236
+ readonly hash: viem.Hex;
1237
+ signature?: viem.Hex;
1238
+ createdAt?: number;
1239
+ }, "empty_callback", MorphoContext> | Rule<{
1240
+ readonly offering: Address;
1241
+ readonly assets: bigint;
1242
+ readonly rate: bigint;
1243
+ readonly maturity: number;
1244
+ readonly expiry: number;
1245
+ readonly nonce: bigint;
1246
+ readonly buy: boolean;
1247
+ readonly chainId: bigint;
1248
+ readonly loanToken: Address;
1249
+ readonly start: number;
1250
+ readonly collaterals: readonly {
1251
+ asset: Address;
1252
+ oracle: Address;
1253
+ lltv: bigint;
1254
+ }[];
1255
+ readonly callback: {
1256
+ readonly address: Address;
1257
+ readonly data: viem.Hex;
1258
+ readonly gasLimit: bigint;
1259
+ };
1260
+ readonly hash: viem.Hex;
1261
+ signature?: viem.Hex;
1262
+ createdAt?: number;
1263
+ }, "sell_offers_empty_callback", MorphoContext> | Rule<{
1264
+ readonly offering: Address;
1265
+ readonly assets: bigint;
1266
+ readonly rate: bigint;
1267
+ readonly maturity: number;
1268
+ readonly expiry: number;
1269
+ readonly nonce: bigint;
1270
+ readonly buy: boolean;
1271
+ readonly chainId: bigint;
1272
+ readonly loanToken: Address;
1273
+ readonly start: number;
1274
+ readonly collaterals: readonly {
1275
+ asset: Address;
1276
+ oracle: Address;
1277
+ lltv: bigint;
1278
+ }[];
1279
+ readonly callback: {
1280
+ readonly address: Address;
1281
+ readonly data: viem.Hex;
1282
+ readonly gasLimit: bigint;
1283
+ };
1284
+ readonly hash: viem.Hex;
1285
+ signature?: viem.Hex;
1286
+ createdAt?: number;
1287
+ }, "buy_offers_empty_callback", MorphoContext>)[];
1288
+
1289
+ type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
1290
+ type ValidationRule_MorphoContext = MorphoContext;
1291
+ type ValidationRule_Rule<T, Name extends string = string, Ctx = void> = Rule<T, Name, Ctx>;
1292
+ type ValidationRule_RuleNames<Rules extends readonly {
1293
+ name: string;
1294
+ }[]> = RuleNames<Rules>;
1295
+ type ValidationRule_Single<T, RuleName extends string, Ctx = void> = Single<T, RuleName, Ctx>;
1296
+ declare const ValidationRule_batch: typeof batch;
1297
+ declare const ValidationRule_morpho: typeof morpho;
1298
+ declare const ValidationRule_single: typeof single;
1299
+ declare namespace ValidationRule {
1300
+ export { type ValidationRule_Batch as Batch, type ValidationRule_MorphoContext as MorphoContext, type ValidationRule_Rule as Rule, type ValidationRule_RuleNames as RuleNames, type ValidationRule_Single as Single, ValidationRule_batch as batch, ValidationRule_morpho as morpho, ValidationRule_single as single };
1301
+ }
1302
+
1303
+ /**
1304
+ * A validation issue.
1305
+ */
1306
+ type Issue<T, RuleName extends string = string> = {
1307
+ /** The name of the rule that caused the issue. */
1308
+ ruleName: RuleName;
1309
+ /** The message of the issue. */
1310
+ message: string;
1311
+ /** The item that was not valid. */
1312
+ item: T;
1313
+ };
1314
+ /**
1315
+ * The result of a validation.
1316
+ */
1317
+ type Result<T, RuleName extends string = string> = {
1318
+ /** The items that were valid. */
1319
+ valid: T[];
1320
+ /** The reports of the failed validations. */
1321
+ issues: Issue<T, RuleName>[];
1322
+ };
1323
+ declare function run<T, Name extends string, Rules extends readonly Rule<T, Name, void>[]>(parameters: {
1324
+ items: T[];
1325
+ rules: Rules;
1326
+ chunkSize?: number;
1327
+ }): Promise<Result<T, RuleNames<Rules>>>;
1328
+ declare function run<T, Ctx, Name extends string, Rules extends readonly Rule<T, Name, Ctx>[]>(parameters: {
1329
+ items: T[];
1330
+ rules: Rules;
1331
+ ctx: Ctx;
1332
+ chunkSize?: number;
1333
+ }): Promise<Result<T, RuleNames<Rules>>>;
1334
+
1335
+ type Validation_Issue<T, RuleName extends string = string> = Issue<T, RuleName>;
1336
+ type Validation_Result<T, RuleName extends string = string> = Result<T, RuleName>;
1337
+ declare const Validation_run: typeof run;
1338
+ declare namespace Validation {
1339
+ export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
1340
+ }
1341
+
1342
+ export { index$1 as ApiSchema, Chain$1 as Chain, type Compute, type Cursor, EVM, Logger$1 as Logger, OfferDB, OfferRepository$1 as OfferRepository, index as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, Validation, ValidationRule, batch$1 as batch, decodeCursor, encodeCursor, offerCollaterals, offerStatus, offers, poll, validateCursor, wait };