@morpho-dev/router 0.1.3 → 0.1.4

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,15 +1,132 @@
1
1
  import * as _morpho_dev_mempool from '@morpho-dev/mempool';
2
2
  import { Offer, Errors, Format, Maturity, LLTV, Compute, Chain } from '@morpho-dev/mempool';
3
3
  export * from '@morpho-dev/mempool';
4
+ import * as viem from 'viem';
5
+ import { PublicActions, Address, Hex } from 'viem';
4
6
  import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
5
7
  import { z, ZodError } from 'zod/v4';
6
- import * as viem from 'viem';
7
- import { Address, Hex } from 'viem';
8
8
  import * as hono_utils_types from 'hono/utils/types';
9
9
  import * as hono from 'hono';
10
10
  import { Context } from 'hono';
11
11
  import * as hono_utils_http_status from 'hono/utils/http-status';
12
12
 
13
+ declare function fetchBalancesAndAllowances(parameters: {
14
+ client: Pick<PublicActions, "multicall">;
15
+ spender: Address;
16
+ pairs: Array<{
17
+ user: Address;
18
+ token: Address;
19
+ }>;
20
+ options?: {
21
+ batchSize?: number;
22
+ retryAttempts?: number;
23
+ retryDelayMs?: number;
24
+ blockNumber?: number;
25
+ };
26
+ }): Promise<Map<Address, Map<Address, {
27
+ balance: bigint;
28
+ allowance: bigint;
29
+ }>>>;
30
+ type LiquidityUserPosition = {
31
+ id: string;
32
+ availableLiquidityQueueId: string;
33
+ user: string;
34
+ chainId: bigint;
35
+ amount: string;
36
+ updatedAt: Date;
37
+ };
38
+ type LiquidityQueue = {
39
+ queueId: string;
40
+ availableLiquidityPoolId: string;
41
+ index: number;
42
+ updatedAt: Date;
43
+ };
44
+ type LiquidityPool = {
45
+ id: string;
46
+ amount: string;
47
+ updatedAt: Date;
48
+ };
49
+ type LiquidityQueueWithPool = {
50
+ queue: LiquidityQueue;
51
+ pool: LiquidityPool;
52
+ };
53
+ type Liquidity = {
54
+ userPosition: LiquidityUserPosition;
55
+ queues: LiquidityQueueWithPool[];
56
+ };
57
+ declare function fetch(parameters: {
58
+ client: Pick<PublicActions, "multicall">;
59
+ chainId: bigint;
60
+ spender: Address;
61
+ type: CallbackType;
62
+ pairs: Array<{
63
+ user: Address;
64
+ contract: Address;
65
+ }>;
66
+ options?: {
67
+ batchSize?: number;
68
+ retryAttempts?: number;
69
+ retryDelayMs?: number;
70
+ blockNumber?: number;
71
+ };
72
+ }): Promise<Liquidity[]>;
73
+ declare function serialize(liquidity: Liquidity): string;
74
+
75
+ type Liquidity$1_Liquidity = Liquidity;
76
+ type Liquidity$1_LiquidityPool = LiquidityPool;
77
+ type Liquidity$1_LiquidityQueue = LiquidityQueue;
78
+ type Liquidity$1_LiquidityQueueWithPool = LiquidityQueueWithPool;
79
+ type Liquidity$1_LiquidityUserPosition = LiquidityUserPosition;
80
+ declare const Liquidity$1_fetch: typeof fetch;
81
+ declare const Liquidity$1_fetchBalancesAndAllowances: typeof fetchBalancesAndAllowances;
82
+ declare const Liquidity$1_serialize: typeof serialize;
83
+ declare namespace Liquidity$1 {
84
+ export { type Liquidity$1_Liquidity as Liquidity, type Liquidity$1_LiquidityPool as LiquidityPool, type Liquidity$1_LiquidityQueue as LiquidityQueue, type Liquidity$1_LiquidityQueueWithPool as LiquidityQueueWithPool, type Liquidity$1_LiquidityUserPosition as LiquidityUserPosition, Liquidity$1_fetch as fetch, Liquidity$1_fetchBalancesAndAllowances as fetchBalancesAndAllowances, Liquidity$1_serialize as serialize };
85
+ }
86
+
87
+ declare enum CallbackType {
88
+ BuyWithEmptyCallback = "buy_with_empty_callback"
89
+ }
90
+ declare function buildLiquidity(parameters: {
91
+ type: CallbackType;
92
+ user: string;
93
+ contract: string;
94
+ chainId: bigint;
95
+ amount: string | bigint;
96
+ index?: number;
97
+ updatedAt?: Date;
98
+ }): Liquidity;
99
+ declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
100
+
101
+ type Callback_CallbackType = CallbackType;
102
+ declare const Callback_CallbackType: typeof CallbackType;
103
+ declare const Callback_buildLiquidity: typeof buildLiquidity;
104
+ declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
105
+ declare namespace Callback {
106
+ export { Callback_CallbackType as CallbackType, Callback_buildLiquidity as buildLiquidity, Callback_getCallbackIdForOffer as getCallbackIdForOffer };
107
+ }
108
+
109
+ type Cursor = {
110
+ sort: "rate" | "maturity" | "expiry" | "amount";
111
+ dir: "asc" | "desc";
112
+ rate?: string;
113
+ maturity?: number;
114
+ expiry?: number;
115
+ assets?: string;
116
+ hash: string;
117
+ };
118
+ declare function validate(cursor: unknown): cursor is Cursor;
119
+ declare function encode(c: Cursor): string;
120
+ declare function decode(token?: string): Cursor | null;
121
+
122
+ type Cursor$1_Cursor = Cursor;
123
+ declare const Cursor$1_decode: typeof decode;
124
+ declare const Cursor$1_encode: typeof encode;
125
+ declare const Cursor$1_validate: typeof validate;
126
+ declare namespace Cursor$1 {
127
+ export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
128
+ }
129
+
13
130
  declare const OpenApi: node_modules_zod_openapi_dist_components_DkyUTLcs_js.OpenAPIObject;
14
131
 
15
132
  declare const schemas: {
@@ -70,7 +187,6 @@ declare const schemas: {
70
187
  max_maturity: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
71
188
  loan_token: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
72
189
  creator: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
73
- status: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<("valid" | "callback_not_supported" | "callback_error" | "unverified")[], string>>>;
74
190
  cursor: z.ZodOptional<z.ZodString>;
75
191
  limit: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>>;
76
192
  }, z.core.$strip>;
@@ -234,14 +350,14 @@ declare function toResponse(routerOffer: RouterOffer): OfferResponse;
234
350
  */
235
351
  declare function fromResponse(offerResponse: OfferResponse): RouterOffer;
236
352
 
237
- type index$3_OfferResponse = OfferResponse;
238
- declare const index$3_OpenApi: typeof OpenApi;
239
- declare const index$3_fromResponse: typeof fromResponse;
240
- declare const index$3_parse: typeof parse;
241
- declare const index$3_safeParse: typeof safeParse;
242
- declare const index$3_toResponse: typeof toResponse;
243
- declare namespace index$3 {
244
- export { type index$3_OfferResponse as OfferResponse, index$3_OpenApi as OpenApi, index$3_fromResponse as fromResponse, index$3_parse as parse, index$3_safeParse as safeParse, index$3_toResponse as toResponse };
353
+ type index$2_OfferResponse = OfferResponse;
354
+ declare const index$2_OpenApi: typeof OpenApi;
355
+ declare const index$2_fromResponse: typeof fromResponse;
356
+ declare const index$2_parse: typeof parse;
357
+ declare const index$2_safeParse: typeof safeParse;
358
+ declare const index$2_toResponse: typeof toResponse;
359
+ declare namespace index$2 {
360
+ export { type index$2_OfferResponse as OfferResponse, index$2_OpenApi as OpenApi, index$2_fromResponse as fromResponse, index$2_parse as parse, index$2_safeParse as safeParse, index$2_toResponse as toResponse };
245
361
  }
246
362
 
247
363
  type GetParameters = {
@@ -481,8 +597,6 @@ type FindMatchingOffersParams = {
481
597
  maxMaturity?: number;
482
598
  loanToken?: string;
483
599
  creator?: string;
484
- /** Filter by offer status; if omitted defaults to ["valid"] */
485
- status?: OfferStatus[];
486
600
  /** Cursor string returned by a previous call, for pagination */
487
601
  cursor?: string;
488
602
  /** Page size; defaults to 20 */
@@ -500,13 +614,13 @@ declare function memory(parameters: {
500
614
  filled: Map<Chain.Id, Map<Address, Map<bigint, bigint>>>;
501
615
  }): OfferStore;
502
616
 
503
- type index$2_FindMatchingOffersParams = FindMatchingOffersParams;
504
- type index$2_GetAllParams = GetAllParams;
505
- type index$2_GetOffersFilters = GetOffersFilters;
506
- type index$2_OfferStore = OfferStore;
507
- declare const index$2_memory: typeof memory;
508
- declare namespace index$2 {
509
- export { type index$2_FindMatchingOffersParams as FindMatchingOffersParams, type index$2_GetAllParams as GetAllParams, type index$2_GetOffersFilters as GetOffersFilters, type index$2_OfferStore as OfferStore, index$2_memory as memory };
617
+ type index$1_FindMatchingOffersParams = FindMatchingOffersParams;
618
+ type index$1_GetAllParams = GetAllParams;
619
+ type index$1_GetOffersFilters = GetOffersFilters;
620
+ type index$1_OfferStore = OfferStore;
621
+ declare const index$1_memory: typeof memory;
622
+ declare namespace index$1 {
623
+ export { type index$1_FindMatchingOffersParams as FindMatchingOffersParams, type index$1_GetAllParams as GetAllParams, type index$1_GetOffersFilters as GetOffersFilters, type index$1_OfferStore as OfferStore, index$1_memory as memory };
510
624
  }
511
625
 
512
626
  /**
@@ -605,39 +719,39 @@ declare class BadRequestError extends APIError {
605
719
  }
606
720
  declare function handleZodError(error: z.ZodError): ValidationError;
607
721
 
608
- type index$1_APIError = APIError;
609
- declare const index$1_APIError: typeof APIError;
610
- type index$1_BadRequestError = BadRequestError;
611
- declare const index$1_BadRequestError: typeof BadRequestError;
612
- type index$1_Client = Client;
613
- type index$1_GetParameters = GetParameters;
614
- type index$1_HttpForbiddenError = HttpForbiddenError;
615
- declare const index$1_HttpForbiddenError: typeof HttpForbiddenError;
616
- type index$1_HttpGetOffersFailedError = HttpGetOffersFailedError;
617
- declare const index$1_HttpGetOffersFailedError: typeof HttpGetOffersFailedError;
618
- type index$1_HttpRateLimitError = HttpRateLimitError;
619
- declare const index$1_HttpRateLimitError: typeof HttpRateLimitError;
620
- type index$1_HttpUnauthorizedError = HttpUnauthorizedError;
621
- declare const index$1_HttpUnauthorizedError: typeof HttpUnauthorizedError;
622
- type index$1_InternalServerError = InternalServerError;
623
- declare const index$1_InternalServerError: typeof InternalServerError;
624
- type index$1_InvalidUrlError = InvalidUrlError;
625
- declare const index$1_InvalidUrlError: typeof InvalidUrlError;
626
- type index$1_MatchParameters = MatchParameters;
627
- type index$1_NotFoundError = NotFoundError;
628
- declare const index$1_NotFoundError: typeof NotFoundError;
629
- type index$1_RouterClientConfig = RouterClientConfig;
630
- type index$1_ValidationError = ValidationError;
631
- declare const index$1_ValidationError: typeof ValidationError;
632
- declare const index$1_connect: typeof connect;
633
- declare const index$1_error: typeof error;
634
- declare const index$1_get: typeof get;
635
- declare const index$1_handleZodError: typeof handleZodError;
636
- declare const index$1_match: typeof match;
637
- declare const index$1_serve: typeof serve;
638
- declare const index$1_success: typeof success;
639
- declare namespace index$1 {
640
- export { index$1_APIError as APIError, index$1_BadRequestError as BadRequestError, type index$1_Client as Client, type index$1_GetParameters as GetParameters, index$1_HttpForbiddenError as HttpForbiddenError, index$1_HttpGetOffersFailedError as HttpGetOffersFailedError, index$1_HttpRateLimitError as HttpRateLimitError, index$1_HttpUnauthorizedError as HttpUnauthorizedError, index$1_InternalServerError as InternalServerError, index$1_InvalidUrlError as InvalidUrlError, type index$1_MatchParameters as MatchParameters, index$1_NotFoundError as NotFoundError, type index$1_RouterClientConfig as RouterClientConfig, index$1_ValidationError as ValidationError, index$1_connect as connect, index$1_error as error, index$1_get as get, index$1_handleZodError as handleZodError, index$1_match as match, index$1_serve as serve, index$1_success as success };
722
+ type index_APIError = APIError;
723
+ declare const index_APIError: typeof APIError;
724
+ type index_BadRequestError = BadRequestError;
725
+ declare const index_BadRequestError: typeof BadRequestError;
726
+ type index_Client = Client;
727
+ type index_GetParameters = GetParameters;
728
+ type index_HttpForbiddenError = HttpForbiddenError;
729
+ declare const index_HttpForbiddenError: typeof HttpForbiddenError;
730
+ type index_HttpGetOffersFailedError = HttpGetOffersFailedError;
731
+ declare const index_HttpGetOffersFailedError: typeof HttpGetOffersFailedError;
732
+ type index_HttpRateLimitError = HttpRateLimitError;
733
+ declare const index_HttpRateLimitError: typeof HttpRateLimitError;
734
+ type index_HttpUnauthorizedError = HttpUnauthorizedError;
735
+ declare const index_HttpUnauthorizedError: typeof HttpUnauthorizedError;
736
+ type index_InternalServerError = InternalServerError;
737
+ declare const index_InternalServerError: typeof InternalServerError;
738
+ type index_InvalidUrlError = InvalidUrlError;
739
+ declare const index_InvalidUrlError: typeof InvalidUrlError;
740
+ type index_MatchParameters = MatchParameters;
741
+ type index_NotFoundError = NotFoundError;
742
+ declare const index_NotFoundError: typeof NotFoundError;
743
+ type index_RouterClientConfig = RouterClientConfig;
744
+ type index_ValidationError = ValidationError;
745
+ declare const index_ValidationError: typeof ValidationError;
746
+ declare const index_connect: typeof connect;
747
+ declare const index_error: typeof error;
748
+ declare const index_get: typeof get;
749
+ declare const index_handleZodError: typeof handleZodError;
750
+ declare const index_match: typeof match;
751
+ declare const index_serve: typeof serve;
752
+ declare const index_success: typeof success;
753
+ declare namespace index {
754
+ export { index_APIError as APIError, index_BadRequestError as BadRequestError, 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_InternalServerError as InternalServerError, index_InvalidUrlError as InvalidUrlError, type index_MatchParameters as MatchParameters, index_NotFoundError as NotFoundError, type index_RouterClientConfig as RouterClientConfig, index_ValidationError as ValidationError, index_connect as connect, index_error as error, index_get as get, index_handleZodError as handleZodError, index_match as match, index_serve as serve, index_success as success };
641
755
  }
642
756
 
643
757
  declare const LogLevelValues: readonly ["silent", "trace", "debug", "info", "warn", "error", "fatal"];
@@ -672,63 +786,6 @@ declare namespace Logger$1 {
672
786
  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, Logger$1_silentLogger as silentLogger };
673
787
  }
674
788
 
675
- /**
676
- * Splits an array into batches of a specified size.
677
- * @param array The array to split.
678
- * @param batchSize The size of each batch.
679
- * @returns An iterator that yields each batch.
680
- * @example
681
- * ```typescript
682
- * const array = [1, 2, 3, 4, 5];
683
- * for (const batch of batch(array, 2)) {
684
- * console.log(batch);
685
- * }
686
- * // Output:
687
- * // [1, 2]
688
- * // [3, 4]
689
- * // [5]
690
- * ```
691
- */
692
- declare function batch$1<T>(array: Array<T>, batchSize: number): Generator<T[], void, unknown>;
693
-
694
- type Cursor = {
695
- sort: "rate" | "maturity" | "expiry" | "amount";
696
- dir: "asc" | "desc";
697
- rate?: string;
698
- maturity?: number;
699
- expiry?: number;
700
- assets?: string;
701
- hash: string;
702
- };
703
- declare function validateCursor(cursor: unknown): cursor is Cursor;
704
- declare function encodeCursor(c: Cursor): string;
705
- declare function decodeCursor(token?: string): Cursor | null;
706
-
707
- /**
708
- * Polls a function at a specified interval.
709
- * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts
710
- */
711
- declare function poll<data>(fn: ({ unpoll }: {
712
- unpoll: () => void;
713
- }) => Promise<data | undefined>, { interval }: {
714
- interval: number;
715
- }): () => boolean;
716
-
717
- declare const retry: <T>(fn: () => Promise<T>, attempts?: number, delayMs?: number) => Promise<T>;
718
-
719
- declare function wait(time: number): Promise<unknown>;
720
-
721
- type index_Cursor = Cursor;
722
- declare const index_decodeCursor: typeof decodeCursor;
723
- declare const index_encodeCursor: typeof encodeCursor;
724
- declare const index_poll: typeof poll;
725
- declare const index_retry: typeof retry;
726
- declare const index_validateCursor: typeof validateCursor;
727
- declare const index_wait: typeof wait;
728
- declare namespace index {
729
- export { type index_Cursor as Cursor, batch$1 as batch, index_decodeCursor as decodeCursor, index_encodeCursor as encodeCursor, index_poll as poll, index_retry as retry, index_validateCursor as validateCursor, index_wait as wait };
730
- }
731
-
732
789
  /**
733
790
  * A validation rule.
734
791
  */
@@ -926,4 +983,4 @@ declare namespace Validation {
926
983
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
927
984
  }
928
985
 
929
- export { index$3 as ApiSchema, Logger$1 as Logger, index$2 as OfferStore, index$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
986
+ export { index$2 as ApiSchema, Callback, Cursor$1 as Cursor, Liquidity$1 as Liquidity, Logger$1 as Logger, index$1 as OfferStore, index as Router, RouterOffer$1 as RouterOffer, Validation, ValidationRule };