@morpho-dev/router 0.1.2 → 0.1.3

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,7 +2,7 @@ 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, PublicClient } from 'viem';
5
+ import { Address, Hex } from 'viem';
6
6
  import { z, ZodError } from 'zod/v4';
7
7
 
8
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
@@ -88,8 +88,8 @@ declare const consumedEvent: {
88
88
  * @param input - The router offer to create.
89
89
  * @returns The created router offer with its hash.
90
90
  */
91
- declare function from$1(input: Omit<RouterOffer, "hash">): RouterOffer;
92
- declare namespace from$1 {
91
+ declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
92
+ declare namespace from {
93
93
  type ErrorType = InvalidRouterOfferError;
94
94
  }
95
95
  /**
@@ -132,12 +132,13 @@ declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
132
132
  type RouterOffer$1_RouterOffer = RouterOffer;
133
133
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
134
134
  declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
135
+ declare const RouterOffer$1_from: typeof from;
135
136
  declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
136
137
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
137
138
  declare const RouterOffer$1_random: typeof random;
138
139
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
139
140
  declare namespace RouterOffer$1 {
140
- 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 };
141
+ 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, RouterOffer$1_from as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
141
142
  }
142
143
 
143
144
  type OfferResponse = {
@@ -433,32 +434,6 @@ declare namespace index$1 {
433
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 };
434
435
  }
435
436
 
436
- declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
437
- type Type = (typeof types)[number];
438
- type BaseEvent<type extends Type = Type> = {
439
- readonly id: string;
440
- readonly type: type;
441
- };
442
- type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
443
- readonly offerConsumed: OfferConsumed;
444
- }> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
445
- readonly offer: Offer.Offer;
446
- }> : never;
447
- /**
448
- * Creates a RouterEvent with a deterministic id.
449
- */
450
- declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
451
- type: T;
452
- }): Compute<RouterEvent<T>>;
453
-
454
- type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
455
- type RouterEvent$1_Type = Type;
456
- declare const RouterEvent$1_from: typeof from;
457
- declare const RouterEvent$1_types: typeof types;
458
- declare namespace RouterEvent$1 {
459
- export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
460
- }
461
-
462
437
  /**
463
438
  * Splits an array into batches of a specified size.
464
439
  * @param array The array to split.
@@ -560,11 +535,9 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
560
535
  */
561
536
  declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
562
537
  type MorphoContext = {
563
- publicClients: Partial<Record<Chain.ChainName, PublicClient>>;
538
+ chain: Chain.Chain;
564
539
  };
565
- declare function morpho(parameters: {
566
- whitelistedChains: Chain.Chain[];
567
- }): (Rule<{
540
+ declare function morpho(): (Rule<{
568
541
  readonly offering: Address;
569
542
  readonly assets: bigint;
570
543
  readonly rate: bigint;
@@ -660,55 +633,7 @@ declare function morpho(parameters: {
660
633
  readonly hash: viem.Hex;
661
634
  signature?: viem.Hex;
662
635
  createdAt?: number;
663
- }, "empty_callback", MorphoContext> | Rule<{
664
- readonly offering: Address;
665
- readonly assets: bigint;
666
- readonly rate: bigint;
667
- readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
668
- readonly expiry: number;
669
- readonly nonce: bigint;
670
- readonly buy: boolean;
671
- readonly chainId: bigint;
672
- readonly loanToken: Address;
673
- readonly start: number;
674
- readonly collaterals: readonly {
675
- asset: Address;
676
- oracle: Address;
677
- lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
678
- }[];
679
- readonly callback: {
680
- readonly address: Address;
681
- readonly data: viem.Hex;
682
- readonly gasLimit: bigint;
683
- };
684
- readonly hash: viem.Hex;
685
- signature?: viem.Hex;
686
- createdAt?: number;
687
- }, "sell_offers_empty_callback", MorphoContext> | Rule<{
688
- readonly offering: Address;
689
- readonly assets: bigint;
690
- readonly rate: bigint;
691
- readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
692
- readonly expiry: number;
693
- readonly nonce: bigint;
694
- readonly buy: boolean;
695
- readonly chainId: bigint;
696
- readonly loanToken: Address;
697
- readonly start: number;
698
- readonly collaterals: readonly {
699
- asset: Address;
700
- oracle: Address;
701
- lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
702
- }[];
703
- readonly callback: {
704
- readonly address: Address;
705
- readonly data: viem.Hex;
706
- readonly gasLimit: bigint;
707
- };
708
- readonly hash: viem.Hex;
709
- signature?: viem.Hex;
710
- createdAt?: number;
711
- }, "buy_offers_empty_callback", MorphoContext>)[];
636
+ }, "empty_callback", MorphoContext>)[];
712
637
 
713
638
  type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
714
639
  type ValidationRule_MorphoContext = MorphoContext;
@@ -763,4 +688,4 @@ declare namespace Validation {
763
688
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
764
689
  }
765
690
 
766
- export { index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
691
+ export { index$1 as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
@@ -2,7 +2,7 @@ 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, PublicClient } from 'viem';
5
+ import { Address, Hex } from 'viem';
6
6
  import { z, ZodError } from 'zod/v4';
7
7
 
8
8
  declare const OfferStatusValues: readonly ["valid", "callback_not_supported", "callback_error", "unverified"];
@@ -88,8 +88,8 @@ declare const consumedEvent: {
88
88
  * @param input - The router offer to create.
89
89
  * @returns The created router offer with its hash.
90
90
  */
91
- declare function from$1(input: Omit<RouterOffer, "hash">): RouterOffer;
92
- declare namespace from$1 {
91
+ declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
92
+ declare namespace from {
93
93
  type ErrorType = InvalidRouterOfferError;
94
94
  }
95
95
  /**
@@ -132,12 +132,13 @@ declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
132
132
  type RouterOffer$1_RouterOffer = RouterOffer;
133
133
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
134
134
  declare const RouterOffer$1_consumedEvent: typeof consumedEvent;
135
+ declare const RouterOffer$1_from: typeof from;
135
136
  declare const RouterOffer$1_fromConsumedLog: typeof fromConsumedLog;
136
137
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
137
138
  declare const RouterOffer$1_random: typeof random;
138
139
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
139
140
  declare namespace RouterOffer$1 {
140
- 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 };
141
+ 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, RouterOffer$1_from as from, RouterOffer$1_fromConsumedLog as fromConsumedLog, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
141
142
  }
142
143
 
143
144
  type OfferResponse = {
@@ -433,32 +434,6 @@ declare namespace index$1 {
433
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 };
434
435
  }
435
436
 
436
- declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
437
- type Type = (typeof types)[number];
438
- type BaseEvent<type extends Type = Type> = {
439
- readonly id: string;
440
- readonly type: type;
441
- };
442
- type RouterEvent<type extends Type = Type> = type extends "offer_consumed" ? Compute<BaseEvent<type> & {
443
- readonly offerConsumed: OfferConsumed;
444
- }> : type extends "offer_created" | "offer_validation" ? Compute<BaseEvent<type> & {
445
- readonly offer: Offer.Offer;
446
- }> : never;
447
- /**
448
- * Creates a RouterEvent with a deterministic id.
449
- */
450
- declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
451
- type: T;
452
- }): Compute<RouterEvent<T>>;
453
-
454
- type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
455
- type RouterEvent$1_Type = Type;
456
- declare const RouterEvent$1_from: typeof from;
457
- declare const RouterEvent$1_types: typeof types;
458
- declare namespace RouterEvent$1 {
459
- export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
460
- }
461
-
462
437
  /**
463
438
  * Splits an array into batches of a specified size.
464
439
  * @param array The array to split.
@@ -560,11 +535,9 @@ declare function single<Name extends string, T, Ctx = void>(name: Name, run: Sin
560
535
  */
561
536
  declare function batch<Name extends string, T, Ctx = void>(name: Name, run: Batch<T, Name, Ctx>): Rule<T, Name, Ctx>;
562
537
  type MorphoContext = {
563
- publicClients: Partial<Record<Chain.ChainName, PublicClient>>;
538
+ chain: Chain.Chain;
564
539
  };
565
- declare function morpho(parameters: {
566
- whitelistedChains: Chain.Chain[];
567
- }): (Rule<{
540
+ declare function morpho(): (Rule<{
568
541
  readonly offering: Address;
569
542
  readonly assets: bigint;
570
543
  readonly rate: bigint;
@@ -660,55 +633,7 @@ declare function morpho(parameters: {
660
633
  readonly hash: viem.Hex;
661
634
  signature?: viem.Hex;
662
635
  createdAt?: number;
663
- }, "empty_callback", MorphoContext> | Rule<{
664
- readonly offering: Address;
665
- readonly assets: bigint;
666
- readonly rate: bigint;
667
- readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
668
- readonly expiry: number;
669
- readonly nonce: bigint;
670
- readonly buy: boolean;
671
- readonly chainId: bigint;
672
- readonly loanToken: Address;
673
- readonly start: number;
674
- readonly collaterals: readonly {
675
- asset: Address;
676
- oracle: Address;
677
- lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
678
- }[];
679
- readonly callback: {
680
- readonly address: Address;
681
- readonly data: viem.Hex;
682
- readonly gasLimit: bigint;
683
- };
684
- readonly hash: viem.Hex;
685
- signature?: viem.Hex;
686
- createdAt?: number;
687
- }, "sell_offers_empty_callback", MorphoContext> | Rule<{
688
- readonly offering: Address;
689
- readonly assets: bigint;
690
- readonly rate: bigint;
691
- readonly maturity: number & _morpho_dev_mempool.Brand<"Maturity">;
692
- readonly expiry: number;
693
- readonly nonce: bigint;
694
- readonly buy: boolean;
695
- readonly chainId: bigint;
696
- readonly loanToken: Address;
697
- readonly start: number;
698
- readonly collaterals: readonly {
699
- asset: Address;
700
- oracle: Address;
701
- lltv: bigint & _morpho_dev_mempool.Brand<"LLTV">;
702
- }[];
703
- readonly callback: {
704
- readonly address: Address;
705
- readonly data: viem.Hex;
706
- readonly gasLimit: bigint;
707
- };
708
- readonly hash: viem.Hex;
709
- signature?: viem.Hex;
710
- createdAt?: number;
711
- }, "buy_offers_empty_callback", MorphoContext>)[];
636
+ }, "empty_callback", MorphoContext>)[];
712
637
 
713
638
  type ValidationRule_Batch<T, RuleName extends string, Ctx = void> = Batch<T, RuleName, Ctx>;
714
639
  type ValidationRule_MorphoContext = MorphoContext;
@@ -763,4 +688,4 @@ declare namespace Validation {
763
688
  export { type Validation_Issue as Issue, type Validation_Result as Result, Validation_run as run };
764
689
  }
765
690
 
766
- export { index$1 as OfferStore, Client$1 as Router, RouterEvent$1 as RouterEvent, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
691
+ export { index$1 as OfferStore, Client$1 as Router, RouterOffer$1 as RouterOffer, index as Utils, Validation, ValidationRule };
@@ -1352,18 +1352,6 @@ function memory(parameters) {
1352
1352
  };
1353
1353
  }
1354
1354
 
1355
- // src/RouterEvent.ts
1356
- var RouterEvent_exports = {};
1357
- __export(RouterEvent_exports, {
1358
- from: () => from2,
1359
- types: () => types
1360
- });
1361
- var types = ["offer_created", "offer_consumed", "offer_validation"];
1362
- function from2(base) {
1363
- const id = base.type === "offer_consumed" ? `${base.type}:${base.offerConsumed.id}` : `${base.type}:${base.offer.hash.toLowerCase()}`;
1364
- return { id, ...base };
1365
- }
1366
-
1367
1355
  // src/Validation.ts
1368
1356
  var Validation_exports = {};
1369
1357
  __export(Validation_exports, {
@@ -1424,25 +1412,19 @@ function single(name, run2) {
1424
1412
  function batch2(name, run2) {
1425
1413
  return { kind: "batch", name, run: run2 };
1426
1414
  }
1427
- function morpho(parameters) {
1428
- const { whitelistedChains } = parameters;
1429
- const whitelistedChainIds = new Set(whitelistedChains.map((chain) => chain.id));
1430
- const whitelistedLoanTokensPerChain = new Map(
1431
- whitelistedChains.map((chain) => [
1432
- chain.id,
1433
- new Set(Array.from(chain.whitelistedAssets).map((a) => a.toLowerCase()))
1434
- ])
1435
- );
1436
- const morphoPerChain = new Map(
1437
- whitelistedChains.map((chain) => [chain.id, chain.morpho.toLowerCase()])
1438
- );
1439
- const chainId = single("chain_id", (offer, _) => {
1440
- if (!whitelistedChainIds.has(offer.chainId)) {
1441
- return { message: `Chain ID ${offer.chainId} is not whitelisted` };
1415
+ function morpho() {
1416
+ const chainId = single("chain_id", (offer, { chain }) => {
1417
+ if (chain.id !== offer.chainId) {
1418
+ return {
1419
+ message: `Chain ID ${offer.chainId} is not the same as the chain ID in the context (${chain.id})`
1420
+ };
1442
1421
  }
1443
1422
  });
1444
- const loanToken = single("loan_token", (offer, _) => {
1445
- if (!whitelistedLoanTokensPerChain.get(offer.chainId)?.has(offer.loanToken.toLowerCase())) {
1423
+ const loanToken = single("loan_token", (offer, { chain }) => {
1424
+ const tokens = new Set(
1425
+ Array.from(chain.whitelistedAssets.values()).map((a) => a.toLowerCase())
1426
+ );
1427
+ if (!tokens.has(offer.loanToken.toLowerCase())) {
1446
1428
  return {
1447
1429
  message: `Loan token ${offer.loanToken} is not whitelisted on chain ${offer.chainId}`
1448
1430
  };
@@ -1453,133 +1435,23 @@ function morpho(parameters) {
1453
1435
  return { message: "Expiry mismatch" };
1454
1436
  }
1455
1437
  });
1456
- const emptyCallback = single("empty_callback", (offer, _) => {
1457
- if (offer.callback.data !== "0x") {
1458
- return { message: "Callback data is not empty. Not supported yet." };
1438
+ const callback = single("empty_callback", (offer, _) => {
1439
+ if (!offer.buy || offer.callback.data !== "0x") {
1440
+ return { message: "Callback not supported yet." };
1459
1441
  }
1460
1442
  });
1461
- const sellOffersEmptyCallback = single(
1462
- "sell_offers_empty_callback",
1463
- (offer, _) => {
1464
- if (!offer.buy && offer.callback.data === "0x") {
1465
- return { message: "Sell offers with empty callback are not supported yet." };
1466
- }
1467
- }
1468
- );
1469
- const buyOffersEmptyCallback = batch2(
1470
- "buy_offers_empty_callback",
1471
- async (offers, { publicClients }) => {
1472
- const issues = /* @__PURE__ */ new Map();
1473
- const hashToIndex = /* @__PURE__ */ new Map();
1474
- for (let i = 0; i < offers.length; i++) {
1475
- const offer = offers[i];
1476
- hashToIndex.set(offer.hash, i);
1477
- }
1478
- const { buyOffers, sellOffers: _sellOffers } = offers.reduce(
1479
- (acc, offer) => {
1480
- offer.buy ? acc.buyOffers.push(offer) : issues.set(hashToIndex.get(offer.hash), {
1481
- message: "Onchain callback for sell offers is not supported yet."
1482
- });
1483
- return acc;
1484
- },
1485
- { buyOffers: [], sellOffers: [] }
1486
- );
1487
- const buyOffersPerLoanAsset = /* @__PURE__ */ new Map();
1488
- for (const offer of buyOffers) {
1489
- const chainName = mempool.Chain.getChain(offer.chainId)?.name;
1490
- const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
1491
- const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
1492
- offers2.push(offer);
1493
- loanTokens.set(offer.loanToken.toLowerCase(), offers2);
1494
- buyOffersPerLoanAsset.set(chainName, loanTokens);
1495
- }
1496
- await Promise.all(
1497
- Array.from(buyOffersPerLoanAsset.entries()).map(async ([name, loanTokens]) => {
1498
- const chainName = name;
1499
- const publicClient = publicClients[chainName];
1500
- const morpho2 = morphoPerChain.get(mempool.Chain.chains[chainName].id);
1501
- if (!publicClient) {
1502
- const offers2 = Array.from(loanTokens.values()).flat();
1503
- for (const offer of offers2) {
1504
- issues.set(hashToIndex.get(offer.hash), {
1505
- message: `Public client for chain "${chainName}" is not available`
1506
- });
1507
- }
1508
- return;
1509
- }
1510
- const balances = /* @__PURE__ */ new Map();
1511
- const allowances = /* @__PURE__ */ new Map();
1512
- for (const [loanToken2, offers2] of loanTokens) {
1513
- const data = await Promise.all(
1514
- offers2.flatMap((offer) => [
1515
- publicClient.readContract({
1516
- address: loanToken2,
1517
- abi: viem.parseAbi([
1518
- "function balanceOf(address owner) view returns (uint256 balance)"
1519
- ]),
1520
- functionName: "balanceOf",
1521
- args: [offer.offering]
1522
- }),
1523
- publicClient.readContract({
1524
- address: loanToken2,
1525
- abi: viem.parseAbi([
1526
- "function allowance(address owner, address spender) public view returns (uint256 remaining)"
1527
- ]),
1528
- functionName: "allowance",
1529
- args: [offer.offering, morpho2]
1530
- })
1531
- ])
1532
- );
1533
- for (let i = 0; i < offers2.length; i++) {
1534
- const user = offers2[i].offering.toLowerCase();
1535
- const balance = data[i * 2] || 0n;
1536
- const allowance = data[i * 2 + 1] || 0n;
1537
- const userBalances = balances.get(user) ?? /* @__PURE__ */ new Map();
1538
- userBalances.set(loanToken2.toLowerCase(), balance);
1539
- const userAllowances = allowances.get(user) ?? /* @__PURE__ */ new Map();
1540
- userAllowances.set(loanToken2.toLowerCase(), allowance);
1541
- balances.set(user, userBalances);
1542
- allowances.set(user, userAllowances);
1543
- }
1544
- }
1545
- for (const offer of Array.from(loanTokens.values()).flat()) {
1546
- const user = offer.offering.toLowerCase();
1547
- const userBalances = balances.get(user);
1548
- const balance = userBalances?.get(offer.loanToken.toLowerCase());
1549
- if (balance < offer.assets) {
1550
- issues.set(hashToIndex.get(offer.hash), {
1551
- message: `Insufficient balance for ${offer.loanToken} on chain ${offer.chainId} (${balance.toString()} < ${offer.assets.toString()})`
1552
- });
1553
- continue;
1554
- }
1555
- const userAllowances = allowances.get(user);
1556
- const allowance = userAllowances?.get(offer.loanToken.toLowerCase());
1557
- if (allowance < offer.assets) {
1558
- issues.set(hashToIndex.get(offer.hash), {
1559
- message: `Insufficient allowance for ${offer.loanToken} on chain ${offer.chainId} (${allowance.toString()} < ${offer.assets.toString()})`
1560
- });
1561
- }
1562
- }
1563
- })
1564
- );
1565
- return issues;
1566
- }
1567
- );
1568
1443
  return [
1569
1444
  chainId,
1570
1445
  loanToken,
1571
1446
  expiry,
1572
- // note: callback onchain check should be done last since it does not mean that the offer is forever invalid
1573
- // integrators should be able to keep the offers that have an invalid callback onchain and be sure that is the only check that is not valid
1574
- emptyCallback,
1575
- sellOffersEmptyCallback,
1576
- buyOffersEmptyCallback
1447
+ // note: callback rule should be the last one, since it does not mean that the offer is forever invalid
1448
+ // integrators should be able to choose if they want to keep the offer or not
1449
+ callback
1577
1450
  ];
1578
1451
  }
1579
1452
 
1580
1453
  exports.OfferStore = OfferStore_exports;
1581
1454
  exports.Router = Client_exports;
1582
- exports.RouterEvent = RouterEvent_exports;
1583
1455
  exports.RouterOffer = RouterOffer_exports;
1584
1456
  exports.Utils = utils_exports;
1585
1457
  exports.Validation = Validation_exports;