generated from anthias-labs/arbiter-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
966 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::settings::{SimulationConfig, parameters::Fixed}; | ||
|
||
use super::*; | ||
|
||
/// A structure representing a block admin agent. | ||
/// This agent is responsible for updating the block number and timestamp. | ||
#[derive(Clone)] | ||
pub struct BlockAdmin { | ||
/// A client to interface with arbiter's revm middleware. | ||
/// You can think of this as the agents wallet or EOA. | ||
pub client: Arc<RevmMiddleware>, | ||
|
||
/// The size of each timestep in the simulation, representing block time passage. | ||
pub timestep_size: u64, | ||
|
||
/// The current simulated block timestamp. | ||
pub block_timestamp: u64, | ||
|
||
/// The current simulated block number. | ||
pub block_number: u64, | ||
} | ||
|
||
impl BlockAdmin { | ||
/// Creates a new BlockAdmin using the provided environment and simulation configuration. | ||
/// | ||
/// # Arguments | ||
/// * [`Environment`] - The environment containing blockchain node information. | ||
/// * [`SimulationConfig<Fixed>`] - The simulation configuration providing block timestep size. | ||
/// | ||
/// # Returns | ||
/// * [`Result<Self>`] - A result containing the new BlockAdmin or an error. | ||
pub async fn new(environment: &Environment, config: &SimulationConfig<Fixed>) -> Result<Self> { | ||
let client = RevmMiddleware::new(environment, "block_admin".into())?; | ||
let timestep_size = config.block.timestep_size; | ||
let block_number = client.get_block_number().await?.as_u64(); | ||
let block_timestamp = client.get_block_timestamp().await?.as_u64(); | ||
|
||
Ok(Self { | ||
client, | ||
timestep_size, | ||
block_timestamp, | ||
block_number, | ||
}) | ||
} | ||
/// Updates the simulated block information. | ||
/// | ||
/// Increments the block number and calculates the new block timestamp based on the timestep size. | ||
/// | ||
/// # Returns | ||
/// * [`Result<()>`] - A result indicating the success or failure of the operation. | ||
pub fn update_block(&mut self) -> Result<()> { | ||
self.block_number += 1; | ||
self.block_timestamp = self.block_number * self.timestep_size; | ||
self.client | ||
.update_block(self.block_number, self.block_timestamp)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Agent for BlockAdmin { | ||
async fn step(&mut self) -> Result<()> { | ||
self.update_block()?; | ||
Ok(()) | ||
} | ||
async fn startup(&mut self) -> Result<()> { | ||
self.update_block()?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::*; | ||
|
||
pub struct DishonestPlayer { | ||
pub address: Address, | ||
pub client: RevmMiddleware, | ||
pub vm: AlphabetVM<RevmMiddleware>, | ||
pub oracle: L2OutputOracle<RevmMiddleware>, | ||
pub block_oracle: BlockOracle<RevmMiddleware>, | ||
pub disputegame: FaultDisputeGame<RevmMiddleware>, | ||
} | ||
|
||
impl DishonestPlayer { | ||
pub fn new() -> Self { | ||
todo!() | ||
} | ||
|
||
pub fn generate_dishonest_dispute() { | ||
todo!() | ||
} | ||
|
||
pub fn start_game_with_dishonest_dispute() { | ||
todo!() | ||
} | ||
|
||
pub fn step() { | ||
// randomly chose a move to make: attack, defend, or step | ||
// randomly select a value in some range to has as move's claim | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use super::*; | ||
|
||
use crate::settings::{SimulationConfig, parameters::Fixed}; | ||
pub mod block_admin; | ||
use std::sync::Arc; | ||
use arbiter_core::environment::Environment; | ||
use arbiter_core::middleware::RevmMiddleware; | ||
use ethers::providers::Middleware; | ||
// use settings::SimulationConfig; | ||
use std::marker::{Send, Sync}; | ||
use alloy_primitives::Address; | ||
use durin_fault::{ | ||
providers::AlphabetTraceProvider, AlphaClaimSolver, FaultDisputeSolver, FaultDisputeState, | ||
}; | ||
use foundry_contracts::{ | ||
alphabet_vm::AlphabetVM, block_oracle::BlockOracle, fault_dispute_game::FaultDisputeGame, | ||
l2_output_oracle::L2OutputOracle, | ||
}; | ||
|
||
// use crate::settings::parameters::Fixed; | ||
|
||
/// Universal agent methods for interacting with the simulation environment or | ||
/// loop. | ||
/// Agents are expected to be both [`Send`] and [`Sync`]. | ||
#[async_trait::async_trait] | ||
pub trait Agent: Sync + Send { | ||
/// Executed outside the main simulation loop. | ||
async fn startup(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
/// Executed by each agent inside the main simulation loop. | ||
/// Ordering is determined by placement in the simulation loop. | ||
async fn step(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
/// Executed by each agent in a separate loop before the main loop. | ||
async fn priority_step(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
/// A collection of agents that can be operated on collectively. | ||
pub struct Agents(pub Vec<Box<dyn Agent>>); | ||
|
||
impl Agents { | ||
/// Returns a mutable iterator over the agents. | ||
/// This can be used to invoke methods on each agent individually. | ||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Box<dyn Agent>> { | ||
self.0.iter_mut() | ||
} | ||
} | ||
|
||
impl Agents { | ||
/// Constructs a new [`Agents`] collection. | ||
/// This static method provides a way to create a new collection of agents. | ||
#[allow(clippy::new_without_default)] | ||
pub fn new() -> Self { | ||
Self(vec![]) | ||
} | ||
|
||
/// Adds a new agent to the collection. | ||
/// This method takes ownership of the agent and adds it to the collection. | ||
#[allow(clippy::should_implement_trait)] | ||
pub fn add(mut self, agent: impl Agent + 'static) -> Self { | ||
self.0.push(Box::new(agent)); | ||
self | ||
} | ||
} | ||
|
||
/// [`Agent`] trait implementation for a collection of agents. | ||
/// This allows collective operations on the group of agents. | ||
#[async_trait::async_trait] | ||
impl Agent for Agents { | ||
/// Implementation of the `step` method for the collection. | ||
/// This allows the collection to forward the step action to each agent. | ||
async fn step(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
/// Implementation of the `priority_step` method for the collection. | ||
/// This allows the collection to forward the priority step action to each agent. | ||
async fn priority_step(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
simulation = "dispute_game" | ||
output_directory = "analysis/dispute_game" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.