Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP Stack update #8

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/monitor_events/networks/base_sepolia.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "base_sepolia",
"l1_contract": "0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254",
"l1_contract": "0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1",
"block_delay": 20,
"poll_period_sec": 10800,
"batch_size": 50000,
"l1_contract_deployment_block": 4370901
"l1_contract_deployment_block": 6189927
}
4 changes: 2 additions & 2 deletions crates/monitor_events/networks/optimism_sepolia.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "optimism_sepolia",
"l1_contract": "0x90E9c4f8a994a250F6aEfd61CAFb4F2e895D458F",
"l1_contract": "0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1",
"block_delay": 20,
"poll_period_sec": 10800,
"batch_size": 50000,
"l1_contract_deployment_block": 4071248
"l1_contract_deployment_block": 5515308
}
42 changes: 30 additions & 12 deletions crates/monitor_events/src/opstack.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use ethers::prelude::*;
use std::sync::Arc;

use ethers::{prelude::*, utils::*};

pub struct OPStackParameters {
l2_output_root: Bytes,
l2_output_index: U256,
l1_game_address: String,
l2_block_number: U256,
l1_timestamp: U256,
l1_transaction_hash: Bytes,
Expand Down Expand Up @@ -50,7 +52,7 @@ pub async fn create_opstack_table_if_not_exists(
"CREATE TABLE IF NOT EXISTS {} (
id SERIAL PRIMARY KEY,
l2_output_root VARCHAR NOT NULL,
l2_output_index INTEGER NOT NULL,
l1_game_address VARCHAR NOT NULL,
l2_block_number INTEGER NOT NULL,
l1_timestamp INTEGER NOT NULL,
l1_transaction_hash VARCHAR NOT NULL,
Expand All @@ -71,7 +73,7 @@ pub async fn create_opstack_table_if_not_exists(
/// * table_name: The name of the postgres table
/// * client: The postgres client
/// * l2_output_root: The output root of the l2
/// * l2_output_index: The output index of the l2
/// * l1_game_address: The contract address of FaultDisputeGame
/// * l2_block_number: The block number of the l2
/// * l1_timestamp: The timestamp of the l1
/// * l1_transaction_hash: The transaction hash of the l1
Expand All @@ -85,13 +87,13 @@ pub async fn insert_into_postgres(
client: &tokio_postgres::Client,
params: OPStackParameters,
) -> Result<(), tokio_postgres::Error> {
let insert_query = format!("INSERT INTO {} (l2_output_root, l2_output_index, l2_block_number, l1_timestamp, l1_transaction_hash, l1_block_number, l1_transaction_index, l1_block_hash) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", table_name);
let insert_query = format!("INSERT INTO {} (l2_output_root, l1_game_address, l2_block_number, l1_timestamp, l1_transaction_hash, l1_block_number, l1_transaction_index, l1_block_hash) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", table_name);
client
.execute(
&insert_query,
&[
&params.l2_output_root.to_string(),
&(params.l2_output_index.as_u64() as i32),
&(params.l1_game_address.to_string()),
&(params.l2_block_number.as_u64() as i32),
&(params.l1_timestamp.as_u64() as i32),
&params.l1_transaction_hash.to_string(),
Expand All @@ -105,23 +107,39 @@ pub async fn insert_into_postgres(
Ok(())
}

pub fn handle_opstack_events(log: &Log) -> OPStackParameters {
let l2_output_root = Bytes::from(log.topics[1].as_bytes().to_vec());
let l2_output_index = U256::from_big_endian(log.topics[2].as_bytes());
let l2_block_number = U256::from_big_endian(log.topics[3].as_bytes());
pub async fn handle_opstack_events(log: &Log, client: &Arc<Provider<Http>>) -> OPStackParameters {
let l1_game_address = Address::from(log.topics[1]);
let l2_output_root = Bytes::from(log.topics[3].as_bytes().to_vec());
let l1_timestamp = U256::from_big_endian(&log.data[..]);
let l1_transaction_hash = Bytes::from(log.transaction_hash.unwrap().as_bytes().to_vec());
let l1_block_number = log.block_number.unwrap();
let l1_transaction_index = log.transaction_index.unwrap();
let l1_block_hash = Bytes::from(log.block_hash.unwrap().as_bytes().to_vec());

let selector = id("l2BlockNumber()");

let block_number = client
.call_raw(
&TransactionRequest::default()
.from(H160::zero())
.to(l1_game_address)
.data(selector)
.into(),
)
.await
.unwrap();
let l2_block_number = U256::from_big_endian(&block_number);

//? We need to format the Address because without it, it is being inserted to db formatted like 0x1234…5678
let formatted_address = format!("0x{}", hex::encode(l1_game_address.as_bytes()));

println!(
"output_root = {l2_output_root}, l2OutputIndex = {l2_output_index}, l2BlockNumber = {l2_block_number}, l1Blocknumber = {l1_block_number}, l1Timestamp = {l1_timestamp}, l1_transaction_hash={l1_transaction_hash}, l1_transaction_index={l1_transaction_index}, L1_block_hash={l1_block_hash}"
"output_root = {l2_output_root}, l1GameAddress = {formatted_address}, l2BlockNumber = {l2_block_number}, l1Blocknumber = {l1_block_number}, l1Timestamp = {l1_timestamp}, l1_transaction_hash={l1_transaction_hash}, l1_transaction_index={l1_transaction_index}, L1_block_hash={l1_block_hash}"
);

OPStackParameters {
l2_output_root,
l2_output_index,
l1_game_address: formatted_address,
l2_block_number,
l1_timestamp,
l1_transaction_hash,
Expand Down
Loading