Skip to content

Commit

Permalink
feat: construct swap
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Aug 21, 2024
1 parent 67130f2 commit 135d41e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ license-file = "./LICENSE"
exclude = ["contracts"]

[dependencies]
alloy = { version = "0.2.1", features = ["full", "node-bindings", "json"] }
rug = "1.25.0"
rand = "0.8.5"
plotly = "0.9.0"
rand_distr = "0.4.3"
async-trait = "0.1.81"
alloy-contract = "0.2.1"
alloy-sol-macro = "0.7.7"
alloy-sol-types = "0.7.7"
async-trait = "0.1.81"
plotly = "0.9.0"
rand = "0.8.5"
rand_distr = "0.4.3"
rug = "1.25.0"
tokio = { version = "1.39.2", features = ["macros"] }
tokio = { version = "1.39.2", features = ["macros"] }
alloy = { version = "0.2.1", features = ["full", "node-bindings", "json"] }
20 changes: 17 additions & 3 deletions src/engine/arbitrageur.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use std::{cmp::Ordering, str::FromStr};

use alloy::primitives::Signed;
use async_trait::async_trait;
use rug::{ops::Pow, Float};

use crate::{types::Fetcher, AnvilProvider, Signal};
use crate::{
types::{Fetcher, PoolManager::SwapParams},
AnvilProvider, Signal,
};

/// Generic trait allowing user defined arbitrage strategies.
#[async_trait]
Expand All @@ -23,9 +29,9 @@ impl Arbitrageur for DefaultArbitrageur {
let current_tick = Float::with_val(53, signal.tick);

let (start, end) = if current_tick < target_tick {
(current_tick, target_tick)
(current_tick.clone(), target_tick.clone())
} else {
(target_tick, current_tick)
(target_tick.clone(), current_tick.clone())
};

let (a, b) = self
Expand All @@ -42,6 +48,14 @@ impl Arbitrageur for DefaultArbitrageur {
// closed form optimal swap solution, ref: https://arxiv.org/pdf/1911.03380
let optimal_swap =
Float::with_val(53, 0).max(&(a.clone() - (k / (signal.pool.fee * (a / b)))));

let zero_for_one = &current_tick > &target_tick;

let swap_params = SwapParams {
amountSpecified: Signed::from_str(&optimal_swap.to_string()).unwrap(),
zeroForOne: zero_for_one,
sqrtPriceLimitX96: signal.sqrt_price_x96,
};
}
}

Expand Down

0 comments on commit 135d41e

Please sign in to comment.