File tree Expand file tree Collapse file tree 6 files changed +28
-11
lines changed
programs/drift/src/controller Expand file tree Collapse file tree 6 files changed +28
-11
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) ?;
Original file line number Diff line number Diff line change 1- 2.139.0-beta.5
1+ 2.139.0-beta.8
Original file line number Diff line number Diff line change 11{
22 "name" : " @drift-labs/sdk" ,
3- "version" : " 2.139.0-beta.5 " ,
3+ "version" : " 2.139.0-beta.8 " ,
44 "main" : " lib/node/index.js" ,
55 "types" : " lib/node/index.d.ts" ,
66 "browser" : " ./lib/browser/index.js" ,
Original file line number Diff line number Diff line change @@ -6639,14 +6639,21 @@ export class DriftClient {
66396639 readablePerpMarketIndex : marketIndex ,
66406640 } ) ;
66416641
6642- const isDelegateSigner = takerInfo . signingAuthority . equals (
6643- takerInfo . takerUserAccount . delegate
6644- ) ;
6645-
66466642 const borshBuf = Buffer . from (
66476643 signedSignedMsgOrderParams . orderParams . toString ( ) ,
66486644 'hex'
66496645 ) ;
6646+
6647+ const isDelegateSigner = borshBuf
6648+ . slice ( 0 , 8 )
6649+ . equals (
6650+ Uint8Array . from (
6651+ Buffer . from (
6652+ sha256 ( 'global' + ':' + 'SignedMsgOrderParamsDelegateMessage' )
6653+ ) . slice ( 0 , 8 )
6654+ )
6655+ ) ;
6656+
66506657 try {
66516658 const { signedMsgOrderParams } = this . decodeSignedMsgOrderParamsMessage (
66526659 borshBuf ,
You can’t perform that action at this time.
0 commit comments