File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
programs/drift/src/instructions Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -3334,6 +3334,10 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>(
33343334 let lp_pool_key = ctx. accounts . lp_pool . key ( ) ;
33353335 let mut lp_pool = ctx. accounts . lp_pool . load_mut ( ) ?;
33363336
3337+ let tvl_before = quote_market
3338+ . get_tvl ( ) ?
3339+ . safe_add ( quote_constituent. vault_token_balance as u128 ) ?;
3340+
33373341 let remaining_accounts_iter = & mut ctx. remaining_accounts . iter ( ) . peekable ( ) ;
33383342 let AccountMaps {
33393343 perp_market_map,
@@ -3547,6 +3551,18 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>(
35473551 ctx. accounts . quote_token_vault . amount ,
35483552 ) ?;
35493553
3554+ let tvl_after = quote_market
3555+ . get_tvl ( ) ?
3556+ . safe_add ( quote_constituent. vault_token_balance as u128 ) ?;
3557+
3558+ validate ! (
3559+ tvl_before. safe_sub( tvl_after) ? <= 10 ,
3560+ ErrorCode :: LpPoolSettleInvariantBreached ,
3561+ "LP pool settlement would decrease TVL: {} -> {}" ,
3562+ tvl_before,
3563+ tvl_after
3564+ ) ?;
3565+
35503566 Ok ( ( ) )
35513567}
35523568
You can’t perform that action at this time.
0 commit comments