In liquidateSecondary
the collateral ratio is calculated using LibOracle.getSavedOrSpotOraclePrice()
.
https://github.com/Cyfrin/2023-09-ditto/blob/a93b4276420a092913f43169a353a6198d3c21b9/contracts/facets/MarginCallSecondaryFacet.sol#L38-L47
While in _secondaryLiquidationHelper
, the collateral amount corresponding to the debt is calculated using LibOracle.getPrice()
.
https://github.com/Cyfrin/2023-09-ditto/blob/a93b4276420a092913f43169a353a6198d3c21b9/contracts/facets/MarginCallSecondaryFacet.sol#L162-L168
Since LibOracle.getSavedOrSpotOraclePrice()
doesn't save the price, a possible mismatch in these prices can result in the transaction reverting when attempting to subtract ercDebtAtOraclePrice
from m.short.collateral
https://github.com/Cyfrin/2023-09-ditto/blob/a93b4276420a092913f43169a353a6198d3c21b9/contracts/facets/MarginCallSecondaryFacet.sol#L162-L177
A user calls liquidateSecondary on a postion with debt = 1
and collateral = 2001
The currently saved oracle price is 2020
but was fetched more than 15mins ago. Hence the oracle price used to calculate the collateralRatio
is fetched from Chainlink and returns 2000
. Hence the collateral ratio calculated is above 1 (2001/2000 > 1).
Inside the _secondaryLiquidationHelper
, since the collateral ratio is more than 1, the remaining collateral is calculated using the following equation
m.short.collateral - ercDebtAtOraclePrice
. The ercDebtAtOraclePrice
is calculated using the previously saved oracle price which is 2020
which will result in ercDebtAtOraclePrice
being 2020 * 1 == 2020
.
The transaction will revert when performing 2000 - 2020
Some secondary liquidations can get reverted for a brief period of time until the oracle price matches up.
Use the price obtained using LibOracle.getSavedOrSpotOraclePrice()
in both places.
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.