in perp settle fees, dont error, rather return early, this enables blindly concatenating perp settle fees to perp settle pnl (#526)

* in perp settle fees, dont error, rather return early

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-03-30 17:00:41 +02:00 committed by GitHub
parent 7d389275a8
commit 2957796de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 11 deletions

View File

@ -43,18 +43,17 @@ pub fn perp_settle_fees(ctx: Context<PerpSettleFees>, max_settle_amount: u64) ->
// Calculate PnL
let pnl = perp_position.unsettled_pnl(&perp_market, oracle_price)?;
// Account perp position must have a loss to be able to settle against the fee account
require!(pnl.is_negative(), MangoError::ProfitabilityMismatch);
require!(
perp_market.fees_accrued.is_positive(),
MangoError::ProfitabilityMismatch
);
let settleable_pnl = perp_position.apply_pnl_settle_limit(&perp_market, pnl);
require!(
settleable_pnl.is_negative(),
MangoError::ProfitabilityMismatch
);
if !settleable_pnl.is_negative() || !perp_market.fees_accrued.is_positive() {
msg!(
"Not settling: pnl {}, perp_market.fees_accrued {}, settleable_pnl {}",
pnl,
perp_market.fees_accrued,
settleable_pnl
);
return Ok(());
}
// Settle for the maximum possible capped to max_settle_amount
let settlement = settleable_pnl