ponder 0.9.3 → 0.9.4
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/bin/ponder.js +527 -485
- package/dist/bin/ponder.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/build/configAndIndexingFunctions.ts +547 -512
- package/src/config/index.ts +4 -4
package/dist/bin/ponder.js
CHANGED
|
@@ -1655,6 +1655,9 @@ var shouldGetTransactionReceipt = (filter) => {
|
|
|
1655
1655
|
return false;
|
|
1656
1656
|
};
|
|
1657
1657
|
|
|
1658
|
+
// src/build/configAndIndexingFunctions.ts
|
|
1659
|
+
import { BlockNotFoundError, hexToNumber as hexToNumber2 } from "viem";
|
|
1660
|
+
|
|
1658
1661
|
// src/utils/offset.ts
|
|
1659
1662
|
import { InvalidAbiDecodingTypeError } from "viem";
|
|
1660
1663
|
function getBytesConsumedByParam(param) {
|
|
@@ -1785,6 +1788,37 @@ async function buildConfigAndIndexingFunctions({
|
|
|
1785
1788
|
rawIndexingFunctions
|
|
1786
1789
|
}) {
|
|
1787
1790
|
const logs = [];
|
|
1791
|
+
const perNetworkLatestBlockNumber = /* @__PURE__ */ new Map();
|
|
1792
|
+
const resolveBlockNumber = async (blockNumberOrTag, network) => {
|
|
1793
|
+
if (blockNumberOrTag === void 0) {
|
|
1794
|
+
return void 0;
|
|
1795
|
+
}
|
|
1796
|
+
if (Number.isNaN(blockNumberOrTag)) {
|
|
1797
|
+
return void 0;
|
|
1798
|
+
}
|
|
1799
|
+
if (blockNumberOrTag === "latest") {
|
|
1800
|
+
if (perNetworkLatestBlockNumber.has(network.name)) {
|
|
1801
|
+
return perNetworkLatestBlockNumber.get(network.name);
|
|
1802
|
+
} else {
|
|
1803
|
+
const blockPromise = network.transport.request({
|
|
1804
|
+
method: "eth_getBlockByNumber",
|
|
1805
|
+
params: ["latest", false]
|
|
1806
|
+
}).then((block) => {
|
|
1807
|
+
if (!block)
|
|
1808
|
+
throw new BlockNotFoundError({ blockNumber: "latest" });
|
|
1809
|
+
return hexToNumber2(block.number);
|
|
1810
|
+
}).catch((e) => {
|
|
1811
|
+
throw new Error(
|
|
1812
|
+
`Unable to fetch "latest" block for network '${network.name}':
|
|
1813
|
+
${e.message}`
|
|
1814
|
+
);
|
|
1815
|
+
});
|
|
1816
|
+
perNetworkLatestBlockNumber.set(network.name, blockPromise);
|
|
1817
|
+
return blockPromise;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
return blockNumberOrTag;
|
|
1821
|
+
};
|
|
1788
1822
|
const networks = await Promise.all(
|
|
1789
1823
|
Object.entries(config.networks).map(async ([networkName, network]) => {
|
|
1790
1824
|
const { chainId, transport } = network;
|
|
@@ -1893,230 +1927,233 @@ async function buildConfigAndIndexingFunctions({
|
|
|
1893
1927
|
`Validation failed: Network for '${source.name}' is null or undefined. Expected one of [${networks.map((n) => `'${n.name}'`).join(", ")}].`
|
|
1894
1928
|
);
|
|
1895
1929
|
}
|
|
1896
|
-
const startBlockMaybeNan = source.startBlock;
|
|
1897
|
-
const startBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
1898
|
-
const endBlockMaybeNan = source.endBlock;
|
|
1899
|
-
const endBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
1900
|
-
if (startBlock !== void 0 && endBlock !== void 0 && endBlock < startBlock) {
|
|
1901
|
-
throw new Error(
|
|
1902
|
-
`Validation failed: Start block for '${source.name}' is after end block (${startBlock} > ${endBlock}).`
|
|
1903
|
-
);
|
|
1904
|
-
}
|
|
1905
1930
|
const network = networks.find((n) => n.name === source.network);
|
|
1906
1931
|
if (!network) {
|
|
1907
1932
|
throw new Error(
|
|
1908
1933
|
`Validation failed: Invalid network for '${source.name}'. Got '${source.network}', expected one of [${networks.map((n) => `'${n.name}'`).join(", ")}].`
|
|
1909
1934
|
);
|
|
1910
1935
|
}
|
|
1936
|
+
const startBlock = await resolveBlockNumber(source.startBlock, network);
|
|
1937
|
+
const endBlock = await resolveBlockNumber(source.endBlock, network);
|
|
1938
|
+
if (startBlock !== void 0 && endBlock !== void 0 && endBlock < startBlock) {
|
|
1939
|
+
throw new Error(
|
|
1940
|
+
`Validation failed: Start block for '${source.name}' is after end block (${startBlock} > ${endBlock}).`
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1911
1943
|
}
|
|
1912
|
-
const contractSources =
|
|
1913
|
-
config.contracts ?? {}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1944
|
+
const contractSources = (await Promise.all(
|
|
1945
|
+
flattenSources(config.contracts ?? {}).map(
|
|
1946
|
+
async (source) => {
|
|
1947
|
+
const network = networks.find((n) => n.name === source.network);
|
|
1948
|
+
const registeredLogEvents = [];
|
|
1949
|
+
const registeredCallTraceEvents = [];
|
|
1950
|
+
for (const eventName of Object.keys(indexingFunctions)) {
|
|
1951
|
+
if (eventName.includes(":")) {
|
|
1952
|
+
const [logContractName, logEventName] = eventName.split(":");
|
|
1953
|
+
if (logContractName === source.name && logEventName !== "setup") {
|
|
1954
|
+
registeredLogEvents.push(logEventName);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
if (eventName.includes(".")) {
|
|
1958
|
+
const [functionContractName, functionName] = eventName.split(
|
|
1959
|
+
"."
|
|
1960
|
+
);
|
|
1961
|
+
if (functionContractName === source.name) {
|
|
1962
|
+
registeredCallTraceEvents.push(functionName);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1923
1965
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
const
|
|
1927
|
-
|
|
1928
|
-
|
|
1966
|
+
const abiEvents = buildAbiEvents({ abi: source.abi });
|
|
1967
|
+
const abiFunctions = buildAbiFunctions({ abi: source.abi });
|
|
1968
|
+
const registeredEventSelectors = [];
|
|
1969
|
+
for (const logEvent of registeredLogEvents) {
|
|
1970
|
+
const abiEvent = abiEvents.bySafeName[logEvent];
|
|
1971
|
+
if (abiEvent === void 0) {
|
|
1972
|
+
throw new Error(
|
|
1973
|
+
`Validation failed: Event name for event '${logEvent}' not found in the contract ABI. Got '${logEvent}', expected one of [${Object.keys(
|
|
1974
|
+
abiEvents.bySafeName
|
|
1975
|
+
).map((eventName) => `'${eventName}'`).join(", ")}].`
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
registeredEventSelectors.push(abiEvent.selector);
|
|
1929
1979
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
const topicsArray = [];
|
|
1959
|
-
if (source.filter !== void 0) {
|
|
1960
|
-
const eventFilters = Array.isArray(source.filter) ? source.filter : [source.filter];
|
|
1961
|
-
for (const filter of eventFilters) {
|
|
1962
|
-
const abiEvent = abiEvents.bySafeName[filter.event];
|
|
1963
|
-
if (!abiEvent) {
|
|
1964
|
-
throw new Error(
|
|
1965
|
-
`Validation failed: Invalid filter for contract '${source.name}'. Got event name '${filter.event}', expected one of [${Object.keys(
|
|
1966
|
-
abiEvents.bySafeName
|
|
1967
|
-
).map((n) => `'${n}'`).join(", ")}].`
|
|
1980
|
+
const registeredFunctionSelectors = [];
|
|
1981
|
+
for (const _function of registeredCallTraceEvents) {
|
|
1982
|
+
const abiFunction = abiFunctions.bySafeName[_function];
|
|
1983
|
+
if (abiFunction === void 0) {
|
|
1984
|
+
throw new Error(
|
|
1985
|
+
`Validation failed: Function name for function '${_function}' not found in the contract ABI. Got '${_function}', expected one of [${Object.keys(
|
|
1986
|
+
abiFunctions.bySafeName
|
|
1987
|
+
).map((eventName) => `'${eventName}'`).join(", ")}].`
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1990
|
+
registeredFunctionSelectors.push(abiFunction.selector);
|
|
1991
|
+
}
|
|
1992
|
+
const topicsArray = [];
|
|
1993
|
+
if (source.filter !== void 0) {
|
|
1994
|
+
const eventFilters = Array.isArray(source.filter) ? source.filter : [source.filter];
|
|
1995
|
+
for (const filter of eventFilters) {
|
|
1996
|
+
const abiEvent = abiEvents.bySafeName[filter.event];
|
|
1997
|
+
if (!abiEvent) {
|
|
1998
|
+
throw new Error(
|
|
1999
|
+
`Validation failed: Invalid filter for contract '${source.name}'. Got event name '${filter.event}', expected one of [${Object.keys(
|
|
2000
|
+
abiEvents.bySafeName
|
|
2001
|
+
).map((n) => `'${n}'`).join(", ")}].`
|
|
2002
|
+
);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
topicsArray.push(...buildTopics(source.abi, eventFilters));
|
|
2006
|
+
const filteredEventSelectors = topicsArray.map(
|
|
2007
|
+
(t) => t.topic0
|
|
1968
2008
|
);
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
topicsArray.push(...buildTopics(source.abi, eventFilters));
|
|
1972
|
-
const filteredEventSelectors = topicsArray.map(
|
|
1973
|
-
(t) => t.topic0
|
|
1974
|
-
);
|
|
1975
|
-
const excludedRegisteredEventSelectors = registeredEventSelectors.filter(
|
|
1976
|
-
(s) => filteredEventSelectors.includes(s) === false
|
|
1977
|
-
);
|
|
1978
|
-
for (const selector of filteredEventSelectors) {
|
|
1979
|
-
if (registeredEventSelectors.includes(selector) === false) {
|
|
1980
|
-
throw new Error(
|
|
1981
|
-
`Validation failed: Event selector '${abiEvents.bySelector[selector]?.safeName}' is used in a filter but does not have a corresponding indexing function.`
|
|
2009
|
+
const excludedRegisteredEventSelectors = registeredEventSelectors.filter(
|
|
2010
|
+
(s) => filteredEventSelectors.includes(s) === false
|
|
1982
2011
|
);
|
|
2012
|
+
for (const selector of filteredEventSelectors) {
|
|
2013
|
+
if (registeredEventSelectors.includes(selector) === false) {
|
|
2014
|
+
throw new Error(
|
|
2015
|
+
`Validation failed: Event selector '${abiEvents.bySelector[selector]?.safeName}' is used in a filter but does not have a corresponding indexing function.`
|
|
2016
|
+
);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
if (excludedRegisteredEventSelectors.length > 0) {
|
|
2020
|
+
topicsArray.push({
|
|
2021
|
+
topic0: excludedRegisteredEventSelectors,
|
|
2022
|
+
topic1: null,
|
|
2023
|
+
topic2: null,
|
|
2024
|
+
topic3: null
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
} else {
|
|
2028
|
+
topicsArray.push({
|
|
2029
|
+
topic0: registeredEventSelectors,
|
|
2030
|
+
topic1: null,
|
|
2031
|
+
topic2: null,
|
|
2032
|
+
topic3: null
|
|
2033
|
+
});
|
|
1983
2034
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
}
|
|
2001
|
-
const startBlockMaybeNan = source.startBlock;
|
|
2002
|
-
const fromBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
2003
|
-
const endBlockMaybeNan = source.endBlock;
|
|
2004
|
-
const toBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
2005
|
-
const contractMetadata = {
|
|
2006
|
-
type: "contract",
|
|
2007
|
-
abi: source.abi,
|
|
2008
|
-
abiEvents,
|
|
2009
|
-
abiFunctions,
|
|
2010
|
-
name: source.name,
|
|
2011
|
-
network
|
|
2012
|
-
};
|
|
2013
|
-
const resolvedAddress = source?.address;
|
|
2014
|
-
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2015
|
-
const logFactory = buildLogFactory({
|
|
2016
|
-
chainId: network.chainId,
|
|
2017
|
-
...resolvedAddress
|
|
2018
|
-
});
|
|
2019
|
-
const logSources2 = topicsArray.map(
|
|
2020
|
-
(topics) => ({
|
|
2021
|
-
...contractMetadata,
|
|
2022
|
-
filter: {
|
|
2023
|
-
type: "log",
|
|
2035
|
+
const fromBlock = await resolveBlockNumber(
|
|
2036
|
+
source.startBlock,
|
|
2037
|
+
network
|
|
2038
|
+
);
|
|
2039
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
2040
|
+
const contractMetadata = {
|
|
2041
|
+
type: "contract",
|
|
2042
|
+
abi: source.abi,
|
|
2043
|
+
abiEvents,
|
|
2044
|
+
abiFunctions,
|
|
2045
|
+
name: source.name,
|
|
2046
|
+
network
|
|
2047
|
+
};
|
|
2048
|
+
const resolvedAddress = source?.address;
|
|
2049
|
+
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2050
|
+
const logFactory = buildLogFactory({
|
|
2024
2051
|
chainId: network.chainId,
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2052
|
+
...resolvedAddress
|
|
2053
|
+
});
|
|
2054
|
+
const logSources2 = topicsArray.map(
|
|
2055
|
+
(topics) => ({
|
|
2056
|
+
...contractMetadata,
|
|
2057
|
+
filter: {
|
|
2058
|
+
type: "log",
|
|
2059
|
+
chainId: network.chainId,
|
|
2060
|
+
address: logFactory,
|
|
2061
|
+
topic0: topics.topic0,
|
|
2062
|
+
topic1: topics.topic1,
|
|
2063
|
+
topic2: topics.topic2,
|
|
2064
|
+
topic3: topics.topic3,
|
|
2065
|
+
fromBlock,
|
|
2066
|
+
toBlock,
|
|
2067
|
+
include: defaultLogFilterInclude.concat(
|
|
2068
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2069
|
+
)
|
|
2070
|
+
}
|
|
2071
|
+
})
|
|
2072
|
+
);
|
|
2073
|
+
if (source.includeCallTraces) {
|
|
2074
|
+
return [
|
|
2075
|
+
...logSources2,
|
|
2076
|
+
{
|
|
2077
|
+
...contractMetadata,
|
|
2078
|
+
filter: {
|
|
2079
|
+
type: "trace",
|
|
2080
|
+
chainId: network.chainId,
|
|
2081
|
+
fromAddress: void 0,
|
|
2082
|
+
toAddress: logFactory,
|
|
2083
|
+
callType: "CALL",
|
|
2084
|
+
functionSelector: registeredFunctionSelectors,
|
|
2085
|
+
includeReverted: false,
|
|
2086
|
+
fromBlock,
|
|
2087
|
+
toBlock,
|
|
2088
|
+
include: defaultTraceFilterInclude.concat(
|
|
2089
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2090
|
+
)
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
];
|
|
2035
2094
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2095
|
+
return logSources2;
|
|
2096
|
+
} else if (resolvedAddress !== void 0) {
|
|
2097
|
+
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2098
|
+
if (!address.startsWith("0x"))
|
|
2099
|
+
throw new Error(
|
|
2100
|
+
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2101
|
+
0,
|
|
2102
|
+
2
|
|
2103
|
+
)}', expected '0x'.`
|
|
2104
|
+
);
|
|
2105
|
+
if (address.length !== 42)
|
|
2106
|
+
throw new Error(
|
|
2107
|
+
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2108
|
+
);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
const validatedAddress = Array.isArray(resolvedAddress) ? dedupe(resolvedAddress).map((r) => toLowerCase(r)) : resolvedAddress !== void 0 ? toLowerCase(resolvedAddress) : void 0;
|
|
2112
|
+
const logSources = topicsArray.map(
|
|
2113
|
+
(topics) => ({
|
|
2042
2114
|
...contractMetadata,
|
|
2043
2115
|
filter: {
|
|
2044
|
-
type: "
|
|
2116
|
+
type: "log",
|
|
2045
2117
|
chainId: network.chainId,
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2118
|
+
address: validatedAddress,
|
|
2119
|
+
topic0: topics.topic0,
|
|
2120
|
+
topic1: topics.topic1,
|
|
2121
|
+
topic2: topics.topic2,
|
|
2122
|
+
topic3: topics.topic3,
|
|
2051
2123
|
fromBlock,
|
|
2052
2124
|
toBlock,
|
|
2053
|
-
include:
|
|
2125
|
+
include: defaultLogFilterInclude.concat(
|
|
2054
2126
|
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2055
2127
|
)
|
|
2056
2128
|
}
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2129
|
+
})
|
|
2130
|
+
);
|
|
2131
|
+
if (source.includeCallTraces) {
|
|
2132
|
+
return [
|
|
2133
|
+
...logSources,
|
|
2134
|
+
{
|
|
2135
|
+
...contractMetadata,
|
|
2136
|
+
filter: {
|
|
2137
|
+
type: "trace",
|
|
2138
|
+
chainId: network.chainId,
|
|
2139
|
+
fromAddress: void 0,
|
|
2140
|
+
toAddress: Array.isArray(validatedAddress) ? validatedAddress : validatedAddress === void 0 ? void 0 : [validatedAddress],
|
|
2141
|
+
callType: "CALL",
|
|
2142
|
+
functionSelector: registeredFunctionSelectors,
|
|
2143
|
+
includeReverted: false,
|
|
2144
|
+
fromBlock,
|
|
2145
|
+
toBlock,
|
|
2146
|
+
include: defaultTraceFilterInclude.concat(
|
|
2147
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2148
|
+
)
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
];
|
|
2152
|
+
} else
|
|
2153
|
+
return logSources;
|
|
2074
2154
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
const logSources = topicsArray.map(
|
|
2078
|
-
(topics) => ({
|
|
2079
|
-
...contractMetadata,
|
|
2080
|
-
filter: {
|
|
2081
|
-
type: "log",
|
|
2082
|
-
chainId: network.chainId,
|
|
2083
|
-
address: validatedAddress,
|
|
2084
|
-
topic0: topics.topic0,
|
|
2085
|
-
topic1: topics.topic1,
|
|
2086
|
-
topic2: topics.topic2,
|
|
2087
|
-
topic3: topics.topic3,
|
|
2088
|
-
fromBlock,
|
|
2089
|
-
toBlock,
|
|
2090
|
-
include: defaultLogFilterInclude.concat(
|
|
2091
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2092
|
-
)
|
|
2093
|
-
}
|
|
2094
|
-
})
|
|
2095
|
-
);
|
|
2096
|
-
if (source.includeCallTraces) {
|
|
2097
|
-
return [
|
|
2098
|
-
...logSources,
|
|
2099
|
-
{
|
|
2100
|
-
...contractMetadata,
|
|
2101
|
-
filter: {
|
|
2102
|
-
type: "trace",
|
|
2103
|
-
chainId: network.chainId,
|
|
2104
|
-
fromAddress: void 0,
|
|
2105
|
-
toAddress: Array.isArray(validatedAddress) ? validatedAddress : validatedAddress === void 0 ? void 0 : [validatedAddress],
|
|
2106
|
-
callType: "CALL",
|
|
2107
|
-
functionSelector: registeredFunctionSelectors,
|
|
2108
|
-
includeReverted: false,
|
|
2109
|
-
fromBlock,
|
|
2110
|
-
toBlock,
|
|
2111
|
-
include: defaultTraceFilterInclude.concat(
|
|
2112
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2113
|
-
)
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
];
|
|
2117
|
-
} else
|
|
2118
|
-
return logSources;
|
|
2119
|
-
}).filter((source) => {
|
|
2155
|
+
)
|
|
2156
|
+
)).flat().filter((source) => {
|
|
2120
2157
|
const hasNoRegisteredIndexingFunctions = source.filter.type === "trace" ? Array.isArray(source.filter.functionSelector) && source.filter.functionSelector.length === 0 : Array.isArray(source.filter.topic0) && source.filter.topic0?.length === 0;
|
|
2121
2158
|
if (hasNoRegisteredIndexingFunctions) {
|
|
2122
2159
|
logs.push({
|
|
@@ -2126,171 +2163,176 @@ async function buildConfigAndIndexingFunctions({
|
|
|
2126
2163
|
}
|
|
2127
2164
|
return hasNoRegisteredIndexingFunctions === false;
|
|
2128
2165
|
});
|
|
2129
|
-
const accountSources =
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
if (resolvedAddress === void 0) {
|
|
2137
|
-
throw new Error(
|
|
2138
|
-
`Validation failed: Account '${source.name}' must specify an 'address'.`
|
|
2139
|
-
);
|
|
2140
|
-
}
|
|
2141
|
-
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2142
|
-
const logFactory = buildLogFactory({
|
|
2143
|
-
chainId: network.chainId,
|
|
2144
|
-
...resolvedAddress
|
|
2145
|
-
});
|
|
2146
|
-
return [
|
|
2147
|
-
{
|
|
2148
|
-
type: "account",
|
|
2149
|
-
name: source.name,
|
|
2150
|
-
network,
|
|
2151
|
-
filter: {
|
|
2152
|
-
type: "transaction",
|
|
2153
|
-
chainId: network.chainId,
|
|
2154
|
-
fromAddress: void 0,
|
|
2155
|
-
toAddress: logFactory,
|
|
2156
|
-
includeReverted: false,
|
|
2157
|
-
fromBlock,
|
|
2158
|
-
toBlock,
|
|
2159
|
-
include: defaultTransactionFilterInclude
|
|
2160
|
-
}
|
|
2161
|
-
},
|
|
2162
|
-
{
|
|
2163
|
-
type: "account",
|
|
2164
|
-
name: source.name,
|
|
2165
|
-
network,
|
|
2166
|
-
filter: {
|
|
2167
|
-
type: "transaction",
|
|
2168
|
-
chainId: network.chainId,
|
|
2169
|
-
fromAddress: logFactory,
|
|
2170
|
-
toAddress: void 0,
|
|
2171
|
-
includeReverted: false,
|
|
2172
|
-
fromBlock,
|
|
2173
|
-
toBlock,
|
|
2174
|
-
include: defaultTransactionFilterInclude
|
|
2175
|
-
}
|
|
2176
|
-
},
|
|
2177
|
-
{
|
|
2178
|
-
type: "account",
|
|
2179
|
-
name: source.name,
|
|
2180
|
-
network,
|
|
2181
|
-
filter: {
|
|
2182
|
-
type: "transfer",
|
|
2183
|
-
chainId: network.chainId,
|
|
2184
|
-
fromAddress: void 0,
|
|
2185
|
-
toAddress: logFactory,
|
|
2186
|
-
includeReverted: false,
|
|
2187
|
-
fromBlock,
|
|
2188
|
-
toBlock,
|
|
2189
|
-
include: defaultTransferFilterInclude.concat(
|
|
2190
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2191
|
-
)
|
|
2192
|
-
}
|
|
2193
|
-
},
|
|
2194
|
-
{
|
|
2195
|
-
type: "account",
|
|
2196
|
-
name: source.name,
|
|
2197
|
-
network,
|
|
2198
|
-
filter: {
|
|
2199
|
-
type: "transfer",
|
|
2200
|
-
chainId: network.chainId,
|
|
2201
|
-
fromAddress: logFactory,
|
|
2202
|
-
toAddress: void 0,
|
|
2203
|
-
includeReverted: false,
|
|
2204
|
-
fromBlock,
|
|
2205
|
-
toBlock,
|
|
2206
|
-
include: defaultTransferFilterInclude.concat(
|
|
2207
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2208
|
-
)
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
];
|
|
2212
|
-
}
|
|
2213
|
-
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2214
|
-
if (!address.startsWith("0x"))
|
|
2215
|
-
throw new Error(
|
|
2216
|
-
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2217
|
-
0,
|
|
2218
|
-
2
|
|
2219
|
-
)}', expected '0x'.`
|
|
2220
|
-
);
|
|
2221
|
-
if (address.length !== 42)
|
|
2222
|
-
throw new Error(
|
|
2223
|
-
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2166
|
+
const accountSources = (await Promise.all(
|
|
2167
|
+
flattenSources(config.accounts ?? {}).map(
|
|
2168
|
+
async (source) => {
|
|
2169
|
+
const network = networks.find((n) => n.name === source.network);
|
|
2170
|
+
const fromBlock = await resolveBlockNumber(
|
|
2171
|
+
source.startBlock,
|
|
2172
|
+
network
|
|
2224
2173
|
);
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
network,
|
|
2232
|
-
filter: {
|
|
2233
|
-
type: "transaction",
|
|
2234
|
-
chainId: network.chainId,
|
|
2235
|
-
fromAddress: void 0,
|
|
2236
|
-
toAddress: validatedAddress,
|
|
2237
|
-
includeReverted: false,
|
|
2238
|
-
fromBlock,
|
|
2239
|
-
toBlock,
|
|
2240
|
-
include: defaultTransactionFilterInclude
|
|
2241
|
-
}
|
|
2242
|
-
},
|
|
2243
|
-
{
|
|
2244
|
-
type: "account",
|
|
2245
|
-
name: source.name,
|
|
2246
|
-
network,
|
|
2247
|
-
filter: {
|
|
2248
|
-
type: "transaction",
|
|
2249
|
-
chainId: network.chainId,
|
|
2250
|
-
fromAddress: validatedAddress,
|
|
2251
|
-
toAddress: void 0,
|
|
2252
|
-
includeReverted: false,
|
|
2253
|
-
fromBlock,
|
|
2254
|
-
toBlock,
|
|
2255
|
-
include: defaultTransactionFilterInclude
|
|
2174
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
2175
|
+
const resolvedAddress = source?.address;
|
|
2176
|
+
if (resolvedAddress === void 0) {
|
|
2177
|
+
throw new Error(
|
|
2178
|
+
`Validation failed: Account '${source.name}' must specify an 'address'.`
|
|
2179
|
+
);
|
|
2256
2180
|
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2181
|
+
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2182
|
+
const logFactory = buildLogFactory({
|
|
2183
|
+
chainId: network.chainId,
|
|
2184
|
+
...resolvedAddress
|
|
2185
|
+
});
|
|
2186
|
+
return [
|
|
2187
|
+
{
|
|
2188
|
+
type: "account",
|
|
2189
|
+
name: source.name,
|
|
2190
|
+
network,
|
|
2191
|
+
filter: {
|
|
2192
|
+
type: "transaction",
|
|
2193
|
+
chainId: network.chainId,
|
|
2194
|
+
fromAddress: void 0,
|
|
2195
|
+
toAddress: logFactory,
|
|
2196
|
+
includeReverted: false,
|
|
2197
|
+
fromBlock,
|
|
2198
|
+
toBlock,
|
|
2199
|
+
include: defaultTransactionFilterInclude
|
|
2200
|
+
}
|
|
2201
|
+
},
|
|
2202
|
+
{
|
|
2203
|
+
type: "account",
|
|
2204
|
+
name: source.name,
|
|
2205
|
+
network,
|
|
2206
|
+
filter: {
|
|
2207
|
+
type: "transaction",
|
|
2208
|
+
chainId: network.chainId,
|
|
2209
|
+
fromAddress: logFactory,
|
|
2210
|
+
toAddress: void 0,
|
|
2211
|
+
includeReverted: false,
|
|
2212
|
+
fromBlock,
|
|
2213
|
+
toBlock,
|
|
2214
|
+
include: defaultTransactionFilterInclude
|
|
2215
|
+
}
|
|
2216
|
+
},
|
|
2217
|
+
{
|
|
2218
|
+
type: "account",
|
|
2219
|
+
name: source.name,
|
|
2220
|
+
network,
|
|
2221
|
+
filter: {
|
|
2222
|
+
type: "transfer",
|
|
2223
|
+
chainId: network.chainId,
|
|
2224
|
+
fromAddress: void 0,
|
|
2225
|
+
toAddress: logFactory,
|
|
2226
|
+
includeReverted: false,
|
|
2227
|
+
fromBlock,
|
|
2228
|
+
toBlock,
|
|
2229
|
+
include: defaultTransferFilterInclude.concat(
|
|
2230
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2231
|
+
)
|
|
2232
|
+
}
|
|
2233
|
+
},
|
|
2234
|
+
{
|
|
2235
|
+
type: "account",
|
|
2236
|
+
name: source.name,
|
|
2237
|
+
network,
|
|
2238
|
+
filter: {
|
|
2239
|
+
type: "transfer",
|
|
2240
|
+
chainId: network.chainId,
|
|
2241
|
+
fromAddress: logFactory,
|
|
2242
|
+
toAddress: void 0,
|
|
2243
|
+
includeReverted: false,
|
|
2244
|
+
fromBlock,
|
|
2245
|
+
toBlock,
|
|
2246
|
+
include: defaultTransferFilterInclude.concat(
|
|
2247
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2248
|
+
)
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
];
|
|
2273
2252
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
toBlock,
|
|
2287
|
-
include: defaultTransferFilterInclude.concat(
|
|
2288
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2289
|
-
)
|
|
2253
|
+
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2254
|
+
if (!address.startsWith("0x"))
|
|
2255
|
+
throw new Error(
|
|
2256
|
+
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2257
|
+
0,
|
|
2258
|
+
2
|
|
2259
|
+
)}', expected '0x'.`
|
|
2260
|
+
);
|
|
2261
|
+
if (address.length !== 42)
|
|
2262
|
+
throw new Error(
|
|
2263
|
+
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2264
|
+
);
|
|
2290
2265
|
}
|
|
2266
|
+
const validatedAddress = Array.isArray(resolvedAddress) ? dedupe(resolvedAddress).map((r) => toLowerCase(r)) : resolvedAddress !== void 0 ? toLowerCase(resolvedAddress) : void 0;
|
|
2267
|
+
return [
|
|
2268
|
+
{
|
|
2269
|
+
type: "account",
|
|
2270
|
+
name: source.name,
|
|
2271
|
+
network,
|
|
2272
|
+
filter: {
|
|
2273
|
+
type: "transaction",
|
|
2274
|
+
chainId: network.chainId,
|
|
2275
|
+
fromAddress: void 0,
|
|
2276
|
+
toAddress: validatedAddress,
|
|
2277
|
+
includeReverted: false,
|
|
2278
|
+
fromBlock,
|
|
2279
|
+
toBlock,
|
|
2280
|
+
include: defaultTransactionFilterInclude
|
|
2281
|
+
}
|
|
2282
|
+
},
|
|
2283
|
+
{
|
|
2284
|
+
type: "account",
|
|
2285
|
+
name: source.name,
|
|
2286
|
+
network,
|
|
2287
|
+
filter: {
|
|
2288
|
+
type: "transaction",
|
|
2289
|
+
chainId: network.chainId,
|
|
2290
|
+
fromAddress: validatedAddress,
|
|
2291
|
+
toAddress: void 0,
|
|
2292
|
+
includeReverted: false,
|
|
2293
|
+
fromBlock,
|
|
2294
|
+
toBlock,
|
|
2295
|
+
include: defaultTransactionFilterInclude
|
|
2296
|
+
}
|
|
2297
|
+
},
|
|
2298
|
+
{
|
|
2299
|
+
type: "account",
|
|
2300
|
+
name: source.name,
|
|
2301
|
+
network,
|
|
2302
|
+
filter: {
|
|
2303
|
+
type: "transfer",
|
|
2304
|
+
chainId: network.chainId,
|
|
2305
|
+
fromAddress: void 0,
|
|
2306
|
+
toAddress: validatedAddress,
|
|
2307
|
+
includeReverted: false,
|
|
2308
|
+
fromBlock,
|
|
2309
|
+
toBlock,
|
|
2310
|
+
include: defaultTransferFilterInclude.concat(
|
|
2311
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2312
|
+
)
|
|
2313
|
+
}
|
|
2314
|
+
},
|
|
2315
|
+
{
|
|
2316
|
+
type: "account",
|
|
2317
|
+
name: source.name,
|
|
2318
|
+
network,
|
|
2319
|
+
filter: {
|
|
2320
|
+
type: "transfer",
|
|
2321
|
+
chainId: network.chainId,
|
|
2322
|
+
fromAddress: validatedAddress,
|
|
2323
|
+
toAddress: void 0,
|
|
2324
|
+
includeReverted: false,
|
|
2325
|
+
fromBlock,
|
|
2326
|
+
toBlock,
|
|
2327
|
+
include: defaultTransferFilterInclude.concat(
|
|
2328
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2329
|
+
)
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
];
|
|
2291
2333
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2334
|
+
)
|
|
2335
|
+
)).flat().filter((source) => {
|
|
2294
2336
|
const eventName = source.filter.type === "transaction" ? source.filter.fromAddress === void 0 ? `${source.name}:transaction:to` : `${source.name}:transaction:from` : source.filter.fromAddress === void 0 ? `${source.name}:transfer:to` : `${source.name}:transfer:from`;
|
|
2295
2337
|
const hasRegisteredIndexingFunction = indexingFunctions[eventName] !== void 0;
|
|
2296
2338
|
if (!hasRegisteredIndexingFunction) {
|
|
@@ -2301,34 +2343,34 @@ async function buildConfigAndIndexingFunctions({
|
|
|
2301
2343
|
}
|
|
2302
2344
|
return hasRegisteredIndexingFunction;
|
|
2303
2345
|
});
|
|
2304
|
-
const blockSources =
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
const startBlockMaybeNan = source.startBlock;
|
|
2314
|
-
const fromBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
2315
|
-
const endBlockMaybeNan = source.endBlock;
|
|
2316
|
-
const toBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
2317
|
-
return {
|
|
2318
|
-
type: "block",
|
|
2319
|
-
name: source.name,
|
|
2320
|
-
network,
|
|
2321
|
-
filter: {
|
|
2322
|
-
type: "block",
|
|
2323
|
-
chainId: network.chainId,
|
|
2324
|
-
interval,
|
|
2325
|
-
offset: (fromBlock ?? 0) % interval,
|
|
2326
|
-
fromBlock,
|
|
2327
|
-
toBlock,
|
|
2328
|
-
include: defaultBlockFilterInclude
|
|
2346
|
+
const blockSources = (await Promise.all(
|
|
2347
|
+
flattenSources(config.blocks ?? {}).map(async (source) => {
|
|
2348
|
+
const network = networks.find((n) => n.name === source.network);
|
|
2349
|
+
const intervalMaybeNan = source.interval ?? 1;
|
|
2350
|
+
const interval = Number.isNaN(intervalMaybeNan) ? 0 : intervalMaybeNan;
|
|
2351
|
+
if (!Number.isInteger(interval) || interval === 0) {
|
|
2352
|
+
throw new Error(
|
|
2353
|
+
`Validation failed: Invalid interval for block source '${source.name}'. Got ${interval}, expected a non-zero integer.`
|
|
2354
|
+
);
|
|
2329
2355
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2356
|
+
const fromBlock = await resolveBlockNumber(source.startBlock, network);
|
|
2357
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
2358
|
+
return {
|
|
2359
|
+
type: "block",
|
|
2360
|
+
name: source.name,
|
|
2361
|
+
network,
|
|
2362
|
+
filter: {
|
|
2363
|
+
type: "block",
|
|
2364
|
+
chainId: network.chainId,
|
|
2365
|
+
interval,
|
|
2366
|
+
offset: (fromBlock ?? 0) % interval,
|
|
2367
|
+
fromBlock,
|
|
2368
|
+
toBlock,
|
|
2369
|
+
include: defaultBlockFilterInclude
|
|
2370
|
+
}
|
|
2371
|
+
};
|
|
2372
|
+
})
|
|
2373
|
+
)).flat().filter((blockSource) => {
|
|
2332
2374
|
const hasRegisteredIndexingFunction = indexingFunctions[`${blockSource.name}:block`] !== void 0;
|
|
2333
2375
|
if (!hasRegisteredIndexingFunction) {
|
|
2334
2376
|
logs.push({
|
|
@@ -7528,7 +7570,7 @@ import {
|
|
|
7528
7570
|
} from "viem";
|
|
7529
7571
|
|
|
7530
7572
|
// src/sync-store/encoding.ts
|
|
7531
|
-
import { hexToBigInt as hexToBigInt3, hexToNumber as
|
|
7573
|
+
import { hexToBigInt as hexToBigInt3, hexToNumber as hexToNumber3 } from "viem";
|
|
7532
7574
|
var encodeBlock = ({
|
|
7533
7575
|
block,
|
|
7534
7576
|
chainId
|
|
@@ -7537,7 +7579,7 @@ var encodeBlock = ({
|
|
|
7537
7579
|
hash: block.hash,
|
|
7538
7580
|
chainId,
|
|
7539
7581
|
checkpoint: encodeCheckpoint({
|
|
7540
|
-
blockTimestamp:
|
|
7582
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7541
7583
|
chainId: BigInt(chainId),
|
|
7542
7584
|
blockNumber: hexToBigInt3(block.number),
|
|
7543
7585
|
transactionIndex: MAX_CHECKPOINT.transactionIndex,
|
|
@@ -7573,7 +7615,7 @@ var encodeLog = ({
|
|
|
7573
7615
|
id: `${log.blockHash}-${log.logIndex}`,
|
|
7574
7616
|
chainId,
|
|
7575
7617
|
checkpoint: block === void 0 ? null : encodeCheckpoint({
|
|
7576
|
-
blockTimestamp:
|
|
7618
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7577
7619
|
chainId: BigInt(chainId),
|
|
7578
7620
|
blockNumber: hexToBigInt3(log.blockNumber),
|
|
7579
7621
|
transactionIndex: hexToBigInt3(log.transactionIndex),
|
|
@@ -7582,9 +7624,9 @@ var encodeLog = ({
|
|
|
7582
7624
|
}),
|
|
7583
7625
|
blockHash: log.blockHash,
|
|
7584
7626
|
blockNumber: hexToBigInt3(log.blockNumber),
|
|
7585
|
-
logIndex:
|
|
7627
|
+
logIndex: hexToNumber3(log.logIndex),
|
|
7586
7628
|
transactionHash: log.transactionHash,
|
|
7587
|
-
transactionIndex:
|
|
7629
|
+
transactionIndex: hexToNumber3(log.transactionIndex),
|
|
7588
7630
|
address: toLowerCase(log.address),
|
|
7589
7631
|
topic0: log.topics[0] ? log.topics[0] : null,
|
|
7590
7632
|
topic1: log.topics[1] ? log.topics[1] : null,
|
|
@@ -7601,7 +7643,7 @@ var encodeTransaction = ({
|
|
|
7601
7643
|
return {
|
|
7602
7644
|
hash: transaction.hash,
|
|
7603
7645
|
checkpoint: encodeCheckpoint({
|
|
7604
|
-
blockTimestamp:
|
|
7646
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7605
7647
|
chainId: BigInt(chainId),
|
|
7606
7648
|
blockNumber: hexToBigInt3(transaction.blockNumber),
|
|
7607
7649
|
transactionIndex: hexToBigInt3(transaction.transactionIndex),
|
|
@@ -7618,11 +7660,11 @@ var encodeTransaction = ({
|
|
|
7618
7660
|
input: transaction.input,
|
|
7619
7661
|
maxFeePerGas: transaction.maxFeePerGas ? hexToBigInt3(transaction.maxFeePerGas) : null,
|
|
7620
7662
|
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? hexToBigInt3(transaction.maxPriorityFeePerGas) : null,
|
|
7621
|
-
nonce:
|
|
7663
|
+
nonce: hexToNumber3(transaction.nonce),
|
|
7622
7664
|
r: transaction.r ?? null,
|
|
7623
7665
|
s: transaction.s ?? null,
|
|
7624
7666
|
to: transaction.to ? toLowerCase(transaction.to) : null,
|
|
7625
|
-
transactionIndex:
|
|
7667
|
+
transactionIndex: hexToNumber3(transaction.transactionIndex),
|
|
7626
7668
|
type: transaction.type ?? "0x0",
|
|
7627
7669
|
value: hexToBigInt3(transaction.value),
|
|
7628
7670
|
v: transaction.v ? hexToBigInt3(transaction.v) : null
|
|
@@ -7645,7 +7687,7 @@ var encodeTransactionReceipt = ({
|
|
|
7645
7687
|
logsBloom: transactionReceipt.logsBloom,
|
|
7646
7688
|
status: transactionReceipt.status,
|
|
7647
7689
|
to: transactionReceipt.to ? toLowerCase(transactionReceipt.to) : null,
|
|
7648
|
-
transactionIndex:
|
|
7690
|
+
transactionIndex: hexToNumber3(transactionReceipt.transactionIndex),
|
|
7649
7691
|
type: transactionReceipt.type
|
|
7650
7692
|
};
|
|
7651
7693
|
};
|
|
@@ -7659,7 +7701,7 @@ function encodeTrace({
|
|
|
7659
7701
|
id: `${transaction.hash}-${trace.index}`,
|
|
7660
7702
|
chainId,
|
|
7661
7703
|
checkpoint: encodeCheckpoint({
|
|
7662
|
-
blockTimestamp:
|
|
7704
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7663
7705
|
chainId: BigInt(chainId),
|
|
7664
7706
|
blockNumber: hexToBigInt3(block.number),
|
|
7665
7707
|
transactionIndex: hexToBigInt3(transaction.transactionIndex),
|
|
@@ -8346,7 +8388,7 @@ import {
|
|
|
8346
8388
|
decodeFunctionData,
|
|
8347
8389
|
decodeFunctionResult,
|
|
8348
8390
|
hexToBigInt as hexToBigInt5,
|
|
8349
|
-
hexToNumber as
|
|
8391
|
+
hexToNumber as hexToNumber4
|
|
8350
8392
|
} from "viem";
|
|
8351
8393
|
var buildEvents = ({
|
|
8352
8394
|
sources,
|
|
@@ -8388,7 +8430,7 @@ var buildEvents = ({
|
|
|
8388
8430
|
chainId: filter.chainId,
|
|
8389
8431
|
sourceIndex: i,
|
|
8390
8432
|
checkpoint: encodeCheckpoint({
|
|
8391
|
-
blockTimestamp:
|
|
8433
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8392
8434
|
chainId: BigInt(filter.chainId),
|
|
8393
8435
|
blockNumber: hexToBigInt5(log.blockNumber),
|
|
8394
8436
|
transactionIndex: hexToBigInt5(log.transactionIndex),
|
|
@@ -8436,7 +8478,7 @@ var buildEvents = ({
|
|
|
8436
8478
|
chainId: filter.chainId,
|
|
8437
8479
|
sourceIndex: i,
|
|
8438
8480
|
checkpoint: encodeCheckpoint({
|
|
8439
|
-
blockTimestamp:
|
|
8481
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8440
8482
|
chainId: BigInt(filter.chainId),
|
|
8441
8483
|
blockNumber: hexToBigInt5(block.number),
|
|
8442
8484
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8479,7 +8521,7 @@ var buildEvents = ({
|
|
|
8479
8521
|
chainId: filter.chainId,
|
|
8480
8522
|
sourceIndex: i,
|
|
8481
8523
|
checkpoint: encodeCheckpoint({
|
|
8482
|
-
blockTimestamp:
|
|
8524
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8483
8525
|
chainId: BigInt(filter.chainId),
|
|
8484
8526
|
blockNumber: hexToBigInt5(block.number),
|
|
8485
8527
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8525,7 +8567,7 @@ var buildEvents = ({
|
|
|
8525
8567
|
chainId: filter.chainId,
|
|
8526
8568
|
sourceIndex: i,
|
|
8527
8569
|
checkpoint: encodeCheckpoint({
|
|
8528
|
-
blockTimestamp:
|
|
8570
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8529
8571
|
chainId: BigInt(filter.chainId),
|
|
8530
8572
|
blockNumber: hexToBigInt5(block.number),
|
|
8531
8573
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8551,7 +8593,7 @@ var buildEvents = ({
|
|
|
8551
8593
|
chainId: filter.chainId,
|
|
8552
8594
|
sourceIndex: i,
|
|
8553
8595
|
checkpoint: encodeCheckpoint({
|
|
8554
|
-
blockTimestamp:
|
|
8596
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8555
8597
|
chainId: BigInt(filter.chainId),
|
|
8556
8598
|
blockNumber: hexToBigInt5(block.number),
|
|
8557
8599
|
transactionIndex: MAX_CHECKPOINT.transactionIndex,
|
|
@@ -9020,7 +9062,7 @@ function intervalRange(interval) {
|
|
|
9020
9062
|
|
|
9021
9063
|
// src/utils/rpc.ts
|
|
9022
9064
|
import {
|
|
9023
|
-
BlockNotFoundError,
|
|
9065
|
+
BlockNotFoundError as BlockNotFoundError2,
|
|
9024
9066
|
TransactionReceiptNotFoundError,
|
|
9025
9067
|
numberToHex
|
|
9026
9068
|
} from "viem";
|
|
@@ -9035,7 +9077,7 @@ var _eth_getBlockByNumber = (requestQueue, {
|
|
|
9035
9077
|
]
|
|
9036
9078
|
}).then((_block) => {
|
|
9037
9079
|
if (!_block)
|
|
9038
|
-
throw new
|
|
9080
|
+
throw new BlockNotFoundError2({
|
|
9039
9081
|
blockNumber: blockNumber ?? blockTag
|
|
9040
9082
|
});
|
|
9041
9083
|
return _block;
|
|
@@ -9045,7 +9087,7 @@ var _eth_getBlockByHash = (requestQueue, { hash }) => requestQueue.request({
|
|
|
9045
9087
|
params: [hash, true]
|
|
9046
9088
|
}).then((_block) => {
|
|
9047
9089
|
if (!_block)
|
|
9048
|
-
throw new
|
|
9090
|
+
throw new BlockNotFoundError2({
|
|
9049
9091
|
blockHash: hash
|
|
9050
9092
|
});
|
|
9051
9093
|
return _block;
|
|
@@ -9171,7 +9213,7 @@ var _debug_traceBlockByHash = (requestQueue, {
|
|
|
9171
9213
|
import { getLogsRetryHelper } from "@ponder/utils";
|
|
9172
9214
|
import {
|
|
9173
9215
|
hexToBigInt as hexToBigInt6,
|
|
9174
|
-
hexToNumber as
|
|
9216
|
+
hexToNumber as hexToNumber5,
|
|
9175
9217
|
toHex,
|
|
9176
9218
|
zeroHash
|
|
9177
9219
|
} from "viem";
|
|
@@ -9258,7 +9300,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9258
9300
|
});
|
|
9259
9301
|
if (getLogsErrorResponse.shouldRetry === false)
|
|
9260
9302
|
throw error;
|
|
9261
|
-
const range2 =
|
|
9303
|
+
const range2 = hexToNumber5(getLogsErrorResponse.ranges[0].toBlock) - hexToNumber5(getLogsErrorResponse.ranges[0].fromBlock);
|
|
9262
9304
|
args.common.logger.debug({
|
|
9263
9305
|
service: "sync",
|
|
9264
9306
|
msg: `Caught eth_getLogs error on '${args.network.name}', updating recommended range to ${range2}.`
|
|
@@ -9407,7 +9449,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9407
9449
|
const address = isAddressFactory(filter.address) ? await syncAddressFactory(filter.address, interval) : filter.address;
|
|
9408
9450
|
const logs = await syncLogsDynamic({ filter, interval, address });
|
|
9409
9451
|
const blocks = await Promise.all(
|
|
9410
|
-
logs.map((log) => syncBlock(
|
|
9452
|
+
logs.map((log) => syncBlock(hexToNumber5(log.blockNumber)))
|
|
9411
9453
|
);
|
|
9412
9454
|
const requiredBlocks = new Set(blocks.map((b) => b.hash));
|
|
9413
9455
|
for (let i = 0; i < logs.length; i++) {
|
|
@@ -9422,7 +9464,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9422
9464
|
if (log.transactionHash === zeroHash) {
|
|
9423
9465
|
args.common.logger.warn({
|
|
9424
9466
|
service: "sync",
|
|
9425
|
-
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${
|
|
9467
|
+
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${hexToNumber5(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
9426
9468
|
});
|
|
9427
9469
|
} else {
|
|
9428
9470
|
throw new Error(
|
|
@@ -9449,7 +9491,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9449
9491
|
if (log.transactionHash === zeroHash) {
|
|
9450
9492
|
args.common.logger.warn({
|
|
9451
9493
|
service: "sync",
|
|
9452
|
-
msg: `Detected log with empty transaction hash in block ${log.blockHash} at log index ${
|
|
9494
|
+
msg: `Detected log with empty transaction hash in block ${log.blockHash} at log index ${hexToNumber5(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
9453
9495
|
});
|
|
9454
9496
|
} else {
|
|
9455
9497
|
blockTransactionHashes.add(log.transactionHash);
|
|
@@ -9715,10 +9757,10 @@ var createMutex = () => {
|
|
|
9715
9757
|
};
|
|
9716
9758
|
|
|
9717
9759
|
// src/sync-realtime/index.ts
|
|
9718
|
-
import { hexToNumber as
|
|
9760
|
+
import { hexToNumber as hexToNumber7, zeroHash as zeroHash2 } from "viem";
|
|
9719
9761
|
|
|
9720
9762
|
// src/sync-realtime/bloom.ts
|
|
9721
|
-
import { hexToBytes, hexToNumber as
|
|
9763
|
+
import { hexToBytes, hexToNumber as hexToNumber6, keccak256 } from "viem";
|
|
9722
9764
|
var zeroLogsBloom = "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
|
9723
9765
|
var BLOOM_SIZE_BYTES = 256;
|
|
9724
9766
|
var isInBloom = (_bloom, input) => {
|
|
@@ -9735,7 +9777,7 @@ function isFilterInBloom({
|
|
|
9735
9777
|
block,
|
|
9736
9778
|
filter
|
|
9737
9779
|
}) {
|
|
9738
|
-
if (
|
|
9780
|
+
if (hexToNumber6(block.number) < (filter.fromBlock ?? 0) || hexToNumber6(block.number) > (filter.toBlock ?? Number.POSITIVE_INFINITY)) {
|
|
9739
9781
|
return false;
|
|
9740
9782
|
}
|
|
9741
9783
|
const isTopicsInBloom = [
|
|
@@ -9861,7 +9903,7 @@ var createRealtimeSync = (args) => {
|
|
|
9861
9903
|
}) => {
|
|
9862
9904
|
args.common.logger.debug({
|
|
9863
9905
|
service: "realtime",
|
|
9864
|
-
msg: `Started syncing '${args.network.name}' block ${
|
|
9906
|
+
msg: `Started syncing '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
9865
9907
|
});
|
|
9866
9908
|
for (const log of factoryLogs) {
|
|
9867
9909
|
for (const filter of factories) {
|
|
@@ -9996,12 +10038,12 @@ var createRealtimeSync = (args) => {
|
|
|
9996
10038
|
const text = _text.filter((t) => t !== void 0).join(" and ");
|
|
9997
10039
|
args.common.logger.info({
|
|
9998
10040
|
service: "realtime",
|
|
9999
|
-
msg: `Synced ${text} from '${args.network.name}' block ${
|
|
10041
|
+
msg: `Synced ${text} from '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
10000
10042
|
});
|
|
10001
10043
|
} else {
|
|
10002
10044
|
args.common.logger.info({
|
|
10003
10045
|
service: "realtime",
|
|
10004
|
-
msg: `Synced block ${
|
|
10046
|
+
msg: `Synced block ${hexToNumber7(block.number)} from '${args.network.name}' `
|
|
10005
10047
|
});
|
|
10006
10048
|
}
|
|
10007
10049
|
unfinalizedBlocks.push(syncBlockToLightBlock(block));
|
|
@@ -10017,20 +10059,20 @@ var createRealtimeSync = (args) => {
|
|
|
10017
10059
|
transactionReceipts,
|
|
10018
10060
|
endClock
|
|
10019
10061
|
});
|
|
10020
|
-
const blockMovesFinality =
|
|
10062
|
+
const blockMovesFinality = hexToNumber7(block.number) >= hexToNumber7(finalizedBlock.number) + 2 * args.network.finalityBlockCount;
|
|
10021
10063
|
if (blockMovesFinality) {
|
|
10022
10064
|
const pendingFinalizedBlock = unfinalizedBlocks.find(
|
|
10023
|
-
(lb) =>
|
|
10065
|
+
(lb) => hexToNumber7(lb.number) === hexToNumber7(block.number) - args.network.finalityBlockCount
|
|
10024
10066
|
);
|
|
10025
10067
|
args.common.logger.debug({
|
|
10026
10068
|
service: "realtime",
|
|
10027
|
-
msg: `Finalized ${
|
|
10069
|
+
msg: `Finalized ${hexToNumber7(pendingFinalizedBlock.number) - hexToNumber7(finalizedBlock.number) + 1} '${args.network.name}' blocks [${hexToNumber7(finalizedBlock.number) + 1}, ${hexToNumber7(pendingFinalizedBlock.number)}]`
|
|
10028
10070
|
});
|
|
10029
10071
|
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
10030
|
-
(lb) =>
|
|
10072
|
+
(lb) => hexToNumber7(lb.number) <= hexToNumber7(pendingFinalizedBlock.number)
|
|
10031
10073
|
);
|
|
10032
10074
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10033
|
-
(lb) =>
|
|
10075
|
+
(lb) => hexToNumber7(lb.number) > hexToNumber7(pendingFinalizedBlock.number)
|
|
10034
10076
|
);
|
|
10035
10077
|
for (const filter of factories) {
|
|
10036
10078
|
for (const { hash } of finalizedBlocks) {
|
|
@@ -10068,13 +10110,13 @@ var createRealtimeSync = (args) => {
|
|
|
10068
10110
|
const handleReorg = async (block) => {
|
|
10069
10111
|
args.common.logger.warn({
|
|
10070
10112
|
service: "realtime",
|
|
10071
|
-
msg: `Detected forked '${args.network.name}' block at height ${
|
|
10113
|
+
msg: `Detected forked '${args.network.name}' block at height ${hexToNumber7(block.number)}`
|
|
10072
10114
|
});
|
|
10073
10115
|
const reorgedBlocks = unfinalizedBlocks.filter(
|
|
10074
|
-
(lb) =>
|
|
10116
|
+
(lb) => hexToNumber7(lb.number) >= hexToNumber7(block.number)
|
|
10075
10117
|
);
|
|
10076
10118
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10077
|
-
(lb) =>
|
|
10119
|
+
(lb) => hexToNumber7(lb.number) < hexToNumber7(block.number)
|
|
10078
10120
|
);
|
|
10079
10121
|
let remoteBlock = block;
|
|
10080
10122
|
while (true) {
|
|
@@ -10082,7 +10124,7 @@ var createRealtimeSync = (args) => {
|
|
|
10082
10124
|
if (parentBlock.hash === remoteBlock.parentHash)
|
|
10083
10125
|
break;
|
|
10084
10126
|
if (unfinalizedBlocks.length === 0) {
|
|
10085
|
-
const msg = `Encountered unrecoverable '${args.network.name}' reorg beyond finalized block ${
|
|
10127
|
+
const msg = `Encountered unrecoverable '${args.network.name}' reorg beyond finalized block ${hexToNumber7(finalizedBlock.number)}`;
|
|
10086
10128
|
args.common.logger.warn({ service: "realtime", msg });
|
|
10087
10129
|
throw new Error(msg);
|
|
10088
10130
|
} else {
|
|
@@ -10096,7 +10138,7 @@ var createRealtimeSync = (args) => {
|
|
|
10096
10138
|
await args.onEvent({ type: "reorg", block: commonAncestor, reorgedBlocks });
|
|
10097
10139
|
args.common.logger.warn({
|
|
10098
10140
|
service: "realtime",
|
|
10099
|
-
msg: `Reconciled ${reorgedBlocks.length}-block '${args.network.name}' reorg with common ancestor block ${
|
|
10141
|
+
msg: `Reconciled ${reorgedBlocks.length}-block '${args.network.name}' reorg with common ancestor block ${hexToNumber7(commonAncestor.number)}`
|
|
10100
10142
|
});
|
|
10101
10143
|
unfinalizedChildAddresses.clear();
|
|
10102
10144
|
for (const filter of factories) {
|
|
@@ -10188,7 +10230,7 @@ var createRealtimeSync = (args) => {
|
|
|
10188
10230
|
if (log.transactionHash === zeroHash2) {
|
|
10189
10231
|
args.common.logger.warn({
|
|
10190
10232
|
service: "sync",
|
|
10191
|
-
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${
|
|
10233
|
+
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${hexToNumber7(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
10192
10234
|
});
|
|
10193
10235
|
} else {
|
|
10194
10236
|
throw new Error(
|
|
@@ -10201,7 +10243,7 @@ var createRealtimeSync = (args) => {
|
|
|
10201
10243
|
if (shouldRequestLogs === false && args.sources.some((s) => s.filter.type === "log")) {
|
|
10202
10244
|
args.common.logger.debug({
|
|
10203
10245
|
service: "realtime",
|
|
10204
|
-
msg: `Skipped fetching '${args.network.name}' logs for block ${
|
|
10246
|
+
msg: `Skipped fetching '${args.network.name}' logs for block ${hexToNumber7(block.number)} due to bloom filter result`
|
|
10205
10247
|
});
|
|
10206
10248
|
}
|
|
10207
10249
|
const shouldRequestTraces = traceFilters.length > 0 || transferFilters.length > 0;
|
|
@@ -10246,7 +10288,7 @@ var createRealtimeSync = (args) => {
|
|
|
10246
10288
|
if (log.transactionHash === zeroHash2) {
|
|
10247
10289
|
args.common.logger.warn({
|
|
10248
10290
|
service: "sync",
|
|
10249
|
-
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${
|
|
10291
|
+
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${hexToNumber7(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
10250
10292
|
});
|
|
10251
10293
|
} else {
|
|
10252
10294
|
requiredTransactions.add(log.transactionHash);
|
|
@@ -10344,22 +10386,22 @@ var createRealtimeSync = (args) => {
|
|
|
10344
10386
|
if (latestBlock.hash === block.hash) {
|
|
10345
10387
|
args.common.logger.trace({
|
|
10346
10388
|
service: "realtime",
|
|
10347
|
-
msg: `Skipped processing '${args.network.name}' block ${
|
|
10389
|
+
msg: `Skipped processing '${args.network.name}' block ${hexToNumber7(block.number)}, already synced`
|
|
10348
10390
|
});
|
|
10349
10391
|
return;
|
|
10350
10392
|
}
|
|
10351
10393
|
try {
|
|
10352
|
-
if (
|
|
10394
|
+
if (hexToNumber7(latestBlock.number) >= hexToNumber7(block.number)) {
|
|
10353
10395
|
await handleReorg(block);
|
|
10354
10396
|
processBlock.clear();
|
|
10355
10397
|
return;
|
|
10356
10398
|
}
|
|
10357
|
-
if (
|
|
10399
|
+
if (hexToNumber7(latestBlock.number) + 1 < hexToNumber7(block.number)) {
|
|
10358
10400
|
const missingBlockRange = range(
|
|
10359
|
-
|
|
10401
|
+
hexToNumber7(latestBlock.number) + 1,
|
|
10360
10402
|
Math.min(
|
|
10361
|
-
|
|
10362
|
-
|
|
10403
|
+
hexToNumber7(block.number),
|
|
10404
|
+
hexToNumber7(latestBlock.number) + MAX_QUEUED_BLOCKS
|
|
10363
10405
|
)
|
|
10364
10406
|
);
|
|
10365
10407
|
const pendingBlocks = await Promise.all(
|
|
@@ -10371,9 +10413,9 @@ var createRealtimeSync = (args) => {
|
|
|
10371
10413
|
);
|
|
10372
10414
|
args.common.logger.debug({
|
|
10373
10415
|
service: "realtime",
|
|
10374
|
-
msg: `Fetched ${missingBlockRange.length} missing '${args.network.name}' blocks [${
|
|
10375
|
-
|
|
10376
|
-
|
|
10416
|
+
msg: `Fetched ${missingBlockRange.length} missing '${args.network.name}' blocks [${hexToNumber7(latestBlock.number) + 1}, ${Math.min(
|
|
10417
|
+
hexToNumber7(block.number),
|
|
10418
|
+
hexToNumber7(latestBlock.number) + MAX_QUEUED_BLOCKS
|
|
10377
10419
|
)}]`
|
|
10378
10420
|
});
|
|
10379
10421
|
processBlock.clear();
|
|
@@ -10398,7 +10440,7 @@ var createRealtimeSync = (args) => {
|
|
|
10398
10440
|
}
|
|
10399
10441
|
args.common.logger.warn({
|
|
10400
10442
|
service: "realtime",
|
|
10401
|
-
msg: `Failed to process '${args.network.name}' block ${
|
|
10443
|
+
msg: `Failed to process '${args.network.name}' block ${hexToNumber7(block.number)}`,
|
|
10402
10444
|
error
|
|
10403
10445
|
});
|
|
10404
10446
|
const duration = ERROR_TIMEOUT[consecutiveErrors];
|
|
@@ -10411,7 +10453,7 @@ var createRealtimeSync = (args) => {
|
|
|
10411
10453
|
if (++consecutiveErrors === ERROR_TIMEOUT.length) {
|
|
10412
10454
|
args.common.logger.error({
|
|
10413
10455
|
service: "realtime",
|
|
10414
|
-
msg: `Fatal error: Unable to process '${args.network.name}' block ${
|
|
10456
|
+
msg: `Fatal error: Unable to process '${args.network.name}' block ${hexToNumber7(block.number)} after ${ERROR_TIMEOUT.length} attempts.`,
|
|
10415
10457
|
error
|
|
10416
10458
|
});
|
|
10417
10459
|
args.onFatalError(error);
|
|
@@ -10426,13 +10468,13 @@ var createRealtimeSync = (args) => {
|
|
|
10426
10468
|
});
|
|
10427
10469
|
args.common.logger.debug({
|
|
10428
10470
|
service: "realtime",
|
|
10429
|
-
msg: `Received latest '${args.network.name}' block ${
|
|
10471
|
+
msg: `Received latest '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
10430
10472
|
});
|
|
10431
10473
|
const latestBlock = getLatestUnfinalizedBlock();
|
|
10432
10474
|
if (latestBlock.hash === block.hash) {
|
|
10433
10475
|
args.common.logger.trace({
|
|
10434
10476
|
service: "realtime",
|
|
10435
|
-
msg: `Skipped processing '${args.network.name}' block ${
|
|
10477
|
+
msg: `Skipped processing '${args.network.name}' block ${hexToNumber7(block.number)}, already synced`
|
|
10436
10478
|
});
|
|
10437
10479
|
return;
|
|
10438
10480
|
}
|
|
@@ -10601,7 +10643,7 @@ var zipperMany = (arrays, compare) => {
|
|
|
10601
10643
|
};
|
|
10602
10644
|
|
|
10603
10645
|
// src/sync/index.ts
|
|
10604
|
-
import { hexToBigInt as hexToBigInt7, hexToNumber as
|
|
10646
|
+
import { hexToBigInt as hexToBigInt7, hexToNumber as hexToNumber8, toHex as toHex2 } from "viem";
|
|
10605
10647
|
var syncBlockToLightBlock = ({
|
|
10606
10648
|
hash,
|
|
10607
10649
|
parentHash,
|
|
@@ -10616,7 +10658,7 @@ var syncBlockToLightBlock = ({
|
|
|
10616
10658
|
var blockToCheckpoint = (block, chainId, rounding) => {
|
|
10617
10659
|
return {
|
|
10618
10660
|
...rounding === "up" ? MAX_CHECKPOINT : ZERO_CHECKPOINT,
|
|
10619
|
-
blockTimestamp:
|
|
10661
|
+
blockTimestamp: hexToNumber8(block.timestamp),
|
|
10620
10662
|
chainId: BigInt(chainId),
|
|
10621
10663
|
blockNumber: hexToBigInt7(block.number)
|
|
10622
10664
|
};
|
|
@@ -10625,16 +10667,16 @@ var isSyncEnd = (syncProgress) => {
|
|
|
10625
10667
|
if (syncProgress.end === void 0 || syncProgress.current === void 0) {
|
|
10626
10668
|
return false;
|
|
10627
10669
|
}
|
|
10628
|
-
return
|
|
10670
|
+
return hexToNumber8(syncProgress.current.number) >= hexToNumber8(syncProgress.end.number);
|
|
10629
10671
|
};
|
|
10630
10672
|
var isSyncFinalized = (syncProgress) => {
|
|
10631
10673
|
if (syncProgress.current === void 0) {
|
|
10632
10674
|
return false;
|
|
10633
10675
|
}
|
|
10634
|
-
return
|
|
10676
|
+
return hexToNumber8(syncProgress.current.number) >= hexToNumber8(syncProgress.finalized.number);
|
|
10635
10677
|
};
|
|
10636
10678
|
var getHistoricalLast = (syncProgress) => {
|
|
10637
|
-
return syncProgress.end === void 0 ? syncProgress.finalized :
|
|
10679
|
+
return syncProgress.end === void 0 ? syncProgress.finalized : hexToNumber8(syncProgress.end.number) > hexToNumber8(syncProgress.finalized.number) ? syncProgress.finalized : syncProgress.end;
|
|
10638
10680
|
};
|
|
10639
10681
|
var splitEvents = (events) => {
|
|
10640
10682
|
let hash;
|
|
@@ -10735,8 +10777,8 @@ var createSync = async (params) => {
|
|
|
10735
10777
|
);
|
|
10736
10778
|
if (localBlock !== void 0) {
|
|
10737
10779
|
status[network.name].block = {
|
|
10738
|
-
timestamp:
|
|
10739
|
-
number:
|
|
10780
|
+
timestamp: hexToNumber8(localBlock.timestamp),
|
|
10781
|
+
number: hexToNumber8(localBlock.number)
|
|
10740
10782
|
};
|
|
10741
10783
|
}
|
|
10742
10784
|
};
|
|
@@ -10820,7 +10862,7 @@ var createSync = async (params) => {
|
|
|
10820
10862
|
});
|
|
10821
10863
|
params.common.logger.debug({
|
|
10822
10864
|
service: "sync",
|
|
10823
|
-
msg: `Extracted ${events.length} '${network.name}' events for block ${
|
|
10865
|
+
msg: `Extracted ${events.length} '${network.name}' events for block ${hexToNumber8(event.block.number)}`
|
|
10824
10866
|
});
|
|
10825
10867
|
if (params.ordering === "multichain") {
|
|
10826
10868
|
const checkpoint = getMultichainCheckpoint({
|
|
@@ -10828,15 +10870,15 @@ var createSync = async (params) => {
|
|
|
10828
10870
|
network
|
|
10829
10871
|
});
|
|
10830
10872
|
status[network.name].block = {
|
|
10831
|
-
timestamp:
|
|
10832
|
-
number:
|
|
10873
|
+
timestamp: hexToNumber8(event.block.timestamp),
|
|
10874
|
+
number: hexToNumber8(event.block.number)
|
|
10833
10875
|
};
|
|
10834
10876
|
const readyEvents = events.concat(pendingEvents);
|
|
10835
10877
|
pendingEvents = [];
|
|
10836
10878
|
executedEvents = executedEvents.concat(readyEvents);
|
|
10837
10879
|
params.common.logger.debug({
|
|
10838
10880
|
service: "sync",
|
|
10839
|
-
msg: `Sequenced ${readyEvents.length} '${network.name}' events for block ${
|
|
10881
|
+
msg: `Sequenced ${readyEvents.length} '${network.name}' events for block ${hexToNumber8(event.block.number)}`
|
|
10840
10882
|
});
|
|
10841
10883
|
params.onRealtimeEvent({
|
|
10842
10884
|
type: "block",
|
|
@@ -10930,7 +10972,7 @@ var createSync = async (params) => {
|
|
|
10930
10972
|
case "reorg": {
|
|
10931
10973
|
let reorgedEvents = 0;
|
|
10932
10974
|
const isReorgedEvent = ({ chainId, block }) => {
|
|
10933
|
-
if (chainId === network.chainId && Number(block.number) >
|
|
10975
|
+
if (chainId === network.chainId && Number(block.number) > hexToNumber8(event.block.number)) {
|
|
10934
10976
|
reorgedEvents++;
|
|
10935
10977
|
return true;
|
|
10936
10978
|
}
|
|
@@ -11041,7 +11083,7 @@ var createSync = async (params) => {
|
|
|
11041
11083
|
);
|
|
11042
11084
|
params.common.logger.info({
|
|
11043
11085
|
service: "sync",
|
|
11044
|
-
msg: `Killing '${network.name}' live indexing because the end block ${
|
|
11086
|
+
msg: `Killing '${network.name}' live indexing because the end block ${hexToNumber8(syncProgress.end.number)} has been finalized`
|
|
11045
11087
|
});
|
|
11046
11088
|
realtimeSync.kill();
|
|
11047
11089
|
}
|
|
@@ -11119,8 +11161,8 @@ var createSync = async (params) => {
|
|
|
11119
11161
|
const { syncProgress, realtimeSync } = perNetworkSync.get(network);
|
|
11120
11162
|
const filters = params.indexingBuild.sources.filter(({ filter }) => filter.chainId === network.chainId).map(({ filter }) => filter);
|
|
11121
11163
|
status[network.name].block = {
|
|
11122
|
-
number:
|
|
11123
|
-
timestamp:
|
|
11164
|
+
number: hexToNumber8(syncProgress.current.number),
|
|
11165
|
+
timestamp: hexToNumber8(syncProgress.current.timestamp)
|
|
11124
11166
|
};
|
|
11125
11167
|
status[network.name].ready = true;
|
|
11126
11168
|
const from = getOmnichainCheckpoint({ tag: "finalized" });
|
|
@@ -11223,30 +11265,30 @@ var getPerChainOnRealtimeSyncEvent = ({
|
|
|
11223
11265
|
syncProgress.current = event.block;
|
|
11224
11266
|
common.logger.debug({
|
|
11225
11267
|
service: "sync",
|
|
11226
|
-
msg: `Updated '${network.name}' current block to ${
|
|
11268
|
+
msg: `Updated '${network.name}' current block to ${hexToNumber8(event.block.number)}`
|
|
11227
11269
|
});
|
|
11228
11270
|
common.metrics.ponder_sync_block.set(
|
|
11229
11271
|
{ network: network.name },
|
|
11230
|
-
|
|
11272
|
+
hexToNumber8(syncProgress.current.number)
|
|
11231
11273
|
);
|
|
11232
11274
|
unfinalizedBlocks.push(event);
|
|
11233
11275
|
return event;
|
|
11234
11276
|
}
|
|
11235
11277
|
case "finalize": {
|
|
11236
11278
|
const finalizedInterval = [
|
|
11237
|
-
|
|
11238
|
-
|
|
11279
|
+
hexToNumber8(syncProgress.finalized.number),
|
|
11280
|
+
hexToNumber8(event.block.number)
|
|
11239
11281
|
];
|
|
11240
11282
|
syncProgress.finalized = event.block;
|
|
11241
11283
|
common.logger.debug({
|
|
11242
11284
|
service: "sync",
|
|
11243
|
-
msg: `Updated '${network.name}' finalized block to ${
|
|
11285
|
+
msg: `Updated '${network.name}' finalized block to ${hexToNumber8(event.block.number)}`
|
|
11244
11286
|
});
|
|
11245
11287
|
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
11246
|
-
({ block }) =>
|
|
11288
|
+
({ block }) => hexToNumber8(block.number) <= hexToNumber8(event.block.number)
|
|
11247
11289
|
);
|
|
11248
11290
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
11249
|
-
({ block }) =>
|
|
11291
|
+
({ block }) => hexToNumber8(block.number) > hexToNumber8(event.block.number)
|
|
11250
11292
|
);
|
|
11251
11293
|
await Promise.all([
|
|
11252
11294
|
syncStore.insertBlocks({
|
|
@@ -11322,14 +11364,14 @@ var getPerChainOnRealtimeSyncEvent = ({
|
|
|
11322
11364
|
syncProgress.current = event.block;
|
|
11323
11365
|
common.logger.debug({
|
|
11324
11366
|
service: "sync",
|
|
11325
|
-
msg: `Updated '${network.name}' current block to ${
|
|
11367
|
+
msg: `Updated '${network.name}' current block to ${hexToNumber8(event.block.number)}`
|
|
11326
11368
|
});
|
|
11327
11369
|
common.metrics.ponder_sync_block.set(
|
|
11328
11370
|
{ network: network.name },
|
|
11329
|
-
|
|
11371
|
+
hexToNumber8(syncProgress.current.number)
|
|
11330
11372
|
);
|
|
11331
11373
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
11332
|
-
({ block }) =>
|
|
11374
|
+
({ block }) => hexToNumber8(block.number) <= hexToNumber8(event.block.number)
|
|
11333
11375
|
);
|
|
11334
11376
|
await syncStore.pruneRpcRequestResult({
|
|
11335
11377
|
chainId: network.chainId,
|
|
@@ -11414,10 +11456,10 @@ async function* getLocalSyncGenerator({
|
|
|
11414
11456
|
historicalSync
|
|
11415
11457
|
}) {
|
|
11416
11458
|
const label = { network: network.name };
|
|
11417
|
-
let cursor =
|
|
11459
|
+
let cursor = hexToNumber8(syncProgress.start.number);
|
|
11418
11460
|
const last = getHistoricalLast(syncProgress);
|
|
11419
11461
|
let estimateRange = 25;
|
|
11420
|
-
if (
|
|
11462
|
+
if (hexToNumber8(syncProgress.start.number) > hexToNumber8(syncProgress.finalized.number)) {
|
|
11421
11463
|
syncProgress.current = syncProgress.finalized;
|
|
11422
11464
|
common.logger.warn({
|
|
11423
11465
|
service: "sync",
|
|
@@ -11425,15 +11467,15 @@ async function* getLocalSyncGenerator({
|
|
|
11425
11467
|
});
|
|
11426
11468
|
common.metrics.ponder_sync_block.set(
|
|
11427
11469
|
label,
|
|
11428
|
-
|
|
11470
|
+
hexToNumber8(syncProgress.current.number)
|
|
11429
11471
|
);
|
|
11430
11472
|
common.metrics.ponder_historical_total_blocks.set(label, 0);
|
|
11431
11473
|
common.metrics.ponder_historical_cached_blocks.set(label, 0);
|
|
11432
11474
|
return;
|
|
11433
11475
|
}
|
|
11434
11476
|
const totalInterval = [
|
|
11435
|
-
|
|
11436
|
-
|
|
11477
|
+
hexToNumber8(syncProgress.start.number),
|
|
11478
|
+
hexToNumber8(last.number)
|
|
11437
11479
|
];
|
|
11438
11480
|
common.logger.debug({
|
|
11439
11481
|
service: "sync",
|
|
@@ -11464,12 +11506,12 @@ async function* getLocalSyncGenerator({
|
|
|
11464
11506
|
if (syncProgress.current !== void 0) {
|
|
11465
11507
|
common.metrics.ponder_sync_block.set(
|
|
11466
11508
|
label,
|
|
11467
|
-
|
|
11509
|
+
hexToNumber8(syncProgress.current.number)
|
|
11468
11510
|
);
|
|
11469
11511
|
yield encodeCheckpoint(
|
|
11470
11512
|
blockToCheckpoint(syncProgress.current, network.chainId, "up")
|
|
11471
11513
|
);
|
|
11472
|
-
if (
|
|
11514
|
+
if (hexToNumber8(syncProgress.current.number) === hexToNumber8(last.number)) {
|
|
11473
11515
|
common.logger.info({
|
|
11474
11516
|
service: "sync",
|
|
11475
11517
|
msg: `Skipped '${network.name}' historical sync because all blocks are cached`
|
|
@@ -11483,7 +11525,7 @@ async function* getLocalSyncGenerator({
|
|
|
11483
11525
|
)} cached`
|
|
11484
11526
|
});
|
|
11485
11527
|
}
|
|
11486
|
-
cursor =
|
|
11528
|
+
cursor = hexToNumber8(syncProgress.current.number) + 1;
|
|
11487
11529
|
} else {
|
|
11488
11530
|
common.logger.info({
|
|
11489
11531
|
service: "historical",
|
|
@@ -11492,8 +11534,8 @@ async function* getLocalSyncGenerator({
|
|
|
11492
11534
|
}
|
|
11493
11535
|
while (true) {
|
|
11494
11536
|
const interval = [
|
|
11495
|
-
Math.min(cursor,
|
|
11496
|
-
Math.min(cursor + estimateRange,
|
|
11537
|
+
Math.min(cursor, hexToNumber8(last.number)),
|
|
11538
|
+
Math.min(cursor + estimateRange, hexToNumber8(last.number))
|
|
11497
11539
|
];
|
|
11498
11540
|
const endClock = startClock();
|
|
11499
11541
|
const synced = await historicalSync.sync(interval);
|
|
@@ -11503,13 +11545,13 @@ async function* getLocalSyncGenerator({
|
|
|
11503
11545
|
});
|
|
11504
11546
|
cursor = interval[1] + 1;
|
|
11505
11547
|
if (synced === void 0) {
|
|
11506
|
-
if (interval[1] ===
|
|
11548
|
+
if (interval[1] === hexToNumber8(last.number)) {
|
|
11507
11549
|
syncProgress.current = last;
|
|
11508
11550
|
} else {
|
|
11509
11551
|
continue;
|
|
11510
11552
|
}
|
|
11511
11553
|
} else {
|
|
11512
|
-
if (interval[1] ===
|
|
11554
|
+
if (interval[1] === hexToNumber8(last.number)) {
|
|
11513
11555
|
syncProgress.current = last;
|
|
11514
11556
|
} else {
|
|
11515
11557
|
syncProgress.current = synced;
|
|
@@ -11517,7 +11559,7 @@ async function* getLocalSyncGenerator({
|
|
|
11517
11559
|
const duration = endClock();
|
|
11518
11560
|
common.metrics.ponder_sync_block.set(
|
|
11519
11561
|
label,
|
|
11520
|
-
|
|
11562
|
+
hexToNumber8(syncProgress.current.number)
|
|
11521
11563
|
);
|
|
11522
11564
|
common.metrics.ponder_historical_duration.observe(label, duration);
|
|
11523
11565
|
common.metrics.ponder_historical_completed_blocks.inc(
|
|
@@ -11574,7 +11616,7 @@ var getLocalSyncProgress = async ({
|
|
|
11574
11616
|
);
|
|
11575
11617
|
const finalized = Math.max(
|
|
11576
11618
|
0,
|
|
11577
|
-
|
|
11619
|
+
hexToNumber8(diagnostics[1].number) - network.finalityBlockCount
|
|
11578
11620
|
);
|
|
11579
11621
|
syncProgress.finalized = await _eth_getBlockByNumber(requestQueue, {
|
|
11580
11622
|
blockNumber: finalized
|
|
@@ -11583,7 +11625,7 @@ var getLocalSyncProgress = async ({
|
|
|
11583
11625
|
if (diagnostics.length === 4) {
|
|
11584
11626
|
syncProgress.current = diagnostics[3];
|
|
11585
11627
|
}
|
|
11586
|
-
if (
|
|
11628
|
+
if (hexToNumber8(diagnostics[0]) !== network.chainId) {
|
|
11587
11629
|
common.logger.warn({
|
|
11588
11630
|
service: "sync",
|
|
11589
11631
|
msg: `Remote chain ID (${diagnostics[0]}) does not match configured chain ID (${network.chainId}) for network "${network.name}"`
|
|
@@ -11593,7 +11635,7 @@ var getLocalSyncProgress = async ({
|
|
|
11593
11635
|
return syncProgress;
|
|
11594
11636
|
}
|
|
11595
11637
|
const end = Math.max(...filters.map((filter) => filter.toBlock));
|
|
11596
|
-
if (end >
|
|
11638
|
+
if (end > hexToNumber8(diagnostics[1].number)) {
|
|
11597
11639
|
syncProgress.end = {
|
|
11598
11640
|
number: toHex2(end),
|
|
11599
11641
|
hash: "0x",
|