Skip to content

Commit

Permalink
feat: broadcast deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu committed Feb 17, 2024
1 parent 7027afb commit c80c735
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
clap = { version = "4.4.8", features = ["derive"] }
serde_json = "1.0.113"
36 changes: 33 additions & 3 deletions src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,15 +38,15 @@ impl Behavior<()> for Deployer {
async fn startup(
&mut self,
client: Arc<ArbiterMiddleware>,
_messager: Messager,
messager: Messager,
) -> Result<Option<EventStream<()>>> {
let token_0 = ArbiterToken::deploy(
client.clone(),
(String::from("Token 0"), String::from("0"), 18),
)?
.send()
.await?;

let token_1 = ArbiterToken::deploy(
client.clone(),
(String::from("Token 1"), String::from("1"), 18),
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/behaviors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use serde::{Deserialize, Serialize};

pub mod deployer;

pub use deployer::Deployer;
pub use deployer::Deployer;

0 comments on commit c80c735

Please sign in to comment.