Skip to content

program: add amm decay for reference price offset #1732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion programs/drift/src/controller/amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ pub fn update_spreads(market: &mut PerpMarket, reserve_price: u64) -> DriftResul

market.amm.long_spread = long_spread;
market.amm.short_spread = short_spread;
market.amm.reference_price_offset = reference_price_offset;

if reference_price_offset == 0 && market.amm.reference_price_offset != 0 {
// smooth decay toward 0
market.amm.reference_price_offset = market.amm.reference_price_offset.safe_sub(market.amm.reference_price_offset.safe_div(10)?)?;
} else {
market.amm.reference_price_offset = reference_price_offset;
}

update_spread_reserves(market)?;

Expand Down
2 changes: 1 addition & 1 deletion programs/drift/src/state/perp_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ impl AMM {
// always allow 1-100 bps of price offset, up to half of the market's max_spread
let lb_bps =
(PERCENTAGE_PRECISION.cast::<i64>()? / 10000).safe_mul(lower_bound_multiplier)?;
let max_offset = (self.max_spread.cast::<i64>()? / 2).max(lb_bps);
let max_offset = (self.max_spread.cast::<i64>()? / 2).min(lb_bps);

Ok(max_offset)
}
Expand Down
Loading