Skip to content

Commit

Permalink
feat: add template strategy example
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Sep 21, 2024
1 parent 49ec16f commit 9430330
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ alloy-sol-macro = "0.8.0"
alloy-sol-types = "0.8.0"
serde = { version = "1.0", features = ["derive"] }
clap = { version = "4.5.16", features = ["derive"] }
tokio = { version = "1.39.2", features = ["macros"] }
tokio = { version = "1.39.2", features = ["macros", "rt-multi-thread"] }
alloy = { version = "0.3.0", features = ["full", "node-bindings", "json"] }
alloy-chains = "0.1.29"
alloy-transport-http = "0.3.0"
83 changes: 83 additions & 0 deletions examples/template_strategy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use alloy::primitives::{Address, Bytes, Signed, Uint, I256};
use arena_core::{
arena::{Arena, ArenaBuilder},
config::Config,
engine::{
arbitrageur::FixedArbitrageur,
inspector::{EmptyInspector, Inspector},
Engine,
},
feed::OrnsteinUhlenbeck,
strategy::Strategy,
AnvilProvider, Signal,
};
use async_trait::async_trait;

struct StrategyMock;

#[async_trait]
impl<T> Strategy<T> for StrategyMock {
async fn init(
&self,
provider: AnvilProvider,
_signal: Signal,
_inspector: &mut Box<dyn Inspector<T>>,
engine: Engine,
) {
// provide a fixed amount of liquidity upon runtime initialization to the pool across the full tick range.
engine
.modify_liquidity(
I256::try_from(10000000).unwrap(),
Signed::try_from(-887272).unwrap(),
Signed::try_from(887272).unwrap(),
Bytes::new(),
provider,
)
.await
.unwrap();
}
async fn process(
&self,
_provider: AnvilProvider,
_signal: Signal,
_inspector: &mut Box<dyn Inspector<T>>,
_engine: Engine,
) {
}
}

#[tokio::main]
async fn main() {
let builder: ArenaBuilder<_> = ArenaBuilder::new();

let mut arena: Arena<_> = builder
.with_strategy(Box::new(StrategyMock))
.with_feed(Box::new(OrnsteinUhlenbeck::new(1.0, 0.1, 1.0, 0.1, 0.1)))
.with_inspector(Box::new(EmptyInspector {}))
.with_arbitrageur(Box::new(FixedArbitrageur {
depth: Signed::try_from(10000).unwrap(),
}))
.build();

arena
.run(Config::new(
// timesteps to run for
10,
// manager fee
Uint::from(0),
// pool tick spacing
Signed::try_from(2).unwrap(),
// hook data
Bytes::new(),
// sqrtpricex96
Uint::from(79228162514264337593543950336_u128),
// pool fee
Uint::from(0),
// initial price
Uint::from(1),
// hook contract
Address::ZERO,
))
.await
.unwrap();
}
1 change: 0 additions & 1 deletion src/artifacts/Fetcher.json

This file was deleted.

10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ pub type AnvilProvider = FillProvider<
>;

mod types {
pub mod fetcher {
use alloy_sol_macro::sol;
sol! {
#[sol(rpc)]
#[derive(Debug)]
Fetcher,
"src/artifacts/Fetcher.json"
}
}

pub mod controller {
use alloy_sol_macro::sol;
sol! {
Expand Down

0 comments on commit 9430330

Please sign in to comment.