There is a miscalculation in Market::getRealizedDebtUsd. The creditDeposits are collateral deposited by perps engine by calling CreditDelegationBranch::depositCreditForMarket. This credit deposit is later converted to USDC to back usd token of engine. So this credit deposit is not debt rather credit. The getRealizedDebtUsd function adds both netUsdTokenIssuance and usd value of all credit deposits and return the value. This is not correct as credit deposit is used to cover debt.
getRealizedDebtUsd incorrectly adds getCreditDepositsValueUsd(self) instead of subtracting it. convertMarketsCreditDepositsToUsdc converts credit deposits to USDC, adding them to usdcCreditPerVaultShare. This means credit deposits are not actual debt but rather equivalent to deposited USDC, so they must be subtracted. netUsdTokenIssuance is the debt and credit deposit is the value that is used to back the usd token issued.
Overstates the market's realized debt, leading to miscalculated vault unsettled debt.
This overestimation will cause users to receive less tokens in StabilityBranch's swap
CreditDelegationBranch::settleVaultsDebt will not work correctly, as vault.getUnsettledRealizedDebt will not return correct value
Modify getRealizedDebtUsd to subtract the credit deposits instead of adding them:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.