Skip to content

Commit

Permalink
feat: use osm in destination oracle
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
  • Loading branch information
Reinis-FRP committed Aug 28, 2023
1 parent dc58950 commit 317f723
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/OevOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract contract OevOracle is IOevOracle {
cachedLatestTimestamp = _latestTimestamp;
}

// TODO: Decide how to handle negative values. Since not all source oracles support negative values we may need to
// limit the support only to positive values.
function rawLatestAnswer() public view override returns (int256) {
if (canReturnCachedValue(cachedLatestTimestamp)) return cachedLatestAnswer;
return sourceAdapter.latestAnswer();
Expand Down
35 changes: 16 additions & 19 deletions src/adapters/makerdao/ChronicleDestinationOracleAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@
pragma solidity 0.8.17;

import "../../controllers/BaseController.sol";
import "../../interfaces/chronicle/IMedian.sol";
import "../../interfaces/chronicle/IOSM.sol";

contract ChronicleDestinationOracleAdapter is BaseController, IMedian {
uint8 public decimals;
contract ChronicleDestinationOracleAdapter is BaseController, IOSM {
constructor(address _sourceAdapter) BaseController(_sourceAdapter) {}

constructor(uint8 _decimals, address _sourceAdapter) BaseController(_sourceAdapter) {
decimals = _decimals;
}

function read() public view override returns (uint256) {
// TODO: if we never have more than 18 decimals on the output oracle then we can subtract decimals and divide.
return (uint256(rawLatestAnswer()) * (10 ** decimals)) / (10 ** 18);
function read() public view override returns (bytes32) {
// MakerDAO performs decimal conversion in collateral adapter contracts, so all oracle prices are expected to have
// 18 decimals, the same as returned by the rawLatestAnswer().
return bytes32(uint256(rawLatestAnswer()));
}

// TODO: might need to add toll functionality to replicate consumer authorization as in MakerDao.
function peek() public view override returns (uint256, bool) {
uint256 val = read();
return (val, val > 0);
}

function age() public view override returns (uint32) {
return uint32(rawLatestTimestamp());
function peek() public view override returns (bytes32, bool) {
uint256 val = uint256(rawLatestAnswer());
// TODO: In current design we cannot pass through invalid 0 values and fetching them from source OSM would revert.
// This might be required for MakerDAO when voiding Oracle sources.
return (bytes32(val), val > 0);
}

function bar() public view override returns (uint256) {
return uint256(decimals);
// This is only implemented to satisfy the interface, but should not be consumed, especially when mixing with other
// source Oracle adapters than OSM.
function zzz() public view override returns (uint64) {
return uint64(rawLatestTimestamp());
}
}
1 change: 1 addition & 0 deletions src/adapters/makerdao/ChronicleSourceOracleAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contract ChronicleSourceOracleAdapter is IBaseOracleAdapter {
}

function latestAnswer() public view override returns (int256) {
// This will revert if the price has been voided.
return int256((uint(source.read()) * (10 ** 18)) / (10 ** decimals));
}

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/chronicle/IOSM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface IOSM {
// function src() external view returns (address); // Address of source oracle.

// function hop() external view returns (uint16); // Oracle delay in seconds.
function zzz() external view returns (uint64); // Start of period timestamp when the price was last updated.
function zzz() external view returns (uint64); // Time of last update (rounded down to nearest multiple of hop).

// function bud(address _addr) external view returns (uint256); // Whitelisted contracts, set by an auth

Expand Down

0 comments on commit 317f723

Please sign in to comment.