Commit f2179e37 authored by Mark Tyneway's avatar Mark Tyneway

contracts: fetch-batches hardhat task

Adds a hardhat task to fetch batches. Logs are written
to stderr so that the stdout can be written to a file
or passed to `jq`.

```bash
export CONTRACTS_TARGET_NETWORK=...
export CONTRACTS_DEPLOYER_KEY=...
export CONTRACTS_RPC_URL=...
npx hardhat fetch-batches --network main --start 14311261
```
parent aa726e84
---
'@eth-optimism/contracts': patch
---
Add a fetch batches hardhat task
...@@ -20,6 +20,7 @@ import './tasks/validate-address-dictator' ...@@ -20,6 +20,7 @@ import './tasks/validate-address-dictator'
import './tasks/validate-chugsplash-dictator' import './tasks/validate-chugsplash-dictator'
import './tasks/whitelist' import './tasks/whitelist'
import './tasks/withdraw-fees' import './tasks/withdraw-fees'
import './tasks/fetch-batches'
import 'hardhat-gas-reporter' import 'hardhat-gas-reporter'
import '@primitivefi/hardhat-dodoc' import '@primitivefi/hardhat-dodoc'
import 'hardhat-output-validator' import 'hardhat-output-validator'
......
import { ethers } from 'ethers'
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { SequencerBatch } from '@eth-optimism/core-utils'
import { names } from '../src/address-names'
import { getContractFromArtifact } from '../src/deploy-utils'
// Need to export env vars
// CONTRACTS_TARGET_NETWORK
// CONTRACTS_DEPLOYER_KEY
// CONTRACTS_RPC_URL
task('fetch-batches')
.addOptionalParam(
'contractsRpcUrl',
'Ethereum HTTP Endpoint',
process.env.CONTRACTS_RPC_URL || 'http://127.0.0.1:8545',
types.string
)
.addOptionalParam('start', 'Start block height', 0, types.int)
.addOptionalParam('end', 'End block height', undefined, types.int)
.setAction(async (args, hre) => {
const provider = new ethers.providers.StaticJsonRpcProvider(
args.contractsRpcUrl
)
let CanonicalTransactionChain = await getContractFromArtifact(
hre,
names.managed.contracts.CanonicalTransactionChain
)
CanonicalTransactionChain = CanonicalTransactionChain.connect(provider)
const start = args.start
let end = args.end
if (!end) {
end = await provider.getBlockNumber()
}
const batches = []
for (let i = start; i < end; i += 2001) {
const tip = Math.min(i + 2000, end)
console.error(`Querying events ${i}-${tip}`)
const events = await CanonicalTransactionChain.queryFilter(
CanonicalTransactionChain.filters.SequencerBatchAppended(),
i,
tip
)
for (const event of events) {
const tx = await provider.getTransaction(event.transactionHash)
const batch = (SequencerBatch as any).fromHex(tx.data)
batches.push(batch.toJSON())
}
}
console.log(JSON.stringify(batches, null, 2))
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment