@morpho-dev/router 0.1.10 → 0.1.12

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 (28) hide show
  1. package/README.md +7 -7
  2. package/dist/drizzle/{offers_v1.1 → router_v1.1}/0000_init.sql +47 -39
  3. package/dist/drizzle/{offers_v1.1/meta/0005_snapshot.json → router_v1.1/meta/0000_snapshot.json} +76 -21
  4. package/dist/drizzle/router_v1.1/meta/_journal.json +13 -0
  5. package/dist/index.browser.d.cts +185 -143
  6. package/dist/index.browser.d.ts +185 -143
  7. package/dist/index.browser.js +808 -443
  8. package/dist/index.browser.js.map +1 -1
  9. package/dist/index.browser.mjs +810 -445
  10. package/dist/index.browser.mjs.map +1 -1
  11. package/dist/index.node.d.cts +1861 -1792
  12. package/dist/index.node.d.ts +1861 -1792
  13. package/dist/index.node.js +2921 -2384
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.node.mjs +2923 -2385
  16. package/dist/index.node.mjs.map +1 -1
  17. package/package.json +4 -4
  18. package/dist/drizzle/offers_v1.1/0001_new_table_for_collectors_block_numbers.sql +0 -5
  19. package/dist/drizzle/offers_v1.1/0002_update-liquidity-tables.sql +0 -8
  20. package/dist/drizzle/offers_v1.1/0003_add-not-null-for-queue-id.sql +0 -1
  21. package/dist/drizzle/offers_v1.1/0004_add-callback-id-to-offer.sql +0 -1
  22. package/dist/drizzle/offers_v1.1/0005_add-missing-indices-to-liquidity-tables.sql +0 -2
  23. package/dist/drizzle/offers_v1.1/meta/0000_snapshot.json +0 -827
  24. package/dist/drizzle/offers_v1.1/meta/0001_snapshot.json +0 -827
  25. package/dist/drizzle/offers_v1.1/meta/0002_snapshot.json +0 -833
  26. package/dist/drizzle/offers_v1.1/meta/0003_snapshot.json +0 -833
  27. package/dist/drizzle/offers_v1.1/meta/0004_snapshot.json +0 -839
  28. package/dist/drizzle/offers_v1.1/meta/_journal.json +0 -48
@@ -2,143 +2,9 @@ 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 { PublicActions, Address, Hex } from 'viem';
5
+ import { Address, Hex, PublicActions } 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
- SellWithdrawFromWallet = "sell_withdraw_from_wallet"
85
- }
86
- declare const WhitelistedCallbackAddresses: Record<CallbackType, readonly string[]>;
87
- declare function buildLiquidity(parameters: {
88
- type: CallbackType;
89
- user: string;
90
- contract: string;
91
- chainId: bigint;
92
- amount: string | bigint;
93
- index?: number;
94
- updatedAt?: Date;
95
- }): Liquidity;
96
- declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
97
- declare function decode$1(parameters: {
98
- type: CallbackType;
99
- data: Hex;
100
- }): Array<{
101
- collateral: Address;
102
- amount: bigint;
103
- }>;
104
- declare function encode$1(parameters: {
105
- type: CallbackType;
106
- data: {
107
- collaterals: Address[];
108
- amounts: bigint[];
109
- };
110
- }): Hex;
111
-
112
- type Callback_CallbackType = CallbackType;
113
- declare const Callback_CallbackType: typeof CallbackType;
114
- declare const Callback_WhitelistedCallbackAddresses: typeof WhitelistedCallbackAddresses;
115
- declare const Callback_buildLiquidity: typeof buildLiquidity;
116
- declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
117
- declare namespace Callback {
118
- export { Callback_CallbackType as CallbackType, Callback_WhitelistedCallbackAddresses as WhitelistedCallbackAddresses, Callback_buildLiquidity as buildLiquidity, decode$1 as decode, encode$1 as encode, Callback_getCallbackIdForOffer as getCallbackIdForOffer };
119
- }
120
-
121
- type Cursor = {
122
- sort: "rate" | "maturity" | "expiry" | "amount";
123
- dir: "asc" | "desc";
124
- rate?: string;
125
- maturity?: number;
126
- expiry?: number;
127
- assets?: string;
128
- hash: string;
129
- };
130
- declare function validate(cursor: unknown): cursor is Cursor;
131
- declare function encode(c: Cursor): string;
132
- declare function decode(token?: string): Cursor | null;
133
-
134
- type Cursor$1_Cursor = Cursor;
135
- declare const Cursor$1_decode: typeof decode;
136
- declare const Cursor$1_encode: typeof encode;
137
- declare const Cursor$1_validate: typeof validate;
138
- declare namespace Cursor$1 {
139
- export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
140
- }
141
-
142
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
143
9
  type OfferStatus = (typeof OfferStatusValues)[number];
144
10
  type OfferMetadata = {
@@ -364,11 +230,11 @@ type MatchParameters = {
364
230
  /** Maximum number of offers to return. Defaults to 20. Maximum is 100. */
365
231
  limit?: number;
366
232
  };
367
- type RouterClientConfig = {
233
+ type RouterApiClientConfig = {
368
234
  readonly url: URL;
369
235
  readonly headers: Headers;
370
236
  };
371
- type Client = Compute<RouterClientConfig & {
237
+ type Client = Compute<RouterApiClientConfig & {
372
238
  get: (parameters: GetParameters) => Promise<{
373
239
  cursor: string | null;
374
240
  offers: OfferResponse[];
@@ -390,7 +256,7 @@ declare namespace connect {
390
256
  * Get offers from the router.
391
257
  * @returns The offers with pagination cursor.
392
258
  */
393
- declare function get(config: RouterClientConfig, parameters: GetParameters): Promise<{
259
+ declare function get(config: RouterApiClientConfig, parameters: GetParameters): Promise<{
394
260
  cursor: string | null;
395
261
  offers: OfferResponse[];
396
262
  }>;
@@ -401,7 +267,7 @@ declare namespace get {
401
267
  * Match offers from the router.
402
268
  * @returns The matched offers with pagination cursor.
403
269
  */
404
- declare function match(config: RouterClientConfig, parameters: MatchParameters): Promise<{
270
+ declare function match(config: RouterApiClientConfig, parameters: MatchParameters): Promise<{
405
271
  cursor: string | null;
406
272
  offers: OfferResponse[];
407
273
  }>;
@@ -445,12 +311,164 @@ declare const Client$1_HttpUnauthorizedError: typeof HttpUnauthorizedError;
445
311
  type Client$1_InvalidUrlError = InvalidUrlError;
446
312
  declare const Client$1_InvalidUrlError: typeof InvalidUrlError;
447
313
  type Client$1_MatchParameters = MatchParameters;
448
- type Client$1_RouterClientConfig = RouterClientConfig;
314
+ type Client$1_RouterApiClientConfig = RouterApiClientConfig;
449
315
  declare const Client$1_connect: typeof connect;
450
316
  declare const Client$1_get: typeof get;
451
317
  declare const Client$1_match: typeof match;
452
318
  declare namespace Client$1 {
453
- export { type Client$1_Client as Client, type Client$1_GetParameters as GetParameters, Client$1_HttpForbiddenError as HttpForbiddenError, Client$1_HttpGetOffersFailedError as HttpGetOffersFailedError, Client$1_HttpRateLimitError as HttpRateLimitError, Client$1_HttpUnauthorizedError as HttpUnauthorizedError, Client$1_InvalidUrlError as InvalidUrlError, type Client$1_MatchParameters as MatchParameters, type Client$1_RouterClientConfig as RouterClientConfig, Client$1_connect as connect, Client$1_get as get, Client$1_match as match };
319
+ export { type Client$1_Client as Client, type Client$1_GetParameters as GetParameters, Client$1_HttpForbiddenError as HttpForbiddenError, Client$1_HttpGetOffersFailedError as HttpGetOffersFailedError, Client$1_HttpRateLimitError as HttpRateLimitError, Client$1_HttpUnauthorizedError as HttpUnauthorizedError, Client$1_InvalidUrlError as InvalidUrlError, type Client$1_MatchParameters as MatchParameters, type Client$1_RouterApiClientConfig as RouterApiClientConfig, Client$1_connect as connect, Client$1_get as get, Client$1_match as match };
320
+ }
321
+
322
+ type LiquidityUserPosition = {
323
+ id: string;
324
+ availableLiquidityQueueId: string;
325
+ user: string;
326
+ chainId: bigint;
327
+ amount: string;
328
+ updatedAt: Date;
329
+ };
330
+ type LiquidityQueue = {
331
+ queueId: string;
332
+ availableLiquidityPoolId: string;
333
+ index: number;
334
+ callbackAmount: string;
335
+ updatedAt: Date;
336
+ };
337
+ type LiquidityPool = {
338
+ id: string;
339
+ amount: string;
340
+ updatedAt: Date;
341
+ };
342
+ type LiquidityQueueWithPool = {
343
+ queue: LiquidityQueue;
344
+ pool: LiquidityPool;
345
+ };
346
+ type Liquidity = {
347
+ userPosition: LiquidityUserPosition;
348
+ queues: LiquidityQueueWithPool[];
349
+ };
350
+ type FetchOptions = {
351
+ batchSize?: number;
352
+ retryAttempts?: number;
353
+ retryDelayMs?: number;
354
+ blockNumber?: number;
355
+ };
356
+ type LiquidityClient = {
357
+ /** Fetch liquidity for buy offers based on wallet token balances and allowances. */
358
+ fetchBuyLiquidity: (parameters: {
359
+ chainId: bigint;
360
+ spender: Address;
361
+ pairs: Array<{
362
+ user: Address;
363
+ loanToken: Address;
364
+ }>;
365
+ options?: FetchOptions;
366
+ }) => Promise<Liquidity[]>;
367
+ /** Fetch liquidity for sell offers based on collateral capacity and existing positions. */
368
+ fetchSellLiquidity: (parameters: {
369
+ chainId: bigint;
370
+ spender: Address;
371
+ morphoAddress: Address;
372
+ offers: Array<Offer.Offer>;
373
+ options?: FetchOptions;
374
+ }) => Promise<Liquidity[]>;
375
+ };
376
+ /**
377
+ * Create a liquidity client with the specified blockchain client.
378
+ *
379
+ * @param config - Configuration containing the blockchain client
380
+ * @returns LiquidityClient
381
+ */
382
+ declare const create: (config: {
383
+ client: Pick<PublicActions, "multicall">;
384
+ }) => LiquidityClient;
385
+ declare function serialize(liquidity: Liquidity): string;
386
+
387
+ type Liquidity$1_Liquidity = Liquidity;
388
+ type Liquidity$1_LiquidityClient = LiquidityClient;
389
+ type Liquidity$1_LiquidityPool = LiquidityPool;
390
+ type Liquidity$1_LiquidityQueue = LiquidityQueue;
391
+ type Liquidity$1_LiquidityQueueWithPool = LiquidityQueueWithPool;
392
+ type Liquidity$1_LiquidityUserPosition = LiquidityUserPosition;
393
+ declare const Liquidity$1_create: typeof create;
394
+ declare const Liquidity$1_serialize: typeof serialize;
395
+ declare namespace Liquidity$1 {
396
+ export { type Liquidity$1_Liquidity as Liquidity, type Liquidity$1_LiquidityClient as LiquidityClient, 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_create as create, Liquidity$1_serialize as serialize };
397
+ }
398
+
399
+ declare enum CallbackType {
400
+ BuyWithEmptyCallback = "buy_with_empty_callback",
401
+ SellERC20Callback = "sell_erc20_callback"
402
+ }
403
+ declare const WhitelistedCallbackAddresses: Record<CallbackType, readonly string[]>;
404
+ type BuildLiquidityParameters = {
405
+ type: CallbackType.BuyWithEmptyCallback;
406
+ user: Address;
407
+ loanToken: Address;
408
+ chainId: Chain.Id;
409
+ amount: bigint;
410
+ index?: number;
411
+ updatedAt?: Date;
412
+ } | {
413
+ type: CallbackType.SellERC20Callback;
414
+ user: Address;
415
+ termId: string;
416
+ offerHash: string;
417
+ chainId: Chain.Id;
418
+ amount: bigint;
419
+ collaterals: Array<{
420
+ collateralAddress: Address;
421
+ balance: bigint;
422
+ callbackAmount: bigint;
423
+ }>;
424
+ index?: number;
425
+ updatedAt?: Date;
426
+ };
427
+ declare function buildLiquidity(parameters: BuildLiquidityParameters): Liquidity;
428
+ declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
429
+ declare function decode$1(parameters: {
430
+ type: CallbackType;
431
+ data: Hex;
432
+ }): Array<{
433
+ collateral: Address;
434
+ amount: bigint;
435
+ }>;
436
+ declare function encode$1(parameters: {
437
+ type: CallbackType;
438
+ data: {
439
+ collaterals: Address[];
440
+ amounts: bigint[];
441
+ };
442
+ }): Hex;
443
+
444
+ type Callback_CallbackType = CallbackType;
445
+ declare const Callback_CallbackType: typeof CallbackType;
446
+ declare const Callback_WhitelistedCallbackAddresses: typeof WhitelistedCallbackAddresses;
447
+ declare const Callback_buildLiquidity: typeof buildLiquidity;
448
+ declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
449
+ declare namespace Callback {
450
+ export { Callback_CallbackType as CallbackType, Callback_WhitelistedCallbackAddresses as WhitelistedCallbackAddresses, Callback_buildLiquidity as buildLiquidity, decode$1 as decode, encode$1 as encode, Callback_getCallbackIdForOffer as getCallbackIdForOffer };
451
+ }
452
+
453
+ type Cursor = {
454
+ sort: "rate" | "maturity" | "expiry" | "amount";
455
+ dir: "asc" | "desc";
456
+ rate?: string;
457
+ maturity?: number;
458
+ expiry?: number;
459
+ assets?: string;
460
+ hash: string;
461
+ };
462
+ declare function validate(cursor: unknown): cursor is Cursor;
463
+ declare function encode(c: Cursor): string;
464
+ declare function decode(token?: string): Cursor | null;
465
+
466
+ type Cursor$1_Cursor = Cursor;
467
+ declare const Cursor$1_decode: typeof decode;
468
+ declare const Cursor$1_encode: typeof encode;
469
+ declare const Cursor$1_validate: typeof validate;
470
+ declare namespace Cursor$1 {
471
+ export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
454
472
  }
455
473
 
456
474
  /**
@@ -691,7 +709,31 @@ declare function morpho(): (Rule<{
691
709
  readonly hash: viem.Hex;
692
710
  signature?: viem.Hex;
693
711
  createdAt?: number;
694
- }, "sell_offers_callback_collateral_invalid", MorphoContext>)[];
712
+ }, "sell_offers_callback_collateral_invalid", MorphoContext> | Rule<{
713
+ readonly offering: Address;
714
+ readonly assets: bigint;
715
+ readonly rate: bigint;
716
+ readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
717
+ readonly expiry: number;
718
+ readonly nonce: bigint;
719
+ readonly buy: boolean;
720
+ readonly chainId: bigint;
721
+ readonly loanToken: Address;
722
+ readonly start: number;
723
+ readonly collaterals: readonly {
724
+ asset: Address;
725
+ oracle: Address;
726
+ lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
727
+ }[];
728
+ readonly callback: {
729
+ readonly address: Address;
730
+ readonly data: viem.Hex;
731
+ readonly gasLimit: bigint;
732
+ };
733
+ readonly hash: viem.Hex;
734
+ signature?: viem.Hex;
735
+ createdAt?: number;
736
+ }, "maturity", MorphoContext>)[];
695
737
 
696
738
  type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
697
739
  type ValidationRule_MorphoContext = MorphoContext;
@@ -746,4 +788,4 @@ declare namespace Validation {
746
788
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
747
789
  }
748
790
 
749
- export { Callback, Cursor$1 as Cursor, Liquidity$1 as Liquidity, Client$1 as Router, RouterOffer$1 as RouterOffer, Validation, ValidationRule };
791
+ export { Callback, Cursor$1 as Cursor, Liquidity$1 as Liquidity, Client$1 as RouterApi, RouterOffer$1 as RouterOffer, Validation, ValidationRule };