-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initial Contracts #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
pragma solidity 0.4.24; | ||
|
||
interface IMedianOracle{ | ||
|
||
// // The number of seconds after which the report is deemed expired. | ||
// uint256 public reportExpirationTimeSec; | ||
|
||
// // The number of seconds since reporting that has to pass before a report | ||
// // is usable. | ||
// uint256 public reportDelaySec; | ||
function reportDelaySec() external returns(uint256); | ||
function reportExpirationTimeSec() external returns(uint256); | ||
function pushReport(uint256 payload) external; | ||
function purgeReports() external; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
pragma solidity 0.4.24; | ||
|
||
|
||
/** | ||
* @title Tellor Getters | ||
* @dev Oracle contract with all tellor getter functions. The logic for the functions on this contract | ||
* is saved on the TellorGettersLibrary, TellorTransfer, TellorGettersLibrary, and TellorStake | ||
*/ | ||
interface ITellorGetters { | ||
function getNewValueCountbyRequestId(uint _requestId) external view returns(uint); | ||
function getTimestampbyRequestIDandIndex(uint _requestID, uint _index) external view returns(uint); | ||
function retrieveData(uint _requestId, uint _timestamp) external view returns (uint); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.22 <0.8.0; | ||
|
||
contract Migrations { | ||
address public owner = msg.sender; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
require( | ||
msg.sender == owner, | ||
"This function is restricted to the contract's owner" | ||
); | ||
_; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pragma solidity 0.4.24; | ||
|
||
import "./ITellorGetters.sol"; | ||
import "./IMedianOracle.sol"; | ||
|
||
contract TellorProvider{ | ||
|
||
ITellorGetters public tellor; | ||
IMedianOracle public medianOracle; | ||
|
||
|
||
struct TellorTimes{ | ||
uint128 time0; | ||
uint128 time1; | ||
} | ||
TellorTimes public tellorReport; | ||
uint256 constant TellorID = 10; | ||
|
||
|
||
constructor(address _tellor, address _medianOracle) public { | ||
tellor = ITellorGetters(_tellor); | ||
medianOracle = IMedianOracle(_medianOracle); | ||
} | ||
|
||
function pushTellor() external { | ||
(bool retrieved, uint256 value, uint256 _time) = getTellorData(); | ||
//Saving _time in a storage value to quickly verify disputes later | ||
if(tellorReport.time0 >= tellorReport.time1) { | ||
tellorReport.time1 = uint128(_time); | ||
} else { | ||
tellorReport.time0 = uint128(_time); | ||
} | ||
medianOracle.pushReport(value); | ||
} | ||
|
||
function verifyTellorReports() external { | ||
//most recent tellor report is in dispute, so let's purge it | ||
if(tellor.retrieveData(TellorID, tellorReport.time0) == 0 || tellor.retrieveData(TellorID,tellorReport.time1) == 0){ | ||
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. How about if one of them is valid, it pushes it after purging? 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. We will add that to the job. After we purge a report, we'll check if we have a valid value and push it again |
||
medianOracle.purgeReports(); | ||
} | ||
} | ||
|
||
function getTellorData() internal view returns(bool, uint256, uint256){ | ||
uint256 _count = tellor.getNewValueCountbyRequestId(TellorID); | ||
if(_count > 0) { | ||
uint256 _time = tellor.getTimestampbyRequestIDandIndex(TellorID, _count - 1); | ||
uint256 _value = tellor.retrieveData(TellorID, _time); | ||
return(true, _value, _time); | ||
} | ||
return (false, 0, 0); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Migrations = artifacts.require("Migrations"); | ||
|
||
module.exports = function (deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
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.
Hey am I missing something or should the report only get pushed if
retrieved
is true?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.
retrieved
is true if the value count is greater than 0.TellorID
10 has months of data with a value count of over 4500, soretrieved
will always be true when using the current Tellor contracts.