From 075f5c89b8244748ae39ebe9a9d453fe0f2ccd99 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 7 Feb 2024 18:59:01 -0500 Subject: [PATCH] jit: fix accounting for amm price --- programs/jit-proxy/src/instructions/jit.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/jit-proxy/src/instructions/jit.rs b/programs/jit-proxy/src/instructions/jit.rs index d1f2cfbe..c77bc46e 100644 --- a/programs/jit-proxy/src/instructions/jit.rs +++ b/programs/jit-proxy/src/instructions/jit.rs @@ -132,24 +132,27 @@ pub fn jit<'info>(ctx: Context<'_, '_, '_, 'info, Jit<'info>>, params: JitParams let perp_market = perp_market_map.get_ref(&market_index)?; let reserve_price = perp_market.amm.reserve_price()?; - let mut maker_price = taker_price; - match maker_direction { + let maker_price = match maker_direction { PositionDirection::Long => { let amm_bid_price = perp_market.amm.bid_price(reserve_price)?; // if amm price is better than maker, use amm price to ensure fill - if taker_price <= amm_bid_price && amm_bid_price < maker_worst_price { - maker_price = amm_bid_price; + if taker_price <= amm_bid_price { + amm_bid_price.min(maker_worst_price) + } else { + taker_price } } PositionDirection::Short => { let amm_ask_price = perp_market.amm.ask_price(reserve_price)?; - if taker_price >= amm_ask_price && amm_ask_price > maker_worst_price { - maker_price = amm_ask_price; + if taker_price >= amm_ask_price { + amm_ask_price.max(maker_worst_price) + } else { + taker_price } } - } + }; maker_price } else {