The CreditDelegationbranch.sol
's settleVaultsDebt
function settles the vault's debt or credit by swapping usdc for assets and vice versa. It incorrectly reads the vault state(whether in credit or debt) and swaps the collaterals
The CreditDelegationbranch.sol
's settleVaultsDebt
function settles the vault's debt or credit by swapping usdc for assets and vice versa. The ctx.vaultUnsettledRealizedDebtUsdX18
is computed via vault.getUnsettledRealizedDebt
function which calculates the unsettledRealizedDebtUsdX18
by adding marketsRealizedDebtUsd
and depositedUsdc
:
Now in accordance to the intended behaviour of the protocol the vault is considered in debt if the net sum of its Markets debt/credit realizations is positive, meaning that it has received more assets than the UsdTokens it had to issue. And when in debt i.e aforementioned value is positive the vault's assets will be swapped to USDC and it will be the inverse/opposite of it when the vault is in credit, meaning the value is negative then the USDC will be swapped to the assets.
But in the codebase the opposite is going on as it checks vaultUnsettledRealizedDebt
> 0
that means that this value is negative and the vault is in credit and its USDC needs to be swapped to the vaultAsset but actually in the code the opposite of this is happening, i.e the assets are being swapped with USDC.
The same opposite behaviour is being performed when the vault's value is positive i.e it is in debt.
manual Review
refactor the code so it works as intended, meaning that when the vault is in debt(positive value, greater than 0) then swap its assets to USDC and if its in credit, then do the inverse, swap usdc to asset.
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.