@morpho-dev/router 0.1.11 → 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 (32) 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/0007_snapshot.json → router_v1.1/meta/0000_snapshot.json} +21 -21
  4. package/dist/drizzle/router_v1.1/meta/_journal.json +13 -0
  5. package/dist/index.browser.d.cts +186 -159
  6. package/dist/index.browser.d.ts +186 -159
  7. package/dist/index.browser.js +807 -491
  8. package/dist/index.browser.js.map +1 -1
  9. package/dist/index.browser.mjs +809 -493
  10. package/dist/index.browser.mjs.map +1 -1
  11. package/dist/index.node.d.cts +1795 -1759
  12. package/dist/index.node.d.ts +1795 -1759
  13. package/dist/index.node.js +2923 -2495
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.node.mjs +2925 -2496
  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/0006_add-callback-amount-to-queues-table.sql +0 -1
  24. package/dist/drizzle/offers_v1.1/0007_add-index-to-created-at.sql +0 -2
  25. package/dist/drizzle/offers_v1.1/meta/0000_snapshot.json +0 -827
  26. package/dist/drizzle/offers_v1.1/meta/0001_snapshot.json +0 -827
  27. package/dist/drizzle/offers_v1.1/meta/0002_snapshot.json +0 -833
  28. package/dist/drizzle/offers_v1.1/meta/0003_snapshot.json +0 -833
  29. package/dist/drizzle/offers_v1.1/meta/0004_snapshot.json +0 -839
  30. package/dist/drizzle/offers_v1.1/meta/0005_snapshot.json +0 -877
  31. package/dist/drizzle/offers_v1.1/meta/0006_snapshot.json +0 -884
  32. package/dist/drizzle/offers_v1.1/meta/_journal.json +0 -62
@@ -1,159 +1,10 @@
1
1
  import * as _morpho_dev_mempool from '@morpho-dev/mempool';
2
- import { Chain, Offer, Errors, Format, Maturity, LLTV, Compute } from '@morpho-dev/mempool';
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
- callbackAmount: string;
38
- updatedAt: Date;
39
- };
40
- type LiquidityPool = {
41
- id: string;
42
- amount: string;
43
- updatedAt: Date;
44
- };
45
- type LiquidityQueueWithPool = {
46
- queue: LiquidityQueue;
47
- pool: LiquidityPool;
48
- };
49
- type Liquidity = {
50
- userPosition: LiquidityUserPosition;
51
- queues: LiquidityQueueWithPool[];
52
- };
53
- declare function fetch(parameters: {
54
- client: Pick<PublicActions, "multicall">;
55
- chainId: bigint;
56
- spender: Address;
57
- type: CallbackType;
58
- pairs: Array<{
59
- user: Address;
60
- loanToken: Address;
61
- }>;
62
- options?: {
63
- batchSize?: number;
64
- retryAttempts?: number;
65
- retryDelayMs?: number;
66
- blockNumber?: number;
67
- };
68
- }): Promise<Liquidity[]>;
69
- declare function serialize(liquidity: Liquidity): string;
70
-
71
- type Liquidity$1_Liquidity = Liquidity;
72
- type Liquidity$1_LiquidityPool = LiquidityPool;
73
- type Liquidity$1_LiquidityQueue = LiquidityQueue;
74
- type Liquidity$1_LiquidityQueueWithPool = LiquidityQueueWithPool;
75
- type Liquidity$1_LiquidityUserPosition = LiquidityUserPosition;
76
- declare const Liquidity$1_fetch: typeof fetch;
77
- declare const Liquidity$1_fetchBalancesAndAllowances: typeof fetchBalancesAndAllowances;
78
- declare const Liquidity$1_serialize: typeof serialize;
79
- declare namespace Liquidity$1 {
80
- 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 };
81
- }
82
-
83
- declare enum CallbackType {
84
- BuyWithEmptyCallback = "buy_with_empty_callback",
85
- SellWithdrawFromWallet = "sell_withdraw_from_wallet"
86
- }
87
- declare const WhitelistedCallbackAddresses: Record<CallbackType, readonly string[]>;
88
- type BuildLiquidityParameters = {
89
- type: CallbackType.BuyWithEmptyCallback;
90
- user: Address;
91
- loanToken: Address;
92
- chainId: Chain.Id;
93
- amount: bigint;
94
- index?: number;
95
- updatedAt?: Date;
96
- } | {
97
- type: CallbackType.SellWithdrawFromWallet;
98
- user: Address;
99
- termId: string;
100
- chainId: Chain.Id;
101
- amount: bigint;
102
- collaterals: Array<{
103
- collateralAddress: Address;
104
- balance: bigint;
105
- callbackAmount: bigint;
106
- }>;
107
- index?: number;
108
- updatedAt?: Date;
109
- };
110
- declare function buildLiquidity(parameters: BuildLiquidityParameters): Liquidity;
111
- declare function getCallbackIdForOffer(offer: Offer.Offer): string | null;
112
- declare function decode$1(parameters: {
113
- type: CallbackType;
114
- data: Hex;
115
- }): Array<{
116
- collateral: Address;
117
- amount: bigint;
118
- }>;
119
- declare function encode$1(parameters: {
120
- type: CallbackType;
121
- data: {
122
- collaterals: Address[];
123
- amounts: bigint[];
124
- };
125
- }): Hex;
126
-
127
- type Callback_CallbackType = CallbackType;
128
- declare const Callback_CallbackType: typeof CallbackType;
129
- declare const Callback_WhitelistedCallbackAddresses: typeof WhitelistedCallbackAddresses;
130
- declare const Callback_buildLiquidity: typeof buildLiquidity;
131
- declare const Callback_getCallbackIdForOffer: typeof getCallbackIdForOffer;
132
- declare namespace Callback {
133
- 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 };
134
- }
135
-
136
- type Cursor = {
137
- sort: "rate" | "maturity" | "expiry" | "amount";
138
- dir: "asc" | "desc";
139
- rate?: string;
140
- maturity?: number;
141
- expiry?: number;
142
- assets?: string;
143
- hash: string;
144
- };
145
- declare function validate(cursor: unknown): cursor is Cursor;
146
- declare function encode(c: Cursor): string;
147
- declare function decode(token?: string): Cursor | null;
148
-
149
- type Cursor$1_Cursor = Cursor;
150
- declare const Cursor$1_decode: typeof decode;
151
- declare const Cursor$1_encode: typeof encode;
152
- declare const Cursor$1_validate: typeof validate;
153
- declare namespace Cursor$1 {
154
- export { type Cursor$1_Cursor as Cursor, Cursor$1_decode as decode, Cursor$1_encode as encode, Cursor$1_validate as validate };
155
- }
156
-
157
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
158
9
  type OfferStatus = (typeof OfferStatusValues)[number];
159
10
  type OfferMetadata = {
@@ -379,11 +230,11 @@ type MatchParameters = {
379
230
  /** Maximum number of offers to return. Defaults to 20. Maximum is 100. */
380
231
  limit?: number;
381
232
  };
382
- type RouterClientConfig = {
233
+ type RouterApiClientConfig = {
383
234
  readonly url: URL;
384
235
  readonly headers: Headers;
385
236
  };
386
- type Client = Compute<RouterClientConfig & {
237
+ type Client = Compute<RouterApiClientConfig & {
387
238
  get: (parameters: GetParameters) => Promise<{
388
239
  cursor: string | null;
389
240
  offers: OfferResponse[];
@@ -405,7 +256,7 @@ declare namespace connect {
405
256
  * Get offers from the router.
406
257
  * @returns The offers with pagination cursor.
407
258
  */
408
- declare function get(config: RouterClientConfig, parameters: GetParameters): Promise<{
259
+ declare function get(config: RouterApiClientConfig, parameters: GetParameters): Promise<{
409
260
  cursor: string | null;
410
261
  offers: OfferResponse[];
411
262
  }>;
@@ -416,7 +267,7 @@ declare namespace get {
416
267
  * Match offers from the router.
417
268
  * @returns The matched offers with pagination cursor.
418
269
  */
419
- declare function match(config: RouterClientConfig, parameters: MatchParameters): Promise<{
270
+ declare function match(config: RouterApiClientConfig, parameters: MatchParameters): Promise<{
420
271
  cursor: string | null;
421
272
  offers: OfferResponse[];
422
273
  }>;
@@ -460,12 +311,164 @@ declare const Client$1_HttpUnauthorizedError: typeof HttpUnauthorizedError;
460
311
  type Client$1_InvalidUrlError = InvalidUrlError;
461
312
  declare const Client$1_InvalidUrlError: typeof InvalidUrlError;
462
313
  type Client$1_MatchParameters = MatchParameters;
463
- type Client$1_RouterClientConfig = RouterClientConfig;
314
+ type Client$1_RouterApiClientConfig = RouterApiClientConfig;
464
315
  declare const Client$1_connect: typeof connect;
465
316
  declare const Client$1_get: typeof get;
466
317
  declare const Client$1_match: typeof match;
467
318
  declare namespace Client$1 {
468
- 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 };
469
472
  }
470
473
 
471
474
  /**
@@ -706,7 +709,31 @@ declare function morpho(): (Rule<{
706
709
  readonly hash: viem.Hex;
707
710
  signature?: viem.Hex;
708
711
  createdAt?: number;
709
- }, "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>)[];
710
737
 
711
738
  type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
712
739
  type ValidationRule_MorphoContext = MorphoContext;
@@ -761,4 +788,4 @@ declare namespace Validation {
761
788
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
762
789
  }
763
790
 
764
- 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 };