@morpho-dev/router 0.1.1 → 0.1.2

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,47 +1,10 @@
1
1
  import * as _morpho_dev_mempool from '@morpho-dev/mempool';
2
- import { Compute, Offer, Errors, Format, Maturity, LLTV } 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
5
  import { Address, Hex, PublicClient } from 'viem';
6
- import { Chain as Chain$2 } from 'viem/chains';
7
6
  import { z, ZodError } from 'zod/v4';
8
7
 
9
- declare const chainNames: readonly ["ethereum", "base", "ethereum-virtual-testnet"];
10
- type ChainName = (typeof chainNames)[number];
11
- declare const ChainId: {
12
- ETHEREUM: bigint;
13
- BASE: bigint;
14
- "ETHEREUM-VIRTUAL-TESTNET": bigint;
15
- };
16
- type ChainId = (typeof ChainId)[keyof typeof ChainId];
17
- declare const chainIds: Set<bigint>;
18
- type Chain = Compute<Omit<Chain$2, "id" | "name"> & {
19
- id: ChainId;
20
- name: ChainName;
21
- whitelistedAssets: Set<Address>;
22
- morpho: Address;
23
- mempool?: {
24
- address: Address;
25
- deploymentBlock: number;
26
- reindexBuffer: number;
27
- };
28
- }>;
29
- declare function getChain(chainId: ChainId): Chain | undefined;
30
- declare const getWhitelistedChains: () => Chain[];
31
- declare const chains: Record<ChainName, Chain>;
32
-
33
- type Chain$1_Chain = Chain;
34
- type Chain$1_ChainId = ChainId;
35
- type Chain$1_ChainName = ChainName;
36
- declare const Chain$1_chainIds: typeof chainIds;
37
- declare const Chain$1_chainNames: typeof chainNames;
38
- declare const Chain$1_chains: typeof chains;
39
- declare const Chain$1_getChain: typeof getChain;
40
- declare const Chain$1_getWhitelistedChains: typeof getWhitelistedChains;
41
- declare namespace Chain$1 {
42
- export { type Chain$1_Chain as Chain, type Chain$1_ChainId as ChainId, type Chain$1_ChainName as ChainName, Chain$1_chainIds as chainIds, Chain$1_chainNames as chainNames, Chain$1_chains as chains, Chain$1_getChain as getChain, Chain$1_getWhitelistedChains as getWhitelistedChains };
43
- }
44
-
45
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
46
9
  type OfferStatus = (typeof OfferStatusValues)[number];
47
10
  type OfferMetadata = {
@@ -398,19 +361,6 @@ type OfferStore = {
398
361
  nonce: Offer.Offer["nonce"];
399
362
  consumed: bigint;
400
363
  }) => Promise<void>;
401
- /** Persist latest indexing progress for a chain and event type. */
402
- saveLatestBlockNumberProcessed: (parameters: {
403
- chainId: Offer.Offer["chainId"];
404
- eventType: "offer_created" | "offer_consumed";
405
- latestBlockNumber: number;
406
- }) => Promise<void>;
407
- /** Retrieve latest indexing progress for a chain and event type. */
408
- getLatestBlockNumberProcessed: (parameters: {
409
- chainId: Offer.Offer["chainId"];
410
- eventType: "offer_created" | "offer_consumed";
411
- }) => Promise<{
412
- latestBlockNumber: number;
413
- } | null>;
414
364
  };
415
365
  type GetOffersFilters = {
416
366
  creators?: string[];
@@ -471,7 +421,7 @@ declare function memory(parameters: {
471
421
  status: OfferStatus;
472
422
  metadata?: OfferMetadata;
473
423
  }>;
474
- filled: Map<ChainId, Map<Address, Map<bigint, bigint>>>;
424
+ filled: Map<Chain.Id, Map<Address, Map<bigint, bigint>>>;
475
425
  }): OfferStore;
476
426
 
477
427
  type index$1_FindMatchingOffersParams = FindMatchingOffersParams;
@@ -610,10 +560,10 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
610
560
  */
611
561
  declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
612
562
  type MorphoContext = {
613
- publicClients: Partial<Record<ChainName, PublicClient>>;
563
+ publicClients: Partial<Record<Chain.ChainName, PublicClient>>;
614
564
  };
615
565
  declare function morpho(parameters: {
616
- whitelistedChains: Chain[];
566
+ whitelistedChains: Chain.Chain[];
617
567
  }): (Rule<{
618
568
  readonly offering: Address;
619
569
  readonly assets: bigint;
@@ -813,4 +763,4 @@ declare namespace Validation {
813
763
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
814
764
  }
815
765
 
816
- export { Chain$1 as Chain, index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
766
+ export { index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
@@ -1,47 +1,10 @@
1
1
  import * as _morpho_dev_mempool from '@morpho-dev/mempool';
2
- import { Compute, Offer, Errors, Format, Maturity, LLTV } 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
5
  import { Address, Hex, PublicClient } from 'viem';
6
- import { Chain as Chain$2 } from 'viem/chains';
7
6
  import { z, ZodError } from 'zod/v4';
8
7
 
9
- declare const chainNames: readonly ["ethereum", "base", "ethereum-virtual-testnet"];
10
- type ChainName = (typeof chainNames)[number];
11
- declare const ChainId: {
12
- ETHEREUM: bigint;
13
- BASE: bigint;
14
- "ETHEREUM-VIRTUAL-TESTNET": bigint;
15
- };
16
- type ChainId = (typeof ChainId)[keyof typeof ChainId];
17
- declare const chainIds: Set<bigint>;
18
- type Chain = Compute<Omit<Chain$2, "id" | "name"> & {
19
- id: ChainId;
20
- name: ChainName;
21
- whitelistedAssets: Set<Address>;
22
- morpho: Address;
23
- mempool?: {
24
- address: Address;
25
- deploymentBlock: number;
26
- reindexBuffer: number;
27
- };
28
- }>;
29
- declare function getChain(chainId: ChainId): Chain | undefined;
30
- declare const getWhitelistedChains: () => Chain[];
31
- declare const chains: Record<ChainName, Chain>;
32
-
33
- type Chain$1_Chain = Chain;
34
- type Chain$1_ChainId = ChainId;
35
- type Chain$1_ChainName = ChainName;
36
- declare const Chain$1_chainIds: typeof chainIds;
37
- declare const Chain$1_chainNames: typeof chainNames;
38
- declare const Chain$1_chains: typeof chains;
39
- declare const Chain$1_getChain: typeof getChain;
40
- declare const Chain$1_getWhitelistedChains: typeof getWhitelistedChains;
41
- declare namespace Chain$1 {
42
- export { type Chain$1_Chain as Chain, type Chain$1_ChainId as ChainId, type Chain$1_ChainName as ChainName, Chain$1_chainIds as chainIds, Chain$1_chainNames as chainNames, Chain$1_chains as chains, Chain$1_getChain as getChain, Chain$1_getWhitelistedChains as getWhitelistedChains };
43
- }
44
-
45
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
46
9
  type OfferStatus = (typeof OfferStatusValues)[number];
47
10
  type OfferMetadata = {
@@ -398,19 +361,6 @@ type OfferStore = {
398
361
  nonce: Offer.Offer["nonce"];
399
362
  consumed: bigint;
400
363
  }) => Promise<void>;
401
- /** Persist latest indexing progress for a chain and event type. */
402
- saveLatestBlockNumberProcessed: (parameters: {
403
- chainId: Offer.Offer["chainId"];
404
- eventType: "offer_created" | "offer_consumed";
405
- latestBlockNumber: number;
406
- }) => Promise<void>;
407
- /** Retrieve latest indexing progress for a chain and event type. */
408
- getLatestBlockNumberProcessed: (parameters: {
409
- chainId: Offer.Offer["chainId"];
410
- eventType: "offer_created" | "offer_consumed";
411
- }) => Promise<{
412
- latestBlockNumber: number;
413
- } | null>;
414
364
  };
415
365
  type GetOffersFilters = {
416
366
  creators?: string[];
@@ -471,7 +421,7 @@ declare function memory(parameters: {
471
421
  status: OfferStatus;
472
422
  metadata?: OfferMetadata;
473
423
  }>;
474
- filled: Map<ChainId, Map<Address, Map<bigint, bigint>>>;
424
+ filled: Map<Chain.Id, Map<Address, Map<bigint, bigint>>>;
475
425
  }): OfferStore;
476
426
 
477
427
  type index$1_FindMatchingOffersParams = FindMatchingOffersParams;
@@ -610,10 +560,10 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
610
560
  */
611
561
  declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
612
562
  type MorphoContext = {
613
- publicClients: Partial<Record<ChainName, PublicClient>>;
563
+ publicClients: Partial<Record<Chain.ChainName, PublicClient>>;
614
564
  };
615
565
  declare function morpho(parameters: {
616
- whitelistedChains: Chain[];
566
+ whitelistedChains: Chain.Chain[];
617
567
  }): (Rule<{
618
568
  readonly offering: Address;
619
569
  readonly assets: bigint;
@@ -813,4 +763,4 @@ declare namespace Validation {
813
763
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
814
764
  }
815
765
 
816
- export { Chain$1 as Chain, index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
766
+ export { index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var mempool = require('@morpho-dev/mempool');
4
- var chains$1 = require('viem/chains');
5
4
  var viem = require('viem');
6
5
  var v4 = require('zod/v4');
7
6
  var zodOpenapi = require('zod-openapi');
@@ -15,85 +14,6 @@ var __export = (target, all) => {
15
14
  };
16
15
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
17
16
 
18
- // src/Chain.ts
19
- var Chain_exports = {};
20
- __export(Chain_exports, {
21
- ChainId: () => ChainId,
22
- chainIds: () => chainIds,
23
- chainNames: () => chainNames,
24
- chains: () => chains,
25
- getChain: () => getChain,
26
- getWhitelistedChains: () => getWhitelistedChains
27
- });
28
- var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
29
- var ChainId = {
30
- ETHEREUM: BigInt(chains$1.mainnet.id),
31
- BASE: BigInt(chains$1.base.id),
32
- "ETHEREUM-VIRTUAL-TESTNET": 109111114n
33
- };
34
- var chainIds = new Set(Object.values(ChainId));
35
- var chainNameLookup = new Map(Object.entries(ChainId).map(([key, value]) => [value, key]));
36
- function getChain(chainId) {
37
- const chainName = chainNameLookup.get(chainId)?.toLowerCase();
38
- if (!chainName) {
39
- return void 0;
40
- }
41
- return chains[chainName];
42
- }
43
- var getWhitelistedChains = () => {
44
- return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
45
- };
46
- var chains = {
47
- ethereum: {
48
- ...chains$1.mainnet,
49
- id: ChainId.ETHEREUM,
50
- name: "ethereum",
51
- whitelistedAssets: new Set(
52
- [
53
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
54
- // USDC
55
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
56
- // DAI
57
- ].map((address) => address.toLowerCase())
58
- ),
59
- morpho: "0x0000000000000000000000000000000000000000"
60
- },
61
- base: {
62
- ...chains$1.base,
63
- id: ChainId.BASE,
64
- name: "base",
65
- whitelistedAssets: new Set(
66
- [
67
- "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
68
- // USDC
69
- "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"
70
- // DAI
71
- ].map((address) => address.toLowerCase())
72
- ),
73
- morpho: "0x0000000000000000000000000000000000000000"
74
- },
75
- "ethereum-virtual-testnet": {
76
- ...chains$1.mainnet,
77
- id: 109111114n,
78
- name: "ethereum-virtual-testnet",
79
- whitelistedAssets: new Set(
80
- [
81
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
82
- // USDC
83
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
84
- // DAI
85
- ].map((address) => address.toLowerCase())
86
- ),
87
- morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
88
- // @TODO: This is mock Consumed contract, update with Terms once stable
89
- mempool: {
90
- address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
91
- deploymentBlock: 23223727,
92
- reindexBuffer: 10
93
- }
94
- }
95
- };
96
-
97
17
  // src/core/router/Client.ts
98
18
  var Client_exports = {};
99
19
  __export(Client_exports, {
@@ -1081,7 +1001,6 @@ function memory(parameters) {
1081
1001
  const map = parameters.offers;
1082
1002
  const filled = parameters.filled;
1083
1003
  const consumedIds = /* @__PURE__ */ new Set();
1084
- const indexingProgress = /* @__PURE__ */ new Map();
1085
1004
  const create = async (parameters2) => {
1086
1005
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
1087
1006
  map.set(parameters2.offer.hash.toLowerCase(), {
@@ -1152,7 +1071,7 @@ function memory(parameters) {
1152
1071
  let {
1153
1072
  creators,
1154
1073
  side,
1155
- chains: chains2,
1074
+ chains,
1156
1075
  loanTokens,
1157
1076
  status = ["valid"],
1158
1077
  callbackAddresses,
@@ -1223,7 +1142,7 @@ function memory(parameters) {
1223
1142
  offers = offers.filter((o) => o.expiry >= now);
1224
1143
  creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
1225
1144
  side && (offers = offers.filter((o) => o.buy === buy));
1226
- chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
1145
+ chains && (offers = offers.filter((o) => chains.includes(Number(o.chainId))));
1227
1146
  loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
1228
1147
  status && (offers = offers.filter((o) => status.includes(o.status)));
1229
1148
  callbackAddresses && (offers = offers.filter(
@@ -1429,15 +1348,6 @@ function memory(parameters) {
1429
1348
  filledForOffering.set(nonce, current + parameters2.consumed);
1430
1349
  filledForChain.set(address, filledForOffering);
1431
1350
  filled.set(chainId, filledForChain);
1432
- },
1433
- saveLatestBlockNumberProcessed: async (parameters2) => {
1434
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1435
- indexingProgress.set(key, parameters2.latestBlockNumber);
1436
- },
1437
- getLatestBlockNumberProcessed: async (parameters2) => {
1438
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1439
- const value = indexingProgress.get(key);
1440
- return value === void 0 ? null : { latestBlockNumber: value };
1441
1351
  }
1442
1352
  };
1443
1353
  }
@@ -1576,7 +1486,7 @@ function morpho(parameters) {
1576
1486
  );
1577
1487
  const buyOffersPerLoanAsset = /* @__PURE__ */ new Map();
1578
1488
  for (const offer of buyOffers) {
1579
- const chainName = getChain(offer.chainId)?.name;
1489
+ const chainName = mempool.Chain.getChain(offer.chainId)?.name;
1580
1490
  const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
1581
1491
  const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
1582
1492
  offers2.push(offer);
@@ -1587,7 +1497,7 @@ function morpho(parameters) {
1587
1497
  Array.from(buyOffersPerLoanAsset.entries()).map(async ([name, loanTokens]) => {
1588
1498
  const chainName = name;
1589
1499
  const publicClient = publicClients[chainName];
1590
- const morpho2 = morphoPerChain.get(chains[chainName].id);
1500
+ const morpho2 = morphoPerChain.get(mempool.Chain.chains[chainName].id);
1591
1501
  if (!publicClient) {
1592
1502
  const offers2 = Array.from(loanTokens.values()).flat();
1593
1503
  for (const offer of offers2) {
@@ -1667,7 +1577,6 @@ function morpho(parameters) {
1667
1577
  ];
1668
1578
  }
1669
1579
 
1670
- exports.Chain = Chain_exports;
1671
1580
  exports.OfferStore = OfferStore_exports;
1672
1581
  exports.Router = Client_exports;
1673
1582
  exports.RouterEvent = RouterEvent_exports;