Skip to content
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 @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- program: add sequence id to exchange/mm oracle ([#1834](https://github.com/drift-labs/protocol-v2/pull/1834))
- program: perp position max margin ratio ([#1847](https://github.com/drift-labs/protocol-v2/pull/1847))
- program: rm lp ([#1755](https://github.com/drift-labs/protocol-v2/pull/1755))

Expand Down
3 changes: 3 additions & 0 deletions programs/drift/src/controller/amm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ fn formualic_k_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

// zero funding cost
Expand Down Expand Up @@ -192,6 +193,7 @@ fn iterative_bounds_formualic_k_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

// negative funding cost
Expand Down Expand Up @@ -236,6 +238,7 @@ fn iterative_no_bounds_formualic_k_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

// negative funding cost
Expand Down
7 changes: 7 additions & 0 deletions programs/drift/src/controller/position/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ fn amm_pred_market_example() {
confidence: 47843,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
Expand Down Expand Up @@ -646,6 +647,7 @@ fn amm_ref_price_decay_tail_test() {
confidence: PRICE_PRECISION_U64 / 100000,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
Expand Down Expand Up @@ -822,6 +824,7 @@ fn amm_ref_price_offset_decay_logic() {
confidence: PRICE_PRECISION_U64 / 1000,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
Expand Down Expand Up @@ -995,6 +998,7 @@ fn amm_negative_ref_price_offset_decay_logic() {
confidence: PRICE_PRECISION_U64 / 1000,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
Expand Down Expand Up @@ -1184,6 +1188,7 @@ fn amm_perp_ref_offset() {
confidence: PRICE_PRECISION_U64 / 1000,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
Expand Down Expand Up @@ -2446,6 +2451,7 @@ fn recenter_amm_2() {
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
oracle_price_data.delay + 1,
1,
OracleValidity::default(),
*oracle_price_data,
)
Expand Down Expand Up @@ -2587,6 +2593,7 @@ fn test_move_amm() {
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
oracle_price_data.delay + 1,
1,
OracleValidity::default(),
*oracle_price_data,
)
Expand Down
10 changes: 10 additions & 0 deletions programs/drift/src/controller/repeg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn update_amm_test() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let reserve_price_before = market.amm.reserve_price().unwrap();
Expand Down Expand Up @@ -227,6 +228,7 @@ pub fn update_amm_test_bad_oracle() {
confidence: 0,
delay: 12,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand Down Expand Up @@ -285,6 +287,7 @@ pub fn update_amm_larg_conf_test() {
confidence: 0,
delay: 9,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand All @@ -309,6 +312,7 @@ pub fn update_amm_larg_conf_test() {
confidence: 100 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand All @@ -335,6 +339,7 @@ pub fn update_amm_larg_conf_test() {
confidence: 100 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let fee_budget = calculate_fee_pool(&market).unwrap();
Expand Down Expand Up @@ -377,6 +382,7 @@ pub fn update_amm_larg_conf_test() {
confidence: 121 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand Down Expand Up @@ -432,6 +438,7 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() {
confidence: 0,
delay: 9,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand Down Expand Up @@ -486,6 +493,7 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() {
confidence: 100 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand All @@ -512,6 +520,7 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() {
confidence: 100 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand Down Expand Up @@ -588,6 +597,7 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() {
confidence: 121 * PRICE_PRECISION_U64,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = market
.get_mm_oracle_price_data(oracle_price_data, slot, &state.oracle_guard_rails.validity)
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/controller/spot_balance/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ fn check_usdc_spot_market_twap() {
confidence: 1,
delay: 0,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

update_spot_market_twap_stats(&mut spot_market, Some(&oracle_price_data), now).unwrap();
Expand Down
24 changes: 24 additions & 0 deletions programs/drift/src/math/amm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn calculate_amm_available_guards() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

assert_eq!(market.amm.net_revenue_since_last_funding, 0);
Expand Down Expand Up @@ -98,6 +99,7 @@ fn calculate_net_user_pnl_test() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let net_user_pnl = calculate_net_user_pnl(&amm, oracle_price_data.price).unwrap();
Expand Down Expand Up @@ -127,6 +129,7 @@ fn calculate_expiry_price_long_imbalance_with_loss_test() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down Expand Up @@ -209,6 +212,7 @@ fn calculate_expiry_price_long_imbalance_test() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down Expand Up @@ -307,6 +311,7 @@ fn calculate_expiry_price_test() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let mut expiry_price = calculate_expiry_price(&amm, oracle_price_data.price, 0).unwrap();
Expand All @@ -324,6 +329,7 @@ fn calculate_expiry_price_test() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down Expand Up @@ -483,10 +489,12 @@ fn calc_mark_std_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
3,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -605,10 +613,12 @@ fn update_mark_twap_tests() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
3,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -704,10 +714,12 @@ fn update_mark_twap_tests() {
confidence: PRICE_PRECISION_U64 / 80,
delay: 14,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
15,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -773,10 +785,12 @@ fn calc_oracle_twap_tests() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
2,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand All @@ -798,10 +812,12 @@ fn calc_oracle_twap_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
3,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -833,10 +849,12 @@ fn calc_oracle_twap_tests() {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
3,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -898,10 +916,12 @@ fn calc_oracle_twap_clamp_update_tests() {
confidence: PRICE_PRECISION_U64 / 10,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
2,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down Expand Up @@ -985,10 +1005,12 @@ fn test_last_oracle_conf_update() {
confidence: PRICE_PRECISION_U64 / 10,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
2,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand All @@ -1004,11 +1026,13 @@ fn test_last_oracle_conf_update() {
confidence: 1,
delay: 5,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
2,
1,
OracleValidity::default(),
oracle_price_data,
)
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/math/funding/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ fn unsettled_funding_pnl() {
let mm_oracle_price_data = MMOraclePriceData::new(
oracle_price_data.price,
oracle_price_data.delay + 1,
0,
OracleValidity::default(),
*oracle_price_data,
)
Expand Down
3 changes: 3 additions & 0 deletions programs/drift/src/math/margin/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ mod test {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down Expand Up @@ -4197,6 +4198,7 @@ mod calculate_perp_position_value_and_pnl_prediction_market {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down Expand Up @@ -4260,6 +4262,7 @@ mod calculate_perp_position_value_and_pnl_prediction_market {
confidence: 0,
delay: 2,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};

let market_position = PerpPosition {
Expand Down
2 changes: 2 additions & 0 deletions programs/drift/src/math/oracle/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn calculate_oracle_valid() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 1,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
let mut market: PerpMarket = PerpMarket {
amm,
Expand Down Expand Up @@ -84,6 +85,7 @@ fn calculate_oracle_valid() {
confidence: PRICE_PRECISION_U64 / 100,
delay: 11,
has_sufficient_number_of_data_points: true,
sequence_id: None,
};
oracle_status = get_oracle_status(
&market,
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/math/repeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn calculate_repeg_validity(
confidence: oracle_conf,
delay: _,
has_sufficient_number_of_data_points: _,
sequence_id: _,
} = *oracle_price_data;

let oracle_price_u128 = oracle_price.cast::<u64>()?;
Expand Down
Loading
Loading