diff --git a/components/dashboard.tsx b/components/dashboard.tsx index 25d7c6e..d4cf674 100644 --- a/components/dashboard.tsx +++ b/components/dashboard.tsx @@ -49,7 +49,7 @@ export default function Dashboard() { } else if (connectionAttempted && !account.isConnected) { router.push("/"); } - }, [account.isConnecting, connectionAttempted, account.isConnected]); + }, [account.isConnecting, connectionAttempted, account.isConnected, router]); const handleCopyAddress = async () => { if (account.address) { diff --git a/package.json b/package.json index a775401..f3dd154 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,13 @@ { "name": "deposit-ui", "version": "0.1.0", - "type": "module", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint", - "update-deposits": "node ./scripts/update-deposits.js" + "update-deposits": "node ./scripts/update-deposits.mjs" }, "dependencies": { "@headlessui/react": "^1.7.18", diff --git a/scripts/contracts.js b/scripts/contracts.mjs similarity index 100% rename from scripts/contracts.js rename to scripts/contracts.mjs diff --git a/scripts/deposits.js b/scripts/deposits.mjs similarity index 100% rename from scripts/deposits.js rename to scripts/deposits.mjs diff --git a/scripts/update-deposits.js b/scripts/update-deposits.mjs similarity index 97% rename from scripts/update-deposits.js rename to scripts/update-deposits.mjs index bc25081..e81a75c 100644 --- a/scripts/update-deposits.js +++ b/scripts/update-deposits.mjs @@ -4,8 +4,9 @@ import { Contract, providers } from "ethers"; import PQueue from "p-queue"; // Network config and ABI -import depositABI from "./deposits.js"; -import { NETWORKS } from "./contracts.js"; +import depositABI from "./deposits.mjs"; +import { NETWORKS } from './contracts.mjs'; + // Config const stepSize = 25_000; diff --git a/scripts/update-deposits.ts b/scripts/update-deposits.ts index 79cf823..7c5daf5 100644 --- a/scripts/update-deposits.ts +++ b/scripts/update-deposits.ts @@ -1,89 +1,89 @@ -import path from "path"; -import { readFile, writeFile, mkdir } from "fs/promises"; - -// Network config and ABI -import CONTRACTS from "../utils/contracts.ts"; -import depositABI from "../utils/abis/deposit.ts"; -import { getPublicClient } from "wagmi/actions"; -import { config } from "../wagmi.ts"; -import { Address } from "viem"; - -// Config -const __dirname = path.dirname(new URL(import.meta.url).pathname); - -const BLOCK_RANGE_SIZE = 5000; -const client = getPublicClient(config); - -async function fetchAllEvents(depositAddress: Address, fromBlock: bigint, toBlock: bigint) { - - let currentBlock = BigInt(fromBlock); - const endBlock = BigInt(toBlock); - let allEvents = []; - - while (currentBlock <= endBlock) { - const nextBlock = currentBlock + BigInt(BLOCK_RANGE_SIZE) > endBlock ? endBlock : currentBlock + BigInt(BLOCK_RANGE_SIZE); - - console.log(`Fetching from block ${currentBlock} to ${nextBlock}`); - - const events = await client.getContractEvents({ - abi: depositABI, - address: depositAddress, - eventName: "DepositEvent", - fromBlock: currentBlock, - toBlock: nextBlock, - }); - - allEvents.push(...events); - currentBlock = nextBlock + BigInt(1); - } - - return allEvents; -} - -async function readCurrentDeposits(filePath: string) { - try { - const content = await readFile(filePath, "utf8"); - return JSON.parse(content); - } catch (err: any) { - if (err.code !== "ENOENT") { - throw err; - } - } - - return {}; -} - -async function updateNetwork(networkId: number) { - const network = CONTRACTS[networkId]; - if (!network) { - throw new Error(`Network with ID ${networkId} does not exist`); - } - - const filePath = path.resolve(__dirname, `../data/${networkId}/deposits.json`); - - let { lastBlock = network.depositStartBlockNumber, deposits = [] } = await readCurrentDeposits(filePath); - - console.log("Fetching existing deposits"); - const fromBlock = lastBlock; - const toBlock = await client.getBlockNumber(); - const events = await fetchAllEvents(CONTRACTS[networkId]!.addresses.deposit, fromBlock, toBlock); - let pks = events.map((e) => e.topics[1]); - - deposits = deposits.concat(pks); - lastBlock = toBlock; - - // Write the new deposits to file - const newContent = JSON.stringify({ lastBlock, deposits }); - await mkdir(path.dirname(filePath), { recursive: true }); - await writeFile(filePath, newContent, "utf8"); - - console.log(`Added ${pks.length} new cached pubkeys, new total is ${deposits.length}.`); -} - -async function main() { - for (const networkId of Object.keys(CONTRACTS)) { - await updateNetwork(Number(networkId)); - } -} - -main(); +// import path from "path"; +// import { readFile, writeFile, mkdir } from "fs/promises"; + +// // Network config and ABI +// import CONTRACTS from "../utils/contracts.ts"; +// import depositABI from "../utils/abis/deposit.ts"; +// import { getPublicClient } from "wagmi/actions"; +// import { config } from "../wagmi.ts"; +// import { Address } from "viem"; + +// // Config +// const __dirname = path.dirname(new URL(import.meta.url).pathname); + +// const BLOCK_RANGE_SIZE = 5000; +// const client = getPublicClient(config); + +// async function fetchAllEvents(depositAddress: Address, fromBlock: bigint, toBlock: bigint) { + +// let currentBlock = BigInt(fromBlock); +// const endBlock = BigInt(toBlock); +// let allEvents = []; + +// while (currentBlock <= endBlock) { +// const nextBlock = currentBlock + BigInt(BLOCK_RANGE_SIZE) > endBlock ? endBlock : currentBlock + BigInt(BLOCK_RANGE_SIZE); + +// console.log(`Fetching from block ${currentBlock} to ${nextBlock}`); + +// const events = await client.getContractEvents({ +// abi: depositABI, +// address: depositAddress, +// eventName: "DepositEvent", +// fromBlock: currentBlock, +// toBlock: nextBlock, +// }); + +// allEvents.push(...events); +// currentBlock = nextBlock + BigInt(1); +// } + +// return allEvents; +// } + +// async function readCurrentDeposits(filePath: string) { +// try { +// const content = await readFile(filePath, "utf8"); +// return JSON.parse(content); +// } catch (err: any) { +// if (err.code !== "ENOENT") { +// throw err; +// } +// } + +// return {}; +// } + +// async function updateNetwork(networkId: number) { +// const network = CONTRACTS[networkId]; +// if (!network) { +// throw new Error(`Network with ID ${networkId} does not exist`); +// } + +// const filePath = path.resolve(__dirname, `../data/${networkId}/deposits.json`); + +// let { lastBlock = network.depositStartBlockNumber, deposits = [] } = await readCurrentDeposits(filePath); + +// console.log("Fetching existing deposits"); +// const fromBlock = lastBlock; +// const toBlock = await client.getBlockNumber(); +// const events = await fetchAllEvents(CONTRACTS[networkId]!.addresses.deposit, fromBlock, toBlock); +// let pks = events.map((e) => e.topics[1]); + +// deposits = deposits.concat(pks); +// lastBlock = toBlock; + +// // Write the new deposits to file +// const newContent = JSON.stringify({ lastBlock, deposits }); +// await mkdir(path.dirname(filePath), { recursive: true }); +// await writeFile(filePath, newContent, "utf8"); + +// console.log(`Added ${pks.length} new cached pubkeys, new total is ${deposits.length}.`); +// } + +// async function main() { +// for (const networkId of Object.keys(CONTRACTS)) { +// await updateNetwork(Number(networkId)); +// } +// } + +// main();