Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: terminator agent #29

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};
}
}
Loading