Commit 1ed50c44 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: update wd-mon to work for OptimismPortal2 (#9334)

parent 31845fd2
---
'@eth-optimism/common-ts': patch
---
Adds a new validator for address types.
---
'@eth-optimism/chain-mon': minor
---
Updates wd-mon inside chain-mon to support FPAC.
import { L2ChainID } from '@eth-optimism/sdk'
// TODO: Consider moving to `@eth-optimism/constants` and generating from superchain registry.
// @see https://github.com/ethereum-optimism/optimism/pull/9041
/**
* Mapping of L2ChainIDs to the L1 block numbers where the wd-mon service should start looking for
* withdrawals by default. L1 block numbers here are based on the block number in which the
* OptimismPortal proxy contract was deployed to L1.
*/
export const DEFAULT_STARTING_BLOCK_NUMBERS: {
[ChainID in L2ChainID]?: number
} = {
[L2ChainID.OPTIMISM]: 17365802 as const,
[L2ChainID.OPTIMISM_GOERLI]: 8299684 as const,
[L2ChainID.OPTIMISM_SEPOLIA]: 4071248 as const,
[L2ChainID.BASE_MAINNET]: 17482143 as const,
[L2ChainID.BASE_GOERLI]: 8411116 as const,
[L2ChainID.BASE_SEPOLIA]: 4370901 as const,
[L2ChainID.ZORA_MAINNET]: 17473938 as const,
}
import { Provider } from '@ethersproject/abstract-provider'
import { Logger } from '@eth-optimism/common-ts'
/**
* Finds
*
* @param
* @param
* @param
* @returns
*/
export const getLastFinalizedBlock = async (
l1RpcProvider: Provider,
faultProofWindow: number,
logger: Logger
): Promise<number> => {
let guessWindowStartBlock
try {
const l1Block = await l1RpcProvider.getBlock('latest')
// The time corresponding to the start of the FPW, based on the current block.
const windowStartTime = l1Block.timestamp - faultProofWindow
// Use the FPW to find the block number that is the start of the FPW.
guessWindowStartBlock = l1Block.number - faultProofWindow / 12
let block = await l1RpcProvider.getBlock(guessWindowStartBlock)
while (block.timestamp > windowStartTime) {
guessWindowStartBlock--
block = await l1RpcProvider.getBlock(guessWindowStartBlock)
}
return block.number
} catch (err) {
logger.fatal('error when calling querying for block', {
errors: err,
})
throw new Error(
`unable to find block number ${guessWindowStartBlock || 'latest'}`
)
}
}
This diff is collapsed.
...@@ -49,6 +49,14 @@ const logLevel = makeValidator<LogLevel>((input) => { ...@@ -49,6 +49,14 @@ const logLevel = makeValidator<LogLevel>((input) => {
} }
}) })
const address = makeValidator<string>((input) => {
if (!ethers.utils.isHexString(input, 20)) {
throw new Error(`expected input to be an address: ${input}`)
} else {
return input as `0x${string}`
}
})
export const validators = { export const validators = {
str, str,
bool, bool,
...@@ -63,4 +71,5 @@ export const validators = { ...@@ -63,4 +71,5 @@ export const validators = {
jsonRpcProvider, jsonRpcProvider,
staticJsonRpcProvider, staticJsonRpcProvider,
logLevel, logLevel,
address,
} }
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