@morpho-dev/router 0.0.24 → 0.0.26

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.
@@ -27,6 +27,7 @@ type Chain = Compute<Omit<Chain$2, "id" | "name"> & {
27
27
  name: ChainName;
28
28
  whitelistedAssets: Set<Address>;
29
29
  morpho: Address;
30
+ termsContract: Address;
30
31
  mempool?: {
31
32
  address: Address;
32
33
  deploymentBlock: number;
@@ -78,10 +79,10 @@ declare const schemas: {
78
79
  min_lltv: z.ZodOptional<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, number>>>;
79
80
  max_lltv: z.ZodOptional<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, number>>>;
80
81
  sort_by: z.ZodOptional<z.ZodEnum<{
82
+ amount: "amount";
81
83
  rate: "rate";
82
84
  maturity: "maturity";
83
85
  expiry: "expiry";
84
- amount: "amount";
85
86
  }>>;
86
87
  sort_order: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
87
88
  asc: "asc";
@@ -126,6 +127,13 @@ type RouterOffer = Offer.Offer & {
126
127
  status: OfferStatus;
127
128
  metadata?: OfferMetadata;
128
129
  };
130
+ type OfferConsumed = {
131
+ id: string;
132
+ chainId: bigint;
133
+ offering: Address;
134
+ nonce: bigint;
135
+ amount: bigint;
136
+ };
129
137
  declare const RouterOfferSchema: (parameters?: {
130
138
  omitHash?: boolean;
131
139
  }) => zod_v4.ZodObject<{
@@ -162,6 +170,30 @@ declare const RouterOfferSchema: (parameters?: {
162
170
  issue: z.ZodString;
163
171
  }, z.core.$strip>>;
164
172
  }, zod_v4_core.$strip>;
173
+ /**
174
+ * ABI for the Consumed event emitted by the terms contract.
175
+ */
176
+ declare const consumedEvent: {
177
+ readonly type: "event";
178
+ readonly name: "Consumed";
179
+ readonly inputs: readonly [{
180
+ readonly name: "user";
181
+ readonly type: "address";
182
+ readonly indexed: true;
183
+ readonly internalType: "address";
184
+ }, {
185
+ readonly name: "nonce";
186
+ readonly type: "uint256";
187
+ readonly indexed: true;
188
+ readonly internalType: "uint256";
189
+ }, {
190
+ readonly name: "amount";
191
+ readonly type: "uint256";
192
+ readonly indexed: false;
193
+ readonly internalType: "uint256";
194
+ }];
195
+ readonly anonymous: false;
196
+ };
165
197
  /**
166
198
  * Creates a router offer from a plain object.
167
199
  * @throws {InvalidRouterOfferError} If the router offer is invalid.
@@ -189,6 +221,15 @@ declare namespace fromSnakeCase {
189
221
  */
190
222
  declare function toSnakeCase(offer: RouterOffer): Format.Snake<RouterOffer>;
191
223
  declare function random(): RouterOffer;
224
+ declare function fromConsumedLog(parameters: {
225
+ blockNumber: bigint;
226
+ logIndex: number;
227
+ chainId: number;
228
+ transactionHash: Hex;
229
+ user: Address;
230
+ nonce: bigint;
231
+ amount: bigint;
232
+ }): OfferConsumed;
192
233
  declare class InvalidRouterOfferError extends Errors.BaseError<ZodError | Error> {
193
234
  readonly name = "RouterOffer.InvalidRouterOfferError";
194
235
  constructor(error: ZodError | Error);
@@ -196,16 +237,19 @@ declare class InvalidRouterOfferError extends Errors.BaseError<ZodError | Error>
196
237
 
197
238
  type RouterOffer$1_InvalidRouterOfferError = InvalidRouterOfferError;
198
239
  declare const RouterOffer$1_InvalidRouterOfferError: typeof InvalidRouterOfferError;
240
+ type RouterOffer$1_OfferConsumed = OfferConsumed;
199
241
  type RouterOffer$1_OfferMetadata = OfferMetadata;
200
242
  type RouterOffer$1_OfferStatus = OfferStatus;
201
243
  declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
202
244
  type RouterOffer$1_RouterOffer = RouterOffer;
203
245
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
246
+ declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
247
+ declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
204
248
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
205
249
  declare const RouterOffer$1_random: typeof random;
206
250
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
207
251
  declare namespace RouterOffer$1 {
208
- export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, from$1 as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
252
+ export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent, from$1 as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
209
253
  }
210
254
 
211
255
  type OfferResponse = {
@@ -423,6 +467,7 @@ type OfferStore = {
423
467
  metadata?: OfferMetadata;
424
468
  }) => Promise<void>;
425
469
  updateConsumedAmount: (parameters: {
470
+ id: string;
426
471
  chainId: Offer.Offer["chainId"];
427
472
  offering: Offer.Offer["offering"];
428
473
  nonce: Offer.Offer["nonce"];
@@ -431,13 +476,13 @@ type OfferStore = {
431
476
  /** Persist latest indexing progress for a chain and event type. */
432
477
  saveLatestBlockNumberProcessed: (parameters: {
433
478
  chainId: Offer.Offer["chainId"];
434
- eventType: "offer_created" | "offer_matched";
479
+ eventType: "offer_created" | "offer_consumed";
435
480
  latestBlockNumber: number;
436
481
  }) => Promise<void>;
437
482
  /** Retrieve latest indexing progress for a chain and event type. */
438
483
  getLatestBlockNumberProcessed: (parameters: {
439
484
  chainId: Offer.Offer["chainId"];
440
- eventType: "offer_created" | "offer_matched";
485
+ eventType: "offer_created" | "offer_consumed";
441
486
  }) => Promise<{
442
487
  latestBlockNumber: number;
443
488
  } | null>;
@@ -674,13 +719,15 @@ declare namespace Logger$1 {
674
719
  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 };
675
720
  }
676
721
 
677
- declare const types: readonly ["offer_created", "offer_matched", "offer_validation"];
722
+ declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
678
723
  type Type = (typeof types)[number];
679
724
  type BaseEvent<type extends Type = Type> = {
680
725
  readonly id: string;
681
726
  readonly type: type;
682
727
  };
683
- type RouterEvent<type extends Type = Type> = type extends "offer_created" | "offer_matched" | "offer_validation" ? Compute<BaseEvent<type> & {
728
+ type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
729
+ readonly offerConsumed: OfferConsumed;
730
+ }> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
684
731
  readonly offer: Offer.Offer;
685
732
  }> : never;
686
733
  /**
@@ -27,6 +27,7 @@ type Chain = Compute<Omit<Chain$2, "id" | "name"> & {
27
27
  name: ChainName;
28
28
  whitelistedAssets: Set<Address>;
29
29
  morpho: Address;
30
+ termsContract: Address;
30
31
  mempool?: {
31
32
  address: Address;
32
33
  deploymentBlock: number;
@@ -78,10 +79,10 @@ declare const schemas: {
78
79
  min_lltv: z.ZodOptional<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, number>>>;
79
80
  max_lltv: z.ZodOptional<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, number>>>;
80
81
  sort_by: z.ZodOptional<z.ZodEnum<{
82
+ amount: "amount";
81
83
  rate: "rate";
82
84
  maturity: "maturity";
83
85
  expiry: "expiry";
84
- amount: "amount";
85
86
  }>>;
86
87
  sort_order: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
87
88
  asc: "asc";
@@ -126,6 +127,13 @@ type RouterOffer = Offer.Offer & {
126
127
  status: OfferStatus;
127
128
  metadata?: OfferMetadata;
128
129
  };
130
+ type OfferConsumed = {
131
+ id: string;
132
+ chainId: bigint;
133
+ offering: Address;
134
+ nonce: bigint;
135
+ amount: bigint;
136
+ };
129
137
  declare const RouterOfferSchema: (parameters?: {
130
138
  omitHash?: boolean;
131
139
  }) => zod_v4.ZodObject<{
@@ -162,6 +170,30 @@ declare const RouterOfferSchema: (parameters?: {
162
170
  issue: z.ZodString;
163
171
  }, z.core.$strip>>;
164
172
  }, zod_v4_core.$strip>;
173
+ /**
174
+ * ABI for the Consumed event emitted by the terms contract.
175
+ */
176
+ declare const consumedEvent: {
177
+ readonly type: "event";
178
+ readonly name: "Consumed";
179
+ readonly inputs: readonly [{
180
+ readonly name: "user";
181
+ readonly type: "address";
182
+ readonly indexed: true;
183
+ readonly internalType: "address";
184
+ }, {
185
+ readonly name: "nonce";
186
+ readonly type: "uint256";
187
+ readonly indexed: true;
188
+ readonly internalType: "uint256";
189
+ }, {
190
+ readonly name: "amount";
191
+ readonly type: "uint256";
192
+ readonly indexed: false;
193
+ readonly internalType: "uint256";
194
+ }];
195
+ readonly anonymous: false;
196
+ };
165
197
  /**
166
198
  * Creates a router offer from a plain object.
167
199
  * @throws {InvalidRouterOfferError} If the router offer is invalid.
@@ -189,6 +221,15 @@ declare namespace fromSnakeCase {
189
221
  */
190
222
  declare function toSnakeCase(offer: RouterOffer): Format.Snake<RouterOffer>;
191
223
  declare function random(): RouterOffer;
224
+ declare function fromConsumedLog(parameters: {
225
+ blockNumber: bigint;
226
+ logIndex: number;
227
+ chainId: number;
228
+ transactionHash: Hex;
229
+ user: Address;
230
+ nonce: bigint;
231
+ amount: bigint;
232
+ }): OfferConsumed;
192
233
  declare class InvalidRouterOfferError extends Errors.BaseError<ZodError | Error> {
193
234
  readonly name = "RouterOffer.InvalidRouterOfferError";
194
235
  constructor(error: ZodError | Error);
@@ -196,16 +237,19 @@ declare class InvalidRouterOfferError extends Errors.BaseError<ZodError | Error>
196
237
 
197
238
  type RouterOffer$1_InvalidRouterOfferError = InvalidRouterOfferError;
198
239
  declare const RouterOffer$1_InvalidRouterOfferError: typeof InvalidRouterOfferError;
240
+ type RouterOffer$1_OfferConsumed = OfferConsumed;
199
241
  type RouterOffer$1_OfferMetadata = OfferMetadata;
200
242
  type RouterOffer$1_OfferStatus = OfferStatus;
201
243
  declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
202
244
  type RouterOffer$1_RouterOffer = RouterOffer;
203
245
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
246
+ declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
247
+ declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
204
248
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
205
249
  declare const RouterOffer$1_random: typeof random;
206
250
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
207
251
  declare namespace RouterOffer$1 {
208
- export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, from$1 as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
252
+ export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferConsumed as OfferConsumed, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_consumedEvent as consumedEvent, from$1 as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
209
253
  }
210
254
 
211
255
  type OfferResponse = {
@@ -423,6 +467,7 @@ type OfferStore = {
423
467
  metadata?: OfferMetadata;
424
468
  }) => Promise<void>;
425
469
  updateConsumedAmount: (parameters: {
470
+ id: string;
426
471
  chainId: Offer.Offer["chainId"];
427
472
  offering: Offer.Offer["offering"];
428
473
  nonce: Offer.Offer["nonce"];
@@ -431,13 +476,13 @@ type OfferStore = {
431
476
  /** Persist latest indexing progress for a chain and event type. */
432
477
  saveLatestBlockNumberProcessed: (parameters: {
433
478
  chainId: Offer.Offer["chainId"];
434
- eventType: "offer_created" | "offer_matched";
479
+ eventType: "offer_created" | "offer_consumed";
435
480
  latestBlockNumber: number;
436
481
  }) => Promise<void>;
437
482
  /** Retrieve latest indexing progress for a chain and event type. */
438
483
  getLatestBlockNumberProcessed: (parameters: {
439
484
  chainId: Offer.Offer["chainId"];
440
- eventType: "offer_created" | "offer_matched";
485
+ eventType: "offer_created" | "offer_consumed";
441
486
  }) => Promise<{
442
487
  latestBlockNumber: number;
443
488
  } | null>;
@@ -674,13 +719,15 @@ declare namespace Logger$1 {
674
719
  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 };
675
720
  }
676
721
 
677
- declare const types: readonly ["offer_created", "offer_matched", "offer_validation"];
722
+ declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
678
723
  type Type = (typeof types)[number];
679
724
  type BaseEvent<type extends Type = Type> = {
680
725
  readonly id: string;
681
726
  readonly type: type;
682
727
  };
683
- type RouterEvent<type extends Type = Type> = type extends "offer_created" | "offer_matched" | "offer_validation" ? Compute<BaseEvent<type> & {
728
+ type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
729
+ readonly offerConsumed: OfferConsumed;
730
+ }> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
684
731
  readonly offer: Offer.Offer;
685
732
  }> : never;
686
733
  /**
@@ -29,7 +29,7 @@ var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
29
29
  var ChainId = {
30
30
  ETHEREUM: BigInt(chains$1.mainnet.id),
31
31
  BASE: BigInt(chains$1.base.id),
32
- "ETHEREUM-VIRTUAL-TESTNET": 121212n
32
+ "ETHEREUM-VIRTUAL-TESTNET": 109111114n
33
33
  };
34
34
  var chainIds = new Set(Object.values(ChainId));
35
35
  var chainNameLookup = new Map(Object.entries(ChainId).map(([key, value]) => [value, key]));
@@ -53,7 +53,8 @@ var chains = {
53
53
  // DAI
54
54
  ].map((address) => address.toLowerCase())
55
55
  ),
56
- morpho: "0x0000000000000000000000000000000000000000"
56
+ morpho: "0x0000000000000000000000000000000000000000",
57
+ termsContract: "0x0000000000000000000000000000000000000000"
57
58
  },
58
59
  base: {
59
60
  ...chains$1.base,
@@ -67,11 +68,12 @@ var chains = {
67
68
  // DAI
68
69
  ].map((address) => address.toLowerCase())
69
70
  ),
70
- morpho: "0x0000000000000000000000000000000000000000"
71
+ morpho: "0x0000000000000000000000000000000000000000",
72
+ termsContract: "0x0000000000000000000000000000000000000000"
71
73
  },
72
74
  "ethereum-virtual-testnet": {
73
75
  ...chains$1.mainnet,
74
- id: 121212n,
76
+ id: 109111114n,
75
77
  name: "ethereum-virtual-testnet",
76
78
  whitelistedAssets: new Set(
77
79
  [
@@ -82,9 +84,10 @@ var chains = {
82
84
  ].map((address) => address.toLowerCase())
83
85
  ),
84
86
  morpho: "0x0000000000000000000000000000000000000000",
87
+ termsContract: "0xa85d462ceb11d6f91f003072fdc701b0a1bbd8bd",
85
88
  mempool: {
86
89
  address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
87
- deploymentBlock: 23225668,
90
+ deploymentBlock: 23223727,
88
91
  reindexBuffer: 10
89
92
  }
90
93
  }
@@ -106,7 +109,9 @@ __export(RouterOffer_exports, {
106
109
  InvalidRouterOfferError: () => InvalidRouterOfferError,
107
110
  OfferStatusValues: () => OfferStatusValues,
108
111
  RouterOfferSchema: () => RouterOfferSchema,
112
+ consumedEvent: () => consumedEvent,
109
113
  from: () => from,
114
+ fromConsumedLog: () => fromConsumedLog,
110
115
  fromSnakeCase: () => fromSnakeCase,
111
116
  random: () => random,
112
117
  toSnakeCase: () => toSnakeCase
@@ -124,6 +129,16 @@ var RouterOfferSchema = (parameters) => mempool.Offer.OfferSchema(parameters).ex
124
129
  issue: v4.z.string()
125
130
  }).optional()
126
131
  });
132
+ var consumedEvent = {
133
+ type: "event",
134
+ name: "Consumed",
135
+ inputs: [
136
+ { name: "user", type: "address", indexed: true, internalType: "address" },
137
+ { name: "nonce", type: "uint256", indexed: true, internalType: "uint256" },
138
+ { name: "amount", type: "uint256", indexed: false, internalType: "uint256" }
139
+ ],
140
+ anonymous: false
141
+ };
127
142
  function from(input) {
128
143
  try {
129
144
  const parsedOffer = RouterOfferSchema({ omitHash: true }).parse(input);
@@ -151,6 +166,16 @@ function random() {
151
166
  consumed: 0n
152
167
  });
153
168
  }
169
+ function fromConsumedLog(parameters) {
170
+ const { blockNumber, logIndex, chainId, transactionHash, user, nonce, amount } = parameters;
171
+ return {
172
+ id: `${blockNumber.toString()}-${logIndex.toString()}-${chainId}-${transactionHash}`,
173
+ chainId: BigInt(chainId),
174
+ offering: user,
175
+ nonce,
176
+ amount
177
+ };
178
+ }
154
179
  var InvalidRouterOfferError = class extends mempool.Errors.BaseError {
155
180
  name = "RouterOffer.InvalidRouterOfferError";
156
181
  constructor(error2) {
@@ -1111,6 +1136,7 @@ __export(OfferStore_exports, {
1111
1136
  function memory(parameters) {
1112
1137
  const map = parameters.offers;
1113
1138
  const filled = parameters.filled;
1139
+ const consumedIds = /* @__PURE__ */ new Set();
1114
1140
  const indexingProgress = /* @__PURE__ */ new Map();
1115
1141
  const create = async (parameters2) => {
1116
1142
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
@@ -1444,12 +1470,15 @@ function memory(parameters) {
1444
1470
  });
1445
1471
  },
1446
1472
  updateConsumedAmount: async (parameters2) => {
1473
+ if (consumedIds.has(parameters2.id)) return;
1474
+ consumedIds.add(parameters2.id);
1447
1475
  const chainId = parameters2.chainId;
1448
1476
  const address = parameters2.offering.toLowerCase();
1449
1477
  const nonce = parameters2.nonce;
1450
1478
  const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
1451
1479
  const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
1452
- filledForOffering.set(nonce, parameters2.consumed);
1480
+ const current = filledForOffering.get(nonce) || 0n;
1481
+ filledForOffering.set(nonce, current + parameters2.consumed);
1453
1482
  filledForChain.set(address, filledForOffering);
1454
1483
  filled.set(chainId, filledForChain);
1455
1484
  },
@@ -1689,9 +1718,9 @@ __export(RouterEvent_exports, {
1689
1718
  from: () => from2,
1690
1719
  types: () => types
1691
1720
  });
1692
- var types = ["offer_created", "offer_matched", "offer_validation"];
1721
+ var types = ["offer_created", "offer_consumed", "offer_validation"];
1693
1722
  function from2(base) {
1694
- const id = `${base.type}:${base.offer.hash.toLowerCase()}`;
1723
+ const id = base.type === "offer_consumed" ? `${base.type}:${base.offerConsumed.id}` : `${base.type}:${base.offer.hash.toLowerCase()}`;
1695
1724
  return { id, ...base };
1696
1725
  }
1697
1726