Skip to content
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

bigz/block-funding-on-stale-amm #757

Merged
merged 3 commits into from
Dec 12, 2023
Merged
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
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
Loading