In the getVaultAccumulatedValues
the it is meant to get the accumulated values for a vault from a market. However the formula used is incorrect.
When recalculateVaultsCreditCapacity
is called, for each vault it will perform _recalculateConnectedMarketsState
. Since the one market can be connected to two vaults the following operations are made in order to calculate the values only for the specific vault:
For each market it will load the debt:
After that it will distribute the debt to the vaults:
To distribute the debt to all the vaults it will calculate the debt per share, which is debt/(credit from all the vaults for the market)
:
After the debt per delegated credit is calculated getVaultAccumulatedValues
is called in order to calculate the debt for the specific vault.
However the getVaultAccumulatedValues
will use wrong formula to calculate the accumulated values:
Here we can see that the vaultCreditShareX18
is calculated. However in the realizedDebtChangeUsdX18
as the values are per share, the vaultDelegatedCreditUsdX18 should be used in order to calculate the realizedDebtChangeUsdX18
instead of vaultCreditShareX18.
Consider the following scenario:
1.There VaultA and VaultB which are connected to MarketAB. Both vaults have delegated 50USD as credit meaning that the total delegated for the market will be 100USD. When the market accrues a realized debt of 10 USD, using the above formula the debt for vault A will be calculated the following way:
realizedDebtUsdPerVaultShare
= 10/100 = 0.1e18USD
vaultCreditShareX18
= 50/100 = 0.5e18
realizedDebtChangeUsdX18
= 0.5*0.1 = 0.05USD instead of the 5 USD it should receive as debt. (in the example we assume that lastVaultDistributedRealizedDebtUsdPerShareX18
is not zero but a very small negligible value)
_recalculateConnectedMarketsState
will always return wrong values.
Manual Review
Multiply by vaultDelegatedCreditUsdX18
instead of totalVaultSharesX18
.
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.