Users can create Smart Vaults to deposit collateral and borrow EURO stablecoins. They also have the option to swap collateral types, as long as the return amount from the swap keeps the position at a healthy ratio. This is enforced by the calculateMinimumAmountOut function, however there is a problem in the way it retrieves its prices which could lead inaccurate amounts.
The calculateMinimumAmountOut function calculates collateralValueMinusSwapValue with the following formula:
To calculate this, the function initially assesses the total value of the user's collateral in euros. This is done using the tokenToEurAvg method from the calculator contract, which calculates an average based on the last four prices of the token:
However, when subtracting the value of the token being swapped from the total collateral, the formula employs tokenToEur, which provides the latest price of the token, rather than an average. This results in a potential mismatch in the valuation method used within the same calculation:
User A swaps their entire collateral of 1 ETH for USD.
The latest ETH price experiences a sharp decline (e.g., 200, 500, 501, 502).
The average price (tokenToEurAvg) would be significantly higher than the latest price (tokenToEur at 200).
The potential inflation or deflation of the calculateMinimumAmountOut value due to inconsistent pricing methods can significantly impact the swap process. This value, used as amountOutMinimum in swaps, can lead to inaccuracies in collateral value assessments. In the worst case, it could lead to the user's position becoming undercollateralized, potentially triggering an unwarranted liquidation.
This inconsistency in price calculations can result in an inaccurate evaluation of swaps, affecting the collateral ratios and potentially leading to liquidations.
Manual analysis
The protocol should standardize the price retrieval method in the calculateMinimumAmountOut function to ensure consistency. Either both components of the formula should use the average price or the latest price to maintain accuracy in collateral swap calculations.
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.