@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.
- package/dist/index.browser.d.cts +129 -2
- package/dist/index.browser.d.ts +129 -2
- package/dist/index.browser.js +377 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +377 -5
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +101 -719
- package/dist/index.node.d.ts +101 -719
- package/dist/index.node.js +735 -1215
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +734 -1204
- package/dist/index.node.mjs.map +1 -1
- package/package.json +3 -12
- package/dist/drizzle/0000_add-offers-table.sql +0 -37
- package/dist/drizzle/0001_create_offer_status_relation.sql +0 -10
- package/dist/drizzle/0002_add_created_at_in_offer_status_relation.sql +0 -3
- package/dist/drizzle/0003_add-cursor-indices-to-offers.sql +0 -6
- package/dist/drizzle/0004_offer-start.sql +0 -1
- package/dist/drizzle/0005_rename-price-token-buy.sql +0 -8
- package/dist/drizzle/0006_rename-buy.sql +0 -3
- package/dist/drizzle/0007_rename-offering.sql +0 -3
- package/dist/drizzle/0008_add-consumed-relation.sql +0 -10
- package/dist/drizzle/meta/0000_snapshot.json +0 -344
- package/dist/drizzle/meta/0001_snapshot.json +0 -426
- package/dist/drizzle/meta/0002_snapshot.json +0 -439
- package/dist/drizzle/meta/0003_snapshot.json +0 -553
- package/dist/drizzle/meta/0004_snapshot.json +0 -559
- package/dist/drizzle/meta/0005_snapshot.json +0 -559
- package/dist/drizzle/meta/0006_snapshot.json +0 -559
- package/dist/drizzle/meta/0007_snapshot.json +0 -559
- package/dist/drizzle/meta/0008_snapshot.json +0 -635
- package/dist/drizzle/meta/_journal.json +0 -69
package/dist/index.node.mjs
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import { Errors, Offer, Format,
|
|
1
|
+
import { Errors, Offer, Format, Time, Maturity, LLTV, Mempool } from '@morpho-dev/mempool';
|
|
2
2
|
export * from '@morpho-dev/mempool';
|
|
3
3
|
import { base, mainnet, optimism, foundry, abstractTestnet, acala, ancient8, ancient8Sepolia, anvil, apexTestnet, arbitrum, arbitrumGoerli, arbitrumNova, assetChainTestnet, astar, astarZkEVM, astarZkyoto, arbitrumSepolia, areonNetwork, areonNetworkTestnet, artelaTestnet, atletaOlympia, aurora, auroraTestnet, auroria, avalanche, avalancheFuji, b3Sepolia, b3, bahamut, baseGoerli, baseSepolia, beam, beamTestnet, bearNetworkChainMainnet, bearNetworkChainTestnet, berachainTestnet, berachainTestnetbArtio, bevmMainnet, bitkub, bitkubTestnet, bitTorrent, bitTorrentTestnet, blast, blastSepolia, bob, bobSepolia, boba, bobaSepolia, botanixTestnet, bronos, bronosTestnet, bsc, bscTestnet, bscGreenfield, btr, btrTestnet, bxn, bxnTestnet, canto, celo, celoAlfajores, chiliz, chips, classic, confluxESpace, confluxESpaceTestnet, coreDao, crab, cronos, cronoszkEVM, cronoszkEVMTestnet, cronosTestnet, crossbell, curtis, cyber, cyberTestnet, darwinia, dchain, dchainTestnet, defichainEvm, defichainEvmTestnet, degen, dfk, dodochainTestnet, dogechain, dreyerxMainnet, dreyerxTestnet, edgeless, edgelessTestnet, edgeware, edgewareTestnet, eon, eos, eosTestnet, etherlink, etherlinkTestnet, evmos, evmosTestnet, ekta, ektaTestnet, fantom, fantomSonicTestnet, fantomTestnet, fibo, filecoin, filecoinCalibration, filecoinHyperspace, flare, flareTestnet, flowPreviewnet, flowMainnet, flowTestnet, fluence, fluenceStage, fluenceTestnet, forma, fraxtal, fraxtalTestnet, funkiMainnet, funkiSepolia, fuse, fuseSparknet, iotex, iotexTestnet, jbc, jbcTestnet, karura, gobi, goerli, gnosis, gnosisChiado, gravity, ham, hardhat, harmonyOne, hashkeyTestnet, haqqMainnet, haqqTestedge2, hedera, hederaTestnet, hederaPreviewnet, holesky, immutableZkEvm, immutableZkEvmTestnet, inEVM, iota, iotaTestnet, kakarotSepolia, kava, kavaTestnet, kcc, klaytn, klaytnBaobab, kaia, kairos, koi, kroma, kromaSepolia, l3x, l3xTestnet, lightlinkPegasus, lightlinkPhoenix, linea, lineaGoerli, lineaSepolia, lineaTestnet, lisk, liskSepolia, localhost, lukso, luksoTestnet, lycan, lyra, mandala, manta, mantaSepoliaTestnet, mantaTestnet, mantle, mantleSepoliaTestnet, mantleTestnet, merlin, metachain, metachainIstanbul, metalL2, meter, meterTestnet, metis, metisGoerli, mev, mevTestnet, mintSepoliaTestnet, mode, modeTestnet, moonbaseAlpha, moonbeam, moonbeamDev, moonriver, morphHolesky, morphSepolia, nautilus, neonDevnet, neonMainnet, nexi, nexilix, oasys, oasisTestnet, okc, optimismGoerli, optimismSepolia, opBNB, opBNBTestnet, oortMainnetDev, otimDevnet, palm, palmTestnet, playfiAlbireo, pgn, pgnTestnet, phoenix, plinga, plumeTestnet, polygon, polygonAmoy, polygonMumbai, polygonZkEvm, polygonZkEvmCardona, polygonZkEvmTestnet, pulsechain, pulsechainV4, qMainnet, qTestnet, real, redbellyTestnet, redstone, reyaNetwork, rollux, rolluxTestnet, ronin, root, rootPorcini, rootstock, rootstockTestnet, rss3, rss3Sepolia, saigon, sapphire, sapphireTestnet, satoshiVM, satoshiVMTestnet, scroll, scrollSepolia, sei, seiDevnet, seiTestnet, sepolia, shapeSepolia, shimmer, shimmerTestnet, skaleBlockBrawlers, skaleCalypso, skaleCalypsoTestnet, skaleCryptoBlades, skaleCryptoColosseum, skaleEuropa, skaleEuropaTestnet, skaleExorde, skaleHumanProtocol, skaleNebula, skaleNebulaTestnet, skaleRazor, skaleTitan, skaleTitanTestnet, sketchpad, soneiumMinato, songbird, songbirdTestnet, sophonTestnet, spicy, shardeumSphinx, shibarium, shibariumTestnet, storyTestnet, stratis, syscoin, syscoinTestnet, taraxa, taiko, taikoHekla, taikoJolnir, taikoKatla, taikoTestnetSepolia, taraxaTestnet, telcoinTestnet, telos, telosTestnet, tenet, thaiChain, thunderTestnet, tron, unreal, vechain, wanchain, wanchainTestnet, wemix, wemixTestnet, xLayerTestnet, x1Testnet, xLayer, xai, xaiTestnet, xdc, xdcTestnet, xrSepolia, yooldoVerse, yooldoVerseTestnet, zetachain, zetachainAthensTestnet, zhejiang, zilliqa, zilliqaTestnet, zkFair, zkFairTestnet, zkLinkNova, zkLinkNovaSepoliaTestnet, zksync, zksyncInMemoryNode, zksyncLocalNode, zksyncSepoliaTestnet, zora, zoraSepolia, zoraTestnet, zircuitTestnet } from 'viem/chains';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
import { createDocument } from 'zod-openapi';
|
|
6
|
-
import { defineChain, hexToBytes as hexToBytes$1, bytesToHex as bytesToHex$1, maxUint256, keccak256 as keccak256$2, toHex, parseEther as parseEther$1, concatHex, pad, createClient, publicActions, walletActions, testActions, parseAbi as parseAbi$1, createTransport, withRetry, numberToHex as numberToHex$2, hexToBigInt as hexToBigInt$1, stringToHex as stringToHex$1, numberToBytes, encodeFunctionData as encodeFunctionData$1, createPublicClient, InternalRpcError, decodeFunctionResult as decodeFunctionResult$1 } from 'viem';
|
|
6
|
+
import { defineChain, hexToBytes as hexToBytes$1, bytesToHex as bytesToHex$1, maxUint256, parseUnits, keccak256 as keccak256$2, toHex, parseEther as parseEther$1, concatHex, pad, createClient, publicActions, walletActions, testActions, parseAbi as parseAbi$1, createTransport, withRetry, numberToHex as numberToHex$2, hexToBigInt as hexToBigInt$1, stringToHex as stringToHex$1, numberToBytes, encodeFunctionData as encodeFunctionData$1, createPublicClient, InternalRpcError, decodeFunctionResult as decodeFunctionResult$1 } from 'viem';
|
|
7
7
|
import { serve as serve$1 } from '@hono/node-server';
|
|
8
8
|
import { Hono } from 'hono';
|
|
9
|
-
import * as drizzle_orm_star from 'drizzle-orm';
|
|
10
|
-
import { desc, sql, eq, gte, lte, inArray, and, asc } from 'drizzle-orm';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
import { PGlite } from '@electric-sql/pglite';
|
|
13
|
-
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
14
|
-
import { migrate as migrate$1 } from 'drizzle-orm/node-postgres/migrator';
|
|
15
|
-
import { drizzle as drizzle$1 } from 'drizzle-orm/pglite';
|
|
16
|
-
import { migrate } from 'drizzle-orm/pglite/migrator';
|
|
17
|
-
import { Pool } from 'pg';
|
|
18
|
-
import { pgTable, timestamp, varchar, bigint, text, boolean, integer, index, serial, jsonb } from 'drizzle-orm/pg-core';
|
|
19
|
-
import { safeParseNumber } from '@morpho-org/blue-sdk-viem';
|
|
20
9
|
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
21
11
|
import * as nc from 'crypto';
|
|
22
12
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
23
13
|
import { hexToBytes as hexToBytes$2, parseEther, getAddress, keccak256 as keccak256$1, bytesToHex as bytesToHex$2, hexToBigInt, hexToNumber as hexToNumber$1, stringToHex, numberToHex as numberToHex$1, bytesToNumber, bytesToBigInt as bytesToBigInt$1, toHex as toHex$1, isHex, parseGwei, fromRlp, encodeFunctionData, decodeErrorResult, decodeFunctionResult, encodeDeployData, toBytes as toBytes$1, serializeTransaction, toRlp } from 'viem/utils';
|
|
@@ -43,15 +33,14 @@ var __export = (target, all) => {
|
|
|
43
33
|
for (var name in all)
|
|
44
34
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
45
35
|
};
|
|
46
|
-
var __copyProps = (to, from2, except,
|
|
36
|
+
var __copyProps = (to, from2, except, desc) => {
|
|
47
37
|
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
|
|
48
38
|
for (let key of __getOwnPropNames(from2))
|
|
49
39
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
50
|
-
__defProp(to, key, { get: () => from2[key], enumerable: !(
|
|
40
|
+
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
|
|
51
41
|
}
|
|
52
42
|
return to;
|
|
53
43
|
};
|
|
54
|
-
var __reExport = (target, mod5, secondTarget) => (__copyProps(target, mod5, "default"), secondTarget);
|
|
55
44
|
var __toESM = (mod5, isNodeMode, target) => (target = mod5 != null ? __create(__getProtoOf(mod5)) : {}, __copyProps(
|
|
56
45
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
57
46
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -385,18 +374,18 @@ var require_common = __commonJS({
|
|
|
385
374
|
if (typeof args[0] !== "string") {
|
|
386
375
|
args.unshift("%O");
|
|
387
376
|
}
|
|
388
|
-
let
|
|
377
|
+
let index = 0;
|
|
389
378
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match2, format) => {
|
|
390
379
|
if (match2 === "%%") {
|
|
391
380
|
return "%";
|
|
392
381
|
}
|
|
393
|
-
|
|
382
|
+
index++;
|
|
394
383
|
const formatter = createDebug.formatters[format];
|
|
395
384
|
if (typeof formatter === "function") {
|
|
396
|
-
const val = args[
|
|
385
|
+
const val = args[index];
|
|
397
386
|
match2 = formatter.call(self2, val);
|
|
398
|
-
args.splice(
|
|
399
|
-
|
|
387
|
+
args.splice(index, 1);
|
|
388
|
+
index--;
|
|
400
389
|
}
|
|
401
390
|
return match2;
|
|
402
391
|
});
|
|
@@ -631,15 +620,15 @@ var require_browser = __commonJS({
|
|
|
631
620
|
}
|
|
632
621
|
const c = "color: " + this.color;
|
|
633
622
|
args.splice(1, 0, c, "color: inherit");
|
|
634
|
-
let
|
|
623
|
+
let index = 0;
|
|
635
624
|
let lastC = 0;
|
|
636
625
|
args[0].replace(/%[a-zA-Z%]/g, (match2) => {
|
|
637
626
|
if (match2 === "%%") {
|
|
638
627
|
return;
|
|
639
628
|
}
|
|
640
|
-
|
|
629
|
+
index++;
|
|
641
630
|
if (match2 === "%c") {
|
|
642
|
-
lastC =
|
|
631
|
+
lastC = index;
|
|
643
632
|
}
|
|
644
633
|
});
|
|
645
634
|
args.splice(lastC, 0, c);
|
|
@@ -1241,8 +1230,8 @@ var require_req = __commonJS({
|
|
|
1241
1230
|
if (req.originalUrl) {
|
|
1242
1231
|
_req.url = req.originalUrl;
|
|
1243
1232
|
} else {
|
|
1244
|
-
const
|
|
1245
|
-
_req.url = typeof
|
|
1233
|
+
const path2 = req.path;
|
|
1234
|
+
_req.url = typeof path2 === "string" ? path2 : req.url ? req.url.path || req.url : void 0;
|
|
1246
1235
|
}
|
|
1247
1236
|
if (req.query) {
|
|
1248
1237
|
_req.query = req.query;
|
|
@@ -1425,17 +1414,17 @@ var require_parse = __commonJS({
|
|
|
1425
1414
|
const wildcards = [];
|
|
1426
1415
|
var wcLen = 0;
|
|
1427
1416
|
const secret = paths2.reduce(function(o, strPath, ix) {
|
|
1428
|
-
var
|
|
1417
|
+
var path2 = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ""));
|
|
1429
1418
|
const leadingBracket = strPath[0] === "[";
|
|
1430
|
-
|
|
1419
|
+
path2 = path2.map((p) => {
|
|
1431
1420
|
if (p[0] === "[") return p.substr(1, p.length - 2);
|
|
1432
1421
|
else return p;
|
|
1433
1422
|
});
|
|
1434
|
-
const star =
|
|
1423
|
+
const star = path2.indexOf("*");
|
|
1435
1424
|
if (star > -1) {
|
|
1436
|
-
const before =
|
|
1425
|
+
const before = path2.slice(0, star);
|
|
1437
1426
|
const beforeStr = before.join(".");
|
|
1438
|
-
const after =
|
|
1427
|
+
const after = path2.slice(star + 1, path2.length);
|
|
1439
1428
|
const nested = after.length > 0;
|
|
1440
1429
|
wcLen++;
|
|
1441
1430
|
wildcards.push({
|
|
@@ -1446,7 +1435,7 @@ var require_parse = __commonJS({
|
|
|
1446
1435
|
});
|
|
1447
1436
|
} else {
|
|
1448
1437
|
o[strPath] = {
|
|
1449
|
-
path:
|
|
1438
|
+
path: path2,
|
|
1450
1439
|
val: void 0,
|
|
1451
1440
|
precensored: false,
|
|
1452
1441
|
circle: "",
|
|
@@ -1491,20 +1480,20 @@ var require_redactor = __commonJS({
|
|
|
1491
1480
|
return redact;
|
|
1492
1481
|
}
|
|
1493
1482
|
function redactTmpl(secret, isCensorFct, censorFctTakesPath) {
|
|
1494
|
-
return Object.keys(secret).map((
|
|
1495
|
-
const { escPath, leadingBracket, path: arrPath } = secret[
|
|
1483
|
+
return Object.keys(secret).map((path2) => {
|
|
1484
|
+
const { escPath, leadingBracket, path: arrPath } = secret[path2];
|
|
1496
1485
|
const skip = leadingBracket ? 1 : 0;
|
|
1497
1486
|
const delim = leadingBracket ? "" : ".";
|
|
1498
1487
|
const hops = [];
|
|
1499
1488
|
var match2;
|
|
1500
|
-
while ((match2 = rx.exec(
|
|
1489
|
+
while ((match2 = rx.exec(path2)) !== null) {
|
|
1501
1490
|
const [, ix] = match2;
|
|
1502
|
-
const { index
|
|
1503
|
-
if (
|
|
1491
|
+
const { index, input } = match2;
|
|
1492
|
+
if (index > skip) hops.push(input.substring(0, index - (ix ? 0 : 1)));
|
|
1504
1493
|
}
|
|
1505
1494
|
var existence = hops.map((p) => `o${delim}${p}`).join(" && ");
|
|
1506
|
-
if (existence.length === 0) existence += `o${delim}${
|
|
1507
|
-
else existence += ` && o${delim}${
|
|
1495
|
+
if (existence.length === 0) existence += `o${delim}${path2} != null`;
|
|
1496
|
+
else existence += ` && o${delim}${path2} != null`;
|
|
1508
1497
|
const circularDetection = `
|
|
1509
1498
|
switch (true) {
|
|
1510
1499
|
${hops.reverse().map((p) => `
|
|
@@ -1517,12 +1506,12 @@ var require_redactor = __commonJS({
|
|
|
1517
1506
|
const censorArgs = censorFctTakesPath ? `val, ${JSON.stringify(arrPath)}` : `val`;
|
|
1518
1507
|
return `
|
|
1519
1508
|
if (${existence}) {
|
|
1520
|
-
const val = o${delim}${
|
|
1509
|
+
const val = o${delim}${path2}
|
|
1521
1510
|
if (val === censor) {
|
|
1522
1511
|
secret[${escPath}].precensored = true
|
|
1523
1512
|
} else {
|
|
1524
1513
|
secret[${escPath}].val = val
|
|
1525
|
-
o${delim}${
|
|
1514
|
+
o${delim}${path2} = ${isCensorFct ? `censor(${censorArgs})` : "censor"}
|
|
1526
1515
|
${circularDetection}
|
|
1527
1516
|
}
|
|
1528
1517
|
}
|
|
@@ -1573,13 +1562,13 @@ var require_modifiers = __commonJS({
|
|
|
1573
1562
|
target[k] = values[i];
|
|
1574
1563
|
}
|
|
1575
1564
|
}
|
|
1576
|
-
function groupRedact(o,
|
|
1577
|
-
const target = get2(o,
|
|
1565
|
+
function groupRedact(o, path2, censor, isCensorFct, censorFctTakesPath) {
|
|
1566
|
+
const target = get2(o, path2);
|
|
1578
1567
|
if (target == null || typeof target === "string") return { keys: null, values: null, target, flat: true };
|
|
1579
1568
|
const keys = Object.keys(target);
|
|
1580
1569
|
const keysLength = keys.length;
|
|
1581
|
-
const pathLength =
|
|
1582
|
-
const pathWithKey = censorFctTakesPath ? [...
|
|
1570
|
+
const pathLength = path2.length;
|
|
1571
|
+
const pathWithKey = censorFctTakesPath ? [...path2] : void 0;
|
|
1583
1572
|
const values = new Array(keysLength);
|
|
1584
1573
|
for (var i = 0; i < keysLength; i++) {
|
|
1585
1574
|
const key = keys[i];
|
|
@@ -1597,29 +1586,29 @@ var require_modifiers = __commonJS({
|
|
|
1597
1586
|
}
|
|
1598
1587
|
function nestedRestore(instructions) {
|
|
1599
1588
|
for (let i = 0; i < instructions.length; i++) {
|
|
1600
|
-
const { target, path:
|
|
1589
|
+
const { target, path: path2, value } = instructions[i];
|
|
1601
1590
|
let current = target;
|
|
1602
|
-
for (let i2 =
|
|
1603
|
-
current = current[
|
|
1591
|
+
for (let i2 = path2.length - 1; i2 > 0; i2--) {
|
|
1592
|
+
current = current[path2[i2]];
|
|
1604
1593
|
}
|
|
1605
|
-
current[
|
|
1594
|
+
current[path2[0]] = value;
|
|
1606
1595
|
}
|
|
1607
1596
|
}
|
|
1608
|
-
function nestedRedact(store, o,
|
|
1609
|
-
const target = get2(o,
|
|
1597
|
+
function nestedRedact(store, o, path2, ns, censor, isCensorFct, censorFctTakesPath) {
|
|
1598
|
+
const target = get2(o, path2);
|
|
1610
1599
|
if (target == null) return;
|
|
1611
1600
|
const keys = Object.keys(target);
|
|
1612
1601
|
const keysLength = keys.length;
|
|
1613
1602
|
for (var i = 0; i < keysLength; i++) {
|
|
1614
1603
|
const key = keys[i];
|
|
1615
|
-
specialSet(store, target, key,
|
|
1604
|
+
specialSet(store, target, key, path2, ns, censor, isCensorFct, censorFctTakesPath);
|
|
1616
1605
|
}
|
|
1617
1606
|
return store;
|
|
1618
1607
|
}
|
|
1619
1608
|
function has(obj, prop) {
|
|
1620
1609
|
return obj !== void 0 && obj !== null ? "hasOwn" in Object ? Object.hasOwn(obj, prop) : Object.prototype.hasOwnProperty.call(obj, prop) : false;
|
|
1621
1610
|
}
|
|
1622
|
-
function specialSet(store, o, k,
|
|
1611
|
+
function specialSet(store, o, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath) {
|
|
1623
1612
|
const afterPathLen = afterPath.length;
|
|
1624
1613
|
const lastPathIndex = afterPathLen - 1;
|
|
1625
1614
|
const originalKey = k;
|
|
@@ -1660,7 +1649,7 @@ var require_modifiers = __commonJS({
|
|
|
1660
1649
|
if (consecutive) {
|
|
1661
1650
|
redactPathCurrent = node(redactPathCurrent, wck, depth);
|
|
1662
1651
|
level = i;
|
|
1663
|
-
ov = iterateNthLevel(wcov, level - 1, k,
|
|
1652
|
+
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);
|
|
1664
1653
|
} else {
|
|
1665
1654
|
if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
|
|
1666
1655
|
if (kIsWc) {
|
|
@@ -1668,7 +1657,7 @@ var require_modifiers = __commonJS({
|
|
|
1668
1657
|
} else {
|
|
1669
1658
|
ov = wcov[k];
|
|
1670
1659
|
}
|
|
1671
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
1660
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
1672
1661
|
if (kIsWc) {
|
|
1673
1662
|
const rv = restoreInstr(node(redactPathCurrent, wck, depth), ov, o[originalKey]);
|
|
1674
1663
|
store.push(rv);
|
|
@@ -1690,7 +1679,7 @@ var require_modifiers = __commonJS({
|
|
|
1690
1679
|
} else {
|
|
1691
1680
|
ov = n[k];
|
|
1692
1681
|
redactPathCurrent = node(redactPathCurrent, k, depth);
|
|
1693
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
1682
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
1694
1683
|
if (has(n, k) && nv === ov || nv === void 0 && censor !== void 0) ; else {
|
|
1695
1684
|
const rv = restoreInstr(redactPathCurrent, ov, o[originalKey]);
|
|
1696
1685
|
store.push(rv);
|
|
@@ -1710,7 +1699,7 @@ var require_modifiers = __commonJS({
|
|
|
1710
1699
|
}
|
|
1711
1700
|
return n;
|
|
1712
1701
|
}
|
|
1713
|
-
function iterateNthLevel(wcov, level, k,
|
|
1702
|
+
function iterateNthLevel(wcov, level, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth) {
|
|
1714
1703
|
if (level === 0) {
|
|
1715
1704
|
if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
|
|
1716
1705
|
if (kIsWc) {
|
|
@@ -1718,7 +1707,7 @@ var require_modifiers = __commonJS({
|
|
|
1718
1707
|
} else {
|
|
1719
1708
|
ov = wcov[k];
|
|
1720
1709
|
}
|
|
1721
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
1710
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
1722
1711
|
if (kIsWc) {
|
|
1723
1712
|
const rv = restoreInstr(redactPathCurrent, ov, parent);
|
|
1724
1713
|
store.push(rv);
|
|
@@ -1735,7 +1724,7 @@ var require_modifiers = __commonJS({
|
|
|
1735
1724
|
for (const key in wcov) {
|
|
1736
1725
|
if (typeof wcov[key] === "object") {
|
|
1737
1726
|
redactPathCurrent = node(redactPathCurrent, key, depth);
|
|
1738
|
-
iterateNthLevel(wcov[key], level - 1, k,
|
|
1727
|
+
iterateNthLevel(wcov[key], level - 1, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth + 1);
|
|
1739
1728
|
}
|
|
1740
1729
|
}
|
|
1741
1730
|
}
|
|
@@ -1757,12 +1746,12 @@ var require_modifiers = __commonJS({
|
|
|
1757
1746
|
}
|
|
1758
1747
|
function restoreInstr(node2, value, target) {
|
|
1759
1748
|
let current = node2;
|
|
1760
|
-
const
|
|
1749
|
+
const path2 = [];
|
|
1761
1750
|
do {
|
|
1762
|
-
|
|
1751
|
+
path2.push(current.key);
|
|
1763
1752
|
current = current.parent;
|
|
1764
1753
|
} while (current.parent != null);
|
|
1765
|
-
return { path:
|
|
1754
|
+
return { path: path2, value, target };
|
|
1766
1755
|
}
|
|
1767
1756
|
}
|
|
1768
1757
|
});
|
|
@@ -1791,10 +1780,10 @@ var require_restorer = __commonJS({
|
|
|
1791
1780
|
};
|
|
1792
1781
|
}
|
|
1793
1782
|
function resetTmpl(secret, paths2) {
|
|
1794
|
-
return paths2.map((
|
|
1795
|
-
const { circle, escPath, leadingBracket } = secret[
|
|
1783
|
+
return paths2.map((path2) => {
|
|
1784
|
+
const { circle, escPath, leadingBracket } = secret[path2];
|
|
1796
1785
|
const delim = leadingBracket ? "" : ".";
|
|
1797
|
-
const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${
|
|
1786
|
+
const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${path2} = secret[${escPath}].val`;
|
|
1798
1787
|
const clear = `secret[${escPath}].val = undefined`;
|
|
1799
1788
|
return `
|
|
1800
1789
|
if (secret[${escPath}].val !== undefined) {
|
|
@@ -1996,8 +1985,8 @@ var require_redaction = __commonJS({
|
|
|
1996
1985
|
if (o[ns] === null) {
|
|
1997
1986
|
return o;
|
|
1998
1987
|
}
|
|
1999
|
-
const { index
|
|
2000
|
-
const nextPath = `${str.substr(
|
|
1988
|
+
const { index } = next;
|
|
1989
|
+
const nextPath = `${str.substr(index, str.length - 1)}`;
|
|
2001
1990
|
o[ns] = o[ns] || [];
|
|
2002
1991
|
if (ns !== wildcardFirstSym && o[ns].length === 0) {
|
|
2003
1992
|
o[ns].push(...o[wildcardFirstSym] || []);
|
|
@@ -2022,8 +2011,8 @@ var require_redaction = __commonJS({
|
|
|
2022
2011
|
if (shape[k] === null) {
|
|
2023
2012
|
o[k] = (value) => topCensor(value, [k]);
|
|
2024
2013
|
} else {
|
|
2025
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
2026
|
-
return censor(value, [k, ...
|
|
2014
|
+
const wrappedCensor = typeof censor === "function" ? (value, path2) => {
|
|
2015
|
+
return censor(value, [k, ...path2]);
|
|
2027
2016
|
} : censor;
|
|
2028
2017
|
o[k] = fastRedact({
|
|
2029
2018
|
paths: shape[k],
|
|
@@ -2083,8 +2072,8 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
2083
2072
|
if (len === 1) return f;
|
|
2084
2073
|
var objects = new Array(len);
|
|
2085
2074
|
objects[0] = ss(f);
|
|
2086
|
-
for (var
|
|
2087
|
-
objects[
|
|
2075
|
+
for (var index = 1; index < len; index++) {
|
|
2076
|
+
objects[index] = ss(args[index]);
|
|
2088
2077
|
}
|
|
2089
2078
|
return objects.join(" ");
|
|
2090
2079
|
}
|
|
@@ -2219,7 +2208,7 @@ var require_sonic_boom = __commonJS({
|
|
|
2219
2208
|
var fs2 = __require("fs");
|
|
2220
2209
|
var EventEmitter2 = __require("events");
|
|
2221
2210
|
var inherits = __require("util").inherits;
|
|
2222
|
-
var
|
|
2211
|
+
var path2 = __require("path");
|
|
2223
2212
|
var sleep = require_atomic_sleep();
|
|
2224
2213
|
var assert2 = __require("assert");
|
|
2225
2214
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -2273,7 +2262,7 @@ var require_sonic_boom = __commonJS({
|
|
|
2273
2262
|
const mode2 = sonic.mode;
|
|
2274
2263
|
if (sonic.sync) {
|
|
2275
2264
|
try {
|
|
2276
|
-
if (sonic.mkdir) fs2.mkdirSync(
|
|
2265
|
+
if (sonic.mkdir) fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
2277
2266
|
const fd = fs2.openSync(file, flags, mode2);
|
|
2278
2267
|
fileOpened(null, fd);
|
|
2279
2268
|
} catch (err) {
|
|
@@ -2281,7 +2270,7 @@ var require_sonic_boom = __commonJS({
|
|
|
2281
2270
|
throw err;
|
|
2282
2271
|
}
|
|
2283
2272
|
} else if (sonic.mkdir) {
|
|
2284
|
-
fs2.mkdir(
|
|
2273
|
+
fs2.mkdir(path2.dirname(file), { recursive: true }, (err) => {
|
|
2285
2274
|
if (err) return fileOpened(err);
|
|
2286
2275
|
fs2.open(file, flags, mode2, fileOpened);
|
|
2287
2276
|
});
|
|
@@ -2837,8 +2826,8 @@ var require_on_exit_leak_free = __commonJS({
|
|
|
2837
2826
|
}
|
|
2838
2827
|
function clear(ref) {
|
|
2839
2828
|
for (const event of ["exit", "beforeExit"]) {
|
|
2840
|
-
const
|
|
2841
|
-
refs[event].splice(
|
|
2829
|
+
const index = refs[event].indexOf(ref);
|
|
2830
|
+
refs[event].splice(index, index + 1);
|
|
2842
2831
|
uninstall(event);
|
|
2843
2832
|
}
|
|
2844
2833
|
}
|
|
@@ -2947,9 +2936,9 @@ var require_package = __commonJS({
|
|
|
2947
2936
|
var require_wait = __commonJS({
|
|
2948
2937
|
"../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/wait.js"(exports, module2) {
|
|
2949
2938
|
var MAX_TIMEOUT = 1e3;
|
|
2950
|
-
function wait2(state,
|
|
2939
|
+
function wait2(state, index, expected, timeout, done) {
|
|
2951
2940
|
const max = Date.now() + timeout;
|
|
2952
|
-
let current = Atomics.load(state,
|
|
2941
|
+
let current = Atomics.load(state, index);
|
|
2953
2942
|
if (current === expected) {
|
|
2954
2943
|
done(null, "ok");
|
|
2955
2944
|
return;
|
|
@@ -2961,7 +2950,7 @@ var require_wait = __commonJS({
|
|
|
2961
2950
|
} else {
|
|
2962
2951
|
setTimeout(() => {
|
|
2963
2952
|
prior = current;
|
|
2964
|
-
current = Atomics.load(state,
|
|
2953
|
+
current = Atomics.load(state, index);
|
|
2965
2954
|
if (current === prior) {
|
|
2966
2955
|
check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : backoff * 2);
|
|
2967
2956
|
} else {
|
|
@@ -2973,9 +2962,9 @@ var require_wait = __commonJS({
|
|
|
2973
2962
|
};
|
|
2974
2963
|
check(1);
|
|
2975
2964
|
}
|
|
2976
|
-
function waitDiff(state,
|
|
2965
|
+
function waitDiff(state, index, expected, timeout, done) {
|
|
2977
2966
|
const max = Date.now() + timeout;
|
|
2978
|
-
let current = Atomics.load(state,
|
|
2967
|
+
let current = Atomics.load(state, index);
|
|
2979
2968
|
if (current !== expected) {
|
|
2980
2969
|
done(null, "ok");
|
|
2981
2970
|
return;
|
|
@@ -2985,7 +2974,7 @@ var require_wait = __commonJS({
|
|
|
2985
2974
|
done(null, "timed-out");
|
|
2986
2975
|
} else {
|
|
2987
2976
|
setTimeout(() => {
|
|
2988
|
-
current = Atomics.load(state,
|
|
2977
|
+
current = Atomics.load(state, index);
|
|
2989
2978
|
if (current !== expected) {
|
|
2990
2979
|
done(null, "ok");
|
|
2991
2980
|
} else {
|
|
@@ -4466,7 +4455,7 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
4466
4455
|
}
|
|
4467
4456
|
}
|
|
4468
4457
|
const circularValue = getCircularValueOption(options);
|
|
4469
|
-
const
|
|
4458
|
+
const bigint = getBooleanOption(options, "bigint");
|
|
4470
4459
|
const deterministic = getDeterministicOption(options);
|
|
4471
4460
|
const comparator = typeof deterministic === "function" ? deterministic : void 0;
|
|
4472
4461
|
const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
|
|
@@ -4574,7 +4563,7 @@ ${originalIndentation}`;
|
|
|
4574
4563
|
case "undefined":
|
|
4575
4564
|
return void 0;
|
|
4576
4565
|
case "bigint":
|
|
4577
|
-
if (
|
|
4566
|
+
if (bigint) {
|
|
4578
4567
|
return String(value);
|
|
4579
4568
|
}
|
|
4580
4569
|
// fallthrough
|
|
@@ -4665,7 +4654,7 @@ ${originalIndentation}`;
|
|
|
4665
4654
|
case "undefined":
|
|
4666
4655
|
return void 0;
|
|
4667
4656
|
case "bigint":
|
|
4668
|
-
if (
|
|
4657
|
+
if (bigint) {
|
|
4669
4658
|
return String(value);
|
|
4670
4659
|
}
|
|
4671
4660
|
// fallthrough
|
|
@@ -4777,7 +4766,7 @@ ${originalIndentation}`;
|
|
|
4777
4766
|
case "undefined":
|
|
4778
4767
|
return void 0;
|
|
4779
4768
|
case "bigint":
|
|
4780
|
-
if (
|
|
4769
|
+
if (bigint) {
|
|
4781
4770
|
return String(value);
|
|
4782
4771
|
}
|
|
4783
4772
|
// fallthrough
|
|
@@ -4873,7 +4862,7 @@ ${originalIndentation}`;
|
|
|
4873
4862
|
case "undefined":
|
|
4874
4863
|
return void 0;
|
|
4875
4864
|
case "bigint":
|
|
4876
|
-
if (
|
|
4865
|
+
if (bigint) {
|
|
4877
4866
|
return String(value);
|
|
4878
4867
|
}
|
|
4879
4868
|
// fallthrough
|
|
@@ -5157,7 +5146,7 @@ var require_pino = __commonJS({
|
|
|
5157
5146
|
redact,
|
|
5158
5147
|
crlf,
|
|
5159
5148
|
serializers: serializers2,
|
|
5160
|
-
timestamp
|
|
5149
|
+
timestamp,
|
|
5161
5150
|
messageKey,
|
|
5162
5151
|
errorKey,
|
|
5163
5152
|
nestedKey,
|
|
@@ -5207,7 +5196,7 @@ var require_pino = __commonJS({
|
|
|
5207
5196
|
chindings = coreChindings(Object.assign({}, base2, { name }));
|
|
5208
5197
|
}
|
|
5209
5198
|
}
|
|
5210
|
-
const time2 =
|
|
5199
|
+
const time2 = timestamp instanceof Function ? timestamp : timestamp ? epochTime : nullTime;
|
|
5211
5200
|
const timeSliceIndex = time2().indexOf(":") + 1;
|
|
5212
5201
|
if (useOnlyCustomLevels && !customLevels) throw Error("customLevels is required if useOnlyCustomLevels is set true");
|
|
5213
5202
|
if (mixin && typeof mixin !== "function") throw Error(`Unknown mixin type "${typeof mixin}" - expected "function"`);
|
|
@@ -7517,9 +7506,9 @@ var require_stream_readable = __commonJS({
|
|
|
7517
7506
|
});
|
|
7518
7507
|
return this;
|
|
7519
7508
|
}
|
|
7520
|
-
var
|
|
7521
|
-
if (
|
|
7522
|
-
state.pipes.splice(
|
|
7509
|
+
var index = indexOf(state.pipes, dest);
|
|
7510
|
+
if (index === -1) return this;
|
|
7511
|
+
state.pipes.splice(index, 1);
|
|
7523
7512
|
state.pipesCount -= 1;
|
|
7524
7513
|
if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
|
7525
7514
|
dest.emit("unpipe", this, unpipeInfo);
|
|
@@ -8102,32 +8091,6 @@ var require_qheap2 = __commonJS({
|
|
|
8102
8091
|
}
|
|
8103
8092
|
});
|
|
8104
8093
|
|
|
8105
|
-
// src/index.node.ts
|
|
8106
|
-
var index_node_exports = {};
|
|
8107
|
-
__export(index_node_exports, {
|
|
8108
|
-
ApiSchema: () => apiSchema_exports,
|
|
8109
|
-
Chain: () => Chain_exports,
|
|
8110
|
-
EVM: () => EVM_exports,
|
|
8111
|
-
Logger: () => Logger_exports,
|
|
8112
|
-
OfferDB: () => OfferDB_exports,
|
|
8113
|
-
OfferRepository: () => OfferRepository_exports,
|
|
8114
|
-
Router: () => core_exports,
|
|
8115
|
-
RouterEvent: () => RouterEvent_exports,
|
|
8116
|
-
RouterOffer: () => RouterOffer_exports,
|
|
8117
|
-
Validation: () => Validation_exports,
|
|
8118
|
-
ValidationRule: () => ValidationRule_exports,
|
|
8119
|
-
batch: () => batch,
|
|
8120
|
-
consumed: () => consumed,
|
|
8121
|
-
decodeCursor: () => decodeCursor,
|
|
8122
|
-
encodeCursor: () => encodeCursor,
|
|
8123
|
-
offerCollaterals: () => offerCollaterals,
|
|
8124
|
-
offerStatus: () => offerStatus,
|
|
8125
|
-
offers: () => offers,
|
|
8126
|
-
poll: () => poll,
|
|
8127
|
-
validateCursor: () => validateCursor,
|
|
8128
|
-
wait: () => wait
|
|
8129
|
-
});
|
|
8130
|
-
|
|
8131
8094
|
// src/Chain.ts
|
|
8132
8095
|
var Chain_exports = {};
|
|
8133
8096
|
__export(Chain_exports, {
|
|
@@ -8250,6 +8213,18 @@ var InvalidRouterOfferError = class extends Errors.BaseError {
|
|
|
8250
8213
|
}
|
|
8251
8214
|
};
|
|
8252
8215
|
|
|
8216
|
+
// src/utils/index.ts
|
|
8217
|
+
var utils_exports = {};
|
|
8218
|
+
__export(utils_exports, {
|
|
8219
|
+
batch: () => batch,
|
|
8220
|
+
decodeCursor: () => decodeCursor,
|
|
8221
|
+
encodeCursor: () => encodeCursor,
|
|
8222
|
+
poll: () => poll,
|
|
8223
|
+
retry: () => retry,
|
|
8224
|
+
validateCursor: () => validateCursor,
|
|
8225
|
+
wait: () => wait
|
|
8226
|
+
});
|
|
8227
|
+
|
|
8253
8228
|
// src/utils/batch.ts
|
|
8254
8229
|
function* batch(array, batchSize) {
|
|
8255
8230
|
for (let i = 0; i < array.length; i += batchSize) {
|
|
@@ -8360,6 +8335,20 @@ function poll(fn, { interval }) {
|
|
|
8360
8335
|
return unwatch;
|
|
8361
8336
|
}
|
|
8362
8337
|
|
|
8338
|
+
// src/utils/retry.ts
|
|
8339
|
+
var retry = async (fn, attempts = 3, delayMs = 50) => {
|
|
8340
|
+
let lastErr;
|
|
8341
|
+
for (let i = 0; i < attempts; i++) {
|
|
8342
|
+
try {
|
|
8343
|
+
return await fn();
|
|
8344
|
+
} catch (err) {
|
|
8345
|
+
lastErr = err;
|
|
8346
|
+
if (i < attempts - 1) await new Promise((r) => setTimeout(r, delayMs));
|
|
8347
|
+
}
|
|
8348
|
+
}
|
|
8349
|
+
throw lastErr;
|
|
8350
|
+
};
|
|
8351
|
+
|
|
8363
8352
|
// src/core/apiSchema/requests.ts
|
|
8364
8353
|
var MAX_LIMIT = 100;
|
|
8365
8354
|
var DEFAULT_LIMIT = 20;
|
|
@@ -8836,27 +8825,27 @@ var OpenApi = createDocument({
|
|
|
8836
8825
|
|
|
8837
8826
|
// src/core/apiSchema/utils.ts
|
|
8838
8827
|
function toResponse(routerOffer) {
|
|
8839
|
-
const { consumed
|
|
8828
|
+
const { consumed, status, metadata, ...offer } = routerOffer;
|
|
8840
8829
|
return {
|
|
8841
8830
|
offer,
|
|
8842
|
-
consumed
|
|
8831
|
+
consumed,
|
|
8843
8832
|
status,
|
|
8844
8833
|
metadata
|
|
8845
8834
|
};
|
|
8846
8835
|
}
|
|
8847
8836
|
function fromResponse(offerResponse) {
|
|
8848
|
-
const { offer, consumed
|
|
8837
|
+
const { offer, consumed, status, metadata } = offerResponse;
|
|
8849
8838
|
return {
|
|
8850
8839
|
...offer,
|
|
8851
|
-
consumed
|
|
8840
|
+
consumed,
|
|
8852
8841
|
status,
|
|
8853
8842
|
metadata
|
|
8854
8843
|
};
|
|
8855
8844
|
}
|
|
8856
8845
|
|
|
8857
|
-
// src/core/index.ts
|
|
8858
|
-
var
|
|
8859
|
-
__export(
|
|
8846
|
+
// src/core/router/index.ts
|
|
8847
|
+
var router_exports = {};
|
|
8848
|
+
__export(router_exports, {
|
|
8860
8849
|
HttpForbiddenError: () => HttpForbiddenError,
|
|
8861
8850
|
HttpGetOffersFailedError: () => HttpGetOffersFailedError,
|
|
8862
8851
|
HttpRateLimitError: () => HttpRateLimitError,
|
|
@@ -8966,8 +8955,8 @@ async function get(config, parameters) {
|
|
|
8966
8955
|
if (parameters.limit !== void 0) {
|
|
8967
8956
|
url.searchParams.set("limit", parameters.limit.toString());
|
|
8968
8957
|
}
|
|
8969
|
-
const { cursor: returnedCursor, data:
|
|
8970
|
-
const routerOffers =
|
|
8958
|
+
const { cursor: returnedCursor, data: offers } = await getApi(config, url);
|
|
8959
|
+
const routerOffers = offers.map(Format.fromSnakeCase).map(fromResponse);
|
|
8971
8960
|
return {
|
|
8972
8961
|
cursor: returnedCursor,
|
|
8973
8962
|
offers: routerOffers.map(from).map(toResponse)
|
|
@@ -9008,8 +8997,8 @@ async function match(config, parameters) {
|
|
|
9008
8997
|
if (parameters.limit !== void 0) {
|
|
9009
8998
|
url.searchParams.set("limit", parameters.limit.toString());
|
|
9010
8999
|
}
|
|
9011
|
-
const { cursor: returnedCursor, data:
|
|
9012
|
-
const routerOffers =
|
|
9000
|
+
const { cursor: returnedCursor, data: offers } = await getApi(config, url);
|
|
9001
|
+
const routerOffers = offers.map(Format.fromSnakeCase).map(fromResponse);
|
|
9013
9002
|
return {
|
|
9014
9003
|
cursor: returnedCursor,
|
|
9015
9004
|
offers: routerOffers.map(from).map(toResponse)
|
|
@@ -9096,558 +9085,217 @@ var HttpGetOffersFailedError = class extends Errors.BaseError {
|
|
|
9096
9085
|
}
|
|
9097
9086
|
};
|
|
9098
9087
|
|
|
9099
|
-
// src/
|
|
9100
|
-
var
|
|
9101
|
-
__export(
|
|
9102
|
-
|
|
9103
|
-
OfferRepository: () => OfferRepository_exports,
|
|
9104
|
-
consumed: () => consumed,
|
|
9105
|
-
offerCollaterals: () => offerCollaterals,
|
|
9106
|
-
offerStatus: () => offerStatus,
|
|
9107
|
-
offers: () => offers
|
|
9108
|
-
});
|
|
9109
|
-
__reExport(OfferDB_exports2, drizzle_orm_star);
|
|
9110
|
-
|
|
9111
|
-
// src/OfferDB/OfferDB.ts
|
|
9112
|
-
var OfferDB_exports = {};
|
|
9113
|
-
__export(OfferDB_exports, {
|
|
9114
|
-
applyMigrations: () => applyMigrations,
|
|
9115
|
-
applyMigrationsPostgres: () => applyMigrationsPostgres,
|
|
9116
|
-
clean: () => clean,
|
|
9117
|
-
create: () => create
|
|
9118
|
-
});
|
|
9119
|
-
|
|
9120
|
-
// src/OfferDB/schema.ts
|
|
9121
|
-
var schema_exports = {};
|
|
9122
|
-
__export(schema_exports, {
|
|
9123
|
-
consumed: () => consumed,
|
|
9124
|
-
offerCollaterals: () => offerCollaterals,
|
|
9125
|
-
offerStatus: () => offerStatus,
|
|
9126
|
-
offers: () => offers
|
|
9088
|
+
// src/OfferStore/index.ts
|
|
9089
|
+
var OfferStore_exports = {};
|
|
9090
|
+
__export(OfferStore_exports, {
|
|
9091
|
+
memory: () => memory
|
|
9127
9092
|
});
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
}
|
|
9148
|
-
(
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
metadata: jsonb("metadata"),
|
|
9188
|
-
createdAt: timestamp("created_at").defaultNow().notNull()
|
|
9189
|
-
},
|
|
9190
|
-
(table) => [
|
|
9191
|
-
index("offer_status_offer_hash_created_at_idx").on(table.offerHash, desc(table.createdAt)),
|
|
9192
|
-
index("offer_status_status_idx").on(table.status)
|
|
9193
|
-
]
|
|
9194
|
-
);
|
|
9195
|
-
var consumed = pgTable(
|
|
9196
|
-
"consumed_per_user_and_nonce",
|
|
9197
|
-
{
|
|
9198
|
-
id: serial("id").primaryKey(),
|
|
9199
|
-
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
9200
|
-
offering: varchar("offering", { length: 42 }).notNull(),
|
|
9201
|
-
nonce: bigint("nonce", { mode: "bigint" }).notNull(),
|
|
9202
|
-
consumed: bigint("consumed", { mode: "bigint" }).notNull(),
|
|
9203
|
-
createdAt: timestamp("created_at").defaultNow().notNull()
|
|
9204
|
-
},
|
|
9205
|
-
(table) => [
|
|
9206
|
-
index("consumed_per_user_and_nonce_chain_id_offering_nonce_created_at_idx").on(
|
|
9207
|
-
table.chainId,
|
|
9208
|
-
table.offering,
|
|
9209
|
-
table.nonce,
|
|
9210
|
-
desc(table.createdAt)
|
|
9211
|
-
)
|
|
9212
|
-
]
|
|
9213
|
-
);
|
|
9214
|
-
|
|
9215
|
-
// src/OfferDB/OfferDB.ts
|
|
9216
|
-
function create({
|
|
9217
|
-
type = "pg",
|
|
9218
|
-
endpoint
|
|
9219
|
-
}) {
|
|
9220
|
-
if (type === "pg") {
|
|
9221
|
-
if (!endpoint) {
|
|
9222
|
-
throw new Error("endpoint is required with pg database");
|
|
9093
|
+
function memory(parameters) {
|
|
9094
|
+
const map = parameters.offers;
|
|
9095
|
+
const filled = parameters.filled;
|
|
9096
|
+
const create = async (parameters2) => {
|
|
9097
|
+
if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
|
|
9098
|
+
map.set(parameters2.offer.hash.toLowerCase(), {
|
|
9099
|
+
...parameters2.offer,
|
|
9100
|
+
status: parameters2.status,
|
|
9101
|
+
metadata: parameters2.metadata
|
|
9102
|
+
});
|
|
9103
|
+
const chainId = parameters2.offer.chainId;
|
|
9104
|
+
const address = parameters2.offer.offering.toLowerCase();
|
|
9105
|
+
const nonce = parameters2.offer.nonce;
|
|
9106
|
+
const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
|
|
9107
|
+
const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
|
|
9108
|
+
if (!filledForOffering.has(nonce)) filledForOffering.set(nonce, 0n);
|
|
9109
|
+
filledForChain.set(address, filledForOffering);
|
|
9110
|
+
filled.set(chainId, filledForChain);
|
|
9111
|
+
return Promise.resolve(parameters2.offer.hash);
|
|
9112
|
+
};
|
|
9113
|
+
const sort = (sortBy, sortOrder, a, b) => {
|
|
9114
|
+
sortBy = sortBy || "expiry";
|
|
9115
|
+
sortOrder = sortOrder || "desc";
|
|
9116
|
+
const sortKey = sortBy === "amount" ? "assets" : sortBy;
|
|
9117
|
+
if (a[sortKey] === b[sortKey]) {
|
|
9118
|
+
if (a.hash === b.hash) return 0;
|
|
9119
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : b.hash > a.hash ? 1 : -1;
|
|
9120
|
+
}
|
|
9121
|
+
switch (sortBy) {
|
|
9122
|
+
case "rate":
|
|
9123
|
+
if (a.rate === b.rate) {
|
|
9124
|
+
if (a.hash === b.hash) return 0;
|
|
9125
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9126
|
+
}
|
|
9127
|
+
return sortOrder === "asc" ? a.rate > b.rate ? 1 : -1 : b.rate > a.rate ? 1 : -1;
|
|
9128
|
+
case "maturity":
|
|
9129
|
+
if (a.maturity === b.maturity) {
|
|
9130
|
+
if (a.hash === b.hash) return 0;
|
|
9131
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9132
|
+
}
|
|
9133
|
+
return sortOrder === "asc" ? a.maturity > b.maturity ? 1 : -1 : b.maturity > a.maturity ? 1 : -1;
|
|
9134
|
+
case "expiry":
|
|
9135
|
+
if (a.expiry === b.expiry) {
|
|
9136
|
+
if (a.hash === b.hash) return 0;
|
|
9137
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9138
|
+
}
|
|
9139
|
+
return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
|
|
9140
|
+
case "amount":
|
|
9141
|
+
if (a.assets === b.assets) {
|
|
9142
|
+
if (a.hash === b.hash) return 0;
|
|
9143
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9144
|
+
}
|
|
9145
|
+
return sortOrder === "asc" ? a.assets > b.assets ? 1 : -1 : b.assets > a.assets ? 1 : -1;
|
|
9146
|
+
default:
|
|
9147
|
+
if (a.expiry === b.expiry) {
|
|
9148
|
+
if (a.hash === b.hash) return 0;
|
|
9149
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9150
|
+
}
|
|
9151
|
+
return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
|
|
9223
9152
|
}
|
|
9224
|
-
|
|
9225
|
-
const client2 = drizzle(pool2, { schema: schema_exports });
|
|
9226
|
-
return Object.assign(client2, { name: "pg", pool: pool2 });
|
|
9227
|
-
}
|
|
9228
|
-
const pool = new PGlite();
|
|
9229
|
-
const client = drizzle$1(pool, { schema: schema_exports });
|
|
9230
|
-
return Object.assign(client, { name: "pglite", pool });
|
|
9231
|
-
}
|
|
9232
|
-
async function applyMigrations(db) {
|
|
9233
|
-
if (db.name !== "pglite") {
|
|
9234
|
-
throw new Error("Migrations can only be applied to PGLite database");
|
|
9235
|
-
}
|
|
9236
|
-
const filePath = path.join(__dirname, "drizzle");
|
|
9237
|
-
await migrate(db, { migrationsFolder: filePath });
|
|
9238
|
-
}
|
|
9239
|
-
async function applyMigrationsPostgres(db) {
|
|
9240
|
-
const filePath = process.env.AWS_LAMBDA_FUNCTION_NAME ? path.join(process.cwd(), "drizzle") : path.join(__dirname, "drizzle");
|
|
9241
|
-
if (db.name !== "pg") {
|
|
9242
|
-
throw new Error("Migrations can only be applied to PostgreSQL database");
|
|
9243
|
-
}
|
|
9244
|
-
await migrate$1(db, { migrationsFolder: filePath });
|
|
9245
|
-
}
|
|
9246
|
-
async function clean(db) {
|
|
9247
|
-
await db.execute(sql`drop schema if exists public cascade`);
|
|
9248
|
-
await db.execute(sql`create schema public`);
|
|
9249
|
-
await db.execute(sql`drop schema if exists drizzle cascade`);
|
|
9250
|
-
}
|
|
9251
|
-
|
|
9252
|
-
// src/OfferDB/repositories/offers/OfferRepository.ts
|
|
9253
|
-
var OfferRepository_exports = {};
|
|
9254
|
-
__export(OfferRepository_exports, {
|
|
9255
|
-
create: () => create2,
|
|
9256
|
-
createTest: () => createTest
|
|
9257
|
-
});
|
|
9258
|
-
function create2(config) {
|
|
9259
|
-
const db = config.db;
|
|
9153
|
+
};
|
|
9260
9154
|
return {
|
|
9261
|
-
create
|
|
9262
|
-
|
|
9263
|
-
return
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
offering: offer.offering.toLowerCase(),
|
|
9267
|
-
assets: offer.assets,
|
|
9268
|
-
rate: offer.rate,
|
|
9269
|
-
maturity: offer.maturity,
|
|
9270
|
-
expiry: offer.expiry,
|
|
9271
|
-
start: offer.start,
|
|
9272
|
-
nonce: offer.nonce,
|
|
9273
|
-
buy: offer.buy,
|
|
9274
|
-
chainId: offer.chainId,
|
|
9275
|
-
loanToken: offer.loanToken.toLowerCase(),
|
|
9276
|
-
callbackAddress: offer.callback.address.toLowerCase(),
|
|
9277
|
-
callbackData: offer.callback.data,
|
|
9278
|
-
callbackGasLimit: offer.callback.gasLimit,
|
|
9279
|
-
signature: offer.signature
|
|
9280
|
-
}).onConflictDoNothing().returning();
|
|
9281
|
-
if (result.length === 0) {
|
|
9282
|
-
return offer.hash;
|
|
9283
|
-
}
|
|
9284
|
-
for (const collateral of offer.collaterals) {
|
|
9285
|
-
await tx.insert(offerCollaterals).values({
|
|
9286
|
-
offerHash: offer.hash.toLowerCase(),
|
|
9287
|
-
asset: collateral.asset.toLowerCase(),
|
|
9288
|
-
oracle: collateral.oracle.toLowerCase(),
|
|
9289
|
-
lltv: collateral.lltv
|
|
9290
|
-
});
|
|
9291
|
-
}
|
|
9292
|
-
await tx.insert(offerStatus).values({
|
|
9293
|
-
offerHash: offer.hash.toLowerCase(),
|
|
9294
|
-
status,
|
|
9295
|
-
metadata
|
|
9296
|
-
});
|
|
9297
|
-
const consumedAmountExists = await tx.select().from(consumed).where(
|
|
9298
|
-
and(
|
|
9299
|
-
eq(consumed.offering, offer.offering.toLowerCase()),
|
|
9300
|
-
eq(consumed.nonce, offer.nonce),
|
|
9301
|
-
eq(consumed.chainId, offer.chainId)
|
|
9302
|
-
)
|
|
9303
|
-
);
|
|
9304
|
-
if (consumedAmountExists.length > 0) {
|
|
9305
|
-
return offer.hash;
|
|
9306
|
-
}
|
|
9307
|
-
await tx.insert(consumed).values({
|
|
9308
|
-
chainId: offer.chainId,
|
|
9309
|
-
offering: offer.offering.toLowerCase(),
|
|
9310
|
-
nonce: offer.nonce,
|
|
9311
|
-
consumed: 0n
|
|
9312
|
-
});
|
|
9313
|
-
return offer.hash;
|
|
9314
|
-
});
|
|
9315
|
-
},
|
|
9316
|
-
createMany: async (parameters) => {
|
|
9317
|
-
return await db.transaction(async (tx) => {
|
|
9318
|
-
const hashes = [];
|
|
9319
|
-
for (const { offer, status, metadata } of parameters) {
|
|
9320
|
-
const result = await tx.insert(offers).values({
|
|
9321
|
-
hash: offer.hash.toLowerCase(),
|
|
9322
|
-
offering: offer.offering.toLowerCase(),
|
|
9323
|
-
assets: offer.assets,
|
|
9324
|
-
rate: offer.rate,
|
|
9325
|
-
maturity: offer.maturity,
|
|
9326
|
-
expiry: offer.expiry,
|
|
9327
|
-
start: offer.start,
|
|
9328
|
-
nonce: offer.nonce,
|
|
9329
|
-
buy: offer.buy,
|
|
9330
|
-
chainId: offer.chainId,
|
|
9331
|
-
loanToken: offer.loanToken.toLowerCase(),
|
|
9332
|
-
callbackAddress: offer.callback.address.toLowerCase(),
|
|
9333
|
-
callbackData: offer.callback.data,
|
|
9334
|
-
callbackGasLimit: offer.callback.gasLimit,
|
|
9335
|
-
signature: offer.signature
|
|
9336
|
-
}).onConflictDoNothing().returning();
|
|
9337
|
-
if (result.length === 0) continue;
|
|
9338
|
-
for (const collateral of offer.collaterals) {
|
|
9339
|
-
await tx.insert(offerCollaterals).values({
|
|
9340
|
-
offerHash: offer.hash.toLowerCase(),
|
|
9341
|
-
asset: collateral.asset.toLowerCase(),
|
|
9342
|
-
oracle: collateral.oracle.toLowerCase(),
|
|
9343
|
-
lltv: collateral.lltv
|
|
9344
|
-
});
|
|
9345
|
-
}
|
|
9346
|
-
await tx.insert(offerStatus).values({
|
|
9347
|
-
offerHash: offer.hash.toLowerCase(),
|
|
9348
|
-
status,
|
|
9349
|
-
metadata
|
|
9350
|
-
});
|
|
9351
|
-
const consumedAmountExists = await tx.select().from(consumed).where(
|
|
9352
|
-
and(
|
|
9353
|
-
eq(consumed.offering, offer.offering.toLowerCase()),
|
|
9354
|
-
eq(consumed.nonce, offer.nonce),
|
|
9355
|
-
eq(consumed.chainId, offer.chainId)
|
|
9356
|
-
)
|
|
9357
|
-
);
|
|
9358
|
-
if (consumedAmountExists.length > 0) {
|
|
9359
|
-
hashes.push(offer.hash);
|
|
9360
|
-
continue;
|
|
9361
|
-
}
|
|
9362
|
-
await tx.insert(consumed).values({
|
|
9363
|
-
chainId: offer.chainId,
|
|
9364
|
-
offering: offer.offering.toLowerCase(),
|
|
9365
|
-
nonce: offer.nonce,
|
|
9366
|
-
consumed: 0n
|
|
9367
|
-
});
|
|
9368
|
-
hashes.push(offer.hash);
|
|
9369
|
-
}
|
|
9370
|
-
return hashes;
|
|
9371
|
-
});
|
|
9155
|
+
create,
|
|
9156
|
+
createMany: async (parameters2) => {
|
|
9157
|
+
return Promise.all(
|
|
9158
|
+
parameters2.map((p) => create({ offer: p.offer, status: p.status, metadata: p.metadata }))
|
|
9159
|
+
);
|
|
9372
9160
|
},
|
|
9373
9161
|
getAll: async (params) => {
|
|
9374
|
-
const { query } = params
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
}
|
|
9411
|
-
if (query?.maxMaturity !== void 0) {
|
|
9412
|
-
conditions.push(lte(offers.maturity, query.maxMaturity));
|
|
9413
|
-
}
|
|
9414
|
-
if (query?.minExpiry !== void 0) {
|
|
9415
|
-
conditions.push(gte(offers.expiry, query.minExpiry));
|
|
9416
|
-
}
|
|
9417
|
-
if (query?.maxExpiry !== void 0) {
|
|
9418
|
-
conditions.push(lte(offers.expiry, query.maxExpiry));
|
|
9419
|
-
}
|
|
9420
|
-
if (query?.collateralAssets && query.collateralAssets.length > 0) {
|
|
9421
|
-
conditions.push(inArray(offerCollaterals.asset, query.collateralAssets));
|
|
9422
|
-
}
|
|
9423
|
-
if (query?.collateralOracles && query.collateralOracles.length > 0) {
|
|
9424
|
-
conditions.push(inArray(offerCollaterals.oracle, query.collateralOracles));
|
|
9425
|
-
}
|
|
9426
|
-
if (query?.collateralTuple && query.collateralTuple.length > 0) {
|
|
9427
|
-
const tupleClauses = query.collateralTuple.map((tuple) => {
|
|
9428
|
-
const parts = [
|
|
9429
|
-
sql`${offerCollaterals.asset} = ${tuple.asset}`
|
|
9430
|
-
];
|
|
9431
|
-
if (tuple.oracle) {
|
|
9432
|
-
parts.push(sql`${offerCollaterals.oracle} = ${tuple.oracle}`);
|
|
9433
|
-
}
|
|
9434
|
-
if (tuple.lltv !== void 0) {
|
|
9435
|
-
const lltvInBasisPoints = safeParseNumber(tuple.lltv / 100, 18);
|
|
9436
|
-
parts.push(sql`${offerCollaterals.lltv} = ${lltvInBasisPoints}`);
|
|
9437
|
-
}
|
|
9438
|
-
let clause = parts[0];
|
|
9439
|
-
for (let i = 1; i < parts.length; i++) {
|
|
9440
|
-
clause = sql`${clause} AND ${parts[i]}`;
|
|
9441
|
-
}
|
|
9442
|
-
return sql`(${clause})`;
|
|
9443
|
-
}).filter((c) => c !== void 0);
|
|
9444
|
-
if (tupleClauses.length > 0) {
|
|
9445
|
-
let combined = tupleClauses[0];
|
|
9446
|
-
for (let i = 1; i < tupleClauses.length; i++) {
|
|
9447
|
-
combined = sql`${combined} OR ${tupleClauses[i]}`;
|
|
9448
|
-
}
|
|
9449
|
-
conditions.push(sql`(${combined})`);
|
|
9162
|
+
const { query } = params || {};
|
|
9163
|
+
let {
|
|
9164
|
+
creators,
|
|
9165
|
+
side,
|
|
9166
|
+
chains: chains2,
|
|
9167
|
+
loanTokens,
|
|
9168
|
+
status = ["valid"],
|
|
9169
|
+
callbackAddresses,
|
|
9170
|
+
minAmount,
|
|
9171
|
+
maxAmount,
|
|
9172
|
+
minRate,
|
|
9173
|
+
maxRate,
|
|
9174
|
+
minMaturity,
|
|
9175
|
+
maxMaturity,
|
|
9176
|
+
minExpiry,
|
|
9177
|
+
maxExpiry,
|
|
9178
|
+
collateralAssets,
|
|
9179
|
+
collateralOracles,
|
|
9180
|
+
collateralTuple,
|
|
9181
|
+
minLltv,
|
|
9182
|
+
maxLltv,
|
|
9183
|
+
sortBy = "expiry",
|
|
9184
|
+
sortOrder = "desc",
|
|
9185
|
+
cursor: queryCursor,
|
|
9186
|
+
limit = 20
|
|
9187
|
+
} = query || {};
|
|
9188
|
+
const now = Time.now();
|
|
9189
|
+
const buy = side === "buy";
|
|
9190
|
+
let offers = Array.from(map.values()).map((o) => ({
|
|
9191
|
+
...o,
|
|
9192
|
+
consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
|
|
9193
|
+
})).filter((o) => o.consumed < o.assets);
|
|
9194
|
+
const cursor = decodeCursor(queryCursor);
|
|
9195
|
+
if (cursor) {
|
|
9196
|
+
if (cursor.sort !== sortBy || cursor.dir !== sortOrder) {
|
|
9197
|
+
throw new Error("Cursor does not match the current sort parameters");
|
|
9450
9198
|
}
|
|
9451
|
-
|
|
9452
|
-
if (query?.minLltv !== void 0) {
|
|
9453
|
-
const minLltvInBasisPoints = safeParseNumber(query.minLltv / 100, 18);
|
|
9454
|
-
conditions.push(gte(offerCollaterals.lltv, minLltvInBasisPoints));
|
|
9455
|
-
}
|
|
9456
|
-
if (query?.maxLltv !== void 0) {
|
|
9457
|
-
const maxLltvInBasisPoints = safeParseNumber(query.maxLltv / 100, 18);
|
|
9458
|
-
conditions.push(lte(offerCollaterals.lltv, maxLltvInBasisPoints));
|
|
9459
|
-
}
|
|
9460
|
-
const sortBy = query?.sortBy ?? "expiry";
|
|
9461
|
-
const sortOrder = query?.sortOrder ?? "desc";
|
|
9462
|
-
const sortColumn = (() => {
|
|
9463
|
-
switch (sortBy) {
|
|
9199
|
+
switch (cursor.sort) {
|
|
9464
9200
|
case "rate":
|
|
9465
|
-
|
|
9201
|
+
offers = offers.filter(
|
|
9202
|
+
(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))
|
|
9203
|
+
);
|
|
9204
|
+
break;
|
|
9466
9205
|
case "maturity":
|
|
9467
|
-
|
|
9206
|
+
offers = offers.filter(
|
|
9207
|
+
(o) => (sortOrder === "asc" ? o.maturity >= BigInt(cursor.maturity) : o.maturity <= BigInt(cursor.maturity)) && (o.maturity !== Maturity.from(cursor.maturity) || (sortOrder === "asc" ? o.hash > cursor.hash : o.hash < cursor.hash))
|
|
9208
|
+
);
|
|
9209
|
+
break;
|
|
9468
9210
|
case "expiry":
|
|
9469
|
-
|
|
9211
|
+
offers = offers.filter(
|
|
9212
|
+
(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))
|
|
9213
|
+
);
|
|
9214
|
+
break;
|
|
9470
9215
|
case "amount":
|
|
9471
|
-
|
|
9216
|
+
offers = offers.filter(
|
|
9217
|
+
(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))
|
|
9218
|
+
);
|
|
9219
|
+
break;
|
|
9472
9220
|
default:
|
|
9473
|
-
|
|
9474
|
-
}
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
).from(consumed).orderBy(desc(consumed.createdAt)).limit(1).as("latest_consumed");
|
|
9514
|
-
const results = await db.select({
|
|
9515
|
-
hash: offers.hash,
|
|
9516
|
-
offering: offers.offering,
|
|
9517
|
-
assets: offers.assets,
|
|
9518
|
-
consumed: latestConsumed.consumed,
|
|
9519
|
-
rate: offers.rate,
|
|
9520
|
-
maturity: offers.maturity,
|
|
9521
|
-
expiry: offers.expiry,
|
|
9522
|
-
start: offers.start,
|
|
9523
|
-
nonce: offers.nonce,
|
|
9524
|
-
buy: offers.buy,
|
|
9525
|
-
chainId: offers.chainId,
|
|
9526
|
-
loanToken: offers.loanToken,
|
|
9527
|
-
callbackAddress: offers.callbackAddress,
|
|
9528
|
-
callbackData: offers.callbackData,
|
|
9529
|
-
callbackGasLimit: offers.callbackGasLimit,
|
|
9530
|
-
signature: offers.signature,
|
|
9531
|
-
createdAt: offers.createdAt,
|
|
9532
|
-
collateralAsset: offerCollaterals.asset,
|
|
9533
|
-
collateralOracle: offerCollaterals.oracle,
|
|
9534
|
-
collateralLltv: offerCollaterals.lltv,
|
|
9535
|
-
status: latestStatus.status,
|
|
9536
|
-
metadata: latestStatus.metadata
|
|
9537
|
-
}).from(offers).leftJoin(offerCollaterals, eq(offers.hash, offerCollaterals.offerHash)).leftJoinLateral(latestStatus, sql`true`).leftJoinLateral(latestConsumed, sql`true`).where(
|
|
9538
|
-
and(
|
|
9539
|
-
conditions.length > 0 ? and(...conditions) : sql`true`,
|
|
9540
|
-
query?.status && query.status.length > 0 ? inArray(latestStatus.status, query.status) : eq(latestStatus.status, "valid"),
|
|
9541
|
-
sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) > 0`
|
|
9221
|
+
throw new Error("Invalid sort parameter");
|
|
9222
|
+
}
|
|
9223
|
+
offers = offers.filter((o) => o.hash !== cursor.hash);
|
|
9224
|
+
}
|
|
9225
|
+
creators && (creators = creators.map((c) => c.toLowerCase()));
|
|
9226
|
+
loanTokens && (loanTokens = loanTokens.map((lt) => lt.toLowerCase()));
|
|
9227
|
+
collateralAssets && (collateralAssets = collateralAssets.map((ca) => ca.toLowerCase()));
|
|
9228
|
+
collateralOracles && (collateralOracles = collateralOracles.map((co) => co.toLowerCase()));
|
|
9229
|
+
collateralTuple && (collateralTuple = collateralTuple.map((ct) => ({
|
|
9230
|
+
asset: ct.asset.toLowerCase(),
|
|
9231
|
+
oracle: ct.oracle?.toLowerCase()
|
|
9232
|
+
})));
|
|
9233
|
+
offers = offers.filter((o) => o.expiry >= now);
|
|
9234
|
+
creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
|
|
9235
|
+
side && (offers = offers.filter((o) => o.buy === buy));
|
|
9236
|
+
chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
|
|
9237
|
+
loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
|
|
9238
|
+
status && (offers = offers.filter((o) => status.includes(o.status)));
|
|
9239
|
+
callbackAddresses && (offers = offers.filter(
|
|
9240
|
+
(o) => callbackAddresses.includes(o.callback.address.toLowerCase())
|
|
9241
|
+
));
|
|
9242
|
+
minAmount && (offers = offers.filter((o) => o.assets >= minAmount));
|
|
9243
|
+
maxAmount && (offers = offers.filter((o) => o.assets <= maxAmount));
|
|
9244
|
+
minRate && (offers = offers.filter((o) => o.rate >= minRate));
|
|
9245
|
+
maxRate && (offers = offers.filter((o) => o.rate <= maxRate));
|
|
9246
|
+
minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
|
|
9247
|
+
maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
|
|
9248
|
+
minExpiry && (offers = offers.filter((o) => o.expiry >= minExpiry));
|
|
9249
|
+
maxExpiry && (offers = offers.filter((o) => o.expiry <= maxExpiry));
|
|
9250
|
+
collateralAssets && (offers = offers.filter(
|
|
9251
|
+
(o) => o.collaterals.some((c) => collateralAssets.includes(c.asset.toLowerCase()))
|
|
9252
|
+
));
|
|
9253
|
+
collateralOracles && (offers = offers.filter(
|
|
9254
|
+
(o) => o.collaterals.some((c) => collateralOracles.includes(c.oracle.toLowerCase()))
|
|
9255
|
+
));
|
|
9256
|
+
collateralTuple && (offers = offers.filter(
|
|
9257
|
+
(o) => o.collaterals.some(
|
|
9258
|
+
(c) => collateralTuple.some(
|
|
9259
|
+
(ct) => c.asset.toLowerCase() === ct.asset.toLowerCase() && (ct.oracle ? c.oracle.toLowerCase() === ct.oracle.toLowerCase() : true) && (ct.lltv ? c.lltv === LLTV.from(BigInt(ct.lltv)) : true)
|
|
9260
|
+
)
|
|
9542
9261
|
)
|
|
9543
|
-
)
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
rate: row.rate,
|
|
9552
|
-
maturity: row.maturity,
|
|
9553
|
-
expiry: row.expiry,
|
|
9554
|
-
start: row.start,
|
|
9555
|
-
nonce: row.nonce,
|
|
9556
|
-
buy: row.buy,
|
|
9557
|
-
chainId: row.chainId,
|
|
9558
|
-
loanToken: row.loanToken,
|
|
9559
|
-
callbackAddress: row.callbackAddress,
|
|
9560
|
-
callbackData: row.callbackData,
|
|
9561
|
-
callbackGasLimit: row.callbackGasLimit,
|
|
9562
|
-
signature: row.signature,
|
|
9563
|
-
createdAt: row.createdAt,
|
|
9564
|
-
collaterals: [],
|
|
9565
|
-
status: row.status,
|
|
9566
|
-
metadata: row.metadata
|
|
9567
|
-
};
|
|
9568
|
-
if (row.collateralAsset && row.collateralOracle && row.collateralLltv) {
|
|
9569
|
-
offer.collaterals.push({
|
|
9570
|
-
asset: row.collateralAsset,
|
|
9571
|
-
oracle: row.collateralOracle,
|
|
9572
|
-
lltv: LLTV.from(row.collateralLltv)
|
|
9573
|
-
});
|
|
9574
|
-
}
|
|
9575
|
-
offerMap.set(row.hash, offer);
|
|
9576
|
-
}
|
|
9262
|
+
));
|
|
9263
|
+
minLltv && (offers = offers.filter(
|
|
9264
|
+
(o) => o.collaterals.every((c) => c.lltv >= LLTV.from(parseUnits(minLltv.toString(), 16)))
|
|
9265
|
+
));
|
|
9266
|
+
maxLltv && (offers = offers.filter(
|
|
9267
|
+
(o) => o.collaterals.every((c) => c.lltv <= LLTV.from(parseUnits(maxLltv.toString(), 16)))
|
|
9268
|
+
));
|
|
9269
|
+
offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
|
|
9577
9270
|
let nextCursor = null;
|
|
9578
|
-
if (
|
|
9579
|
-
const
|
|
9271
|
+
if (offers.length > limit) {
|
|
9272
|
+
const last = offers[limit - 1];
|
|
9580
9273
|
const base2 = {
|
|
9581
9274
|
sort: sortBy,
|
|
9582
9275
|
dir: sortOrder,
|
|
9583
|
-
hash:
|
|
9276
|
+
hash: last.hash
|
|
9584
9277
|
};
|
|
9585
9278
|
switch (sortBy) {
|
|
9586
9279
|
case "rate":
|
|
9587
|
-
base2.rate =
|
|
9280
|
+
base2.rate = last.rate.toString();
|
|
9588
9281
|
break;
|
|
9589
9282
|
case "amount":
|
|
9590
|
-
base2.assets =
|
|
9283
|
+
base2.assets = last.assets.toString();
|
|
9591
9284
|
break;
|
|
9592
9285
|
case "maturity":
|
|
9593
|
-
base2.maturity =
|
|
9286
|
+
base2.maturity = last.maturity;
|
|
9594
9287
|
break;
|
|
9595
9288
|
default:
|
|
9596
|
-
base2.expiry =
|
|
9289
|
+
base2.expiry = last.expiry;
|
|
9597
9290
|
}
|
|
9598
9291
|
nextCursor = encodeCursor(base2);
|
|
9599
9292
|
}
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
rate: offerData.rate,
|
|
9606
|
-
maturity: Maturity.from(offerData.maturity),
|
|
9607
|
-
expiry: offerData.expiry,
|
|
9608
|
-
start: offerData.start,
|
|
9609
|
-
nonce: offerData.nonce,
|
|
9610
|
-
buy: offerData.buy,
|
|
9611
|
-
chainId: offerData.chainId,
|
|
9612
|
-
loanToken: offerData.loanToken,
|
|
9613
|
-
collaterals: offerData.collaterals.map((c) => ({
|
|
9614
|
-
asset: c.asset,
|
|
9615
|
-
oracle: c.oracle,
|
|
9616
|
-
lltv: LLTV.from(c.lltv)
|
|
9617
|
-
})).sort((a, b) => a.asset.toLowerCase().localeCompare(b.asset.toLowerCase())),
|
|
9618
|
-
callback: {
|
|
9619
|
-
address: offerData.callbackAddress,
|
|
9620
|
-
data: offerData.callbackData,
|
|
9621
|
-
gasLimit: offerData.callbackGasLimit
|
|
9622
|
-
},
|
|
9623
|
-
signature: offerData.signature === null ? void 0 : offerData.signature
|
|
9624
|
-
});
|
|
9625
|
-
transformedResults.push({
|
|
9626
|
-
...offer,
|
|
9627
|
-
consumed: offerData.consumed,
|
|
9628
|
-
status: offerData.status,
|
|
9629
|
-
...offerData.metadata !== null ? { metadata: offerData.metadata } : {}
|
|
9630
|
-
});
|
|
9631
|
-
}
|
|
9632
|
-
return { offers: transformedResults, nextCursor };
|
|
9293
|
+
offers = offers.slice(0, limit);
|
|
9294
|
+
return {
|
|
9295
|
+
offers,
|
|
9296
|
+
nextCursor
|
|
9297
|
+
};
|
|
9633
9298
|
},
|
|
9634
|
-
/**
|
|
9635
|
-
* Returns offers that match specified offer based on the provided parameters.
|
|
9636
|
-
*
|
|
9637
|
-
* Rules for filtering:
|
|
9638
|
-
* - If offer expiry is in the past compared to now, it should not be included
|
|
9639
|
-
* - If offer maturity is in the past compared to now, it should not be included
|
|
9640
|
-
* - It should return if buyOffer.rate >= sellOffer.rate
|
|
9641
|
-
* - It should return if buyOffer.userAddress != sellOffer.userAddress
|
|
9642
|
-
* - It should return if maturity matches
|
|
9643
|
-
* - It should return if loanToken matches
|
|
9644
|
-
* - If the incoming intent is a buy / lend offer, only consider existing sell / borrow offers.
|
|
9645
|
-
* - If the incoming intent is a sell / borrow offer, only consider existing buy / lend offers.
|
|
9646
|
-
* - When the intent is lend: require offer_collaterals ⊆ intent_collaterals
|
|
9647
|
-
* - When the intent is borrow: require intent_collaterals ⊆ offer_collaterals
|
|
9648
|
-
* - It should sort by increasing rate if the input offer is a buy/lend offer
|
|
9649
|
-
* - It should sort by decreasing rate if the input offer is a sell/borrow offer
|
|
9650
|
-
*/
|
|
9651
9299
|
findMatchingOffers: async (params) => {
|
|
9652
9300
|
const {
|
|
9653
9301
|
side,
|
|
@@ -9660,192 +9308,80 @@ function create2(config) {
|
|
|
9660
9308
|
loanToken,
|
|
9661
9309
|
creator,
|
|
9662
9310
|
status,
|
|
9663
|
-
cursor,
|
|
9311
|
+
cursor: queryCursor,
|
|
9664
9312
|
limit = 20
|
|
9665
9313
|
} = params;
|
|
9314
|
+
const now = Time.now();
|
|
9666
9315
|
const buy = side !== "buy";
|
|
9667
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
9668
9316
|
const sortOrder = buy ? "asc" : "desc";
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
if (
|
|
9675
|
-
|
|
9676
|
-
if (maxMaturity !== void 0) conditions.push(lte(offers.maturity, maxMaturity));
|
|
9677
|
-
if (loanToken) conditions.push(eq(offers.loanToken, loanToken.toLowerCase()));
|
|
9678
|
-
if (creator) conditions.push(eq(offers.offering, creator.toLowerCase()));
|
|
9679
|
-
if (rate !== void 0) {
|
|
9680
|
-
conditions.push(buy ? gte(offers.rate, rate) : lte(offers.rate, rate));
|
|
9681
|
-
}
|
|
9682
|
-
const decoded = decodeCursor(cursor);
|
|
9683
|
-
if (decoded) {
|
|
9684
|
-
if (decoded.sort !== "rate" || decoded.dir !== sortOrder) {
|
|
9317
|
+
let offers = Array.from(map.values()).map((o) => ({
|
|
9318
|
+
...o,
|
|
9319
|
+
consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
|
|
9320
|
+
})).filter((o) => o.consumed < o.assets);
|
|
9321
|
+
const cursor = decodeCursor(queryCursor);
|
|
9322
|
+
if (cursor) {
|
|
9323
|
+
if (cursor.sort !== "rate" || cursor.dir !== sortOrder) {
|
|
9685
9324
|
throw new Error("Cursor does not match the current sort parameters");
|
|
9686
9325
|
}
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
sql`(${offers.rate}, ${offers.hash}) ${op} (${BigInt(decoded.rate)}, ${decoded.hash})`
|
|
9326
|
+
offers = offers.filter(
|
|
9327
|
+
(o) => sortOrder === "asc" ? o.rate >= BigInt(cursor.rate) : o.rate <= BigInt(cursor.rate)
|
|
9690
9328
|
);
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
)
|
|
9720
|
-
|
|
9721
|
-
conditions.push(buy ? lendPredicate : borrowPredicate);
|
|
9722
|
-
}
|
|
9723
|
-
const latestStatus = db.select({
|
|
9724
|
-
status: offerStatus.status,
|
|
9725
|
-
metadata: offerStatus.metadata
|
|
9726
|
-
}).from(offerStatus).where(eq(offerStatus.offerHash, offers.hash)).orderBy(desc(offerStatus.createdAt)).limit(1).as("latest_status");
|
|
9727
|
-
const latestConsumed = db.selectDistinctOn(
|
|
9728
|
-
[
|
|
9729
|
-
consumed.offering,
|
|
9730
|
-
consumed.nonce,
|
|
9731
|
-
consumed.chainId,
|
|
9732
|
-
consumed.createdAt
|
|
9733
|
-
],
|
|
9734
|
-
{
|
|
9735
|
-
consumed: consumed.consumed
|
|
9329
|
+
offers = offers.filter((o) => o.hash !== cursor.hash);
|
|
9330
|
+
}
|
|
9331
|
+
offers = offers.filter((o) => o.buy === buy);
|
|
9332
|
+
offers = offers.filter((o) => o.chainId === BigInt(chainId));
|
|
9333
|
+
offers = offers.filter((o) => o.expiry >= now);
|
|
9334
|
+
rate && (offers = offers.filter((o) => buy ? o.rate >= rate : o.rate <= rate));
|
|
9335
|
+
collaterals.length > 0 && (offers = offers.filter(
|
|
9336
|
+
(o) => buy ? collaterals.every((c) => {
|
|
9337
|
+
return o.collaterals.some(
|
|
9338
|
+
(oc) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
9339
|
+
);
|
|
9340
|
+
}) : o.collaterals.every((oc) => {
|
|
9341
|
+
return collaterals.some(
|
|
9342
|
+
(c) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
9343
|
+
);
|
|
9344
|
+
})
|
|
9345
|
+
));
|
|
9346
|
+
maturity && (offers = offers.filter((o) => o.maturity === maturity));
|
|
9347
|
+
minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
|
|
9348
|
+
maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
|
|
9349
|
+
loanToken && (offers = offers.filter((o) => o.loanToken.toLowerCase() === loanToken.toLowerCase()));
|
|
9350
|
+
creator && (offers = offers.filter((o) => o.offering.toLowerCase() === creator.toLowerCase()));
|
|
9351
|
+
status && (offers = offers.filter((o) => status.includes(o.status)));
|
|
9352
|
+
const byGroup = /* @__PURE__ */ new Map();
|
|
9353
|
+
for (const offer of offers) {
|
|
9354
|
+
const groupKey = `${offer.chainId}-${offer.offering.toLowerCase()}-${offer.nonce}-${offer.buy}`;
|
|
9355
|
+
const current = byGroup.get(groupKey);
|
|
9356
|
+
if (!current) {
|
|
9357
|
+
byGroup.set(groupKey, offer);
|
|
9358
|
+
continue;
|
|
9736
9359
|
}
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
loanToken: offers.loanToken,
|
|
9755
|
-
callbackAddress: offers.callbackAddress,
|
|
9756
|
-
callbackData: offers.callbackData,
|
|
9757
|
-
callbackGasLimit: offers.callbackGasLimit,
|
|
9758
|
-
signature: offers.signature,
|
|
9759
|
-
status: latestStatus.status,
|
|
9760
|
-
metadata: latestStatus.metadata
|
|
9761
|
-
}
|
|
9762
|
-
).from(offers).leftJoinLateral(latestStatus, sql`true`).leftJoinLateral(latestConsumed, sql`true`).where(
|
|
9763
|
-
and(
|
|
9764
|
-
and(...conditions),
|
|
9765
|
-
statusCondition,
|
|
9766
|
-
sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) > 0`
|
|
9767
|
-
)
|
|
9768
|
-
).orderBy(
|
|
9769
|
-
offers.offering,
|
|
9770
|
-
offers.nonce,
|
|
9771
|
-
offers.buy,
|
|
9772
|
-
// 1 price (direction depends on side)
|
|
9773
|
-
sql`CASE WHEN ${offers.buy} THEN ${offers.rate} ELSE -${offers.rate} END`,
|
|
9774
|
-
// 2 size (remaining)
|
|
9775
|
-
sql`( ${offers.assets} - COALESCE(${latestConsumed.consumed}, 0) ) DESC`,
|
|
9776
|
-
// 3 term (longer maturity)
|
|
9777
|
-
desc(offers.maturity)
|
|
9778
|
-
).as("best_offers");
|
|
9779
|
-
const rows = await db.select({
|
|
9780
|
-
hash: bestOffers.hash,
|
|
9781
|
-
offering: bestOffers.offering,
|
|
9782
|
-
assets: bestOffers.assets,
|
|
9783
|
-
consumed: bestOffers.consumed,
|
|
9784
|
-
rate: bestOffers.rate,
|
|
9785
|
-
maturity: bestOffers.maturity,
|
|
9786
|
-
expiry: bestOffers.expiry,
|
|
9787
|
-
start: bestOffers.start,
|
|
9788
|
-
nonce: bestOffers.nonce,
|
|
9789
|
-
buy: bestOffers.buy,
|
|
9790
|
-
chainId: bestOffers.chainId,
|
|
9791
|
-
loanToken: bestOffers.loanToken,
|
|
9792
|
-
callbackAddress: bestOffers.callbackAddress,
|
|
9793
|
-
callbackData: bestOffers.callbackData,
|
|
9794
|
-
callbackGasLimit: bestOffers.callbackGasLimit,
|
|
9795
|
-
signature: bestOffers.signature,
|
|
9796
|
-
status: bestOffers.status,
|
|
9797
|
-
metadata: bestOffers.metadata,
|
|
9798
|
-
collateralAsset: offerCollaterals.asset,
|
|
9799
|
-
collateralOracle: offerCollaterals.oracle,
|
|
9800
|
-
collateralLltv: offerCollaterals.lltv
|
|
9801
|
-
}).from(bestOffers).leftJoin(offerCollaterals, eq(bestOffers.hash, offerCollaterals.offerHash)).orderBy(
|
|
9802
|
-
sortOrder === "asc" ? sql`CASE WHEN ${bestOffers.buy} THEN ${bestOffers.rate} ELSE -${bestOffers.rate} END ASC` : sql`CASE WHEN ${bestOffers.buy} THEN -${bestOffers.rate} ELSE ${bestOffers.rate} END DESC`
|
|
9803
|
-
).limit(limit + 1);
|
|
9804
|
-
const offerMap = /* @__PURE__ */ new Map();
|
|
9805
|
-
for (const r of rows) {
|
|
9806
|
-
const entry = offerMap.get(r.hash) ?? { base: r, collaterals: [] };
|
|
9807
|
-
if (r.collateralAsset && r.collateralOracle && r.collateralLltv) {
|
|
9808
|
-
entry.collaterals.push({
|
|
9809
|
-
asset: r.collateralAsset,
|
|
9810
|
-
oracle: r.collateralOracle,
|
|
9811
|
-
lltv: LLTV.from(r.collateralLltv)
|
|
9812
|
-
});
|
|
9360
|
+
const remainingCandidate = offer.assets - offer.consumed;
|
|
9361
|
+
const remainingCurrent = current.assets - current.consumed;
|
|
9362
|
+
let candidateIsBetter = false;
|
|
9363
|
+
if (offer.buy) {
|
|
9364
|
+
if (offer.rate !== current.rate) candidateIsBetter = offer.rate < current.rate;
|
|
9365
|
+
else if (remainingCandidate !== remainingCurrent)
|
|
9366
|
+
candidateIsBetter = remainingCandidate > remainingCurrent;
|
|
9367
|
+
else if (offer.maturity !== current.maturity)
|
|
9368
|
+
candidateIsBetter = offer.maturity > current.maturity;
|
|
9369
|
+
else candidateIsBetter = offer.hash < current.hash;
|
|
9370
|
+
} else {
|
|
9371
|
+
if (offer.rate !== current.rate) candidateIsBetter = offer.rate > current.rate;
|
|
9372
|
+
else if (remainingCandidate !== remainingCurrent)
|
|
9373
|
+
candidateIsBetter = remainingCandidate > remainingCurrent;
|
|
9374
|
+
else if (offer.maturity !== current.maturity)
|
|
9375
|
+
candidateIsBetter = offer.maturity > current.maturity;
|
|
9376
|
+
else candidateIsBetter = offer.hash < current.hash;
|
|
9813
9377
|
}
|
|
9814
|
-
|
|
9378
|
+
if (candidateIsBetter) byGroup.set(groupKey, offer);
|
|
9815
9379
|
}
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
);
|
|
9819
|
-
const page = offersArray.slice(0, limit);
|
|
9820
|
-
const data = page.map(({ base: base2, collaterals: cols }) => ({
|
|
9821
|
-
...Offer.from({
|
|
9822
|
-
offering: base2.offering,
|
|
9823
|
-
assets: base2.assets,
|
|
9824
|
-
rate: base2.rate,
|
|
9825
|
-
maturity: Maturity.from(base2.maturity),
|
|
9826
|
-
expiry: base2.expiry,
|
|
9827
|
-
start: base2.start,
|
|
9828
|
-
nonce: base2.nonce,
|
|
9829
|
-
buy: base2.buy,
|
|
9830
|
-
chainId: base2.chainId,
|
|
9831
|
-
loanToken: base2.loanToken,
|
|
9832
|
-
collaterals: cols.sort(
|
|
9833
|
-
(a, b) => a.asset.toLowerCase().localeCompare(b.asset.toLowerCase())
|
|
9834
|
-
),
|
|
9835
|
-
callback: {
|
|
9836
|
-
address: base2.callbackAddress,
|
|
9837
|
-
data: base2.callbackData,
|
|
9838
|
-
gasLimit: base2.callbackGasLimit
|
|
9839
|
-
},
|
|
9840
|
-
signature: base2.signature === null ? void 0 : base2.signature
|
|
9841
|
-
}),
|
|
9842
|
-
consumed: base2.consumed || 0n,
|
|
9843
|
-
status: base2.status,
|
|
9844
|
-
...base2.metadata ? { metadata: base2.metadata } : {}
|
|
9845
|
-
}));
|
|
9380
|
+
offers = Array.from(byGroup.values());
|
|
9381
|
+
offers = offers.sort((a, b) => sort("rate", sortOrder, a, b));
|
|
9846
9382
|
let nextCursor = null;
|
|
9847
|
-
if (
|
|
9848
|
-
const last =
|
|
9383
|
+
if (offers.length > limit) {
|
|
9384
|
+
const last = offers[limit - 1];
|
|
9849
9385
|
nextCursor = encodeCursor({
|
|
9850
9386
|
sort: "rate",
|
|
9851
9387
|
dir: sortOrder,
|
|
@@ -9853,62 +9389,59 @@ function create2(config) {
|
|
|
9853
9389
|
rate: last.rate.toString()
|
|
9854
9390
|
});
|
|
9855
9391
|
}
|
|
9856
|
-
|
|
9392
|
+
offers = offers.slice(0, limit);
|
|
9393
|
+
return {
|
|
9394
|
+
offers,
|
|
9395
|
+
nextCursor
|
|
9396
|
+
};
|
|
9857
9397
|
},
|
|
9858
9398
|
delete: async (hash3) => {
|
|
9859
|
-
|
|
9860
|
-
|
|
9399
|
+
if (!map.has(hash3.toLowerCase())) return false;
|
|
9400
|
+
map.delete(hash3.toLowerCase());
|
|
9401
|
+
return true;
|
|
9861
9402
|
},
|
|
9862
9403
|
deleteMany: async (hashes) => {
|
|
9863
|
-
|
|
9864
|
-
|
|
9404
|
+
let deleted = 0;
|
|
9405
|
+
for (const hash3 of hashes) {
|
|
9406
|
+
if (map.has(hash3.toLowerCase())) {
|
|
9407
|
+
map.delete(hash3.toLowerCase());
|
|
9408
|
+
deleted++;
|
|
9409
|
+
}
|
|
9865
9410
|
}
|
|
9866
|
-
return
|
|
9867
|
-
const normalizedHashes = hashes.map((hash3) => hash3.toLowerCase());
|
|
9868
|
-
const result = await tx.delete(offers).where(
|
|
9869
|
-
sql`${offers.hash} = ANY(${sql.raw(`ARRAY[${normalizedHashes.map((h) => `'${h}'`).join(", ")}]`)})`
|
|
9870
|
-
);
|
|
9871
|
-
return result.affectedRows;
|
|
9872
|
-
});
|
|
9873
|
-
},
|
|
9874
|
-
updateStatus: async (parameters) => {
|
|
9875
|
-
await db.insert(offerStatus).values(parameters);
|
|
9411
|
+
return deleted;
|
|
9876
9412
|
},
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
create: async (_parameters) => "",
|
|
9885
|
-
createMany: async (_parameters) => [],
|
|
9886
|
-
getAll: async (_params) => ({ offers: [], nextCursor: null }),
|
|
9887
|
-
findMatchingOffers: async (_params) => ({ offers: [], nextCursor: null }),
|
|
9888
|
-
delete: async (_hash) => false,
|
|
9889
|
-
deleteMany: async (_hashes) => 0,
|
|
9890
|
-
updateStatus: async (_params) => {
|
|
9413
|
+
updateStatus: async (parameters2) => {
|
|
9414
|
+
if (!map.has(parameters2.offerHash.toLowerCase())) return;
|
|
9415
|
+
map.set(parameters2.offerHash.toLowerCase(), {
|
|
9416
|
+
...map.get(parameters2.offerHash.toLowerCase()),
|
|
9417
|
+
status: parameters2.status,
|
|
9418
|
+
metadata: parameters2.metadata
|
|
9419
|
+
});
|
|
9891
9420
|
},
|
|
9892
|
-
updateConsumedAmount: async (
|
|
9421
|
+
updateConsumedAmount: async (parameters2) => {
|
|
9422
|
+
const chainId = parameters2.chainId;
|
|
9423
|
+
const address = parameters2.offering.toLowerCase();
|
|
9424
|
+
const nonce = parameters2.nonce;
|
|
9425
|
+
const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
|
|
9426
|
+
const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
|
|
9427
|
+
filledForOffering.set(nonce, parameters2.consumed);
|
|
9428
|
+
filledForChain.set(address, filledForOffering);
|
|
9429
|
+
filled.set(chainId, filledForChain);
|
|
9893
9430
|
}
|
|
9894
9431
|
};
|
|
9895
9432
|
}
|
|
9896
9433
|
|
|
9897
|
-
// src/core/Server.ts
|
|
9434
|
+
// src/core/router/Server.ts
|
|
9898
9435
|
async function serve(parameters) {
|
|
9899
9436
|
const app = new Hono();
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
}
|
|
9904
|
-
const db = OfferDB_exports.create({ type: "pglite" });
|
|
9905
|
-
repository = OfferRepository_exports.create({ db });
|
|
9906
|
-
await OfferDB_exports.applyMigrations(db);
|
|
9907
|
-
}
|
|
9437
|
+
const store = parameters.store ? parameters.store : memory({
|
|
9438
|
+
offers: /* @__PURE__ */ new Map(),
|
|
9439
|
+
filled: /* @__PURE__ */ new Map()
|
|
9440
|
+
});
|
|
9908
9441
|
app.get("/v1/offers", async (c) => {
|
|
9909
9442
|
try {
|
|
9910
9443
|
const params = parse("get_offers", c.req.query());
|
|
9911
|
-
const
|
|
9444
|
+
const offers = await store.getAll({
|
|
9912
9445
|
query: {
|
|
9913
9446
|
creators: params.creators,
|
|
9914
9447
|
side: params.side,
|
|
@@ -9936,10 +9469,10 @@ async function serve(parameters) {
|
|
|
9936
9469
|
}
|
|
9937
9470
|
});
|
|
9938
9471
|
return Mempool.success(c, {
|
|
9939
|
-
data:
|
|
9472
|
+
data: offers.offers.map(
|
|
9940
9473
|
(offer) => Format.stringifyBigint(Format.toSnakeCase(toResponse(offer)))
|
|
9941
9474
|
),
|
|
9942
|
-
cursor:
|
|
9475
|
+
cursor: offers.nextCursor ?? null
|
|
9943
9476
|
});
|
|
9944
9477
|
} catch (err) {
|
|
9945
9478
|
console.error(err);
|
|
@@ -9949,7 +9482,7 @@ async function serve(parameters) {
|
|
|
9949
9482
|
app.get("/v1/match-offers", async (c) => {
|
|
9950
9483
|
try {
|
|
9951
9484
|
const params = parse("match_offers", c.req.query());
|
|
9952
|
-
const
|
|
9485
|
+
const offers = await store.findMatchingOffers({
|
|
9953
9486
|
side: params.side,
|
|
9954
9487
|
chainId: params.chain_id,
|
|
9955
9488
|
rate: params.rate,
|
|
@@ -9964,10 +9497,10 @@ async function serve(parameters) {
|
|
|
9964
9497
|
limit: params.limit
|
|
9965
9498
|
});
|
|
9966
9499
|
return Mempool.success(c, {
|
|
9967
|
-
data:
|
|
9500
|
+
data: offers.offers.map(
|
|
9968
9501
|
(offer) => Format.stringifyBigint(Format.toSnakeCase(toResponse(offer)))
|
|
9969
9502
|
),
|
|
9970
|
-
cursor:
|
|
9503
|
+
cursor: offers.nextCursor ?? null
|
|
9971
9504
|
});
|
|
9972
9505
|
} catch (err) {
|
|
9973
9506
|
console.error(err);
|
|
@@ -10196,7 +9729,7 @@ function aoutput(out, instance) {
|
|
|
10196
9729
|
function u32(arr) {
|
|
10197
9730
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
10198
9731
|
}
|
|
10199
|
-
function
|
|
9732
|
+
function clean(...arrays) {
|
|
10200
9733
|
for (let i = 0; i < arrays.length; i++) {
|
|
10201
9734
|
arrays[i].fill(0);
|
|
10202
9735
|
}
|
|
@@ -10379,7 +9912,7 @@ var HashMD = class extends Hash {
|
|
|
10379
9912
|
const { buffer, view, blockLen, isLE: isLE3 } = this;
|
|
10380
9913
|
let { pos } = this;
|
|
10381
9914
|
buffer[pos++] = 128;
|
|
10382
|
-
|
|
9915
|
+
clean(this.buffer.subarray(pos));
|
|
10383
9916
|
if (this.padOffset > blockLen - pos) {
|
|
10384
9917
|
this.process(view, 0);
|
|
10385
9918
|
pos = 0;
|
|
@@ -10587,11 +10120,11 @@ var SHA256 = class extends HashMD {
|
|
|
10587
10120
|
this.set(A, B, C, D, E, F2, G, H);
|
|
10588
10121
|
}
|
|
10589
10122
|
roundClean() {
|
|
10590
|
-
|
|
10123
|
+
clean(SHA256_W);
|
|
10591
10124
|
}
|
|
10592
10125
|
destroy() {
|
|
10593
10126
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
10594
|
-
|
|
10127
|
+
clean(this.buffer);
|
|
10595
10128
|
}
|
|
10596
10129
|
};
|
|
10597
10130
|
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
@@ -10619,7 +10152,7 @@ var HMAC = class extends Hash {
|
|
|
10619
10152
|
for (let i = 0; i < pad2.length; i++)
|
|
10620
10153
|
pad2[i] ^= 54 ^ 92;
|
|
10621
10154
|
this.oHash.update(pad2);
|
|
10622
|
-
|
|
10155
|
+
clean(pad2);
|
|
10623
10156
|
}
|
|
10624
10157
|
update(buf) {
|
|
10625
10158
|
aexists(this);
|
|
@@ -12268,8 +11801,8 @@ function getHash(hash3) {
|
|
|
12268
11801
|
};
|
|
12269
11802
|
}
|
|
12270
11803
|
function createCurve(curveDef, defHash) {
|
|
12271
|
-
const
|
|
12272
|
-
return { ...
|
|
11804
|
+
const create = (hash3) => weierstrass({ ...curveDef, ...getHash(hash3) });
|
|
11805
|
+
return { ...create(defHash), create };
|
|
12273
11806
|
}
|
|
12274
11807
|
|
|
12275
11808
|
// ../../node_modules/.pnpm/@noble+curves@1.9.0/node_modules/@noble/curves/esm/secp256k1.js
|
|
@@ -12556,11 +12089,11 @@ function concatBytes3(...arrays) {
|
|
|
12556
12089
|
function utf8ToBytes2(utf) {
|
|
12557
12090
|
return new TextEncoder().encode(utf);
|
|
12558
12091
|
}
|
|
12559
|
-
function numberToHex(
|
|
12560
|
-
if (
|
|
12092
|
+
function numberToHex(integer) {
|
|
12093
|
+
if (integer < 0) {
|
|
12561
12094
|
throw EthereumJSErrorWithoutCode("Invalid integer as argument, must be unsigned!");
|
|
12562
12095
|
}
|
|
12563
|
-
const hex =
|
|
12096
|
+
const hex = integer.toString(16);
|
|
12564
12097
|
return hex.length % 2 ? `0${hex}` : hex;
|
|
12565
12098
|
}
|
|
12566
12099
|
function padToEven(a) {
|
|
@@ -12940,7 +12473,7 @@ function keccakP(s, rounds = 24) {
|
|
|
12940
12473
|
s[0] ^= SHA3_IOTA_H[round];
|
|
12941
12474
|
s[1] ^= SHA3_IOTA_L[round];
|
|
12942
12475
|
}
|
|
12943
|
-
|
|
12476
|
+
clean(B);
|
|
12944
12477
|
}
|
|
12945
12478
|
var Keccak = class _Keccak extends Hash {
|
|
12946
12479
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
@@ -13036,7 +12569,7 @@ var Keccak = class _Keccak extends Hash {
|
|
|
13036
12569
|
}
|
|
13037
12570
|
destroy() {
|
|
13038
12571
|
this.destroyed = true;
|
|
13039
|
-
|
|
12572
|
+
clean(this.state);
|
|
13040
12573
|
}
|
|
13041
12574
|
_cloneInto(to) {
|
|
13042
12575
|
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
@@ -13401,8 +12934,8 @@ function isEOACode7702AuthorizationList(input) {
|
|
|
13401
12934
|
|
|
13402
12935
|
// ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/withdrawal.js
|
|
13403
12936
|
function withdrawalToBytesArray(withdrawal) {
|
|
13404
|
-
const { index
|
|
13405
|
-
const indexBytes = toType(
|
|
12937
|
+
const { index, validatorIndex, address, amount } = withdrawal;
|
|
12938
|
+
const indexBytes = toType(index, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(index, TypeOutput.Uint8Array);
|
|
13406
12939
|
const validatorIndexBytes = toType(validatorIndex, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(validatorIndex, TypeOutput.Uint8Array);
|
|
13407
12940
|
const addressBytes = address instanceof Address ? address.bytes : toType(address, TypeOutput.Uint8Array);
|
|
13408
12941
|
const amountBytes = toType(amount, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(amount, TypeOutput.Uint8Array);
|
|
@@ -13414,8 +12947,8 @@ var Withdrawal = class {
|
|
|
13414
12947
|
* Use the static factory methods to assist in creating a Withdrawal object from varying data types.
|
|
13415
12948
|
* Its amount is in Gwei to match CL representation and for eventual ssz withdrawalsRoot
|
|
13416
12949
|
*/
|
|
13417
|
-
constructor(
|
|
13418
|
-
this.index =
|
|
12950
|
+
constructor(index, validatorIndex, address, amount) {
|
|
12951
|
+
this.index = index;
|
|
13419
12952
|
this.validatorIndex = validatorIndex;
|
|
13420
12953
|
this.address = address;
|
|
13421
12954
|
this.amount = amount;
|
|
@@ -13442,11 +12975,11 @@ var Withdrawal = class {
|
|
|
13442
12975
|
};
|
|
13443
12976
|
function createWithdrawal(withdrawalData) {
|
|
13444
12977
|
const { index: indexData, validatorIndex: validatorIndexData, address: addressData, amount: amountData } = withdrawalData;
|
|
13445
|
-
const
|
|
12978
|
+
const index = toType(indexData, TypeOutput.BigInt);
|
|
13446
12979
|
const validatorIndex = toType(validatorIndexData, TypeOutput.BigInt);
|
|
13447
12980
|
const address = addressData instanceof Address ? addressData : new Address(toBytes3(addressData));
|
|
13448
12981
|
const amount = toType(amountData, TypeOutput.BigInt);
|
|
13449
|
-
return new Withdrawal(
|
|
12982
|
+
return new Withdrawal(index, validatorIndex, address, amount);
|
|
13450
12983
|
}
|
|
13451
12984
|
|
|
13452
12985
|
// ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/signature.js
|
|
@@ -13855,8 +13388,8 @@ if (typeof Int32Array !== "undefined") {
|
|
|
13855
13388
|
}
|
|
13856
13389
|
var crc = (current, previous) => {
|
|
13857
13390
|
let crc2 = 0 ^ -1;
|
|
13858
|
-
for (let
|
|
13859
|
-
crc2 = TABLE[(crc2 ^ current[
|
|
13391
|
+
for (let index = 0; index < current.length; index++) {
|
|
13392
|
+
crc2 = TABLE[(crc2 ^ current[index]) & 255] ^ crc2 >>> 8;
|
|
13860
13393
|
}
|
|
13861
13394
|
return crc2 ^ -1;
|
|
13862
13395
|
};
|
|
@@ -14689,15 +14222,15 @@ var Common = class {
|
|
|
14689
14222
|
*/
|
|
14690
14223
|
getHardforkBy(opts) {
|
|
14691
14224
|
const blockNumber = toType(opts.blockNumber, TypeOutput.BigInt);
|
|
14692
|
-
const
|
|
14225
|
+
const timestamp = toType(opts.timestamp, TypeOutput.BigInt);
|
|
14693
14226
|
const hfs = this.hardforks().filter((hf) => hf.block !== null || hf.timestamp !== void 0);
|
|
14694
|
-
let hfIndex = hfs.findIndex((hf) => blockNumber !== void 0 && hf.block !== null && BigInt(hf.block) > blockNumber ||
|
|
14227
|
+
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);
|
|
14695
14228
|
if (hfIndex === -1) {
|
|
14696
14229
|
hfIndex = hfs.length;
|
|
14697
14230
|
} else if (hfIndex === 0) {
|
|
14698
14231
|
throw Error("Must have at least one hardfork at block 0");
|
|
14699
14232
|
}
|
|
14700
|
-
if (
|
|
14233
|
+
if (timestamp === void 0) {
|
|
14701
14234
|
const stepBack = hfs.slice(0, hfIndex).reverse().findIndex((hf) => hf.block !== null);
|
|
14702
14235
|
hfIndex = hfIndex - stepBack;
|
|
14703
14236
|
}
|
|
@@ -14708,13 +14241,13 @@ var Common = class {
|
|
|
14708
14241
|
break;
|
|
14709
14242
|
}
|
|
14710
14243
|
}
|
|
14711
|
-
if (
|
|
14244
|
+
if (timestamp !== void 0) {
|
|
14712
14245
|
const minTimeStamp = hfs.slice(0, hfStartIndex).reduce((acc, hf) => Math.max(Number(hf.timestamp ?? "0"), acc), 0);
|
|
14713
|
-
if (minTimeStamp >
|
|
14246
|
+
if (minTimeStamp > timestamp) {
|
|
14714
14247
|
throw Error(`Maximum HF determined by timestamp is lower than the block number HF`);
|
|
14715
14248
|
}
|
|
14716
|
-
const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ??
|
|
14717
|
-
if (maxTimeStamp <
|
|
14249
|
+
const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ?? timestamp), acc), Number(timestamp));
|
|
14250
|
+
if (maxTimeStamp < timestamp) {
|
|
14718
14251
|
throw Error(`Maximum HF determined by block number is lower than timestamp HF`);
|
|
14719
14252
|
}
|
|
14720
14253
|
}
|
|
@@ -14885,8 +14418,8 @@ var Common = class {
|
|
|
14885
14418
|
* @param blockNumber Block number
|
|
14886
14419
|
* * @returns The value requested or `BigInt(0)` if not found
|
|
14887
14420
|
*/
|
|
14888
|
-
paramByBlock(name, blockNumber,
|
|
14889
|
-
const hardfork = this.getHardforkBy({ blockNumber, timestamp
|
|
14421
|
+
paramByBlock(name, blockNumber, timestamp) {
|
|
14422
|
+
const hardfork = this.getHardforkBy({ blockNumber, timestamp });
|
|
14890
14423
|
return this.paramByHardfork(name, hardfork);
|
|
14891
14424
|
}
|
|
14892
14425
|
/**
|
|
@@ -14938,13 +14471,13 @@ var Common = class {
|
|
|
14938
14471
|
hardfork1 = hardfork1 ?? this._hardfork;
|
|
14939
14472
|
const hardforks = this.hardforks();
|
|
14940
14473
|
let posHf1 = -1, posHf2 = -1;
|
|
14941
|
-
let
|
|
14474
|
+
let index = 0;
|
|
14942
14475
|
for (const hf of hardforks) {
|
|
14943
14476
|
if (hf["name"] === hardfork1)
|
|
14944
|
-
posHf1 =
|
|
14477
|
+
posHf1 = index;
|
|
14945
14478
|
if (hf["name"] === hardfork2)
|
|
14946
|
-
posHf2 =
|
|
14947
|
-
|
|
14479
|
+
posHf2 = index;
|
|
14480
|
+
index += 1;
|
|
14948
14481
|
}
|
|
14949
14482
|
return posHf1 >= posHf2 && posHf2 !== -1;
|
|
14950
14483
|
}
|
|
@@ -14971,11 +14504,11 @@ var Common = class {
|
|
|
14971
14504
|
}
|
|
14972
14505
|
hardforkTimestamp(hardfork) {
|
|
14973
14506
|
hardfork = hardfork ?? this._hardfork;
|
|
14974
|
-
const
|
|
14975
|
-
if (
|
|
14507
|
+
const timestamp = this._getHardfork(hardfork)?.["timestamp"];
|
|
14508
|
+
if (timestamp === void 0 || timestamp === null) {
|
|
14976
14509
|
return null;
|
|
14977
14510
|
}
|
|
14978
|
-
return BigInt(
|
|
14511
|
+
return BigInt(timestamp);
|
|
14979
14512
|
}
|
|
14980
14513
|
/**
|
|
14981
14514
|
* Returns the hardfork change block for eip
|
|
@@ -15050,8 +14583,8 @@ var Common = class {
|
|
|
15050
14583
|
let hfBytes = new Uint8Array(0);
|
|
15051
14584
|
let prevBlockOrTime = 0;
|
|
15052
14585
|
for (const hf of this.hardforks()) {
|
|
15053
|
-
const { block, timestamp
|
|
15054
|
-
let blockOrTime =
|
|
14586
|
+
const { block, timestamp, name } = hf;
|
|
14587
|
+
let blockOrTime = timestamp ?? block;
|
|
15055
14588
|
blockOrTime = blockOrTime !== null ? Number(blockOrTime) : null;
|
|
15056
14589
|
if (typeof blockOrTime === "number" && blockOrTime !== 0 && blockOrTime !== prevBlockOrTime && name !== Hardfork.Paris) {
|
|
15057
14590
|
const hfBlockBytes = hexToBytes5(`0x${blockOrTime.toString(16).padStart(16, "0")}`);
|
|
@@ -17266,9 +16799,9 @@ var handlers = /* @__PURE__ */ new Map([
|
|
|
17266
16799
|
[
|
|
17267
16800
|
73,
|
|
17268
16801
|
function(runState) {
|
|
17269
|
-
const
|
|
17270
|
-
if (runState.env.blobVersionedHashes.length > Number(
|
|
17271
|
-
runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(
|
|
16802
|
+
const index = runState.stack.pop();
|
|
16803
|
+
if (runState.env.blobVersionedHashes.length > Number(index)) {
|
|
16804
|
+
runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(index)]));
|
|
17272
16805
|
} else {
|
|
17273
16806
|
runState.stack.push(BIGINT_02);
|
|
17274
16807
|
}
|
|
@@ -19332,11 +18865,11 @@ var Stack = class {
|
|
|
19332
18865
|
const peekArray = Array(num);
|
|
19333
18866
|
let start = this._len;
|
|
19334
18867
|
for (let peek = 0; peek < num; peek++) {
|
|
19335
|
-
const
|
|
19336
|
-
if (
|
|
18868
|
+
const index = --start;
|
|
18869
|
+
if (index < 0) {
|
|
19337
18870
|
throw new EVMError(EVMError.errorMessages.STACK_UNDERFLOW);
|
|
19338
18871
|
}
|
|
19339
|
-
peekArray[peek] = this._store[
|
|
18872
|
+
peekArray[peek] = this._store[index];
|
|
19340
18873
|
}
|
|
19341
18874
|
return peekArray;
|
|
19342
18875
|
}
|
|
@@ -24946,8 +24479,8 @@ var msmGasUsed = (numPairs, gasUsedPerPair, discountTable) => {
|
|
|
24946
24479
|
return BigInt(numPairs) * gasUsedPerPair * BigInt(gasDiscountMultiplier) / BigInt(1e3);
|
|
24947
24480
|
};
|
|
24948
24481
|
var leading16ZeroBytesCheck = (opts, zeroByteRanges, pName, pairStart = 0) => {
|
|
24949
|
-
for (const
|
|
24950
|
-
const slicedBuffer = opts.data.subarray(zeroByteRanges[
|
|
24482
|
+
for (const index in zeroByteRanges) {
|
|
24483
|
+
const slicedBuffer = opts.data.subarray(zeroByteRanges[index][0] + pairStart, zeroByteRanges[index][1] + pairStart);
|
|
24951
24484
|
if (!(equalsBytes(slicedBuffer, ZERO_BYTES_16) === true)) {
|
|
24952
24485
|
if (opts._debug !== void 0) {
|
|
24953
24486
|
opts._debug(`${pName} failed: Point not on curve`);
|
|
@@ -25365,11 +24898,11 @@ var RIPEMD160 = class extends HashMD {
|
|
|
25365
24898
|
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);
|
|
25366
24899
|
}
|
|
25367
24900
|
roundClean() {
|
|
25368
|
-
|
|
24901
|
+
clean(BUF_160);
|
|
25369
24902
|
}
|
|
25370
24903
|
destroy() {
|
|
25371
24904
|
this.destroyed = true;
|
|
25372
|
-
|
|
24905
|
+
clean(this.buffer);
|
|
25373
24906
|
this.set(0, 0, 0, 0, 0);
|
|
25374
24907
|
}
|
|
25375
24908
|
};
|
|
@@ -28732,11 +28265,11 @@ var LRUCache = class _LRUCache {
|
|
|
28732
28265
|
free: c.#free,
|
|
28733
28266
|
// methods
|
|
28734
28267
|
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
28735
|
-
backgroundFetch: (k,
|
|
28736
|
-
moveToTail: (
|
|
28268
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
28269
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
28737
28270
|
indexes: (options) => c.#indexes(options),
|
|
28738
28271
|
rindexes: (options) => c.#rindexes(options),
|
|
28739
|
-
isStale: (
|
|
28272
|
+
isStale: (index) => c.#isStale(index)
|
|
28740
28273
|
};
|
|
28741
28274
|
}
|
|
28742
28275
|
// Protected read-only members
|
|
@@ -28891,13 +28424,13 @@ var LRUCache = class _LRUCache {
|
|
|
28891
28424
|
const starts = new ZeroArray(this.#max);
|
|
28892
28425
|
this.#ttls = ttls;
|
|
28893
28426
|
this.#starts = starts;
|
|
28894
|
-
this.#setItemTTL = (
|
|
28895
|
-
starts[
|
|
28896
|
-
ttls[
|
|
28427
|
+
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
28428
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
28429
|
+
ttls[index] = ttl;
|
|
28897
28430
|
if (ttl !== 0 && this.ttlAutopurge) {
|
|
28898
28431
|
const t = setTimeout(() => {
|
|
28899
|
-
if (this.#isStale(
|
|
28900
|
-
this.#delete(this.#keyList[
|
|
28432
|
+
if (this.#isStale(index)) {
|
|
28433
|
+
this.#delete(this.#keyList[index], "expire");
|
|
28901
28434
|
}
|
|
28902
28435
|
}, ttl + 1);
|
|
28903
28436
|
if (t.unref) {
|
|
@@ -28905,13 +28438,13 @@ var LRUCache = class _LRUCache {
|
|
|
28905
28438
|
}
|
|
28906
28439
|
}
|
|
28907
28440
|
};
|
|
28908
|
-
this.#updateItemAge = (
|
|
28909
|
-
starts[
|
|
28441
|
+
this.#updateItemAge = (index) => {
|
|
28442
|
+
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
28910
28443
|
};
|
|
28911
|
-
this.#statusTTL = (status,
|
|
28912
|
-
if (ttls[
|
|
28913
|
-
const ttl = ttls[
|
|
28914
|
-
const start = starts[
|
|
28444
|
+
this.#statusTTL = (status, index) => {
|
|
28445
|
+
if (ttls[index]) {
|
|
28446
|
+
const ttl = ttls[index];
|
|
28447
|
+
const start = starts[index];
|
|
28915
28448
|
if (!ttl || !start)
|
|
28916
28449
|
return;
|
|
28917
28450
|
status.ttl = ttl;
|
|
@@ -28934,21 +28467,21 @@ var LRUCache = class _LRUCache {
|
|
|
28934
28467
|
return n;
|
|
28935
28468
|
};
|
|
28936
28469
|
this.getRemainingTTL = (key) => {
|
|
28937
|
-
const
|
|
28938
|
-
if (
|
|
28470
|
+
const index = this.#keyMap.get(key);
|
|
28471
|
+
if (index === void 0) {
|
|
28939
28472
|
return 0;
|
|
28940
28473
|
}
|
|
28941
|
-
const ttl = ttls[
|
|
28942
|
-
const start = starts[
|
|
28474
|
+
const ttl = ttls[index];
|
|
28475
|
+
const start = starts[index];
|
|
28943
28476
|
if (!ttl || !start) {
|
|
28944
28477
|
return Infinity;
|
|
28945
28478
|
}
|
|
28946
28479
|
const age = (cachedNow || getNow()) - start;
|
|
28947
28480
|
return ttl - age;
|
|
28948
28481
|
};
|
|
28949
|
-
this.#isStale = (
|
|
28950
|
-
const s = starts[
|
|
28951
|
-
const t = ttls[
|
|
28482
|
+
this.#isStale = (index) => {
|
|
28483
|
+
const s = starts[index];
|
|
28484
|
+
const t = ttls[index];
|
|
28952
28485
|
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
28953
28486
|
};
|
|
28954
28487
|
}
|
|
@@ -28965,9 +28498,9 @@ var LRUCache = class _LRUCache {
|
|
|
28965
28498
|
const sizes = new ZeroArray(this.#max);
|
|
28966
28499
|
this.#calculatedSize = 0;
|
|
28967
28500
|
this.#sizes = sizes;
|
|
28968
|
-
this.#removeItemSize = (
|
|
28969
|
-
this.#calculatedSize -= sizes[
|
|
28970
|
-
sizes[
|
|
28501
|
+
this.#removeItemSize = (index) => {
|
|
28502
|
+
this.#calculatedSize -= sizes[index];
|
|
28503
|
+
sizes[index] = 0;
|
|
28971
28504
|
};
|
|
28972
28505
|
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
28973
28506
|
if (this.#isBackgroundFetch(v)) {
|
|
@@ -28988,15 +28521,15 @@ var LRUCache = class _LRUCache {
|
|
|
28988
28521
|
}
|
|
28989
28522
|
return size;
|
|
28990
28523
|
};
|
|
28991
|
-
this.#addItemSize = (
|
|
28992
|
-
sizes[
|
|
28524
|
+
this.#addItemSize = (index, size, status) => {
|
|
28525
|
+
sizes[index] = size;
|
|
28993
28526
|
if (this.#maxSize) {
|
|
28994
|
-
const maxSize2 = this.#maxSize - sizes[
|
|
28527
|
+
const maxSize2 = this.#maxSize - sizes[index];
|
|
28995
28528
|
while (this.#calculatedSize > maxSize2) {
|
|
28996
28529
|
this.#evict(true);
|
|
28997
28530
|
}
|
|
28998
28531
|
}
|
|
28999
|
-
this.#calculatedSize += sizes[
|
|
28532
|
+
this.#calculatedSize += sizes[index];
|
|
29000
28533
|
if (status) {
|
|
29001
28534
|
status.entrySize = size;
|
|
29002
28535
|
status.totalCalculatedSize = this.#calculatedSize;
|
|
@@ -29047,8 +28580,8 @@ var LRUCache = class _LRUCache {
|
|
|
29047
28580
|
}
|
|
29048
28581
|
}
|
|
29049
28582
|
}
|
|
29050
|
-
#isValidIndex(
|
|
29051
|
-
return
|
|
28583
|
+
#isValidIndex(index) {
|
|
28584
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
29052
28585
|
}
|
|
29053
28586
|
/**
|
|
29054
28587
|
* Return a generator yielding `[key, value]` pairs,
|
|
@@ -29335,23 +28868,23 @@ var LRUCache = class _LRUCache {
|
|
|
29335
28868
|
this.#delete(k, "set");
|
|
29336
28869
|
return this;
|
|
29337
28870
|
}
|
|
29338
|
-
let
|
|
29339
|
-
if (
|
|
29340
|
-
|
|
29341
|
-
this.#keyList[
|
|
29342
|
-
this.#valList[
|
|
29343
|
-
this.#keyMap.set(k,
|
|
29344
|
-
this.#next[this.#tail] =
|
|
29345
|
-
this.#prev[
|
|
29346
|
-
this.#tail =
|
|
28871
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
28872
|
+
if (index === void 0) {
|
|
28873
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
28874
|
+
this.#keyList[index] = k;
|
|
28875
|
+
this.#valList[index] = v;
|
|
28876
|
+
this.#keyMap.set(k, index);
|
|
28877
|
+
this.#next[this.#tail] = index;
|
|
28878
|
+
this.#prev[index] = this.#tail;
|
|
28879
|
+
this.#tail = index;
|
|
29347
28880
|
this.#size++;
|
|
29348
|
-
this.#addItemSize(
|
|
28881
|
+
this.#addItemSize(index, size, status);
|
|
29349
28882
|
if (status)
|
|
29350
28883
|
status.set = "add";
|
|
29351
28884
|
noUpdateTTL = false;
|
|
29352
28885
|
} else {
|
|
29353
|
-
this.#moveToTail(
|
|
29354
|
-
const oldVal = this.#valList[
|
|
28886
|
+
this.#moveToTail(index);
|
|
28887
|
+
const oldVal = this.#valList[index];
|
|
29355
28888
|
if (v !== oldVal) {
|
|
29356
28889
|
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
29357
28890
|
oldVal.__abortController.abort(new Error("replaced"));
|
|
@@ -29372,9 +28905,9 @@ var LRUCache = class _LRUCache {
|
|
|
29372
28905
|
this.#disposed?.push([oldVal, k, "set"]);
|
|
29373
28906
|
}
|
|
29374
28907
|
}
|
|
29375
|
-
this.#removeItemSize(
|
|
29376
|
-
this.#addItemSize(
|
|
29377
|
-
this.#valList[
|
|
28908
|
+
this.#removeItemSize(index);
|
|
28909
|
+
this.#addItemSize(index, size, status);
|
|
28910
|
+
this.#valList[index] = v;
|
|
29378
28911
|
if (status) {
|
|
29379
28912
|
status.set = "replace";
|
|
29380
28913
|
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
@@ -29390,10 +28923,10 @@ var LRUCache = class _LRUCache {
|
|
|
29390
28923
|
}
|
|
29391
28924
|
if (this.#ttls) {
|
|
29392
28925
|
if (!noUpdateTTL) {
|
|
29393
|
-
this.#setItemTTL(
|
|
28926
|
+
this.#setItemTTL(index, ttl, start);
|
|
29394
28927
|
}
|
|
29395
28928
|
if (status)
|
|
29396
|
-
this.#statusTTL(status,
|
|
28929
|
+
this.#statusTTL(status, index);
|
|
29397
28930
|
}
|
|
29398
28931
|
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
29399
28932
|
const dt = this.#disposed;
|
|
@@ -29479,24 +29012,24 @@ var LRUCache = class _LRUCache {
|
|
|
29479
29012
|
*/
|
|
29480
29013
|
has(k, hasOptions = {}) {
|
|
29481
29014
|
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
29482
|
-
const
|
|
29483
|
-
if (
|
|
29484
|
-
const v = this.#valList[
|
|
29015
|
+
const index = this.#keyMap.get(k);
|
|
29016
|
+
if (index !== void 0) {
|
|
29017
|
+
const v = this.#valList[index];
|
|
29485
29018
|
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
29486
29019
|
return false;
|
|
29487
29020
|
}
|
|
29488
|
-
if (!this.#isStale(
|
|
29021
|
+
if (!this.#isStale(index)) {
|
|
29489
29022
|
if (updateAgeOnHas) {
|
|
29490
|
-
this.#updateItemAge(
|
|
29023
|
+
this.#updateItemAge(index);
|
|
29491
29024
|
}
|
|
29492
29025
|
if (status) {
|
|
29493
29026
|
status.has = "hit";
|
|
29494
|
-
this.#statusTTL(status,
|
|
29027
|
+
this.#statusTTL(status, index);
|
|
29495
29028
|
}
|
|
29496
29029
|
return true;
|
|
29497
29030
|
} else if (status) {
|
|
29498
29031
|
status.has = "stale";
|
|
29499
|
-
this.#statusTTL(status,
|
|
29032
|
+
this.#statusTTL(status, index);
|
|
29500
29033
|
}
|
|
29501
29034
|
} else if (status) {
|
|
29502
29035
|
status.has = "miss";
|
|
@@ -29512,15 +29045,15 @@ var LRUCache = class _LRUCache {
|
|
|
29512
29045
|
*/
|
|
29513
29046
|
peek(k, peekOptions = {}) {
|
|
29514
29047
|
const { allowStale = this.allowStale } = peekOptions;
|
|
29515
|
-
const
|
|
29516
|
-
if (
|
|
29048
|
+
const index = this.#keyMap.get(k);
|
|
29049
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
29517
29050
|
return;
|
|
29518
29051
|
}
|
|
29519
|
-
const v = this.#valList[
|
|
29052
|
+
const v = this.#valList[index];
|
|
29520
29053
|
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
29521
29054
|
}
|
|
29522
|
-
#backgroundFetch(k,
|
|
29523
|
-
const v =
|
|
29055
|
+
#backgroundFetch(k, index, options, context) {
|
|
29056
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
29524
29057
|
if (this.#isBackgroundFetch(v)) {
|
|
29525
29058
|
return v;
|
|
29526
29059
|
}
|
|
@@ -29551,10 +29084,10 @@ var LRUCache = class _LRUCache {
|
|
|
29551
29084
|
return fetchFail(ac.signal.reason);
|
|
29552
29085
|
}
|
|
29553
29086
|
const bf2 = p;
|
|
29554
|
-
if (this.#valList[
|
|
29087
|
+
if (this.#valList[index] === p) {
|
|
29555
29088
|
if (v2 === void 0) {
|
|
29556
29089
|
if (bf2.__staleWhileFetching) {
|
|
29557
|
-
this.#valList[
|
|
29090
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
29558
29091
|
} else {
|
|
29559
29092
|
this.#delete(k, "fetch");
|
|
29560
29093
|
}
|
|
@@ -29579,12 +29112,12 @@ var LRUCache = class _LRUCache {
|
|
|
29579
29112
|
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
29580
29113
|
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
29581
29114
|
const bf2 = p;
|
|
29582
|
-
if (this.#valList[
|
|
29115
|
+
if (this.#valList[index] === p) {
|
|
29583
29116
|
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
29584
29117
|
if (del) {
|
|
29585
29118
|
this.#delete(k, "fetch");
|
|
29586
29119
|
} else if (!allowStaleAborted) {
|
|
29587
|
-
this.#valList[
|
|
29120
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
29588
29121
|
}
|
|
29589
29122
|
}
|
|
29590
29123
|
if (allowStale) {
|
|
@@ -29618,11 +29151,11 @@ var LRUCache = class _LRUCache {
|
|
|
29618
29151
|
__staleWhileFetching: v,
|
|
29619
29152
|
__returned: void 0
|
|
29620
29153
|
});
|
|
29621
|
-
if (
|
|
29154
|
+
if (index === void 0) {
|
|
29622
29155
|
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
29623
|
-
|
|
29156
|
+
index = this.#keyMap.get(k);
|
|
29624
29157
|
} else {
|
|
29625
|
-
this.#valList[
|
|
29158
|
+
this.#valList[index] = bf;
|
|
29626
29159
|
}
|
|
29627
29160
|
return bf;
|
|
29628
29161
|
}
|
|
@@ -29680,14 +29213,14 @@ var LRUCache = class _LRUCache {
|
|
|
29680
29213
|
status,
|
|
29681
29214
|
signal
|
|
29682
29215
|
};
|
|
29683
|
-
let
|
|
29684
|
-
if (
|
|
29216
|
+
let index = this.#keyMap.get(k);
|
|
29217
|
+
if (index === void 0) {
|
|
29685
29218
|
if (status)
|
|
29686
29219
|
status.fetch = "miss";
|
|
29687
|
-
const p = this.#backgroundFetch(k,
|
|
29220
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
29688
29221
|
return p.__returned = p;
|
|
29689
29222
|
} else {
|
|
29690
|
-
const v = this.#valList[
|
|
29223
|
+
const v = this.#valList[index];
|
|
29691
29224
|
if (this.#isBackgroundFetch(v)) {
|
|
29692
29225
|
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
29693
29226
|
if (status) {
|
|
@@ -29697,19 +29230,19 @@ var LRUCache = class _LRUCache {
|
|
|
29697
29230
|
}
|
|
29698
29231
|
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
29699
29232
|
}
|
|
29700
|
-
const isStale = this.#isStale(
|
|
29233
|
+
const isStale = this.#isStale(index);
|
|
29701
29234
|
if (!forceRefresh && !isStale) {
|
|
29702
29235
|
if (status)
|
|
29703
29236
|
status.fetch = "hit";
|
|
29704
|
-
this.#moveToTail(
|
|
29237
|
+
this.#moveToTail(index);
|
|
29705
29238
|
if (updateAgeOnGet) {
|
|
29706
|
-
this.#updateItemAge(
|
|
29239
|
+
this.#updateItemAge(index);
|
|
29707
29240
|
}
|
|
29708
29241
|
if (status)
|
|
29709
|
-
this.#statusTTL(status,
|
|
29242
|
+
this.#statusTTL(status, index);
|
|
29710
29243
|
return v;
|
|
29711
29244
|
}
|
|
29712
|
-
const p = this.#backgroundFetch(k,
|
|
29245
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
29713
29246
|
const hasStale = p.__staleWhileFetching !== void 0;
|
|
29714
29247
|
const staleVal = hasStale && allowStale;
|
|
29715
29248
|
if (status) {
|
|
@@ -29750,13 +29283,13 @@ var LRUCache = class _LRUCache {
|
|
|
29750
29283
|
*/
|
|
29751
29284
|
get(k, getOptions = {}) {
|
|
29752
29285
|
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
29753
|
-
const
|
|
29754
|
-
if (
|
|
29755
|
-
const value = this.#valList[
|
|
29286
|
+
const index = this.#keyMap.get(k);
|
|
29287
|
+
if (index !== void 0) {
|
|
29288
|
+
const value = this.#valList[index];
|
|
29756
29289
|
const fetching = this.#isBackgroundFetch(value);
|
|
29757
29290
|
if (status)
|
|
29758
|
-
this.#statusTTL(status,
|
|
29759
|
-
if (this.#isStale(
|
|
29291
|
+
this.#statusTTL(status, index);
|
|
29292
|
+
if (this.#isStale(index)) {
|
|
29760
29293
|
if (status)
|
|
29761
29294
|
status.get = "stale";
|
|
29762
29295
|
if (!fetching) {
|
|
@@ -29778,9 +29311,9 @@ var LRUCache = class _LRUCache {
|
|
|
29778
29311
|
if (fetching) {
|
|
29779
29312
|
return value.__staleWhileFetching;
|
|
29780
29313
|
}
|
|
29781
|
-
this.#moveToTail(
|
|
29314
|
+
this.#moveToTail(index);
|
|
29782
29315
|
if (updateAgeOnGet) {
|
|
29783
|
-
this.#updateItemAge(
|
|
29316
|
+
this.#updateItemAge(index);
|
|
29784
29317
|
}
|
|
29785
29318
|
return value;
|
|
29786
29319
|
}
|
|
@@ -29792,15 +29325,15 @@ var LRUCache = class _LRUCache {
|
|
|
29792
29325
|
this.#prev[n] = p;
|
|
29793
29326
|
this.#next[p] = n;
|
|
29794
29327
|
}
|
|
29795
|
-
#moveToTail(
|
|
29796
|
-
if (
|
|
29797
|
-
if (
|
|
29798
|
-
this.#head = this.#next[
|
|
29328
|
+
#moveToTail(index) {
|
|
29329
|
+
if (index !== this.#tail) {
|
|
29330
|
+
if (index === this.#head) {
|
|
29331
|
+
this.#head = this.#next[index];
|
|
29799
29332
|
} else {
|
|
29800
|
-
this.#connect(this.#prev[
|
|
29333
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
29801
29334
|
}
|
|
29802
|
-
this.#connect(this.#tail,
|
|
29803
|
-
this.#tail =
|
|
29335
|
+
this.#connect(this.#tail, index);
|
|
29336
|
+
this.#tail = index;
|
|
29804
29337
|
}
|
|
29805
29338
|
}
|
|
29806
29339
|
/**
|
|
@@ -29814,14 +29347,14 @@ var LRUCache = class _LRUCache {
|
|
|
29814
29347
|
#delete(k, reason) {
|
|
29815
29348
|
let deleted = false;
|
|
29816
29349
|
if (this.#size !== 0) {
|
|
29817
|
-
const
|
|
29818
|
-
if (
|
|
29350
|
+
const index = this.#keyMap.get(k);
|
|
29351
|
+
if (index !== void 0) {
|
|
29819
29352
|
deleted = true;
|
|
29820
29353
|
if (this.#size === 1) {
|
|
29821
29354
|
this.#clear(reason);
|
|
29822
29355
|
} else {
|
|
29823
|
-
this.#removeItemSize(
|
|
29824
|
-
const v = this.#valList[
|
|
29356
|
+
this.#removeItemSize(index);
|
|
29357
|
+
const v = this.#valList[index];
|
|
29825
29358
|
if (this.#isBackgroundFetch(v)) {
|
|
29826
29359
|
v.__abortController.abort(new Error("deleted"));
|
|
29827
29360
|
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
@@ -29833,20 +29366,20 @@ var LRUCache = class _LRUCache {
|
|
|
29833
29366
|
}
|
|
29834
29367
|
}
|
|
29835
29368
|
this.#keyMap.delete(k);
|
|
29836
|
-
this.#keyList[
|
|
29837
|
-
this.#valList[
|
|
29838
|
-
if (
|
|
29839
|
-
this.#tail = this.#prev[
|
|
29840
|
-
} else if (
|
|
29841
|
-
this.#head = this.#next[
|
|
29369
|
+
this.#keyList[index] = void 0;
|
|
29370
|
+
this.#valList[index] = void 0;
|
|
29371
|
+
if (index === this.#tail) {
|
|
29372
|
+
this.#tail = this.#prev[index];
|
|
29373
|
+
} else if (index === this.#head) {
|
|
29374
|
+
this.#head = this.#next[index];
|
|
29842
29375
|
} else {
|
|
29843
|
-
const pi = this.#prev[
|
|
29844
|
-
this.#next[pi] = this.#next[
|
|
29845
|
-
const ni = this.#next[
|
|
29846
|
-
this.#prev[ni] = this.#prev[
|
|
29376
|
+
const pi = this.#prev[index];
|
|
29377
|
+
this.#next[pi] = this.#next[index];
|
|
29378
|
+
const ni = this.#next[index];
|
|
29379
|
+
this.#prev[ni] = this.#prev[index];
|
|
29847
29380
|
}
|
|
29848
29381
|
this.#size--;
|
|
29849
|
-
this.#free.push(
|
|
29382
|
+
this.#free.push(index);
|
|
29850
29383
|
}
|
|
29851
29384
|
}
|
|
29852
29385
|
}
|
|
@@ -29866,12 +29399,12 @@ var LRUCache = class _LRUCache {
|
|
|
29866
29399
|
return this.#clear("delete");
|
|
29867
29400
|
}
|
|
29868
29401
|
#clear(reason) {
|
|
29869
|
-
for (const
|
|
29870
|
-
const v = this.#valList[
|
|
29402
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
29403
|
+
const v = this.#valList[index];
|
|
29871
29404
|
if (this.#isBackgroundFetch(v)) {
|
|
29872
29405
|
v.__abortController.abort(new Error("deleted"));
|
|
29873
29406
|
} else {
|
|
29874
|
-
const k = this.#keyList[
|
|
29407
|
+
const k = this.#keyList[index];
|
|
29875
29408
|
if (this.#hasDispose) {
|
|
29876
29409
|
this.#dispose?.(v, k, reason);
|
|
29877
29410
|
}
|
|
@@ -36636,9 +36169,9 @@ function sign(tx, privateKey, extraEntropy = true) {
|
|
|
36636
36169
|
const { recovery, r, s } = ecSignFunction(msgHash, privateKey, { extraEntropy });
|
|
36637
36170
|
const signedTx = tx.addSignature(BigInt(recovery), r, s, true);
|
|
36638
36171
|
if (hackApplied) {
|
|
36639
|
-
const
|
|
36640
|
-
if (
|
|
36641
|
-
tx["activeCapabilities"].splice(
|
|
36172
|
+
const index = tx["activeCapabilities"].indexOf(Capability.EIP155ReplayProtection);
|
|
36173
|
+
if (index > -1) {
|
|
36174
|
+
tx["activeCapabilities"].splice(index, 1);
|
|
36642
36175
|
}
|
|
36643
36176
|
}
|
|
36644
36177
|
return signedTx;
|
|
@@ -38595,7 +38128,7 @@ var BlockHeader = class {
|
|
|
38595
38128
|
const number2 = toType(headerData.number, TypeOutput.BigInt) ?? defaults2.number;
|
|
38596
38129
|
const gasLimit = toType(headerData.gasLimit, TypeOutput.BigInt) ?? defaults2.gasLimit;
|
|
38597
38130
|
const gasUsed = toType(headerData.gasUsed, TypeOutput.BigInt) ?? defaults2.gasUsed;
|
|
38598
|
-
const
|
|
38131
|
+
const timestamp = toType(headerData.timestamp, TypeOutput.BigInt) ?? defaults2.timestamp;
|
|
38599
38132
|
const extraData = toType(headerData.extraData, TypeOutput.Uint8Array) ?? defaults2.extraData;
|
|
38600
38133
|
const mixHash = toType(headerData.mixHash, TypeOutput.Uint8Array) ?? defaults2.mixHash;
|
|
38601
38134
|
const nonce = toType(headerData.nonce, TypeOutput.Uint8Array) ?? defaults2.nonce;
|
|
@@ -38603,7 +38136,7 @@ var BlockHeader = class {
|
|
|
38603
38136
|
if (setHardfork === true) {
|
|
38604
38137
|
this.common.setHardforkBy({
|
|
38605
38138
|
blockNumber: number2,
|
|
38606
|
-
timestamp
|
|
38139
|
+
timestamp
|
|
38607
38140
|
});
|
|
38608
38141
|
}
|
|
38609
38142
|
const hardforkDefaults = {
|
|
@@ -38653,7 +38186,7 @@ var BlockHeader = class {
|
|
|
38653
38186
|
this.number = number2;
|
|
38654
38187
|
this.gasLimit = gasLimit;
|
|
38655
38188
|
this.gasUsed = gasUsed;
|
|
38656
|
-
this.timestamp =
|
|
38189
|
+
this.timestamp = timestamp;
|
|
38657
38190
|
this.extraData = extraData;
|
|
38658
38191
|
this.mixHash = mixHash;
|
|
38659
38192
|
this.nonce = nonce;
|
|
@@ -39588,8 +39121,8 @@ var hmac2 = (hash3, key, message) => new HMAC2(hash3, key).update(message).diges
|
|
|
39588
39121
|
hmac2.create = (hash3, key) => new HMAC2(hash3, key);
|
|
39589
39122
|
|
|
39590
39123
|
// ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/abstract/utils.js
|
|
39591
|
-
var
|
|
39592
|
-
__export(
|
|
39124
|
+
var utils_exports2 = {};
|
|
39125
|
+
__export(utils_exports2, {
|
|
39593
39126
|
abytes: () => abytes4,
|
|
39594
39127
|
bitGet: () => bitGet2,
|
|
39595
39128
|
bitLen: () => bitLen3,
|
|
@@ -40231,7 +39764,7 @@ function validatePointOpts2(curve) {
|
|
|
40231
39764
|
}
|
|
40232
39765
|
return Object.freeze({ ...opts });
|
|
40233
39766
|
}
|
|
40234
|
-
var { bytesToNumberBE: b2n, hexToBytes: h2b } =
|
|
39767
|
+
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports2;
|
|
40235
39768
|
var DER3 = {
|
|
40236
39769
|
// asn.1 DER encoding utils
|
|
40237
39770
|
Err: class DERErr3 extends Error {
|
|
@@ -41011,8 +40544,8 @@ function getHash2(hash3) {
|
|
|
41011
40544
|
};
|
|
41012
40545
|
}
|
|
41013
40546
|
function createCurve2(curveDef, defHash) {
|
|
41014
|
-
const
|
|
41015
|
-
return Object.freeze({ ...
|
|
40547
|
+
const create = (hash3) => weierstrass3({ ...curveDef, ...getHash2(hash3) });
|
|
40548
|
+
return Object.freeze({ ...create(defHash), create });
|
|
41016
40549
|
}
|
|
41017
40550
|
|
|
41018
40551
|
// ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/secp256k1.js
|
|
@@ -41456,11 +40989,11 @@ function concatBytes8(...arrays) {
|
|
|
41456
40989
|
function utf8ToBytes5(utf) {
|
|
41457
40990
|
return new TextEncoder().encode(utf);
|
|
41458
40991
|
}
|
|
41459
|
-
function numberToHex4(
|
|
41460
|
-
if (
|
|
40992
|
+
function numberToHex4(integer) {
|
|
40993
|
+
if (integer < 0) {
|
|
41461
40994
|
throw new Error("Invalid integer as argument, must be unsigned!");
|
|
41462
40995
|
}
|
|
41463
|
-
const hex =
|
|
40996
|
+
const hex = integer.toString(16);
|
|
41464
40997
|
return hex.length % 2 ? `0${hex}` : hex;
|
|
41465
40998
|
}
|
|
41466
40999
|
function padToEven4(a) {
|
|
@@ -42019,11 +41552,11 @@ var LRUCache2 = class _LRUCache {
|
|
|
42019
41552
|
free: c.#free,
|
|
42020
41553
|
// methods
|
|
42021
41554
|
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
42022
|
-
backgroundFetch: (k,
|
|
42023
|
-
moveToTail: (
|
|
41555
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
41556
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
42024
41557
|
indexes: (options) => c.#indexes(options),
|
|
42025
41558
|
rindexes: (options) => c.#rindexes(options),
|
|
42026
|
-
isStale: (
|
|
41559
|
+
isStale: (index) => c.#isStale(index)
|
|
42027
41560
|
};
|
|
42028
41561
|
}
|
|
42029
41562
|
// Protected read-only members
|
|
@@ -42170,13 +41703,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42170
41703
|
const starts = new ZeroArray2(this.#max);
|
|
42171
41704
|
this.#ttls = ttls;
|
|
42172
41705
|
this.#starts = starts;
|
|
42173
|
-
this.#setItemTTL = (
|
|
42174
|
-
starts[
|
|
42175
|
-
ttls[
|
|
41706
|
+
this.#setItemTTL = (index, ttl, start = perf2.now()) => {
|
|
41707
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
41708
|
+
ttls[index] = ttl;
|
|
42176
41709
|
if (ttl !== 0 && this.ttlAutopurge) {
|
|
42177
41710
|
const t = setTimeout(() => {
|
|
42178
|
-
if (this.#isStale(
|
|
42179
|
-
this.delete(this.#keyList[
|
|
41711
|
+
if (this.#isStale(index)) {
|
|
41712
|
+
this.delete(this.#keyList[index]);
|
|
42180
41713
|
}
|
|
42181
41714
|
}, ttl + 1);
|
|
42182
41715
|
if (t.unref) {
|
|
@@ -42184,13 +41717,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42184
41717
|
}
|
|
42185
41718
|
}
|
|
42186
41719
|
};
|
|
42187
|
-
this.#updateItemAge = (
|
|
42188
|
-
starts[
|
|
41720
|
+
this.#updateItemAge = (index) => {
|
|
41721
|
+
starts[index] = ttls[index] !== 0 ? perf2.now() : 0;
|
|
42189
41722
|
};
|
|
42190
|
-
this.#statusTTL = (status,
|
|
42191
|
-
if (ttls[
|
|
42192
|
-
const ttl = ttls[
|
|
42193
|
-
const start = starts[
|
|
41723
|
+
this.#statusTTL = (status, index) => {
|
|
41724
|
+
if (ttls[index]) {
|
|
41725
|
+
const ttl = ttls[index];
|
|
41726
|
+
const start = starts[index];
|
|
42194
41727
|
if (!ttl || !start)
|
|
42195
41728
|
return;
|
|
42196
41729
|
status.ttl = ttl;
|
|
@@ -42213,21 +41746,21 @@ var LRUCache2 = class _LRUCache {
|
|
|
42213
41746
|
return n;
|
|
42214
41747
|
};
|
|
42215
41748
|
this.getRemainingTTL = (key) => {
|
|
42216
|
-
const
|
|
42217
|
-
if (
|
|
41749
|
+
const index = this.#keyMap.get(key);
|
|
41750
|
+
if (index === void 0) {
|
|
42218
41751
|
return 0;
|
|
42219
41752
|
}
|
|
42220
|
-
const ttl = ttls[
|
|
42221
|
-
const start = starts[
|
|
41753
|
+
const ttl = ttls[index];
|
|
41754
|
+
const start = starts[index];
|
|
42222
41755
|
if (!ttl || !start) {
|
|
42223
41756
|
return Infinity;
|
|
42224
41757
|
}
|
|
42225
41758
|
const age = (cachedNow || getNow()) - start;
|
|
42226
41759
|
return ttl - age;
|
|
42227
41760
|
};
|
|
42228
|
-
this.#isStale = (
|
|
42229
|
-
const s = starts[
|
|
42230
|
-
const t = ttls[
|
|
41761
|
+
this.#isStale = (index) => {
|
|
41762
|
+
const s = starts[index];
|
|
41763
|
+
const t = ttls[index];
|
|
42231
41764
|
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
42232
41765
|
};
|
|
42233
41766
|
}
|
|
@@ -42244,9 +41777,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42244
41777
|
const sizes = new ZeroArray2(this.#max);
|
|
42245
41778
|
this.#calculatedSize = 0;
|
|
42246
41779
|
this.#sizes = sizes;
|
|
42247
|
-
this.#removeItemSize = (
|
|
42248
|
-
this.#calculatedSize -= sizes[
|
|
42249
|
-
sizes[
|
|
41780
|
+
this.#removeItemSize = (index) => {
|
|
41781
|
+
this.#calculatedSize -= sizes[index];
|
|
41782
|
+
sizes[index] = 0;
|
|
42250
41783
|
};
|
|
42251
41784
|
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
42252
41785
|
if (this.#isBackgroundFetch(v)) {
|
|
@@ -42267,15 +41800,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42267
41800
|
}
|
|
42268
41801
|
return size;
|
|
42269
41802
|
};
|
|
42270
|
-
this.#addItemSize = (
|
|
42271
|
-
sizes[
|
|
41803
|
+
this.#addItemSize = (index, size, status) => {
|
|
41804
|
+
sizes[index] = size;
|
|
42272
41805
|
if (this.#maxSize) {
|
|
42273
|
-
const maxSize2 = this.#maxSize - sizes[
|
|
41806
|
+
const maxSize2 = this.#maxSize - sizes[index];
|
|
42274
41807
|
while (this.#calculatedSize > maxSize2) {
|
|
42275
41808
|
this.#evict(true);
|
|
42276
41809
|
}
|
|
42277
41810
|
}
|
|
42278
|
-
this.#calculatedSize += sizes[
|
|
41811
|
+
this.#calculatedSize += sizes[index];
|
|
42279
41812
|
if (status) {
|
|
42280
41813
|
status.entrySize = size;
|
|
42281
41814
|
status.totalCalculatedSize = this.#calculatedSize;
|
|
@@ -42326,8 +41859,8 @@ var LRUCache2 = class _LRUCache {
|
|
|
42326
41859
|
}
|
|
42327
41860
|
}
|
|
42328
41861
|
}
|
|
42329
|
-
#isValidIndex(
|
|
42330
|
-
return
|
|
41862
|
+
#isValidIndex(index) {
|
|
41863
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
42331
41864
|
}
|
|
42332
41865
|
/**
|
|
42333
41866
|
* Return a generator yielding `[key, value]` pairs,
|
|
@@ -42560,23 +42093,23 @@ var LRUCache2 = class _LRUCache {
|
|
|
42560
42093
|
this.delete(k);
|
|
42561
42094
|
return this;
|
|
42562
42095
|
}
|
|
42563
|
-
let
|
|
42564
|
-
if (
|
|
42565
|
-
|
|
42566
|
-
this.#keyList[
|
|
42567
|
-
this.#valList[
|
|
42568
|
-
this.#keyMap.set(k,
|
|
42569
|
-
this.#next[this.#tail] =
|
|
42570
|
-
this.#prev[
|
|
42571
|
-
this.#tail =
|
|
42096
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
42097
|
+
if (index === void 0) {
|
|
42098
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
42099
|
+
this.#keyList[index] = k;
|
|
42100
|
+
this.#valList[index] = v;
|
|
42101
|
+
this.#keyMap.set(k, index);
|
|
42102
|
+
this.#next[this.#tail] = index;
|
|
42103
|
+
this.#prev[index] = this.#tail;
|
|
42104
|
+
this.#tail = index;
|
|
42572
42105
|
this.#size++;
|
|
42573
|
-
this.#addItemSize(
|
|
42106
|
+
this.#addItemSize(index, size, status);
|
|
42574
42107
|
if (status)
|
|
42575
42108
|
status.set = "add";
|
|
42576
42109
|
noUpdateTTL = false;
|
|
42577
42110
|
} else {
|
|
42578
|
-
this.#moveToTail(
|
|
42579
|
-
const oldVal = this.#valList[
|
|
42111
|
+
this.#moveToTail(index);
|
|
42112
|
+
const oldVal = this.#valList[index];
|
|
42580
42113
|
if (v !== oldVal) {
|
|
42581
42114
|
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
42582
42115
|
oldVal.__abortController.abort(new Error("replaced"));
|
|
@@ -42597,9 +42130,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42597
42130
|
this.#disposed?.push([oldVal, k, "set"]);
|
|
42598
42131
|
}
|
|
42599
42132
|
}
|
|
42600
|
-
this.#removeItemSize(
|
|
42601
|
-
this.#addItemSize(
|
|
42602
|
-
this.#valList[
|
|
42133
|
+
this.#removeItemSize(index);
|
|
42134
|
+
this.#addItemSize(index, size, status);
|
|
42135
|
+
this.#valList[index] = v;
|
|
42603
42136
|
if (status) {
|
|
42604
42137
|
status.set = "replace";
|
|
42605
42138
|
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
@@ -42615,10 +42148,10 @@ var LRUCache2 = class _LRUCache {
|
|
|
42615
42148
|
}
|
|
42616
42149
|
if (this.#ttls) {
|
|
42617
42150
|
if (!noUpdateTTL) {
|
|
42618
|
-
this.#setItemTTL(
|
|
42151
|
+
this.#setItemTTL(index, ttl, start);
|
|
42619
42152
|
}
|
|
42620
42153
|
if (status)
|
|
42621
|
-
this.#statusTTL(status,
|
|
42154
|
+
this.#statusTTL(status, index);
|
|
42622
42155
|
}
|
|
42623
42156
|
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
42624
42157
|
const dt = this.#disposed;
|
|
@@ -42696,24 +42229,24 @@ var LRUCache2 = class _LRUCache {
|
|
|
42696
42229
|
*/
|
|
42697
42230
|
has(k, hasOptions = {}) {
|
|
42698
42231
|
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
42699
|
-
const
|
|
42700
|
-
if (
|
|
42701
|
-
const v = this.#valList[
|
|
42232
|
+
const index = this.#keyMap.get(k);
|
|
42233
|
+
if (index !== void 0) {
|
|
42234
|
+
const v = this.#valList[index];
|
|
42702
42235
|
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
42703
42236
|
return false;
|
|
42704
42237
|
}
|
|
42705
|
-
if (!this.#isStale(
|
|
42238
|
+
if (!this.#isStale(index)) {
|
|
42706
42239
|
if (updateAgeOnHas) {
|
|
42707
|
-
this.#updateItemAge(
|
|
42240
|
+
this.#updateItemAge(index);
|
|
42708
42241
|
}
|
|
42709
42242
|
if (status) {
|
|
42710
42243
|
status.has = "hit";
|
|
42711
|
-
this.#statusTTL(status,
|
|
42244
|
+
this.#statusTTL(status, index);
|
|
42712
42245
|
}
|
|
42713
42246
|
return true;
|
|
42714
42247
|
} else if (status) {
|
|
42715
42248
|
status.has = "stale";
|
|
42716
|
-
this.#statusTTL(status,
|
|
42249
|
+
this.#statusTTL(status, index);
|
|
42717
42250
|
}
|
|
42718
42251
|
} else if (status) {
|
|
42719
42252
|
status.has = "miss";
|
|
@@ -42729,15 +42262,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42729
42262
|
*/
|
|
42730
42263
|
peek(k, peekOptions = {}) {
|
|
42731
42264
|
const { allowStale = this.allowStale } = peekOptions;
|
|
42732
|
-
const
|
|
42733
|
-
if (
|
|
42265
|
+
const index = this.#keyMap.get(k);
|
|
42266
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
42734
42267
|
return;
|
|
42735
42268
|
}
|
|
42736
|
-
const v = this.#valList[
|
|
42269
|
+
const v = this.#valList[index];
|
|
42737
42270
|
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
42738
42271
|
}
|
|
42739
|
-
#backgroundFetch(k,
|
|
42740
|
-
const v =
|
|
42272
|
+
#backgroundFetch(k, index, options, context) {
|
|
42273
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
42741
42274
|
if (this.#isBackgroundFetch(v)) {
|
|
42742
42275
|
return v;
|
|
42743
42276
|
}
|
|
@@ -42768,10 +42301,10 @@ var LRUCache2 = class _LRUCache {
|
|
|
42768
42301
|
return fetchFail(ac.signal.reason);
|
|
42769
42302
|
}
|
|
42770
42303
|
const bf2 = p;
|
|
42771
|
-
if (this.#valList[
|
|
42304
|
+
if (this.#valList[index] === p) {
|
|
42772
42305
|
if (v2 === void 0) {
|
|
42773
42306
|
if (bf2.__staleWhileFetching) {
|
|
42774
|
-
this.#valList[
|
|
42307
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
42775
42308
|
} else {
|
|
42776
42309
|
this.delete(k);
|
|
42777
42310
|
}
|
|
@@ -42796,12 +42329,12 @@ var LRUCache2 = class _LRUCache {
|
|
|
42796
42329
|
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
42797
42330
|
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
42798
42331
|
const bf2 = p;
|
|
42799
|
-
if (this.#valList[
|
|
42332
|
+
if (this.#valList[index] === p) {
|
|
42800
42333
|
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
42801
42334
|
if (del) {
|
|
42802
42335
|
this.delete(k);
|
|
42803
42336
|
} else if (!allowStaleAborted) {
|
|
42804
|
-
this.#valList[
|
|
42337
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
42805
42338
|
}
|
|
42806
42339
|
}
|
|
42807
42340
|
if (allowStale) {
|
|
@@ -42835,11 +42368,11 @@ var LRUCache2 = class _LRUCache {
|
|
|
42835
42368
|
__staleWhileFetching: v,
|
|
42836
42369
|
__returned: void 0
|
|
42837
42370
|
});
|
|
42838
|
-
if (
|
|
42371
|
+
if (index === void 0) {
|
|
42839
42372
|
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
42840
|
-
|
|
42373
|
+
index = this.#keyMap.get(k);
|
|
42841
42374
|
} else {
|
|
42842
|
-
this.#valList[
|
|
42375
|
+
this.#valList[index] = bf;
|
|
42843
42376
|
}
|
|
42844
42377
|
return bf;
|
|
42845
42378
|
}
|
|
@@ -42897,14 +42430,14 @@ var LRUCache2 = class _LRUCache {
|
|
|
42897
42430
|
status,
|
|
42898
42431
|
signal
|
|
42899
42432
|
};
|
|
42900
|
-
let
|
|
42901
|
-
if (
|
|
42433
|
+
let index = this.#keyMap.get(k);
|
|
42434
|
+
if (index === void 0) {
|
|
42902
42435
|
if (status)
|
|
42903
42436
|
status.fetch = "miss";
|
|
42904
|
-
const p = this.#backgroundFetch(k,
|
|
42437
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
42905
42438
|
return p.__returned = p;
|
|
42906
42439
|
} else {
|
|
42907
|
-
const v = this.#valList[
|
|
42440
|
+
const v = this.#valList[index];
|
|
42908
42441
|
if (this.#isBackgroundFetch(v)) {
|
|
42909
42442
|
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
42910
42443
|
if (status) {
|
|
@@ -42914,19 +42447,19 @@ var LRUCache2 = class _LRUCache {
|
|
|
42914
42447
|
}
|
|
42915
42448
|
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
42916
42449
|
}
|
|
42917
|
-
const isStale = this.#isStale(
|
|
42450
|
+
const isStale = this.#isStale(index);
|
|
42918
42451
|
if (!forceRefresh && !isStale) {
|
|
42919
42452
|
if (status)
|
|
42920
42453
|
status.fetch = "hit";
|
|
42921
|
-
this.#moveToTail(
|
|
42454
|
+
this.#moveToTail(index);
|
|
42922
42455
|
if (updateAgeOnGet) {
|
|
42923
|
-
this.#updateItemAge(
|
|
42456
|
+
this.#updateItemAge(index);
|
|
42924
42457
|
}
|
|
42925
42458
|
if (status)
|
|
42926
|
-
this.#statusTTL(status,
|
|
42459
|
+
this.#statusTTL(status, index);
|
|
42927
42460
|
return v;
|
|
42928
42461
|
}
|
|
42929
|
-
const p = this.#backgroundFetch(k,
|
|
42462
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
42930
42463
|
const hasStale = p.__staleWhileFetching !== void 0;
|
|
42931
42464
|
const staleVal = hasStale && allowStale;
|
|
42932
42465
|
if (status) {
|
|
@@ -42945,13 +42478,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42945
42478
|
*/
|
|
42946
42479
|
get(k, getOptions = {}) {
|
|
42947
42480
|
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
42948
|
-
const
|
|
42949
|
-
if (
|
|
42950
|
-
const value = this.#valList[
|
|
42481
|
+
const index = this.#keyMap.get(k);
|
|
42482
|
+
if (index !== void 0) {
|
|
42483
|
+
const value = this.#valList[index];
|
|
42951
42484
|
const fetching = this.#isBackgroundFetch(value);
|
|
42952
42485
|
if (status)
|
|
42953
|
-
this.#statusTTL(status,
|
|
42954
|
-
if (this.#isStale(
|
|
42486
|
+
this.#statusTTL(status, index);
|
|
42487
|
+
if (this.#isStale(index)) {
|
|
42955
42488
|
if (status)
|
|
42956
42489
|
status.get = "stale";
|
|
42957
42490
|
if (!fetching) {
|
|
@@ -42973,9 +42506,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42973
42506
|
if (fetching) {
|
|
42974
42507
|
return value.__staleWhileFetching;
|
|
42975
42508
|
}
|
|
42976
|
-
this.#moveToTail(
|
|
42509
|
+
this.#moveToTail(index);
|
|
42977
42510
|
if (updateAgeOnGet) {
|
|
42978
|
-
this.#updateItemAge(
|
|
42511
|
+
this.#updateItemAge(index);
|
|
42979
42512
|
}
|
|
42980
42513
|
return value;
|
|
42981
42514
|
}
|
|
@@ -42987,15 +42520,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42987
42520
|
this.#prev[n] = p;
|
|
42988
42521
|
this.#next[p] = n;
|
|
42989
42522
|
}
|
|
42990
|
-
#moveToTail(
|
|
42991
|
-
if (
|
|
42992
|
-
if (
|
|
42993
|
-
this.#head = this.#next[
|
|
42523
|
+
#moveToTail(index) {
|
|
42524
|
+
if (index !== this.#tail) {
|
|
42525
|
+
if (index === this.#head) {
|
|
42526
|
+
this.#head = this.#next[index];
|
|
42994
42527
|
} else {
|
|
42995
|
-
this.#connect(this.#prev[
|
|
42528
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
42996
42529
|
}
|
|
42997
|
-
this.#connect(this.#tail,
|
|
42998
|
-
this.#tail =
|
|
42530
|
+
this.#connect(this.#tail, index);
|
|
42531
|
+
this.#tail = index;
|
|
42999
42532
|
}
|
|
43000
42533
|
}
|
|
43001
42534
|
/**
|
|
@@ -43005,14 +42538,14 @@ var LRUCache2 = class _LRUCache {
|
|
|
43005
42538
|
delete(k) {
|
|
43006
42539
|
let deleted = false;
|
|
43007
42540
|
if (this.#size !== 0) {
|
|
43008
|
-
const
|
|
43009
|
-
if (
|
|
42541
|
+
const index = this.#keyMap.get(k);
|
|
42542
|
+
if (index !== void 0) {
|
|
43010
42543
|
deleted = true;
|
|
43011
42544
|
if (this.#size === 1) {
|
|
43012
42545
|
this.clear();
|
|
43013
42546
|
} else {
|
|
43014
|
-
this.#removeItemSize(
|
|
43015
|
-
const v = this.#valList[
|
|
42547
|
+
this.#removeItemSize(index);
|
|
42548
|
+
const v = this.#valList[index];
|
|
43016
42549
|
if (this.#isBackgroundFetch(v)) {
|
|
43017
42550
|
v.__abortController.abort(new Error("deleted"));
|
|
43018
42551
|
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
@@ -43024,20 +42557,20 @@ var LRUCache2 = class _LRUCache {
|
|
|
43024
42557
|
}
|
|
43025
42558
|
}
|
|
43026
42559
|
this.#keyMap.delete(k);
|
|
43027
|
-
this.#keyList[
|
|
43028
|
-
this.#valList[
|
|
43029
|
-
if (
|
|
43030
|
-
this.#tail = this.#prev[
|
|
43031
|
-
} else if (
|
|
43032
|
-
this.#head = this.#next[
|
|
42560
|
+
this.#keyList[index] = void 0;
|
|
42561
|
+
this.#valList[index] = void 0;
|
|
42562
|
+
if (index === this.#tail) {
|
|
42563
|
+
this.#tail = this.#prev[index];
|
|
42564
|
+
} else if (index === this.#head) {
|
|
42565
|
+
this.#head = this.#next[index];
|
|
43033
42566
|
} else {
|
|
43034
|
-
const pi = this.#prev[
|
|
43035
|
-
this.#next[pi] = this.#next[
|
|
43036
|
-
const ni = this.#next[
|
|
43037
|
-
this.#prev[ni] = this.#prev[
|
|
42567
|
+
const pi = this.#prev[index];
|
|
42568
|
+
this.#next[pi] = this.#next[index];
|
|
42569
|
+
const ni = this.#next[index];
|
|
42570
|
+
this.#prev[ni] = this.#prev[index];
|
|
43038
42571
|
}
|
|
43039
42572
|
this.#size--;
|
|
43040
|
-
this.#free.push(
|
|
42573
|
+
this.#free.push(index);
|
|
43041
42574
|
}
|
|
43042
42575
|
}
|
|
43043
42576
|
}
|
|
@@ -43054,12 +42587,12 @@ var LRUCache2 = class _LRUCache {
|
|
|
43054
42587
|
* Clear the cache entirely, throwing away all values.
|
|
43055
42588
|
*/
|
|
43056
42589
|
clear() {
|
|
43057
|
-
for (const
|
|
43058
|
-
const v = this.#valList[
|
|
42590
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
42591
|
+
const v = this.#valList[index];
|
|
43059
42592
|
if (this.#isBackgroundFetch(v)) {
|
|
43060
42593
|
v.__abortController.abort(new Error("deleted"));
|
|
43061
42594
|
} else {
|
|
43062
|
-
const k = this.#keyList[
|
|
42595
|
+
const k = this.#keyList[index];
|
|
43063
42596
|
if (this.#hasDispose) {
|
|
43064
42597
|
this.#dispose?.(v, k, "delete");
|
|
43065
42598
|
}
|
|
@@ -43197,9 +42730,9 @@ var CheckpointDB4 = class _CheckpointDB {
|
|
|
43197
42730
|
return value2;
|
|
43198
42731
|
}
|
|
43199
42732
|
}
|
|
43200
|
-
for (let
|
|
43201
|
-
if (this.checkpoints[
|
|
43202
|
-
return this.checkpoints[
|
|
42733
|
+
for (let index = this.checkpoints.length - 1; index >= 0; index--) {
|
|
42734
|
+
if (this.checkpoints[index].keyValueMap.has(keyHex)) {
|
|
42735
|
+
return this.checkpoints[index].keyValueMap.get(keyHex);
|
|
43203
42736
|
}
|
|
43204
42737
|
}
|
|
43205
42738
|
const value = await this.db.get(keyHex, {
|
|
@@ -45271,7 +44804,7 @@ function valuesArrayToHeaderData2(values) {
|
|
|
45271
44804
|
number2,
|
|
45272
44805
|
gasLimit,
|
|
45273
44806
|
gasUsed,
|
|
45274
|
-
|
|
44807
|
+
timestamp,
|
|
45275
44808
|
extraData,
|
|
45276
44809
|
mixHash,
|
|
45277
44810
|
nonce,
|
|
@@ -45300,7 +44833,7 @@ function valuesArrayToHeaderData2(values) {
|
|
|
45300
44833
|
...number2 !== void 0 ? { number: number2 } : {},
|
|
45301
44834
|
...gasLimit !== void 0 ? { gasLimit } : {},
|
|
45302
44835
|
...gasUsed !== void 0 ? { gasUsed } : {},
|
|
45303
|
-
...
|
|
44836
|
+
...timestamp !== void 0 ? { timestamp } : {},
|
|
45304
44837
|
...extraData !== void 0 ? { extraData } : {},
|
|
45305
44838
|
...mixHash !== void 0 ? { mixHash } : {},
|
|
45306
44839
|
...nonce !== void 0 ? { nonce } : {},
|
|
@@ -45461,7 +44994,7 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45461
44994
|
const number2 = safeToType(headerData.number, 1) ?? defaults2.number;
|
|
45462
44995
|
const gasLimit = safeToType(headerData.gasLimit, 1) ?? defaults2.gasLimit;
|
|
45463
44996
|
const gasUsed = safeToType(headerData.gasUsed, 1) ?? defaults2.gasUsed;
|
|
45464
|
-
const
|
|
44997
|
+
const timestamp = safeToType(headerData.timestamp, 1) ?? defaults2.timestamp;
|
|
45465
44998
|
const extraData = safeToType(headerData.extraData, 2) ?? defaults2.extraData;
|
|
45466
44999
|
const mixHash = safeToType(headerData.mixHash, 2) ?? defaults2.mixHash;
|
|
45467
45000
|
const nonce = safeToType(headerData.nonce, 2) ?? defaults2.nonce;
|
|
@@ -45469,12 +45002,12 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45469
45002
|
if (setHardfork === true) {
|
|
45470
45003
|
this.common.ethjsCommon.setHardforkBy({
|
|
45471
45004
|
blockNumber: number2,
|
|
45472
|
-
timestamp
|
|
45005
|
+
timestamp
|
|
45473
45006
|
});
|
|
45474
45007
|
} else if (typeof setHardfork !== "boolean") {
|
|
45475
45008
|
this.common.ethjsCommon.setHardforkBy({
|
|
45476
45009
|
blockNumber: number2,
|
|
45477
|
-
timestamp
|
|
45010
|
+
timestamp
|
|
45478
45011
|
});
|
|
45479
45012
|
}
|
|
45480
45013
|
const hardforkDefaults = {
|
|
@@ -45522,7 +45055,7 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45522
45055
|
this.number = number2;
|
|
45523
45056
|
this.gasLimit = gasLimit;
|
|
45524
45057
|
this.gasUsed = gasUsed;
|
|
45525
|
-
this.timestamp =
|
|
45058
|
+
this.timestamp = timestamp;
|
|
45526
45059
|
this.extraData = extraData;
|
|
45527
45060
|
this.mixHash = mixHash;
|
|
45528
45061
|
this.nonce = nonce;
|
|
@@ -46285,8 +45818,8 @@ var Block2 = class _Block {
|
|
|
46285
45818
|
for (const uncleHeaderData of uhsData ?? []) {
|
|
46286
45819
|
uncleHeaders.push(BlockHeader2.fromValuesArray(uncleHeaderData, uncleOpts));
|
|
46287
45820
|
}
|
|
46288
|
-
const withdrawals = withdrawalBytes?.map(([
|
|
46289
|
-
index
|
|
45821
|
+
const withdrawals = withdrawalBytes?.map(([index, validatorIndex, address, amount]) => ({
|
|
45822
|
+
index,
|
|
46290
45823
|
validatorIndex,
|
|
46291
45824
|
address,
|
|
46292
45825
|
amount
|
|
@@ -46325,14 +45858,14 @@ var Block2 = class _Block {
|
|
|
46325
45858
|
executionWitness
|
|
46326
45859
|
} = payload;
|
|
46327
45860
|
const txs = [];
|
|
46328
|
-
for (const [
|
|
45861
|
+
for (const [index, serializedTx] of transactions.entries()) {
|
|
46329
45862
|
try {
|
|
46330
45863
|
const tx = createTxFromRLP(hexToBytes$2(serializedTx), {
|
|
46331
45864
|
common: opts?.common.ethjsCommon
|
|
46332
45865
|
});
|
|
46333
45866
|
txs.push(tx);
|
|
46334
45867
|
} catch (error) {
|
|
46335
|
-
const validationError2 = `Invalid tx at index ${
|
|
45868
|
+
const validationError2 = `Invalid tx at index ${index}: ${error}`;
|
|
46336
45869
|
throw validationError2;
|
|
46337
45870
|
}
|
|
46338
45871
|
}
|
|
@@ -46582,9 +46115,9 @@ var Block2 = class _Block {
|
|
|
46582
46115
|
return;
|
|
46583
46116
|
}
|
|
46584
46117
|
if (verifyTxs) {
|
|
46585
|
-
for (const [
|
|
46118
|
+
for (const [index, tx] of this.transactions.entries()) {
|
|
46586
46119
|
if (!tx.isSigned()) {
|
|
46587
|
-
const msg = this._errorMsg(`invalid transactions: transaction at index ${
|
|
46120
|
+
const msg = this._errorMsg(`invalid transactions: transaction at index ${index} is unsigned`);
|
|
46588
46121
|
throw new Error(msg);
|
|
46589
46122
|
}
|
|
46590
46123
|
}
|
|
@@ -46810,7 +46343,7 @@ function blockHeaderFromRpc(blockParams, options) {
|
|
|
46810
46343
|
number: number2,
|
|
46811
46344
|
gasLimit,
|
|
46812
46345
|
gasUsed,
|
|
46813
|
-
timestamp
|
|
46346
|
+
timestamp,
|
|
46814
46347
|
extraData,
|
|
46815
46348
|
mixHash,
|
|
46816
46349
|
nonce,
|
|
@@ -46834,7 +46367,7 @@ function blockHeaderFromRpc(blockParams, options) {
|
|
|
46834
46367
|
number: number2,
|
|
46835
46368
|
gasLimit,
|
|
46836
46369
|
gasUsed,
|
|
46837
|
-
timestamp
|
|
46370
|
+
timestamp,
|
|
46838
46371
|
extraData,
|
|
46839
46372
|
mixHash,
|
|
46840
46373
|
nonce,
|
|
@@ -47397,11 +46930,11 @@ var Evm = class _Evm extends EVM {
|
|
|
47397
46930
|
"Custom precompiles is empty. This is an internal bug as it should always be defined"
|
|
47398
46931
|
);
|
|
47399
46932
|
}
|
|
47400
|
-
const
|
|
47401
|
-
if (
|
|
46933
|
+
const index = this._customPrecompiles.indexOf(precompile);
|
|
46934
|
+
if (index === -1) {
|
|
47402
46935
|
throw new InvalidParamsError("Precompile not found");
|
|
47403
46936
|
}
|
|
47404
|
-
this._customPrecompiles.splice(
|
|
46937
|
+
this._customPrecompiles.splice(index, 1);
|
|
47405
46938
|
this._precompiles = getActivePrecompiles(this.common, this._customPrecompiles);
|
|
47406
46939
|
}
|
|
47407
46940
|
/**
|
|
@@ -47656,8 +47189,8 @@ var ReceiptsManager = class _ReceiptsManager {
|
|
|
47656
47189
|
const block = value;
|
|
47657
47190
|
if (operation === 0) {
|
|
47658
47191
|
for (const [i, tx] of block.transactions.entries()) {
|
|
47659
|
-
const
|
|
47660
|
-
const encoded = this.rlp(0, 2,
|
|
47192
|
+
const index = [block.hash(), i];
|
|
47193
|
+
const encoded = this.rlp(0, 2, index);
|
|
47661
47194
|
await this.mapDb.put("TxHash", tx.hash(), encoded);
|
|
47662
47195
|
}
|
|
47663
47196
|
} else if (operation === 1) {
|
|
@@ -49344,12 +48877,12 @@ createBlockHeader();
|
|
|
49344
48877
|
|
|
49345
48878
|
// ../../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
|
|
49346
48879
|
var parentBeaconBlockRootAddress2 = createAddressFromString("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02");
|
|
49347
|
-
var accumulateParentBeaconBlockRoot2 = (vm) => async (root2,
|
|
48880
|
+
var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp) => {
|
|
49348
48881
|
if (!vm.common.ethjsCommon.isActivatedEIP(4788)) {
|
|
49349
48882
|
throw new EipNotEnabledError("Cannot call `accumulateParentBeaconBlockRoot`: EIP 4788 is not active");
|
|
49350
48883
|
}
|
|
49351
48884
|
const historicalRootsLength = 8191n;
|
|
49352
|
-
const timestampIndex =
|
|
48885
|
+
const timestampIndex = timestamp % historicalRootsLength;
|
|
49353
48886
|
const timestampExtended = timestampIndex + historicalRootsLength;
|
|
49354
48887
|
if (await vm.stateManager.getAccount(parentBeaconBlockRootAddress2) === void 0) {
|
|
49355
48888
|
await vm.evm.journal.putAccount(parentBeaconBlockRootAddress2, new Account());
|
|
@@ -49357,7 +48890,7 @@ var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp2) => {
|
|
|
49357
48890
|
await vm.stateManager.putStorage(
|
|
49358
48891
|
parentBeaconBlockRootAddress2,
|
|
49359
48892
|
setLengthLeft(toBytes$1(timestampIndex), 32),
|
|
49360
|
-
toBytes$1(
|
|
48893
|
+
toBytes$1(timestamp)
|
|
49361
48894
|
);
|
|
49362
48895
|
await vm.stateManager.putStorage(parentBeaconBlockRootAddress2, setLengthLeft(toBytes$1(timestampExtended), 32), root2);
|
|
49363
48896
|
};
|
|
@@ -50406,7 +49939,7 @@ var BlockBuilder2 = class {
|
|
|
50406
49939
|
const receiptTrie = await this.receiptTrie();
|
|
50407
49940
|
const logsBloom = this.logsBloom();
|
|
50408
49941
|
const gasUsed = this.gasUsed;
|
|
50409
|
-
const
|
|
49942
|
+
const timestamp = this.headerData.timestamp ?? 0n;
|
|
50410
49943
|
let blobGasUsed = void 0;
|
|
50411
49944
|
if (this.vm.common.ethjsCommon.isActivatedEIP(4844) === true) {
|
|
50412
49945
|
blobGasUsed = this.blobGasUsed;
|
|
@@ -50420,7 +49953,7 @@ var BlockBuilder2 = class {
|
|
|
50420
49953
|
receiptTrie,
|
|
50421
49954
|
logsBloom,
|
|
50422
49955
|
gasUsed,
|
|
50423
|
-
timestamp
|
|
49956
|
+
timestamp
|
|
50424
49957
|
// correct excessBlobGas should already be part of headerData used above
|
|
50425
49958
|
};
|
|
50426
49959
|
if (consensusType === ConsensusType.ProofOfWork) {
|
|
@@ -50449,8 +49982,8 @@ var BlockBuilder2 = class {
|
|
|
50449
49982
|
await this.vm.evm.journal.checkpoint();
|
|
50450
49983
|
this.checkpointed = true;
|
|
50451
49984
|
}
|
|
50452
|
-
const { parentBeaconBlockRoot, timestamp
|
|
50453
|
-
const timestampValue =
|
|
49985
|
+
const { parentBeaconBlockRoot, timestamp } = this.headerData;
|
|
49986
|
+
const timestampValue = timestamp ?? 0n;
|
|
50454
49987
|
const timestampBigInt = toType(timestampValue, TypeOutput.BigInt) ?? 0n;
|
|
50455
49988
|
const parentBeaconBlockRootBuf = parentBeaconBlockRoot ? toType(parentBeaconBlockRoot, TypeOutput.Uint8Array) : new Uint8Array(32);
|
|
50456
49989
|
await accumulateParentBeaconBlockRoot2(this.vm)(
|
|
@@ -50858,9 +50391,9 @@ var createTevmNode = (options = {}) => {
|
|
|
50858
50391
|
removeListener(eventName, listener) {
|
|
50859
50392
|
const listeners = events.get(eventName);
|
|
50860
50393
|
if (listeners) {
|
|
50861
|
-
const
|
|
50862
|
-
if (
|
|
50863
|
-
listeners.splice(
|
|
50394
|
+
const index = listeners.findIndex((l) => l === listener);
|
|
50395
|
+
if (index !== -1) {
|
|
50396
|
+
listeners.splice(index, 1);
|
|
50864
50397
|
if (listeners.length === 0) {
|
|
50865
50398
|
events.delete(eventName);
|
|
50866
50399
|
}
|
|
@@ -51692,12 +51225,12 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51692
51225
|
const receiptsManager = await client.getReceiptsManager();
|
|
51693
51226
|
for (let count = 0; count < blockCount; count++) {
|
|
51694
51227
|
const parentBlock = await vm.blockchain.getCanonicalHeadBlock();
|
|
51695
|
-
let
|
|
51696
|
-
|
|
51228
|
+
let timestamp = Math.max(Math.floor(Date.now() / 1e3), Number(parentBlock.header.timestamp));
|
|
51229
|
+
timestamp = count === 0 ? timestamp : timestamp + interval;
|
|
51697
51230
|
const blockBuilder = await vm.buildBlock({
|
|
51698
51231
|
parentBlock,
|
|
51699
51232
|
headerData: {
|
|
51700
|
-
timestamp
|
|
51233
|
+
timestamp,
|
|
51701
51234
|
number: parentBlock.header.number + 1n,
|
|
51702
51235
|
// The following 2 are currently not supported
|
|
51703
51236
|
// difficulty: undefined,
|
|
@@ -51726,13 +51259,13 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51726
51259
|
] : await pool.txsByPriceAndNonce({
|
|
51727
51260
|
baseFee: parentBlock.header.calcNextBaseFee()
|
|
51728
51261
|
});
|
|
51729
|
-
let
|
|
51262
|
+
let index = 0;
|
|
51730
51263
|
const blockFull = false;
|
|
51731
51264
|
const receipts = [];
|
|
51732
|
-
while (
|
|
51265
|
+
while (index < orderedTx.length && !blockFull) {
|
|
51733
51266
|
const nextTx = (
|
|
51734
51267
|
/** @type {import('@tevm/tx').TypedTransaction}*/
|
|
51735
|
-
orderedTx[
|
|
51268
|
+
orderedTx[index]
|
|
51736
51269
|
);
|
|
51737
51270
|
client.logger.debug(bytesToHex$2(nextTx.hash()), "new tx added");
|
|
51738
51271
|
const txResult = await blockBuilder.addTransaction(nextTx, {
|
|
@@ -51741,7 +51274,7 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51741
51274
|
skipHardForkValidation: true
|
|
51742
51275
|
});
|
|
51743
51276
|
receipts.push(txResult.receipt);
|
|
51744
|
-
|
|
51277
|
+
index++;
|
|
51745
51278
|
}
|
|
51746
51279
|
await vm.stateManager.checkpoint();
|
|
51747
51280
|
const createNewStateRoot = true;
|
|
@@ -57522,9 +57055,6 @@ function getLogger() {
|
|
|
57522
57055
|
return loggerContext.getStore() ?? defaultLogger();
|
|
57523
57056
|
}
|
|
57524
57057
|
|
|
57525
|
-
// src/index.node.ts
|
|
57526
|
-
__reExport(index_node_exports, OfferDB_exports2);
|
|
57527
|
-
|
|
57528
57058
|
// src/RouterEvent.ts
|
|
57529
57059
|
var RouterEvent_exports = {};
|
|
57530
57060
|
__export(RouterEvent_exports, {
|
|
@@ -57650,14 +57180,14 @@ function morpho(parameters) {
|
|
|
57650
57180
|
);
|
|
57651
57181
|
const buyOffersEmptyCallback = batch2(
|
|
57652
57182
|
"buy_offers_empty_callback",
|
|
57653
|
-
async (
|
|
57183
|
+
async (offers, { publicClients }) => {
|
|
57654
57184
|
const issues = /* @__PURE__ */ new Map();
|
|
57655
57185
|
const hashToIndex = /* @__PURE__ */ new Map();
|
|
57656
|
-
for (let i = 0; i <
|
|
57657
|
-
const offer =
|
|
57186
|
+
for (let i = 0; i < offers.length; i++) {
|
|
57187
|
+
const offer = offers[i];
|
|
57658
57188
|
hashToIndex.set(offer.hash, i);
|
|
57659
57189
|
}
|
|
57660
|
-
const { buyOffers, sellOffers: _sellOffers } =
|
|
57190
|
+
const { buyOffers, sellOffers: _sellOffers } = offers.reduce(
|
|
57661
57191
|
(acc, offer) => {
|
|
57662
57192
|
offer.buy ? acc.buyOffers.push(offer) : issues.set(hashToIndex.get(offer.hash), {
|
|
57663
57193
|
message: "Onchain callback for sell offers is not supported yet."
|
|
@@ -57670,9 +57200,9 @@ function morpho(parameters) {
|
|
|
57670
57200
|
for (const offer of buyOffers) {
|
|
57671
57201
|
const chainName = getChain(offer.chainId)?.name;
|
|
57672
57202
|
const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
|
|
57673
|
-
const
|
|
57674
|
-
|
|
57675
|
-
loanTokens.set(offer.loanToken.toLowerCase(),
|
|
57203
|
+
const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
|
|
57204
|
+
offers2.push(offer);
|
|
57205
|
+
loanTokens.set(offer.loanToken.toLowerCase(), offers2);
|
|
57676
57206
|
buyOffersPerLoanAsset.set(chainName, loanTokens);
|
|
57677
57207
|
}
|
|
57678
57208
|
await Promise.all(
|
|
@@ -57681,8 +57211,8 @@ function morpho(parameters) {
|
|
|
57681
57211
|
const publicClient = publicClients[chainName];
|
|
57682
57212
|
const morpho2 = morphoPerChain.get(chains[chainName].id);
|
|
57683
57213
|
if (!publicClient) {
|
|
57684
|
-
const
|
|
57685
|
-
for (const offer of
|
|
57214
|
+
const offers2 = Array.from(loanTokens.values()).flat();
|
|
57215
|
+
for (const offer of offers2) {
|
|
57686
57216
|
issues.set(hashToIndex.get(offer.hash), {
|
|
57687
57217
|
message: `Public client for chain "${chainName}" is not available`
|
|
57688
57218
|
});
|
|
@@ -57691,9 +57221,9 @@ function morpho(parameters) {
|
|
|
57691
57221
|
}
|
|
57692
57222
|
const balances = /* @__PURE__ */ new Map();
|
|
57693
57223
|
const allowances = /* @__PURE__ */ new Map();
|
|
57694
|
-
for (const [loanToken2,
|
|
57224
|
+
for (const [loanToken2, offers2] of loanTokens) {
|
|
57695
57225
|
const data = await Promise.all(
|
|
57696
|
-
|
|
57226
|
+
offers2.flatMap((offer) => [
|
|
57697
57227
|
publicClient.readContract({
|
|
57698
57228
|
address: loanToken2,
|
|
57699
57229
|
abi: parseAbi$1([
|
|
@@ -57712,8 +57242,8 @@ function morpho(parameters) {
|
|
|
57712
57242
|
})
|
|
57713
57243
|
])
|
|
57714
57244
|
);
|
|
57715
|
-
for (let i = 0; i <
|
|
57716
|
-
const user =
|
|
57245
|
+
for (let i = 0; i < offers2.length; i++) {
|
|
57246
|
+
const user = offers2[i].offering.toLowerCase();
|
|
57717
57247
|
const balance = data[i * 2] || 0n;
|
|
57718
57248
|
const allowance = data[i * 2 + 1] || 0n;
|
|
57719
57249
|
const userBalances = balances.get(user) ?? /* @__PURE__ */ new Map();
|
|
@@ -57790,6 +57320,6 @@ safe-buffer/index.js:
|
|
|
57790
57320
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
57791
57321
|
*/
|
|
57792
57322
|
|
|
57793
|
-
export { apiSchema_exports as ApiSchema, Chain_exports as Chain, EVM_exports as EVM, Logger_exports as Logger,
|
|
57323
|
+
export { apiSchema_exports as ApiSchema, Chain_exports as Chain, EVM_exports as EVM, Logger_exports as Logger, OfferStore_exports as OfferStore, router_exports as Router, RouterEvent_exports as RouterEvent, RouterOffer_exports as RouterOffer, utils_exports as Utils, Validation_exports as Validation, ValidationRule_exports as ValidationRule };
|
|
57794
57324
|
//# sourceMappingURL=index.node.mjs.map
|
|
57795
57325
|
//# sourceMappingURL=index.node.mjs.map
|