-
Notifications
You must be signed in to change notification settings - Fork 93
OETH Oracle #1815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
OETH Oracle #1815
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2ca524f
Added AggregatorV3Interface diagram
naddison36 876fd06
Updated OETH Oracle contracts diagram
naddison36 c7dc5b4
Added price Oracle to vault
naddison36 4c6361c
Added reference implementation of OETH Oracle
naddison36 08824ef
Refactor OETH Oracle
naddison36 3be9b7a
Fixed warnings of price override
naddison36 0d55c81
Fix unit tests
naddison36 90e8e8c
Fix fork tests
naddison36 db6fa51
Implements two floorPrice functions to compare
naddison36 dbd9525
Remove test floorPrice2
naddison36 714e393
Added price cap on OETH Oracle
naddison36 06a6691
Merge remote-tracking branch 'origin/master' into nicka/oeth-oracle
naddison36 8e03c2d
Only get OETH floor price from the vault if the market price is < 0.995
naddison36 3eb58da
Merge remote-tracking branch 'origin/master' into nicka/oeth-oracle
naddison36 d08572e
Updated OETH Oracle Natspec and code comments
naddison36 0805d43
Update Vault Natspec for floorPrice
naddison36 7e21054
fixed OETH Oracle fork tests
naddison36 b7e118a
Merge remote-tracking branch 'origin/master' into nicka/oeth-oracle
naddison36 f52cd40
fix unit tests after merge
naddison36 d8e34a1
regenerated OETH Oracle contract diagrams
naddison36 a393ffd
Updated Oracle docs
naddison36 2bd9e0a
Fix Slither error
naddison36 2789e13
Fixed OETHOracle deploy script
naddison36 f31dcca
Added OETH Oracle unit tests
naddison36 85bf20e
Removed transferToken from governable behaviour as that is strategy r…
naddison36 b6af118
Internal review updates to the OETH Oracle
naddison36 467a0d2
Merge remote-tracking branch 'origin/master' into nicka/oeth-oracle
naddison36 2b83ec6
Merge remote-tracking branch 'origin/master' into nicka/oeth-oracle
naddison36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Diagrams | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { MockCurveAbstractMetapool } from "./MockCurveAbstractMetapool.sol"; | ||
| import "../MintableERC20.sol"; | ||
|
|
||
| contract MockCurveOethEthPool is MockCurveAbstractMetapool { | ||
| constructor(address[2] memory _coins) | ||
| ERC20("Curve.fi Factory Pool: OETH", "OETHCRV-f") | ||
| { | ||
| coins = _coins; | ||
| } | ||
|
|
||
| // Simulate pool's EMA Oracle price | ||
| uint256 public price_oracle = 9995e14; // 0.9995 | ||
|
|
||
| function setOraclePrice(uint256 _price) public { | ||
| price_oracle = _price; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { IOracleReceiver } from "./IOracleReceiver.sol"; | ||
| import { AggregatorV3Interface } from "../interfaces/chainlink/AggregatorV3Interface.sol"; | ||
| import { Governable } from "../governance/Governable.sol"; | ||
|
|
||
| /** | ||
| * @title BaseOracle | ||
| * @notice Generic Chainlink style oracle | ||
| * @author Origin Protocol Inc | ||
| */ | ||
| abstract contract BaseOracle is | ||
| AggregatorV3Interface, | ||
| IOracleReceiver, | ||
| Governable | ||
| { | ||
| /// @notice Contract or account that can call addRoundData() to update the Oracle prices | ||
| address public oracleUpdater; | ||
|
|
||
| /// @notice Last round ID where isBadData is false and price is within maximum deviation | ||
| uint80 public lastCorrectRoundId; | ||
|
|
||
| /// @notice Historical Oracle prices | ||
| Round[] public rounds; | ||
|
|
||
| /// @notice Packed Round data struct | ||
| /// @notice price Oracle price to 18 decimals | ||
| /// @notice timestamp timestamp in seconds of price | ||
| struct Round { | ||
| uint128 price; | ||
| uint40 timestamp; | ||
| } | ||
|
|
||
| event SetOracleUpdater(address oracleUpdater); | ||
|
|
||
| constructor(address _oracleUpdater) Governable() { | ||
| _setOracleUpdater(_oracleUpdater); | ||
| } | ||
|
|
||
| /*************************************** | ||
| Internal Setters | ||
| ****************************************/ | ||
|
|
||
| /// @notice Sets the contract or account that can add Oracle prices | ||
| /// @param _oracleUpdater Address of the contract or account that can update the Oracle prices | ||
| function _setOracleUpdater(address _oracleUpdater) internal { | ||
| emit SetOracleUpdater(_oracleUpdater); | ||
| oracleUpdater = _oracleUpdater; | ||
| } | ||
|
|
||
| /*************************************** | ||
| External Setters | ||
| ****************************************/ | ||
|
|
||
| /// @notice Sets the contract or account that can update the Oracle prices | ||
| /// @param _oracleUpdater Address of the contract or account that can update the Oracle prices | ||
| function setOracleUpdater(address _oracleUpdater) external onlyGovernor { | ||
| _setOracleUpdater(_oracleUpdater); | ||
| } | ||
|
|
||
| /*************************************** | ||
| Metadata | ||
| ****************************************/ | ||
|
|
||
| /// @notice The number of decimals in the Oracle price. | ||
| function decimals() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be expressed as: |
||
| external | ||
| pure | ||
| virtual | ||
| override | ||
| returns (uint8 _decimals) | ||
| { | ||
| _decimals = 18; | ||
| } | ||
|
|
||
| /// @notice The version number for the AggregatorV3Interface. | ||
| /// @dev Adheres to AggregatorV3Interface, which is different than typical semver | ||
| function version() | ||
| external | ||
| view | ||
| virtual | ||
| override | ||
| returns (uint256 _version) | ||
| { | ||
| _version = 1; | ||
| } | ||
|
|
||
| /*************************************** | ||
| Oracle Receiver | ||
| ****************************************/ | ||
|
|
||
| /// @notice Adds a new Oracle price by the Oracle updater. | ||
| /// Can not be run twice in the same block. | ||
| /// @param _price is the Oracle price with 18 decimals | ||
| function addPrice(uint128 _price) external override { | ||
| if (msg.sender != oracleUpdater) revert OnlyOracleUpdater(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 on using custom errors |
||
| if (_price == 0) revert NoPriceData(); | ||
|
|
||
| // Can not add price in the same or previous blocks | ||
| uint256 _roundsLength = rounds.length; | ||
| if ( | ||
| _roundsLength > 0 && | ||
| block.timestamp <= rounds[_roundsLength - 1].timestamp | ||
| ) { | ||
| revert AddPriceSameBlock(); | ||
| } | ||
|
|
||
| lastCorrectRoundId = uint80(_roundsLength); | ||
|
|
||
| rounds.push( | ||
| Round({ price: _price, timestamp: uint40(block.timestamp) }) | ||
| ); | ||
| } | ||
|
|
||
| /*************************************** | ||
| Prices | ||
| ****************************************/ | ||
|
|
||
| function _getRoundData(uint80 _roundId) | ||
| internal | ||
| view | ||
| returns ( | ||
| uint80 roundId, | ||
| int256 answer, | ||
| uint256 startedAt, | ||
| uint256 updatedAt, | ||
| uint80 answeredInRound | ||
| ) | ||
| { | ||
| if (rounds.length <= _roundId) revert NoPriceData(); | ||
DanielVF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Round memory _round = rounds[_roundId]; | ||
| answer = int256(uint256(_round.price)); | ||
|
|
||
| roundId = answeredInRound = _roundId; | ||
| startedAt = updatedAt = _round.timestamp; | ||
| } | ||
|
|
||
| /// @notice Returns the Oracle price data for a specific round. | ||
| /// @param _roundId The round ID | ||
| /// @return roundId The round ID | ||
| /// @return answer The Oracle price | ||
| /// @return startedAt Timestamp of when the round started | ||
| /// @return updatedAt Timestamp of when the round was updated | ||
| /// @return answeredInRound The round ID in which the answer was computed | ||
| function getRoundData(uint80 _roundId) | ||
| external | ||
| view | ||
| override | ||
| returns ( | ||
| uint80 roundId, | ||
| int256 answer, | ||
| uint256 startedAt, | ||
| uint256 updatedAt, | ||
| uint80 answeredInRound | ||
| ) | ||
| { | ||
| ( | ||
| roundId, | ||
| answer, | ||
| startedAt, | ||
| updatedAt, | ||
| answeredInRound | ||
| ) = _getRoundData(_roundId); | ||
| } | ||
|
|
||
| /// @notice Returns the latest Oracle price data. | ||
| /// @return roundId The round ID | ||
| /// @return answer The Oracle price | ||
| /// @return startedAt Timestamp of when the round started | ||
| /// @return updatedAt Timestamp of when the round was updated | ||
| /// @return answeredInRound The round ID in which the answer was computed | ||
| function latestRoundData() | ||
| external | ||
| view | ||
| override | ||
| returns ( | ||
| uint80 roundId, | ||
| int256 answer, | ||
| uint256 startedAt, | ||
| uint256 updatedAt, | ||
| uint80 answeredInRound | ||
| ) | ||
| { | ||
| ( | ||
| roundId, | ||
| answer, | ||
| startedAt, | ||
| updatedAt, | ||
| answeredInRound | ||
| ) = _getRoundData(lastCorrectRoundId); | ||
| } | ||
|
|
||
| /*************************************** | ||
| Errors | ||
| ****************************************/ | ||
|
|
||
| error AddPriceSameBlock(); | ||
| error NoPriceData(); | ||
| error OnlyOracleUpdater(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface IOracleReceiver { | ||
| function addPrice(uint128 price) external; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { BaseOracle } from "./BaseOracle.sol"; | ||
|
|
||
| /** | ||
| * @title OETH Oracle | ||
| * @notice Chainlink style oracle for OETH/ETH | ||
| * @author Origin Protocol Inc | ||
| */ | ||
| contract OETHOracle is BaseOracle { | ||
| string public constant override description = "OETH / ETH"; | ||
|
|
||
| /** | ||
| * @param _oracleUpdater Address of the contract that is authorized to add prices | ||
| */ | ||
| constructor(address _oracleUpdater) BaseOracle(_oracleUpdater) {} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find any reference to
isBadDatadoes this comment need updating?