diff --git a/programs/openbook-v2/src/instructions/sweep_fees.rs b/programs/openbook-v2/src/instructions/sweep_fees.rs index 037130cb5..7aa48d48e 100644 --- a/programs/openbook-v2/src/instructions/sweep_fees.rs +++ b/programs/openbook-v2/src/instructions/sweep_fees.rs @@ -8,15 +8,15 @@ use crate::token_utils::*; pub fn sweep_fees(ctx: Context) -> Result<()> { let mut market = ctx.accounts.market.load_mut()?; - let amount = market.fees_available; + let fee_amount = market.fees_available; market.fees_available = 0; - market.quote_deposit_total -= amount; + market.quote_deposit_total -= fee_amount; let seeds = market_seeds!(market, ctx.accounts.market.key()); drop(market); token_transfer_signed( - amount, + fee_amount, &ctx.accounts.token_program, &ctx.accounts.market_quote_vault, &ctx.accounts.token_receiver_account, @@ -24,10 +24,18 @@ pub fn sweep_fees(ctx: Context) -> Result<()> { seeds, )?; + let rent = Rent::get()?; + let rent_exempt_amount = rent.minimum_balance(ctx.accounts.market.to_account_info().data_len()); + let penalty_amount = ctx.accounts.market.to_account_info().lamports().saturating_sub(rent_exempt_amount); + ctx.accounts.market.sub_lamports(penalty_amount)?; + ctx.accounts.collect_fee_admin.add_lamports(penalty_amount)?; + emit!(SweepFeesLog { market: ctx.accounts.market.key(), - amount, - receiver: ctx.accounts.token_receiver_account.key(), + fee_amount, + fee_receiver: ctx.accounts.token_receiver_account.key(), + penalty_amount, + penalty_receiver: ctx.accounts.collect_fee_admin.key(), }); Ok(()) diff --git a/programs/openbook-v2/src/logs.rs b/programs/openbook-v2/src/logs.rs index 98b3868ce..d1c8af058 100644 --- a/programs/openbook-v2/src/logs.rs +++ b/programs/openbook-v2/src/logs.rs @@ -72,8 +72,10 @@ pub struct SettleFundsLog { #[event] pub struct SweepFeesLog { pub market: Pubkey, - pub amount: u64, - pub receiver: Pubkey, + pub fee_amount: u64, + pub fee_receiver: Pubkey, + pub penalty_amount: u64, + pub penalty_receiver: Pubkey, } #[event]