File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
programs/drift/src/controller Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
1010### Features
1111
12+ - program: allow resolve perp pnl deficit if pnl pool isnt 0 but at deficit ([ #1909 ] ( https://github.com/drift-labs/protocol-v2/pull/1909 ) )
1213- program: auction order params account for twap divergence ([ #1882 ] ( https://github.com/drift-labs/protocol-v2/pull/1882 ) )
1314- program: add delegate stake if ([ #1859 ] ( https://github.com/drift-labs/protocol-v2/pull/1859 ) )
1415
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use crate::controller::spot_balance::{
1111} ;
1212use crate :: error:: { DriftResult , ErrorCode } ;
1313use crate :: get_then_update_id;
14- use crate :: math:: amm:: calculate_quote_asset_amount_swapped;
14+ use crate :: math:: amm:: { calculate_net_user_pnl , calculate_quote_asset_amount_swapped} ;
1515use crate :: math:: amm_spread:: { calculate_spread_reserves, get_spread_reserves} ;
1616use crate :: math:: casting:: Cast ;
1717use crate :: math:: constants:: {
@@ -942,7 +942,7 @@ pub fn calculate_perp_market_amm_summary_stats(
942942 . safe_add ( fee_pool_token_amount) ?
943943 . cast ( ) ?;
944944
945- let net_user_pnl = amm :: calculate_net_user_pnl ( & perp_market. amm , perp_market_oracle_price) ?;
945+ let net_user_pnl = calculate_net_user_pnl ( & perp_market. amm , perp_market_oracle_price) ?;
946946
947947 // amm's mm_fee can be incorrect with drifting integer math error
948948 let mut new_total_fee_minus_distributions = pnl_tokens_available. safe_sub ( net_user_pnl) ?;
Original file line number Diff line number Diff line change @@ -843,11 +843,20 @@ pub fn resolve_perp_pnl_deficit(
843843 & SpotBalanceType :: Deposit ,
844844 ) ?;
845845
846+ let net_user_pnl = calculate_net_user_pnl (
847+ & market. amm ,
848+ market
849+ . amm
850+ . historical_oracle_data
851+ . last_oracle_price_twap_5min ,
852+ ) ?;
853+
846854 validate ! (
847- pnl_pool_token_amount == 0 ,
855+ pnl_pool_token_amount. cast :: < i128 > ( ) ? < net_user_pnl ,
848856 ErrorCode :: SufficientPerpPnlPool ,
849- "pnl_pool_token_amount > 0 (={})" ,
850- pnl_pool_token_amount
857+ "pnl_pool_token_amount >= net_user_pnl ({} >= {})" ,
858+ pnl_pool_token_amount,
859+ net_user_pnl
851860 ) ?;
852861
853862 update_spot_market_cumulative_interest ( spot_market, None , now) ?;
You can’t perform that action at this time.
0 commit comments