Skip to content

Commit

Permalink
Refactor/test/behaviors (#137)
Browse files Browse the repository at this point in the history
* refactor behaviors

---------

Co-authored-by: Waylon Jepsen <waylonjepsen1@gmail.com>
  • Loading branch information
Autoparallel and 0xJepsen authored Apr 26, 2024
1 parent b7e3c47 commit 44231d6
Showing 31 changed files with 507 additions and 673 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:
with:
toolchain: nightly
- name: test
run: cargo test --workspace --all-features
run: cargo +nightly test --workspace --all-features

clippy:
name: clippy
@@ -28,10 +28,10 @@ jobs:
- name: install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.75.0
toolchain: nightly
components: clippy
- name: cargo clippy
run: cargo clippy --workspace --all-features -- -D warnings
run: cargo +nightly clippy --workspace --all-features -- -D warnings

udeps:
name: udeps
125 changes: 6 additions & 119 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions kit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,10 +9,10 @@ keywords = ["ethereum", "smart-contracts", "automated market makers"]
readme = "../README.md"

[dependencies]
arbiter-core = { git = "https://github.com/primitivefinance/arbiter.git", rev = "aff29d30" }
arbiter-engine = { git = "https://github.com/primitivefinance/arbiter.git", rev = "aff29d30" }
arbiter-macros = { git = "https://github.com/primitivefinance/arbiter.git", rev = "aff29d30" }
arbiter-bindings = { git = "https://github.com/primitivefinance/arbiter.git", rev = "aff29d30" }
arbiter-core = { git = "https://github.com/primitivefinance/arbiter.git", rev = "d5bc1bb3" }
arbiter-engine = { git = "https://github.com/primitivefinance/arbiter.git", rev = "d5bc1bb3" }
arbiter-macros = { git = "https://github.com/primitivefinance/arbiter.git", rev = "d5bc1bb3" }
arbiter-bindings = { git = "https://github.com/primitivefinance/arbiter.git", rev = "d5bc1bb3" }

# Ethereum
ethers = "2.0.13"
@@ -29,10 +29,9 @@ serde_json = "1.0.114"
# Errors and tracing
anyhow = "1.0.81"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

# CLI
clap = { version = "4.5.1", features = ["derive"] }
[dev-dependencies]
tracing-subscriber = "0.3.18"

[[bin]]
name = "kit"
37 changes: 14 additions & 23 deletions kit/src/behaviors/allocate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::*;

pub trait AllocateType<E>: Debug + Serialize + Clone
pub trait AllocateType<E>
where
E: Send + 'static,
{
// TODO: This should probably be how we do it, but this generic `P` gets
// annoying fn change_allocation_amount(&mut self, event: E) ->
// Option<P::AllocationData>;
fn change_allocation_amount(&mut self, event: E) -> Option<Vec<eI256>>;
fn get_stream(&self) -> Pin<Box<dyn Stream<Item = E> + Send + Sync>>;
}

#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -24,11 +23,12 @@ where
_phantom_e: PhantomData<E>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, State)]
pub struct Config<P: PoolType> {
pub allocation_data: P::AllocationData,
}

#[derive(State)]
pub struct Processing<P, E>
where
P: PoolType,
@@ -40,43 +40,34 @@ where
_phantom: PhantomData<E>,
}

impl<P: PoolType> State for Config<P> {
type Data = Self;
}

impl<P, E> State for Processing<P, E>
where
P: PoolType,
E: Send + 'static,
{
type Data = Self;
}

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

#[async_trait::async_trait]
impl<A, P, E> Processor<E> for Allocate<A, E, Processing<P, E>>
where
A: AllocateType<E> + Debug + Send + Sync + 'static,
P: PoolType + Debug + Send + Sync + 'static,
E: Debug + Send + Sync + 'static,
A: AllocateType<E> + Send,
P: PoolType + Send,
E: Send + 'static,
{
async fn get_stream(&mut self) -> Result<Option<EventStream<E>>> {
todo!("We have not implemented the 'get_stream' method yet for the 'Allocate' behavior.");
}
async fn process(&mut self, _event: E) -> Result<ControlFlow> {
Ok(ControlFlow::Halt)
}
Loading

0 comments on commit 44231d6

Please sign in to comment.