@morpho-dev/router 0.0.17 → 0.0.19
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 +139 -12
- package/dist/index.browser.d.ts +139 -12
- package/dist/index.browser.js +533 -92
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +534 -89
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +132 -750
- package/dist/index.node.d.ts +132 -750
- package/dist/index.node.js +895 -1302
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +894 -1291
- 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, LLTV, Maturity, Offer, Format, Time, 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 { parseUnits, defineChain, hexToBytes as hexToBytes$1, bytesToHex as bytesToHex$1, maxUint256, formatUnits, 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;
|
|
@@ -8430,19 +8419,33 @@ var GetOffersQueryParams = z.object({
|
|
|
8430
8419
|
example: "1500000000000000000"
|
|
8431
8420
|
}),
|
|
8432
8421
|
// Time range
|
|
8433
|
-
min_maturity: z.
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8422
|
+
min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
8423
|
+
try {
|
|
8424
|
+
return Maturity.from(maturity);
|
|
8425
|
+
} catch (e) {
|
|
8426
|
+
ctx.addIssue({
|
|
8427
|
+
code: "custom",
|
|
8428
|
+
message: e.message
|
|
8429
|
+
});
|
|
8430
|
+
return z.NEVER;
|
|
8431
|
+
}
|
|
8432
|
+
}).optional(),
|
|
8433
|
+
max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
8434
|
+
try {
|
|
8435
|
+
return Maturity.from(maturity);
|
|
8436
|
+
} catch (e) {
|
|
8437
|
+
ctx.addIssue({
|
|
8438
|
+
code: "custom",
|
|
8439
|
+
message: e.message
|
|
8440
|
+
});
|
|
8441
|
+
return z.NEVER;
|
|
8442
|
+
}
|
|
8443
|
+
}).optional(),
|
|
8444
|
+
min_expiry: z.coerce.number().int().optional().meta({
|
|
8442
8445
|
description: "Minimum expiry timestamp (Unix timestamp in seconds)",
|
|
8443
8446
|
example: "1700000000"
|
|
8444
8447
|
}),
|
|
8445
|
-
max_expiry: z.
|
|
8448
|
+
max_expiry: z.coerce.number().int().optional().meta({
|
|
8446
8449
|
description: "Maximum expiry timestamp (Unix timestamp in seconds)",
|
|
8447
8450
|
example: "1800000000"
|
|
8448
8451
|
}),
|
|
@@ -8464,51 +8467,81 @@ var GetOffersQueryParams = z.object({
|
|
|
8464
8467
|
{
|
|
8465
8468
|
message: "Collateral tuple must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Asset must be 0x + 40 hex chars, oracle must be 0x + 40 hex chars, lltv must be a number (e.g., 80.5)."
|
|
8466
8469
|
}
|
|
8467
|
-
).transform((val) => {
|
|
8470
|
+
).transform((val, ctx) => {
|
|
8468
8471
|
return val.split("#").map((tuple) => {
|
|
8469
8472
|
const parts = tuple.split(":");
|
|
8470
8473
|
if (parts.length === 0 || !parts[0]) {
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
]);
|
|
8474
|
+
ctx.addIssue({
|
|
8475
|
+
code: "custom",
|
|
8476
|
+
message: "Asset address is required for each collateral tuple",
|
|
8477
|
+
path: ["asset"],
|
|
8478
|
+
input: val
|
|
8479
|
+
});
|
|
8480
|
+
return z.NEVER;
|
|
8479
8481
|
}
|
|
8480
8482
|
const asset = parts[0]?.toLowerCase();
|
|
8481
8483
|
const oracle = parts[1]?.toLowerCase();
|
|
8482
8484
|
const lltv = parts[2] ? parseFloat(parts[2]) : void 0;
|
|
8483
8485
|
if (lltv !== void 0 && (lltv < MIN_LLTV || lltv > MAX_LLTV)) {
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
+
ctx.addIssue({
|
|
8487
|
+
code: "custom",
|
|
8488
|
+
message: `LLTV must be between ${MIN_LLTV} and ${MAX_LLTV} (0-100%)`,
|
|
8489
|
+
path: ["lltv"],
|
|
8490
|
+
input: val
|
|
8491
|
+
});
|
|
8492
|
+
return z.NEVER;
|
|
8493
|
+
}
|
|
8494
|
+
let lltvValue;
|
|
8495
|
+
if (lltv !== void 0) {
|
|
8496
|
+
try {
|
|
8497
|
+
lltvValue = LLTV.from(parseUnits(lltv.toString(), 16));
|
|
8498
|
+
} catch (e) {
|
|
8499
|
+
ctx.issues.push({
|
|
8486
8500
|
code: "custom",
|
|
8487
|
-
message:
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
}
|
|
8491
|
-
|
|
8501
|
+
message: e instanceof LLTV.InvalidLLTVError || e instanceof LLTV.InvalidOptionError ? e.message : "Invalid LLTV.",
|
|
8502
|
+
input: lltv,
|
|
8503
|
+
path: ["lltv"]
|
|
8504
|
+
});
|
|
8505
|
+
return z.NEVER;
|
|
8506
|
+
}
|
|
8492
8507
|
}
|
|
8493
8508
|
return {
|
|
8494
8509
|
asset,
|
|
8495
8510
|
oracle,
|
|
8496
|
-
lltv
|
|
8511
|
+
lltv: lltvValue
|
|
8497
8512
|
};
|
|
8498
8513
|
});
|
|
8499
8514
|
}).optional().meta({
|
|
8500
8515
|
description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
|
|
8501
|
-
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:
|
|
8516
|
+
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
|
|
8502
8517
|
}),
|
|
8503
|
-
min_lltv: z.
|
|
8504
|
-
|
|
8505
|
-
|
|
8518
|
+
min_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
|
|
8519
|
+
try {
|
|
8520
|
+
return LLTV.from(parseUnits(lltv.toString(), 16));
|
|
8521
|
+
} catch (e) {
|
|
8522
|
+
ctx.addIssue({
|
|
8523
|
+
code: "custom",
|
|
8524
|
+
message: e.message,
|
|
8525
|
+
input: lltv
|
|
8526
|
+
});
|
|
8527
|
+
return z.NEVER;
|
|
8528
|
+
}
|
|
8529
|
+
}).optional().meta({
|
|
8506
8530
|
description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
|
|
8507
8531
|
example: "80.5"
|
|
8508
8532
|
}),
|
|
8509
|
-
max_lltv: z.
|
|
8510
|
-
|
|
8511
|
-
|
|
8533
|
+
max_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
|
|
8534
|
+
try {
|
|
8535
|
+
return LLTV.from(parseUnits(lltv.toString(), 16));
|
|
8536
|
+
} catch (e) {
|
|
8537
|
+
ctx.addIssue({
|
|
8538
|
+
code: "custom",
|
|
8539
|
+
message: e.message,
|
|
8540
|
+
input: lltv
|
|
8541
|
+
});
|
|
8542
|
+
return z.NEVER;
|
|
8543
|
+
}
|
|
8544
|
+
}).optional().meta({
|
|
8512
8545
|
description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
|
|
8513
8546
|
example: "95.5"
|
|
8514
8547
|
}),
|
|
@@ -8601,68 +8634,89 @@ var MatchOffersQueryParams = z.object({
|
|
|
8601
8634
|
}),
|
|
8602
8635
|
// Collateral filtering
|
|
8603
8636
|
collaterals: z.string().regex(
|
|
8604
|
-
/^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}
|
|
8637
|
+
/^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)(#0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)*$/,
|
|
8605
8638
|
{
|
|
8606
8639
|
message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral."
|
|
8607
8640
|
}
|
|
8608
|
-
).transform((val) => {
|
|
8641
|
+
).transform((val, ctx) => {
|
|
8609
8642
|
return val.split("#").map((collateral) => {
|
|
8610
8643
|
const parts = collateral.split(":");
|
|
8611
8644
|
if (parts.length !== 3) {
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
]);
|
|
8645
|
+
ctx.addIssue({
|
|
8646
|
+
code: "custom",
|
|
8647
|
+
message: "Each collateral must have exactly 3 parts: asset:oracle:lltv",
|
|
8648
|
+
path: ["collaterals"],
|
|
8649
|
+
input: val
|
|
8650
|
+
});
|
|
8651
|
+
return z.NEVER;
|
|
8620
8652
|
}
|
|
8621
8653
|
const [asset, oracle, lltvStr] = parts;
|
|
8622
8654
|
if (!asset || !oracle || !lltvStr) {
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
}
|
|
8630
|
-
]);
|
|
8655
|
+
ctx.addIssue({
|
|
8656
|
+
code: "custom",
|
|
8657
|
+
message: "Asset, oracle, and lltv are all required for each collateral",
|
|
8658
|
+
path: ["collaterals"],
|
|
8659
|
+
input: val
|
|
8660
|
+
});
|
|
8631
8661
|
}
|
|
8632
|
-
|
|
8633
|
-
if (
|
|
8634
|
-
|
|
8635
|
-
|
|
8662
|
+
let lltvValue;
|
|
8663
|
+
if (lltvStr !== void 0) {
|
|
8664
|
+
try {
|
|
8665
|
+
lltvValue = LLTV.from(parseUnits(lltvStr, 16));
|
|
8666
|
+
} catch (e) {
|
|
8667
|
+
ctx.issues.push({
|
|
8636
8668
|
code: "custom",
|
|
8637
|
-
message:
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
}
|
|
8641
|
-
|
|
8669
|
+
message: e instanceof LLTV.InvalidLLTVError || e instanceof LLTV.InvalidOptionError ? e.message : "Invalid LLTV.",
|
|
8670
|
+
input: lltvStr,
|
|
8671
|
+
path: ["lltv"]
|
|
8672
|
+
});
|
|
8673
|
+
return z.NEVER;
|
|
8674
|
+
}
|
|
8642
8675
|
}
|
|
8643
8676
|
return {
|
|
8644
8677
|
asset: asset.toLowerCase(),
|
|
8645
8678
|
oracle: oracle.toLowerCase(),
|
|
8646
|
-
lltv
|
|
8679
|
+
lltv: lltvValue
|
|
8647
8680
|
};
|
|
8648
8681
|
});
|
|
8649
8682
|
}).optional().meta({
|
|
8650
8683
|
description: "Collateral requirements in format: asset:oracle:lltv#asset2:oracle2:lltv2. Use # to separate multiple collaterals.",
|
|
8651
|
-
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:
|
|
8684
|
+
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
|
|
8652
8685
|
}),
|
|
8653
8686
|
// Maturity filtering
|
|
8654
|
-
maturity: z.
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8687
|
+
maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
8688
|
+
try {
|
|
8689
|
+
return Maturity.from(maturity);
|
|
8690
|
+
} catch (e) {
|
|
8691
|
+
ctx.addIssue({
|
|
8692
|
+
code: "custom",
|
|
8693
|
+
message: e.message
|
|
8694
|
+
});
|
|
8695
|
+
return z.NEVER;
|
|
8696
|
+
}
|
|
8697
|
+
}).optional(),
|
|
8698
|
+
min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
8699
|
+
try {
|
|
8700
|
+
return Maturity.from(maturity);
|
|
8701
|
+
} catch (e) {
|
|
8702
|
+
ctx.addIssue({
|
|
8703
|
+
code: "custom",
|
|
8704
|
+
message: e.message
|
|
8705
|
+
});
|
|
8706
|
+
return z.NEVER;
|
|
8707
|
+
}
|
|
8708
|
+
}).optional(),
|
|
8709
|
+
max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
8710
|
+
try {
|
|
8711
|
+
return Maturity.from(maturity);
|
|
8712
|
+
} catch (e) {
|
|
8713
|
+
ctx.addIssue({
|
|
8714
|
+
code: "custom",
|
|
8715
|
+
message: e.message
|
|
8716
|
+
});
|
|
8717
|
+
return z.NEVER;
|
|
8718
|
+
}
|
|
8719
|
+
}).optional(),
|
|
8666
8720
|
// Asset and creator filtering
|
|
8667
8721
|
loan_token: z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
|
|
8668
8722
|
message: "Loan asset must be a valid Ethereum address"
|
|
@@ -8727,8 +8781,10 @@ var schemas = {
|
|
|
8727
8781
|
function parse(action, query) {
|
|
8728
8782
|
return schemas[action].parse(query);
|
|
8729
8783
|
}
|
|
8730
|
-
function safeParse(action, query) {
|
|
8731
|
-
return schemas[action].safeParse(query
|
|
8784
|
+
function safeParse(action, query, error) {
|
|
8785
|
+
return schemas[action].safeParse(query, {
|
|
8786
|
+
error
|
|
8787
|
+
});
|
|
8732
8788
|
}
|
|
8733
8789
|
|
|
8734
8790
|
// src/core/apiSchema/openapi.ts
|
|
@@ -8780,7 +8836,7 @@ var paths = {
|
|
|
8780
8836
|
}
|
|
8781
8837
|
}
|
|
8782
8838
|
},
|
|
8783
|
-
"/v1/match
|
|
8839
|
+
"/v1/offers/match": {
|
|
8784
8840
|
get: {
|
|
8785
8841
|
summary: "Match offers",
|
|
8786
8842
|
description: "Find offers that match specific criteria",
|
|
@@ -8836,27 +8892,27 @@ var OpenApi = createDocument({
|
|
|
8836
8892
|
|
|
8837
8893
|
// src/core/apiSchema/utils.ts
|
|
8838
8894
|
function toResponse(routerOffer) {
|
|
8839
|
-
const { consumed
|
|
8895
|
+
const { consumed, status, metadata, ...offer } = routerOffer;
|
|
8840
8896
|
return {
|
|
8841
8897
|
offer,
|
|
8842
|
-
consumed
|
|
8898
|
+
consumed,
|
|
8843
8899
|
status,
|
|
8844
8900
|
metadata
|
|
8845
8901
|
};
|
|
8846
8902
|
}
|
|
8847
8903
|
function fromResponse(offerResponse) {
|
|
8848
|
-
const { offer, consumed
|
|
8904
|
+
const { offer, consumed, status, metadata } = offerResponse;
|
|
8849
8905
|
return {
|
|
8850
8906
|
...offer,
|
|
8851
|
-
consumed
|
|
8907
|
+
consumed,
|
|
8852
8908
|
status,
|
|
8853
8909
|
metadata
|
|
8854
8910
|
};
|
|
8855
8911
|
}
|
|
8856
8912
|
|
|
8857
|
-
// src/core/index.ts
|
|
8858
|
-
var
|
|
8859
|
-
__export(
|
|
8913
|
+
// src/core/router/index.ts
|
|
8914
|
+
var router_exports = {};
|
|
8915
|
+
__export(router_exports, {
|
|
8860
8916
|
HttpForbiddenError: () => HttpForbiddenError,
|
|
8861
8917
|
HttpGetOffersFailedError: () => HttpGetOffersFailedError,
|
|
8862
8918
|
HttpRateLimitError: () => HttpRateLimitError,
|
|
@@ -8943,16 +8999,16 @@ async function get(config, parameters) {
|
|
|
8943
8999
|
} else if (lltv !== void 0) {
|
|
8944
9000
|
result += `:`;
|
|
8945
9001
|
}
|
|
8946
|
-
if (lltv !== void 0) result += `:${lltv}`;
|
|
9002
|
+
if (lltv !== void 0) result += `:${formatUnits(lltv, 16)}`;
|
|
8947
9003
|
return result;
|
|
8948
9004
|
}).join("#");
|
|
8949
9005
|
url.searchParams.set("collateral_tuple", tupleStr);
|
|
8950
9006
|
}
|
|
8951
9007
|
if (parameters.minLltv !== void 0) {
|
|
8952
|
-
url.searchParams.set("min_lltv", parameters.minLltv
|
|
9008
|
+
url.searchParams.set("min_lltv", formatUnits(parameters.minLltv, 16));
|
|
8953
9009
|
}
|
|
8954
9010
|
if (parameters.maxLltv !== void 0) {
|
|
8955
|
-
url.searchParams.set("max_lltv", parameters.maxLltv
|
|
9011
|
+
url.searchParams.set("max_lltv", formatUnits(parameters.maxLltv, 16));
|
|
8956
9012
|
}
|
|
8957
9013
|
if (parameters.sortBy) {
|
|
8958
9014
|
url.searchParams.set("sort_by", parameters.sortBy);
|
|
@@ -8966,22 +9022,22 @@ async function get(config, parameters) {
|
|
|
8966
9022
|
if (parameters.limit !== void 0) {
|
|
8967
9023
|
url.searchParams.set("limit", parameters.limit.toString());
|
|
8968
9024
|
}
|
|
8969
|
-
const { cursor: returnedCursor, data:
|
|
8970
|
-
const routerOffers =
|
|
9025
|
+
const { cursor: returnedCursor, data: offers } = await getApi(config, url);
|
|
9026
|
+
const routerOffers = offers.map(Format.fromSnakeCase).map(fromResponse);
|
|
8971
9027
|
return {
|
|
8972
9028
|
cursor: returnedCursor,
|
|
8973
9029
|
offers: routerOffers.map(from).map(toResponse)
|
|
8974
9030
|
};
|
|
8975
9031
|
}
|
|
8976
9032
|
async function match(config, parameters) {
|
|
8977
|
-
const url = new URL(`${config.url.toString()}v1/match
|
|
9033
|
+
const url = new URL(`${config.url.toString()}v1/offers/match`);
|
|
8978
9034
|
url.searchParams.set("side", parameters.side);
|
|
8979
9035
|
url.searchParams.set("chain_id", parameters.chainId.toString());
|
|
8980
9036
|
if (parameters.rate !== void 0) {
|
|
8981
9037
|
url.searchParams.set("rate", parameters.rate.toString());
|
|
8982
9038
|
}
|
|
8983
9039
|
if (parameters.collaterals?.length) {
|
|
8984
|
-
const collateralsStr = parameters.collaterals.map(({ asset, oracle, lltv }) => `${asset}:${oracle}:${lltv}`).join("#");
|
|
9040
|
+
const collateralsStr = parameters.collaterals.map(({ asset, oracle, lltv }) => `${asset}:${oracle}:${formatUnits(lltv, 16)}`).join("#");
|
|
8985
9041
|
url.searchParams.set("collaterals", collateralsStr);
|
|
8986
9042
|
}
|
|
8987
9043
|
if (parameters.maturity !== void 0) {
|
|
@@ -9008,8 +9064,8 @@ async function match(config, parameters) {
|
|
|
9008
9064
|
if (parameters.limit !== void 0) {
|
|
9009
9065
|
url.searchParams.set("limit", parameters.limit.toString());
|
|
9010
9066
|
}
|
|
9011
|
-
const { cursor: returnedCursor, data:
|
|
9012
|
-
const routerOffers =
|
|
9067
|
+
const { cursor: returnedCursor, data: offers } = await getApi(config, url);
|
|
9068
|
+
const routerOffers = offers.map(Format.fromSnakeCase).map(fromResponse);
|
|
9013
9069
|
return {
|
|
9014
9070
|
cursor: returnedCursor,
|
|
9015
9071
|
offers: routerOffers.map(from).map(toResponse)
|
|
@@ -9022,7 +9078,7 @@ async function getApi(config, url) {
|
|
|
9022
9078
|
case pathname.includes("/v1/offers"):
|
|
9023
9079
|
action = "get_offers";
|
|
9024
9080
|
break;
|
|
9025
|
-
case pathname.includes("/v1/match
|
|
9081
|
+
case pathname.includes("/v1/offers/match"):
|
|
9026
9082
|
action = "match_offers";
|
|
9027
9083
|
break;
|
|
9028
9084
|
default:
|
|
@@ -9096,558 +9152,214 @@ var HttpGetOffersFailedError = class extends Errors.BaseError {
|
|
|
9096
9152
|
}
|
|
9097
9153
|
};
|
|
9098
9154
|
|
|
9099
|
-
// src/
|
|
9100
|
-
var
|
|
9101
|
-
__export(
|
|
9102
|
-
|
|
9103
|
-
OfferRepository: () => OfferRepository_exports,
|
|
9104
|
-
consumed: () => consumed,
|
|
9105
|
-
offerCollaterals: () => offerCollaterals,
|
|
9106
|
-
offerStatus: () => offerStatus,
|
|
9107
|
-
offers: () => offers
|
|
9155
|
+
// src/OfferStore/index.ts
|
|
9156
|
+
var OfferStore_exports = {};
|
|
9157
|
+
__export(OfferStore_exports, {
|
|
9158
|
+
memory: () => memory
|
|
9108
9159
|
});
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
});
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
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
|
-
offerHash: varchar("offer_hash", { length: 66 }).notNull().references(() => offers.hash, { onDelete: "cascade" }),
|
|
9169
|
-
asset: varchar("asset", { length: 42 }).notNull(),
|
|
9170
|
-
oracle: varchar("oracle", { length: 42 }).notNull(),
|
|
9171
|
-
lltv: bigint("lltv", { mode: "bigint" }).notNull()
|
|
9172
|
-
},
|
|
9173
|
-
(table) => [
|
|
9174
|
-
index("offer_collaterals_offer_hash_idx").on(table.offerHash),
|
|
9175
|
-
index("offer_collaterals_asset_idx").on(table.asset),
|
|
9176
|
-
index("offer_collaterals_oracle_idx").on(table.oracle),
|
|
9177
|
-
// Composite index
|
|
9178
|
-
index("offer_collaterals_tuple_idx").on(table.asset, table.oracle, table.lltv)
|
|
9179
|
-
]
|
|
9180
|
-
);
|
|
9181
|
-
var offerStatus = pgTable(
|
|
9182
|
-
"offer_status",
|
|
9183
|
-
{
|
|
9184
|
-
id: serial("id").primaryKey(),
|
|
9185
|
-
offerHash: varchar("offer_hash", { length: 66 }).notNull().references(() => offers.hash, { onDelete: "cascade" }),
|
|
9186
|
-
status: text("status").$type().notNull(),
|
|
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");
|
|
9160
|
+
function memory(parameters) {
|
|
9161
|
+
const map = parameters.offers;
|
|
9162
|
+
const filled = parameters.filled;
|
|
9163
|
+
const create = async (parameters2) => {
|
|
9164
|
+
if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
|
|
9165
|
+
map.set(parameters2.offer.hash.toLowerCase(), {
|
|
9166
|
+
...parameters2.offer,
|
|
9167
|
+
status: parameters2.status,
|
|
9168
|
+
metadata: parameters2.metadata
|
|
9169
|
+
});
|
|
9170
|
+
const chainId = parameters2.offer.chainId;
|
|
9171
|
+
const address = parameters2.offer.offering.toLowerCase();
|
|
9172
|
+
const nonce = parameters2.offer.nonce;
|
|
9173
|
+
const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
|
|
9174
|
+
const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
|
|
9175
|
+
if (!filledForOffering.has(nonce)) filledForOffering.set(nonce, 0n);
|
|
9176
|
+
filledForChain.set(address, filledForOffering);
|
|
9177
|
+
filled.set(chainId, filledForChain);
|
|
9178
|
+
return Promise.resolve(parameters2.offer.hash);
|
|
9179
|
+
};
|
|
9180
|
+
const sort = (sortBy, sortOrder, a, b) => {
|
|
9181
|
+
sortBy = sortBy || "expiry";
|
|
9182
|
+
sortOrder = sortOrder || "desc";
|
|
9183
|
+
const sortKey = sortBy === "amount" ? "assets" : sortBy;
|
|
9184
|
+
if (a[sortKey] === b[sortKey]) {
|
|
9185
|
+
if (a.hash === b.hash) return 0;
|
|
9186
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : b.hash > a.hash ? 1 : -1;
|
|
9187
|
+
}
|
|
9188
|
+
switch (sortBy) {
|
|
9189
|
+
case "rate":
|
|
9190
|
+
if (a.rate === b.rate) {
|
|
9191
|
+
if (a.hash === b.hash) return 0;
|
|
9192
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9193
|
+
}
|
|
9194
|
+
return sortOrder === "asc" ? a.rate > b.rate ? 1 : -1 : b.rate > a.rate ? 1 : -1;
|
|
9195
|
+
case "maturity":
|
|
9196
|
+
if (a.maturity === b.maturity) {
|
|
9197
|
+
if (a.hash === b.hash) return 0;
|
|
9198
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9199
|
+
}
|
|
9200
|
+
return sortOrder === "asc" ? a.maturity > b.maturity ? 1 : -1 : b.maturity > a.maturity ? 1 : -1;
|
|
9201
|
+
case "expiry":
|
|
9202
|
+
if (a.expiry === b.expiry) {
|
|
9203
|
+
if (a.hash === b.hash) return 0;
|
|
9204
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9205
|
+
}
|
|
9206
|
+
return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
|
|
9207
|
+
case "amount":
|
|
9208
|
+
if (a.assets === b.assets) {
|
|
9209
|
+
if (a.hash === b.hash) return 0;
|
|
9210
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9211
|
+
}
|
|
9212
|
+
return sortOrder === "asc" ? a.assets > b.assets ? 1 : -1 : b.assets > a.assets ? 1 : -1;
|
|
9213
|
+
default:
|
|
9214
|
+
if (a.expiry === b.expiry) {
|
|
9215
|
+
if (a.hash === b.hash) return 0;
|
|
9216
|
+
return sortOrder === "asc" ? a.hash > b.hash ? 1 : -1 : a.hash > b.hash ? -1 : 1;
|
|
9217
|
+
}
|
|
9218
|
+
return sortOrder === "asc" ? a.expiry > b.expiry ? 1 : -1 : b.expiry > a.expiry ? 1 : -1;
|
|
9223
9219
|
}
|
|
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;
|
|
9220
|
+
};
|
|
9260
9221
|
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
|
-
});
|
|
9222
|
+
create,
|
|
9223
|
+
createMany: async (parameters2) => {
|
|
9224
|
+
return Promise.all(
|
|
9225
|
+
parameters2.map((p) => create({ offer: p.offer, status: p.status, metadata: p.metadata }))
|
|
9226
|
+
);
|
|
9372
9227
|
},
|
|
9373
9228
|
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})`);
|
|
9229
|
+
const { query } = params || {};
|
|
9230
|
+
let {
|
|
9231
|
+
creators,
|
|
9232
|
+
side,
|
|
9233
|
+
chains: chains2,
|
|
9234
|
+
loanTokens,
|
|
9235
|
+
status = ["valid"],
|
|
9236
|
+
callbackAddresses,
|
|
9237
|
+
minAmount,
|
|
9238
|
+
maxAmount,
|
|
9239
|
+
minRate,
|
|
9240
|
+
maxRate,
|
|
9241
|
+
minMaturity,
|
|
9242
|
+
maxMaturity,
|
|
9243
|
+
minExpiry,
|
|
9244
|
+
maxExpiry,
|
|
9245
|
+
collateralAssets,
|
|
9246
|
+
collateralOracles,
|
|
9247
|
+
collateralTuple,
|
|
9248
|
+
minLltv,
|
|
9249
|
+
maxLltv,
|
|
9250
|
+
sortBy = "expiry",
|
|
9251
|
+
sortOrder = "desc",
|
|
9252
|
+
cursor: queryCursor,
|
|
9253
|
+
limit = 20
|
|
9254
|
+
} = query || {};
|
|
9255
|
+
const now = Time.now();
|
|
9256
|
+
const buy = side === "buy";
|
|
9257
|
+
let offers = Array.from(map.values()).map((o) => ({
|
|
9258
|
+
...o,
|
|
9259
|
+
consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
|
|
9260
|
+
})).filter((o) => o.consumed < o.assets);
|
|
9261
|
+
const cursor = decodeCursor(queryCursor);
|
|
9262
|
+
if (cursor) {
|
|
9263
|
+
if (cursor.sort !== sortBy || cursor.dir !== sortOrder) {
|
|
9264
|
+
throw new Error("Cursor does not match the current sort parameters");
|
|
9450
9265
|
}
|
|
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) {
|
|
9266
|
+
switch (cursor.sort) {
|
|
9464
9267
|
case "rate":
|
|
9465
|
-
|
|
9268
|
+
offers = offers.filter(
|
|
9269
|
+
(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))
|
|
9270
|
+
);
|
|
9271
|
+
break;
|
|
9466
9272
|
case "maturity":
|
|
9467
|
-
|
|
9273
|
+
offers = offers.filter(
|
|
9274
|
+
(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))
|
|
9275
|
+
);
|
|
9276
|
+
break;
|
|
9468
9277
|
case "expiry":
|
|
9469
|
-
|
|
9278
|
+
offers = offers.filter(
|
|
9279
|
+
(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))
|
|
9280
|
+
);
|
|
9281
|
+
break;
|
|
9470
9282
|
case "amount":
|
|
9471
|
-
|
|
9283
|
+
offers = offers.filter(
|
|
9284
|
+
(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))
|
|
9285
|
+
);
|
|
9286
|
+
break;
|
|
9472
9287
|
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
|
-
|
|
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`
|
|
9288
|
+
throw new Error("Invalid sort parameter");
|
|
9289
|
+
}
|
|
9290
|
+
offers = offers.filter((o) => o.hash !== cursor.hash);
|
|
9291
|
+
}
|
|
9292
|
+
creators && (creators = creators.map((c) => c.toLowerCase()));
|
|
9293
|
+
loanTokens && (loanTokens = loanTokens.map((lt) => lt.toLowerCase()));
|
|
9294
|
+
callbackAddresses && (callbackAddresses = callbackAddresses.map((ca) => ca.toLowerCase()));
|
|
9295
|
+
collateralAssets && (collateralAssets = collateralAssets.map((ca) => ca.toLowerCase()));
|
|
9296
|
+
collateralOracles && (collateralOracles = collateralOracles.map((co) => co.toLowerCase()));
|
|
9297
|
+
collateralTuple && (collateralTuple = collateralTuple.map((ct) => ({
|
|
9298
|
+
asset: ct.asset.toLowerCase(),
|
|
9299
|
+
oracle: ct.oracle?.toLowerCase()
|
|
9300
|
+
})));
|
|
9301
|
+
offers = offers.filter((o) => o.expiry >= now);
|
|
9302
|
+
creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
|
|
9303
|
+
side && (offers = offers.filter((o) => o.buy === buy));
|
|
9304
|
+
chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
|
|
9305
|
+
loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
|
|
9306
|
+
status && (offers = offers.filter((o) => status.includes(o.status)));
|
|
9307
|
+
callbackAddresses && (offers = offers.filter(
|
|
9308
|
+
(o) => callbackAddresses.includes(o.callback.address.toLowerCase())
|
|
9309
|
+
));
|
|
9310
|
+
minAmount && (offers = offers.filter((o) => o.assets >= minAmount));
|
|
9311
|
+
maxAmount && (offers = offers.filter((o) => o.assets <= maxAmount));
|
|
9312
|
+
minRate && (offers = offers.filter((o) => o.rate >= minRate));
|
|
9313
|
+
maxRate && (offers = offers.filter((o) => o.rate <= maxRate));
|
|
9314
|
+
minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
|
|
9315
|
+
maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
|
|
9316
|
+
minExpiry && (offers = offers.filter((o) => o.expiry >= minExpiry));
|
|
9317
|
+
maxExpiry && (offers = offers.filter((o) => o.expiry <= maxExpiry));
|
|
9318
|
+
collateralAssets && (offers = offers.filter(
|
|
9319
|
+
(o) => o.collaterals.some((c) => collateralAssets.includes(c.asset.toLowerCase()))
|
|
9320
|
+
));
|
|
9321
|
+
collateralOracles && (offers = offers.filter(
|
|
9322
|
+
(o) => o.collaterals.some((c) => collateralOracles.includes(c.oracle.toLowerCase()))
|
|
9323
|
+
));
|
|
9324
|
+
collateralTuple && (offers = offers.filter(
|
|
9325
|
+
(o) => o.collaterals.some(
|
|
9326
|
+
(c) => collateralTuple.some(
|
|
9327
|
+
(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)
|
|
9328
|
+
)
|
|
9542
9329
|
)
|
|
9543
|
-
)
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
hash: row.hash,
|
|
9548
|
-
offering: row.offering,
|
|
9549
|
-
assets: row.assets,
|
|
9550
|
-
consumed: row.consumed || 0n,
|
|
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
|
-
}
|
|
9330
|
+
));
|
|
9331
|
+
minLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv >= minLltv)));
|
|
9332
|
+
maxLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv <= maxLltv)));
|
|
9333
|
+
offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
|
|
9577
9334
|
let nextCursor = null;
|
|
9578
|
-
if (
|
|
9579
|
-
const
|
|
9335
|
+
if (offers.length > limit) {
|
|
9336
|
+
const last = offers[limit - 1];
|
|
9580
9337
|
const base2 = {
|
|
9581
9338
|
sort: sortBy,
|
|
9582
9339
|
dir: sortOrder,
|
|
9583
|
-
hash:
|
|
9340
|
+
hash: last.hash
|
|
9584
9341
|
};
|
|
9585
9342
|
switch (sortBy) {
|
|
9586
9343
|
case "rate":
|
|
9587
|
-
base2.rate =
|
|
9344
|
+
base2.rate = last.rate.toString();
|
|
9588
9345
|
break;
|
|
9589
9346
|
case "amount":
|
|
9590
|
-
base2.assets =
|
|
9347
|
+
base2.assets = last.assets.toString();
|
|
9591
9348
|
break;
|
|
9592
9349
|
case "maturity":
|
|
9593
|
-
base2.maturity =
|
|
9350
|
+
base2.maturity = last.maturity;
|
|
9594
9351
|
break;
|
|
9595
9352
|
default:
|
|
9596
|
-
base2.expiry =
|
|
9353
|
+
base2.expiry = last.expiry;
|
|
9597
9354
|
}
|
|
9598
9355
|
nextCursor = encodeCursor(base2);
|
|
9599
9356
|
}
|
|
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 };
|
|
9357
|
+
offers = offers.slice(0, limit);
|
|
9358
|
+
return {
|
|
9359
|
+
offers,
|
|
9360
|
+
nextCursor
|
|
9361
|
+
};
|
|
9633
9362
|
},
|
|
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
9363
|
findMatchingOffers: async (params) => {
|
|
9652
9364
|
const {
|
|
9653
9365
|
side,
|
|
@@ -9660,192 +9372,86 @@ function create2(config) {
|
|
|
9660
9372
|
loanToken,
|
|
9661
9373
|
creator,
|
|
9662
9374
|
status,
|
|
9663
|
-
cursor,
|
|
9375
|
+
cursor: queryCursor,
|
|
9664
9376
|
limit = 20
|
|
9665
9377
|
} = params;
|
|
9666
|
-
const
|
|
9667
|
-
const
|
|
9668
|
-
const sortOrder =
|
|
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) {
|
|
9378
|
+
const now = Time.now();
|
|
9379
|
+
const isBuying = side === "buy";
|
|
9380
|
+
const sortOrder = isBuying ? "desc" : "asc";
|
|
9381
|
+
let offers = Array.from(map.values()).map((o) => ({
|
|
9382
|
+
...o,
|
|
9383
|
+
consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
|
|
9384
|
+
})).filter((o) => o.consumed < o.assets);
|
|
9385
|
+
const cursor = decodeCursor(queryCursor);
|
|
9386
|
+
if (cursor) {
|
|
9387
|
+
if (cursor.sort !== "rate" || cursor.dir !== sortOrder) {
|
|
9685
9388
|
throw new Error("Cursor does not match the current sort parameters");
|
|
9686
9389
|
}
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
sql`(${offers.rate}, ${offers.hash}) ${op} (${BigInt(decoded.rate)}, ${decoded.hash})`
|
|
9390
|
+
offers = offers.filter(
|
|
9391
|
+
(o) => sortOrder === "asc" ? o.rate >= BigInt(cursor.rate) : o.rate <= BigInt(cursor.rate)
|
|
9690
9392
|
);
|
|
9691
9393
|
}
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
SELECT 1 FROM ${offerCollaterals} oc
|
|
9712
|
-
WHERE oc.offer_hash = ${offers.hash}
|
|
9713
|
-
AND NOT EXISTS (
|
|
9714
|
-
SELECT 1 FROM ${userCollaterals}
|
|
9715
|
-
WHERE uc.asset = oc.asset
|
|
9716
|
-
AND uc.oracle = oc.oracle
|
|
9717
|
-
AND uc.lltv = oc.lltv
|
|
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
|
|
9736
|
-
}
|
|
9737
|
-
).from(consumed).orderBy(desc(consumed.createdAt)).limit(1).as("latest_consumed");
|
|
9738
|
-
const statusCondition = status && status.length > 0 ? inArray(latestStatus.status, status) : eq(latestStatus.status, "valid");
|
|
9739
|
-
const bestOffers = db.selectDistinctOn(
|
|
9740
|
-
// group key
|
|
9741
|
-
[offers.offering, offers.nonce, offers.buy],
|
|
9742
|
-
{
|
|
9743
|
-
hash: offers.hash,
|
|
9744
|
-
offering: offers.offering,
|
|
9745
|
-
assets: offers.assets,
|
|
9746
|
-
consumed: latestConsumed.consumed,
|
|
9747
|
-
rate: offers.rate,
|
|
9748
|
-
maturity: offers.maturity,
|
|
9749
|
-
expiry: offers.expiry,
|
|
9750
|
-
start: offers.start,
|
|
9751
|
-
nonce: offers.nonce,
|
|
9752
|
-
buy: offers.buy,
|
|
9753
|
-
chainId: offers.chainId,
|
|
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`
|
|
9394
|
+
offers = offers.filter((o) => o.buy === !isBuying);
|
|
9395
|
+
offers = offers.filter((o) => o.chainId === BigInt(chainId));
|
|
9396
|
+
offers = offers.filter((o) => o.expiry >= now);
|
|
9397
|
+
rate && (offers = offers.filter((o) => isBuying ? o.rate >= rate : o.rate <= rate));
|
|
9398
|
+
collaterals.length > 0 && (offers = offers.filter(
|
|
9399
|
+
(o) => isBuying ? (
|
|
9400
|
+
// when wanting to buy, sell offer collaterals ⊆ user buy collaterals
|
|
9401
|
+
o.collaterals.every((oc) => {
|
|
9402
|
+
return collaterals.some(
|
|
9403
|
+
(c) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
9404
|
+
);
|
|
9405
|
+
})
|
|
9406
|
+
) : (
|
|
9407
|
+
// when wanting to sell, user sell collaterals ⊆ buy offer collaterals
|
|
9408
|
+
collaterals.every((c) => {
|
|
9409
|
+
return o.collaterals.some(
|
|
9410
|
+
(oc) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
9411
|
+
);
|
|
9412
|
+
})
|
|
9767
9413
|
)
|
|
9768
|
-
)
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9775
|
-
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
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
|
-
});
|
|
9414
|
+
));
|
|
9415
|
+
maturity && (offers = offers.filter((o) => o.maturity === maturity));
|
|
9416
|
+
minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
|
|
9417
|
+
maxMaturity && (offers = offers.filter((o) => o.maturity <= maxMaturity));
|
|
9418
|
+
loanToken && (offers = offers.filter((o) => o.loanToken.toLowerCase() === loanToken.toLowerCase()));
|
|
9419
|
+
creator && (offers = offers.filter((o) => o.offering.toLowerCase() === creator.toLowerCase()));
|
|
9420
|
+
status && (offers = offers.filter((o) => status.includes(o.status)));
|
|
9421
|
+
const byGroup = /* @__PURE__ */ new Map();
|
|
9422
|
+
for (const offer of offers) {
|
|
9423
|
+
const groupKey = `${offer.chainId}-${offer.offering.toLowerCase()}-${offer.nonce}-${offer.buy}`;
|
|
9424
|
+
const current = byGroup.get(groupKey);
|
|
9425
|
+
if (!current) {
|
|
9426
|
+
byGroup.set(groupKey, offer);
|
|
9427
|
+
continue;
|
|
9813
9428
|
}
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
(
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
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
|
-
}));
|
|
9429
|
+
const remainingCandidate = offer.assets - offer.consumed;
|
|
9430
|
+
const remainingCurrent = current.assets - current.consumed;
|
|
9431
|
+
let candidateIsBetter = false;
|
|
9432
|
+
if (offer.buy) {
|
|
9433
|
+
if (offer.rate !== current.rate) candidateIsBetter = offer.rate < current.rate;
|
|
9434
|
+
else if (remainingCandidate !== remainingCurrent)
|
|
9435
|
+
candidateIsBetter = remainingCandidate > remainingCurrent;
|
|
9436
|
+
else if (offer.maturity !== current.maturity)
|
|
9437
|
+
candidateIsBetter = offer.maturity > current.maturity;
|
|
9438
|
+
else candidateIsBetter = offer.hash < current.hash;
|
|
9439
|
+
} else {
|
|
9440
|
+
if (offer.rate !== current.rate) candidateIsBetter = offer.rate > current.rate;
|
|
9441
|
+
else if (remainingCandidate !== remainingCurrent)
|
|
9442
|
+
candidateIsBetter = remainingCandidate > remainingCurrent;
|
|
9443
|
+
else if (offer.maturity !== current.maturity)
|
|
9444
|
+
candidateIsBetter = offer.maturity > current.maturity;
|
|
9445
|
+
else candidateIsBetter = offer.hash < current.hash;
|
|
9446
|
+
}
|
|
9447
|
+
if (candidateIsBetter) byGroup.set(groupKey, offer);
|
|
9448
|
+
}
|
|
9449
|
+
offers = Array.from(byGroup.values());
|
|
9450
|
+
offers = offers.sort((a, b) => sort("rate", sortOrder, a, b));
|
|
9451
|
+
cursor && (offers = offers.filter((o) => o.hash !== cursor.hash));
|
|
9846
9452
|
let nextCursor = null;
|
|
9847
|
-
if (
|
|
9848
|
-
const last =
|
|
9453
|
+
if (offers.length > limit) {
|
|
9454
|
+
const last = offers[limit - 1];
|
|
9849
9455
|
nextCursor = encodeCursor({
|
|
9850
9456
|
sort: "rate",
|
|
9851
9457
|
dir: sortOrder,
|
|
@@ -9853,62 +9459,62 @@ function create2(config) {
|
|
|
9853
9459
|
rate: last.rate.toString()
|
|
9854
9460
|
});
|
|
9855
9461
|
}
|
|
9856
|
-
|
|
9462
|
+
offers = offers.slice(0, limit);
|
|
9463
|
+
return {
|
|
9464
|
+
offers,
|
|
9465
|
+
nextCursor
|
|
9466
|
+
};
|
|
9857
9467
|
},
|
|
9858
9468
|
delete: async (hash3) => {
|
|
9859
|
-
|
|
9860
|
-
|
|
9469
|
+
if (!map.has(hash3.toLowerCase())) return false;
|
|
9470
|
+
map.delete(hash3.toLowerCase());
|
|
9471
|
+
return true;
|
|
9861
9472
|
},
|
|
9862
9473
|
deleteMany: async (hashes) => {
|
|
9863
|
-
|
|
9864
|
-
|
|
9474
|
+
let deleted = 0;
|
|
9475
|
+
for (const hash3 of hashes) {
|
|
9476
|
+
if (map.has(hash3.toLowerCase())) {
|
|
9477
|
+
map.delete(hash3.toLowerCase());
|
|
9478
|
+
deleted++;
|
|
9479
|
+
}
|
|
9865
9480
|
}
|
|
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
|
-
});
|
|
9481
|
+
return deleted;
|
|
9873
9482
|
},
|
|
9874
|
-
updateStatus: async (
|
|
9875
|
-
|
|
9876
|
-
|
|
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) => {
|
|
9483
|
+
updateStatus: async (parameters2) => {
|
|
9484
|
+
const key = parameters2.offerHash.toLowerCase();
|
|
9485
|
+
const existing = map.get(key);
|
|
9486
|
+
if (!existing) return;
|
|
9487
|
+
if (existing.status === parameters2.status) return;
|
|
9488
|
+
map.set(key, {
|
|
9489
|
+
...existing,
|
|
9490
|
+
status: parameters2.status,
|
|
9491
|
+
metadata: parameters2.metadata
|
|
9492
|
+
});
|
|
9891
9493
|
},
|
|
9892
|
-
updateConsumedAmount: async (
|
|
9494
|
+
updateConsumedAmount: async (parameters2) => {
|
|
9495
|
+
const chainId = parameters2.chainId;
|
|
9496
|
+
const address = parameters2.offering.toLowerCase();
|
|
9497
|
+
const nonce = parameters2.nonce;
|
|
9498
|
+
const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
|
|
9499
|
+
const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
|
|
9500
|
+
filledForOffering.set(nonce, parameters2.consumed);
|
|
9501
|
+
filledForChain.set(address, filledForOffering);
|
|
9502
|
+
filled.set(chainId, filledForChain);
|
|
9893
9503
|
}
|
|
9894
9504
|
};
|
|
9895
9505
|
}
|
|
9896
9506
|
|
|
9897
|
-
// src/core/Server.ts
|
|
9507
|
+
// src/core/router/Server.ts
|
|
9898
9508
|
async function serve(parameters) {
|
|
9899
9509
|
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
|
-
}
|
|
9510
|
+
const store = parameters.store ? parameters.store : memory({
|
|
9511
|
+
offers: /* @__PURE__ */ new Map(),
|
|
9512
|
+
filled: /* @__PURE__ */ new Map()
|
|
9513
|
+
});
|
|
9908
9514
|
app.get("/v1/offers", async (c) => {
|
|
9909
9515
|
try {
|
|
9910
9516
|
const params = parse("get_offers", c.req.query());
|
|
9911
|
-
const
|
|
9517
|
+
const offers = await store.getAll({
|
|
9912
9518
|
query: {
|
|
9913
9519
|
creators: params.creators,
|
|
9914
9520
|
side: params.side,
|
|
@@ -9936,20 +9542,20 @@ async function serve(parameters) {
|
|
|
9936
9542
|
}
|
|
9937
9543
|
});
|
|
9938
9544
|
return Mempool.success(c, {
|
|
9939
|
-
data:
|
|
9545
|
+
data: offers.offers.map(
|
|
9940
9546
|
(offer) => Format.stringifyBigint(Format.toSnakeCase(toResponse(offer)))
|
|
9941
9547
|
),
|
|
9942
|
-
cursor:
|
|
9548
|
+
cursor: offers.nextCursor ?? null
|
|
9943
9549
|
});
|
|
9944
9550
|
} catch (err) {
|
|
9945
9551
|
console.error(err);
|
|
9946
9552
|
return Mempool.error(err, c);
|
|
9947
9553
|
}
|
|
9948
9554
|
});
|
|
9949
|
-
app.get("/v1/match
|
|
9555
|
+
app.get("/v1/offers/match", async (c) => {
|
|
9950
9556
|
try {
|
|
9951
9557
|
const params = parse("match_offers", c.req.query());
|
|
9952
|
-
const
|
|
9558
|
+
const offers = await store.findMatchingOffers({
|
|
9953
9559
|
side: params.side,
|
|
9954
9560
|
chainId: params.chain_id,
|
|
9955
9561
|
rate: params.rate,
|
|
@@ -9964,10 +9570,10 @@ async function serve(parameters) {
|
|
|
9964
9570
|
limit: params.limit
|
|
9965
9571
|
});
|
|
9966
9572
|
return Mempool.success(c, {
|
|
9967
|
-
data:
|
|
9573
|
+
data: offers.offers.map(
|
|
9968
9574
|
(offer) => Format.stringifyBigint(Format.toSnakeCase(toResponse(offer)))
|
|
9969
9575
|
),
|
|
9970
|
-
cursor:
|
|
9576
|
+
cursor: offers.nextCursor ?? null
|
|
9971
9577
|
});
|
|
9972
9578
|
} catch (err) {
|
|
9973
9579
|
console.error(err);
|
|
@@ -10196,7 +9802,7 @@ function aoutput(out, instance) {
|
|
|
10196
9802
|
function u32(arr) {
|
|
10197
9803
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
10198
9804
|
}
|
|
10199
|
-
function
|
|
9805
|
+
function clean(...arrays) {
|
|
10200
9806
|
for (let i = 0; i < arrays.length; i++) {
|
|
10201
9807
|
arrays[i].fill(0);
|
|
10202
9808
|
}
|
|
@@ -10379,7 +9985,7 @@ var HashMD = class extends Hash {
|
|
|
10379
9985
|
const { buffer, view, blockLen, isLE: isLE3 } = this;
|
|
10380
9986
|
let { pos } = this;
|
|
10381
9987
|
buffer[pos++] = 128;
|
|
10382
|
-
|
|
9988
|
+
clean(this.buffer.subarray(pos));
|
|
10383
9989
|
if (this.padOffset > blockLen - pos) {
|
|
10384
9990
|
this.process(view, 0);
|
|
10385
9991
|
pos = 0;
|
|
@@ -10587,11 +10193,11 @@ var SHA256 = class extends HashMD {
|
|
|
10587
10193
|
this.set(A, B, C, D, E, F2, G, H);
|
|
10588
10194
|
}
|
|
10589
10195
|
roundClean() {
|
|
10590
|
-
|
|
10196
|
+
clean(SHA256_W);
|
|
10591
10197
|
}
|
|
10592
10198
|
destroy() {
|
|
10593
10199
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
10594
|
-
|
|
10200
|
+
clean(this.buffer);
|
|
10595
10201
|
}
|
|
10596
10202
|
};
|
|
10597
10203
|
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
@@ -10619,7 +10225,7 @@ var HMAC = class extends Hash {
|
|
|
10619
10225
|
for (let i = 0; i < pad2.length; i++)
|
|
10620
10226
|
pad2[i] ^= 54 ^ 92;
|
|
10621
10227
|
this.oHash.update(pad2);
|
|
10622
|
-
|
|
10228
|
+
clean(pad2);
|
|
10623
10229
|
}
|
|
10624
10230
|
update(buf) {
|
|
10625
10231
|
aexists(this);
|
|
@@ -12268,8 +11874,8 @@ function getHash(hash3) {
|
|
|
12268
11874
|
};
|
|
12269
11875
|
}
|
|
12270
11876
|
function createCurve(curveDef, defHash) {
|
|
12271
|
-
const
|
|
12272
|
-
return { ...
|
|
11877
|
+
const create = (hash3) => weierstrass({ ...curveDef, ...getHash(hash3) });
|
|
11878
|
+
return { ...create(defHash), create };
|
|
12273
11879
|
}
|
|
12274
11880
|
|
|
12275
11881
|
// ../../node_modules/.pnpm/@noble+curves@1.9.0/node_modules/@noble/curves/esm/secp256k1.js
|
|
@@ -12556,11 +12162,11 @@ function concatBytes3(...arrays) {
|
|
|
12556
12162
|
function utf8ToBytes2(utf) {
|
|
12557
12163
|
return new TextEncoder().encode(utf);
|
|
12558
12164
|
}
|
|
12559
|
-
function numberToHex(
|
|
12560
|
-
if (
|
|
12165
|
+
function numberToHex(integer) {
|
|
12166
|
+
if (integer < 0) {
|
|
12561
12167
|
throw EthereumJSErrorWithoutCode("Invalid integer as argument, must be unsigned!");
|
|
12562
12168
|
}
|
|
12563
|
-
const hex =
|
|
12169
|
+
const hex = integer.toString(16);
|
|
12564
12170
|
return hex.length % 2 ? `0${hex}` : hex;
|
|
12565
12171
|
}
|
|
12566
12172
|
function padToEven(a) {
|
|
@@ -12940,7 +12546,7 @@ function keccakP(s, rounds = 24) {
|
|
|
12940
12546
|
s[0] ^= SHA3_IOTA_H[round];
|
|
12941
12547
|
s[1] ^= SHA3_IOTA_L[round];
|
|
12942
12548
|
}
|
|
12943
|
-
|
|
12549
|
+
clean(B);
|
|
12944
12550
|
}
|
|
12945
12551
|
var Keccak = class _Keccak extends Hash {
|
|
12946
12552
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
@@ -13036,7 +12642,7 @@ var Keccak = class _Keccak extends Hash {
|
|
|
13036
12642
|
}
|
|
13037
12643
|
destroy() {
|
|
13038
12644
|
this.destroyed = true;
|
|
13039
|
-
|
|
12645
|
+
clean(this.state);
|
|
13040
12646
|
}
|
|
13041
12647
|
_cloneInto(to) {
|
|
13042
12648
|
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
@@ -13401,8 +13007,8 @@ function isEOACode7702AuthorizationList(input) {
|
|
|
13401
13007
|
|
|
13402
13008
|
// ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/withdrawal.js
|
|
13403
13009
|
function withdrawalToBytesArray(withdrawal) {
|
|
13404
|
-
const { index
|
|
13405
|
-
const indexBytes = toType(
|
|
13010
|
+
const { index, validatorIndex, address, amount } = withdrawal;
|
|
13011
|
+
const indexBytes = toType(index, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(index, TypeOutput.Uint8Array);
|
|
13406
13012
|
const validatorIndexBytes = toType(validatorIndex, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(validatorIndex, TypeOutput.Uint8Array);
|
|
13407
13013
|
const addressBytes = address instanceof Address ? address.bytes : toType(address, TypeOutput.Uint8Array);
|
|
13408
13014
|
const amountBytes = toType(amount, TypeOutput.BigInt) === BIGINT_02 ? new Uint8Array() : toType(amount, TypeOutput.Uint8Array);
|
|
@@ -13414,8 +13020,8 @@ var Withdrawal = class {
|
|
|
13414
13020
|
* Use the static factory methods to assist in creating a Withdrawal object from varying data types.
|
|
13415
13021
|
* Its amount is in Gwei to match CL representation and for eventual ssz withdrawalsRoot
|
|
13416
13022
|
*/
|
|
13417
|
-
constructor(
|
|
13418
|
-
this.index =
|
|
13023
|
+
constructor(index, validatorIndex, address, amount) {
|
|
13024
|
+
this.index = index;
|
|
13419
13025
|
this.validatorIndex = validatorIndex;
|
|
13420
13026
|
this.address = address;
|
|
13421
13027
|
this.amount = amount;
|
|
@@ -13442,11 +13048,11 @@ var Withdrawal = class {
|
|
|
13442
13048
|
};
|
|
13443
13049
|
function createWithdrawal(withdrawalData) {
|
|
13444
13050
|
const { index: indexData, validatorIndex: validatorIndexData, address: addressData, amount: amountData } = withdrawalData;
|
|
13445
|
-
const
|
|
13051
|
+
const index = toType(indexData, TypeOutput.BigInt);
|
|
13446
13052
|
const validatorIndex = toType(validatorIndexData, TypeOutput.BigInt);
|
|
13447
13053
|
const address = addressData instanceof Address ? addressData : new Address(toBytes3(addressData));
|
|
13448
13054
|
const amount = toType(amountData, TypeOutput.BigInt);
|
|
13449
|
-
return new Withdrawal(
|
|
13055
|
+
return new Withdrawal(index, validatorIndex, address, amount);
|
|
13450
13056
|
}
|
|
13451
13057
|
|
|
13452
13058
|
// ../../node_modules/.pnpm/@ethereumjs+util@10.0.0/node_modules/@ethereumjs/util/dist/esm/signature.js
|
|
@@ -13855,8 +13461,8 @@ if (typeof Int32Array !== "undefined") {
|
|
|
13855
13461
|
}
|
|
13856
13462
|
var crc = (current, previous) => {
|
|
13857
13463
|
let crc2 = 0 ^ -1;
|
|
13858
|
-
for (let
|
|
13859
|
-
crc2 = TABLE[(crc2 ^ current[
|
|
13464
|
+
for (let index = 0; index < current.length; index++) {
|
|
13465
|
+
crc2 = TABLE[(crc2 ^ current[index]) & 255] ^ crc2 >>> 8;
|
|
13860
13466
|
}
|
|
13861
13467
|
return crc2 ^ -1;
|
|
13862
13468
|
};
|
|
@@ -14689,15 +14295,15 @@ var Common = class {
|
|
|
14689
14295
|
*/
|
|
14690
14296
|
getHardforkBy(opts) {
|
|
14691
14297
|
const blockNumber = toType(opts.blockNumber, TypeOutput.BigInt);
|
|
14692
|
-
const
|
|
14298
|
+
const timestamp = toType(opts.timestamp, TypeOutput.BigInt);
|
|
14693
14299
|
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 ||
|
|
14300
|
+
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
14301
|
if (hfIndex === -1) {
|
|
14696
14302
|
hfIndex = hfs.length;
|
|
14697
14303
|
} else if (hfIndex === 0) {
|
|
14698
14304
|
throw Error("Must have at least one hardfork at block 0");
|
|
14699
14305
|
}
|
|
14700
|
-
if (
|
|
14306
|
+
if (timestamp === void 0) {
|
|
14701
14307
|
const stepBack = hfs.slice(0, hfIndex).reverse().findIndex((hf) => hf.block !== null);
|
|
14702
14308
|
hfIndex = hfIndex - stepBack;
|
|
14703
14309
|
}
|
|
@@ -14708,13 +14314,13 @@ var Common = class {
|
|
|
14708
14314
|
break;
|
|
14709
14315
|
}
|
|
14710
14316
|
}
|
|
14711
|
-
if (
|
|
14317
|
+
if (timestamp !== void 0) {
|
|
14712
14318
|
const minTimeStamp = hfs.slice(0, hfStartIndex).reduce((acc, hf) => Math.max(Number(hf.timestamp ?? "0"), acc), 0);
|
|
14713
|
-
if (minTimeStamp >
|
|
14319
|
+
if (minTimeStamp > timestamp) {
|
|
14714
14320
|
throw Error(`Maximum HF determined by timestamp is lower than the block number HF`);
|
|
14715
14321
|
}
|
|
14716
|
-
const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ??
|
|
14717
|
-
if (maxTimeStamp <
|
|
14322
|
+
const maxTimeStamp = hfs.slice(hfIndex + 1).reduce((acc, hf) => Math.min(Number(hf.timestamp ?? timestamp), acc), Number(timestamp));
|
|
14323
|
+
if (maxTimeStamp < timestamp) {
|
|
14718
14324
|
throw Error(`Maximum HF determined by block number is lower than timestamp HF`);
|
|
14719
14325
|
}
|
|
14720
14326
|
}
|
|
@@ -14885,8 +14491,8 @@ var Common = class {
|
|
|
14885
14491
|
* @param blockNumber Block number
|
|
14886
14492
|
* * @returns The value requested or `BigInt(0)` if not found
|
|
14887
14493
|
*/
|
|
14888
|
-
paramByBlock(name, blockNumber,
|
|
14889
|
-
const hardfork = this.getHardforkBy({ blockNumber, timestamp
|
|
14494
|
+
paramByBlock(name, blockNumber, timestamp) {
|
|
14495
|
+
const hardfork = this.getHardforkBy({ blockNumber, timestamp });
|
|
14890
14496
|
return this.paramByHardfork(name, hardfork);
|
|
14891
14497
|
}
|
|
14892
14498
|
/**
|
|
@@ -14938,13 +14544,13 @@ var Common = class {
|
|
|
14938
14544
|
hardfork1 = hardfork1 ?? this._hardfork;
|
|
14939
14545
|
const hardforks = this.hardforks();
|
|
14940
14546
|
let posHf1 = -1, posHf2 = -1;
|
|
14941
|
-
let
|
|
14547
|
+
let index = 0;
|
|
14942
14548
|
for (const hf of hardforks) {
|
|
14943
14549
|
if (hf["name"] === hardfork1)
|
|
14944
|
-
posHf1 =
|
|
14550
|
+
posHf1 = index;
|
|
14945
14551
|
if (hf["name"] === hardfork2)
|
|
14946
|
-
posHf2 =
|
|
14947
|
-
|
|
14552
|
+
posHf2 = index;
|
|
14553
|
+
index += 1;
|
|
14948
14554
|
}
|
|
14949
14555
|
return posHf1 >= posHf2 && posHf2 !== -1;
|
|
14950
14556
|
}
|
|
@@ -14971,11 +14577,11 @@ var Common = class {
|
|
|
14971
14577
|
}
|
|
14972
14578
|
hardforkTimestamp(hardfork) {
|
|
14973
14579
|
hardfork = hardfork ?? this._hardfork;
|
|
14974
|
-
const
|
|
14975
|
-
if (
|
|
14580
|
+
const timestamp = this._getHardfork(hardfork)?.["timestamp"];
|
|
14581
|
+
if (timestamp === void 0 || timestamp === null) {
|
|
14976
14582
|
return null;
|
|
14977
14583
|
}
|
|
14978
|
-
return BigInt(
|
|
14584
|
+
return BigInt(timestamp);
|
|
14979
14585
|
}
|
|
14980
14586
|
/**
|
|
14981
14587
|
* Returns the hardfork change block for eip
|
|
@@ -15050,8 +14656,8 @@ var Common = class {
|
|
|
15050
14656
|
let hfBytes = new Uint8Array(0);
|
|
15051
14657
|
let prevBlockOrTime = 0;
|
|
15052
14658
|
for (const hf of this.hardforks()) {
|
|
15053
|
-
const { block, timestamp
|
|
15054
|
-
let blockOrTime =
|
|
14659
|
+
const { block, timestamp, name } = hf;
|
|
14660
|
+
let blockOrTime = timestamp ?? block;
|
|
15055
14661
|
blockOrTime = blockOrTime !== null ? Number(blockOrTime) : null;
|
|
15056
14662
|
if (typeof blockOrTime === "number" && blockOrTime !== 0 && blockOrTime !== prevBlockOrTime && name !== Hardfork.Paris) {
|
|
15057
14663
|
const hfBlockBytes = hexToBytes5(`0x${blockOrTime.toString(16).padStart(16, "0")}`);
|
|
@@ -17266,9 +16872,9 @@ var handlers = /* @__PURE__ */ new Map([
|
|
|
17266
16872
|
[
|
|
17267
16873
|
73,
|
|
17268
16874
|
function(runState) {
|
|
17269
|
-
const
|
|
17270
|
-
if (runState.env.blobVersionedHashes.length > Number(
|
|
17271
|
-
runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(
|
|
16875
|
+
const index = runState.stack.pop();
|
|
16876
|
+
if (runState.env.blobVersionedHashes.length > Number(index)) {
|
|
16877
|
+
runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(index)]));
|
|
17272
16878
|
} else {
|
|
17273
16879
|
runState.stack.push(BIGINT_02);
|
|
17274
16880
|
}
|
|
@@ -19332,11 +18938,11 @@ var Stack = class {
|
|
|
19332
18938
|
const peekArray = Array(num);
|
|
19333
18939
|
let start = this._len;
|
|
19334
18940
|
for (let peek = 0; peek < num; peek++) {
|
|
19335
|
-
const
|
|
19336
|
-
if (
|
|
18941
|
+
const index = --start;
|
|
18942
|
+
if (index < 0) {
|
|
19337
18943
|
throw new EVMError(EVMError.errorMessages.STACK_UNDERFLOW);
|
|
19338
18944
|
}
|
|
19339
|
-
peekArray[peek] = this._store[
|
|
18945
|
+
peekArray[peek] = this._store[index];
|
|
19340
18946
|
}
|
|
19341
18947
|
return peekArray;
|
|
19342
18948
|
}
|
|
@@ -24946,8 +24552,8 @@ var msmGasUsed = (numPairs, gasUsedPerPair, discountTable) => {
|
|
|
24946
24552
|
return BigInt(numPairs) * gasUsedPerPair * BigInt(gasDiscountMultiplier) / BigInt(1e3);
|
|
24947
24553
|
};
|
|
24948
24554
|
var leading16ZeroBytesCheck = (opts, zeroByteRanges, pName, pairStart = 0) => {
|
|
24949
|
-
for (const
|
|
24950
|
-
const slicedBuffer = opts.data.subarray(zeroByteRanges[
|
|
24555
|
+
for (const index in zeroByteRanges) {
|
|
24556
|
+
const slicedBuffer = opts.data.subarray(zeroByteRanges[index][0] + pairStart, zeroByteRanges[index][1] + pairStart);
|
|
24951
24557
|
if (!(equalsBytes(slicedBuffer, ZERO_BYTES_16) === true)) {
|
|
24952
24558
|
if (opts._debug !== void 0) {
|
|
24953
24559
|
opts._debug(`${pName} failed: Point not on curve`);
|
|
@@ -25365,11 +24971,11 @@ var RIPEMD160 = class extends HashMD {
|
|
|
25365
24971
|
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
24972
|
}
|
|
25367
24973
|
roundClean() {
|
|
25368
|
-
|
|
24974
|
+
clean(BUF_160);
|
|
25369
24975
|
}
|
|
25370
24976
|
destroy() {
|
|
25371
24977
|
this.destroyed = true;
|
|
25372
|
-
|
|
24978
|
+
clean(this.buffer);
|
|
25373
24979
|
this.set(0, 0, 0, 0, 0);
|
|
25374
24980
|
}
|
|
25375
24981
|
};
|
|
@@ -28732,11 +28338,11 @@ var LRUCache = class _LRUCache {
|
|
|
28732
28338
|
free: c.#free,
|
|
28733
28339
|
// methods
|
|
28734
28340
|
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
28735
|
-
backgroundFetch: (k,
|
|
28736
|
-
moveToTail: (
|
|
28341
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
28342
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
28737
28343
|
indexes: (options) => c.#indexes(options),
|
|
28738
28344
|
rindexes: (options) => c.#rindexes(options),
|
|
28739
|
-
isStale: (
|
|
28345
|
+
isStale: (index) => c.#isStale(index)
|
|
28740
28346
|
};
|
|
28741
28347
|
}
|
|
28742
28348
|
// Protected read-only members
|
|
@@ -28891,13 +28497,13 @@ var LRUCache = class _LRUCache {
|
|
|
28891
28497
|
const starts = new ZeroArray(this.#max);
|
|
28892
28498
|
this.#ttls = ttls;
|
|
28893
28499
|
this.#starts = starts;
|
|
28894
|
-
this.#setItemTTL = (
|
|
28895
|
-
starts[
|
|
28896
|
-
ttls[
|
|
28500
|
+
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
28501
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
28502
|
+
ttls[index] = ttl;
|
|
28897
28503
|
if (ttl !== 0 && this.ttlAutopurge) {
|
|
28898
28504
|
const t = setTimeout(() => {
|
|
28899
|
-
if (this.#isStale(
|
|
28900
|
-
this.#delete(this.#keyList[
|
|
28505
|
+
if (this.#isStale(index)) {
|
|
28506
|
+
this.#delete(this.#keyList[index], "expire");
|
|
28901
28507
|
}
|
|
28902
28508
|
}, ttl + 1);
|
|
28903
28509
|
if (t.unref) {
|
|
@@ -28905,13 +28511,13 @@ var LRUCache = class _LRUCache {
|
|
|
28905
28511
|
}
|
|
28906
28512
|
}
|
|
28907
28513
|
};
|
|
28908
|
-
this.#updateItemAge = (
|
|
28909
|
-
starts[
|
|
28514
|
+
this.#updateItemAge = (index) => {
|
|
28515
|
+
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
28910
28516
|
};
|
|
28911
|
-
this.#statusTTL = (status,
|
|
28912
|
-
if (ttls[
|
|
28913
|
-
const ttl = ttls[
|
|
28914
|
-
const start = starts[
|
|
28517
|
+
this.#statusTTL = (status, index) => {
|
|
28518
|
+
if (ttls[index]) {
|
|
28519
|
+
const ttl = ttls[index];
|
|
28520
|
+
const start = starts[index];
|
|
28915
28521
|
if (!ttl || !start)
|
|
28916
28522
|
return;
|
|
28917
28523
|
status.ttl = ttl;
|
|
@@ -28934,21 +28540,21 @@ var LRUCache = class _LRUCache {
|
|
|
28934
28540
|
return n;
|
|
28935
28541
|
};
|
|
28936
28542
|
this.getRemainingTTL = (key) => {
|
|
28937
|
-
const
|
|
28938
|
-
if (
|
|
28543
|
+
const index = this.#keyMap.get(key);
|
|
28544
|
+
if (index === void 0) {
|
|
28939
28545
|
return 0;
|
|
28940
28546
|
}
|
|
28941
|
-
const ttl = ttls[
|
|
28942
|
-
const start = starts[
|
|
28547
|
+
const ttl = ttls[index];
|
|
28548
|
+
const start = starts[index];
|
|
28943
28549
|
if (!ttl || !start) {
|
|
28944
28550
|
return Infinity;
|
|
28945
28551
|
}
|
|
28946
28552
|
const age = (cachedNow || getNow()) - start;
|
|
28947
28553
|
return ttl - age;
|
|
28948
28554
|
};
|
|
28949
|
-
this.#isStale = (
|
|
28950
|
-
const s = starts[
|
|
28951
|
-
const t = ttls[
|
|
28555
|
+
this.#isStale = (index) => {
|
|
28556
|
+
const s = starts[index];
|
|
28557
|
+
const t = ttls[index];
|
|
28952
28558
|
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
28953
28559
|
};
|
|
28954
28560
|
}
|
|
@@ -28965,9 +28571,9 @@ var LRUCache = class _LRUCache {
|
|
|
28965
28571
|
const sizes = new ZeroArray(this.#max);
|
|
28966
28572
|
this.#calculatedSize = 0;
|
|
28967
28573
|
this.#sizes = sizes;
|
|
28968
|
-
this.#removeItemSize = (
|
|
28969
|
-
this.#calculatedSize -= sizes[
|
|
28970
|
-
sizes[
|
|
28574
|
+
this.#removeItemSize = (index) => {
|
|
28575
|
+
this.#calculatedSize -= sizes[index];
|
|
28576
|
+
sizes[index] = 0;
|
|
28971
28577
|
};
|
|
28972
28578
|
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
28973
28579
|
if (this.#isBackgroundFetch(v)) {
|
|
@@ -28988,15 +28594,15 @@ var LRUCache = class _LRUCache {
|
|
|
28988
28594
|
}
|
|
28989
28595
|
return size;
|
|
28990
28596
|
};
|
|
28991
|
-
this.#addItemSize = (
|
|
28992
|
-
sizes[
|
|
28597
|
+
this.#addItemSize = (index, size, status) => {
|
|
28598
|
+
sizes[index] = size;
|
|
28993
28599
|
if (this.#maxSize) {
|
|
28994
|
-
const maxSize2 = this.#maxSize - sizes[
|
|
28600
|
+
const maxSize2 = this.#maxSize - sizes[index];
|
|
28995
28601
|
while (this.#calculatedSize > maxSize2) {
|
|
28996
28602
|
this.#evict(true);
|
|
28997
28603
|
}
|
|
28998
28604
|
}
|
|
28999
|
-
this.#calculatedSize += sizes[
|
|
28605
|
+
this.#calculatedSize += sizes[index];
|
|
29000
28606
|
if (status) {
|
|
29001
28607
|
status.entrySize = size;
|
|
29002
28608
|
status.totalCalculatedSize = this.#calculatedSize;
|
|
@@ -29047,8 +28653,8 @@ var LRUCache = class _LRUCache {
|
|
|
29047
28653
|
}
|
|
29048
28654
|
}
|
|
29049
28655
|
}
|
|
29050
|
-
#isValidIndex(
|
|
29051
|
-
return
|
|
28656
|
+
#isValidIndex(index) {
|
|
28657
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
29052
28658
|
}
|
|
29053
28659
|
/**
|
|
29054
28660
|
* Return a generator yielding `[key, value]` pairs,
|
|
@@ -29335,23 +28941,23 @@ var LRUCache = class _LRUCache {
|
|
|
29335
28941
|
this.#delete(k, "set");
|
|
29336
28942
|
return this;
|
|
29337
28943
|
}
|
|
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 =
|
|
28944
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
28945
|
+
if (index === void 0) {
|
|
28946
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
28947
|
+
this.#keyList[index] = k;
|
|
28948
|
+
this.#valList[index] = v;
|
|
28949
|
+
this.#keyMap.set(k, index);
|
|
28950
|
+
this.#next[this.#tail] = index;
|
|
28951
|
+
this.#prev[index] = this.#tail;
|
|
28952
|
+
this.#tail = index;
|
|
29347
28953
|
this.#size++;
|
|
29348
|
-
this.#addItemSize(
|
|
28954
|
+
this.#addItemSize(index, size, status);
|
|
29349
28955
|
if (status)
|
|
29350
28956
|
status.set = "add";
|
|
29351
28957
|
noUpdateTTL = false;
|
|
29352
28958
|
} else {
|
|
29353
|
-
this.#moveToTail(
|
|
29354
|
-
const oldVal = this.#valList[
|
|
28959
|
+
this.#moveToTail(index);
|
|
28960
|
+
const oldVal = this.#valList[index];
|
|
29355
28961
|
if (v !== oldVal) {
|
|
29356
28962
|
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
29357
28963
|
oldVal.__abortController.abort(new Error("replaced"));
|
|
@@ -29372,9 +28978,9 @@ var LRUCache = class _LRUCache {
|
|
|
29372
28978
|
this.#disposed?.push([oldVal, k, "set"]);
|
|
29373
28979
|
}
|
|
29374
28980
|
}
|
|
29375
|
-
this.#removeItemSize(
|
|
29376
|
-
this.#addItemSize(
|
|
29377
|
-
this.#valList[
|
|
28981
|
+
this.#removeItemSize(index);
|
|
28982
|
+
this.#addItemSize(index, size, status);
|
|
28983
|
+
this.#valList[index] = v;
|
|
29378
28984
|
if (status) {
|
|
29379
28985
|
status.set = "replace";
|
|
29380
28986
|
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
@@ -29390,10 +28996,10 @@ var LRUCache = class _LRUCache {
|
|
|
29390
28996
|
}
|
|
29391
28997
|
if (this.#ttls) {
|
|
29392
28998
|
if (!noUpdateTTL) {
|
|
29393
|
-
this.#setItemTTL(
|
|
28999
|
+
this.#setItemTTL(index, ttl, start);
|
|
29394
29000
|
}
|
|
29395
29001
|
if (status)
|
|
29396
|
-
this.#statusTTL(status,
|
|
29002
|
+
this.#statusTTL(status, index);
|
|
29397
29003
|
}
|
|
29398
29004
|
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
29399
29005
|
const dt = this.#disposed;
|
|
@@ -29479,24 +29085,24 @@ var LRUCache = class _LRUCache {
|
|
|
29479
29085
|
*/
|
|
29480
29086
|
has(k, hasOptions = {}) {
|
|
29481
29087
|
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
29482
|
-
const
|
|
29483
|
-
if (
|
|
29484
|
-
const v = this.#valList[
|
|
29088
|
+
const index = this.#keyMap.get(k);
|
|
29089
|
+
if (index !== void 0) {
|
|
29090
|
+
const v = this.#valList[index];
|
|
29485
29091
|
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
29486
29092
|
return false;
|
|
29487
29093
|
}
|
|
29488
|
-
if (!this.#isStale(
|
|
29094
|
+
if (!this.#isStale(index)) {
|
|
29489
29095
|
if (updateAgeOnHas) {
|
|
29490
|
-
this.#updateItemAge(
|
|
29096
|
+
this.#updateItemAge(index);
|
|
29491
29097
|
}
|
|
29492
29098
|
if (status) {
|
|
29493
29099
|
status.has = "hit";
|
|
29494
|
-
this.#statusTTL(status,
|
|
29100
|
+
this.#statusTTL(status, index);
|
|
29495
29101
|
}
|
|
29496
29102
|
return true;
|
|
29497
29103
|
} else if (status) {
|
|
29498
29104
|
status.has = "stale";
|
|
29499
|
-
this.#statusTTL(status,
|
|
29105
|
+
this.#statusTTL(status, index);
|
|
29500
29106
|
}
|
|
29501
29107
|
} else if (status) {
|
|
29502
29108
|
status.has = "miss";
|
|
@@ -29512,15 +29118,15 @@ var LRUCache = class _LRUCache {
|
|
|
29512
29118
|
*/
|
|
29513
29119
|
peek(k, peekOptions = {}) {
|
|
29514
29120
|
const { allowStale = this.allowStale } = peekOptions;
|
|
29515
|
-
const
|
|
29516
|
-
if (
|
|
29121
|
+
const index = this.#keyMap.get(k);
|
|
29122
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
29517
29123
|
return;
|
|
29518
29124
|
}
|
|
29519
|
-
const v = this.#valList[
|
|
29125
|
+
const v = this.#valList[index];
|
|
29520
29126
|
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
29521
29127
|
}
|
|
29522
|
-
#backgroundFetch(k,
|
|
29523
|
-
const v =
|
|
29128
|
+
#backgroundFetch(k, index, options, context) {
|
|
29129
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
29524
29130
|
if (this.#isBackgroundFetch(v)) {
|
|
29525
29131
|
return v;
|
|
29526
29132
|
}
|
|
@@ -29551,10 +29157,10 @@ var LRUCache = class _LRUCache {
|
|
|
29551
29157
|
return fetchFail(ac.signal.reason);
|
|
29552
29158
|
}
|
|
29553
29159
|
const bf2 = p;
|
|
29554
|
-
if (this.#valList[
|
|
29160
|
+
if (this.#valList[index] === p) {
|
|
29555
29161
|
if (v2 === void 0) {
|
|
29556
29162
|
if (bf2.__staleWhileFetching) {
|
|
29557
|
-
this.#valList[
|
|
29163
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
29558
29164
|
} else {
|
|
29559
29165
|
this.#delete(k, "fetch");
|
|
29560
29166
|
}
|
|
@@ -29579,12 +29185,12 @@ var LRUCache = class _LRUCache {
|
|
|
29579
29185
|
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
29580
29186
|
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
29581
29187
|
const bf2 = p;
|
|
29582
|
-
if (this.#valList[
|
|
29188
|
+
if (this.#valList[index] === p) {
|
|
29583
29189
|
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
29584
29190
|
if (del) {
|
|
29585
29191
|
this.#delete(k, "fetch");
|
|
29586
29192
|
} else if (!allowStaleAborted) {
|
|
29587
|
-
this.#valList[
|
|
29193
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
29588
29194
|
}
|
|
29589
29195
|
}
|
|
29590
29196
|
if (allowStale) {
|
|
@@ -29618,11 +29224,11 @@ var LRUCache = class _LRUCache {
|
|
|
29618
29224
|
__staleWhileFetching: v,
|
|
29619
29225
|
__returned: void 0
|
|
29620
29226
|
});
|
|
29621
|
-
if (
|
|
29227
|
+
if (index === void 0) {
|
|
29622
29228
|
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
29623
|
-
|
|
29229
|
+
index = this.#keyMap.get(k);
|
|
29624
29230
|
} else {
|
|
29625
|
-
this.#valList[
|
|
29231
|
+
this.#valList[index] = bf;
|
|
29626
29232
|
}
|
|
29627
29233
|
return bf;
|
|
29628
29234
|
}
|
|
@@ -29680,14 +29286,14 @@ var LRUCache = class _LRUCache {
|
|
|
29680
29286
|
status,
|
|
29681
29287
|
signal
|
|
29682
29288
|
};
|
|
29683
|
-
let
|
|
29684
|
-
if (
|
|
29289
|
+
let index = this.#keyMap.get(k);
|
|
29290
|
+
if (index === void 0) {
|
|
29685
29291
|
if (status)
|
|
29686
29292
|
status.fetch = "miss";
|
|
29687
|
-
const p = this.#backgroundFetch(k,
|
|
29293
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
29688
29294
|
return p.__returned = p;
|
|
29689
29295
|
} else {
|
|
29690
|
-
const v = this.#valList[
|
|
29296
|
+
const v = this.#valList[index];
|
|
29691
29297
|
if (this.#isBackgroundFetch(v)) {
|
|
29692
29298
|
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
29693
29299
|
if (status) {
|
|
@@ -29697,19 +29303,19 @@ var LRUCache = class _LRUCache {
|
|
|
29697
29303
|
}
|
|
29698
29304
|
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
29699
29305
|
}
|
|
29700
|
-
const isStale = this.#isStale(
|
|
29306
|
+
const isStale = this.#isStale(index);
|
|
29701
29307
|
if (!forceRefresh && !isStale) {
|
|
29702
29308
|
if (status)
|
|
29703
29309
|
status.fetch = "hit";
|
|
29704
|
-
this.#moveToTail(
|
|
29310
|
+
this.#moveToTail(index);
|
|
29705
29311
|
if (updateAgeOnGet) {
|
|
29706
|
-
this.#updateItemAge(
|
|
29312
|
+
this.#updateItemAge(index);
|
|
29707
29313
|
}
|
|
29708
29314
|
if (status)
|
|
29709
|
-
this.#statusTTL(status,
|
|
29315
|
+
this.#statusTTL(status, index);
|
|
29710
29316
|
return v;
|
|
29711
29317
|
}
|
|
29712
|
-
const p = this.#backgroundFetch(k,
|
|
29318
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
29713
29319
|
const hasStale = p.__staleWhileFetching !== void 0;
|
|
29714
29320
|
const staleVal = hasStale && allowStale;
|
|
29715
29321
|
if (status) {
|
|
@@ -29750,13 +29356,13 @@ var LRUCache = class _LRUCache {
|
|
|
29750
29356
|
*/
|
|
29751
29357
|
get(k, getOptions = {}) {
|
|
29752
29358
|
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
29753
|
-
const
|
|
29754
|
-
if (
|
|
29755
|
-
const value = this.#valList[
|
|
29359
|
+
const index = this.#keyMap.get(k);
|
|
29360
|
+
if (index !== void 0) {
|
|
29361
|
+
const value = this.#valList[index];
|
|
29756
29362
|
const fetching = this.#isBackgroundFetch(value);
|
|
29757
29363
|
if (status)
|
|
29758
|
-
this.#statusTTL(status,
|
|
29759
|
-
if (this.#isStale(
|
|
29364
|
+
this.#statusTTL(status, index);
|
|
29365
|
+
if (this.#isStale(index)) {
|
|
29760
29366
|
if (status)
|
|
29761
29367
|
status.get = "stale";
|
|
29762
29368
|
if (!fetching) {
|
|
@@ -29778,9 +29384,9 @@ var LRUCache = class _LRUCache {
|
|
|
29778
29384
|
if (fetching) {
|
|
29779
29385
|
return value.__staleWhileFetching;
|
|
29780
29386
|
}
|
|
29781
|
-
this.#moveToTail(
|
|
29387
|
+
this.#moveToTail(index);
|
|
29782
29388
|
if (updateAgeOnGet) {
|
|
29783
|
-
this.#updateItemAge(
|
|
29389
|
+
this.#updateItemAge(index);
|
|
29784
29390
|
}
|
|
29785
29391
|
return value;
|
|
29786
29392
|
}
|
|
@@ -29792,15 +29398,15 @@ var LRUCache = class _LRUCache {
|
|
|
29792
29398
|
this.#prev[n] = p;
|
|
29793
29399
|
this.#next[p] = n;
|
|
29794
29400
|
}
|
|
29795
|
-
#moveToTail(
|
|
29796
|
-
if (
|
|
29797
|
-
if (
|
|
29798
|
-
this.#head = this.#next[
|
|
29401
|
+
#moveToTail(index) {
|
|
29402
|
+
if (index !== this.#tail) {
|
|
29403
|
+
if (index === this.#head) {
|
|
29404
|
+
this.#head = this.#next[index];
|
|
29799
29405
|
} else {
|
|
29800
|
-
this.#connect(this.#prev[
|
|
29406
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
29801
29407
|
}
|
|
29802
|
-
this.#connect(this.#tail,
|
|
29803
|
-
this.#tail =
|
|
29408
|
+
this.#connect(this.#tail, index);
|
|
29409
|
+
this.#tail = index;
|
|
29804
29410
|
}
|
|
29805
29411
|
}
|
|
29806
29412
|
/**
|
|
@@ -29814,14 +29420,14 @@ var LRUCache = class _LRUCache {
|
|
|
29814
29420
|
#delete(k, reason) {
|
|
29815
29421
|
let deleted = false;
|
|
29816
29422
|
if (this.#size !== 0) {
|
|
29817
|
-
const
|
|
29818
|
-
if (
|
|
29423
|
+
const index = this.#keyMap.get(k);
|
|
29424
|
+
if (index !== void 0) {
|
|
29819
29425
|
deleted = true;
|
|
29820
29426
|
if (this.#size === 1) {
|
|
29821
29427
|
this.#clear(reason);
|
|
29822
29428
|
} else {
|
|
29823
|
-
this.#removeItemSize(
|
|
29824
|
-
const v = this.#valList[
|
|
29429
|
+
this.#removeItemSize(index);
|
|
29430
|
+
const v = this.#valList[index];
|
|
29825
29431
|
if (this.#isBackgroundFetch(v)) {
|
|
29826
29432
|
v.__abortController.abort(new Error("deleted"));
|
|
29827
29433
|
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
@@ -29833,20 +29439,20 @@ var LRUCache = class _LRUCache {
|
|
|
29833
29439
|
}
|
|
29834
29440
|
}
|
|
29835
29441
|
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[
|
|
29442
|
+
this.#keyList[index] = void 0;
|
|
29443
|
+
this.#valList[index] = void 0;
|
|
29444
|
+
if (index === this.#tail) {
|
|
29445
|
+
this.#tail = this.#prev[index];
|
|
29446
|
+
} else if (index === this.#head) {
|
|
29447
|
+
this.#head = this.#next[index];
|
|
29842
29448
|
} else {
|
|
29843
|
-
const pi = this.#prev[
|
|
29844
|
-
this.#next[pi] = this.#next[
|
|
29845
|
-
const ni = this.#next[
|
|
29846
|
-
this.#prev[ni] = this.#prev[
|
|
29449
|
+
const pi = this.#prev[index];
|
|
29450
|
+
this.#next[pi] = this.#next[index];
|
|
29451
|
+
const ni = this.#next[index];
|
|
29452
|
+
this.#prev[ni] = this.#prev[index];
|
|
29847
29453
|
}
|
|
29848
29454
|
this.#size--;
|
|
29849
|
-
this.#free.push(
|
|
29455
|
+
this.#free.push(index);
|
|
29850
29456
|
}
|
|
29851
29457
|
}
|
|
29852
29458
|
}
|
|
@@ -29866,12 +29472,12 @@ var LRUCache = class _LRUCache {
|
|
|
29866
29472
|
return this.#clear("delete");
|
|
29867
29473
|
}
|
|
29868
29474
|
#clear(reason) {
|
|
29869
|
-
for (const
|
|
29870
|
-
const v = this.#valList[
|
|
29475
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
29476
|
+
const v = this.#valList[index];
|
|
29871
29477
|
if (this.#isBackgroundFetch(v)) {
|
|
29872
29478
|
v.__abortController.abort(new Error("deleted"));
|
|
29873
29479
|
} else {
|
|
29874
|
-
const k = this.#keyList[
|
|
29480
|
+
const k = this.#keyList[index];
|
|
29875
29481
|
if (this.#hasDispose) {
|
|
29876
29482
|
this.#dispose?.(v, k, reason);
|
|
29877
29483
|
}
|
|
@@ -36636,9 +36242,9 @@ function sign(tx, privateKey, extraEntropy = true) {
|
|
|
36636
36242
|
const { recovery, r, s } = ecSignFunction(msgHash, privateKey, { extraEntropy });
|
|
36637
36243
|
const signedTx = tx.addSignature(BigInt(recovery), r, s, true);
|
|
36638
36244
|
if (hackApplied) {
|
|
36639
|
-
const
|
|
36640
|
-
if (
|
|
36641
|
-
tx["activeCapabilities"].splice(
|
|
36245
|
+
const index = tx["activeCapabilities"].indexOf(Capability.EIP155ReplayProtection);
|
|
36246
|
+
if (index > -1) {
|
|
36247
|
+
tx["activeCapabilities"].splice(index, 1);
|
|
36642
36248
|
}
|
|
36643
36249
|
}
|
|
36644
36250
|
return signedTx;
|
|
@@ -38595,7 +38201,7 @@ var BlockHeader = class {
|
|
|
38595
38201
|
const number2 = toType(headerData.number, TypeOutput.BigInt) ?? defaults2.number;
|
|
38596
38202
|
const gasLimit = toType(headerData.gasLimit, TypeOutput.BigInt) ?? defaults2.gasLimit;
|
|
38597
38203
|
const gasUsed = toType(headerData.gasUsed, TypeOutput.BigInt) ?? defaults2.gasUsed;
|
|
38598
|
-
const
|
|
38204
|
+
const timestamp = toType(headerData.timestamp, TypeOutput.BigInt) ?? defaults2.timestamp;
|
|
38599
38205
|
const extraData = toType(headerData.extraData, TypeOutput.Uint8Array) ?? defaults2.extraData;
|
|
38600
38206
|
const mixHash = toType(headerData.mixHash, TypeOutput.Uint8Array) ?? defaults2.mixHash;
|
|
38601
38207
|
const nonce = toType(headerData.nonce, TypeOutput.Uint8Array) ?? defaults2.nonce;
|
|
@@ -38603,7 +38209,7 @@ var BlockHeader = class {
|
|
|
38603
38209
|
if (setHardfork === true) {
|
|
38604
38210
|
this.common.setHardforkBy({
|
|
38605
38211
|
blockNumber: number2,
|
|
38606
|
-
timestamp
|
|
38212
|
+
timestamp
|
|
38607
38213
|
});
|
|
38608
38214
|
}
|
|
38609
38215
|
const hardforkDefaults = {
|
|
@@ -38653,7 +38259,7 @@ var BlockHeader = class {
|
|
|
38653
38259
|
this.number = number2;
|
|
38654
38260
|
this.gasLimit = gasLimit;
|
|
38655
38261
|
this.gasUsed = gasUsed;
|
|
38656
|
-
this.timestamp =
|
|
38262
|
+
this.timestamp = timestamp;
|
|
38657
38263
|
this.extraData = extraData;
|
|
38658
38264
|
this.mixHash = mixHash;
|
|
38659
38265
|
this.nonce = nonce;
|
|
@@ -39588,8 +39194,8 @@ var hmac2 = (hash3, key, message) => new HMAC2(hash3, key).update(message).diges
|
|
|
39588
39194
|
hmac2.create = (hash3, key) => new HMAC2(hash3, key);
|
|
39589
39195
|
|
|
39590
39196
|
// ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/abstract/utils.js
|
|
39591
|
-
var
|
|
39592
|
-
__export(
|
|
39197
|
+
var utils_exports2 = {};
|
|
39198
|
+
__export(utils_exports2, {
|
|
39593
39199
|
abytes: () => abytes4,
|
|
39594
39200
|
bitGet: () => bitGet2,
|
|
39595
39201
|
bitLen: () => bitLen3,
|
|
@@ -40231,7 +39837,7 @@ function validatePointOpts2(curve) {
|
|
|
40231
39837
|
}
|
|
40232
39838
|
return Object.freeze({ ...opts });
|
|
40233
39839
|
}
|
|
40234
|
-
var { bytesToNumberBE: b2n, hexToBytes: h2b } =
|
|
39840
|
+
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports2;
|
|
40235
39841
|
var DER3 = {
|
|
40236
39842
|
// asn.1 DER encoding utils
|
|
40237
39843
|
Err: class DERErr3 extends Error {
|
|
@@ -41011,8 +40617,8 @@ function getHash2(hash3) {
|
|
|
41011
40617
|
};
|
|
41012
40618
|
}
|
|
41013
40619
|
function createCurve2(curveDef, defHash) {
|
|
41014
|
-
const
|
|
41015
|
-
return Object.freeze({ ...
|
|
40620
|
+
const create = (hash3) => weierstrass3({ ...curveDef, ...getHash2(hash3) });
|
|
40621
|
+
return Object.freeze({ ...create(defHash), create });
|
|
41016
40622
|
}
|
|
41017
40623
|
|
|
41018
40624
|
// ../../node_modules/.pnpm/@noble+curves@1.4.2/node_modules/@noble/curves/esm/secp256k1.js
|
|
@@ -41456,11 +41062,11 @@ function concatBytes8(...arrays) {
|
|
|
41456
41062
|
function utf8ToBytes5(utf) {
|
|
41457
41063
|
return new TextEncoder().encode(utf);
|
|
41458
41064
|
}
|
|
41459
|
-
function numberToHex4(
|
|
41460
|
-
if (
|
|
41065
|
+
function numberToHex4(integer) {
|
|
41066
|
+
if (integer < 0) {
|
|
41461
41067
|
throw new Error("Invalid integer as argument, must be unsigned!");
|
|
41462
41068
|
}
|
|
41463
|
-
const hex =
|
|
41069
|
+
const hex = integer.toString(16);
|
|
41464
41070
|
return hex.length % 2 ? `0${hex}` : hex;
|
|
41465
41071
|
}
|
|
41466
41072
|
function padToEven4(a) {
|
|
@@ -42019,11 +41625,11 @@ var LRUCache2 = class _LRUCache {
|
|
|
42019
41625
|
free: c.#free,
|
|
42020
41626
|
// methods
|
|
42021
41627
|
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
42022
|
-
backgroundFetch: (k,
|
|
42023
|
-
moveToTail: (
|
|
41628
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
41629
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
42024
41630
|
indexes: (options) => c.#indexes(options),
|
|
42025
41631
|
rindexes: (options) => c.#rindexes(options),
|
|
42026
|
-
isStale: (
|
|
41632
|
+
isStale: (index) => c.#isStale(index)
|
|
42027
41633
|
};
|
|
42028
41634
|
}
|
|
42029
41635
|
// Protected read-only members
|
|
@@ -42170,13 +41776,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42170
41776
|
const starts = new ZeroArray2(this.#max);
|
|
42171
41777
|
this.#ttls = ttls;
|
|
42172
41778
|
this.#starts = starts;
|
|
42173
|
-
this.#setItemTTL = (
|
|
42174
|
-
starts[
|
|
42175
|
-
ttls[
|
|
41779
|
+
this.#setItemTTL = (index, ttl, start = perf2.now()) => {
|
|
41780
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
41781
|
+
ttls[index] = ttl;
|
|
42176
41782
|
if (ttl !== 0 && this.ttlAutopurge) {
|
|
42177
41783
|
const t = setTimeout(() => {
|
|
42178
|
-
if (this.#isStale(
|
|
42179
|
-
this.delete(this.#keyList[
|
|
41784
|
+
if (this.#isStale(index)) {
|
|
41785
|
+
this.delete(this.#keyList[index]);
|
|
42180
41786
|
}
|
|
42181
41787
|
}, ttl + 1);
|
|
42182
41788
|
if (t.unref) {
|
|
@@ -42184,13 +41790,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42184
41790
|
}
|
|
42185
41791
|
}
|
|
42186
41792
|
};
|
|
42187
|
-
this.#updateItemAge = (
|
|
42188
|
-
starts[
|
|
41793
|
+
this.#updateItemAge = (index) => {
|
|
41794
|
+
starts[index] = ttls[index] !== 0 ? perf2.now() : 0;
|
|
42189
41795
|
};
|
|
42190
|
-
this.#statusTTL = (status,
|
|
42191
|
-
if (ttls[
|
|
42192
|
-
const ttl = ttls[
|
|
42193
|
-
const start = starts[
|
|
41796
|
+
this.#statusTTL = (status, index) => {
|
|
41797
|
+
if (ttls[index]) {
|
|
41798
|
+
const ttl = ttls[index];
|
|
41799
|
+
const start = starts[index];
|
|
42194
41800
|
if (!ttl || !start)
|
|
42195
41801
|
return;
|
|
42196
41802
|
status.ttl = ttl;
|
|
@@ -42213,21 +41819,21 @@ var LRUCache2 = class _LRUCache {
|
|
|
42213
41819
|
return n;
|
|
42214
41820
|
};
|
|
42215
41821
|
this.getRemainingTTL = (key) => {
|
|
42216
|
-
const
|
|
42217
|
-
if (
|
|
41822
|
+
const index = this.#keyMap.get(key);
|
|
41823
|
+
if (index === void 0) {
|
|
42218
41824
|
return 0;
|
|
42219
41825
|
}
|
|
42220
|
-
const ttl = ttls[
|
|
42221
|
-
const start = starts[
|
|
41826
|
+
const ttl = ttls[index];
|
|
41827
|
+
const start = starts[index];
|
|
42222
41828
|
if (!ttl || !start) {
|
|
42223
41829
|
return Infinity;
|
|
42224
41830
|
}
|
|
42225
41831
|
const age = (cachedNow || getNow()) - start;
|
|
42226
41832
|
return ttl - age;
|
|
42227
41833
|
};
|
|
42228
|
-
this.#isStale = (
|
|
42229
|
-
const s = starts[
|
|
42230
|
-
const t = ttls[
|
|
41834
|
+
this.#isStale = (index) => {
|
|
41835
|
+
const s = starts[index];
|
|
41836
|
+
const t = ttls[index];
|
|
42231
41837
|
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
42232
41838
|
};
|
|
42233
41839
|
}
|
|
@@ -42244,9 +41850,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42244
41850
|
const sizes = new ZeroArray2(this.#max);
|
|
42245
41851
|
this.#calculatedSize = 0;
|
|
42246
41852
|
this.#sizes = sizes;
|
|
42247
|
-
this.#removeItemSize = (
|
|
42248
|
-
this.#calculatedSize -= sizes[
|
|
42249
|
-
sizes[
|
|
41853
|
+
this.#removeItemSize = (index) => {
|
|
41854
|
+
this.#calculatedSize -= sizes[index];
|
|
41855
|
+
sizes[index] = 0;
|
|
42250
41856
|
};
|
|
42251
41857
|
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
42252
41858
|
if (this.#isBackgroundFetch(v)) {
|
|
@@ -42267,15 +41873,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42267
41873
|
}
|
|
42268
41874
|
return size;
|
|
42269
41875
|
};
|
|
42270
|
-
this.#addItemSize = (
|
|
42271
|
-
sizes[
|
|
41876
|
+
this.#addItemSize = (index, size, status) => {
|
|
41877
|
+
sizes[index] = size;
|
|
42272
41878
|
if (this.#maxSize) {
|
|
42273
|
-
const maxSize2 = this.#maxSize - sizes[
|
|
41879
|
+
const maxSize2 = this.#maxSize - sizes[index];
|
|
42274
41880
|
while (this.#calculatedSize > maxSize2) {
|
|
42275
41881
|
this.#evict(true);
|
|
42276
41882
|
}
|
|
42277
41883
|
}
|
|
42278
|
-
this.#calculatedSize += sizes[
|
|
41884
|
+
this.#calculatedSize += sizes[index];
|
|
42279
41885
|
if (status) {
|
|
42280
41886
|
status.entrySize = size;
|
|
42281
41887
|
status.totalCalculatedSize = this.#calculatedSize;
|
|
@@ -42326,8 +41932,8 @@ var LRUCache2 = class _LRUCache {
|
|
|
42326
41932
|
}
|
|
42327
41933
|
}
|
|
42328
41934
|
}
|
|
42329
|
-
#isValidIndex(
|
|
42330
|
-
return
|
|
41935
|
+
#isValidIndex(index) {
|
|
41936
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
42331
41937
|
}
|
|
42332
41938
|
/**
|
|
42333
41939
|
* Return a generator yielding `[key, value]` pairs,
|
|
@@ -42560,23 +42166,23 @@ var LRUCache2 = class _LRUCache {
|
|
|
42560
42166
|
this.delete(k);
|
|
42561
42167
|
return this;
|
|
42562
42168
|
}
|
|
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 =
|
|
42169
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
42170
|
+
if (index === void 0) {
|
|
42171
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
42172
|
+
this.#keyList[index] = k;
|
|
42173
|
+
this.#valList[index] = v;
|
|
42174
|
+
this.#keyMap.set(k, index);
|
|
42175
|
+
this.#next[this.#tail] = index;
|
|
42176
|
+
this.#prev[index] = this.#tail;
|
|
42177
|
+
this.#tail = index;
|
|
42572
42178
|
this.#size++;
|
|
42573
|
-
this.#addItemSize(
|
|
42179
|
+
this.#addItemSize(index, size, status);
|
|
42574
42180
|
if (status)
|
|
42575
42181
|
status.set = "add";
|
|
42576
42182
|
noUpdateTTL = false;
|
|
42577
42183
|
} else {
|
|
42578
|
-
this.#moveToTail(
|
|
42579
|
-
const oldVal = this.#valList[
|
|
42184
|
+
this.#moveToTail(index);
|
|
42185
|
+
const oldVal = this.#valList[index];
|
|
42580
42186
|
if (v !== oldVal) {
|
|
42581
42187
|
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
42582
42188
|
oldVal.__abortController.abort(new Error("replaced"));
|
|
@@ -42597,9 +42203,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42597
42203
|
this.#disposed?.push([oldVal, k, "set"]);
|
|
42598
42204
|
}
|
|
42599
42205
|
}
|
|
42600
|
-
this.#removeItemSize(
|
|
42601
|
-
this.#addItemSize(
|
|
42602
|
-
this.#valList[
|
|
42206
|
+
this.#removeItemSize(index);
|
|
42207
|
+
this.#addItemSize(index, size, status);
|
|
42208
|
+
this.#valList[index] = v;
|
|
42603
42209
|
if (status) {
|
|
42604
42210
|
status.set = "replace";
|
|
42605
42211
|
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
@@ -42615,10 +42221,10 @@ var LRUCache2 = class _LRUCache {
|
|
|
42615
42221
|
}
|
|
42616
42222
|
if (this.#ttls) {
|
|
42617
42223
|
if (!noUpdateTTL) {
|
|
42618
|
-
this.#setItemTTL(
|
|
42224
|
+
this.#setItemTTL(index, ttl, start);
|
|
42619
42225
|
}
|
|
42620
42226
|
if (status)
|
|
42621
|
-
this.#statusTTL(status,
|
|
42227
|
+
this.#statusTTL(status, index);
|
|
42622
42228
|
}
|
|
42623
42229
|
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
42624
42230
|
const dt = this.#disposed;
|
|
@@ -42696,24 +42302,24 @@ var LRUCache2 = class _LRUCache {
|
|
|
42696
42302
|
*/
|
|
42697
42303
|
has(k, hasOptions = {}) {
|
|
42698
42304
|
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
42699
|
-
const
|
|
42700
|
-
if (
|
|
42701
|
-
const v = this.#valList[
|
|
42305
|
+
const index = this.#keyMap.get(k);
|
|
42306
|
+
if (index !== void 0) {
|
|
42307
|
+
const v = this.#valList[index];
|
|
42702
42308
|
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
42703
42309
|
return false;
|
|
42704
42310
|
}
|
|
42705
|
-
if (!this.#isStale(
|
|
42311
|
+
if (!this.#isStale(index)) {
|
|
42706
42312
|
if (updateAgeOnHas) {
|
|
42707
|
-
this.#updateItemAge(
|
|
42313
|
+
this.#updateItemAge(index);
|
|
42708
42314
|
}
|
|
42709
42315
|
if (status) {
|
|
42710
42316
|
status.has = "hit";
|
|
42711
|
-
this.#statusTTL(status,
|
|
42317
|
+
this.#statusTTL(status, index);
|
|
42712
42318
|
}
|
|
42713
42319
|
return true;
|
|
42714
42320
|
} else if (status) {
|
|
42715
42321
|
status.has = "stale";
|
|
42716
|
-
this.#statusTTL(status,
|
|
42322
|
+
this.#statusTTL(status, index);
|
|
42717
42323
|
}
|
|
42718
42324
|
} else if (status) {
|
|
42719
42325
|
status.has = "miss";
|
|
@@ -42729,15 +42335,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42729
42335
|
*/
|
|
42730
42336
|
peek(k, peekOptions = {}) {
|
|
42731
42337
|
const { allowStale = this.allowStale } = peekOptions;
|
|
42732
|
-
const
|
|
42733
|
-
if (
|
|
42338
|
+
const index = this.#keyMap.get(k);
|
|
42339
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
42734
42340
|
return;
|
|
42735
42341
|
}
|
|
42736
|
-
const v = this.#valList[
|
|
42342
|
+
const v = this.#valList[index];
|
|
42737
42343
|
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
42738
42344
|
}
|
|
42739
|
-
#backgroundFetch(k,
|
|
42740
|
-
const v =
|
|
42345
|
+
#backgroundFetch(k, index, options, context) {
|
|
42346
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
42741
42347
|
if (this.#isBackgroundFetch(v)) {
|
|
42742
42348
|
return v;
|
|
42743
42349
|
}
|
|
@@ -42768,10 +42374,10 @@ var LRUCache2 = class _LRUCache {
|
|
|
42768
42374
|
return fetchFail(ac.signal.reason);
|
|
42769
42375
|
}
|
|
42770
42376
|
const bf2 = p;
|
|
42771
|
-
if (this.#valList[
|
|
42377
|
+
if (this.#valList[index] === p) {
|
|
42772
42378
|
if (v2 === void 0) {
|
|
42773
42379
|
if (bf2.__staleWhileFetching) {
|
|
42774
|
-
this.#valList[
|
|
42380
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
42775
42381
|
} else {
|
|
42776
42382
|
this.delete(k);
|
|
42777
42383
|
}
|
|
@@ -42796,12 +42402,12 @@ var LRUCache2 = class _LRUCache {
|
|
|
42796
42402
|
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
42797
42403
|
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
42798
42404
|
const bf2 = p;
|
|
42799
|
-
if (this.#valList[
|
|
42405
|
+
if (this.#valList[index] === p) {
|
|
42800
42406
|
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
42801
42407
|
if (del) {
|
|
42802
42408
|
this.delete(k);
|
|
42803
42409
|
} else if (!allowStaleAborted) {
|
|
42804
|
-
this.#valList[
|
|
42410
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
42805
42411
|
}
|
|
42806
42412
|
}
|
|
42807
42413
|
if (allowStale) {
|
|
@@ -42835,11 +42441,11 @@ var LRUCache2 = class _LRUCache {
|
|
|
42835
42441
|
__staleWhileFetching: v,
|
|
42836
42442
|
__returned: void 0
|
|
42837
42443
|
});
|
|
42838
|
-
if (
|
|
42444
|
+
if (index === void 0) {
|
|
42839
42445
|
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
42840
|
-
|
|
42446
|
+
index = this.#keyMap.get(k);
|
|
42841
42447
|
} else {
|
|
42842
|
-
this.#valList[
|
|
42448
|
+
this.#valList[index] = bf;
|
|
42843
42449
|
}
|
|
42844
42450
|
return bf;
|
|
42845
42451
|
}
|
|
@@ -42897,14 +42503,14 @@ var LRUCache2 = class _LRUCache {
|
|
|
42897
42503
|
status,
|
|
42898
42504
|
signal
|
|
42899
42505
|
};
|
|
42900
|
-
let
|
|
42901
|
-
if (
|
|
42506
|
+
let index = this.#keyMap.get(k);
|
|
42507
|
+
if (index === void 0) {
|
|
42902
42508
|
if (status)
|
|
42903
42509
|
status.fetch = "miss";
|
|
42904
|
-
const p = this.#backgroundFetch(k,
|
|
42510
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
42905
42511
|
return p.__returned = p;
|
|
42906
42512
|
} else {
|
|
42907
|
-
const v = this.#valList[
|
|
42513
|
+
const v = this.#valList[index];
|
|
42908
42514
|
if (this.#isBackgroundFetch(v)) {
|
|
42909
42515
|
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
42910
42516
|
if (status) {
|
|
@@ -42914,19 +42520,19 @@ var LRUCache2 = class _LRUCache {
|
|
|
42914
42520
|
}
|
|
42915
42521
|
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
42916
42522
|
}
|
|
42917
|
-
const isStale = this.#isStale(
|
|
42523
|
+
const isStale = this.#isStale(index);
|
|
42918
42524
|
if (!forceRefresh && !isStale) {
|
|
42919
42525
|
if (status)
|
|
42920
42526
|
status.fetch = "hit";
|
|
42921
|
-
this.#moveToTail(
|
|
42527
|
+
this.#moveToTail(index);
|
|
42922
42528
|
if (updateAgeOnGet) {
|
|
42923
|
-
this.#updateItemAge(
|
|
42529
|
+
this.#updateItemAge(index);
|
|
42924
42530
|
}
|
|
42925
42531
|
if (status)
|
|
42926
|
-
this.#statusTTL(status,
|
|
42532
|
+
this.#statusTTL(status, index);
|
|
42927
42533
|
return v;
|
|
42928
42534
|
}
|
|
42929
|
-
const p = this.#backgroundFetch(k,
|
|
42535
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
42930
42536
|
const hasStale = p.__staleWhileFetching !== void 0;
|
|
42931
42537
|
const staleVal = hasStale && allowStale;
|
|
42932
42538
|
if (status) {
|
|
@@ -42945,13 +42551,13 @@ var LRUCache2 = class _LRUCache {
|
|
|
42945
42551
|
*/
|
|
42946
42552
|
get(k, getOptions = {}) {
|
|
42947
42553
|
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
42948
|
-
const
|
|
42949
|
-
if (
|
|
42950
|
-
const value = this.#valList[
|
|
42554
|
+
const index = this.#keyMap.get(k);
|
|
42555
|
+
if (index !== void 0) {
|
|
42556
|
+
const value = this.#valList[index];
|
|
42951
42557
|
const fetching = this.#isBackgroundFetch(value);
|
|
42952
42558
|
if (status)
|
|
42953
|
-
this.#statusTTL(status,
|
|
42954
|
-
if (this.#isStale(
|
|
42559
|
+
this.#statusTTL(status, index);
|
|
42560
|
+
if (this.#isStale(index)) {
|
|
42955
42561
|
if (status)
|
|
42956
42562
|
status.get = "stale";
|
|
42957
42563
|
if (!fetching) {
|
|
@@ -42973,9 +42579,9 @@ var LRUCache2 = class _LRUCache {
|
|
|
42973
42579
|
if (fetching) {
|
|
42974
42580
|
return value.__staleWhileFetching;
|
|
42975
42581
|
}
|
|
42976
|
-
this.#moveToTail(
|
|
42582
|
+
this.#moveToTail(index);
|
|
42977
42583
|
if (updateAgeOnGet) {
|
|
42978
|
-
this.#updateItemAge(
|
|
42584
|
+
this.#updateItemAge(index);
|
|
42979
42585
|
}
|
|
42980
42586
|
return value;
|
|
42981
42587
|
}
|
|
@@ -42987,15 +42593,15 @@ var LRUCache2 = class _LRUCache {
|
|
|
42987
42593
|
this.#prev[n] = p;
|
|
42988
42594
|
this.#next[p] = n;
|
|
42989
42595
|
}
|
|
42990
|
-
#moveToTail(
|
|
42991
|
-
if (
|
|
42992
|
-
if (
|
|
42993
|
-
this.#head = this.#next[
|
|
42596
|
+
#moveToTail(index) {
|
|
42597
|
+
if (index !== this.#tail) {
|
|
42598
|
+
if (index === this.#head) {
|
|
42599
|
+
this.#head = this.#next[index];
|
|
42994
42600
|
} else {
|
|
42995
|
-
this.#connect(this.#prev[
|
|
42601
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
42996
42602
|
}
|
|
42997
|
-
this.#connect(this.#tail,
|
|
42998
|
-
this.#tail =
|
|
42603
|
+
this.#connect(this.#tail, index);
|
|
42604
|
+
this.#tail = index;
|
|
42999
42605
|
}
|
|
43000
42606
|
}
|
|
43001
42607
|
/**
|
|
@@ -43005,14 +42611,14 @@ var LRUCache2 = class _LRUCache {
|
|
|
43005
42611
|
delete(k) {
|
|
43006
42612
|
let deleted = false;
|
|
43007
42613
|
if (this.#size !== 0) {
|
|
43008
|
-
const
|
|
43009
|
-
if (
|
|
42614
|
+
const index = this.#keyMap.get(k);
|
|
42615
|
+
if (index !== void 0) {
|
|
43010
42616
|
deleted = true;
|
|
43011
42617
|
if (this.#size === 1) {
|
|
43012
42618
|
this.clear();
|
|
43013
42619
|
} else {
|
|
43014
|
-
this.#removeItemSize(
|
|
43015
|
-
const v = this.#valList[
|
|
42620
|
+
this.#removeItemSize(index);
|
|
42621
|
+
const v = this.#valList[index];
|
|
43016
42622
|
if (this.#isBackgroundFetch(v)) {
|
|
43017
42623
|
v.__abortController.abort(new Error("deleted"));
|
|
43018
42624
|
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
@@ -43024,20 +42630,20 @@ var LRUCache2 = class _LRUCache {
|
|
|
43024
42630
|
}
|
|
43025
42631
|
}
|
|
43026
42632
|
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[
|
|
42633
|
+
this.#keyList[index] = void 0;
|
|
42634
|
+
this.#valList[index] = void 0;
|
|
42635
|
+
if (index === this.#tail) {
|
|
42636
|
+
this.#tail = this.#prev[index];
|
|
42637
|
+
} else if (index === this.#head) {
|
|
42638
|
+
this.#head = this.#next[index];
|
|
43033
42639
|
} else {
|
|
43034
|
-
const pi = this.#prev[
|
|
43035
|
-
this.#next[pi] = this.#next[
|
|
43036
|
-
const ni = this.#next[
|
|
43037
|
-
this.#prev[ni] = this.#prev[
|
|
42640
|
+
const pi = this.#prev[index];
|
|
42641
|
+
this.#next[pi] = this.#next[index];
|
|
42642
|
+
const ni = this.#next[index];
|
|
42643
|
+
this.#prev[ni] = this.#prev[index];
|
|
43038
42644
|
}
|
|
43039
42645
|
this.#size--;
|
|
43040
|
-
this.#free.push(
|
|
42646
|
+
this.#free.push(index);
|
|
43041
42647
|
}
|
|
43042
42648
|
}
|
|
43043
42649
|
}
|
|
@@ -43054,12 +42660,12 @@ var LRUCache2 = class _LRUCache {
|
|
|
43054
42660
|
* Clear the cache entirely, throwing away all values.
|
|
43055
42661
|
*/
|
|
43056
42662
|
clear() {
|
|
43057
|
-
for (const
|
|
43058
|
-
const v = this.#valList[
|
|
42663
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
42664
|
+
const v = this.#valList[index];
|
|
43059
42665
|
if (this.#isBackgroundFetch(v)) {
|
|
43060
42666
|
v.__abortController.abort(new Error("deleted"));
|
|
43061
42667
|
} else {
|
|
43062
|
-
const k = this.#keyList[
|
|
42668
|
+
const k = this.#keyList[index];
|
|
43063
42669
|
if (this.#hasDispose) {
|
|
43064
42670
|
this.#dispose?.(v, k, "delete");
|
|
43065
42671
|
}
|
|
@@ -43197,9 +42803,9 @@ var CheckpointDB4 = class _CheckpointDB {
|
|
|
43197
42803
|
return value2;
|
|
43198
42804
|
}
|
|
43199
42805
|
}
|
|
43200
|
-
for (let
|
|
43201
|
-
if (this.checkpoints[
|
|
43202
|
-
return this.checkpoints[
|
|
42806
|
+
for (let index = this.checkpoints.length - 1; index >= 0; index--) {
|
|
42807
|
+
if (this.checkpoints[index].keyValueMap.has(keyHex)) {
|
|
42808
|
+
return this.checkpoints[index].keyValueMap.get(keyHex);
|
|
43203
42809
|
}
|
|
43204
42810
|
}
|
|
43205
42811
|
const value = await this.db.get(keyHex, {
|
|
@@ -45271,7 +44877,7 @@ function valuesArrayToHeaderData2(values) {
|
|
|
45271
44877
|
number2,
|
|
45272
44878
|
gasLimit,
|
|
45273
44879
|
gasUsed,
|
|
45274
|
-
|
|
44880
|
+
timestamp,
|
|
45275
44881
|
extraData,
|
|
45276
44882
|
mixHash,
|
|
45277
44883
|
nonce,
|
|
@@ -45300,7 +44906,7 @@ function valuesArrayToHeaderData2(values) {
|
|
|
45300
44906
|
...number2 !== void 0 ? { number: number2 } : {},
|
|
45301
44907
|
...gasLimit !== void 0 ? { gasLimit } : {},
|
|
45302
44908
|
...gasUsed !== void 0 ? { gasUsed } : {},
|
|
45303
|
-
...
|
|
44909
|
+
...timestamp !== void 0 ? { timestamp } : {},
|
|
45304
44910
|
...extraData !== void 0 ? { extraData } : {},
|
|
45305
44911
|
...mixHash !== void 0 ? { mixHash } : {},
|
|
45306
44912
|
...nonce !== void 0 ? { nonce } : {},
|
|
@@ -45461,7 +45067,7 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45461
45067
|
const number2 = safeToType(headerData.number, 1) ?? defaults2.number;
|
|
45462
45068
|
const gasLimit = safeToType(headerData.gasLimit, 1) ?? defaults2.gasLimit;
|
|
45463
45069
|
const gasUsed = safeToType(headerData.gasUsed, 1) ?? defaults2.gasUsed;
|
|
45464
|
-
const
|
|
45070
|
+
const timestamp = safeToType(headerData.timestamp, 1) ?? defaults2.timestamp;
|
|
45465
45071
|
const extraData = safeToType(headerData.extraData, 2) ?? defaults2.extraData;
|
|
45466
45072
|
const mixHash = safeToType(headerData.mixHash, 2) ?? defaults2.mixHash;
|
|
45467
45073
|
const nonce = safeToType(headerData.nonce, 2) ?? defaults2.nonce;
|
|
@@ -45469,12 +45075,12 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45469
45075
|
if (setHardfork === true) {
|
|
45470
45076
|
this.common.ethjsCommon.setHardforkBy({
|
|
45471
45077
|
blockNumber: number2,
|
|
45472
|
-
timestamp
|
|
45078
|
+
timestamp
|
|
45473
45079
|
});
|
|
45474
45080
|
} else if (typeof setHardfork !== "boolean") {
|
|
45475
45081
|
this.common.ethjsCommon.setHardforkBy({
|
|
45476
45082
|
blockNumber: number2,
|
|
45477
|
-
timestamp
|
|
45083
|
+
timestamp
|
|
45478
45084
|
});
|
|
45479
45085
|
}
|
|
45480
45086
|
const hardforkDefaults = {
|
|
@@ -45522,7 +45128,7 @@ var BlockHeader2 = class _BlockHeader {
|
|
|
45522
45128
|
this.number = number2;
|
|
45523
45129
|
this.gasLimit = gasLimit;
|
|
45524
45130
|
this.gasUsed = gasUsed;
|
|
45525
|
-
this.timestamp =
|
|
45131
|
+
this.timestamp = timestamp;
|
|
45526
45132
|
this.extraData = extraData;
|
|
45527
45133
|
this.mixHash = mixHash;
|
|
45528
45134
|
this.nonce = nonce;
|
|
@@ -46285,8 +45891,8 @@ var Block2 = class _Block {
|
|
|
46285
45891
|
for (const uncleHeaderData of uhsData ?? []) {
|
|
46286
45892
|
uncleHeaders.push(BlockHeader2.fromValuesArray(uncleHeaderData, uncleOpts));
|
|
46287
45893
|
}
|
|
46288
|
-
const withdrawals = withdrawalBytes?.map(([
|
|
46289
|
-
index
|
|
45894
|
+
const withdrawals = withdrawalBytes?.map(([index, validatorIndex, address, amount]) => ({
|
|
45895
|
+
index,
|
|
46290
45896
|
validatorIndex,
|
|
46291
45897
|
address,
|
|
46292
45898
|
amount
|
|
@@ -46325,14 +45931,14 @@ var Block2 = class _Block {
|
|
|
46325
45931
|
executionWitness
|
|
46326
45932
|
} = payload;
|
|
46327
45933
|
const txs = [];
|
|
46328
|
-
for (const [
|
|
45934
|
+
for (const [index, serializedTx] of transactions.entries()) {
|
|
46329
45935
|
try {
|
|
46330
45936
|
const tx = createTxFromRLP(hexToBytes$2(serializedTx), {
|
|
46331
45937
|
common: opts?.common.ethjsCommon
|
|
46332
45938
|
});
|
|
46333
45939
|
txs.push(tx);
|
|
46334
45940
|
} catch (error) {
|
|
46335
|
-
const validationError2 = `Invalid tx at index ${
|
|
45941
|
+
const validationError2 = `Invalid tx at index ${index}: ${error}`;
|
|
46336
45942
|
throw validationError2;
|
|
46337
45943
|
}
|
|
46338
45944
|
}
|
|
@@ -46582,9 +46188,9 @@ var Block2 = class _Block {
|
|
|
46582
46188
|
return;
|
|
46583
46189
|
}
|
|
46584
46190
|
if (verifyTxs) {
|
|
46585
|
-
for (const [
|
|
46191
|
+
for (const [index, tx] of this.transactions.entries()) {
|
|
46586
46192
|
if (!tx.isSigned()) {
|
|
46587
|
-
const msg = this._errorMsg(`invalid transactions: transaction at index ${
|
|
46193
|
+
const msg = this._errorMsg(`invalid transactions: transaction at index ${index} is unsigned`);
|
|
46588
46194
|
throw new Error(msg);
|
|
46589
46195
|
}
|
|
46590
46196
|
}
|
|
@@ -46810,7 +46416,7 @@ function blockHeaderFromRpc(blockParams, options) {
|
|
|
46810
46416
|
number: number2,
|
|
46811
46417
|
gasLimit,
|
|
46812
46418
|
gasUsed,
|
|
46813
|
-
timestamp
|
|
46419
|
+
timestamp,
|
|
46814
46420
|
extraData,
|
|
46815
46421
|
mixHash,
|
|
46816
46422
|
nonce,
|
|
@@ -46834,7 +46440,7 @@ function blockHeaderFromRpc(blockParams, options) {
|
|
|
46834
46440
|
number: number2,
|
|
46835
46441
|
gasLimit,
|
|
46836
46442
|
gasUsed,
|
|
46837
|
-
timestamp
|
|
46443
|
+
timestamp,
|
|
46838
46444
|
extraData,
|
|
46839
46445
|
mixHash,
|
|
46840
46446
|
nonce,
|
|
@@ -47397,11 +47003,11 @@ var Evm = class _Evm extends EVM {
|
|
|
47397
47003
|
"Custom precompiles is empty. This is an internal bug as it should always be defined"
|
|
47398
47004
|
);
|
|
47399
47005
|
}
|
|
47400
|
-
const
|
|
47401
|
-
if (
|
|
47006
|
+
const index = this._customPrecompiles.indexOf(precompile);
|
|
47007
|
+
if (index === -1) {
|
|
47402
47008
|
throw new InvalidParamsError("Precompile not found");
|
|
47403
47009
|
}
|
|
47404
|
-
this._customPrecompiles.splice(
|
|
47010
|
+
this._customPrecompiles.splice(index, 1);
|
|
47405
47011
|
this._precompiles = getActivePrecompiles(this.common, this._customPrecompiles);
|
|
47406
47012
|
}
|
|
47407
47013
|
/**
|
|
@@ -47656,8 +47262,8 @@ var ReceiptsManager = class _ReceiptsManager {
|
|
|
47656
47262
|
const block = value;
|
|
47657
47263
|
if (operation === 0) {
|
|
47658
47264
|
for (const [i, tx] of block.transactions.entries()) {
|
|
47659
|
-
const
|
|
47660
|
-
const encoded = this.rlp(0, 2,
|
|
47265
|
+
const index = [block.hash(), i];
|
|
47266
|
+
const encoded = this.rlp(0, 2, index);
|
|
47661
47267
|
await this.mapDb.put("TxHash", tx.hash(), encoded);
|
|
47662
47268
|
}
|
|
47663
47269
|
} else if (operation === 1) {
|
|
@@ -49344,12 +48950,12 @@ createBlockHeader();
|
|
|
49344
48950
|
|
|
49345
48951
|
// ../../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
48952
|
var parentBeaconBlockRootAddress2 = createAddressFromString("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02");
|
|
49347
|
-
var accumulateParentBeaconBlockRoot2 = (vm) => async (root2,
|
|
48953
|
+
var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp) => {
|
|
49348
48954
|
if (!vm.common.ethjsCommon.isActivatedEIP(4788)) {
|
|
49349
48955
|
throw new EipNotEnabledError("Cannot call `accumulateParentBeaconBlockRoot`: EIP 4788 is not active");
|
|
49350
48956
|
}
|
|
49351
48957
|
const historicalRootsLength = 8191n;
|
|
49352
|
-
const timestampIndex =
|
|
48958
|
+
const timestampIndex = timestamp % historicalRootsLength;
|
|
49353
48959
|
const timestampExtended = timestampIndex + historicalRootsLength;
|
|
49354
48960
|
if (await vm.stateManager.getAccount(parentBeaconBlockRootAddress2) === void 0) {
|
|
49355
48961
|
await vm.evm.journal.putAccount(parentBeaconBlockRootAddress2, new Account());
|
|
@@ -49357,7 +48963,7 @@ var accumulateParentBeaconBlockRoot2 = (vm) => async (root2, timestamp2) => {
|
|
|
49357
48963
|
await vm.stateManager.putStorage(
|
|
49358
48964
|
parentBeaconBlockRootAddress2,
|
|
49359
48965
|
setLengthLeft(toBytes$1(timestampIndex), 32),
|
|
49360
|
-
toBytes$1(
|
|
48966
|
+
toBytes$1(timestamp)
|
|
49361
48967
|
);
|
|
49362
48968
|
await vm.stateManager.putStorage(parentBeaconBlockRootAddress2, setLengthLeft(toBytes$1(timestampExtended), 32), root2);
|
|
49363
48969
|
};
|
|
@@ -50406,7 +50012,7 @@ var BlockBuilder2 = class {
|
|
|
50406
50012
|
const receiptTrie = await this.receiptTrie();
|
|
50407
50013
|
const logsBloom = this.logsBloom();
|
|
50408
50014
|
const gasUsed = this.gasUsed;
|
|
50409
|
-
const
|
|
50015
|
+
const timestamp = this.headerData.timestamp ?? 0n;
|
|
50410
50016
|
let blobGasUsed = void 0;
|
|
50411
50017
|
if (this.vm.common.ethjsCommon.isActivatedEIP(4844) === true) {
|
|
50412
50018
|
blobGasUsed = this.blobGasUsed;
|
|
@@ -50420,7 +50026,7 @@ var BlockBuilder2 = class {
|
|
|
50420
50026
|
receiptTrie,
|
|
50421
50027
|
logsBloom,
|
|
50422
50028
|
gasUsed,
|
|
50423
|
-
timestamp
|
|
50029
|
+
timestamp
|
|
50424
50030
|
// correct excessBlobGas should already be part of headerData used above
|
|
50425
50031
|
};
|
|
50426
50032
|
if (consensusType === ConsensusType.ProofOfWork) {
|
|
@@ -50449,8 +50055,8 @@ var BlockBuilder2 = class {
|
|
|
50449
50055
|
await this.vm.evm.journal.checkpoint();
|
|
50450
50056
|
this.checkpointed = true;
|
|
50451
50057
|
}
|
|
50452
|
-
const { parentBeaconBlockRoot, timestamp
|
|
50453
|
-
const timestampValue =
|
|
50058
|
+
const { parentBeaconBlockRoot, timestamp } = this.headerData;
|
|
50059
|
+
const timestampValue = timestamp ?? 0n;
|
|
50454
50060
|
const timestampBigInt = toType(timestampValue, TypeOutput.BigInt) ?? 0n;
|
|
50455
50061
|
const parentBeaconBlockRootBuf = parentBeaconBlockRoot ? toType(parentBeaconBlockRoot, TypeOutput.Uint8Array) : new Uint8Array(32);
|
|
50456
50062
|
await accumulateParentBeaconBlockRoot2(this.vm)(
|
|
@@ -50858,9 +50464,9 @@ var createTevmNode = (options = {}) => {
|
|
|
50858
50464
|
removeListener(eventName, listener) {
|
|
50859
50465
|
const listeners = events.get(eventName);
|
|
50860
50466
|
if (listeners) {
|
|
50861
|
-
const
|
|
50862
|
-
if (
|
|
50863
|
-
listeners.splice(
|
|
50467
|
+
const index = listeners.findIndex((l) => l === listener);
|
|
50468
|
+
if (index !== -1) {
|
|
50469
|
+
listeners.splice(index, 1);
|
|
50864
50470
|
if (listeners.length === 0) {
|
|
50865
50471
|
events.delete(eventName);
|
|
50866
50472
|
}
|
|
@@ -51692,12 +51298,12 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51692
51298
|
const receiptsManager = await client.getReceiptsManager();
|
|
51693
51299
|
for (let count = 0; count < blockCount; count++) {
|
|
51694
51300
|
const parentBlock = await vm.blockchain.getCanonicalHeadBlock();
|
|
51695
|
-
let
|
|
51696
|
-
|
|
51301
|
+
let timestamp = Math.max(Math.floor(Date.now() / 1e3), Number(parentBlock.header.timestamp));
|
|
51302
|
+
timestamp = count === 0 ? timestamp : timestamp + interval;
|
|
51697
51303
|
const blockBuilder = await vm.buildBlock({
|
|
51698
51304
|
parentBlock,
|
|
51699
51305
|
headerData: {
|
|
51700
|
-
timestamp
|
|
51306
|
+
timestamp,
|
|
51701
51307
|
number: parentBlock.header.number + 1n,
|
|
51702
51308
|
// The following 2 are currently not supported
|
|
51703
51309
|
// difficulty: undefined,
|
|
@@ -51726,13 +51332,13 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51726
51332
|
] : await pool.txsByPriceAndNonce({
|
|
51727
51333
|
baseFee: parentBlock.header.calcNextBaseFee()
|
|
51728
51334
|
});
|
|
51729
|
-
let
|
|
51335
|
+
let index = 0;
|
|
51730
51336
|
const blockFull = false;
|
|
51731
51337
|
const receipts = [];
|
|
51732
|
-
while (
|
|
51338
|
+
while (index < orderedTx.length && !blockFull) {
|
|
51733
51339
|
const nextTx = (
|
|
51734
51340
|
/** @type {import('@tevm/tx').TypedTransaction}*/
|
|
51735
|
-
orderedTx[
|
|
51341
|
+
orderedTx[index]
|
|
51736
51342
|
);
|
|
51737
51343
|
client.logger.debug(bytesToHex$2(nextTx.hash()), "new tx added");
|
|
51738
51344
|
const txResult = await blockBuilder.addTransaction(nextTx, {
|
|
@@ -51741,7 +51347,7 @@ var mineHandler = (client, options = {}) => async ({ throwOnFail = options.throw
|
|
|
51741
51347
|
skipHardForkValidation: true
|
|
51742
51348
|
});
|
|
51743
51349
|
receipts.push(txResult.receipt);
|
|
51744
|
-
|
|
51350
|
+
index++;
|
|
51745
51351
|
}
|
|
51746
51352
|
await vm.stateManager.checkpoint();
|
|
51747
51353
|
const createNewStateRoot = true;
|
|
@@ -57522,9 +57128,6 @@ function getLogger() {
|
|
|
57522
57128
|
return loggerContext.getStore() ?? defaultLogger();
|
|
57523
57129
|
}
|
|
57524
57130
|
|
|
57525
|
-
// src/index.node.ts
|
|
57526
|
-
__reExport(index_node_exports, OfferDB_exports2);
|
|
57527
|
-
|
|
57528
57131
|
// src/RouterEvent.ts
|
|
57529
57132
|
var RouterEvent_exports = {};
|
|
57530
57133
|
__export(RouterEvent_exports, {
|
|
@@ -57650,14 +57253,14 @@ function morpho(parameters) {
|
|
|
57650
57253
|
);
|
|
57651
57254
|
const buyOffersEmptyCallback = batch2(
|
|
57652
57255
|
"buy_offers_empty_callback",
|
|
57653
|
-
async (
|
|
57256
|
+
async (offers, { publicClients }) => {
|
|
57654
57257
|
const issues = /* @__PURE__ */ new Map();
|
|
57655
57258
|
const hashToIndex = /* @__PURE__ */ new Map();
|
|
57656
|
-
for (let i = 0; i <
|
|
57657
|
-
const offer =
|
|
57259
|
+
for (let i = 0; i < offers.length; i++) {
|
|
57260
|
+
const offer = offers[i];
|
|
57658
57261
|
hashToIndex.set(offer.hash, i);
|
|
57659
57262
|
}
|
|
57660
|
-
const { buyOffers, sellOffers: _sellOffers } =
|
|
57263
|
+
const { buyOffers, sellOffers: _sellOffers } = offers.reduce(
|
|
57661
57264
|
(acc, offer) => {
|
|
57662
57265
|
offer.buy ? acc.buyOffers.push(offer) : issues.set(hashToIndex.get(offer.hash), {
|
|
57663
57266
|
message: "Onchain callback for sell offers is not supported yet."
|
|
@@ -57670,9 +57273,9 @@ function morpho(parameters) {
|
|
|
57670
57273
|
for (const offer of buyOffers) {
|
|
57671
57274
|
const chainName = getChain(offer.chainId)?.name;
|
|
57672
57275
|
const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
|
|
57673
|
-
const
|
|
57674
|
-
|
|
57675
|
-
loanTokens.set(offer.loanToken.toLowerCase(),
|
|
57276
|
+
const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
|
|
57277
|
+
offers2.push(offer);
|
|
57278
|
+
loanTokens.set(offer.loanToken.toLowerCase(), offers2);
|
|
57676
57279
|
buyOffersPerLoanAsset.set(chainName, loanTokens);
|
|
57677
57280
|
}
|
|
57678
57281
|
await Promise.all(
|
|
@@ -57681,8 +57284,8 @@ function morpho(parameters) {
|
|
|
57681
57284
|
const publicClient = publicClients[chainName];
|
|
57682
57285
|
const morpho2 = morphoPerChain.get(chains[chainName].id);
|
|
57683
57286
|
if (!publicClient) {
|
|
57684
|
-
const
|
|
57685
|
-
for (const offer of
|
|
57287
|
+
const offers2 = Array.from(loanTokens.values()).flat();
|
|
57288
|
+
for (const offer of offers2) {
|
|
57686
57289
|
issues.set(hashToIndex.get(offer.hash), {
|
|
57687
57290
|
message: `Public client for chain "${chainName}" is not available`
|
|
57688
57291
|
});
|
|
@@ -57691,9 +57294,9 @@ function morpho(parameters) {
|
|
|
57691
57294
|
}
|
|
57692
57295
|
const balances = /* @__PURE__ */ new Map();
|
|
57693
57296
|
const allowances = /* @__PURE__ */ new Map();
|
|
57694
|
-
for (const [loanToken2,
|
|
57297
|
+
for (const [loanToken2, offers2] of loanTokens) {
|
|
57695
57298
|
const data = await Promise.all(
|
|
57696
|
-
|
|
57299
|
+
offers2.flatMap((offer) => [
|
|
57697
57300
|
publicClient.readContract({
|
|
57698
57301
|
address: loanToken2,
|
|
57699
57302
|
abi: parseAbi$1([
|
|
@@ -57712,8 +57315,8 @@ function morpho(parameters) {
|
|
|
57712
57315
|
})
|
|
57713
57316
|
])
|
|
57714
57317
|
);
|
|
57715
|
-
for (let i = 0; i <
|
|
57716
|
-
const user =
|
|
57318
|
+
for (let i = 0; i < offers2.length; i++) {
|
|
57319
|
+
const user = offers2[i].offering.toLowerCase();
|
|
57717
57320
|
const balance = data[i * 2] || 0n;
|
|
57718
57321
|
const allowance = data[i * 2 + 1] || 0n;
|
|
57719
57322
|
const userBalances = balances.get(user) ?? /* @__PURE__ */ new Map();
|
|
@@ -57790,6 +57393,6 @@ safe-buffer/index.js:
|
|
|
57790
57393
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
57791
57394
|
*/
|
|
57792
57395
|
|
|
57793
|
-
export { apiSchema_exports as ApiSchema, Chain_exports as Chain, EVM_exports as EVM, Logger_exports as Logger,
|
|
57396
|
+
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
57397
|
//# sourceMappingURL=index.node.mjs.map
|
|
57795
57398
|
//# sourceMappingURL=index.node.mjs.map
|