From 08c573f53913f5ed2fec76f222671dd33ed479e0 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Thu, 29 Feb 2024 20:19:18 +0000 Subject: [PATCH] feat: terminator agent --- configs/stable_pool.toml | 5 ++++- src/behaviors/mod.rs | 3 +++ src/behaviors/terminator.rs | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/behaviors/terminator.rs diff --git a/configs/stable_pool.toml b/configs/stable_pool.toml index f219801..c3ec8a2 100644 --- a/configs/stable_pool.toml +++ b/configs/stable_pool.toml @@ -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 } \ No newline at end of file +PriceChanger = { mu = 1, theta = 1, sigma = 1, cursor = 0, value = 1, seed = 69 } + +[[terminator]] +Terminator = { steps = 10, current_step = 1 } \ No newline at end of file diff --git a/src/behaviors/mod.rs b/src/behaviors/mod.rs index 068dd40..82ebba1 100644 --- a/src/behaviors/mod.rs +++ b/src/behaviors/mod.rs @@ -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), } diff --git a/src/behaviors/terminator.rs b/src/behaviors/terminator.rs new file mode 100644 index 0000000..46060e6 --- /dev/null +++ b/src/behaviors/terminator.rs @@ -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 for Terminator { + async fn startup( + &mut self, + _client: Arc, + messager: Messager, + ) -> Result>> { + Ok(Some(messager.clone().stream().unwrap())) + } + + async fn process(&mut self, event: Message) -> Result { + if self.current_step >= self.steps { + return Ok(ControlFlow::Halt); + } + + let _query: PriceUpdate = match serde_json::from_str::(&event.data) { + Ok(_) => { + self.current_step += 1; + return Ok(ControlFlow::Continue); + } + Err(_) => { + return Ok(ControlFlow::Continue); + } + }; + } +}