Skip to content

Commit

Permalink
feat: changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu committed Jul 28, 2024
1 parent bde79ab commit fb7d331
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy = { version = "0.1.3", features = ["full", "node-bindings", "sol-types", "contract", "transports", "transport-http"] }
alloy = { version = "0.1.3", features = ["rlp", "node-bindings", "sol-types", "contract", "transports", "transport-http"] }
tokio = { version = "1.36.0", features = ["full"] }
revm = "10.0.0"
octane = { git = "https://github.com/arena-rs/octane" }
Expand All @@ -23,6 +23,7 @@ serde_json = "1.0.120"
futures = "0.3.30"
rand = "0.8.5"
rand_distr = "0.4.3"
bytes = "1.6.1"

[lib]
doctest = false
Expand Down
17 changes: 7 additions & 10 deletions src/arbitrageur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ use super::*;

#[derive(Debug, Deserialize, Serialize, Clone)]
struct Arbitrageur {
#[serde(skip)]
pub messager: Option<Messager>,

#[serde(skip)]
pub client: Option<Arc<AnvilProvider>>,

pub base: Base,
pub deployment: Option<Address>,

pub pool: Option<PoolParams>,
}

Expand All @@ -20,8 +14,8 @@ impl Behavior<Message> for Arbitrageur {
client: Arc<AnvilProvider>,
messager: Messager,
) -> Result<Option<EventStream<Message>>> {
self.client = Some(client.clone());
self.messager = Some(messager.clone());
self.base.client = Some(client.clone());
self.base.messager = Some(messager.clone());

let mut stream = messager.clone().stream().unwrap();

Expand All @@ -41,7 +35,6 @@ impl Behavior<Message> for Arbitrageur {

Ok(Some(messager.clone().stream().unwrap()))
}

async fn process(&mut self, event: Message) -> Result<ControlFlow> {
let _query: PriceUpdate = match serde_json::from_str(&event.data) {
Ok(query) => query,
Expand All @@ -51,6 +44,10 @@ impl Behavior<Message> for Arbitrageur {
}
};

let manager = PoolManager::new(self.deployment.unwrap(), self.base.client.clone().unwrap());

let id = keccak256(&self.pool.clone().unwrap().key.encode());

return Ok(ControlFlow::Continue);
}
}
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::{fmt::Debug, sync::Arc};

use alloy::primitives::{Address, Bytes, Uint, U256};
use alloy::{
primitives::{keccak256, Address, Bytes, Uint, B256, U256},
rlp::Encodable,
sol_types::SolCall,
};
use anyhow::Result;
use bytes::BufMut;
use futures::stream::StreamExt;
use octane::{
machine::{Behavior, ControlFlow, EventStream},
Expand All @@ -25,6 +30,7 @@ use crate::{
types::process::{OrnsteinUhlenbeck, StochasticProcess},
LiquidExchange::LiquidExchangeInstance,
};

pub mod arbitrageur;
pub mod bindings;
pub mod deployer;
Expand All @@ -33,6 +39,22 @@ pub mod pool_admin;
pub mod price_changer;
pub mod types;

impl PoolKey {
fn encode(self) -> Vec<u8> {
let mut encoded = Vec::new();

&self.currency0.encode(&mut encoded);
&self.currency1.encode(&mut encoded);

&U256::from(self.fee).encode(&mut encoded);
&U256::from(self.tickSpacing as u32).encode(&mut encoded);

&self.hooks.encode(&mut encoded);

encoded
}
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct Base {
#[serde(skip)]
Expand Down
3 changes: 1 addition & 2 deletions src/pool_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use super::*;
#[derive(Debug, Serialize, Deserialize)]
pub struct PoolAdmin {
pub base: Base,

pub deployment: Option<Address>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct PoolParams {
#[serde(skip)]
key: PoolKey,
pub key: PoolKey,

sqrt_price_x96: U256,
hook_data: Bytes,
Expand Down
2 changes: 0 additions & 2 deletions src/price_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ where
T: StochasticProcess,
{
pub base: Base,

pub process: T,

pub lex: Option<Address>,
}

Expand Down

0 comments on commit fb7d331

Please sign in to comment.