Skip to content

Commit

Permalink
feat: deploy manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Aug 11, 2024
1 parent 3d9ee14 commit ac67b31
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use alloy::{providers::ProviderBuilder, signers::local::PrivateKeySigner};

use super::*;
use crate::{config::Config, feed::Feed, strategy::Strategy, types::PoolKey};
use crate::{config::Config, feed::Feed, strategy::Strategy, types::PoolManager::PoolKey, types::PoolManager};

pub struct Arena {
pub env: AnvilInstance,
Expand All @@ -15,14 +15,16 @@ pub struct Arena {
}

impl Arena {
pub fn run(&mut self, config: Config) {
pub async fn run(&mut self, config: Config) {
let pool_manager = PoolManager::deploy(self.providers[&0].clone(), U256::from(0)).await;

for (idx, strategy) in self.strategies.iter_mut().enumerate() {
strategy.init(self.providers[&idx].clone());
strategy.init(self.providers[&(idx + 1)].clone());
}

for step in 0..config.steps {
for (idx, strategy) in self.strategies.iter_mut().enumerate() {
strategy.process(self.providers[&idx].clone());
strategy.process(self.providers[&(idx + 1)].clone());
}

self.feed.step();
Expand Down Expand Up @@ -68,7 +70,7 @@ impl ArenaBuilder {
pub fn build(self) -> Arena {
let mut providers = HashMap::new();

for i in 0..10 {
for i in 0..9 {
let signer: PrivateKeySigner = self.env.keys()[i].clone().into();
let wallet = EthereumWallet::from(signer);

Expand All @@ -79,7 +81,7 @@ impl ArenaBuilder {
.wallet(wallet)
.on_http(rpc_url);

providers.insert(i, provider).unwrap();
providers.insert(i, provider);
}

Arena {
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
pub struct Config {
pub steps: usize,
}

impl Config {
pub fn new(steps: usize) -> Self {
Config { steps }
}
}
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ pub mod config;
pub mod feed;
pub mod strategy;
pub mod types;
use crate::arena::ArenaBuilder;
use crate::strategy::Strategy;
use crate::types::PoolManager::PoolKey;
use crate::config::Config;
use crate::feed::OrnsteinUhlenbeck;

use alloy::{
network::{Ethereum, EthereumWallet},
Expand All @@ -12,6 +17,7 @@ use alloy::{
Identity, RootProvider,
},
transports::http::{Client, Http},
primitives::{U256, Address},
};

pub type AnvilProvider = FillProvider<
Expand All @@ -23,3 +29,34 @@ pub type AnvilProvider = FillProvider<
Http<Client>,
Ethereum,
>;

#[cfg(test)]
mod tests {
use super::*;

struct StrategyMock;

impl Strategy for StrategyMock {
fn init(&self, _provider: AnvilProvider) {}
fn process(&self, _provider: AnvilProvider) {}
}

#[tokio::test]
async fn test_arena() {
let builder = ArenaBuilder::new();

let mut arena = builder
.with_strategy(Box::new(StrategyMock {}))
.with_pool(PoolKey {
currency0: Address::default(),
currency1: Address::default(),
fee: 4000,
tickSpacing: 2,
hooks: Address::default(),
})
.with_feed(Box::new(OrnsteinUhlenbeck::new(0.1, 0.1, 0.1, 0.1, 0.1)))
.build();

arena.run(Config::new(0)).await;
}
}

0 comments on commit ac67b31

Please sign in to comment.