Skip to content

Commit

Permalink
feat: updated price oracle sentinel interface
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Oct 28, 2022
1 parent 0e9927e commit 0457e71
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
19 changes: 16 additions & 3 deletions contracts/interfaces/ISequencerOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ pragma solidity 0.8.10;
interface ISequencerOracle {
/**
* @notice Returns the health status of the sequencer.
* @return True if the sequencer is down, false otherwise
* @return The timestamp of last time the sequencer got up
* @return roundId The round ID from the aggregator for which the data was retrieved combined with a phase to ensure
* that round IDs get larger as time moves forward.
* @return answer The answer for the latest round: 0 if the sequencer is up, 1 if it is down.
* @return startedAt The timestamp when the round was started.
* @return updatedAt The timestamp of the block in which the answer was updated on L1.
* @return answeredInRound The round ID of the round in which the answer was computed.
*/
function latestAnswer() external view returns (bool, uint256);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
19 changes: 17 additions & 2 deletions contracts/mocks/oracle/SequencerOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ contract SequencerOracle is ISequencerOracle, Ownable {
}

/// @inheritdoc ISequencerOracle
function latestAnswer() external view override returns (bool, uint256) {
return (_isDown, _timestampGotUp);
function latestRoundData()
external
view
override
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
int256 isDown;
if (_isDown) {
isDown = 1;
}
return (0, isDown, 0, _timestampGotUp, 0);
}
}
4 changes: 2 additions & 2 deletions contracts/protocol/configuration/PriceOracleSentinel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ contract PriceOracleSentinel is IPriceOracleSentinel {
* @return True if the SequencerOracle is up and the grace period passed, false otherwise
*/
function _isUpAndGracePeriodPassed() internal view returns (bool) {
(bool isDown, uint256 timestampGotUp) = _sequencerOracle.latestAnswer();
return !isDown && block.timestamp - timestampGotUp > _gracePeriod;
(, int256 answer, , uint256 lastUpdateTimestamp, ) = _sequencerOracle.latestRoundData();
return answer == 0 && block.timestamp - lastUpdateTimestamp > _gracePeriod;
}

/// @inheritdoc IPriceOracleSentinel
Expand Down
12 changes: 6 additions & 6 deletions test-suites/price-oracle-sentinel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ makeSuite('PriceOracleSentinel', (testEnv: TestEnv) => {

expect(await addressesProvider.getPriceOracleSentinel()).to.be.eq(priceOracleSentinel.address);

const answer = await sequencerOracle.latestAnswer();
expect(answer[0]).to.be.eq(false);
const answer = await sequencerOracle.latestRoundData();
expect(answer[1]).to.be.eq(0);
expect(answer[3]).to.be.eq(0);
});

it('Pooladmin updates grace period for sentinel', async () => {
Expand Down Expand Up @@ -212,8 +212,8 @@ makeSuite('PriceOracleSentinel', (testEnv: TestEnv) => {
const userGlobalData = await pool.getUserAccountData(borrower.address);

expect(userGlobalData.healthFactor).to.be.lt(utils.parseUnits('1', 18), INVALID_HF);
const currAnswer = await sequencerOracle.latestAnswer();
waitForTx(await sequencerOracle.setAnswer(true, currAnswer[1]));
const currAnswer = await sequencerOracle.latestRoundData();
waitForTx(await sequencerOracle.setAnswer(true, currAnswer[3]));
});

it('Tries to liquidate borrower when sequencer is down (HF > 0.95) (revert expected)', async () => {
Expand Down Expand Up @@ -431,8 +431,8 @@ makeSuite('PriceOracleSentinel', (testEnv: TestEnv) => {
});

it('Turn off sequencer + increase time more than grace period', async () => {
const currAnswer = await sequencerOracle.latestAnswer();
await waitForTx(await sequencerOracle.setAnswer(true, currAnswer[1]));
const currAnswer = await sequencerOracle.latestRoundData();
await waitForTx(await sequencerOracle.setAnswer(true, currAnswer[3]));
await increaseTime(GRACE_PERIOD.mul(2).toNumber());
});

Expand Down

0 comments on commit 0457e71

Please sign in to comment.