Skip to content

Commit

Permalink
program: block funding on stale amm (#757)
Browse files Browse the repository at this point in the history
* bigz/block-funding-on-stale-amm

* update CHANGELOG.md

---------

Co-authored-by: lil perp <[email protected]>
  • Loading branch information
0xbigz and crispheaney committed Dec 12, 2023
1 parent 69bccca commit 4eba60a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- program: don't perform funding rate updates when slots_since_amm_update is stale ([#757](https://github.com/drift-labs/protocol-v2/pull/757))
- program: add update last slot for filler in pay_keeper_flat_reward_for_spot

### Breaking
Expand Down
2 changes: 2 additions & 0 deletions programs/drift/src/controller/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub fn update_funding_rate(
market: &mut PerpMarket,
oracle_map: &mut OracleMap,
now: UnixTimestamp,
slot: u64,
guard_rails: &OracleGuardRails,
funding_paused: bool,
precomputed_reserve_price: Option<u64>,
Expand All @@ -164,6 +165,7 @@ pub fn update_funding_rate(
oracle_map.get_price_data(&market.amm.oracle)?,
guard_rails,
Some(reserve_price),
slot
)?;

let time_until_next_update = on_the_hour_update(
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ pub fn fill_perp_order(
market,
oracle_map,
now,
slot,
&state.oracle_guard_rails,
funding_paused,
Some(reserve_price_before),
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/instructions/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ pub fn handle_update_funding_rate(
perp_market,
&mut oracle_map,
now,
clock_slot,
&state.oracle_guard_rails,
state.funding_paused()?,
None,
Expand Down
7 changes: 5 additions & 2 deletions programs/drift/src/math/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub fn block_operation(
oracle_price_data: &OraclePriceData,
guard_rails: &OracleGuardRails,
precomputed_reserve_price: Option<u64>,
slot: u64,
) -> DriftResult<bool> {
let OracleStatus {
oracle_validity,
Expand All @@ -119,10 +120,12 @@ pub fn block_operation(
)?;
let is_oracle_valid =
is_oracle_valid_for_action(oracle_validity, Some(DriftAction::UpdateFunding))?;


let slots_since_amm_update = slot.saturating_sub(market.amm.last_update_slot);

let funding_paused_on_market = market.status == MarketStatus::FundingPaused;

let block = !is_oracle_valid || is_oracle_mark_too_divergent || funding_paused_on_market;
let block = slots_since_amm_update > 10 || !is_oracle_valid || is_oracle_mark_too_divergent || funding_paused_on_market;
Ok(block)
}

Expand Down

0 comments on commit 4eba60a

Please sign in to comment.