Skip to content

Commit

Permalink
feat: liquidity provision and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Jul 31, 2024
1 parent 1f5296c commit 9775265
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 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 = ["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" }
Expand Down
9 changes: 4 additions & 5 deletions src/arbitrageur.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::f64::consts::LN_2;

use super::*;

Expand Down Expand Up @@ -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 {
Expand All @@ -56,7 +55,7 @@ impl Arbitrageur {
}
}

return (a + b) / 2.0;
(a + b) / 2.0
}

pub fn get_price_at_tick(tick: f64) -> f64 {
Expand Down Expand Up @@ -151,7 +150,7 @@ impl Behavior<Message> 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?;

Expand All @@ -162,7 +161,7 @@ impl Behavior<Message> 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);
Expand Down
8 changes: 5 additions & 3 deletions src/bindings/fetcher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[allow(clippy::type_complexity)]
#[allow(clippy::needless_lifetimes)]

/**
Generated by the following Solidity interface...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -579,8 +582,7 @@ pub mod Fetcher {
impl alloy_sol_types::EventTopic for PoolKey {
#[inline]
fn topic_preimage_length(rust: &Self::RustType) -> usize {
0usize
+ <Currency as alloy_sol_types::EventTopic>::topic_preimage_length(
<Currency as alloy_sol_types::EventTopic>::topic_preimage_length(
&rust.currency0,
)
+ <Currency as alloy_sol_types::EventTopic>::topic_preimage_length(
Expand Down
2 changes: 2 additions & 0 deletions src/bindings/liquidexchange.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[allow(clippy::type_complexity)]
#[allow(clippy::needless_lifetimes)]
#[allow(clippy::useless_conversion)]

/**
Expand Down
45 changes: 29 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -15,7 +13,6 @@ use octane::{
use serde::{Deserialize, Serialize};

use crate::{
arbitrageur::Arbitrageur,
bindings::{
arenatoken::ArenaToken,
fetcher::{Fetcher, Fetcher::PoolKey as FetcherPoolKey},
Expand All @@ -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;
Expand Down Expand Up @@ -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?;
Expand All @@ -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?;
Expand Down Expand Up @@ -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: <FixedBytes<32> as SolType>::abi_decode(&[0u8; 32], true)
.unwrap(),
},
},
)
.await?;

use tokio::time::{sleep, Duration};

while let Some(event) = stream.next().await {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/liquidity_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9775265

Please sign in to comment.