From fb7d33189af4d673884da67e58fd0f25d764df39 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:59:21 +0000 Subject: [PATCH] feat: changes --- Cargo.lock | 6 ++++-- Cargo.toml | 3 ++- src/arbitrageur.rs | 17 +++++++---------- src/lib.rs | 24 +++++++++++++++++++++++- src/pool_admin.rs | 3 +-- src/price_changer.rs | 2 -- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05a6311..d35f90d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,7 @@ dependencies = [ "alloy-dyn-abi", "alloy-json-abi", "alloy-primitives", + "alloy-rlp", "alloy-sol-types", ] @@ -663,6 +664,7 @@ dependencies = [ "alloy-transport-http", "anyhow", "async-trait", + "bytes", "crossbeam-channel", "env_logger", "futures", @@ -997,9 +999,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index e9e3d71..d0590e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -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 diff --git a/src/arbitrageur.rs b/src/arbitrageur.rs index b84a626..b519366 100644 --- a/src/arbitrageur.rs +++ b/src/arbitrageur.rs @@ -2,14 +2,8 @@ use super::*; #[derive(Debug, Deserialize, Serialize, Clone)] struct Arbitrageur { - #[serde(skip)] - pub messager: Option, - - #[serde(skip)] - pub client: Option>, - + pub base: Base, pub deployment: Option
, - pub pool: Option, } @@ -20,8 +14,8 @@ impl Behavior for Arbitrageur { client: Arc, messager: Messager, ) -> Result>> { - 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(); @@ -41,7 +35,6 @@ impl Behavior for Arbitrageur { Ok(Some(messager.clone().stream().unwrap())) } - async fn process(&mut self, event: Message) -> Result { let _query: PriceUpdate = match serde_json::from_str(&event.data) { Ok(query) => query, @@ -51,6 +44,10 @@ impl Behavior 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); } } diff --git a/src/lib.rs b/src/lib.rs index 1ee2813..5709d2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}, @@ -25,6 +30,7 @@ use crate::{ types::process::{OrnsteinUhlenbeck, StochasticProcess}, LiquidExchange::LiquidExchangeInstance, }; + pub mod arbitrageur; pub mod bindings; pub mod deployer; @@ -33,6 +39,22 @@ pub mod pool_admin; pub mod price_changer; pub mod types; +impl PoolKey { + fn encode(self) -> Vec { + 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)] diff --git a/src/pool_admin.rs b/src/pool_admin.rs index 42d40fc..1668a6f 100644 --- a/src/pool_admin.rs +++ b/src/pool_admin.rs @@ -6,14 +6,13 @@ use super::*; #[derive(Debug, Serialize, Deserialize)] pub struct PoolAdmin { pub base: Base, - pub deployment: Option
, } #[derive(Debug, Deserialize, Serialize, Clone)] pub struct PoolParams { #[serde(skip)] - key: PoolKey, + pub key: PoolKey, sqrt_price_x96: U256, hook_data: Bytes, diff --git a/src/price_changer.rs b/src/price_changer.rs index d30b217..0da29d7 100644 --- a/src/price_changer.rs +++ b/src/price_changer.rs @@ -13,9 +13,7 @@ where T: StochasticProcess, { pub base: Base, - pub process: T, - pub lex: Option
, }