@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.
@@ -2,9 +2,126 @@ 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
4
  import * as viem from 'viem';
5
- import { Address, Hex } from 'viem';
5
+ import { PublicActions, Address, Hex } from 'viem';
6
6
  import { z, ZodError } from 'zod/v4';
7
7
 
8
+ declare function fetchBalancesAndAllowances(parameters: {
9
+ client: Pick<PublicActions, "multicall">;
10
+ spender: Address;
11
+ pairs: Array<{
12
+ user: Address;
13
+ token: Address;
14
+ }>;
15
+ options?: {
16
+ batchSize?: number;
17
+ retryAttempts?: number;
18
+ retryDelayMs?: number;
19
+ blockNumber?: number;
20
+ };
21
+ }): Promise<Map<Address, Map<Address, {
22
+ balance: bigint;
23
+ allowance: bigint;
24
+ }>>>;
25
+ type LiquidityUserPosition = {
26
+ id: string;
27
+ availableLiquidityQueueId: string;
28
+ user: string;
29
+ chainId: bigint;
30
+ amount: string;
31
+ updatedAt: Date;
32
+ };
33
+ type LiquidityQueue = {
34
+ queueId: string;
35
+ availableLiquidityPoolId: string;
36
+ index: number;
37
+ updatedAt: Date;
38
+ };
39
+ type LiquidityPool = {
40
+ id: string;
41
+ amount: string;
42
+ updatedAt: Date;
43
+ };
44
+ type LiquidityQueueWithPool = {
45
+ queue: LiquidityQueue;
46
+ pool: LiquidityPool;
47
+ };
48
+ type Liquidity = {
49
+ userPosition: LiquidityUserPosition;
50
+ queues: LiquidityQueueWithPool[];
51
+ };
52
+ declare function fetch(parameters: {
53
+ client: Pick<PublicActions, "multicall">;
54
+ chainId: bigint;
55
+ spender: Address;
56
+ type: CallbackType;
57
+ pairs: Array<{
58
+ user: Address;
59
+ contract: Address;
60
+ }>;
61
+ options?: {
62
+ batchSize?: number;
63
+ retryAttempts?: number;
64
+ retryDelayMs?: number;
65
+ blockNumber?: number;
66
+ };
67
+ }): Promise<Liquidity[]>;
68
+ declare function serialize(liquidity: Liquidity): string;
69
+
70
+ type Liquidity$1_Liquidity = Liquidity;
71
+ type Liquidity$1_LiquidityPool = LiquidityPool;
72
+ type Liquidity$1_LiquidityQueue = LiquidityQueue;
73
+ type Liquidity$1_LiquidityQueueWithPool = LiquidityQueueWithPool;
74
+ type Liquidity$1_LiquidityUserPosition = LiquidityUserPosition;
75
+ declare const Liquidity$1_fetch: typeof fetch;
76
+ declare const Liquidity$1_fetchBalancesAndAllowances: typeof fetchBalancesAndAllowances;
77
+ declare const Liquidity$1_serialize: typeof serialize;
78
+ declare namespace Liquidity$1 {
79
+ 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 };
80
+ }
81
+
82
+ declare enum CallbackType {
83
+ BuyWithEmptyCallback = "buy_with_empty_callback"
84
+ }
85
+ declare function buildLiquidity(parameters: {
86
+ type: CallbackType;
87
+ user: string;
88
+ contract: string;
89
+ chainId: bigint;
90
+ amount: string | bigint;
91
+ index?: number;
92
+ updatedAt?: Date;
93
+ }): Liquidity;
94
+ declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
95
+
96
+ type Callback_CallbackType = CallbackType;
97
+ declare const Callback_CallbackType: typeof CallbackType;
98
+ declare const Callback_buildLiquidity: typeof buildLiquidity;
99
+ declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
100
+ declare namespace Callback {
101
+ export { Callback_CallbackType as CallbackType, Callback_buildLiquidity as buildLiquidity, Callback_getCallbackIdForOffer as getCallbackIdForOffer };
102
+ }
103
+
104
+ type Cursor = {
105
+ sort: "rate" | "maturity" | "expiry" | "amount";
106
+ dir: "asc" | "desc";
107
+ rate?: string;
108
+ maturity?: number;
109
+ expiry?: number;
110
+ assets?: string;
111
+ hash: string;
112
+ };
113
+ declare function validate(cursor: unknown): cursor is Cursor;
114
+ declare function encode(c: Cursor): string;
115
+ declare function decode(token?: string): Cursor | null;
116
+
117
+ type Cursor$1_Cursor = Cursor;
118
+ declare const Cursor$1_decode: typeof decode;
119
+ declare const Cursor$1_encode: typeof encode;
120
+ declare const Cursor$1_validate: typeof validate;
121
+ declare namespace Cursor$1 {
122
+ export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
123
+ }
124
+
8
125
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
9
126
  type OfferStatus = (typeof OfferStatusValues)[number];
10
127
  type OfferMetadata = {
@@ -406,8 +523,6 @@ type FindMatchingOffersParams = {
406
523
  maxMaturity?: number;
407
524
  loanToken?: string;
408
525
  creator?: string;
409
- /** Filter by offer status; if omitted defaults to ["valid"] */
410
- status?: OfferStatus[];
411
526
  /** Cursor string returned by a previous call, for pagination */
412
527
  cursor?: string;
413
528
  /** Page size; defaults to 20 */
@@ -425,70 +540,13 @@ declare function memory(parameters: {
425
540
  filled: Map<Chain.Id, Map<Address, Map<bigint, bigint>>>;
426
541
  }): OfferStore;
427
542
 
428
- type index$1_FindMatchingOffersParams = FindMatchingOffersParams;
429
- type index$1_GetAllParams = GetAllParams;
430
- type index$1_GetOffersFilters = GetOffersFilters;
431
- type index$1_OfferStore = OfferStore;
432
- declare const index$1_memory: typeof memory;
433
- declare namespace index$1 {
434
- 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 };
435
- }
436
-
437
- /**
438
- * Splits an array into batches of a specified size.
439
- * @param array The array to split.
440
- * @param batchSize The size of each batch.
441
- * @returns An iterator that yields each batch.
442
- * @example
443
- * ```typescript
444
- * const array = [1, 2, 3, 4, 5];
445
- * for (const batch of batch(array, 2)) {
446
- * console.log(batch);
447
- * }
448
- * // Output:
449
- * // [1, 2]
450
- * // [3, 4]
451
- * // [5]
452
- * ```
453
- */
454
- declare function batch$1<T>(array: Array<T>, batchSize: number): Generator<T[], void, unknown>;
455
-
456
- type Cursor = {
457
- sort: "rate" | "maturity" | "expiry" | "amount";
458
- dir: "asc" | "desc";
459
- rate?: string;
460
- maturity?: number;
461
- expiry?: number;
462
- assets?: string;
463
- hash: string;
464
- };
465
- declare function validateCursor(cursor: unknown): cursor is Cursor;
466
- declare function encodeCursor(c: Cursor): string;
467
- declare function decodeCursor(token?: string): Cursor | null;
468
-
469
- /**
470
- * Polls a function at a specified interval.
471
- * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts
472
- */
473
- declare function poll<data>(fn: ({ unpoll }: {
474
- unpoll: () => void;
475
- }) => Promise<data | undefined>, { interval }: {
476
- interval: number;
477
- }): () => boolean;
478
-
479
- declare const retry: <T>(fn: () => Promise<T>, attempts?: number, delayMs?: number) => Promise<T>;
480
-
481
- declare function wait(time: number): Promise<unknown>;
482
-
483
- type index_Cursor = Cursor;
484
- declare const index_decodeCursor: typeof decodeCursor;
485
- declare const index_encodeCursor: typeof encodeCursor;
486
- declare const index_poll: typeof poll;
487
- declare const index_retry: typeof retry;
488
- declare const index_validateCursor: typeof validateCursor;
489
- declare const index_wait: typeof wait;
543
+ type index_FindMatchingOffersParams = FindMatchingOffersParams;
544
+ type index_GetAllParams = GetAllParams;
545
+ type index_GetOffersFilters = GetOffersFilters;
546
+ type index_OfferStore = OfferStore;
547
+ declare const index_memory: typeof memory;
490
548
  declare namespace index {
491
- 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 };
549
+ export { type index_FindMatchingOffersParams as FindMatchingOffersParams, type index_GetAllParams as GetAllParams, type index_GetOffersFilters as GetOffersFilters, type index_OfferStore as OfferStore, index_memory as memory };
492
550
  }
493
551
 
494
552
  /**
@@ -688,4 +746,4 @@ declare namespace Validation {
688
746
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
689
747
  }
690
748
 
691
- export { index$1 as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
749
+ export { Callback, Cursor$1 as Cursor, Liquidity$1 as Liquidity, index as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, Validation, ValidationRule };
@@ -2,9 +2,126 @@ 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
4
  import * as viem from 'viem';
5
- import { Address, Hex } from 'viem';
5
+ import { PublicActions, Address, Hex } from 'viem';
6
6
  import { z, ZodError } from 'zod/v4';
7
7
 
8
+ declare function fetchBalancesAndAllowances(parameters: {
9
+ client: Pick<PublicActions, "multicall">;
10
+ spender: Address;
11
+ pairs: Array<{
12
+ user: Address;
13
+ token: Address;
14
+ }>;
15
+ options?: {
16
+ batchSize?: number;
17
+ retryAttempts?: number;
18
+ retryDelayMs?: number;
19
+ blockNumber?: number;
20
+ };
21
+ }): Promise<Map<Address, Map<Address, {
22
+ balance: bigint;
23
+ allowance: bigint;
24
+ }>>>;
25
+ type LiquidityUserPosition = {
26
+ id: string;
27
+ availableLiquidityQueueId: string;
28
+ user: string;
29
+ chainId: bigint;
30
+ amount: string;
31
+ updatedAt: Date;
32
+ };
33
+ type LiquidityQueue = {
34
+ queueId: string;
35
+ availableLiquidityPoolId: string;
36
+ index: number;
37
+ updatedAt: Date;
38
+ };
39
+ type LiquidityPool = {
40
+ id: string;
41
+ amount: string;
42
+ updatedAt: Date;
43
+ };
44
+ type LiquidityQueueWithPool = {
45
+ queue: LiquidityQueue;
46
+ pool: LiquidityPool;
47
+ };
48
+ type Liquidity = {
49
+ userPosition: LiquidityUserPosition;
50
+ queues: LiquidityQueueWithPool[];
51
+ };
52
+ declare function fetch(parameters: {
53
+ client: Pick<PublicActions, "multicall">;
54
+ chainId: bigint;
55
+ spender: Address;
56
+ type: CallbackType;
57
+ pairs: Array<{
58
+ user: Address;
59
+ contract: Address;
60
+ }>;
61
+ options?: {
62
+ batchSize?: number;
63
+ retryAttempts?: number;
64
+ retryDelayMs?: number;
65
+ blockNumber?: number;
66
+ };
67
+ }): Promise<Liquidity[]>;
68
+ declare function serialize(liquidity: Liquidity): string;
69
+
70
+ type Liquidity$1_Liquidity = Liquidity;
71
+ type Liquidity$1_LiquidityPool = LiquidityPool;
72
+ type Liquidity$1_LiquidityQueue = LiquidityQueue;
73
+ type Liquidity$1_LiquidityQueueWithPool = LiquidityQueueWithPool;
74
+ type Liquidity$1_LiquidityUserPosition = LiquidityUserPosition;
75
+ declare const Liquidity$1_fetch: typeof fetch;
76
+ declare const Liquidity$1_fetchBalancesAndAllowances: typeof fetchBalancesAndAllowances;
77
+ declare const Liquidity$1_serialize: typeof serialize;
78
+ declare namespace Liquidity$1 {
79
+ 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 };
80
+ }
81
+
82
+ declare enum CallbackType {
83
+ BuyWithEmptyCallback = "buy_with_empty_callback"
84
+ }
85
+ declare function buildLiquidity(parameters: {
86
+ type: CallbackType;
87
+ user: string;
88
+ contract: string;
89
+ chainId: bigint;
90
+ amount: string | bigint;
91
+ index?: number;
92
+ updatedAt?: Date;
93
+ }): Liquidity;
94
+ declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
95
+
96
+ type Callback_CallbackType = CallbackType;
97
+ declare const Callback_CallbackType: typeof CallbackType;
98
+ declare const Callback_buildLiquidity: typeof buildLiquidity;
99
+ declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
100
+ declare namespace Callback {
101
+ export { Callback_CallbackType as CallbackType, Callback_buildLiquidity as buildLiquidity, Callback_getCallbackIdForOffer as getCallbackIdForOffer };
102
+ }
103
+
104
+ type Cursor = {
105
+ sort: "rate" | "maturity" | "expiry" | "amount";
106
+ dir: "asc" | "desc";
107
+ rate?: string;
108
+ maturity?: number;
109
+ expiry?: number;
110
+ assets?: string;
111
+ hash: string;
112
+ };
113
+ declare function validate(cursor: unknown): cursor is Cursor;
114
+ declare function encode(c: Cursor): string;
115
+ declare function decode(token?: string): Cursor | null;
116
+
117
+ type Cursor$1_Cursor = Cursor;
118
+ declare const Cursor$1_decode: typeof decode;
119
+ declare const Cursor$1_encode: typeof encode;
120
+ declare const Cursor$1_validate: typeof validate;
121
+ declare namespace Cursor$1 {
122
+ export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
123
+ }
124
+
8
125
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
9
126
  type OfferStatus = (typeof OfferStatusValues)[number];
10
127
  type OfferMetadata = {
@@ -406,8 +523,6 @@ type FindMatchingOffersParams = {
406
523
  maxMaturity?: number;
407
524
  loanToken?: string;
408
525
  creator?: string;
409
- /** Filter by offer status; if omitted defaults to ["valid"] */
410
- status?: OfferStatus[];
411
526
  /** Cursor string returned by a previous call, for pagination */
412
527
  cursor?: string;
413
528
  /** Page size; defaults to 20 */
@@ -425,70 +540,13 @@ declare function memory(parameters: {
425
540
  filled: Map<Chain.Id, Map<Address, Map<bigint, bigint>>>;
426
541
  }): OfferStore;
427
542
 
428
- type index$1_FindMatchingOffersParams = FindMatchingOffersParams;
429
- type index$1_GetAllParams = GetAllParams;
430
- type index$1_GetOffersFilters = GetOffersFilters;
431
- type index$1_OfferStore = OfferStore;
432
- declare const index$1_memory: typeof memory;
433
- declare namespace index$1 {
434
- 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 };
435
- }
436
-
437
- /**
438
- * Splits an array into batches of a specified size.
439
- * @param array The array to split.
440
- * @param batchSize The size of each batch.
441
- * @returns An iterator that yields each batch.
442
- * @example
443
- * ```typescript
444
- * const array = [1, 2, 3, 4, 5];
445
- * for (const batch of batch(array, 2)) {
446
- * console.log(batch);
447
- * }
448
- * // Output:
449
- * // [1, 2]
450
- * // [3, 4]
451
- * // [5]
452
- * ```
453
- */
454
- declare function batch$1<T>(array: Array<T>, batchSize: number): Generator<T[], void, unknown>;
455
-
456
- type Cursor = {
457
- sort: "rate" | "maturity" | "expiry" | "amount";
458
- dir: "asc" | "desc";
459
- rate?: string;
460
- maturity?: number;
461
- expiry?: number;
462
- assets?: string;
463
- hash: string;
464
- };
465
- declare function validateCursor(cursor: unknown): cursor is Cursor;
466
- declare function encodeCursor(c: Cursor): string;
467
- declare function decodeCursor(token?: string): Cursor | null;
468
-
469
- /**
470
- * Polls a function at a specified interval.
471
- * Inspired by https://github.com/wevm/viem/blob/845994d20275d08ff892018e237a4b599eeefb6a/src/utils/poll.ts
472
- */
473
- declare function poll<data>(fn: ({ unpoll }: {
474
- unpoll: () => void;
475
- }) => Promise<data | undefined>, { interval }: {
476
- interval: number;
477
- }): () => boolean;
478
-
479
- declare const retry: <T>(fn: () => Promise<T>, attempts?: number, delayMs?: number) => Promise<T>;
480
-
481
- declare function wait(time: number): Promise<unknown>;
482
-
483
- type index_Cursor = Cursor;
484
- declare const index_decodeCursor: typeof decodeCursor;
485
- declare const index_encodeCursor: typeof encodeCursor;
486
- declare const index_poll: typeof poll;
487
- declare const index_retry: typeof retry;
488
- declare const index_validateCursor: typeof validateCursor;
489
- declare const index_wait: typeof wait;
543
+ type index_FindMatchingOffersParams = FindMatchingOffersParams;
544
+ type index_GetAllParams = GetAllParams;
545
+ type index_GetOffersFilters = GetOffersFilters;
546
+ type index_OfferStore = OfferStore;
547
+ declare const index_memory: typeof memory;
490
548
  declare namespace index {
491
- 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 };
549
+ export { type index_FindMatchingOffersParams as FindMatchingOffersParams, type index_GetAllParams as GetAllParams, type index_GetOffersFilters as GetOffersFilters, type index_OfferStore as OfferStore, index_memory as memory };
492
550
  }
493
551
 
494
552
  /**
@@ -688,4 +746,4 @@ declare namespace Validation {
688
746
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
689
747
  }
690
748
 
691
- export { index$1 as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
749
+ export { Callback, Cursor$1 as Cursor, Liquidity$1 as Liquidity, index as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, Validation, ValidationRule };