Skip to content

Commit

Permalink
Revert "feat: using main macro"
Browse files Browse the repository at this point in the history
This reverts commit 78c0032.
  • Loading branch information
Autoparallel committed Feb 23, 2024
1 parent 78c0032 commit 0fedb6c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 103 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ edition = "2021"
[dependencies]
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
arbiter-bindings = "0.1.6"
arbiter-core = "0.10.3"
arbiter-macros = "0.1.3"
arbiter-engine = "0.3.1"
arbiter-core = { version = "0.10.1" }
arbiter-macros = { version = "0.1.1" }
arbiter-engine = { version = "0.3.0" }
tokio = { version = "1.36.0", features = ["full"] }
ethers = "2.0.10"
ethers = { version = "2.0.10" }
serde = { version = "1.0.189", features = ["derive"] }
anyhow = "1.0.79"
anyhow = { version = "1.0.79" }
async-trait = "0.1.74"
clap = { version = "4.4.8", features = ["derive"] }
serde_json = "1.0.113"
2 changes: 1 addition & 1 deletion configs/example.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[[my_agent]]
Deployer = {}
Incrementer = { max_number_of_times = 5 }
131 changes: 64 additions & 67 deletions src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use arbiter_engine::{
messager::{Messager, To},
};
use ethers::types::H160;
use tracing::debug;

use super::*;
use crate::bindings::uniswap_v3_factory::UniswapV3Factory;
use arbiter_bindings::bindings::{arbiter_token::ArbiterToken, liquid_exchange::LiquidExchange};
use crate::bindings::{
liquid_exchange::LiquidExchange, token::ArbiterToken, uniswap_v3_factory::UniswapV3Factory,
};

#[derive(Debug, Deserialize, Serialize)]
pub struct DeploymentData {
Expand Down Expand Up @@ -41,7 +41,7 @@ impl DeploymentData {
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Deployer {}
pub struct Deployer;

#[async_trait::async_trait]
impl Behavior<()> for Deployer {
Expand All @@ -50,24 +50,15 @@ impl Behavior<()> for Deployer {
client: Arc<ArbiterMiddleware>,
messager: Messager,
) -> Result<Option<EventStream<()>>> {
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 token_0 = self.deploy_token(&client, "Token 0", "0").await?;
let token_1 = self.deploy_token(&client, "Token 1", "1").await?;

let pool = create_pool(&factory, token_0.address(), token_1.address()).await?;
println!("Got here.");
let factory = self.deploy_factory(&client).await?;
let liquid_exchange = self.deploy_liquid_exchange(&client).await?;

let pool = self
.create_pool(&factory, token_0.address(), token_1.address())
.await?;

let deployment_data = DeploymentData {
token_0: token_0.address(),
Expand All @@ -77,60 +68,66 @@ impl Behavior<()> for Deployer {
pool,
};

println!("Deployment data: {:?}", deployment_data);
messager
let _ = messager
.send(To::All, serde_json::to_string(&deployment_data)?)
.await?;
debug!("Sent deployment data: {:?}", deployment_data);
.await;

Ok(None)
}
}

async fn deploy_token(
client: Arc<ArbiterMiddleware>,
name: &str,
symbol: &str,
) -> Result<ArbiterToken<ArbiterMiddleware>> {
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<ArbiterMiddleware>,
) -> Result<UniswapV3Factory<ArbiterMiddleware>> {
UniswapV3Factory::deploy(client.clone(), ())
.map_err(|e| anyhow!("Failed to deploy factory: {}", e))?
impl Deployer {
async fn deploy_token(
&self,
client: &Arc<ArbiterMiddleware>,
name: &str,
symbol: &str,
) -> Result<ArbiterToken<ArbiterMiddleware>> {
ArbiterToken::deploy(
client.clone(),
(String::from(name), String::from(symbol), 18),
)
.map_err(|e| anyhow!("Failed to deploy token {}: {}", name, e))?
.send()
.await
.map_err(|e| anyhow!("Failed to send factory deployment: {}", e))
}
.map_err(|e| anyhow!("Failed to send token {}: {}", name, e))
}

async fn deploy_liquid_exchange(
client: &Arc<ArbiterMiddleware>,
) -> Result<LiquidExchange<ArbiterMiddleware>> {
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_factory(
&self,
client: &Arc<ArbiterMiddleware>,
) -> Result<UniswapV3Factory<ArbiterMiddleware>> {
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))
}

async fn create_pool<M>(factory: &UniswapV3Factory<M>, token_0: H160, token_1: H160) -> Result<H160>
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 deploy_liquid_exchange(
&self,
client: &Arc<ArbiterMiddleware>,
) -> Result<LiquidExchange<ArbiterMiddleware>> {
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<M>(
&self,
factory: &UniswapV3Factory<M>,
token_0: H160,
token_1: H160,
) -> Result<H160>
where
M: ethers::providers::Middleware,
{
factory
.create_pool(token_0, token_1, 100)
.call()
.await
.map_err(|e| anyhow!("Failed to create pool: {}", e))
}
}
8 changes: 1 addition & 7 deletions src/behaviors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use arbiter_engine::machine::*;
use arbiter_macros::Behaviors;
use serde::{Deserialize, Serialize};

pub mod deployer;
use deployer::Deployer;

#[derive(Behaviors, Debug, Serialize, Deserialize)]
pub enum Behaviors {
Deployer(Deployer),
}
pub use deployer::Deployer;
34 changes: 12 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
use arbiter_engine::{agent::Agent, world::World};

pub mod behaviors;
pub mod bindings;

use crate::behaviors::Behaviors;
use crate::behaviors::Deployer;

#[tokio::main]
async fn main() {
let mut world = World::new("univ3");

let deployer = Agent::builder("deployer").with_behavior(Deployer);

/// 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() {}
world.add_agent(deployer);
let _ = world.run().await;
}

0 comments on commit 0fedb6c

Please sign in to comment.