From 97752651536391e4ff318adc68cf7897db3fee40 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:49:27 +0000 Subject: [PATCH] feat: liquidity provision and clippy --- Cargo.toml | 2 +- src/arbitrageur.rs | 9 +++---- src/bindings/fetcher.rs | 8 +++--- src/bindings/liquidexchange.rs | 2 ++ src/lib.rs | 45 ++++++++++++++++++++++------------ src/liquidity_admin.rs | 4 +-- 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0590e1..c578c2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy = { version = "0.1.3", features = ["rlp", "node-bindings", "sol-types", "contract", "transports", "transport-http"] } +alloy = { version = "0.1.3", features = ["rlp", "node-bindings", "sol-types", "contract", "transports", "transport-http", "rpc"] } tokio = { version = "1.36.0", features = ["full"] } revm = "10.0.0" octane = { git = "https://github.com/arena-rs/octane" } diff --git a/src/arbitrageur.rs b/src/arbitrageur.rs index 4dd7a48..db359a4 100644 --- a/src/arbitrageur.rs +++ b/src/arbitrageur.rs @@ -1,4 +1,3 @@ -use std::f64::consts::LN_2; use super::*; @@ -38,7 +37,7 @@ impl Arbitrageur { let (profit_mid, new_price_mid) = Arbitrageur::profit(mid, p_ext, p_uni, fee, next_tick_liquidity); - let (profit_next, new_price_next) = + let (profit_next, _new_price_next) = Arbitrageur::profit(mid + tol, p_ext, p_uni, fee, next_tick_liquidity); if profit_mid > profit_next { @@ -56,7 +55,7 @@ impl Arbitrageur { } } - return (a + b) / 2.0; + (a + b) / 2.0 } pub fn get_price_at_tick(tick: f64) -> f64 { @@ -151,7 +150,7 @@ impl Behavior for Arbitrageur { let id = fetcher.toId(fetcher_key).call().await?.poolId; let get_slot0_return = fetcher - .getSlot0(manager.address().clone(), id) + .getSlot0(*manager.address(), id) .call() .await?; @@ -162,7 +161,7 @@ impl Behavior for Arbitrageur { let lex_price = liquid_exchange.price().call().await?._0; - let diff = scaled_price.abs_diff(lex_price); + let _diff = scaled_price.abs_diff(lex_price); let p_uni = f64::from(scaled_price) / 10f64.powi(18); let p_ext = f64::from(lex_price) / 10f64.powi(18); diff --git a/src/bindings/fetcher.rs b/src/bindings/fetcher.rs index 51c04b5..9c56ca1 100644 --- a/src/bindings/fetcher.rs +++ b/src/bindings/fetcher.rs @@ -1,3 +1,6 @@ +#[allow(clippy::type_complexity)] +#[allow(clippy::needless_lifetimes)] + /** Generated by the following Solidity interface... @@ -175,7 +178,7 @@ interface Fetcher { pub mod Fetcher { use alloy::sol_types as alloy_sol_types; - use super::*; + /// The creation / init bytecode of the contract. /// /// ```text @@ -579,8 +582,7 @@ pub mod Fetcher { impl alloy_sol_types::EventTopic for PoolKey { #[inline] fn topic_preimage_length(rust: &Self::RustType) -> usize { - 0usize - + ::topic_preimage_length( + ::topic_preimage_length( &rust.currency0, ) + ::topic_preimage_length( diff --git a/src/bindings/liquidexchange.rs b/src/bindings/liquidexchange.rs index 87c8b09..0fbc03b 100644 --- a/src/bindings/liquidexchange.rs +++ b/src/bindings/liquidexchange.rs @@ -1,4 +1,6 @@ #[allow(clippy::type_complexity)] +#[allow(clippy::needless_lifetimes)] +#[allow(clippy::useless_conversion)] /** diff --git a/src/lib.rs b/src/lib.rs index 2fbbd80..9cb9335 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,8 @@ -use std::{cmp::Ordering, fmt::Debug, str::FromStr, sync::Arc}; +use std::{cmp::Ordering, fmt::Debug, sync::Arc}; use alloy::{ primitives::{Address, Bytes, Uint, U256}, - providers::WalletProvider, }; -use alloy_sol_types::sol_data::FixedBytes; use anyhow::Result; use futures::stream::StreamExt; use octane::{ @@ -15,7 +13,6 @@ use octane::{ use serde::{Deserialize, Serialize}; use crate::{ - arbitrageur::Arbitrageur, bindings::{ arenatoken::ArenaToken, fetcher::{Fetcher, Fetcher::PoolKey as FetcherPoolKey}, @@ -25,10 +22,9 @@ use crate::{ PoolManager::{ModifyLiquidityParams, PoolKey}, }, }, - deployer::{DeploymentRequest, DeploymentResponse, PoolParams}, - liquidity_admin::{AllocationRequest, LiquidityAdmin}, - price_changer::{PriceChanger, PriceUpdate, Signal}, - types::process::{OrnsteinUhlenbeck, StochasticProcess}, + deployer::{DeploymentResponse, PoolParams}, + price_changer::{Signal}, + types::process::{StochasticProcess}, }; pub mod arbitrageur; @@ -81,7 +77,7 @@ mod tests { symbol: String::from("TST0"), decimals: 18, initial_mint: 1000000, - receiver: self.client.clone().unwrap().default_signer_address(), + receiver: client.clone().default_signer_address(), }, ) .await?; @@ -94,7 +90,7 @@ mod tests { symbol: String::from("TST1"), decimals: 18, initial_mint: 1000000, - receiver: self.client.clone().unwrap().default_signer_address(), + receiver: client.clone().default_signer_address(), }, ) .await?; @@ -165,13 +161,29 @@ mod tests { .send( To::All, DeploymentRequest::Pool(PoolParams { - key, + key: key.clone(), sqrt_price_x96: U256::from_str("79228162514264337593543950336").unwrap(), hook_data: Bytes::default(), }), ) .await?; + messager + .send( + To::All, + AllocationRequest { + pool: key.clone(), + modification: ModifyLiquidityParams { + tickLower: -10, + tickUpper: 10, + liquidityDelta: Signed::from_str("1000").unwrap(), + salt: as SolType>::abi_decode(&[0u8; 32], true) + .unwrap(), + }, + }, + ) + .await?; + use tokio::time::{sleep, Duration}; while let Some(event) = stream.next().await { @@ -203,13 +215,14 @@ mod tests { async fn test_price_changer() { env_logger::init(); - let token_deployer = Agent::builder("tdeployer").with_behavior(TokenDeployer { - messager: None, - client: None, - }); + let token_deployer = Agent::builder("tdeployer") + .with_behavior(TokenDeployer { + messager: None, + client: None, + }) + .with_behavior(LiquidityAdmin::default()); let deployer = Agent::builder("deployer").with_behavior(Deployer::default()); - let liquidity_admin = Agent::builder("liqadmin").with_behavior(LiquidityAdmin::default()); let mock_deployer = Agent::builder("mock_deployer").with_behavior(MockOrchestrator { client: None, diff --git a/src/liquidity_admin.rs b/src/liquidity_admin.rs index 274537c..4880257 100644 --- a/src/liquidity_admin.rs +++ b/src/liquidity_admin.rs @@ -10,10 +10,10 @@ pub struct LiquidityAdmin { #[derive(Deserialize, Serialize, Clone)] pub struct AllocationRequest { #[serde(skip)] - pool: PoolKey, + pub pool: PoolKey, #[serde(skip)] - modification: ModifyLiquidityParams, + pub modification: ModifyLiquidityParams, } #[async_trait::async_trait]