Skip to content

Commit

Permalink
feat: terminator agent (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Mar 1, 2024
1 parent 415757d commit a4d7acc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion configs/stable_pool.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ PoolAdmin = {}
TokenAdmin = { token_data.TKN0 = { name = "TKN0", symbol = "Token 0", decimals = 18 } }

[[changer]]
PriceChanger = { mu = 1, theta = 1, sigma = 1, cursor = 0, value = 1, seed = 69 }
PriceChanger = { mu = 1, theta = 1, sigma = 1, cursor = 0, value = 1, seed = 69 }

[[terminator]]
Terminator = { steps = 10, current_step = 1 }
3 changes: 3 additions & 0 deletions src/behaviors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ use serde::{Deserialize, Serialize};
pub mod deployer;
pub mod pool_admin;
pub mod price_changer;
pub mod terminator;
pub mod token_admin;

use deployer::Deployer;
use pool_admin::PoolAdmin;
use price_changer::PriceChanger;
use terminator::Terminator;
use token_admin::TokenAdmin;

#[derive(Behaviors, Debug, Serialize, Deserialize)]
pub enum Behaviors {
Deployer(Deployer),
TokenAdmin(TokenAdmin),
Terminator(Terminator),
PoolAdmin(PoolAdmin),
PriceChanger(PriceChanger),
}
41 changes: 41 additions & 0 deletions src/behaviors/terminator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::sync::Arc;

use anyhow::Result;
use arbiter_core::middleware::ArbiterMiddleware;
use arbiter_engine::messager::{Message, Messager};

use super::*;
use crate::behaviors::price_changer::PriceUpdate;

#[derive(Debug, Deserialize, Serialize)]
pub struct Terminator {
pub steps: usize,
pub current_step: usize,
}

#[async_trait::async_trait]
impl Behavior<Message> for Terminator {
async fn startup(
&mut self,
_client: Arc<ArbiterMiddleware>,
messager: Messager,
) -> Result<Option<EventStream<Message>>> {
Ok(Some(messager.clone().stream().unwrap()))
}

async fn process(&mut self, event: Message) -> Result<ControlFlow> {
if self.current_step >= self.steps {
return Ok(ControlFlow::Halt);
}

let _query: PriceUpdate = match serde_json::from_str::<PriceUpdate>(&event.data) {
Ok(_) => {
self.current_step += 1;
return Ok(ControlFlow::Continue);
}
Err(_) => {
return Ok(ControlFlow::Continue);
}
};
}
}

0 comments on commit a4d7acc

Please sign in to comment.