Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into git-update-event
Browse files Browse the repository at this point in the history
merging master into branch
  • Loading branch information
NourAlharithi committed Sep 8, 2023
2 parents 15f64df + b0fcbc8 commit 954aad6
Show file tree
Hide file tree
Showing 43 changed files with 2,302 additions and 874 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

### Fixes

### Breaking

## [2.39.0] - 2023-09-07

### Features

- sdk: updated anchor to 0.28.1-beta.2
- sdk: add priorityFeeSubscriber
- program: allow up to 12500 users
- program: scale initial asset weight for spot markets based on total deposits ([#575](https://github.com/drift-labs/protocol-v2/pull/575))

### Fixes

- program: let auction start/end be the same ([#597](https://github.com/drift-labs/protocol-v2/pull/597))
- program: account for reduce only when checking margin in trigger order ([#583](https://github.com/drift-labs/protocol-v2/pull/583))
- program: use per_lp_base_unit for calculating base imbalance for lp jit ([#604](https://github.com/drift-labs/protocol-v2/pull/604))

### Breaking

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/drift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drift"
version = "2.38.0"
version = "2.39.0"
description = "Created with Anchor"
edition = "2018"

Expand Down
43 changes: 21 additions & 22 deletions programs/drift/src/controller/liquidation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,8 +1815,8 @@ pub mod liquidate_spot {
calculate_margin_requirement_and_total_collateral, MarginRequirementType,
};
use crate::math::spot_balance::{get_strict_token_value, get_token_amount, get_token_value};
use crate::state::oracle::HistoricalOracleData;
use crate::state::oracle::OracleSource;
use crate::state::oracle::{HistoricalOracleData, StrictOraclePrice};
use crate::state::oracle_map::OracleMap;
use crate::state::perp_market_map::PerpMarketMap;
use crate::state::spot_market::{SpotBalanceType, SpotMarket};
Expand Down Expand Up @@ -2267,27 +2267,26 @@ pub mod liquidate_spot {
let token_value =
get_token_value(token_amount as i128, 6, oracle_price_data.price).unwrap();

let strict_token_value_1 = get_strict_token_value(
token_amount as i128,
6,
oracle_price_data,
oracle_price_data.price / 10,
)
.unwrap();
let strict_token_value_2 = get_strict_token_value(
token_amount as i128,
6,
oracle_price_data,
oracle_price_data.price * 2,
)
.unwrap();
let strict_token_value_3 = get_strict_token_value(
-(token_amount as i128),
6,
oracle_price_data,
oracle_price_data.price * 2,
)
.unwrap();
let strict_price_1 = StrictOraclePrice {
current: oracle_price_data.price,
twap_5min: Some(oracle_price_data.price / 10),
};
let strict_token_value_1 =
get_strict_token_value(token_amount as i128, 6, &strict_price_1).unwrap();

let strict_price_2 = StrictOraclePrice {
current: oracle_price_data.price,
twap_5min: Some(oracle_price_data.price * 2),
};
let strict_token_value_2 =
get_strict_token_value(token_amount as i128, 6, &strict_price_2).unwrap();

let strict_price_3 = StrictOraclePrice {
current: oracle_price_data.price,
twap_5min: Some(oracle_price_data.price * 2),
};
let strict_token_value_3 =
get_strict_token_value(-(token_amount as i128), 6, &strict_price_3).unwrap();

assert_eq!(token_amount, 406769);
assert_eq!(token_value, 40676900);
Expand Down
8 changes: 3 additions & 5 deletions programs/drift/src/controller/lp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::math::margin::{
calculate_margin_requirement_and_total_collateral, calculate_perp_position_value_and_pnl,
meets_maintenance_margin_requirement, MarginRequirementType,
};
use crate::state::oracle::OraclePriceData;
use crate::state::oracle::{HistoricalOracleData, OracleSource};
use crate::state::oracle::{OraclePriceData, StrictOraclePrice};
use crate::state::oracle_map::OracleMap;
use crate::state::perp_market::{MarketStatus, PerpMarket, PoolBalance};
use crate::state::perp_market_map::PerpMarketMap;
Expand Down Expand Up @@ -722,18 +722,16 @@ fn test_lp_margin_calc() {
assert_eq!(sim_user_pos.quote_asset_amount, -20000000000);
assert_eq!(sim_user_pos.last_cumulative_funding_rate, 16900000000);

let strict_quote_price = StrictOraclePrice::test(1000000);
// ensure margin calc doesnt incorrectly count funding rate (funding pnl MUST come before settling lp)
let (margin_requirement, weighted_unrealized_pnl, worse_case_base_asset_value) =
calculate_perp_position_value_and_pnl(
&user.perp_positions[0],
&market,
&oracle_price_data,
1000000,
1000000,
&strict_quote_price,
crate::math::margin::MarginRequirementType::Initial,
0,
false,
false,
)
.unwrap();

Expand Down
Loading

0 comments on commit 954aad6

Please sign in to comment.