Skip to content

Commit

Permalink
wip: Save
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Apr 10, 2024
1 parent 4305fbb commit 9b74e54
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 530 deletions.
531 changes: 255 additions & 276 deletions Cargo.lock

Large diffs are not rendered by default.

208 changes: 106 additions & 102 deletions kit/src/behaviors/allocate.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use std::marker::PhantomData;
// use std::marker::PhantomData;

use arbiter_core::events::stream_event;
use arbiter_engine::machine::{Configuration, ControlFlow, Processing, Processor, State};
// use arbiter_core::events::stream_event;
// use arbiter_engine::machine::{Configuration, ControlFlow, Processing, Processor, State};

use self::{
pool::PoolType,
token_admin::{MintRequest, TokenAdminQuery},
};
use super::*;
// use self::{
// pool::PoolType,
// token_admin::{MintRequest, TokenAdminQuery},
// };
// use super::*;

// Notes:
// * The point of this function is to have the event piped to it from the
// behavior/processor and this just dictates how, based on some event, we want
// to change the allocation we have (or will have) in a pool.
trait AllocationType<P, E>
where
P: PoolType,
{
fn change_allocation_amount(&self, event: E) -> Option<P::AllocationData>;
}
// trait AllocationType<P, E>
// where
// P: PoolType,
// E: Send + 'static,
// {
// fn change_allocation_amount(&self, event: E) -> Option<P::AllocationData>;
// }

// Notes:
// * The idea here is that the `ChangeAllocation` is generic over everything it
Expand Down Expand Up @@ -49,99 +50,102 @@ where
// Configuration>` since this should be Deserializable.
//
// Some more notes:
#[derive(Debug, Serialize, Deserialize)]
struct ChangeAllocation<A, P, E, S>
where
A: AllocationType<P, E>,
P: PoolType,
S: State,
{
// APES LOL
_phantom_a: PhantomData<A>,
_phantom_p: PhantomData<P>,
_phantom_e: PhantomData<E>,
pub data: S::Data,
}
// #[derive(Debug, Serialize, Deserialize)]
// struct ChangeAllocation<A, P, E, S>
// where
// A: AllocationType<P, E>,
// P: PoolType,
// E: Send + 'static,
// S: State,
// {
// // APES LOL
// _phantom_a: PhantomData<A>,
// _phantom_p: PhantomData<P>,
// _phantom_e: PhantomData<E>,
// pub data: S::Data,
// }

// This `ChangeAllocationStructData` will be the `D` in `S == Processing<D>`
pub struct ChangeAllocationStructData<A, P, E>
where
A: AllocationType<P, E>,
P: PoolType,
{
pub client: Arc<ArbiterMiddleware>,
pub pool: P,
pub allocation_data: P::AllocationData,
pub allocation_type: A,
_phantom: PhantomData<E>,
}
// // This `ChangeAllocationStructData` will be the `D` in `S == Processing<D>`
// pub struct ChangeAllocationStructData<A, P, E>
// where
// A: AllocationType<P, E>,
// P: PoolType,
// E: Send + 'static,
// {
// pub client: Arc<ArbiterMiddleware>,
// pub pool: P,
// pub allocation_data: P::AllocationData,
// pub allocation_type: A,
// _phantom: PhantomData<E>,
// }

impl<A, P, E, S> AllocationType<P, E> for ChangeAllocation<A, P, E, S>
where
A: AllocationType<P, E>,
P: PoolType,
S: State,
{
fn change_allocation_amount(&self, event: E) -> Option<P::AllocationData> {
None
}
}
// impl<A, P, E, S> AllocationType<P, E> for ChangeAllocation<A, P, E, S>
// where
// A: AllocationType<P, E>,
// P: PoolType,
// E: Send + 'static,
// S: State,
// {
// fn change_allocation_amount(&self, event: E) -> Option<P::AllocationData> {
// None
// }
// }

#[derive(Debug)]
pub struct InitialAllocation<P: PoolType> {
/// The initial amount of token X.
pub initial_x: eU256,
/// The initial Price
pub initial_price: eU256,
/// Initial Parameters
pub initial_parameters: P::AllocationData,
/// The tokens to allocate
pub tokens: (
ArbiterToken<ArbiterMiddleware>,
ArbiterToken<ArbiterMiddleware>,
),
/// The tokens to request.
pub token_data: TokenData,
/// The agent ID to request tokens to.
pub request_to: String,
/// Client to have an address to receive token mint to and check balance
// #[serde(skip)]
pub client: Option<Arc<ArbiterMiddleware>>,
/// The messaging layer for the token requester.
// #[serde(skip)]
pub messager: Option<Messager>,
}
// #[derive(Debug)]
// pub struct InitialAllocation<P: PoolType> {
// /// The initial amount of token X.
// pub initial_x: eU256,
// /// The initial Price
// pub initial_price: eU256,
// /// Initial Parameters
// pub initial_parameters: P::AllocationData,
// /// The tokens to allocate
// pub tokens: (
// ArbiterToken<ArbiterMiddleware>,
// ArbiterToken<ArbiterMiddleware>,
// ),
// /// The tokens to request.
// pub token_data: TokenData,
// /// The agent ID to request tokens to.
// pub request_to: String,
// /// Client to have an address to receive token mint to and check balance
// // #[serde(skip)]
// pub client: Option<Arc<ArbiterMiddleware>>,
// /// The messaging layer for the token requester.
// // #[serde(skip)]
// pub messager: Option<Messager>,
// }

#[allow(unused_variables)]
#[async_trait::async_trait]
impl<A, P, E> Behavior<E> for ChangeAllocation<A, P, E, Configuration>
where
A: AllocationType<P, E> + std::fmt::Debug + Send + Sync + 'static,
P: PoolType + std::fmt::Debug + Send + Sync + 'static,
E: std::fmt::Debug + Send + Sync + 'static,
{
type Processor = ChangeAllocation<A, P, E, Processing<ChangeAllocationStructData<A, P, E>>>;
async fn startup(
&mut self,
client: Arc<ArbiterMiddleware>,
messager: Messager,
) -> Result<Option<(Self::Processor, EventStream<E>)>> {
todo!();
}
}
// #[allow(unused_variables)]
// #[async_trait::async_trait]
// impl<A, P, E> Behavior<E> for ChangeAllocation<A, P, E, Configuration>
// where
// A: AllocationType<P, E> + std::fmt::Debug + Send + Sync + 'static,
// P: PoolType + std::fmt::Debug + Send + Sync + 'static,
// E: std::fmt::Debug + Send + Sync + 'static,
// {
// type Processor = ChangeAllocation<A, P, E, Processing<ChangeAllocationStructData<A, P, E>>>;
// async fn startup(
// &mut self,
// client: Arc<ArbiterMiddleware>,
// messager: Messager,
// ) -> Result<Option<(Self::Processor, EventStream<E>)>> {
// todo!();
// }
// }

#[async_trait::async_trait]
impl<A, P, E> Processor<E>
for ChangeAllocation<A, P, E, Processing<ChangeAllocationStructData<A, P, E>>>
where
A: AllocationType<P, E>,
P: PoolType,
E: Send + 'static,
{
async fn process(&mut self, event: E) -> Result<ControlFlow> {
Ok(ControlFlow::Halt)
}
}
// #[async_trait::async_trait]
// impl<A, P, E> Processor<E>
// for ChangeAllocation<A, P, E, Processing<ChangeAllocationStructData<A, P, E>>>
// where
// A: AllocationType<P, E>,
// P: PoolType,
// E: Send + 'static,
// {
// async fn process(&mut self, event: E) -> Result<ControlFlow> {
// Ok(ControlFlow::Halt)
// }
// }

// #[allow(unused_variables)]
// #[async_trait::async_trait]
Expand Down
53 changes: 53 additions & 0 deletions kit/src/behaviors/creator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

use super::*;
use arbiter_engine::machine::{State, Configuration, Processing, Behavior, Processor};
use crate::pool::{PoolType, Pool, PoolConfigurer};

// Idea: Let's make a behavior that has two states:
// State 1. This is for configuration and it should have everything be `Serialize`/`Deserialize` so that it can be read in from a config.
// State 2. This is the "built" version of the behavior that may now own client, messager, or contracts (etc.) and other things that had to be gotten from running the `startup` method.


// Example:
// Let's make a "pool_creator" type of behavior that will take some configuration for a pool and work to attempt to deploy that pool.

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PoolCreator<S: State> {
pub data: S::Data,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PoolConfig<P: PoolConfigurer> {
pub params: P::PoolParameters,
pub token_list: Vec<eAddress>,
pub initial_allocation: Vec<eU256>,
}

pub struct PoolProcessor<P: PoolType> {
pub pool: Pool<P>
}


#[async_trait::async_trait]
impl<T> Behavior<()> for PoolCreator<Configuration<PoolConfig<T>>>
where
T: PoolConfigurer,
// P: PoolType,
// E: Send + Sync + 'static,
{
type Processor = ();
async fn startup(&mut self, client: Arc<ArbiterMiddleware>, messager: Messager) -> Result<Option<(Self::Processor, EventStream<()>)>> {
todo!()
}
}

// #[async_trait::async_trait]
// impl<P,E> Processor<E> for PoolCreator<Processing<PoolProcessor<P>>>
// where
// P: PoolType,
// E: Send + Sync + 'static,
// {
// async fn process(&mut self, event: E) {
// todo!()
// }
// }
12 changes: 6 additions & 6 deletions kit/src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,32 @@ impl Behavior<()> for Deployer {
// println!("{:?}", parsed_data);

// assert_eq!(
//
//
// Address::from_str("0xb00efcb70090a21d46660adf95a16ec69623f694").unwrap(),
// parsed_data.weth
// );
// assert_eq!(
//
//
// Address::from_str("0x27781b40bd019ccb1dcb0c809135db71222e9353").unwrap(),
// parsed_data.dfmm
// );
// assert_eq!(
//
//
// Address::from_str("0x6e0035324097bfc66442e2d3f37ef378fb3750b2").unwrap(),
// parsed_data.geometric_mean
// );
// assert_eq!(
//
//
// Address::from_str("0x4be050270d209ef9f0c0435736c731767486279f").unwrap(),
// parsed_data.log_normal
// );
// assert_eq!(
//
//
// Address::from_str("0xaeb166f1355c6254d01a54317ef8d4d21bfcb4b0").unwrap(),
// parsed_data.constant_sum
// );
// assert_eq!(
//
//
// Address::from_str("0xa4bb88cbfc92d86ae00842dcfa5a1ac32b0714b3").unwrap(),
// parsed_data.n_token_geometric_mean
// );
Expand Down
21 changes: 11 additions & 10 deletions kit/src/behaviors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ use std::sync::Arc;

use arbiter_bindings::bindings::arbiter_token::ArbiterToken;
use arbiter_engine::{
machine::{Behavior, ControlFlow, CreateStateMachine, Engine, EventStream, StateMachine},
machine::{Behavior, Configuration, ControlFlow, CreateStateMachine, Engine, EventStream, StateMachine},
messager::{Message, Messager, To},
};
use arbiter_macros::Behaviors;
use serde::{Deserialize, Serialize};

use self::{
allocate::InitialAllocation, deployer::Deployer, pool::PoolType, token_admin::TokenAdmin,
creator::{PoolConfig, PoolCreator}, deployer::Deployer, pool::{PoolConfigurer, PoolType} //token_admin::TokenAdmin,allocate::InitialAllocation,
};
use super::*;

pub mod allocate;
// pub mod allocate;
pub mod deployer;
pub mod token_admin;
// pub mod token_admin;
pub mod creator;

#[derive(Debug, Deserialize, Serialize)]
pub enum Behaviors<P: PoolConfigurer> {
Creator(PoolCreator<Configuration<PoolConfig<P>>>),
Deployer(Deployer),
}

// #[derive(Behaviors, Debug, Deserialize, Serialize)]
// pub enum Behaviors<P> {
// Allocate(InitialAllocation<P>),
// Deployer(Deployer<P>),
// TokenAdmin(TokenAdmin<P>),
// }

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenData {
Expand Down
Loading

0 comments on commit 9b74e54

Please sign in to comment.