diff --git a/kit/src/behaviors/swap/mod.rs b/kit/src/behaviors/swap/mod.rs index 0421d391..c9b91816 100644 --- a/kit/src/behaviors/swap/mod.rs +++ b/kit/src/behaviors/swap/mod.rs @@ -16,6 +16,28 @@ where pub _phantom: PhantomData, } +pub trait SwapStream where E: Send + 'static { + fn get_typed_stream(swap_type: SwapType, channel: Messager, client: Arc) -> Result>>; +} + + +#[derive(Deserialize, Clone)] +pub struct SwapOnce { + pub amount: eU256, + pub input: InputToken, +} + + +impl SwapStream for Swap, SwapOnce, Message> +where + P: PoolType + Send + Sync, +{ + fn get_typed_stream(swap_type: SwapOnce, channel: Messager, client: Arc) -> Result>> { + let thing = channel.stream()?; + Ok(Some(thing)) + } +} + // TODO: This needs to be configurable in some way to make the `SwapType` become // transparent and useful. // Should also get some data necessary for mint amounts and what not. @@ -46,7 +68,7 @@ where impl Behavior for Swap, T, E> where P: PoolType + Send + Sync, - T: SwapType + Send, + T: SwapType + Send + Clone, E: Send + 'static, { type Processor = Swap, T, E>; @@ -125,11 +147,12 @@ where impl Processor for Swap, T, E> where P: PoolType + Send + Sync, - T: SwapType + Send, + T: SwapType + Send + Clone, E: Send + 'static, + Swap, T, E>: SwapStream, { async fn get_stream(&mut self) -> Result>> { - todo!("We have not implemented the 'get_stream' method yet for the 'Swap' behavior.") + behaviors::swap::Swap::, T, E>::get_typed_stream(self.swap_type.clone(), self.data.messager.clone(), self.data.client) } async fn process(&mut self, event: E) -> Result { let (swap_amount, input) = self.swap_type.compute_swap_amount(event); diff --git a/kit/tests/common.rs b/kit/tests/common.rs index a6897cfb..18601f2f 100644 --- a/kit/tests/common.rs +++ b/kit/tests/common.rs @@ -1,23 +1,26 @@ use std::{collections::VecDeque, marker::PhantomData}; -use arbiter_engine::{agent::Agent, messager::Message, world::World}; +use arbiter_core::middleware::ArbiterMiddleware; +use arbiter_engine::{agent::Agent, machine::State, messager::{Message, Messager}, world::World}; use dfmm_kit::{ behaviors::{ creator::{self, Create}, deploy::Deploy, - swap::{self, Swap, SwapType}, + swap::{self, Swap, SwapStream, SwapType}, token::{self, TokenAdmin}, update::{self, Update}, }, bindings::constant_sum_solver::ConstantSumParams, pool::{ constant_sum::{ConstantSumAllocationData, ConstantSumPool}, - BaseConfig, InputToken, PoolCreation, + BaseConfig, InputToken, }, TokenData, }; + +use anyhow::Result; use ethers::types::{Address as eAddress, U256 as eU256}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use tracing::Level; use tracing_subscriber::FmtSubscriber; @@ -106,6 +109,12 @@ impl SwapType for SwapOnce { (self.amount, self.input.clone()) } } +impl SwapStream for Swap where S: State{ + fn get_typed_stream(_swap_type: SwapOnce, mut channel: Messager, _client: Arc) -> Result>> { + let thing = channel.stream()?; + Ok(Some(thing)) + } +} fn mock_token_admin_behavior() -> TokenAdmin { TokenAdmin:: {