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

Feat: eth_simulateV1 Request / Response types #1042

Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ pub mod geth;
pub mod opcode;
pub mod otterscan;
pub mod parity;
pub mod simulate;
pub mod tracerequest;
75 changes: 75 additions & 0 deletions crates/rpc-types-trace/src/simulate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! 'eth_simulateV1' Request / Response types

use alloy_primitives::{Bytes, Log, B256, U64};
use alloy_rpc_types_eth::{state::StateOverride, BlockOverrides, Header, TransactionRequest};
use serde::{Deserialize, Serialize};

/// The maximum number of blocks that can be simulated in a single request,
pub const MAX_SIMULATE_BLOCKS: U64 = U64::from_limbs([256_u64]);
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved

/// Represents a batch of calls to be simulated sequentially within a block.
/// This struct includes block and state overrides as well as the transaction requests to be
/// executed.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimBlock {
/// Modifications to the default block characteristics.
pub block_overrides: BlockOverrides,
/// State modifications to apply before executing the transactions.
pub state_overrides: StateOverride,
/// A vector of transactions to be simulated.
pub calls: Vec<TransactionRequest>,
}

/// Captures the outcome of a transaction simulation.
/// It includes the return value, logs produced, gas used, and the status of the transaction.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimCallResult {
/// The raw bytes returned by the transaction.
pub return_value: Bytes,
/// Logs generated during the execution of the transaction.
pub logs: Vec<Log>,
/// The amount of gas used by the transaction.
pub gas_used: U64,
/// The final status of the transaction, typically indicating success or failure.
pub status: U64,
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
//what we should use here ?
//Error *callError `json:"error,omitempty"`
}

/// Simulation options for executing multiple blocks and transactions.
/// This struct configures how simulations are executed, including whether to trace token transfers,
/// validate transaction sequences, and whether to return full transaction objects.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimOpts {
/// A vector of simulated blocks each containing state and transaction overrides.
pub block_state_calls: Vec<SimBlock>,
/// Flag to determine whether to trace ERC20/ERC721 token transfers within transactions.
pub trace_transfers: bool,
/// Flag to enable or disable validation of the transaction sequence in the blocks.
pub validation: bool,
/// Flag to decide if full transactions should be returned instead of just their outcomes.
pub return_full_transactions: bool,
}

/// Represents a simulator backend to handle state and transaction processing.
#[derive(Clone, Debug)]
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
pub struct Simulator {
//What we should use here for backend ?
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
//b Backend
/// List of hashes representing the blocks to be simulated.
pub hashes: Vec<B256>,
// should we use StadeDB of revm here ?
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved

// state *state.StateDB
/// The base block header from which the simulation starts.
pub base: Header,
/// Indicates whether ERC20/ERC721 token transfers are traced.
pub trace_transfers: bool,
/// Indicates whether transaction validation is performed.
pub validate: bool,
/// Indicates whether full transaction details are returned.
pub full_tx: bool,
}
Loading