From 78c0032d1f3551020c7c5e582b2f243f96b3bbb5 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Thu, 22 Feb 2024 21:37:25 -0700 Subject: [PATCH] feat: using main macro There are some debug prints in here right now as I'm seeing that this is not running properly. --- Cargo.toml | 11 ++-- configs/example.toml | 2 +- src/behaviors/deployer.rs | 131 +++++++++++++++++++------------------- src/behaviors/mod.rs | 8 ++- src/main.rs | 34 ++++++---- 5 files changed, 103 insertions(+), 83 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 897087b..00af782 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,14 @@ edition = "2021" [dependencies] tracing = "0.1.40" tracing-subscriber = "0.3.18" -arbiter-core = { version = "0.10.1" } -arbiter-macros = { version = "0.1.1" } -arbiter-engine = { version = "0.3.0" } +arbiter-bindings = "0.1.6" +arbiter-core = "0.10.3" +arbiter-macros = "0.1.3" +arbiter-engine = "0.3.1" tokio = { version = "1.36.0", features = ["full"] } -ethers = { version = "2.0.10" } +ethers = "2.0.10" serde = { version = "1.0.189", features = ["derive"] } -anyhow = { version = "1.0.79" } +anyhow = "1.0.79" async-trait = "0.1.74" clap = { version = "4.4.8", features = ["derive"] } serde_json = "1.0.113" diff --git a/configs/example.toml b/configs/example.toml index d1b5df6..bf2cd89 100644 --- a/configs/example.toml +++ b/configs/example.toml @@ -1,2 +1,2 @@ [[my_agent]] -Incrementer = { max_number_of_times = 5 } +Deployer = {} diff --git a/src/behaviors/deployer.rs b/src/behaviors/deployer.rs index 67882ed..7afcc2e 100644 --- a/src/behaviors/deployer.rs +++ b/src/behaviors/deployer.rs @@ -7,11 +7,11 @@ use arbiter_engine::{ messager::{Messager, To}, }; use ethers::types::H160; +use tracing::debug; use super::*; -use crate::bindings::{ - liquid_exchange::LiquidExchange, token::ArbiterToken, uniswap_v3_factory::UniswapV3Factory, -}; +use crate::bindings::uniswap_v3_factory::UniswapV3Factory; +use arbiter_bindings::bindings::{arbiter_token::ArbiterToken, liquid_exchange::LiquidExchange}; #[derive(Debug, Deserialize, Serialize)] pub struct DeploymentData { @@ -41,7 +41,7 @@ impl DeploymentData { } #[derive(Debug, Deserialize, Serialize)] -pub struct Deployer; +pub struct Deployer {} #[async_trait::async_trait] impl Behavior<()> for Deployer { @@ -50,15 +50,24 @@ impl Behavior<()> for Deployer { client: Arc, messager: Messager, ) -> Result>> { - let token_0 = self.deploy_token(&client, "Token 0", "0").await?; - let token_1 = self.deploy_token(&client, "Token 1", "1").await?; - - let factory = self.deploy_factory(&client).await?; - let liquid_exchange = self.deploy_liquid_exchange(&client).await?; + println!("Prior to token deployment."); + let token_0 = + ArbiterToken::deploy(client.clone(), ("Token 0".to_owned(), "TKN".to_owned(), 18))? + .send() + .await?; + println!("Deployed token 0"); + let token_1 = ArbiterToken::deploy( + client.clone(), + ("Token 1".to_owned(), "TKN0".to_owned(), 18), + )? + .send() + .await?; + println!("Deployed tokens"); + let factory = deploy_factory(&client).await?; + let liquid_exchange = deploy_liquid_exchange(&client).await?; - let pool = self - .create_pool(&factory, token_0.address(), token_1.address()) - .await?; + let pool = create_pool(&factory, token_0.address(), token_1.address()).await?; + println!("Got here."); let deployment_data = DeploymentData { token_0: token_0.address(), @@ -68,66 +77,60 @@ impl Behavior<()> for Deployer { pool, }; - let _ = messager + println!("Deployment data: {:?}", deployment_data); + messager .send(To::All, serde_json::to_string(&deployment_data)?) - .await; + .await?; + debug!("Sent deployment data: {:?}", deployment_data); Ok(None) } } -impl Deployer { - async fn deploy_token( - &self, - client: &Arc, - name: &str, - symbol: &str, - ) -> Result> { - ArbiterToken::deploy( - client.clone(), - (String::from(name), String::from(symbol), 18), - ) - .map_err(|e| anyhow!("Failed to deploy token {}: {}", name, e))? +async fn deploy_token( + client: Arc, + name: &str, + symbol: &str, +) -> Result> { + println!("In here."); + let thing = ArbiterToken::deploy( + client.clone(), + (String::from(name), String::from(symbol), 18), + )? + .send() + .await; + println!("Thing: {:?}", thing); + + Ok(thing?) +} + +async fn deploy_factory( + client: &Arc, +) -> Result> { + UniswapV3Factory::deploy(client.clone(), ()) + .map_err(|e| anyhow!("Failed to deploy factory: {}", e))? .send() .await - .map_err(|e| anyhow!("Failed to send token {}: {}", name, e)) - } - - async fn deploy_factory( - &self, - client: &Arc, - ) -> Result> { - UniswapV3Factory::deploy(client.clone(), ()) - .map_err(|e| anyhow!("Failed to deploy factory: {}", e))? - .send() - .await - .map_err(|e| anyhow!("Failed to send factory deployment: {}", e)) - } + .map_err(|e| anyhow!("Failed to send factory deployment: {}", e)) +} - async fn deploy_liquid_exchange( - &self, - client: &Arc, - ) -> Result> { - LiquidExchange::deploy(client.clone(), ()) - .map_err(|e| anyhow!("Failed to deploy liquid exchange: {}", e))? - .send() - .await - .map_err(|e| anyhow!("Failed to send liquid exchange: {}", e)) - } +async fn deploy_liquid_exchange( + client: &Arc, +) -> Result> { + LiquidExchange::deploy(client.clone(), ()) + .map_err(|e| anyhow!("Failed to deploy liquid exchange: {}", e))? + .send() + .await + .map_err(|e| anyhow!("Failed to send liquid exchange: {}", e)) +} - async fn create_pool( - &self, - factory: &UniswapV3Factory, - token_0: H160, - token_1: H160, - ) -> Result - where - M: ethers::providers::Middleware, - { - factory - .create_pool(token_0, token_1, 100) - .call() - .await - .map_err(|e| anyhow!("Failed to create pool: {}", e)) - } +async fn create_pool(factory: &UniswapV3Factory, token_0: H160, token_1: H160) -> Result +where + M: ethers::providers::Middleware, +{ + factory + .create_pool(token_0, token_1, 100) + .call() + .await + .map_err(|e| anyhow!("Failed to create pool: {}", e)) } diff --git a/src/behaviors/mod.rs b/src/behaviors/mod.rs index 38b8105..4fc66d1 100644 --- a/src/behaviors/mod.rs +++ b/src/behaviors/mod.rs @@ -1,5 +1,11 @@ +use arbiter_engine::machine::*; +use arbiter_macros::Behaviors; use serde::{Deserialize, Serialize}; pub mod deployer; +use deployer::Deployer; -pub use deployer::Deployer; +#[derive(Behaviors, Debug, Serialize, Deserialize)] +pub enum Behaviors { + Deployer(Deployer), +} diff --git a/src/main.rs b/src/main.rs index 0d778d6..7035f46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,26 @@ -use arbiter_engine::{agent::Agent, world::World}; - pub mod behaviors; pub mod bindings; -use crate::behaviors::Deployer; - -#[tokio::main] -async fn main() { - let mut world = World::new("univ3"); - - let deployer = Agent::builder("deployer").with_behavior(Deployer); +use crate::behaviors::Behaviors; - world.add_agent(deployer); - let _ = world.run().await; -} +/// To run this example, you can do the following from the project root directory: +/// ```sh +/// cargo run simulate configs/example.toml +/// ``` +/// If you would like to see more detailed logs, you can run the following: +/// ```sh +/// cargo run simulate configs/example.toml -vvv +/// ``` +/// to get `debug` level logs (the default with no verbosity is `ERROR`). +/// +/// By running +/// ```sh +/// cargo run +/// ``` +/// you will get the `--help` message for the project. +#[arbiter_macros::main( + name = "Uniswap V3 Simulation", + about = "Simulating Uniswap V3 with Arbiter", + behaviors = Behaviors +)] +async fn main() {}