From 297a17ab6eeb1e950eb8bfaa1eca88de05339334 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:37:22 +0000 Subject: [PATCH] feat: optimal swap calculation --- src/engine/arbitrageur.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/engine/arbitrageur.rs b/src/engine/arbitrageur.rs index 737a885..3829024 100644 --- a/src/engine/arbitrageur.rs +++ b/src/engine/arbitrageur.rs @@ -36,6 +36,12 @@ impl Arbitrageur for DefaultArbitrageur { end.to_i32_saturating().unwrap(), ) .await; + + let k = a.clone() * b.clone(); + + // 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))))); } }