@morpho-dev/router 0.0.17 → 0.0.18

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/dist/index.browser.d.cts +129 -2
  2. package/dist/index.browser.d.ts +129 -2
  3. package/dist/index.browser.js +377 -9
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.browser.mjs +377 -5
  6. package/dist/index.browser.mjs.map +1 -1
  7. package/dist/index.node.d.cts +101 -719
  8. package/dist/index.node.d.ts +101 -719
  9. package/dist/index.node.js +735 -1215
  10. package/dist/index.node.js.map +1 -1
  11. package/dist/index.node.mjs +734 -1204
  12. package/dist/index.node.mjs.map +1 -1
  13. package/package.json +3 -12
  14. package/dist/drizzle/0000_add-offers-table.sql +0 -37
  15. package/dist/drizzle/0001_create_offer_status_relation.sql +0 -10
  16. package/dist/drizzle/0002_add_created_at_in_offer_status_relation.sql +0 -3
  17. package/dist/drizzle/0003_add-cursor-indices-to-offers.sql +0 -6
  18. package/dist/drizzle/0004_offer-start.sql +0 -1
  19. package/dist/drizzle/0005_rename-price-token-buy.sql +0 -8
  20. package/dist/drizzle/0006_rename-buy.sql +0 -3
  21. package/dist/drizzle/0007_rename-offering.sql +0 -3
  22. package/dist/drizzle/0008_add-consumed-relation.sql +0 -10
  23. package/dist/drizzle/meta/0000_snapshot.json +0 -344
  24. package/dist/drizzle/meta/0001_snapshot.json +0 -426
  25. package/dist/drizzle/meta/0002_snapshot.json +0 -439
  26. package/dist/drizzle/meta/0003_snapshot.json +0 -553
  27. package/dist/drizzle/meta/0004_snapshot.json +0 -559
  28. package/dist/drizzle/meta/0005_snapshot.json +0 -559
  29. package/dist/drizzle/meta/0006_snapshot.json +0 -559
  30. package/dist/drizzle/meta/0007_snapshot.json +0 -559
  31. package/dist/drizzle/meta/0008_snapshot.json +0 -635
  32. package/dist/drizzle/meta/_journal.json +0 -69
@@ -7,17 +7,8 @@ var zodOpenapi = require('zod-openapi');
7
7
  var viem = require('viem');
8
8
  var nodeServer = require('@hono/node-server');
9
9
  var hono = require('hono');
10
- var drizzle_orm_star = require('drizzle-orm');
11
- var path = require('path');
12
- var pglite = require('@electric-sql/pglite');
13
- var nodePostgres = require('drizzle-orm/node-postgres');
14
- var migrator$1 = require('drizzle-orm/node-postgres/migrator');
15
- var pglite$1 = require('drizzle-orm/pglite');
16
- var migrator = require('drizzle-orm/pglite/migrator');
17
- var pg = require('pg');
18
- var pgCore = require('drizzle-orm/pg-core');
19
- var blueSdkViem = require('@morpho-org/blue-sdk-viem');
20
10
  var fs = require('fs');
11
+ var path = require('path');
21
12
  var nc = require('crypto');
22
13
  var accounts = require('viem/accounts');
23
14
  var utils = require('viem/utils');
@@ -44,9 +35,8 @@ function _interopNamespace(e) {
44
35
  return Object.freeze(n);
45
36
  }
46
37
 
47
- var drizzle_orm_star__namespace = /*#__PURE__*/_interopNamespace(drizzle_orm_star);
48
- var path__default = /*#__PURE__*/_interopDefault(path);
49
38
  var fs__default = /*#__PURE__*/_interopDefault(fs);
39
+ var path__default = /*#__PURE__*/_interopDefault(path);
50
40
  var nc__namespace = /*#__PURE__*/_interopNamespace(nc);
51
41
 
52
42
  var __create = Object.create;
@@ -68,15 +58,14 @@ var __export = (target, all) => {
68
58
  for (var name in all)
69
59
  __defProp(target, name, { get: all[name], enumerable: true });
70
60
  };
71
- var __copyProps = (to, from2, except, desc3) => {
61
+ var __copyProps = (to, from2, except, desc) => {
72
62
  if (from2 && typeof from2 === "object" || typeof from2 === "function") {
73
63
  for (let key of __getOwnPropNames(from2))
74
64
  if (!__hasOwnProp.call(to, key) && key !== except)
75
- __defProp(to, key, { get: () => from2[key], enumerable: !(desc3 = __getOwnPropDesc(from2, key)) || desc3.enumerable });
65
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
76
66
  }
77
67
  return to;
78
68
  };
79
- var __reExport = (target, mod5, secondTarget) => (__copyProps(target, mod5, "default"), secondTarget);
80
69
  var __toESM = (mod5, isNodeMode, target) => (target = mod5 != null ? __create(__getProtoOf(mod5)) : {}, __copyProps(
81
70
  // If the importer is in node compatibility mode or this is not an ESM
82
71
  // file that has been converted to a CommonJS file using a Babel-
@@ -410,18 +399,18 @@ var require_common = __commonJS({
410
399
  if (typeof args[0] !== "string") {
411
400
  args.unshift("%O");
412
401
  }
413
- let index2 = 0;
402
+ let index = 0;
414
403
  args[0] = args[0].replace(/%([a-zA-Z%])/g, (match2, format) => {
415
404
  if (match2 === "%%") {
416
405
  return "%";
417
406
  }
418
- index2++;
407
+ index++;
419
408
  const formatter = createDebug.formatters[format];
420
409
  if (typeof formatter === "function") {
421
- const val = args[index2];
410
+ const val = args[index];
422
411
  match2 = formatter.call(self2, val);
423
- args.splice(index2, 1);
424
- index2--;
412
+ args.splice(index, 1);
413
+ index--;
425
414
  }
426
415
  return match2;
427
416
  });
@@ -656,15 +645,15 @@ var require_browser = __commonJS({
656
645
  }
657
646
  const c = "color: " + this.color;
658
647
  args.splice(1, 0, c, "color: inherit");
659
- let index2 = 0;
648
+ let index = 0;
660
649
  let lastC = 0;
661
650
  args[0].replace(/%[a-zA-Z%]/g, (match2) => {
662
651
  if (match2 === "%%") {
663
652
  return;
664
653
  }
665
- index2++;
654
+ index++;
666
655
  if (match2 === "%c") {
667
- lastC = index2;
656
+ lastC = index;
668
657
  }
669
658
  });
670
659
  args.splice(lastC, 0, c);
@@ -1266,8 +1255,8 @@ var require_req = __commonJS({
1266
1255
  if (req.originalUrl) {
1267
1256
  _req.url = req.originalUrl;
1268
1257
  } else {
1269
- const path3 = req.path;
1270
- _req.url = typeof path3 === "string" ? path3 : req.url ? req.url.path || req.url : void 0;
1258
+ const path2 = req.path;
1259
+ _req.url = typeof path2 === "string" ? path2 : req.url ? req.url.path || req.url : void 0;
1271
1260
  }
1272
1261
  if (req.query) {
1273
1262
  _req.query = req.query;
@@ -1450,17 +1439,17 @@ var require_parse = __commonJS({
1450
1439
  const wildcards = [];
1451
1440
  var wcLen = 0;
1452
1441
  const secret = paths2.reduce(function(o, strPath, ix) {
1453
- var path3 = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ""));
1442
+ var path2 = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ""));
1454
1443
  const leadingBracket = strPath[0] === "[";
1455
- path3 = path3.map((p) => {
1444
+ path2 = path2.map((p) => {
1456
1445
  if (p[0] === "[") return p.substr(1, p.length - 2);
1457
1446
  else return p;
1458
1447
  });
1459
- const star = path3.indexOf("*");
1448
+ const star = path2.indexOf("*");
1460
1449
  if (star > -1) {
1461
- const before = path3.slice(0, star);
1450
+ const before = path2.slice(0, star);
1462
1451
  const beforeStr = before.join(".");
1463
- const after = path3.slice(star + 1, path3.length);
1452
+ const after = path2.slice(star + 1, path2.length);
1464
1453
  const nested = after.length > 0;
1465
1454
  wcLen++;
1466
1455
  wildcards.push({
@@ -1471,7 +1460,7 @@ var require_parse = __commonJS({
1471
1460
  });
1472
1461
  } else {
1473
1462
  o[strPath] = {
1474
- path: path3,
1463
+ path: path2,
1475
1464
  val: void 0,
1476
1465
  precensored: false,
1477
1466
  circle: "",
@@ -1516,20 +1505,20 @@ var require_redactor = __commonJS({
1516
1505
  return redact;
1517
1506
  }
1518
1507
  function redactTmpl(secret, isCensorFct, censorFctTakesPath) {
1519
- return Object.keys(secret).map((path3) => {
1520
- const { escPath, leadingBracket, path: arrPath } = secret[path3];
1508
+ return Object.keys(secret).map((path2) => {
1509
+ const { escPath, leadingBracket, path: arrPath } = secret[path2];
1521
1510
  const skip = leadingBracket ? 1 : 0;
1522
1511
  const delim = leadingBracket ? "" : ".";
1523
1512
  const hops = [];
1524
1513
  var match2;
1525
- while ((match2 = rx.exec(path3)) !== null) {
1514
+ while ((match2 = rx.exec(path2)) !== null) {
1526
1515
  const [, ix] = match2;
1527
- const { index: index2, input } = match2;
1528
- if (index2 > skip) hops.push(input.substring(0, index2 - (ix ? 0 : 1)));
1516
+ const { index, input } = match2;
1517
+ if (index > skip) hops.push(input.substring(0, index - (ix ? 0 : 1)));
1529
1518
  }
1530
1519
  var existence = hops.map((p) => `o${delim}${p}`).join(" && ");
1531
- if (existence.length === 0) existence += `o${delim}${path3} != null`;
1532
- else existence += ` && o${delim}${path3} != null`;
1520
+ if (existence.length === 0) existence += `o${delim}${path2} != null`;
1521
+ else existence += ` && o${delim}${path2} != null`;
1533
1522
  const circularDetection = `
1534
1523
  switch (true) {
1535
1524
  ${hops.reverse().map((p) => `
@@ -1542,12 +1531,12 @@ var require_redactor = __commonJS({
1542
1531
  const censorArgs = censorFctTakesPath ? `val, ${JSON.stringify(arrPath)}` : `val`;
1543
1532
  return `
1544
1533
  if (${existence}) {
1545
- const val = o${delim}${path3}
1534
+ const val = o${delim}${path2}
1546
1535
  if (val === censor) {
1547
1536
  secret[${escPath}].precensored = true
1548
1537
  } else {
1549
1538
  secret[${escPath}].val = val
1550
- o${delim}${path3} = ${isCensorFct ? `censor(${censorArgs})` : "censor"}
1539
+ o${delim}${path2} = ${isCensorFct ? `censor(${censorArgs})` : "censor"}
1551
1540
  ${circularDetection}
1552
1541
  }
1553
1542
  }
@@ -1598,13 +1587,13 @@ var require_modifiers = __commonJS({
1598
1587
  target[k] = values[i];
1599
1588
  }
1600
1589
  }
1601
- function groupRedact(o, path3, censor, isCensorFct, censorFctTakesPath) {
1602
- const target = get2(o, path3);
1590
+ function groupRedact(o, path2, censor, isCensorFct, censorFctTakesPath) {
1591
+ const target = get2(o, path2);
1603
1592
  if (target == null || typeof target === "string") return { keys: null, values: null, target, flat: true };
1604
1593
  const keys = Object.keys(target);
1605
1594
  const keysLength = keys.length;
1606
- const pathLength = path3.length;
1607
- const pathWithKey = censorFctTakesPath ? [...path3] : void 0;
1595
+ const pathLength = path2.length;
1596
+ const pathWithKey = censorFctTakesPath ? [...path2] : void 0;
1608
1597
  const values = new Array(keysLength);
1609
1598
  for (var i = 0; i < keysLength; i++) {
1610
1599
  const key = keys[i];
@@ -1622,29 +1611,29 @@ var require_modifiers = __commonJS({
1622
1611
  }
1623
1612
  function nestedRestore(instructions) {
1624
1613
  for (let i = 0; i < instructions.length; i++) {
1625
- const { target, path: path3, value } = instructions[i];
1614
+ const { target, path: path2, value } = instructions[i];
1626
1615
  let current = target;
1627
- for (let i2 = path3.length - 1; i2 > 0; i2--) {
1628
- current = current[path3[i2]];
1616
+ for (let i2 = path2.length - 1; i2 > 0; i2--) {
1617
+ current = current[path2[i2]];
1629
1618
  }
1630
- current[path3[0]] = value;
1619
+ current[path2[0]] = value;
1631
1620
  }
1632
1621
  }
1633
- function nestedRedact(store, o, path3, ns, censor, isCensorFct, censorFctTakesPath) {
1634
- const target = get2(o, path3);
1622
+ function nestedRedact(store, o, path2, ns, censor, isCensorFct, censorFctTakesPath) {
1623
+ const target = get2(o, path2);
1635
1624
  if (target == null) return;
1636
1625
  const keys = Object.keys(target);
1637
1626
  const keysLength = keys.length;
1638
1627
  for (var i = 0; i < keysLength; i++) {
1639
1628
  const key = keys[i];
1640
- specialSet(store, target, key, path3, ns, censor, isCensorFct, censorFctTakesPath);
1629
+ specialSet(store, target, key, path2, ns, censor, isCensorFct, censorFctTakesPath);
1641
1630
  }
1642
1631
  return store;
1643
1632
  }
1644
1633
  function has(obj, prop) {
1645
1634
  return obj !== void 0 && obj !== null ? "hasOwn" in Object ? Object.hasOwn(obj, prop) : Object.prototype.hasOwnProperty.call(obj, prop) : false;
1646
1635
  }
1647
- function specialSet(store, o, k, path3, afterPath, censor, isCensorFct, censorFctTakesPath) {
1636
+ function specialSet(store, o, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath) {
1648
1637
  const afterPathLen = afterPath.length;
1649
1638
  const lastPathIndex = afterPathLen - 1;
1650
1639
  const originalKey = k;
@@ -1685,7 +1674,7 @@ var require_modifiers = __commonJS({
1685
1674
  if (consecutive) {
1686
1675
  redactPathCurrent = node(redactPathCurrent, wck, depth);
1687
1676
  level = i;
1688
- ov = iterateNthLevel(wcov, level - 1, k, path3, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, o[originalKey], depth + 1);
1677
+ ov = iterateNthLevel(wcov, level - 1, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, o[originalKey], depth + 1);
1689
1678
  } else {
1690
1679
  if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
1691
1680
  if (kIsWc) {
@@ -1693,7 +1682,7 @@ var require_modifiers = __commonJS({
1693
1682
  } else {
1694
1683
  ov = wcov[k];
1695
1684
  }
1696
- nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path3, originalKey, ...afterPath]) : censor(ov) : censor;
1685
+ nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
1697
1686
  if (kIsWc) {
1698
1687
  const rv = restoreInstr(node(redactPathCurrent, wck, depth), ov, o[originalKey]);
1699
1688
  store.push(rv);
@@ -1715,7 +1704,7 @@ var require_modifiers = __commonJS({
1715
1704
  } else {
1716
1705
  ov = n[k];
1717
1706
  redactPathCurrent = node(redactPathCurrent, k, depth);
1718
- nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path3, originalKey, ...afterPath]) : censor(ov) : censor;
1707
+ nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
1719
1708
  if (has(n, k) && nv === ov || nv === void 0 && censor !== void 0) ; else {
1720
1709
  const rv = restoreInstr(redactPathCurrent, ov, o[originalKey]);
1721
1710
  store.push(rv);
@@ -1735,7 +1724,7 @@ var require_modifiers = __commonJS({
1735
1724
  }
1736
1725
  return n;
1737
1726
  }
1738
- function iterateNthLevel(wcov, level, k, path3, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth) {
1727
+ function iterateNthLevel(wcov, level, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth) {
1739
1728
  if (level === 0) {
1740
1729
  if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
1741
1730
  if (kIsWc) {
@@ -1743,7 +1732,7 @@ var require_modifiers = __commonJS({
1743
1732
  } else {
1744
1733
  ov = wcov[k];
1745
1734
  }
1746
- nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path3, originalKey, ...afterPath]) : censor(ov) : censor;
1735
+ nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
1747
1736
  if (kIsWc) {
1748
1737
  const rv = restoreInstr(redactPathCurrent, ov, parent);
1749
1738
  store.push(rv);
@@ -1760,7 +1749,7 @@ var require_modifiers = __commonJS({
1760
1749
  for (const key in wcov) {
1761
1750
  if (typeof wcov[key] === "object") {
1762
1751
  redactPathCurrent = node(redactPathCurrent, key, depth);
1763
- iterateNthLevel(wcov[key], level - 1, k, path3, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth + 1);
1752
+ iterateNthLevel(wcov[key], level - 1, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth + 1);
1764
1753
  }
1765
1754
  }
1766
1755
  }
@@ -1782,12 +1771,12 @@ var require_modifiers = __commonJS({
1782
1771
  }
1783
1772
  function restoreInstr(node2, value, target) {
1784
1773
  let current = node2;
1785
- const path3 = [];
1774
+ const path2 = [];
1786
1775
  do {
1787
- path3.push(current.key);
1776
+ path2.push(current.key);
1788
1777
  current = current.parent;
1789
1778
  } while (current.parent != null);
1790
- return { path: path3, value, target };
1779
+ return { path: path2, value, target };
1791
1780
  }
1792
1781
  }
1793
1782
  });
@@ -1816,10 +1805,10 @@ var require_restorer = __commonJS({
1816
1805
  };
1817
1806
  }
1818
1807
  function resetTmpl(secret, paths2) {
1819
- return paths2.map((path3) => {
1820
- const { circle, escPath, leadingBracket } = secret[path3];
1808
+ return paths2.map((path2) => {
1809
+ const { circle, escPath, leadingBracket } = secret[path2];
1821
1810
  const delim = leadingBracket ? "" : ".";
1822
- const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${path3} = secret[${escPath}].val`;
1811
+ const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${path2} = secret[${escPath}].val`;
1823
1812
  const clear = `secret[${escPath}].val = undefined`;
1824
1813
  return `
1825
1814
  if (secret[${escPath}].val !== undefined) {
@@ -2021,8 +2010,8 @@ var require_redaction = __commonJS({
2021
2010
  if (o[ns] === null) {
2022
2011
  return o;
2023
2012
  }
2024
- const { index: index2 } = next;
2025
- const nextPath = `${str.substr(index2, str.length - 1)}`;
2013
+ const { index } = next;
2014
+ const nextPath = `${str.substr(index, str.length - 1)}`;
2026
2015
  o[ns] = o[ns] || [];
2027
2016
  if (ns !== wildcardFirstSym && o[ns].length === 0) {
2028
2017
  o[ns].push(...o[wildcardFirstSym] || []);
@@ -2047,8 +2036,8 @@ var require_redaction = __commonJS({
2047
2036
  if (shape[k] === null) {
2048
2037
  o[k] = (value) => topCensor(value, [k]);
2049
2038
  } else {
2050
- const wrappedCensor = typeof censor === "function" ? (value, path3) => {
2051
- return censor(value, [k, ...path3]);
2039
+ const wrappedCensor = typeof censor === "function" ? (value, path2) => {
2040
+ return censor(value, [k, ...path2]);
2052
2041
  } : censor;
2053
2042
  o[k] = fastRedact({
2054
2043
  paths: shape[k],
@@ -2108,8 +2097,8 @@ var require_quick_format_unescaped = __commonJS({
2108
2097
  if (len === 1) return f;
2109
2098
  var objects = new Array(len);
2110
2099
  objects[0] = ss(f);
2111
- for (var index2 = 1; index2 < len; index2++) {
2112
- objects[index2] = ss(args[index2]);
2100
+ for (var index = 1; index < len; index++) {
2101
+ objects[index] = ss(args[index]);
2113
2102
  }
2114
2103
  return objects.join(" ");
2115
2104
  }
@@ -2244,7 +2233,7 @@ var require_sonic_boom = __commonJS({
2244
2233
  var fs2 = __require("fs");
2245
2234
  var EventEmitter2 = __require("events");
2246
2235
  var inherits = __require("util").inherits;
2247
- var path3 = __require("path");
2236
+ var path2 = __require("path");
2248
2237
  var sleep = require_atomic_sleep();
2249
2238
  var assert2 = __require("assert");
2250
2239
  var BUSY_WRITE_TIMEOUT = 100;
@@ -2298,7 +2287,7 @@ var require_sonic_boom = __commonJS({
2298
2287
  const mode2 = sonic.mode;
2299
2288
  if (sonic.sync) {
2300
2289
  try {
2301
- if (sonic.mkdir) fs2.mkdirSync(path3.dirname(file), { recursive: true });
2290
+ if (sonic.mkdir) fs2.mkdirSync(path2.dirname(file), { recursive: true });
2302
2291
  const fd = fs2.openSync(file, flags, mode2);
2303
2292
  fileOpened(null, fd);
2304
2293
  } catch (err) {
@@ -2306,7 +2295,7 @@ var require_sonic_boom = __commonJS({
2306
2295
  throw err;
2307
2296
  }
2308
2297
  } else if (sonic.mkdir) {
2309
- fs2.mkdir(path3.dirname(file), { recursive: true }, (err) => {
2298
+ fs2.mkdir(path2.dirname(file), { recursive: true }, (err) => {
2310
2299
  if (err) return fileOpened(err);
2311
2300
  fs2.open(file, flags, mode2, fileOpened);
2312
2301
  });
@@ -2862,8 +2851,8 @@ var require_on_exit_leak_free = __commonJS({
2862
2851
  }
2863
2852
  function clear(ref) {
2864
2853
  for (const event of ["exit", "beforeExit"]) {
2865
- const index2 = refs[event].indexOf(ref);
2866
- refs[event].splice(index2, index2 + 1);
2854
+ const index = refs[event].indexOf(ref);
2855
+ refs[event].splice(index, index + 1);
2867
2856
  uninstall(event);
2868
2857
  }
2869
2858
  }
@@ -2972,9 +2961,9 @@ var require_package = __commonJS({
2972
2961
  var require_wait = __commonJS({
2973
2962
  "../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/wait.js"(exports, module2) {
2974
2963
  var MAX_TIMEOUT = 1e3;
2975
- function wait2(state, index2, expected, timeout, done) {
2964
+ function wait2(state, index, expected, timeout, done) {
2976
2965
  const max = Date.now() + timeout;
2977
- let current = Atomics.load(state, index2);
2966
+ let current = Atomics.load(state, index);
2978
2967
  if (current === expected) {
2979
2968
  done(null, "ok");
2980
2969
  return;
@@ -2986,7 +2975,7 @@ var require_wait = __commonJS({
2986
2975
  } else {
2987
2976
  setTimeout(() => {
2988
2977
  prior = current;
2989
- current = Atomics.load(state, index2);
2978
+ current = Atomics.load(state, index);
2990
2979
  if (current === prior) {
2991
2980
  check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : backoff * 2);
2992
2981
  } else {
@@ -2998,9 +2987,9 @@ var require_wait = __commonJS({
2998
2987
  };
2999
2988
  check(1);
3000
2989
  }
3001
- function waitDiff(state, index2, expected, timeout, done) {
2990
+ function waitDiff(state, index, expected, timeout, done) {
3002
2991
  const max = Date.now() + timeout;
3003
- let current = Atomics.load(state, index2);
2992
+ let current = Atomics.load(state, index);
3004
2993
  if (current !== expected) {
3005
2994
  done(null, "ok");
3006
2995
  return;
@@ -3010,7 +2999,7 @@ var require_wait = __commonJS({
3010
2999
  done(null, "timed-out");
3011
3000
  } else {
3012
3001
  setTimeout(() => {
3013
- current = Atomics.load(state, index2);
3002
+ current = Atomics.load(state, index);
3014
3003
  if (current !== expected) {
3015
3004
  done(null, "ok");
3016
3005
  } else {
@@ -4491,7 +4480,7 @@ var require_safe_stable_stringify = __commonJS({
4491
4480
  }
4492
4481
  }
4493
4482
  const circularValue = getCircularValueOption(options);
4494
- const bigint2 = getBooleanOption(options, "bigint");
4483
+ const bigint = getBooleanOption(options, "bigint");
4495
4484
  const deterministic = getDeterministicOption(options);
4496
4485
  const comparator = typeof deterministic === "function" ? deterministic : void 0;
4497
4486
  const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
@@ -4599,7 +4588,7 @@ ${originalIndentation}`;
4599
4588
  case "undefined":
4600
4589
  return void 0;
4601
4590
  case "bigint":
4602
- if (bigint2) {
4591
+ if (bigint) {
4603
4592
  return String(value);
4604
4593
  }
4605
4594
  // fallthrough
@@ -4690,7 +4679,7 @@ ${originalIndentation}`;
4690
4679
  case "undefined":
4691
4680
  return void 0;
4692
4681
  case "bigint":
4693
- if (bigint2) {
4682
+ if (bigint) {
4694
4683
  return String(value);
4695
4684
  }
4696
4685
  // fallthrough
@@ -4802,7 +4791,7 @@ ${originalIndentation}`;
4802
4791
  case "undefined":
4803
4792
  return void 0;
4804
4793
  case "bigint":
4805
- if (bigint2) {
4794
+ if (bigint) {
4806
4795
  return String(value);
4807
4796
  }
4808
4797
  // fallthrough
@@ -4898,7 +4887,7 @@ ${originalIndentation}`;
4898
4887
  case "undefined":
4899
4888
  return void 0;
4900
4889
  case "bigint":
4901
- if (bigint2) {
4890
+ if (bigint) {
4902
4891
  return String(value);
4903
4892
  }
4904
4893
  // fallthrough
@@ -5182,7 +5171,7 @@ var require_pino = __commonJS({
5182
5171
  redact,
5183
5172
  crlf,
5184
5173
  serializers: serializers2,
5185
- timestamp: timestamp2,
5174
+ timestamp,
5186
5175
  messageKey,
5187
5176
  errorKey,
5188
5177
  nestedKey,
@@ -5232,7 +5221,7 @@ var require_pino = __commonJS({
5232
5221
  chindings = coreChindings(Object.assign({}, base2, { name }));
5233
5222
  }
5234
5223
  }
5235
- const time2 = timestamp2 instanceof Function ? timestamp2 : timestamp2 ? epochTime : nullTime;
5224
+ const time2 = timestamp instanceof Function ? timestamp : timestamp ? epochTime : nullTime;
5236
5225
  const timeSliceIndex = time2().indexOf(":") + 1;
5237
5226
  if (useOnlyCustomLevels && !customLevels) throw Error("customLevels is required if useOnlyCustomLevels is set true");
5238
5227
  if (mixin && typeof mixin !== "function") throw Error(`Unknown mixin type "${typeof mixin}" - expected "function"`);
@@ -7542,9 +7531,9 @@ var require_stream_readable = __commonJS({
7542
7531
  });
7543
7532
  return this;
7544
7533
  }
7545
- var index2 = indexOf(state.pipes, dest);
7546
- if (index2 === -1) return this;
7547
- state.pipes.splice(index2, 1);
7534
+ var index = indexOf(state.pipes, dest);
7535
+ if (index === -1) return this;
7536
+ state.pipes.splice(index, 1);
7548
7537
  state.pipesCount -= 1;
7549
7538
  if (state.pipesCount === 1) state.pipes = state.pipes[0];
7550
7539
  dest.emit("unpipe", this, unpipeInfo);
@@ -8127,32 +8116,6 @@ var require_qheap2 = __commonJS({
8127
8116
  }
8128
8117
  });
8129
8118
 
8130
- // src/index.node.ts
8131
- var index_node_exports = {};
8132
- __export(index_node_exports, {
8133
- ApiSchema: () => apiSchema_exports,
8134
- Chain: () => Chain_exports,
8135
- EVM: () => EVM_exports,
8136
- Logger: () => Logger_exports,
8137
- OfferDB: () => OfferDB_exports,
8138
- OfferRepository: () => OfferRepository_exports,
8139
- Router: () => core_exports,
8140
- RouterEvent: () => RouterEvent_exports,
8141
- RouterOffer: () => RouterOffer_exports,
8142
- Validation: () => Validation_exports,
8143
- ValidationRule: () => ValidationRule_exports,
8144
- batch: () => batch,
8145
- consumed: () => consumed,
8146
- decodeCursor: () => decodeCursor,
8147
- encodeCursor: () => encodeCursor,
8148
- offerCollaterals: () => offerCollaterals,
8149
- offerStatus: () => offerStatus,
8150
- offers: () => offers,
8151
- poll: () => poll,
8152
- validateCursor: () => validateCursor,
8153
- wait: () => wait
8154
- });
8155
-
8156
8119
  // src/Chain.ts
8157
8120
  var Chain_exports = {};
8158
8121
  __export(Chain_exports, {
@@ -8275,6 +8238,18 @@ var InvalidRouterOfferError = class extends mempool.Errors.BaseError {
8275
8238
  }
8276
8239
  };
8277
8240
 
8241
+ // src/utils/index.ts
8242
+ var utils_exports = {};
8243
+ __export(utils_exports, {
8244
+ batch: () => batch,
8245
+ decodeCursor: () => decodeCursor,
8246
+ encodeCursor: () => encodeCursor,
8247
+ poll: () => poll,
8248
+ retry: () => retry,
8249
+ validateCursor: () => validateCursor,
8250
+ wait: () => wait
8251
+ });
8252
+
8278
8253
  // src/utils/batch.ts
8279
8254
  function* batch(array, batchSize) {
8280
8255
  for (let i = 0; i < array.length; i += batchSize) {
@@ -8385,6 +8360,20 @@ function poll(fn, { interval }) {
8385
8360
  return unwatch;
8386
8361
  }
8387
8362
 
8363
+ // src/utils/retry.ts
8364
+ var retry = async (fn, attempts = 3, delayMs = 50) => {
8365
+ let lastErr;
8366
+ for (let i = 0; i < attempts; i++) {
8367
+ try {
8368
+ return await fn();
8369
+ } catch (err) {
8370
+ lastErr = err;
8371
+ if (i < attempts - 1) await new Promise((r) => setTimeout(r, delayMs));
8372
+ }
8373
+ }
8374
+ throw lastErr;
8375
+ };
8376
+
8388
8377
  // src/core/apiSchema/requests.ts
8389
8378
  var MAX_LIMIT = 100;
8390
8379
  var DEFAULT_LIMIT = 20;
@@ -8861,27 +8850,27 @@ var OpenApi = zodOpenapi.createDocument({
8861
8850
 
8862
8851
  // src/core/apiSchema/utils.ts
8863
8852
  function toResponse(routerOffer) {
8864
- const { consumed: consumed2, status, metadata, ...offer } = routerOffer;
8853
+ const { consumed, status, metadata, ...offer } = routerOffer;
8865
8854
  return {
8866
8855
  offer,
8867
- consumed: consumed2,
8856
+ consumed,
8868
8857
  status,
8869
8858
  metadata
8870
8859
  };
8871
8860
  }
8872
8861
  function fromResponse(offerResponse) {
8873
- const { offer, consumed: consumed2, status, metadata } = offerResponse;
8862
+ const { offer, consumed, status, metadata } = offerResponse;
8874
8863
  return {
8875
8864
  ...offer,
8876
- consumed: consumed2,
8865
+ consumed,
8877
8866
  status,
8878
8867
  metadata
8879
8868
  };
8880
8869
  }
8881
8870
 
8882
- // src/core/index.ts
8883
- var core_exports = {};
8884
- __export(core_exports, {
8871
+ // src/core/router/index.ts
8872
+ var router_exports = {};
8873
+ __export(router_exports, {
8885
8874
  HttpForbiddenError: () => HttpForbiddenError,
8886
8875
  HttpGetOffersFailedError: () => HttpGetOffersFailedError,
8887
8876
  HttpRateLimitError: () => HttpRateLimitError,
@@ -8991,8 +8980,8 @@ async function get(config, parameters) {
8991
8980
  if (parameters.limit !== void 0) {
8992
8981
  url.searchParams.set("limit", parameters.limit.toString());
8993
8982
  }
8994
- const { cursor: returnedCursor, data: offers2 } = await getApi(config, url);
8995
- const routerOffers = offers2.map(mempool.Format.fromSnakeCase).map(fromResponse);
8983
+ const { cursor: returnedCursor, data: offers } = await getApi(config, url);
8984
+ const routerOffers = offers.map(mempool.Format.fromSnakeCase).map(fromResponse);
8996
8985
  return {
8997
8986
  cursor: returnedCursor,
8998
8987
  offers: routerOffers.map(from).map(toResponse)
@@ -9033,8 +9022,8 @@ async function match(config, parameters) {
9033
9022
  if (parameters.limit !== void 0) {
9034
9023
  url.searchParams.set("limit", parameters.limit.toString());
9035
9024
  }
9036
- const { cursor: returnedCursor, data: offers2 } = await getApi(config, url);
9037
- const routerOffers = offers2.map(mempool.Format.fromSnakeCase).map(fromResponse);
9025
+ const { cursor: returnedCursor, data: offers } = await getApi(config, url);
9026
+ const routerOffers = offers.map(mempool.Format.fromSnakeCase).map(fromResponse);
9038
9027
  return {
9039
9028
  cursor: returnedCursor,
9040
9029
  offers: routerOffers.map(from).map(toResponse)
@@ -9121,558 +9110,217 @@ var HttpGetOffersFailedError = class extends mempool.Errors.BaseError {
9121
9110
  }
9122
9111
  };
9123
9112
 
9124
- // src/OfferDB/index.ts
9125
- var OfferDB_exports2 = {};
9126
- __export(OfferDB_exports2, {
9127
- OfferDB: () => OfferDB_exports,
9128
- OfferRepository: () => OfferRepository_exports,
9129
- consumed: () => consumed,
9130
- offerCollaterals: () => offerCollaterals,
9131
- offerStatus: () => offerStatus,
9132
- offers: () => offers
9133
- });
9134
- __reExport(OfferDB_exports2, drizzle_orm_star__namespace);
9135
-
9136
- // src/OfferDB/OfferDB.ts
9137
- var OfferDB_exports = {};
9138
- __export(OfferDB_exports, {
9139
- applyMigrations: () => applyMigrations,
9140
- applyMigrationsPostgres: () => applyMigrationsPostgres,
9141
- clean: () => clean,
9142
- create: () => create
9113
+ // src/OfferStore/index.ts
9114
+ var OfferStore_exports = {};
9115
+ __export(OfferStore_exports, {
9116
+ memory: () => memory
9143
9117
  });
9144
-
9145
- // src/OfferDB/schema.ts
9146
- var schema_exports = {};
9147
- __export(schema_exports, {
9148
- consumed: () => consumed,
9149
- offerCollaterals: () => offerCollaterals,
9150
- offerStatus: () => offerStatus,
9151
- offers: () => offers
9152
- });
9153
- var offers = pgCore.pgTable(
9154
- "offers",
9155
- {
9156
- hash: pgCore.varchar("hash", { length: 66 }).primaryKey(),
9157
- offering: pgCore.varchar("offering", { length: 42 }).notNull(),
9158
- assets: pgCore.bigint("assets", { mode: "bigint" }).notNull(),
9159
- rate: pgCore.bigint("rate", { mode: "bigint" }).notNull(),
9160
- maturity: pgCore.integer("maturity").notNull(),
9161
- expiry: pgCore.integer("expiry").notNull(),
9162
- start: pgCore.integer("start").notNull(),
9163
- nonce: pgCore.bigint("nonce", { mode: "bigint" }).notNull(),
9164
- buy: pgCore.boolean("buy").notNull(),
9165
- chainId: pgCore.bigint("chain_id", { mode: "bigint" }).notNull(),
9166
- loanToken: pgCore.varchar("loan_token", { length: 42 }).notNull(),
9167
- callbackAddress: pgCore.varchar("callback_address", { length: 42 }).notNull(),
9168
- callbackData: pgCore.text("callback_data").notNull(),
9169
- callbackGasLimit: pgCore.bigint("callback_gas_limit", { mode: "bigint" }).notNull(),
9170
- signature: pgCore.varchar("signature", { length: 132 }),
9171
- createdAt: pgCore.timestamp("created_at").defaultNow().notNull()
9172
- },
9173
- (table) => [
9174
- pgCore.index("offers_offering_idx").on(table.offering),
9175
- pgCore.index("offers_buy_idx").on(table.buy),
9176
- pgCore.index("offers_chain_id_idx").on(table.chainId),
9177
- pgCore.index("offers_loan_token_idx").on(table.loanToken),
9178
- pgCore.index("offers_maturity_idx").on(table.maturity),
9179
- pgCore.index("offers_expiry_idx").on(table.expiry),
9180
- pgCore.index("offers_rate_idx").on(table.rate),
9181
- pgCore.index("offers_assets_idx").on(table.assets),
9182
- // Compound indices for cursor pagination with hash
9183
- pgCore.index("offers_rate_hash_idx").on(table.rate, table.hash),
9184
- pgCore.index("offers_maturity_hash_idx").on(table.maturity, table.hash),
9185
- pgCore.index("offers_expiry_hash_idx").on(table.expiry, table.hash),
9186
- pgCore.index("offers_assets_hash_idx").on(table.assets, table.hash)
9187
- ]
9188
- );
9189
- var offerCollaterals = pgCore.pgTable(
9190
- "offer_collaterals",
9191
- {
9192
- id: pgCore.serial("id").primaryKey(),
9193
- offerHash: pgCore.varchar("offer_hash", { length: 66 }).notNull().references(() => offers.hash, { onDelete: "cascade" }),
9194
- asset: pgCore.varchar("asset", { length: 42 }).notNull(),
9195
- oracle: pgCore.varchar("oracle", { length: 42 }).notNull(),
9196
- lltv: pgCore.bigint("lltv", { mode: "bigint" }).notNull()
9197
- },
9198
- (table) => [
9199
- pgCore.index("offer_collaterals_offer_hash_idx").on(table.offerHash),
9200
- pgCore.index("offer_collaterals_asset_idx").on(table.asset),
9201
- pgCore.index("offer_collaterals_oracle_idx").on(table.oracle),
9202
- // Composite index
9203
- pgCore.index("offer_collaterals_tuple_idx").on(table.asset, table.oracle, table.lltv)
9204
- ]
9205
- );
9206
- var offerStatus = pgCore.pgTable(
9207
- "offer_status",
9208
- {
9209
- id: pgCore.serial("id").primaryKey(),
9210
- offerHash: pgCore.varchar("offer_hash", { length: 66 }).notNull().references(() => offers.hash, { onDelete: "cascade" }),
9211
- status: pgCore.text("status").$type().notNull(),
9212
- metadata: pgCore.jsonb("metadata"),
9213
- createdAt: pgCore.timestamp("created_at").defaultNow().notNull()
9214
- },
9215
- (table) => [
9216
- pgCore.index("offer_status_offer_hash_created_at_idx").on(table.offerHash, drizzle_orm_star.desc(table.createdAt)),
9217
- pgCore.index("offer_status_status_idx").on(table.status)
9218
- ]
9219
- );
9220
- var consumed = pgCore.pgTable(
9221
- "consumed_per_user_and_nonce",
9222
- {
9223
- id: pgCore.serial("id").primaryKey(),
9224
- chainId: pgCore.bigint("chain_id", { mode: "bigint" }).notNull(),
9225
- offering: pgCore.varchar("offering", { length: 42 }).notNull(),
9226
- nonce: pgCore.bigint("nonce", { mode: "bigint" }).notNull(),
9227
- consumed: pgCore.bigint("consumed", { mode: "bigint" }).notNull(),
9228
- createdAt: pgCore.timestamp("created_at").defaultNow().notNull()
9229
- },
9230
- (table) => [
9231
- pgCore.index("consumed_per_user_and_nonce_chain_id_offering_nonce_created_at_idx").on(
9232
- table.chainId,
9233
- table.offering,
9234
- table.nonce,
9235
- drizzle_orm_star.desc(table.createdAt)
9236
- )
9237
- ]
9238
- );
9239
-
9240
- // src/OfferDB/OfferDB.ts
9241
- function create({
9242
- type = "pg",
9243
- endpoint
9244
- }) {
9245
- if (type === "pg") {
9246
- if (!endpoint) {
9247
- throw new Error("endpoint is required with pg database");
9118
+ function memory(parameters) {
9119
+ const map = parameters.offers;
9120
+ const filled = parameters.filled;
9121
+ const create = async (parameters2) => {
9122
+ if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
9123
+ map.set(parameters2.offer.hash.toLowerCase(), {
9124
+ ...parameters2.offer,
9125
+ status: parameters2.status,
9126
+ metadata: parameters2.metadata
9127
+ });
9128
+ const chainId = parameters2.offer.chainId;
9129
+ const address = parameters2.offer.offering.toLowerCase();
9130
+ const nonce = parameters2.offer.nonce;
9131
+ const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
9132
+ const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
9133
+ if (!filledForOffering.has(nonce)) filledForOffering.set(nonce, 0n);
9134
+ filledForChain.set(address, filledForOffering);
9135
+ filled.set(chainId, filledForChain);
9136
+ return Promise.resolve(parameters2.offer.hash);
9137
+ };
9138
+ const sort = (sortBy, sortOrder, a, b) => {
9139
+ sortBy = sortBy || "expiry";
9140
+ sortOrder = sortOrder || "desc";
9141
+ const sortKey = sortBy === "amount" ? "assets" : sortBy;
9142
+ if (a[sortKey] === b[sortKey]) {
9143
+ if (a.hash === b.hash) return 0;
9144
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : b.hash > a.hash ? 1 : -1;
9145
+ }
9146
+ switch (sortBy) {
9147
+ case "rate":
9148
+ if (a.rate === b.rate) {
9149
+ if (a.hash === b.hash) return 0;
9150
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
9151
+ }
9152
+ return sortOrder === "asc" ? a.rate > b.rate ? 1 : -1 : b.rate > a.rate ? 1 : -1;
9153
+ case "maturity":
9154
+ if (a.maturity === b.maturity) {
9155
+ if (a.hash === b.hash) return 0;
9156
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
9157
+ }
9158
+ return sortOrder === "asc" ? a.maturity > b.maturity ? 1 : -1 : b.maturity > a.maturity ? 1 : -1;
9159
+ case "expiry":
9160
+ if (a.expiry === b.expiry) {
9161
+ if (a.hash === b.hash) return 0;
9162
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
9163
+ }
9164
+ return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
9165
+ case "amount":
9166
+ if (a.assets === b.assets) {
9167
+ if (a.hash === b.hash) return 0;
9168
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
9169
+ }
9170
+ return sortOrder === "asc" ? a.assets > b.assets ? 1 : -1 : b.assets > a.assets ? 1 : -1;
9171
+ default:
9172
+ if (a.expiry === b.expiry) {
9173
+ if (a.hash === b.hash) return 0;
9174
+ return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
9175
+ }
9176
+ return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
9248
9177
  }
9249
- const pool2 = new pg.Pool({ connectionString: endpoint });
9250
- const client2 = nodePostgres.drizzle(pool2, { schema: schema_exports });
9251
- return Object.assign(client2, { name: "pg", pool: pool2 });
9252
- }
9253
- const pool = new pglite.PGlite();
9254
- const client = pglite$1.drizzle(pool, { schema: schema_exports });
9255
- return Object.assign(client, { name: "pglite", pool });
9256
- }
9257
- async function applyMigrations(db) {
9258
- if (db.name !== "pglite") {
9259
- throw new Error("Migrations can only be applied to PGLite database");
9260
- }
9261
- const filePath = path__default.default.join(__dirname, "drizzle");
9262
- await migrator.migrate(db, { migrationsFolder: filePath });
9263
- }
9264
- async function applyMigrationsPostgres(db) {
9265
- const filePath = process.env.AWS_LAMBDA_FUNCTION_NAME ? path__default.default.join(process.cwd(), "drizzle") : path__default.default.join(__dirname, "drizzle");
9266
- if (db.name !== "pg") {
9267
- throw new Error("Migrations can only be applied to PostgreSQL database");
9268
- }
9269
- await migrator$1.migrate(db, { migrationsFolder: filePath });
9270
- }
9271
- async function clean(db) {
9272
- await db.execute(drizzle_orm_star.sql`drop schema if exists public cascade`);
9273
- await db.execute(drizzle_orm_star.sql`create schema public`);
9274
- await db.execute(drizzle_orm_star.sql`drop schema if exists drizzle cascade`);
9275
- }
9276
-
9277
- // src/OfferDB/repositories/offers/OfferRepository.ts
9278
- var OfferRepository_exports = {};
9279
- __export(OfferRepository_exports, {
9280
- create: () => create2,
9281
- createTest: () => createTest
9282
- });
9283
- function create2(config) {
9284
- const db = config.db;
9178
+ };
9285
9179
  return {
9286
- create: async (parameters) => {
9287
- const { offer, status, metadata = {} } = parameters;
9288
- return await db.transaction(async (tx) => {
9289
- const result = await tx.insert(offers).values({
9290
- hash: offer.hash.toLowerCase(),
9291
- offering: offer.offering.toLowerCase(),
9292
- assets: offer.assets,
9293
- rate: offer.rate,
9294
- maturity: offer.maturity,
9295
- expiry: offer.expiry,
9296
- start: offer.start,
9297
- nonce: offer.nonce,
9298
- buy: offer.buy,
9299
- chainId: offer.chainId,
9300
- loanToken: offer.loanToken.toLowerCase(),
9301
- callbackAddress: offer.callback.address.toLowerCase(),
9302
- callbackData: offer.callback.data,
9303
- callbackGasLimit: offer.callback.gasLimit,
9304
- signature: offer.signature
9305
- }).onConflictDoNothing().returning();
9306
- if (result.length === 0) {
9307
- return offer.hash;
9308
- }
9309
- for (const collateral of offer.collaterals) {
9310
- await tx.insert(offerCollaterals).values({
9311
- offerHash: offer.hash.toLowerCase(),
9312
- asset: collateral.asset.toLowerCase(),
9313
- oracle: collateral.oracle.toLowerCase(),
9314
- lltv: collateral.lltv
9315
- });
9316
- }
9317
- await tx.insert(offerStatus).values({
9318
- offerHash: offer.hash.toLowerCase(),
9319
- status,
9320
- metadata
9321
- });
9322
- const consumedAmountExists = await tx.select().from(consumed).where(
9323
- drizzle_orm_star.and(
9324
- drizzle_orm_star.eq(consumed.offering, offer.offering.toLowerCase()),
9325
- drizzle_orm_star.eq(consumed.nonce, offer.nonce),
9326
- drizzle_orm_star.eq(consumed.chainId, offer.chainId)
9327
- )
9328
- );
9329
- if (consumedAmountExists.length > 0) {
9330
- return offer.hash;
9331
- }
9332
- await tx.insert(consumed).values({
9333
- chainId: offer.chainId,
9334
- offering: offer.offering.toLowerCase(),
9335
- nonce: offer.nonce,
9336
- consumed: 0n
9337
- });
9338
- return offer.hash;
9339
- });
9340
- },
9341
- createMany: async (parameters) => {
9342
- return await db.transaction(async (tx) => {
9343
- const hashes = [];
9344
- for (const { offer, status, metadata } of parameters) {
9345
- const result = await tx.insert(offers).values({
9346
- hash: offer.hash.toLowerCase(),
9347
- offering: offer.offering.toLowerCase(),
9348
- assets: offer.assets,
9349
- rate: offer.rate,
9350
- maturity: offer.maturity,
9351
- expiry: offer.expiry,
9352
- start: offer.start,
9353
- nonce: offer.nonce,
9354
- buy: offer.buy,
9355
- chainId: offer.chainId,
9356
- loanToken: offer.loanToken.toLowerCase(),
9357
- callbackAddress: offer.callback.address.toLowerCase(),
9358
- callbackData: offer.callback.data,
9359
- callbackGasLimit: offer.callback.gasLimit,
9360
- signature: offer.signature
9361
- }).onConflictDoNothing().returning();
9362
- if (result.length === 0) continue;
9363
- for (const collateral of offer.collaterals) {
9364
- await tx.insert(offerCollaterals).values({
9365
- offerHash: offer.hash.toLowerCase(),
9366
- asset: collateral.asset.toLowerCase(),
9367
- oracle: collateral.oracle.toLowerCase(),
9368
- lltv: collateral.lltv
9369
- });
9370
- }
9371
- await tx.insert(offerStatus).values({
9372
- offerHash: offer.hash.toLowerCase(),
9373
- status,
9374
- metadata
9375
- });
9376
- const consumedAmountExists = await tx.select().from(consumed).where(
9377
- drizzle_orm_star.and(
9378
- drizzle_orm_star.eq(consumed.offering, offer.offering.toLowerCase()),
9379
- drizzle_orm_star.eq(consumed.nonce, offer.nonce),
9380
- drizzle_orm_star.eq(consumed.chainId, offer.chainId)
9381
- )
9382
- );
9383
- if (consumedAmountExists.length > 0) {
9384
- hashes.push(offer.hash);
9385
- continue;
9386
- }
9387
- await tx.insert(consumed).values({
9388
- chainId: offer.chainId,
9389
- offering: offer.offering.toLowerCase(),
9390
- nonce: offer.nonce,
9391
- consumed: 0n
9392
- });
9393
- hashes.push(offer.hash);
9394
- }
9395
- return hashes;
9396
- });
9180
+ create,
9181
+ createMany: async (parameters2) => {
9182
+ return Promise.all(
9183
+ parameters2.map((p) => create({ offer: p.offer, status: p.status, metadata: p.metadata }))
9184
+ );
9397
9185
  },
9398
9186
  getAll: async (params) => {
9399
- const { query } = params ?? {};
9400
- const conditions = [];
9401
- if (query?.creators && query.creators.length > 0) {
9402
- conditions.push(drizzle_orm_star.inArray(offers.offering, query.creators));
9403
- }
9404
- if (query?.side) {
9405
- conditions.push(drizzle_orm_star.eq(offers.buy, query.side === "buy"));
9406
- }
9407
- if (query?.chains && query.chains.length > 0) {
9408
- conditions.push(
9409
- drizzle_orm_star.inArray(
9410
- offers.chainId,
9411
- query.chains.map((chain) => BigInt(chain))
9412
- )
9413
- );
9414
- }
9415
- if (query?.loanTokens && query.loanTokens.length > 0) {
9416
- conditions.push(drizzle_orm_star.inArray(offers.loanToken, query.loanTokens));
9417
- }
9418
- if (query?.callbackAddresses && query.callbackAddresses.length > 0) {
9419
- conditions.push(drizzle_orm_star.inArray(offers.callbackAddress, query.callbackAddresses));
9420
- }
9421
- if (query?.minAmount !== void 0) {
9422
- conditions.push(drizzle_orm_star.gte(offers.assets, query.minAmount));
9423
- }
9424
- if (query?.maxAmount !== void 0) {
9425
- conditions.push(drizzle_orm_star.lte(offers.assets, query.maxAmount));
9426
- }
9427
- if (query?.minRate !== void 0) {
9428
- conditions.push(drizzle_orm_star.gte(offers.rate, query.minRate));
9429
- }
9430
- if (query?.maxRate !== void 0) {
9431
- conditions.push(drizzle_orm_star.lte(offers.rate, query.maxRate));
9432
- }
9433
- if (query?.minMaturity !== void 0) {
9434
- conditions.push(drizzle_orm_star.gte(offers.maturity, query.minMaturity));
9435
- }
9436
- if (query?.maxMaturity !== void 0) {
9437
- conditions.push(drizzle_orm_star.lte(offers.maturity, query.maxMaturity));
9438
- }
9439
- if (query?.minExpiry !== void 0) {
9440
- conditions.push(drizzle_orm_star.gte(offers.expiry, query.minExpiry));
9441
- }
9442
- if (query?.maxExpiry !== void 0) {
9443
- conditions.push(drizzle_orm_star.lte(offers.expiry, query.maxExpiry));
9444
- }
9445
- if (query?.collateralAssets && query.collateralAssets.length > 0) {
9446
- conditions.push(drizzle_orm_star.inArray(offerCollaterals.asset, query.collateralAssets));
9447
- }
9448
- if (query?.collateralOracles && query.collateralOracles.length > 0) {
9449
- conditions.push(drizzle_orm_star.inArray(offerCollaterals.oracle, query.collateralOracles));
9450
- }
9451
- if (query?.collateralTuple && query.collateralTuple.length > 0) {
9452
- const tupleClauses = query.collateralTuple.map((tuple) => {
9453
- const parts = [
9454
- drizzle_orm_star.sql`${offerCollaterals.asset} = ${tuple.asset}`
9455
- ];
9456
- if (tuple.oracle) {
9457
- parts.push(drizzle_orm_star.sql`${offerCollaterals.oracle} = ${tuple.oracle}`);
9458
- }
9459
- if (tuple.lltv !== void 0) {
9460
- const lltvInBasisPoints = blueSdkViem.safeParseNumber(tuple.lltv / 100, 18);
9461
- parts.push(drizzle_orm_star.sql`${offerCollaterals.lltv} = ${lltvInBasisPoints}`);
9462
- }
9463
- let clause = parts[0];
9464
- for (let i = 1; i < parts.length; i++) {
9465
- clause = drizzle_orm_star.sql`${clause} AND ${parts[i]}`;
9466
- }
9467
- return drizzle_orm_star.sql`(${clause})`;
9468
- }).filter((c) => c !== void 0);
9469
- if (tupleClauses.length > 0) {
9470
- let combined = tupleClauses[0];
9471
- for (let i = 1; i < tupleClauses.length; i++) {
9472
- combined = drizzle_orm_star.sql`${combined} OR ${tupleClauses[i]}`;
9473
- }
9474
- conditions.push(drizzle_orm_star.sql`(${combined})`);
9187
+ const { query } = params || {};
9188
+ let {
9189
+ creators,
9190
+ side,
9191
+ chains: chains2,
9192
+ loanTokens,
9193
+ status = ["valid"],
9194
+ callbackAddresses,
9195
+ minAmount,
9196
+ maxAmount,
9197
+ minRate,
9198
+ maxRate,
9199
+ minMaturity,
9200
+ maxMaturity,
9201
+ minExpiry,
9202
+ maxExpiry,
9203
+ collateralAssets,
9204
+ collateralOracles,
9205
+ collateralTuple,
9206
+ minLltv,
9207
+ maxLltv,
9208
+ sortBy = "expiry",
9209
+ sortOrder = "desc",
9210
+ cursor: queryCursor,
9211
+ limit = 20
9212
+ } = query || {};
9213
+ const now = mempool.Time.now();
9214
+ const buy = side === "buy";
9215
+ let offers = Array.from(map.values()).map((o) => ({
9216
+ ...o,
9217
+ consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
9218
+ })).filter((o) => o.consumed < o.assets);
9219
+ const cursor = decodeCursor(queryCursor);
9220
+ if (cursor) {
9221
+ if (cursor.sort !== sortBy || cursor.dir !== sortOrder) {
9222
+ throw new Error("Cursor does not match the current sort parameters");
9475
9223
  }
9476
- }
9477
- if (query?.minLltv !== void 0) {
9478
- const minLltvInBasisPoints = blueSdkViem.safeParseNumber(query.minLltv / 100, 18);
9479
- conditions.push(drizzle_orm_star.gte(offerCollaterals.lltv, minLltvInBasisPoints));
9480
- }
9481
- if (query?.maxLltv !== void 0) {
9482
- const maxLltvInBasisPoints = blueSdkViem.safeParseNumber(query.maxLltv / 100, 18);
9483
- conditions.push(drizzle_orm_star.lte(offerCollaterals.lltv, maxLltvInBasisPoints));
9484
- }
9485
- const sortBy = query?.sortBy ?? "expiry";
9486
- const sortOrder = query?.sortOrder ?? "desc";
9487
- const sortColumn = (() => {
9488
- switch (sortBy) {
9224
+ switch (cursor.sort) {
9489
9225
  case "rate":
9490
- return offers.rate;
9226
+ offers = offers.filter(
9227
+ (o) => (sortOrder === "asc" ? o.rate >= BigInt(cursor.rate) : o.rate <= BigInt(cursor.rate)) && (o.rate !== BigInt(cursor.rate) || (sortOrder === "asc" ? o.hash > cursor.hash : o.hash < cursor.hash))
9228
+ );
9229
+ break;
9491
9230
  case "maturity":
9492
- return offers.maturity;
9231
+ offers = offers.filter(
9232
+ (o) => (sortOrder === "asc" ? o.maturity >= BigInt(cursor.maturity) : o.maturity <= BigInt(cursor.maturity)) && (o.maturity !== mempool.Maturity.from(cursor.maturity) || (sortOrder === "asc" ? o.hash > cursor.hash : o.hash < cursor.hash))
9233
+ );
9234
+ break;
9493
9235
  case "expiry":
9494
- return offers.expiry;
9236
+ offers = offers.filter(
9237
+ (o) => (sortOrder === "asc" ? o.expiry >= cursor.expiry : o.expiry <= cursor.expiry) && (o.expiry !== cursor.expiry || (sortOrder === "asc" ? o.hash > cursor.hash : o.hash < cursor.hash))
9238
+ );
9239
+ break;
9495
9240
  case "amount":
9496
- return offers.assets;
9241
+ offers = offers.filter(
9242
+ (o) => (sortOrder === "asc" ? o.assets >= BigInt(cursor.assets) : o.assets <= BigInt(cursor.assets)) && (o.assets !== BigInt(cursor.assets) || (sortOrder === "asc" ? o.hash > cursor.hash : o.hash < cursor.hash))
9243
+ );
9244
+ break;
9497
9245
  default:
9498
- return offers.expiry;
9499
- }
9500
- })();
9501
- const cursor = decodeCursor(query?.cursor);
9502
- if (cursor) {
9503
- if (cursor.sort !== sortBy || cursor.dir !== sortOrder) {
9504
- throw new Error("Cursor does not match the current sort parameters");
9505
- }
9506
- const op = sortOrder === "asc" ? drizzle_orm_star.sql`>` : drizzle_orm_star.sql`<`;
9507
- const cursorVal = (() => {
9508
- switch (sortBy) {
9509
- case "rate":
9510
- return BigInt(cursor.rate);
9511
- case "amount":
9512
- return BigInt(cursor.assets);
9513
- case "maturity":
9514
- return cursor.maturity;
9515
- case "expiry":
9516
- return cursor.expiry;
9517
- default:
9518
- return cursor.expiry;
9519
- }
9520
- })();
9521
- conditions.push(drizzle_orm_star.sql`(${sortColumn}, ${offers.hash}) ${op} (${cursorVal}, ${cursor.hash})`);
9522
- }
9523
- const limit = query?.limit ?? 20;
9524
- const latestStatus = db.select({
9525
- status: offerStatus.status,
9526
- metadata: offerStatus.metadata
9527
- }).from(offerStatus).where(drizzle_orm_star.eq(offerStatus.offerHash, offers.hash)).orderBy(drizzle_orm_star.desc(offerStatus.createdAt)).limit(1).as("latest_status");
9528
- const latestConsumed = db.selectDistinctOn(
9529
- [
9530
- consumed.offering,
9531
- consumed.nonce,
9532
- consumed.chainId,
9533
- consumed.createdAt
9534
- ],
9535
- {
9536
- consumed: consumed.consumed
9537
- }
9538
- ).from(consumed).orderBy(drizzle_orm_star.desc(consumed.createdAt)).limit(1).as("latest_consumed");
9539
- const results = await db.select({
9540
- hash: offers.hash,
9541
- offering: offers.offering,
9542
- assets: offers.assets,
9543
- consumed: latestConsumed.consumed,
9544
- rate: offers.rate,
9545
- maturity: offers.maturity,
9546
- expiry: offers.expiry,
9547
- start: offers.start,
9548
- nonce: offers.nonce,
9549
- buy: offers.buy,
9550
- chainId: offers.chainId,
9551
- loanToken: offers.loanToken,
9552
- callbackAddress: offers.callbackAddress,
9553
- callbackData: offers.callbackData,
9554
- callbackGasLimit: offers.callbackGasLimit,
9555
- signature: offers.signature,
9556
- createdAt: offers.createdAt,
9557
- collateralAsset: offerCollaterals.asset,
9558
- collateralOracle: offerCollaterals.oracle,
9559
- collateralLltv: offerCollaterals.lltv,
9560
- status: latestStatus.status,
9561
- metadata: latestStatus.metadata
9562
- }).from(offers).leftJoin(offerCollaterals, drizzle_orm_star.eq(offers.hash, offerCollaterals.offerHash)).leftJoinLateral(latestStatus, drizzle_orm_star.sql`true`).leftJoinLateral(latestConsumed, drizzle_orm_star.sql`true`).where(
9563
- drizzle_orm_star.and(
9564
- conditions.length > 0 ? drizzle_orm_star.and(...conditions) : drizzle_orm_star.sql`true`,
9565
- query?.status && query.status.length > 0 ? drizzle_orm_star.inArray(latestStatus.status, query.status) : drizzle_orm_star.eq(latestStatus.status, "valid"),
9566
- drizzle_orm_star.sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) > 0`
9246
+ throw new Error("Invalid sort parameter");
9247
+ }
9248
+ offers = offers.filter((o) => o.hash !== cursor.hash);
9249
+ }
9250
+ creators && (creators = creators.map((c) => c.toLowerCase()));
9251
+ loanTokens && (loanTokens = loanTokens.map((lt) => lt.toLowerCase()));
9252
+ collateralAssets && (collateralAssets = collateralAssets.map((ca) => ca.toLowerCase()));
9253
+ collateralOracles && (collateralOracles = collateralOracles.map((co) => co.toLowerCase()));
9254
+ collateralTuple && (collateralTuple = collateralTuple.map((ct) => ({
9255
+ asset: ct.asset.toLowerCase(),
9256
+ oracle: ct.oracle?.toLowerCase()
9257
+ })));
9258
+ offers = offers.filter((o) => o.expiry >= now);
9259
+ creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
9260
+ side && (offers = offers.filter((o) => o.buy === buy));
9261
+ chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
9262
+ loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
9263
+ status && (offers = offers.filter((o) => status.includes(o.status)));
9264
+ callbackAddresses && (offers = offers.filter(
9265
+ (o) => callbackAddresses.includes(o.callback.address.toLowerCase())
9266
+ ));
9267
+ minAmount && (offers = offers.filter((o) => o.assets >= minAmount));
9268
+ maxAmount && (offers = offers.filter((o) => o.assets <= maxAmount));
9269
+ minRate && (offers = offers.filter((o) => o.rate >= minRate));
9270
+ maxRate && (offers = offers.filter((o) => o.rate <= maxRate));
9271
+ minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
9272
+ maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
9273
+ minExpiry && (offers = offers.filter((o) => o.expiry >= minExpiry));
9274
+ maxExpiry && (offers = offers.filter((o) => o.expiry <= maxExpiry));
9275
+ collateralAssets && (offers = offers.filter(
9276
+ (o) => o.collaterals.some((c) => collateralAssets.includes(c.asset.toLowerCase()))
9277
+ ));
9278
+ collateralOracles && (offers = offers.filter(
9279
+ (o) => o.collaterals.some((c) => collateralOracles.includes(c.oracle.toLowerCase()))
9280
+ ));
9281
+ collateralTuple && (offers = offers.filter(
9282
+ (o) => o.collaterals.some(
9283
+ (c) => collateralTuple.some(
9284
+ (ct) => c.asset.toLowerCase() === ct.asset.toLowerCase() && (ct.oracle ? c.oracle.toLowerCase() === ct.oracle.toLowerCase() : true) && (ct.lltv ? c.lltv === mempool.LLTV.from(BigInt(ct.lltv)) : true)
9285
+ )
9567
9286
  )
9568
- ).orderBy(sortOrder === "asc" ? drizzle_orm_star.asc(sortColumn) : drizzle_orm_star.desc(sortColumn)).limit(limit);
9569
- const offerMap = /* @__PURE__ */ new Map();
9570
- for (const row of results) {
9571
- const offer = offerMap.get(row.hash) || {
9572
- hash: row.hash,
9573
- offering: row.offering,
9574
- assets: row.assets,
9575
- consumed: row.consumed || 0n,
9576
- rate: row.rate,
9577
- maturity: row.maturity,
9578
- expiry: row.expiry,
9579
- start: row.start,
9580
- nonce: row.nonce,
9581
- buy: row.buy,
9582
- chainId: row.chainId,
9583
- loanToken: row.loanToken,
9584
- callbackAddress: row.callbackAddress,
9585
- callbackData: row.callbackData,
9586
- callbackGasLimit: row.callbackGasLimit,
9587
- signature: row.signature,
9588
- createdAt: row.createdAt,
9589
- collaterals: [],
9590
- status: row.status,
9591
- metadata: row.metadata
9592
- };
9593
- if (row.collateralAsset && row.collateralOracle && row.collateralLltv) {
9594
- offer.collaterals.push({
9595
- asset: row.collateralAsset,
9596
- oracle: row.collateralOracle,
9597
- lltv: mempool.LLTV.from(row.collateralLltv)
9598
- });
9599
- }
9600
- offerMap.set(row.hash, offer);
9601
- }
9287
+ ));
9288
+ minLltv && (offers = offers.filter(
9289
+ (o) => o.collaterals.every((c) => c.lltv >= mempool.LLTV.from(viem.parseUnits(minLltv.toString(), 16)))
9290
+ ));
9291
+ maxLltv && (offers = offers.filter(
9292
+ (o) => o.collaterals.every((c) => c.lltv <= mempool.LLTV.from(viem.parseUnits(maxLltv.toString(), 16)))
9293
+ ));
9294
+ offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
9602
9295
  let nextCursor = null;
9603
- if (results.length === limit && results.length > 0) {
9604
- const lastRow = results[results.length - 1];
9296
+ if (offers.length > limit) {
9297
+ const last = offers[limit - 1];
9605
9298
  const base2 = {
9606
9299
  sort: sortBy,
9607
9300
  dir: sortOrder,
9608
- hash: lastRow.hash
9301
+ hash: last.hash
9609
9302
  };
9610
9303
  switch (sortBy) {
9611
9304
  case "rate":
9612
- base2.rate = lastRow.rate.toString();
9305
+ base2.rate = last.rate.toString();
9613
9306
  break;
9614
9307
  case "amount":
9615
- base2.assets = lastRow.assets.toString();
9308
+ base2.assets = last.assets.toString();
9616
9309
  break;
9617
9310
  case "maturity":
9618
- base2.maturity = lastRow.maturity;
9311
+ base2.maturity = last.maturity;
9619
9312
  break;
9620
9313
  default:
9621
- base2.expiry = lastRow.expiry;
9314
+ base2.expiry = last.expiry;
9622
9315
  }
9623
9316
  nextCursor = encodeCursor(base2);
9624
9317
  }
9625
- const transformedResults = [];
9626
- for (const offerData of offerMap.values()) {
9627
- const offer = mempool.Offer.from({
9628
- offering: offerData.offering,
9629
- assets: offerData.assets,
9630
- rate: offerData.rate,
9631
- maturity: mempool.Maturity.from(offerData.maturity),
9632
- expiry: offerData.expiry,
9633
- start: offerData.start,
9634
- nonce: offerData.nonce,
9635
- buy: offerData.buy,
9636
- chainId: offerData.chainId,
9637
- loanToken: offerData.loanToken,
9638
- collaterals: offerData.collaterals.map((c) => ({
9639
- asset: c.asset,
9640
- oracle: c.oracle,
9641
- lltv: mempool.LLTV.from(c.lltv)
9642
- })).sort((a, b) => a.asset.toLowerCase().localeCompare(b.asset.toLowerCase())),
9643
- callback: {
9644
- address: offerData.callbackAddress,
9645
- data: offerData.callbackData,
9646
- gasLimit: offerData.callbackGasLimit
9647
- },
9648
- signature: offerData.signature === null ? void 0 : offerData.signature
9649
- });
9650
- transformedResults.push({
9651
- ...offer,
9652
- consumed: offerData.consumed,
9653
- status: offerData.status,
9654
- ...offerData.metadata !== null ? { metadata: offerData.metadata } : {}
9655
- });
9656
- }
9657
- return { offers: transformedResults, nextCursor };
9318
+ offers = offers.slice(0, limit);
9319
+ return {
9320
+ offers,
9321
+ nextCursor
9322
+ };
9658
9323
  },
9659
- /**
9660
- * Returns offers that match specified offer based on the provided parameters.
9661
- *
9662
- * Rules for filtering:
9663
- * - If offer expiry is in the past compared to now, it should not be included
9664
- * - If offer maturity is in the past compared to now, it should not be included
9665
- * - It should return if buyOffer.rate >= sellOffer.rate
9666
- * - It should return if buyOffer.userAddress != sellOffer.userAddress
9667
- * - It should return if maturity matches
9668
- * - It should return if loanToken matches
9669
- * - If the incoming intent is a buy / lend offer, only consider existing sell / borrow offers.
9670
- * - If the incoming intent is a sell / borrow offer, only consider existing buy / lend offers.
9671
- * - When the intent is lend: require offer_collaterals ⊆ intent_collaterals
9672
- * - When the intent is borrow: require intent_collaterals ⊆ offer_collaterals
9673
- * - It should sort by increasing rate if the input offer is a buy/lend offer
9674
- * - It should sort by decreasing rate if the input offer is a sell/borrow offer
9675
- */
9676
9324
  findMatchingOffers: async (params) => {
9677
9325
  const {
9678
9326
  side,
@@ -9685,192 +9333,80 @@ function create2(config) {
9685
9333
  loanToken,
9686
9334
  creator,
9687
9335
  status,
9688
- cursor,
9336
+ cursor: queryCursor,
9689
9337
  limit = 20
9690
9338
  } = params;
9339
+ const now = mempool.Time.now();
9691
9340
  const buy = side !== "buy";
9692
- const now = Math.floor(Date.now() / 1e3);
9693
9341
  const sortOrder = buy ? "asc" : "desc";
9694
- const conditions = [];
9695
- conditions.push(drizzle_orm_star.eq(offers.buy, buy));
9696
- conditions.push(drizzle_orm_star.eq(offers.chainId, BigInt(chainId)));
9697
- conditions.push(drizzle_orm_star.gte(offers.expiry, now));
9698
- conditions.push(drizzle_orm_star.gte(offers.maturity, now));
9699
- if (maturity !== void 0) conditions.push(drizzle_orm_star.eq(offers.maturity, maturity));
9700
- if (minMaturity !== void 0) conditions.push(drizzle_orm_star.gte(offers.maturity, minMaturity));
9701
- if (maxMaturity !== void 0) conditions.push(drizzle_orm_star.lte(offers.maturity, maxMaturity));
9702
- if (loanToken) conditions.push(drizzle_orm_star.eq(offers.loanToken, loanToken.toLowerCase()));
9703
- if (creator) conditions.push(drizzle_orm_star.eq(offers.offering, creator.toLowerCase()));
9704
- if (rate !== void 0) {
9705
- conditions.push(buy ? drizzle_orm_star.gte(offers.rate, rate) : drizzle_orm_star.lte(offers.rate, rate));
9706
- }
9707
- const decoded = decodeCursor(cursor);
9708
- if (decoded) {
9709
- if (decoded.sort !== "rate" || decoded.dir !== sortOrder) {
9342
+ let offers = Array.from(map.values()).map((o) => ({
9343
+ ...o,
9344
+ consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
9345
+ })).filter((o) => o.consumed < o.assets);
9346
+ const cursor = decodeCursor(queryCursor);
9347
+ if (cursor) {
9348
+ if (cursor.sort !== "rate" || cursor.dir !== sortOrder) {
9710
9349
  throw new Error("Cursor does not match the current sort parameters");
9711
9350
  }
9712
- const op = sortOrder === "asc" ? drizzle_orm_star.sql`>` : drizzle_orm_star.sql`<`;
9713
- conditions.push(
9714
- drizzle_orm_star.sql`(${offers.rate}, ${offers.hash}) ${op} (${BigInt(decoded.rate)}, ${decoded.hash})`
9351
+ offers = offers.filter(
9352
+ (o) => sortOrder === "asc" ? o.rate >= BigInt(cursor.rate) : o.rate <= BigInt(cursor.rate)
9715
9353
  );
9716
- }
9717
- if (collaterals.length > 0) {
9718
- const collateralValues = collaterals.map(
9719
- (c) => `('${c.asset.toLowerCase()}', '${c.oracle.toLowerCase()}', ${c.lltv.toString()})`
9720
- ).join(", ");
9721
- const userCollaterals = drizzle_orm_star.sql`(VALUES ${drizzle_orm_star.sql.raw(collateralValues)}) AS uc(asset, oracle, lltv)`;
9722
- const lendPredicate = drizzle_orm_star.sql`
9723
- NOT EXISTS (
9724
- SELECT 1 FROM ${userCollaterals}
9725
- WHERE NOT EXISTS (
9726
- SELECT 1 FROM ${offerCollaterals} oc
9727
- WHERE oc.offer_hash = ${offers.hash}
9728
- AND oc.asset = uc.asset
9729
- AND oc.oracle = uc.oracle
9730
- AND oc.lltv = uc.lltv
9731
- )
9732
- )
9733
- `;
9734
- const borrowPredicate = drizzle_orm_star.sql`
9735
- NOT EXISTS (
9736
- SELECT 1 FROM ${offerCollaterals} oc
9737
- WHERE oc.offer_hash = ${offers.hash}
9738
- AND NOT EXISTS (
9739
- SELECT 1 FROM ${userCollaterals}
9740
- WHERE uc.asset = oc.asset
9741
- AND uc.oracle = oc.oracle
9742
- AND uc.lltv = oc.lltv
9743
- )
9744
- )
9745
- `;
9746
- conditions.push(buy ? lendPredicate : borrowPredicate);
9747
- }
9748
- const latestStatus = db.select({
9749
- status: offerStatus.status,
9750
- metadata: offerStatus.metadata
9751
- }).from(offerStatus).where(drizzle_orm_star.eq(offerStatus.offerHash, offers.hash)).orderBy(drizzle_orm_star.desc(offerStatus.createdAt)).limit(1).as("latest_status");
9752
- const latestConsumed = db.selectDistinctOn(
9753
- [
9754
- consumed.offering,
9755
- consumed.nonce,
9756
- consumed.chainId,
9757
- consumed.createdAt
9758
- ],
9759
- {
9760
- consumed: consumed.consumed
9354
+ offers = offers.filter((o) => o.hash !== cursor.hash);
9355
+ }
9356
+ offers = offers.filter((o) => o.buy === buy);
9357
+ offers = offers.filter((o) => o.chainId === BigInt(chainId));
9358
+ offers = offers.filter((o) => o.expiry >= now);
9359
+ rate && (offers = offers.filter((o) => buy ? o.rate >= rate : o.rate <= rate));
9360
+ collaterals.length > 0 && (offers = offers.filter(
9361
+ (o) => buy ? collaterals.every((c) => {
9362
+ return o.collaterals.some(
9363
+ (oc) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
9364
+ );
9365
+ }) : o.collaterals.every((oc) => {
9366
+ return collaterals.some(
9367
+ (c) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
9368
+ );
9369
+ })
9370
+ ));
9371
+ maturity && (offers = offers.filter((o) => o.maturity === maturity));
9372
+ minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
9373
+ maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
9374
+ loanToken && (offers = offers.filter((o) => o.loanToken.toLowerCase() === loanToken.toLowerCase()));
9375
+ creator && (offers = offers.filter((o) => o.offering.toLowerCase() === creator.toLowerCase()));
9376
+ status && (offers = offers.filter((o) => status.includes(o.status)));
9377
+ const byGroup = /* @__PURE__ */ new Map();
9378
+ for (const offer of offers) {
9379
+ const groupKey = `${offer.chainId}-${offer.offering.toLowerCase()}-${offer.nonce}-${offer.buy}`;
9380
+ const current = byGroup.get(groupKey);
9381
+ if (!current) {
9382
+ byGroup.set(groupKey, offer);
9383
+ continue;
9761
9384
  }
9762
- ).from(consumed).orderBy(drizzle_orm_star.desc(consumed.createdAt)).limit(1).as("latest_consumed");
9763
- const statusCondition = status && status.length > 0 ? drizzle_orm_star.inArray(latestStatus.status, status) : drizzle_orm_star.eq(latestStatus.status, "valid");
9764
- const bestOffers = db.selectDistinctOn(
9765
- // group key
9766
- [offers.offering, offers.nonce, offers.buy],
9767
- {
9768
- hash: offers.hash,
9769
- offering: offers.offering,
9770
- assets: offers.assets,
9771
- consumed: latestConsumed.consumed,
9772
- rate: offers.rate,
9773
- maturity: offers.maturity,
9774
- expiry: offers.expiry,
9775
- start: offers.start,
9776
- nonce: offers.nonce,
9777
- buy: offers.buy,
9778
- chainId: offers.chainId,
9779
- loanToken: offers.loanToken,
9780
- callbackAddress: offers.callbackAddress,
9781
- callbackData: offers.callbackData,
9782
- callbackGasLimit: offers.callbackGasLimit,
9783
- signature: offers.signature,
9784
- status: latestStatus.status,
9785
- metadata: latestStatus.metadata
9786
- }
9787
- ).from(offers).leftJoinLateral(latestStatus, drizzle_orm_star.sql`true`).leftJoinLateral(latestConsumed, drizzle_orm_star.sql`true`).where(
9788
- drizzle_orm_star.and(
9789
- drizzle_orm_star.and(...conditions),
9790
- statusCondition,
9791
- drizzle_orm_star.sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) > 0`
9792
- )
9793
- ).orderBy(
9794
- offers.offering,
9795
- offers.nonce,
9796
- offers.buy,
9797
- // 1 price (direction depends on side)
9798
- drizzle_orm_star.sql`CASE WHEN ${offers.buy} THEN ${offers.rate} ELSE -${offers.rate} END`,
9799
- // 2 size (remaining)
9800
- drizzle_orm_star.sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) DESC`,
9801
- // 3 term (longer maturity)
9802
- drizzle_orm_star.desc(offers.maturity)
9803
- ).as("best_offers");
9804
- const rows = await db.select({
9805
- hash: bestOffers.hash,
9806
- offering: bestOffers.offering,
9807
- assets: bestOffers.assets,
9808
- consumed: bestOffers.consumed,
9809
- rate: bestOffers.rate,
9810
- maturity: bestOffers.maturity,
9811
- expiry: bestOffers.expiry,
9812
- start: bestOffers.start,
9813
- nonce: bestOffers.nonce,
9814
- buy: bestOffers.buy,
9815
- chainId: bestOffers.chainId,
9816
- loanToken: bestOffers.loanToken,
9817
- callbackAddress: bestOffers.callbackAddress,
9818
- callbackData: bestOffers.callbackData,
9819
- callbackGasLimit: bestOffers.callbackGasLimit,
9820
- signature: bestOffers.signature,
9821
- status: bestOffers.status,
9822
- metadata: bestOffers.metadata,
9823
- collateralAsset: offerCollaterals.asset,
9824
- collateralOracle: offerCollaterals.oracle,
9825
- collateralLltv: offerCollaterals.lltv
9826
- }).from(bestOffers).leftJoin(offerCollaterals, drizzle_orm_star.eq(bestOffers.hash, offerCollaterals.offerHash)).orderBy(
9827
- sortOrder === "asc" ? drizzle_orm_star.sql`CASE WHEN ${bestOffers.buy} THEN ${bestOffers.rate} ELSE -${bestOffers.rate} END ASC` : drizzle_orm_star.sql`CASE WHEN ${bestOffers.buy} THEN -${bestOffers.rate} ELSE ${bestOffers.rate} END DESC`
9828
- ).limit(limit + 1);
9829
- const offerMap = /* @__PURE__ */ new Map();
9830
- for (const r of rows) {
9831
- const entry = offerMap.get(r.hash) ?? { base: r, collaterals: [] };
9832
- if (r.collateralAsset && r.collateralOracle && r.collateralLltv) {
9833
- entry.collaterals.push({
9834
- asset: r.collateralAsset,
9835
- oracle: r.collateralOracle,
9836
- lltv: mempool.LLTV.from(r.collateralLltv)
9837
- });
9385
+ const remainingCandidate = offer.assets - offer.consumed;
9386
+ const remainingCurrent = current.assets - current.consumed;
9387
+ let candidateIsBetter = false;
9388
+ if (offer.buy) {
9389
+ if (offer.rate !== current.rate) candidateIsBetter = offer.rate < current.rate;
9390
+ else if (remainingCandidate !== remainingCurrent)
9391
+ candidateIsBetter = remainingCandidate > remainingCurrent;
9392
+ else if (offer.maturity !== current.maturity)
9393
+ candidateIsBetter = offer.maturity > current.maturity;
9394
+ else candidateIsBetter = offer.hash < current.hash;
9395
+ } else {
9396
+ if (offer.rate !== current.rate) candidateIsBetter = offer.rate > current.rate;
9397
+ else if (remainingCandidate !== remainingCurrent)
9398
+ candidateIsBetter = remainingCandidate > remainingCurrent;
9399
+ else if (offer.maturity !== current.maturity)
9400
+ candidateIsBetter = offer.maturity > current.maturity;
9401
+ else candidateIsBetter = offer.hash < current.hash;
9838
9402
  }
9839
- offerMap.set(r.hash, entry);
9403
+ if (candidateIsBetter) byGroup.set(groupKey, offer);
9840
9404
  }
9841
- const offersArray = Array.from(offerMap.values()).sort(
9842
- (a, b) => sortOrder === "asc" ? a.base.rate < b.base.rate ? -1 : 1 : a.base.rate > b.base.rate ? -1 : 1
9843
- );
9844
- const page = offersArray.slice(0, limit);
9845
- const data = page.map(({ base: base2, collaterals: cols }) => ({
9846
- ...mempool.Offer.from({
9847
- offering: base2.offering,
9848
- assets: base2.assets,
9849
- rate: base2.rate,
9850
- maturity: mempool.Maturity.from(base2.maturity),
9851
- expiry: base2.expiry,
9852
- start: base2.start,
9853
- nonce: base2.nonce,
9854
- buy: base2.buy,
9855
- chainId: base2.chainId,
9856
- loanToken: base2.loanToken,
9857
- collaterals: cols.sort(
9858
- (a, b) => a.asset.toLowerCase().localeCompare(b.asset.toLowerCase())
9859
- ),
9860
- callback: {
9861
- address: base2.callbackAddress,
9862
- data: base2.callbackData,
9863
- gasLimit: base2.callbackGasLimit
9864
- },
9865
- signature: base2.signature === null ? void 0 : base2.signature
9866
- }),
9867
- consumed: base2.consumed || 0n,
9868
- status: base2.status,
9869
- ...base2.metadata ? { metadata: base2.metadata } : {}
9870
- }));
9405
+ offers = Array.from(byGroup.values());
9406
+ offers = offers.sort((a, b) => sort("rate", sortOrder, a, b));
9871
9407
  let nextCursor = null;
9872
- if (offersArray.length > limit) {
9873
- const last = page[page.length - 1].base;
9408
+ if (offers.length > limit) {
9409
+ const last = offers[limit - 1];
9874
9410
  nextCursor = encodeCursor({
9875
9411
  sort: "rate",
9876
9412
  dir: sortOrder,
@@ -9878,62 +9414,59 @@ function create2(config) {
9878
9414
  rate: last.rate.toString()
9879
9415
  });
9880
9416
  }
9881
- return { offers: data, nextCursor };
9417
+ offers = offers.slice(0, limit);
9418
+ return {
9419
+ offers,
9420
+ nextCursor
9421
+ };
9882
9422
  },
9883
9423
  delete: async (hash3) => {
9884
- const result = await db.delete(offers).where(drizzle_orm_star.eq(offers.hash, hash3.toLowerCase()));
9885
- return result.affectedRows > 0;
9424
+ if (!map.has(hash3.toLowerCase())) return false;
9425
+ map.delete(hash3.toLowerCase());
9426
+ return true;
9886
9427
  },
9887
9428
  deleteMany: async (hashes) => {
9888
- if (hashes.length === 0) {
9889
- return 0;
9429
+ let deleted = 0;
9430
+ for (const hash3 of hashes) {
9431
+ if (map.has(hash3.toLowerCase())) {
9432
+ map.delete(hash3.toLowerCase());
9433
+ deleted++;
9434
+ }
9890
9435
  }
9891
- return await db.transaction(async (tx) => {
9892
- const normalizedHashes = hashes.map((hash3) => hash3.toLowerCase());
9893
- const result = await tx.delete(offers).where(
9894
- drizzle_orm_star.sql`${offers.hash} = ANY(${drizzle_orm_star.sql.raw(`ARRAY[${normalizedHashes.map((h) => `'${h}'`).join(", ")}]`)})`
9895
- );
9896
- return result.affectedRows;
9897
- });
9898
- },
9899
- updateStatus: async (parameters) => {
9900
- await db.insert(offerStatus).values(parameters);
9436
+ return deleted;
9901
9437
  },
9902
- updateConsumedAmount: async (parameters) => {
9903
- await db.insert(consumed).values(parameters);
9904
- }
9905
- };
9906
- }
9907
- function createTest() {
9908
- return {
9909
- create: async (_parameters) => "",
9910
- createMany: async (_parameters) => [],
9911
- getAll: async (_params) => ({ offers: [], nextCursor: null }),
9912
- findMatchingOffers: async (_params) => ({ offers: [], nextCursor: null }),
9913
- delete: async (_hash) => false,
9914
- deleteMany: async (_hashes) => 0,
9915
- updateStatus: async (_params) => {
9438
+ updateStatus: async (parameters2) => {
9439
+ if (!map.has(parameters2.offerHash.toLowerCase())) return;
9440
+ map.set(parameters2.offerHash.toLowerCase(), {
9441
+ ...map.get(parameters2.offerHash.toLowerCase()),
9442
+ status: parameters2.status,
9443
+ metadata: parameters2.metadata
9444
+ });
9916
9445
  },
9917
- updateConsumedAmount: async (_params) => {
9446
+ updateConsumedAmount: async (parameters2) => {
9447
+ const chainId = parameters2.chainId;
9448
+ const address = parameters2.offering.toLowerCase();
9449
+ const nonce = parameters2.nonce;
9450
+ const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
9451
+ const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
9452
+ filledForOffering.set(nonce, parameters2.consumed);
9453
+ filledForChain.set(address, filledForOffering);
9454
+ filled.set(chainId, filledForChain);
9918
9455
  }
9919
9456
  };
9920
9457
  }
9921
9458
 
9922
- // src/core/Server.ts
9459
+ // src/core/router/Server.ts
9923
9460
  async function serve(parameters) {
9924
9461
  const app = new hono.Hono();
9925
- let repository;
9926
- if (parameters.store) {
9927
- repository = parameters.store;
9928
- } else {
9929
- const db = OfferDB_exports.create({ type: "pglite" });
9930
- repository = OfferRepository_exports.create({ db });
9931
- await OfferDB_exports.applyMigrations(db);
9932
- }
9462
+ const store = parameters.store ? parameters.store : memory({
9463
+ offers: /* @__PURE__ */ new Map(),
9464
+ filled: /* @__PURE__ */ new Map()
9465
+ });
9933
9466
  app.get("/v1/offers", async (c) => {
9934
9467
  try {
9935
9468
  const params = parse("get_offers", c.req.query());
9936
- const offers2 = await repository.getAll({
9469
+ const offers = await store.getAll({
9937
9470
  query: {
9938
9471
  creators: params.creators,
9939
9472
  side: params.side,
@@ -9961,10 +9494,10 @@ async function serve(parameters) {
9961
9494
  }
9962
9495
  });
9963
9496
  return mempool.Mempool.success(c, {
9964
- data: offers2.offers.map(
9497
+ data: offers.offers.map(
9965
9498
  (offer) => mempool.Format.stringifyBigint(mempool.Format.toSnakeCase(toResponse(offer)))
9966
9499
  ),
9967
- cursor: offers2.nextCursor ?? null
9500
+ cursor: offers.nextCursor ?? null
9968
9501
  });
9969
9502
  } catch (err) {
9970
9503
  console.error(err);
@@ -9974,7 +9507,7 @@ async function serve(parameters) {
9974
9507
  app.get("/v1/match-offers", async (c) => {
9975
9508
  try {
9976
9509
  const params = parse("match_offers", c.req.query());
9977
- const offers2 = await repository.findMatchingOffers({
9510
+ const offers = await store.findMatchingOffers({
9978
9511
  side: params.side,
9979
9512
  chainId: params.chain_id,
9980
9513
  rate: params.rate,
@@ -9989,10 +9522,10 @@ async function serve(parameters) {
9989
9522
  limit: params.limit
9990
9523
  });
9991
9524
  return mempool.Mempool.success(c, {
9992
- data: offers2.offers.map(
9525
+ data: offers.offers.map(
9993
9526
  (offer) => mempool.Format.stringifyBigint(mempool.Format.toSnakeCase(toResponse(offer)))
9994
9527
  ),
9995
- cursor: offers2.nextCursor ?? null
9528
+ cursor: offers.nextCursor ?? null
9996
9529
  });
9997
9530
  } catch (err) {
9998
9531
  console.error(err);
@@ -10221,7 +9754,7 @@ function aoutput(out, instance) {
10221
9754
  function u32(arr) {
10222
9755
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
10223
9756
  }
10224
- function clean2(...arrays) {
9757
+ function clean(...arrays) {
10225
9758
  for (let i = 0; i < arrays.length; i++) {
10226
9759
  arrays[i].fill(0);
10227
9760
  }
@@ -10404,7 +9937,7 @@ var HashMD = class extends Hash {
10404
9937
  const { buffer, view, blockLen, isLE: isLE3 } = this;
10405
9938
  let { pos } = this;
10406
9939
  buffer[pos++] = 128;
10407
- clean2(this.buffer.subarray(pos));
9940
+ clean(this.buffer.subarray(pos));
10408
9941
  if (this.padOffset > blockLen - pos) {
10409
9942
  this.process(view, 0);
10410
9943
  pos = 0;
@@ -10612,11 +10145,11 @@ var SHA256 = class extends HashMD {
10612
10145
  this.set(A, B, C, D, E, F2, G, H);
10613
10146
  }
10614
10147
  roundClean() {
10615
- clean2(SHA256_W);
10148
+ clean(SHA256_W);
10616
10149
  }
10617
10150
  destroy() {
10618
10151
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
10619
- clean2(this.buffer);
10152
+ clean(this.buffer);
10620
10153
  }
10621
10154
  };
10622
10155
  var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
@@ -10644,7 +10177,7 @@ var HMAC = class extends Hash {
10644
10177
  for (let i = 0; i < pad2.length; i++)
10645
10178
  pad2[i] ^= 54 ^ 92;
10646
10179
  this.oHash.update(pad2);
10647
- clean2(pad2);
10180
+ clean(pad2);
10648
10181
  }
10649
10182
  update(buf) {
10650
10183
  aexists(this);
@@ -12293,8 +11826,8 @@ function getHash(hash3) {
12293
11826
  };
12294
11827
  }
12295
11828
  function createCurve(curveDef, defHash) {
12296
- const create3 = (hash3) => weierstrass({ ...curveDef, ...getHash(hash3) });
12297
- return { ...create3(defHash), create: create3 };
11829
+ const create = (hash3) => weierstrass({ ...curveDef, ...getHash(hash3) });
11830
+ return { ...create(defHash), create };
12298
11831
  }
12299
11832
 
12300
11833
  // ../../node_modules/.pnpm/@noble+curves@1.9.0/node_modules/@noble/curves/esm/secp256k1.js
@@ -12581,11 +12114,11 @@ function concatBytes3(...arrays) {
12581
12114
  function utf8ToBytes2(utf) {
12582
12115
  return new TextEncoder().encode(utf);
12583
12116
  }
12584
- function numberToHex(integer2) {
12585
- if (integer2 < 0) {
12117
+ function numberToHex(integer) {
12118
+ if (integer < 0) {
12586
12119
  throw EthereumJSErrorWithoutCode("Invalid integer as argument, must be unsigned!");
12587
12120
  }
12588
- const hex = integer2.toString(16);
12121
+ const hex = integer.toString(16);
12589
12122
  return hex.length % 2 ? `0${hex}` : hex;
12590
12123
  }
12591
12124
  function padToEven(a) {
@@ -12965,7 +12498,7 @@ function keccakP(s, rounds = 24) {
12965
12498
  s[0] ^= SHA3_IOTA_H[round];
12966
12499
  s[1] ^= SHA3_IOTA_L[round];
12967
12500
  }
12968
- clean2(B);
12501
+ clean(B);
12969
12502
  }
12970
12503
  var Keccak = class _Keccak extends Hash {
12971
12504
  // NOTE: we accept arguments in bytes instead of bits here.
@@ -13061,7 +12594,7 @@ var Keccak = class _Keccak extends Hash {
13061
12594
  }
13062
12595
  destroy() {
13063
12596
  this.destroyed = true;
13064
- clean2(this.state);
12597
+ clean(this.state);
13065
12598
  }
13066
12599
  _cloneInto(to) {
13067
12600
  const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
@@ -13426,8 +12959,8 @@ function isEOACode7702AuthorizationList(input) {
13426
12959
 
13427
12960
  // ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/withdrawal.js
13428
12961
  function withdrawalToBytesArray(withdrawal) {
13429
- const { index: index2, validatorIndex, address, amount } = withdrawal;
13430
- const indexBytes = toType(index2, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(index2, TypeOutput.Uint8Array);
12962
+ const { index, validatorIndex, address, amount } = withdrawal;
12963
+ const indexBytes = toType(index, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(index, TypeOutput.Uint8Array);
13431
12964
  const validatorIndexBytes = toType(validatorIndex, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(validatorIndex, TypeOutput.Uint8Array);
13432
12965
  const addressBytes = address instanceof Address ? address.bytes : toType(address, TypeOutput.Uint8Array);
13433
12966
  const amountBytes = toType(amount, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(amount, TypeOutput.Uint8Array);
@@ -13439,8 +12972,8 @@ var Withdrawal = class {
13439
12972
  * Use the static factory methods to assist in creating a Withdrawal object from varying data types.
13440
12973
  * Its amount is in Gwei to match CL representation and for eventual ssz withdrawalsRoot
13441
12974
  */
13442
- constructor(index2, validatorIndex, address, amount) {
13443
- this.index = index2;
12975
+ constructor(index, validatorIndex, address, amount) {
12976
+ this.index = index;
13444
12977
  this.validatorIndex = validatorIndex;
13445
12978
  this.address = address;
13446
12979
  this.amount = amount;
@@ -13467,11 +13000,11 @@ var Withdrawal = class {
13467
13000
  };
13468
13001
  function createWithdrawal(withdrawalData) {
13469
13002
  const { index: indexData, validatorIndex: validatorIndexData, address: addressData, amount: amountData } = withdrawalData;
13470
- const index2 = toType(indexData, TypeOutput.BigInt);
13003
+ const index = toType(indexData, TypeOutput.BigInt);
13471
13004
  const validatorIndex = toType(validatorIndexData, TypeOutput.BigInt);
13472
13005
  const address = addressData instanceof Address ? addressData : new Address(toBytes3(addressData));
13473
13006
  const amount = toType(amountData, TypeOutput.BigInt);
13474
- return new Withdrawal(index2, validatorIndex, address, amount);
13007
+ return new Withdrawal(index, validatorIndex, address, amount);
13475
13008
  }
13476
13009
 
13477
13010
  // ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/signature.js
@@ -13880,8 +13413,8 @@ if (typeof Int32Array !== "undefined") {
13880
13413
  }
13881
13414
  var crc = (current, previous) => {
13882
13415
  let crc2 = 0 ^ -1;
13883
- for (let index2 = 0; index2 < current.length; index2++) {
13884
- crc2 = TABLE[(crc2 ^ current[index2]) & 255] ^ crc2 >>> 8;
13416
+ for (let index = 0; index < current.length; index++) {
13417
+ crc2 = TABLE[(crc2 ^ current[index]) & 255] ^ crc2 >>> 8;
13885
13418
  }
13886
13419
  return crc2 ^ -1;
13887
13420
  };
@@ -14714,15 +14247,15 @@ var Common = class {
14714
14247
  */
14715
14248
  getHardforkBy(opts) {
14716
14249
  const blockNumber = toType(opts.blockNumber, TypeOutput.BigInt);
14717
- const timestamp2 = toType(opts.timestamp, TypeOutput.BigInt);
14250
+ const timestamp = toType(opts.timestamp, TypeOutput.BigInt);
14718
14251
  const hfs = this.hardforks().filter((hf) => hf.block !== null || hf.timestamp !== void 0);
14719
- let hfIndex = hfs.findIndex((hf) => blockNumber !== void 0 && hf.block !== null && BigInt(hf.block) > blockNumber || timestamp2 !== void 0 && hf.timestamp !== void 0 && BigInt(hf.timestamp) > timestamp2);
14252
+ let hfIndex = hfs.findIndex((hf) => blockNumber !== void 0 && hf.block !== null && BigInt(hf.block) > blockNumber || timestamp !== void 0 && hf.timestamp !== void 0 && BigInt(hf.timestamp) > timestamp);
14720
14253
  if (hfIndex === -1) {
14721
14254
  hfIndex = hfs.length;
14722
14255
  } else if (hfIndex === 0) {
14723
14256
  throw Error("Must have at least one hardfork at block 0");
14724
14257
  }
14725
- if (timestamp2 === void 0) {
14258
+ if (timestamp === void 0) {
14726
14259
  const stepBack = hfs.slice(0, hfIndex).reverse().findIndex((hf) => hf.block !== null);
14727
14260
  hfIndex = hfIndex - stepBack;
14728
14261
  }
@@ -14733,13 +14266,13 @@ var Common = class {
14733
14266
  break;
14734
14267
  }
14735
14268
  }
14736
- if (timestamp2 !== void 0) {
14269
+ if (timestamp !== void 0) {
14737
14270
  const minTimeStamp = hfs.slice(0, hfStartIndex).reduce((acc, hf) => Math.max(Number(hf.timestamp ?? "0"), acc), 0);
14738
- if (minTimeStamp > timestamp2) {
14271
+ if (minTimeStamp > timestamp) {
14739
14272
  throw Error(`Maximum HF determined by timestamp is lower than the block number HF`);
14740
14273
  }
14741
- const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ?? timestamp2), acc), Number(timestamp2));
14742
- if (maxTimeStamp < timestamp2) {
14274
+ const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ?? timestamp), acc), Number(timestamp));
14275
+ if (maxTimeStamp < timestamp) {
14743
14276
  throw Error(`Maximum HF determined by block number is lower than timestamp HF`);
14744
14277
  }
14745
14278
  }
@@ -14910,8 +14443,8 @@ var Common = class {
14910
14443
  * @param blockNumber Block number
14911
14444
  * * @returns The value requested or `BigInt(0)` if not found
14912
14445
  */
14913
- paramByBlock(name, blockNumber, timestamp2) {
14914
- const hardfork = this.getHardforkBy({ blockNumber, timestamp: timestamp2 });
14446
+ paramByBlock(name, blockNumber, timestamp) {
14447
+ const hardfork = this.getHardforkBy({ blockNumber, timestamp });
14915
14448
  return this.paramByHardfork(name, hardfork);
14916
14449
  }
14917
14450
  /**
@@ -14963,13 +14496,13 @@ var Common = class {
14963
14496
  hardfork1 = hardfork1 ?? this._hardfork;
14964
14497
  const hardforks = this.hardforks();
14965
14498
  let posHf1 = -1, posHf2 = -1;
14966
- let index2 = 0;
14499
+ let index = 0;
14967
14500
  for (const hf of hardforks) {
14968
14501
  if (hf["name"] === hardfork1)
14969
- posHf1 = index2;
14502
+ posHf1 = index;
14970
14503
  if (hf["name"] === hardfork2)
14971
- posHf2 = index2;
14972
- index2 += 1;
14504
+ posHf2 = index;
14505
+ index += 1;
14973
14506
  }
14974
14507
  return posHf1 >= posHf2 && posHf2 !== -1;
14975
14508
  }
@@ -14996,11 +14529,11 @@ var Common = class {
14996
14529
  }
14997
14530
  hardforkTimestamp(hardfork) {
14998
14531
  hardfork = hardfork ?? this._hardfork;
14999
- const timestamp2 = this._getHardfork(hardfork)?.["timestamp"];
15000
- if (timestamp2 === void 0 || timestamp2 === null) {
14532
+ const timestamp = this._getHardfork(hardfork)?.["timestamp"];
14533
+ if (timestamp === void 0 || timestamp === null) {
15001
14534
  return null;
15002
14535
  }
15003
- return BigInt(timestamp2);
14536
+ return BigInt(timestamp);
15004
14537
  }
15005
14538
  /**
15006
14539
  * Returns the hardfork change block for eip
@@ -15075,8 +14608,8 @@ var Common = class {
15075
14608
  let hfBytes = new Uint8Array(0);
15076
14609
  let prevBlockOrTime = 0;
15077
14610
  for (const hf of this.hardforks()) {
15078
- const { block, timestamp: timestamp2, name } = hf;
15079
- let blockOrTime = timestamp2 ?? block;
14611
+ const { block, timestamp, name } = hf;
14612
+ let blockOrTime = timestamp ?? block;
15080
14613
  blockOrTime = blockOrTime !== null ? Number(blockOrTime) : null;
15081
14614
  if (typeof blockOrTime === "number" && blockOrTime !== 0 && blockOrTime !== prevBlockOrTime && name !== Hardfork.Paris) {
15082
14615
  const hfBlockBytes = hexToBytes5(`0x${blockOrTime.toString(16).padStart(16, "0")}`);
@@ -17291,9 +16824,9 @@ var handlers = /* @__PURE__ */ new Map([
17291
16824
  [
17292
16825
  73,
17293
16826
  function(runState) {
17294
- const index2 = runState.stack.pop();
17295
- if (runState.env.blobVersionedHashes.length > Number(index2)) {
17296
- runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(index2)]));
16827
+ const index = runState.stack.pop();
16828
+ if (runState.env.blobVersionedHashes.length > Number(index)) {
16829
+ runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(index)]));
17297
16830
  } else {
17298
16831
  runState.stack.push(BIGINT_02);
17299
16832
  }
@@ -19357,11 +18890,11 @@ var Stack = class {
19357
18890
  const peekArray = Array(num);
19358
18891
  let start = this._len;
19359
18892
  for (let peek = 0; peek < num; peek++) {
19360
- const index2 = --start;
19361
- if (index2 < 0) {
18893
+ const index = --start;
18894
+ if (index < 0) {
19362
18895
  throw new EVMError(EVMError.errorMessages.STACK_UNDERFLOW);
19363
18896
  }
19364
- peekArray[peek] = this._store[index2];
18897
+ peekArray[peek] = this._store[index];
19365
18898
  }
19366
18899
  return peekArray;
19367
18900
  }
@@ -24971,8 +24504,8 @@ var msmGasUsed = (numPairs, gasUsedPerPair, discountTable) => {
24971
24504
  return BigInt(numPairs) * gasUsedPerPair * BigInt(gasDiscountMultiplier) / BigInt(1e3);
24972
24505
  };
24973
24506
  var leading16ZeroBytesCheck = (opts, zeroByteRanges, pName, pairStart = 0) => {
24974
- for (const index2 in zeroByteRanges) {
24975
- const slicedBuffer = opts.data.subarray(zeroByteRanges[index2][0] + pairStart, zeroByteRanges[index2][1] + pairStart);
24507
+ for (const index in zeroByteRanges) {
24508
+ const slicedBuffer = opts.data.subarray(zeroByteRanges[index][0] + pairStart, zeroByteRanges[index][1] + pairStart);
24976
24509
  if (!(equalsBytes(slicedBuffer, ZERO_BYTES_16) === true)) {
24977
24510
  if (opts._debug !== void 0) {
24978
24511
  opts._debug(`${pName} failed: Point not on curve`);
@@ -25390,11 +24923,11 @@ var RIPEMD160 = class extends HashMD {
25390
24923
  this.set(this.h1 + cl + dr | 0, this.h2 + dl + er | 0, this.h3 + el + ar | 0, this.h4 + al + br | 0, this.h0 + bl + cr | 0);
25391
24924
  }
25392
24925
  roundClean() {
25393
- clean2(BUF_160);
24926
+ clean(BUF_160);
25394
24927
  }
25395
24928
  destroy() {
25396
24929
  this.destroyed = true;
25397
- clean2(this.buffer);
24930
+ clean(this.buffer);
25398
24931
  this.set(0, 0, 0, 0, 0);
25399
24932
  }
25400
24933
  };
@@ -28757,11 +28290,11 @@ var LRUCache = class _LRUCache {
28757
28290
  free: c.#free,
28758
28291
  // methods
28759
28292
  isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
28760
- backgroundFetch: (k, index2, options, context) => c.#backgroundFetch(k, index2, options, context),
28761
- moveToTail: (index2) => c.#moveToTail(index2),
28293
+ backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
28294
+ moveToTail: (index) => c.#moveToTail(index),
28762
28295
  indexes: (options) => c.#indexes(options),
28763
28296
  rindexes: (options) => c.#rindexes(options),
28764
- isStale: (index2) => c.#isStale(index2)
28297
+ isStale: (index) => c.#isStale(index)
28765
28298
  };
28766
28299
  }
28767
28300
  // Protected read-only members
@@ -28916,13 +28449,13 @@ var LRUCache = class _LRUCache {
28916
28449
  const starts = new ZeroArray(this.#max);
28917
28450
  this.#ttls = ttls;
28918
28451
  this.#starts = starts;
28919
- this.#setItemTTL = (index2, ttl, start = perf.now()) => {
28920
- starts[index2] = ttl !== 0 ? start : 0;
28921
- ttls[index2] = ttl;
28452
+ this.#setItemTTL = (index, ttl, start = perf.now()) => {
28453
+ starts[index] = ttl !== 0 ? start : 0;
28454
+ ttls[index] = ttl;
28922
28455
  if (ttl !== 0 && this.ttlAutopurge) {
28923
28456
  const t = setTimeout(() => {
28924
- if (this.#isStale(index2)) {
28925
- this.#delete(this.#keyList[index2], "expire");
28457
+ if (this.#isStale(index)) {
28458
+ this.#delete(this.#keyList[index], "expire");
28926
28459
  }
28927
28460
  }, ttl + 1);
28928
28461
  if (t.unref) {
@@ -28930,13 +28463,13 @@ var LRUCache = class _LRUCache {
28930
28463
  }
28931
28464
  }
28932
28465
  };
28933
- this.#updateItemAge = (index2) => {
28934
- starts[index2] = ttls[index2] !== 0 ? perf.now() : 0;
28466
+ this.#updateItemAge = (index) => {
28467
+ starts[index] = ttls[index] !== 0 ? perf.now() : 0;
28935
28468
  };
28936
- this.#statusTTL = (status, index2) => {
28937
- if (ttls[index2]) {
28938
- const ttl = ttls[index2];
28939
- const start = starts[index2];
28469
+ this.#statusTTL = (status, index) => {
28470
+ if (ttls[index]) {
28471
+ const ttl = ttls[index];
28472
+ const start = starts[index];
28940
28473
  if (!ttl || !start)
28941
28474
  return;
28942
28475
  status.ttl = ttl;
@@ -28959,21 +28492,21 @@ var LRUCache = class _LRUCache {
28959
28492
  return n;
28960
28493
  };
28961
28494
  this.getRemainingTTL = (key) => {
28962
- const index2 = this.#keyMap.get(key);
28963
- if (index2 === void 0) {
28495
+ const index = this.#keyMap.get(key);
28496
+ if (index === void 0) {
28964
28497
  return 0;
28965
28498
  }
28966
- const ttl = ttls[index2];
28967
- const start = starts[index2];
28499
+ const ttl = ttls[index];
28500
+ const start = starts[index];
28968
28501
  if (!ttl || !start) {
28969
28502
  return Infinity;
28970
28503
  }
28971
28504
  const age = (cachedNow || getNow()) - start;
28972
28505
  return ttl - age;
28973
28506
  };
28974
- this.#isStale = (index2) => {
28975
- const s = starts[index2];
28976
- const t = ttls[index2];
28507
+ this.#isStale = (index) => {
28508
+ const s = starts[index];
28509
+ const t = ttls[index];
28977
28510
  return !!t && !!s && (cachedNow || getNow()) - s > t;
28978
28511
  };
28979
28512
  }
@@ -28990,9 +28523,9 @@ var LRUCache = class _LRUCache {
28990
28523
  const sizes = new ZeroArray(this.#max);
28991
28524
  this.#calculatedSize = 0;
28992
28525
  this.#sizes = sizes;
28993
- this.#removeItemSize = (index2) => {
28994
- this.#calculatedSize -= sizes[index2];
28995
- sizes[index2] = 0;
28526
+ this.#removeItemSize = (index) => {
28527
+ this.#calculatedSize -= sizes[index];
28528
+ sizes[index] = 0;
28996
28529
  };
28997
28530
  this.#requireSize = (k, v, size, sizeCalculation) => {
28998
28531
  if (this.#isBackgroundFetch(v)) {
@@ -29013,15 +28546,15 @@ var LRUCache = class _LRUCache {
29013
28546
  }
29014
28547
  return size;
29015
28548
  };
29016
- this.#addItemSize = (index2, size, status) => {
29017
- sizes[index2] = size;
28549
+ this.#addItemSize = (index, size, status) => {
28550
+ sizes[index] = size;
29018
28551
  if (this.#maxSize) {
29019
- const maxSize2 = this.#maxSize - sizes[index2];
28552
+ const maxSize2 = this.#maxSize - sizes[index];
29020
28553
  while (this.#calculatedSize > maxSize2) {
29021
28554
  this.#evict(true);
29022
28555
  }
29023
28556
  }
29024
- this.#calculatedSize += sizes[index2];
28557
+ this.#calculatedSize += sizes[index];
29025
28558
  if (status) {
29026
28559
  status.entrySize = size;
29027
28560
  status.totalCalculatedSize = this.#calculatedSize;
@@ -29072,8 +28605,8 @@ var LRUCache = class _LRUCache {
29072
28605
  }
29073
28606
  }
29074
28607
  }
29075
- #isValidIndex(index2) {
29076
- return index2 !== void 0 && this.#keyMap.get(this.#keyList[index2]) === index2;
28608
+ #isValidIndex(index) {
28609
+ return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
29077
28610
  }
29078
28611
  /**
29079
28612
  * Return a generator yielding `[key, value]` pairs,
@@ -29360,23 +28893,23 @@ var LRUCache = class _LRUCache {
29360
28893
  this.#delete(k, "set");
29361
28894
  return this;
29362
28895
  }
29363
- let index2 = this.#size === 0 ? void 0 : this.#keyMap.get(k);
29364
- if (index2 === void 0) {
29365
- index2 = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
29366
- this.#keyList[index2] = k;
29367
- this.#valList[index2] = v;
29368
- this.#keyMap.set(k, index2);
29369
- this.#next[this.#tail] = index2;
29370
- this.#prev[index2] = this.#tail;
29371
- this.#tail = index2;
28896
+ let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
28897
+ if (index === void 0) {
28898
+ index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
28899
+ this.#keyList[index] = k;
28900
+ this.#valList[index] = v;
28901
+ this.#keyMap.set(k, index);
28902
+ this.#next[this.#tail] = index;
28903
+ this.#prev[index] = this.#tail;
28904
+ this.#tail = index;
29372
28905
  this.#size++;
29373
- this.#addItemSize(index2, size, status);
28906
+ this.#addItemSize(index, size, status);
29374
28907
  if (status)
29375
28908
  status.set = "add";
29376
28909
  noUpdateTTL = false;
29377
28910
  } else {
29378
- this.#moveToTail(index2);
29379
- const oldVal = this.#valList[index2];
28911
+ this.#moveToTail(index);
28912
+ const oldVal = this.#valList[index];
29380
28913
  if (v !== oldVal) {
29381
28914
  if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
29382
28915
  oldVal.__abortController.abort(new Error("replaced"));
@@ -29397,9 +28930,9 @@ var LRUCache = class _LRUCache {
29397
28930
  this.#disposed?.push([oldVal, k, "set"]);
29398
28931
  }
29399
28932
  }
29400
- this.#removeItemSize(index2);
29401
- this.#addItemSize(index2, size, status);
29402
- this.#valList[index2] = v;
28933
+ this.#removeItemSize(index);
28934
+ this.#addItemSize(index, size, status);
28935
+ this.#valList[index] = v;
29403
28936
  if (status) {
29404
28937
  status.set = "replace";
29405
28938
  const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
@@ -29415,10 +28948,10 @@ var LRUCache = class _LRUCache {
29415
28948
  }
29416
28949
  if (this.#ttls) {
29417
28950
  if (!noUpdateTTL) {
29418
- this.#setItemTTL(index2, ttl, start);
28951
+ this.#setItemTTL(index, ttl, start);
29419
28952
  }
29420
28953
  if (status)
29421
- this.#statusTTL(status, index2);
28954
+ this.#statusTTL(status, index);
29422
28955
  }
29423
28956
  if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
29424
28957
  const dt = this.#disposed;
@@ -29504,24 +29037,24 @@ var LRUCache = class _LRUCache {
29504
29037
  */
29505
29038
  has(k, hasOptions = {}) {
29506
29039
  const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
29507
- const index2 = this.#keyMap.get(k);
29508
- if (index2 !== void 0) {
29509
- const v = this.#valList[index2];
29040
+ const index = this.#keyMap.get(k);
29041
+ if (index !== void 0) {
29042
+ const v = this.#valList[index];
29510
29043
  if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
29511
29044
  return false;
29512
29045
  }
29513
- if (!this.#isStale(index2)) {
29046
+ if (!this.#isStale(index)) {
29514
29047
  if (updateAgeOnHas) {
29515
- this.#updateItemAge(index2);
29048
+ this.#updateItemAge(index);
29516
29049
  }
29517
29050
  if (status) {
29518
29051
  status.has = "hit";
29519
- this.#statusTTL(status, index2);
29052
+ this.#statusTTL(status, index);
29520
29053
  }
29521
29054
  return true;
29522
29055
  } else if (status) {
29523
29056
  status.has = "stale";
29524
- this.#statusTTL(status, index2);
29057
+ this.#statusTTL(status, index);
29525
29058
  }
29526
29059
  } else if (status) {
29527
29060
  status.has = "miss";
@@ -29537,15 +29070,15 @@ var LRUCache = class _LRUCache {
29537
29070
  */
29538
29071
  peek(k, peekOptions = {}) {
29539
29072
  const { allowStale = this.allowStale } = peekOptions;
29540
- const index2 = this.#keyMap.get(k);
29541
- if (index2 === void 0 || !allowStale && this.#isStale(index2)) {
29073
+ const index = this.#keyMap.get(k);
29074
+ if (index === void 0 || !allowStale && this.#isStale(index)) {
29542
29075
  return;
29543
29076
  }
29544
- const v = this.#valList[index2];
29077
+ const v = this.#valList[index];
29545
29078
  return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
29546
29079
  }
29547
- #backgroundFetch(k, index2, options, context) {
29548
- const v = index2 === void 0 ? void 0 : this.#valList[index2];
29080
+ #backgroundFetch(k, index, options, context) {
29081
+ const v = index === void 0 ? void 0 : this.#valList[index];
29549
29082
  if (this.#isBackgroundFetch(v)) {
29550
29083
  return v;
29551
29084
  }
@@ -29576,10 +29109,10 @@ var LRUCache = class _LRUCache {
29576
29109
  return fetchFail(ac.signal.reason);
29577
29110
  }
29578
29111
  const bf2 = p;
29579
- if (this.#valList[index2] === p) {
29112
+ if (this.#valList[index] === p) {
29580
29113
  if (v2 === void 0) {
29581
29114
  if (bf2.__staleWhileFetching) {
29582
- this.#valList[index2] = bf2.__staleWhileFetching;
29115
+ this.#valList[index] = bf2.__staleWhileFetching;
29583
29116
  } else {
29584
29117
  this.#delete(k, "fetch");
29585
29118
  }
@@ -29604,12 +29137,12 @@ var LRUCache = class _LRUCache {
29604
29137
  const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
29605
29138
  const noDelete = allowStale || options.noDeleteOnFetchRejection;
29606
29139
  const bf2 = p;
29607
- if (this.#valList[index2] === p) {
29140
+ if (this.#valList[index] === p) {
29608
29141
  const del = !noDelete || bf2.__staleWhileFetching === void 0;
29609
29142
  if (del) {
29610
29143
  this.#delete(k, "fetch");
29611
29144
  } else if (!allowStaleAborted) {
29612
- this.#valList[index2] = bf2.__staleWhileFetching;
29145
+ this.#valList[index] = bf2.__staleWhileFetching;
29613
29146
  }
29614
29147
  }
29615
29148
  if (allowStale) {
@@ -29643,11 +29176,11 @@ var LRUCache = class _LRUCache {
29643
29176
  __staleWhileFetching: v,
29644
29177
  __returned: void 0
29645
29178
  });
29646
- if (index2 === void 0) {
29179
+ if (index === void 0) {
29647
29180
  this.set(k, bf, { ...fetchOpts.options, status: void 0 });
29648
- index2 = this.#keyMap.get(k);
29181
+ index = this.#keyMap.get(k);
29649
29182
  } else {
29650
- this.#valList[index2] = bf;
29183
+ this.#valList[index] = bf;
29651
29184
  }
29652
29185
  return bf;
29653
29186
  }
@@ -29705,14 +29238,14 @@ var LRUCache = class _LRUCache {
29705
29238
  status,
29706
29239
  signal
29707
29240
  };
29708
- let index2 = this.#keyMap.get(k);
29709
- if (index2 === void 0) {
29241
+ let index = this.#keyMap.get(k);
29242
+ if (index === void 0) {
29710
29243
  if (status)
29711
29244
  status.fetch = "miss";
29712
- const p = this.#backgroundFetch(k, index2, options, context);
29245
+ const p = this.#backgroundFetch(k, index, options, context);
29713
29246
  return p.__returned = p;
29714
29247
  } else {
29715
- const v = this.#valList[index2];
29248
+ const v = this.#valList[index];
29716
29249
  if (this.#isBackgroundFetch(v)) {
29717
29250
  const stale = allowStale && v.__staleWhileFetching !== void 0;
29718
29251
  if (status) {
@@ -29722,19 +29255,19 @@ var LRUCache = class _LRUCache {
29722
29255
  }
29723
29256
  return stale ? v.__staleWhileFetching : v.__returned = v;
29724
29257
  }
29725
- const isStale = this.#isStale(index2);
29258
+ const isStale = this.#isStale(index);
29726
29259
  if (!forceRefresh && !isStale) {
29727
29260
  if (status)
29728
29261
  status.fetch = "hit";
29729
- this.#moveToTail(index2);
29262
+ this.#moveToTail(index);
29730
29263
  if (updateAgeOnGet) {
29731
- this.#updateItemAge(index2);
29264
+ this.#updateItemAge(index);
29732
29265
  }
29733
29266
  if (status)
29734
- this.#statusTTL(status, index2);
29267
+ this.#statusTTL(status, index);
29735
29268
  return v;
29736
29269
  }
29737
- const p = this.#backgroundFetch(k, index2, options, context);
29270
+ const p = this.#backgroundFetch(k, index, options, context);
29738
29271
  const hasStale = p.__staleWhileFetching !== void 0;
29739
29272
  const staleVal = hasStale && allowStale;
29740
29273
  if (status) {
@@ -29775,13 +29308,13 @@ var LRUCache = class _LRUCache {
29775
29308
  */
29776
29309
  get(k, getOptions = {}) {
29777
29310
  const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
29778
- const index2 = this.#keyMap.get(k);
29779
- if (index2 !== void 0) {
29780
- const value = this.#valList[index2];
29311
+ const index = this.#keyMap.get(k);
29312
+ if (index !== void 0) {
29313
+ const value = this.#valList[index];
29781
29314
  const fetching = this.#isBackgroundFetch(value);
29782
29315
  if (status)
29783
- this.#statusTTL(status, index2);
29784
- if (this.#isStale(index2)) {
29316
+ this.#statusTTL(status, index);
29317
+ if (this.#isStale(index)) {
29785
29318
  if (status)
29786
29319
  status.get = "stale";
29787
29320
  if (!fetching) {
@@ -29803,9 +29336,9 @@ var LRUCache = class _LRUCache {
29803
29336
  if (fetching) {
29804
29337
  return value.__staleWhileFetching;
29805
29338
  }
29806
- this.#moveToTail(index2);
29339
+ this.#moveToTail(index);
29807
29340
  if (updateAgeOnGet) {
29808
- this.#updateItemAge(index2);
29341
+ this.#updateItemAge(index);
29809
29342
  }
29810
29343
  return value;
29811
29344
  }
@@ -29817,15 +29350,15 @@ var LRUCache = class _LRUCache {
29817
29350
  this.#prev[n] = p;
29818
29351
  this.#next[p] = n;
29819
29352
  }
29820
- #moveToTail(index2) {
29821
- if (index2 !== this.#tail) {
29822
- if (index2 === this.#head) {
29823
- this.#head = this.#next[index2];
29353
+ #moveToTail(index) {
29354
+ if (index !== this.#tail) {
29355
+ if (index === this.#head) {
29356
+ this.#head = this.#next[index];
29824
29357
  } else {
29825
- this.#connect(this.#prev[index2], this.#next[index2]);
29358
+ this.#connect(this.#prev[index], this.#next[index]);
29826
29359
  }
29827
- this.#connect(this.#tail, index2);
29828
- this.#tail = index2;
29360
+ this.#connect(this.#tail, index);
29361
+ this.#tail = index;
29829
29362
  }
29830
29363
  }
29831
29364
  /**
@@ -29839,14 +29372,14 @@ var LRUCache = class _LRUCache {
29839
29372
  #delete(k, reason) {
29840
29373
  let deleted = false;
29841
29374
  if (this.#size !== 0) {
29842
- const index2 = this.#keyMap.get(k);
29843
- if (index2 !== void 0) {
29375
+ const index = this.#keyMap.get(k);
29376
+ if (index !== void 0) {
29844
29377
  deleted = true;
29845
29378
  if (this.#size === 1) {
29846
29379
  this.#clear(reason);
29847
29380
  } else {
29848
- this.#removeItemSize(index2);
29849
- const v = this.#valList[index2];
29381
+ this.#removeItemSize(index);
29382
+ const v = this.#valList[index];
29850
29383
  if (this.#isBackgroundFetch(v)) {
29851
29384
  v.__abortController.abort(new Error("deleted"));
29852
29385
  } else if (this.#hasDispose || this.#hasDisposeAfter) {
@@ -29858,20 +29391,20 @@ var LRUCache = class _LRUCache {
29858
29391
  }
29859
29392
  }
29860
29393
  this.#keyMap.delete(k);
29861
- this.#keyList[index2] = void 0;
29862
- this.#valList[index2] = void 0;
29863
- if (index2 === this.#tail) {
29864
- this.#tail = this.#prev[index2];
29865
- } else if (index2 === this.#head) {
29866
- this.#head = this.#next[index2];
29394
+ this.#keyList[index] = void 0;
29395
+ this.#valList[index] = void 0;
29396
+ if (index === this.#tail) {
29397
+ this.#tail = this.#prev[index];
29398
+ } else if (index === this.#head) {
29399
+ this.#head = this.#next[index];
29867
29400
  } else {
29868
- const pi = this.#prev[index2];
29869
- this.#next[pi] = this.#next[index2];
29870
- const ni = this.#next[index2];
29871
- this.#prev[ni] = this.#prev[index2];
29401
+ const pi = this.#prev[index];
29402
+ this.#next[pi] = this.#next[index];
29403
+ const ni = this.#next[index];
29404
+ this.#prev[ni] = this.#prev[index];
29872
29405
  }
29873
29406
  this.#size--;
29874
- this.#free.push(index2);
29407
+ this.#free.push(index);
29875
29408
  }
29876
29409
  }
29877
29410
  }
@@ -29891,12 +29424,12 @@ var LRUCache = class _LRUCache {
29891
29424
  return this.#clear("delete");
29892
29425
  }
29893
29426
  #clear(reason) {
29894
- for (const index2 of this.#rindexes({ allowStale: true })) {
29895
- const v = this.#valList[index2];
29427
+ for (const index of this.#rindexes({ allowStale: true })) {
29428
+ const v = this.#valList[index];
29896
29429
  if (this.#isBackgroundFetch(v)) {
29897
29430
  v.__abortController.abort(new Error("deleted"));
29898
29431
  } else {
29899
- const k = this.#keyList[index2];
29432
+ const k = this.#keyList[index];
29900
29433
  if (this.#hasDispose) {
29901
29434
  this.#dispose?.(v, k, reason);
29902
29435
  }
@@ -36661,9 +36194,9 @@ function sign(tx, privateKey, extraEntropy = true) {
36661
36194
  const { recovery, r, s } = ecSignFunction(msgHash, privateKey, { extraEntropy });
36662
36195
  const signedTx = tx.addSignature(BigInt(recovery), r, s, true);
36663
36196
  if (hackApplied) {
36664
- const index2 = tx["activeCapabilities"].indexOf(Capability.EIP155ReplayProtection);
36665
- if (index2 > -1) {
36666
- tx["activeCapabilities"].splice(index2, 1);
36197
+ const index = tx["activeCapabilities"].indexOf(Capability.EIP155ReplayProtection);
36198
+ if (index > -1) {
36199
+ tx["activeCapabilities"].splice(index, 1);
36667
36200
  }
36668
36201
  }
36669
36202
  return signedTx;
@@ -38620,7 +38153,7 @@ var BlockHeader = class {
38620
38153
  const number2 = toType(headerData.number, TypeOutput.BigInt) ?? defaults2.number;
38621
38154
  const gasLimit = toType(headerData.gasLimit, TypeOutput.BigInt) ?? defaults2.gasLimit;
38622
38155
  const gasUsed = toType(headerData.gasUsed, TypeOutput.BigInt) ?? defaults2.gasUsed;
38623
- const timestamp2 = toType(headerData.timestamp, TypeOutput.BigInt) ?? defaults2.timestamp;
38156
+ const timestamp = toType(headerData.timestamp, TypeOutput.BigInt) ?? defaults2.timestamp;
38624
38157
  const extraData = toType(headerData.extraData, TypeOutput.Uint8Array) ?? defaults2.extraData;
38625
38158
  const mixHash = toType(headerData.mixHash, TypeOutput.Uint8Array) ?? defaults2.mixHash;
38626
38159
  const nonce = toType(headerData.nonce, TypeOutput.Uint8Array) ?? defaults2.nonce;
@@ -38628,7 +38161,7 @@ var BlockHeader = class {
38628
38161
  if (setHardfork === true) {
38629
38162
  this.common.setHardforkBy({
38630
38163
  blockNumber: number2,
38631
- timestamp: timestamp2
38164
+ timestamp
38632
38165
  });
38633
38166
  }
38634
38167
  const hardforkDefaults = {
@@ -38678,7 +38211,7 @@ var BlockHeader = class {
38678
38211
  this.number = number2;
38679
38212
  this.gasLimit = gasLimit;
38680
38213
  this.gasUsed = gasUsed;
38681
- this.timestamp = timestamp2;
38214
+ this.timestamp = timestamp;
38682
38215
  this.extraData = extraData;
38683
38216
  this.mixHash = mixHash;
38684
38217
  this.nonce = nonce;
@@ -39613,8 +39146,8 @@ var hmac2 = (hash3, key, message) => new HMAC2(hash3, key).update(message).diges
39613
39146
  hmac2.create = (hash3, key) => new HMAC2(hash3, key);
39614
39147
 
39615
39148
  // ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/abstract/utils.js
39616
- var utils_exports = {};
39617
- __export(utils_exports, {
39149
+ var utils_exports2 = {};
39150
+ __export(utils_exports2, {
39618
39151
  abytes: () => abytes4,
39619
39152
  bitGet: () => bitGet2,
39620
39153
  bitLen: () => bitLen3,
@@ -40256,7 +39789,7 @@ function validatePointOpts2(curve) {
40256
39789
  }
40257
39790
  return Object.freeze({ ...opts });
40258
39791
  }
40259
- var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports;
39792
+ var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports2;
40260
39793
  var DER3 = {
40261
39794
  // asn.1 DER encoding utils
40262
39795
  Err: class DERErr3 extends Error {
@@ -41036,8 +40569,8 @@ function getHash2(hash3) {
41036
40569
  };
41037
40570
  }
41038
40571
  function createCurve2(curveDef, defHash) {
41039
- const create3 = (hash3) => weierstrass3({ ...curveDef, ...getHash2(hash3) });
41040
- return Object.freeze({ ...create3(defHash), create: create3 });
40572
+ const create = (hash3) => weierstrass3({ ...curveDef, ...getHash2(hash3) });
40573
+ return Object.freeze({ ...create(defHash), create });
41041
40574
  }
41042
40575
 
41043
40576
  // ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/secp256k1.js
@@ -41481,11 +41014,11 @@ function concatBytes8(...arrays) {
41481
41014
  function utf8ToBytes5(utf) {
41482
41015
  return new TextEncoder().encode(utf);
41483
41016
  }
41484
- function numberToHex4(integer2) {
41485
- if (integer2 < 0) {
41017
+ function numberToHex4(integer) {
41018
+ if (integer < 0) {
41486
41019
  throw new Error("Invalid integer as argument, must be unsigned!");
41487
41020
  }
41488
- const hex = integer2.toString(16);
41021
+ const hex = integer.toString(16);
41489
41022
  return hex.length % 2 ? `0${hex}` : hex;
41490
41023
  }
41491
41024
  function padToEven4(a) {
@@ -42044,11 +41577,11 @@ var LRUCache2 = class _LRUCache {
42044
41577
  free: c.#free,
42045
41578
  // methods
42046
41579
  isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
42047
- backgroundFetch: (k, index2, options, context) => c.#backgroundFetch(k, index2, options, context),
42048
- moveToTail: (index2) => c.#moveToTail(index2),
41580
+ backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
41581
+ moveToTail: (index) => c.#moveToTail(index),
42049
41582
  indexes: (options) => c.#indexes(options),
42050
41583
  rindexes: (options) => c.#rindexes(options),
42051
- isStale: (index2) => c.#isStale(index2)
41584
+ isStale: (index) => c.#isStale(index)
42052
41585
  };
42053
41586
  }
42054
41587
  // Protected read-only members
@@ -42195,13 +41728,13 @@ var LRUCache2 = class _LRUCache {
42195
41728
  const starts = new ZeroArray2(this.#max);
42196
41729
  this.#ttls = ttls;
42197
41730
  this.#starts = starts;
42198
- this.#setItemTTL = (index2, ttl, start = perf2.now()) => {
42199
- starts[index2] = ttl !== 0 ? start : 0;
42200
- ttls[index2] = ttl;
41731
+ this.#setItemTTL = (index, ttl, start = perf2.now()) => {
41732
+ starts[index] = ttl !== 0 ? start : 0;
41733
+ ttls[index] = ttl;
42201
41734
  if (ttl !== 0 && this.ttlAutopurge) {
42202
41735
  const t = setTimeout(() => {
42203
- if (this.#isStale(index2)) {
42204
- this.delete(this.#keyList[index2]);
41736
+ if (this.#isStale(index)) {
41737
+ this.delete(this.#keyList[index]);
42205
41738
  }
42206
41739
  }, ttl + 1);
42207
41740
  if (t.unref) {
@@ -42209,13 +41742,13 @@ var LRUCache2 = class _LRUCache {
42209
41742
  }
42210
41743
  }
42211
41744
  };
42212
- this.#updateItemAge = (index2) => {
42213
- starts[index2] = ttls[index2] !== 0 ? perf2.now() : 0;
41745
+ this.#updateItemAge = (index) => {
41746
+ starts[index] = ttls[index] !== 0 ? perf2.now() : 0;
42214
41747
  };
42215
- this.#statusTTL = (status, index2) => {
42216
- if (ttls[index2]) {
42217
- const ttl = ttls[index2];
42218
- const start = starts[index2];
41748
+ this.#statusTTL = (status, index) => {
41749
+ if (ttls[index]) {
41750
+ const ttl = ttls[index];
41751
+ const start = starts[index];
42219
41752
  if (!ttl || !start)
42220
41753
  return;
42221
41754
  status.ttl = ttl;
@@ -42238,21 +41771,21 @@ var LRUCache2 = class _LRUCache {
42238
41771
  return n;
42239
41772
  };
42240
41773
  this.getRemainingTTL = (key) => {
42241
- const index2 = this.#keyMap.get(key);
42242
- if (index2 === void 0) {
41774
+ const index = this.#keyMap.get(key);
41775
+ if (index === void 0) {
42243
41776
  return 0;
42244
41777
  }
42245
- const ttl = ttls[index2];
42246
- const start = starts[index2];
41778
+ const ttl = ttls[index];
41779
+ const start = starts[index];
42247
41780
  if (!ttl || !start) {
42248
41781
  return Infinity;
42249
41782
  }
42250
41783
  const age = (cachedNow || getNow()) - start;
42251
41784
  return ttl - age;
42252
41785
  };
42253
- this.#isStale = (index2) => {
42254
- const s = starts[index2];
42255
- const t = ttls[index2];
41786
+ this.#isStale = (index) => {
41787
+ const s = starts[index];
41788
+ const t = ttls[index];
42256
41789
  return !!t && !!s && (cachedNow || getNow()) - s > t;
42257
41790
  };
42258
41791
  }
@@ -42269,9 +41802,9 @@ var LRUCache2 = class _LRUCache {
42269
41802
  const sizes = new ZeroArray2(this.#max);
42270
41803
  this.#calculatedSize = 0;
42271
41804
  this.#sizes = sizes;
42272
- this.#removeItemSize = (index2) => {
42273
- this.#calculatedSize -= sizes[index2];
42274
- sizes[index2] = 0;
41805
+ this.#removeItemSize = (index) => {
41806
+ this.#calculatedSize -= sizes[index];
41807
+ sizes[index] = 0;
42275
41808
  };
42276
41809
  this.#requireSize = (k, v, size, sizeCalculation) => {
42277
41810
  if (this.#isBackgroundFetch(v)) {
@@ -42292,15 +41825,15 @@ var LRUCache2 = class _LRUCache {
42292
41825
  }
42293
41826
  return size;
42294
41827
  };
42295
- this.#addItemSize = (index2, size, status) => {
42296
- sizes[index2] = size;
41828
+ this.#addItemSize = (index, size, status) => {
41829
+ sizes[index] = size;
42297
41830
  if (this.#maxSize) {
42298
- const maxSize2 = this.#maxSize - sizes[index2];
41831
+ const maxSize2 = this.#maxSize - sizes[index];
42299
41832
  while (this.#calculatedSize > maxSize2) {
42300
41833
  this.#evict(true);
42301
41834
  }
42302
41835
  }
42303
- this.#calculatedSize += sizes[index2];
41836
+ this.#calculatedSize += sizes[index];
42304
41837
  if (status) {
42305
41838
  status.entrySize = size;
42306
41839
  status.totalCalculatedSize = this.#calculatedSize;
@@ -42351,8 +41884,8 @@ var LRUCache2 = class _LRUCache {
42351
41884
  }
42352
41885
  }
42353
41886
  }
42354
- #isValidIndex(index2) {
42355
- return index2 !== void 0 && this.#keyMap.get(this.#keyList[index2]) === index2;
41887
+ #isValidIndex(index) {
41888
+ return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
42356
41889
  }
42357
41890
  /**
42358
41891
  * Return a generator yielding `[key, value]` pairs,
@@ -42585,23 +42118,23 @@ var LRUCache2 = class _LRUCache {
42585
42118
  this.delete(k);
42586
42119
  return this;
42587
42120
  }
42588
- let index2 = this.#size === 0 ? void 0 : this.#keyMap.get(k);
42589
- if (index2 === void 0) {
42590
- index2 = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
42591
- this.#keyList[index2] = k;
42592
- this.#valList[index2] = v;
42593
- this.#keyMap.set(k, index2);
42594
- this.#next[this.#tail] = index2;
42595
- this.#prev[index2] = this.#tail;
42596
- this.#tail = index2;
42121
+ let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
42122
+ if (index === void 0) {
42123
+ index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
42124
+ this.#keyList[index] = k;
42125
+ this.#valList[index] = v;
42126
+ this.#keyMap.set(k, index);
42127
+ this.#next[this.#tail] = index;
42128
+ this.#prev[index] = this.#tail;
42129
+ this.#tail = index;
42597
42130
  this.#size++;
42598
- this.#addItemSize(index2, size, status);
42131
+ this.#addItemSize(index, size, status);
42599
42132
  if (status)
42600
42133
  status.set = "add";
42601
42134
  noUpdateTTL = false;
42602
42135
  } else {
42603
- this.#moveToTail(index2);
42604
- const oldVal = this.#valList[index2];
42136
+ this.#moveToTail(index);
42137
+ const oldVal = this.#valList[index];
42605
42138
  if (v !== oldVal) {
42606
42139
  if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
42607
42140
  oldVal.__abortController.abort(new Error("replaced"));
@@ -42622,9 +42155,9 @@ var LRUCache2 = class _LRUCache {
42622
42155
  this.#disposed?.push([oldVal, k, "set"]);
42623
42156
  }
42624
42157
  }
42625
- this.#removeItemSize(index2);
42626
- this.#addItemSize(index2, size, status);
42627
- this.#valList[index2] = v;
42158
+ this.#removeItemSize(index);
42159
+ this.#addItemSize(index, size, status);
42160
+ this.#valList[index] = v;
42628
42161
  if (status) {
42629
42162
  status.set = "replace";
42630
42163
  const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
@@ -42640,10 +42173,10 @@ var LRUCache2 = class _LRUCache {
42640
42173
  }
42641
42174
  if (this.#ttls) {
42642
42175
  if (!noUpdateTTL) {
42643
- this.#setItemTTL(index2, ttl, start);
42176
+ this.#setItemTTL(index, ttl, start);
42644
42177
  }
42645
42178
  if (status)
42646
- this.#statusTTL(status, index2);
42179
+ this.#statusTTL(status, index);
42647
42180
  }
42648
42181
  if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
42649
42182
  const dt = this.#disposed;
@@ -42721,24 +42254,24 @@ var LRUCache2 = class _LRUCache {
42721
42254
  */
42722
42255
  has(k, hasOptions = {}) {
42723
42256
  const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
42724
- const index2 = this.#keyMap.get(k);
42725
- if (index2 !== void 0) {
42726
- const v = this.#valList[index2];
42257
+ const index = this.#keyMap.get(k);
42258
+ if (index !== void 0) {
42259
+ const v = this.#valList[index];
42727
42260
  if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
42728
42261
  return false;
42729
42262
  }
42730
- if (!this.#isStale(index2)) {
42263
+ if (!this.#isStale(index)) {
42731
42264
  if (updateAgeOnHas) {
42732
- this.#updateItemAge(index2);
42265
+ this.#updateItemAge(index);
42733
42266
  }
42734
42267
  if (status) {
42735
42268
  status.has = "hit";
42736
- this.#statusTTL(status, index2);
42269
+ this.#statusTTL(status, index);
42737
42270
  }
42738
42271
  return true;
42739
42272
  } else if (status) {
42740
42273
  status.has = "stale";
42741
- this.#statusTTL(status, index2);
42274
+ this.#statusTTL(status, index);
42742
42275
  }
42743
42276
  } else if (status) {
42744
42277
  status.has = "miss";
@@ -42754,15 +42287,15 @@ var LRUCache2 = class _LRUCache {
42754
42287
  */
42755
42288
  peek(k, peekOptions = {}) {
42756
42289
  const { allowStale = this.allowStale } = peekOptions;
42757
- const index2 = this.#keyMap.get(k);
42758
- if (index2 === void 0 || !allowStale && this.#isStale(index2)) {
42290
+ const index = this.#keyMap.get(k);
42291
+ if (index === void 0 || !allowStale && this.#isStale(index)) {
42759
42292
  return;
42760
42293
  }
42761
- const v = this.#valList[index2];
42294
+ const v = this.#valList[index];
42762
42295
  return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
42763
42296
  }
42764
- #backgroundFetch(k, index2, options, context) {
42765
- const v = index2 === void 0 ? void 0 : this.#valList[index2];
42297
+ #backgroundFetch(k, index, options, context) {
42298
+ const v = index === void 0 ? void 0 : this.#valList[index];
42766
42299
  if (this.#isBackgroundFetch(v)) {
42767
42300
  return v;
42768
42301
  }
@@ -42793,10 +42326,10 @@ var LRUCache2 = class _LRUCache {
42793
42326
  return fetchFail(ac.signal.reason);
42794
42327
  }
42795
42328
  const bf2 = p;
42796
- if (this.#valList[index2] === p) {
42329
+ if (this.#valList[index] === p) {
42797
42330
  if (v2 === void 0) {
42798
42331
  if (bf2.__staleWhileFetching) {
42799
- this.#valList[index2] = bf2.__staleWhileFetching;
42332
+ this.#valList[index] = bf2.__staleWhileFetching;
42800
42333
  } else {
42801
42334
  this.delete(k);
42802
42335
  }
@@ -42821,12 +42354,12 @@ var LRUCache2 = class _LRUCache {
42821
42354
  const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
42822
42355
  const noDelete = allowStale || options.noDeleteOnFetchRejection;
42823
42356
  const bf2 = p;
42824
- if (this.#valList[index2] === p) {
42357
+ if (this.#valList[index] === p) {
42825
42358
  const del = !noDelete || bf2.__staleWhileFetching === void 0;
42826
42359
  if (del) {
42827
42360
  this.delete(k);
42828
42361
  } else if (!allowStaleAborted) {
42829
- this.#valList[index2] = bf2.__staleWhileFetching;
42362
+ this.#valList[index] = bf2.__staleWhileFetching;
42830
42363
  }
42831
42364
  }
42832
42365
  if (allowStale) {
@@ -42860,11 +42393,11 @@ var LRUCache2 = class _LRUCache {
42860
42393
  __staleWhileFetching: v,
42861
42394
  __returned: void 0
42862
42395
  });
42863
- if (index2 === void 0) {
42396
+ if (index === void 0) {
42864
42397
  this.set(k, bf, { ...fetchOpts.options, status: void 0 });
42865
- index2 = this.#keyMap.get(k);
42398
+ index = this.#keyMap.get(k);
42866
42399
  } else {
42867
- this.#valList[index2] = bf;
42400
+ this.#valList[index] = bf;
42868
42401
  }
42869
42402
  return bf;
42870
42403
  }
@@ -42922,14 +42455,14 @@ var LRUCache2 = class _LRUCache {
42922
42455
  status,
42923
42456
  signal
42924
42457
  };
42925
- let index2 = this.#keyMap.get(k);
42926
- if (index2 === void 0) {
42458
+ let index = this.#keyMap.get(k);
42459
+ if (index === void 0) {
42927
42460
  if (status)
42928
42461
  status.fetch = "miss";
42929
- const p = this.#backgroundFetch(k, index2, options, context);
42462
+ const p = this.#backgroundFetch(k, index, options, context);
42930
42463
  return p.__returned = p;
42931
42464
  } else {
42932
- const v = this.#valList[index2];
42465
+ const v = this.#valList[index];
42933
42466
  if (this.#isBackgroundFetch(v)) {
42934
42467
  const stale = allowStale && v.__staleWhileFetching !== void 0;
42935
42468
  if (status) {
@@ -42939,19 +42472,19 @@ var LRUCache2 = class _LRUCache {
42939
42472
  }
42940
42473
  return stale ? v.__staleWhileFetching : v.__returned = v;
42941
42474
  }
42942
- const isStale = this.#isStale(index2);
42475
+ const isStale = this.#isStale(index);
42943
42476
  if (!forceRefresh && !isStale) {
42944
42477
  if (status)
42945
42478
  status.fetch = "hit";
42946
- this.#moveToTail(index2);
42479
+ this.#moveToTail(index);
42947
42480
  if (updateAgeOnGet) {
42948
- this.#updateItemAge(index2);
42481
+ this.#updateItemAge(index);
42949
42482
  }
42950
42483
  if (status)
42951
- this.#statusTTL(status, index2);
42484
+ this.#statusTTL(status, index);
42952
42485
  return v;
42953
42486
  }
42954
- const p = this.#backgroundFetch(k, index2, options, context);
42487
+ const p = this.#backgroundFetch(k, index, options, context);
42955
42488
  const hasStale = p.__staleWhileFetching !== void 0;
42956
42489
  const staleVal = hasStale && allowStale;
42957
42490
  if (status) {
@@ -42970,13 +42503,13 @@ var LRUCache2 = class _LRUCache {
42970
42503
  */
42971
42504
  get(k, getOptions = {}) {
42972
42505
  const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
42973
- const index2 = this.#keyMap.get(k);
42974
- if (index2 !== void 0) {
42975
- const value = this.#valList[index2];
42506
+ const index = this.#keyMap.get(k);
42507
+ if (index !== void 0) {
42508
+ const value = this.#valList[index];
42976
42509
  const fetching = this.#isBackgroundFetch(value);
42977
42510
  if (status)
42978
- this.#statusTTL(status, index2);
42979
- if (this.#isStale(index2)) {
42511
+ this.#statusTTL(status, index);
42512
+ if (this.#isStale(index)) {
42980
42513
  if (status)
42981
42514
  status.get = "stale";
42982
42515
  if (!fetching) {
@@ -42998,9 +42531,9 @@ var LRUCache2 = class _LRUCache {
42998
42531
  if (fetching) {
42999
42532
  return value.__staleWhileFetching;
43000
42533
  }
43001
- this.#moveToTail(index2);
42534
+ this.#moveToTail(index);
43002
42535
  if (updateAgeOnGet) {
43003
- this.#updateItemAge(index2);
42536
+ this.#updateItemAge(index);
43004
42537
  }
43005
42538
  return value;
43006
42539
  }
@@ -43012,15 +42545,15 @@ var LRUCache2 = class _LRUCache {
43012
42545
  this.#prev[n] = p;
43013
42546
  this.#next[p] = n;
43014
42547
  }
43015
- #moveToTail(index2) {
43016
- if (index2 !== this.#tail) {
43017
- if (index2 === this.#head) {
43018
- this.#head = this.#next[index2];
42548
+ #moveToTail(index) {
42549
+ if (index !== this.#tail) {
42550
+ if (index === this.#head) {
42551
+ this.#head = this.#next[index];
43019
42552
  } else {
43020
- this.#connect(this.#prev[index2], this.#next[index2]);
42553
+ this.#connect(this.#prev[index], this.#next[index]);
43021
42554
  }
43022
- this.#connect(this.#tail, index2);
43023
- this.#tail = index2;
42555
+ this.#connect(this.#tail, index);
42556
+ this.#tail = index;
43024
42557
  }
43025
42558
  }
43026
42559
  /**
@@ -43030,14 +42563,14 @@ var LRUCache2 = class _LRUCache {
43030
42563
  delete(k) {
43031
42564
  let deleted = false;
43032
42565
  if (this.#size !== 0) {
43033
- const index2 = this.#keyMap.get(k);
43034
- if (index2 !== void 0) {
42566
+ const index = this.#keyMap.get(k);
42567
+ if (index !== void 0) {
43035
42568
  deleted = true;
43036
42569
  if (this.#size === 1) {
43037
42570
  this.clear();
43038
42571
  } else {
43039
- this.#removeItemSize(index2);
43040
- const v = this.#valList[index2];
42572
+ this.#removeItemSize(index);
42573
+ const v = this.#valList[index];
43041
42574
  if (this.#isBackgroundFetch(v)) {
43042
42575
  v.__abortController.abort(new Error("deleted"));
43043
42576
  } else if (this.#hasDispose || this.#hasDisposeAfter) {
@@ -43049,20 +42582,20 @@ var LRUCache2 = class _LRUCache {
43049
42582
  }
43050
42583
  }
43051
42584
  this.#keyMap.delete(k);
43052
- this.#keyList[index2] = void 0;
43053
- this.#valList[index2] = void 0;
43054
- if (index2 === this.#tail) {
43055
- this.#tail = this.#prev[index2];
43056
- } else if (index2 === this.#head) {
43057
- this.#head = this.#next[index2];
42585
+ this.#keyList[index] = void 0;
42586
+ this.#valList[index] = void 0;
42587
+ if (index === this.#tail) {
42588
+ this.#tail = this.#prev[index];
42589
+ } else if (index === this.#head) {
42590
+ this.#head = this.#next[index];
43058
42591
  } else {
43059
- const pi = this.#prev[index2];
43060
- this.#next[pi] = this.#next[index2];
43061
- const ni = this.#next[index2];
43062
- this.#prev[ni] = this.#prev[index2];
42592
+ const pi = this.#prev[index];
42593
+ this.#next[pi] = this.#next[index];
42594
+ const ni = this.#next[index];
42595
+ this.#prev[ni] = this.#prev[index];
43063
42596
  }
43064
42597
  this.#size--;
43065
- this.#free.push(index2);
42598
+ this.#free.push(index);
43066
42599
  }
43067
42600
  }
43068
42601
  }
@@ -43079,12 +42612,12 @@ var LRUCache2 = class _LRUCache {
43079
42612
  * Clear the cache entirely, throwing away all values.
43080
42613
  */
43081
42614
  clear() {
43082
- for (const index2 of this.#rindexes({ allowStale: true })) {
43083
- const v = this.#valList[index2];
42615
+ for (const index of this.#rindexes({ allowStale: true })) {
42616
+ const v = this.#valList[index];
43084
42617
  if (this.#isBackgroundFetch(v)) {
43085
42618
  v.__abortController.abort(new Error("deleted"));
43086
42619
  } else {
43087
- const k = this.#keyList[index2];
42620
+ const k = this.#keyList[index];
43088
42621
  if (this.#hasDispose) {
43089
42622
  this.#dispose?.(v, k, "delete");
43090
42623
  }
@@ -43222,9 +42755,9 @@ var CheckpointDB4 = class _CheckpointDB {
43222
42755
  return value2;
43223
42756
  }
43224
42757
  }
43225
- for (let index2 = this.checkpoints.length - 1; index2 >= 0; index2--) {
43226
- if (this.checkpoints[index2].keyValueMap.has(keyHex)) {
43227
- return this.checkpoints[index2].keyValueMap.get(keyHex);
42758
+ for (let index = this.checkpoints.length - 1; index >= 0; index--) {
42759
+ if (this.checkpoints[index].keyValueMap.has(keyHex)) {
42760
+ return this.checkpoints[index].keyValueMap.get(keyHex);
43228
42761
  }
43229
42762
  }
43230
42763
  const value = await this.db.get(keyHex, {
@@ -45296,7 +44829,7 @@ function valuesArrayToHeaderData2(values) {
45296
44829
  number2,
45297
44830
  gasLimit,
45298
44831
  gasUsed,
45299
- timestamp2,
44832
+ timestamp,
45300
44833
  extraData,
45301
44834
  mixHash,
45302
44835
  nonce,
@@ -45325,7 +44858,7 @@ function valuesArrayToHeaderData2(values) {
45325
44858
  ...number2 !== void 0 ? { number: number2 } : {},
45326
44859
  ...gasLimit !== void 0 ? { gasLimit } : {},
45327
44860
  ...gasUsed !== void 0 ? { gasUsed } : {},
45328
- ...timestamp2 !== void 0 ? { timestamp: timestamp2 } : {},
44861
+ ...timestamp !== void 0 ? { timestamp } : {},
45329
44862
  ...extraData !== void 0 ? { extraData } : {},
45330
44863
  ...mixHash !== void 0 ? { mixHash } : {},
45331
44864
  ...nonce !== void 0 ? { nonce } : {},
@@ -45486,7 +45019,7 @@ var BlockHeader2 = class _BlockHeader {
45486
45019
  const number2 = safeToType(headerData.number, 1) ?? defaults2.number;
45487
45020
  const gasLimit = safeToType(headerData.gasLimit, 1) ?? defaults2.gasLimit;
45488
45021
  const gasUsed = safeToType(headerData.gasUsed, 1) ?? defaults2.gasUsed;
45489
- const timestamp2 = safeToType(headerData.timestamp, 1) ?? defaults2.timestamp;
45022
+ const timestamp = safeToType(headerData.timestamp, 1) ?? defaults2.timestamp;
45490
45023
  const extraData = safeToType(headerData.extraData, 2) ?? defaults2.extraData;
45491
45024
  const mixHash = safeToType(headerData.mixHash, 2) ?? defaults2.mixHash;
45492
45025
  const nonce = safeToType(headerData.nonce, 2) ?? defaults2.nonce;
@@ -45494,12 +45027,12 @@ var BlockHeader2 = class _BlockHeader {
45494
45027
  if (setHardfork === true) {
45495
45028
  this.common.ethjsCommon.setHardforkBy({
45496
45029
  blockNumber: number2,
45497
- timestamp: timestamp2
45030
+ timestamp
45498
45031
  });
45499
45032
  } else if (typeof setHardfork !== "boolean") {
45500
45033
  this.common.ethjsCommon.setHardforkBy({
45501
45034
  blockNumber: number2,
45502
- timestamp: timestamp2
45035
+ timestamp
45503
45036
  });
45504
45037
  }
45505
45038
  const hardforkDefaults = {
@@ -45547,7 +45080,7 @@ var BlockHeader2 = class _BlockHeader {
45547
45080
  this.number = number2;
45548
45081
  this.gasLimit = gasLimit;
45549
45082
  this.gasUsed = gasUsed;
45550
- this.timestamp = timestamp2;
45083
+ this.timestamp = timestamp;
45551
45084
  this.extraData = extraData;
45552
45085
  this.mixHash = mixHash;
45553
45086
  this.nonce = nonce;
@@ -46310,8 +45843,8 @@ var Block2 = class _Block {
46310
45843
  for (const uncleHeaderData of uhsData ?? []) {
46311
45844
  uncleHeaders.push(BlockHeader2.fromValuesArray(uncleHeaderData, uncleOpts));
46312
45845
  }
46313
- const withdrawals = withdrawalBytes?.map(([index2, validatorIndex, address, amount]) => ({
46314
- index: index2,
45846
+ const withdrawals = withdrawalBytes?.map(([index, validatorIndex, address, amount]) => ({
45847
+ index,
46315
45848
  validatorIndex,
46316
45849
  address,
46317
45850
  amount
@@ -46350,14 +45883,14 @@ var Block2 = class _Block {
46350
45883
  executionWitness
46351
45884
  } = payload;
46352
45885
  const txs = [];
46353
- for (const [index2, serializedTx] of transactions.entries()) {
45886
+ for (const [index, serializedTx] of transactions.entries()) {
46354
45887
  try {
46355
45888
  const tx = createTxFromRLP(utils.hexToBytes(serializedTx), {
46356
45889
  common: opts?.common.ethjsCommon
46357
45890
  });
46358
45891
  txs.push(tx);
46359
45892
  } catch (error) {
46360
- const validationError2 = `Invalid tx at index ${index2}: ${error}`;
45893
+ const validationError2 = `Invalid tx at index ${index}: ${error}`;
46361
45894
  throw validationError2;
46362
45895
  }
46363
45896
  }
@@ -46607,9 +46140,9 @@ var Block2 = class _Block {
46607
46140
  return;
46608
46141
  }
46609
46142
  if (verifyTxs) {
46610
- for (const [index2, tx] of this.transactions.entries()) {
46143
+ for (const [index, tx] of this.transactions.entries()) {
46611
46144
  if (!tx.isSigned()) {
46612
- const msg = this._errorMsg(`invalid transactions: transaction at index ${index2} is unsigned`);
46145
+ const msg = this._errorMsg(`invalid transactions: transaction at index ${index} is unsigned`);
46613
46146
  throw new Error(msg);
46614
46147
  }
46615
46148
  }
@@ -46835,7 +46368,7 @@ function blockHeaderFromRpc(blockParams, options) {
46835
46368
  number: number2,
46836
46369
  gasLimit,
46837
46370
  gasUsed,
46838
- timestamp: timestamp2,
46371
+ timestamp,
46839
46372
  extraData,
46840
46373
  mixHash,
46841
46374
  nonce,
@@ -46859,7 +46392,7 @@ function blockHeaderFromRpc(blockParams, options) {
46859
46392
  number: number2,
46860
46393
  gasLimit,
46861
46394
  gasUsed,
46862
- timestamp: timestamp2,
46395
+ timestamp,
46863
46396
  extraData,
46864
46397
  mixHash,
46865
46398
  nonce,
@@ -47422,11 +46955,11 @@ var Evm = class _Evm extends EVM {
47422
46955
  "Custom precompiles is empty. This is an internal bug as it should always be defined"
47423
46956
  );
47424
46957
  }
47425
- const index2 = this._customPrecompiles.indexOf(precompile);
47426
- if (index2 === -1) {
46958
+ const index = this._customPrecompiles.indexOf(precompile);
46959
+ if (index === -1) {
47427
46960
  throw new InvalidParamsError("Precompile not found");
47428
46961
  }
47429
- this._customPrecompiles.splice(index2, 1);
46962
+ this._customPrecompiles.splice(index, 1);
47430
46963
  this._precompiles = getActivePrecompiles(this.common, this._customPrecompiles);
47431
46964
  }
47432
46965
  /**
@@ -47681,8 +47214,8 @@ var ReceiptsManager = class _ReceiptsManager {
47681
47214
  const block = value;
47682
47215
  if (operation === 0) {
47683
47216
  for (const [i, tx] of block.transactions.entries()) {
47684
- const index2 = [block.hash(), i];
47685
- const encoded = this.rlp(0, 2, index2);
47217
+ const index = [block.hash(), i];
47218
+ const encoded = this.rlp(0, 2, index);
47686
47219
  await this.mapDb.put("TxHash", tx.hash(), encoded);
47687
47220
  }
47688
47221
  } else if (operation === 1) {
@@ -49369,12 +48902,12 @@ createBlockHeader();
49369
48902
 
49370
48903
  // ../../node_modules/.pnpm/@tevm+vm@1.0.0-next.147_typescript@5.8.3_viem@2.33.1_typescript@5.8.3_zod@3.25.67__zod@3.25.67/node_modules/@tevm/vm/dist/index.js
49371
48904
  var parentBeaconBlockRootAddress2 = createAddressFromString("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02");
49372
- var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp2) => {
48905
+ var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp) => {
49373
48906
  if (!vm.common.ethjsCommon.isActivatedEIP(4788)) {
49374
48907
  throw new EipNotEnabledError("Cannot call `accumulateParentBeaconBlockRoot`: EIP 4788 is not active");
49375
48908
  }
49376
48909
  const historicalRootsLength = 8191n;
49377
- const timestampIndex = timestamp2 % historicalRootsLength;
48910
+ const timestampIndex = timestamp % historicalRootsLength;
49378
48911
  const timestampExtended = timestampIndex + historicalRootsLength;
49379
48912
  if (await vm.stateManager.getAccount(parentBeaconBlockRootAddress2) === void 0) {
49380
48913
  await vm.evm.journal.putAccount(parentBeaconBlockRootAddress2, new Account());
@@ -49382,7 +48915,7 @@ var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp2) => {
49382
48915
  await vm.stateManager.putStorage(
49383
48916
  parentBeaconBlockRootAddress2,
49384
48917
  setLengthLeft(utils.toBytes(timestampIndex), 32),
49385
- utils.toBytes(timestamp2)
48918
+ utils.toBytes(timestamp)
49386
48919
  );
49387
48920
  await vm.stateManager.putStorage(parentBeaconBlockRootAddress2, setLengthLeft(utils.toBytes(timestampExtended), 32), root2);
49388
48921
  };
@@ -50431,7 +49964,7 @@ var BlockBuilder2 = class {
50431
49964
  const receiptTrie = await this.receiptTrie();
50432
49965
  const logsBloom = this.logsBloom();
50433
49966
  const gasUsed = this.gasUsed;
50434
- const timestamp2 = this.headerData.timestamp ?? 0n;
49967
+ const timestamp = this.headerData.timestamp ?? 0n;
50435
49968
  let blobGasUsed = void 0;
50436
49969
  if (this.vm.common.ethjsCommon.isActivatedEIP(4844) === true) {
50437
49970
  blobGasUsed = this.blobGasUsed;
@@ -50445,7 +49978,7 @@ var BlockBuilder2 = class {
50445
49978
  receiptTrie,
50446
49979
  logsBloom,
50447
49980
  gasUsed,
50448
- timestamp: timestamp2
49981
+ timestamp
50449
49982
  // correct excessBlobGas should already be part of headerData used above
50450
49983
  };
50451
49984
  if (consensusType === ConsensusType.ProofOfWork) {
@@ -50474,8 +50007,8 @@ var BlockBuilder2 = class {
50474
50007
  await this.vm.evm.journal.checkpoint();
50475
50008
  this.checkpointed = true;
50476
50009
  }
50477
- const { parentBeaconBlockRoot, timestamp: timestamp2 } = this.headerData;
50478
- const timestampValue = timestamp2 ?? 0n;
50010
+ const { parentBeaconBlockRoot, timestamp } = this.headerData;
50011
+ const timestampValue = timestamp ?? 0n;
50479
50012
  const timestampBigInt = toType(timestampValue, TypeOutput.BigInt) ?? 0n;
50480
50013
  const parentBeaconBlockRootBuf = parentBeaconBlockRoot ? toType(parentBeaconBlockRoot, TypeOutput.Uint8Array) : new Uint8Array(32);
50481
50014
  await accumulateParentBeaconBlockRoot2(this.vm)(
@@ -50883,9 +50416,9 @@ var createTevmNode = (options = {}) => {
50883
50416
  removeListener(eventName, listener) {
50884
50417
  const listeners = events.get(eventName);
50885
50418
  if (listeners) {
50886
- const index2 = listeners.findIndex((l) => l === listener);
50887
- if (index2 !== -1) {
50888
- listeners.splice(index2, 1);
50419
+ const index = listeners.findIndex((l) => l === listener);
50420
+ if (index !== -1) {
50421
+ listeners.splice(index, 1);
50889
50422
  if (listeners.length === 0) {
50890
50423
  events.delete(eventName);
50891
50424
  }
@@ -51717,12 +51250,12 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
51717
51250
  const receiptsManager = await client.getReceiptsManager();
51718
51251
  for (let count = 0; count < blockCount; count++) {
51719
51252
  const parentBlock = await vm.blockchain.getCanonicalHeadBlock();
51720
- let timestamp2 = Math.max(Math.floor(Date.now() / 1e3), Number(parentBlock.header.timestamp));
51721
- timestamp2 = count === 0 ? timestamp2 : timestamp2 + interval;
51253
+ let timestamp = Math.max(Math.floor(Date.now() / 1e3), Number(parentBlock.header.timestamp));
51254
+ timestamp = count === 0 ? timestamp : timestamp + interval;
51722
51255
  const blockBuilder = await vm.buildBlock({
51723
51256
  parentBlock,
51724
51257
  headerData: {
51725
- timestamp: timestamp2,
51258
+ timestamp,
51726
51259
  number: parentBlock.header.number + 1n,
51727
51260
  // The following 2 are currently not supported
51728
51261
  // difficulty: undefined,
@@ -51751,13 +51284,13 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
51751
51284
  ] : await pool.txsByPriceAndNonce({
51752
51285
  baseFee: parentBlock.header.calcNextBaseFee()
51753
51286
  });
51754
- let index2 = 0;
51287
+ let index = 0;
51755
51288
  const blockFull = false;
51756
51289
  const receipts = [];
51757
- while (index2 < orderedTx.length && !blockFull) {
51290
+ while (index < orderedTx.length && !blockFull) {
51758
51291
  const nextTx = (
51759
51292
  /** @type {import('@tevm/tx').TypedTransaction}*/
51760
- orderedTx[index2]
51293
+ orderedTx[index]
51761
51294
  );
51762
51295
  client.logger.debug(utils.bytesToHex(nextTx.hash()), "new tx added");
51763
51296
  const txResult = await blockBuilder.addTransaction(nextTx, {
@@ -51766,7 +51299,7 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
51766
51299
  skipHardForkValidation: true
51767
51300
  });
51768
51301
  receipts.push(txResult.receipt);
51769
- index2++;
51302
+ index++;
51770
51303
  }
51771
51304
  await vm.stateManager.checkpoint();
51772
51305
  const createNewStateRoot = true;
@@ -57547,9 +57080,6 @@ function getLogger() {
57547
57080
  return loggerContext.getStore() ?? defaultLogger();
57548
57081
  }
57549
57082
 
57550
- // src/index.node.ts
57551
- __reExport(index_node_exports, OfferDB_exports2);
57552
-
57553
57083
  // src/RouterEvent.ts
57554
57084
  var RouterEvent_exports = {};
57555
57085
  __export(RouterEvent_exports, {
@@ -57675,14 +57205,14 @@ function morpho(parameters) {
57675
57205
  );
57676
57206
  const buyOffersEmptyCallback = batch2(
57677
57207
  "buy_offers_empty_callback",
57678
- async (offers2, { publicClients }) => {
57208
+ async (offers, { publicClients }) => {
57679
57209
  const issues = /* @__PURE__ */ new Map();
57680
57210
  const hashToIndex = /* @__PURE__ */ new Map();
57681
- for (let i = 0; i < offers2.length; i++) {
57682
- const offer = offers2[i];
57211
+ for (let i = 0; i < offers.length; i++) {
57212
+ const offer = offers[i];
57683
57213
  hashToIndex.set(offer.hash, i);
57684
57214
  }
57685
- const { buyOffers, sellOffers: _sellOffers } = offers2.reduce(
57215
+ const { buyOffers, sellOffers: _sellOffers } = offers.reduce(
57686
57216
  (acc, offer) => {
57687
57217
  offer.buy ? acc.buyOffers.push(offer) : issues.set(hashToIndex.get(offer.hash), {
57688
57218
  message: "Onchain callback for sell offers is not supported yet."
@@ -57695,9 +57225,9 @@ function morpho(parameters) {
57695
57225
  for (const offer of buyOffers) {
57696
57226
  const chainName = getChain(offer.chainId)?.name;
57697
57227
  const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
57698
- const offers3 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
57699
- offers3.push(offer);
57700
- loanTokens.set(offer.loanToken.toLowerCase(), offers3);
57228
+ const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
57229
+ offers2.push(offer);
57230
+ loanTokens.set(offer.loanToken.toLowerCase(), offers2);
57701
57231
  buyOffersPerLoanAsset.set(chainName, loanTokens);
57702
57232
  }
57703
57233
  await Promise.all(
@@ -57706,8 +57236,8 @@ function morpho(parameters) {
57706
57236
  const publicClient = publicClients[chainName];
57707
57237
  const morpho2 = morphoPerChain.get(chains[chainName].id);
57708
57238
  if (!publicClient) {
57709
- const offers3 = Array.from(loanTokens.values()).flat();
57710
- for (const offer of offers3) {
57239
+ const offers2 = Array.from(loanTokens.values()).flat();
57240
+ for (const offer of offers2) {
57711
57241
  issues.set(hashToIndex.get(offer.hash), {
57712
57242
  message: `Public client for chain "${chainName}" is not available`
57713
57243
  });
@@ -57716,9 +57246,9 @@ function morpho(parameters) {
57716
57246
  }
57717
57247
  const balances = /* @__PURE__ */ new Map();
57718
57248
  const allowances = /* @__PURE__ */ new Map();
57719
- for (const [loanToken2, offers3] of loanTokens) {
57249
+ for (const [loanToken2, offers2] of loanTokens) {
57720
57250
  const data = await Promise.all(
57721
- offers3.flatMap((offer) => [
57251
+ offers2.flatMap((offer) => [
57722
57252
  publicClient.readContract({
57723
57253
  address: loanToken2,
57724
57254
  abi: viem.parseAbi([
@@ -57737,8 +57267,8 @@ function morpho(parameters) {
57737
57267
  })
57738
57268
  ])
57739
57269
  );
57740
- for (let i = 0; i < offers3.length; i++) {
57741
- const user = offers3[i].offering.toLowerCase();
57270
+ for (let i = 0; i < offers2.length; i++) {
57271
+ const user = offers2[i].offering.toLowerCase();
57742
57272
  const balance = data[i * 2] || 0n;
57743
57273
  const allowance = data[i * 2 + 1] || 0n;
57744
57274
  const userBalances = balances.get(user) ?? /* @__PURE__ */ new Map();
@@ -57819,23 +57349,13 @@ exports.ApiSchema = apiSchema_exports;
57819
57349
  exports.Chain = Chain_exports;
57820
57350
  exports.EVM = EVM_exports;
57821
57351
  exports.Logger = Logger_exports;
57822
- exports.OfferDB = OfferDB_exports;
57823
- exports.OfferRepository = OfferRepository_exports;
57824
- exports.Router = core_exports;
57352
+ exports.OfferStore = OfferStore_exports;
57353
+ exports.Router = router_exports;
57825
57354
  exports.RouterEvent = RouterEvent_exports;
57826
57355
  exports.RouterOffer = RouterOffer_exports;
57356
+ exports.Utils = utils_exports;
57827
57357
  exports.Validation = Validation_exports;
57828
57358
  exports.ValidationRule = ValidationRule_exports;
57829
- exports.batch = batch;
57830
- exports.consumed = consumed;
57831
- exports.decodeCursor = decodeCursor;
57832
- exports.encodeCursor = encodeCursor;
57833
- exports.offerCollaterals = offerCollaterals;
57834
- exports.offerStatus = offerStatus;
57835
- exports.offers = offers;
57836
- exports.poll = poll;
57837
- exports.validateCursor = validateCursor;
57838
- exports.wait = wait;
57839
57359
  Object.keys(mempool).forEach(function (k) {
57840
57360
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
57841
57361
  enumerable: true,