From c80c73583ddcc4b5dea7fef0e44ac5ce07f69f02 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:40:35 +0000 Subject: [PATCH] feat: broadcast deployment --- Cargo.toml | 3 ++- src/behaviors/deployer.rs | 36 +++++++++++++++++++++++++++++++++--- src/behaviors/mod.rs | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3ca5e1..897087b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ ethers = { version = "2.0.10" } serde = { version = "1.0.189", features = ["derive"] } anyhow = { version = "1.0.79" } async-trait = "0.1.74" -clap = { version = "4.4.8", features = ["derive"] } \ No newline at end of file +clap = { version = "4.4.8", features = ["derive"] } +serde_json = "1.0.113" diff --git a/src/behaviors/deployer.rs b/src/behaviors/deployer.rs index 2ee4769..0d8faa5 100644 --- a/src/behaviors/deployer.rs +++ b/src/behaviors/deployer.rs @@ -4,12 +4,32 @@ use anyhow::Result; use arbiter_core::middleware::ArbiterMiddleware; use arbiter_engine::{ machine::{Behavior, EventStream}, - messager::Messager, + messager::{Messager, To}, }; +use ethers::types::H160; use super::*; use crate::bindings::{token::ArbiterToken, uniswap_v3_factory::UniswapV3Factory}; +#[derive(Debug, Deserialize, Serialize)] +pub struct DeploymentData { + token_0: H160, + token_1: H160, + factory: H160, + pool: H160, +} + +impl DeploymentData { + pub fn new(token_0: H160, token_1: H160, factory: H160, pool: H160) -> Self { + Self { + token_0, + token_1, + factory, + pool, + } + } +} + #[derive(Debug, Deserialize, Serialize)] pub struct Deployer; @@ -18,7 +38,7 @@ impl Behavior<()> for Deployer { async fn startup( &mut self, client: Arc, - _messager: Messager, + messager: Messager, ) -> Result>> { let token_0 = ArbiterToken::deploy( client.clone(), @@ -26,7 +46,7 @@ impl Behavior<()> for Deployer { )? .send() .await?; - + let token_1 = ArbiterToken::deploy( client.clone(), (String::from("Token 1"), String::from("1"), 18), @@ -41,6 +61,16 @@ impl Behavior<()> for Deployer { .call() .await?; + // Construct a data object that all other behaviours will recieve containing requisites for simulation. + let deployment_data = DeploymentData::new( + token_0.address(), + token_1.address(), + factory.address(), + pool, + ); + + messager.send(To::All, serde_json::to_string(&deployment_data)?).await; + Ok(None) } } diff --git a/src/behaviors/mod.rs b/src/behaviors/mod.rs index 38b8105..e6dbeac 100644 --- a/src/behaviors/mod.rs +++ b/src/behaviors/mod.rs @@ -2,4 +2,4 @@ use serde::{Deserialize, Serialize}; pub mod deployer; -pub use deployer::Deployer; +pub use deployer::Deployer; \ No newline at end of file