Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions contracts/IMedianOracle.sol
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;
}
14 changes: 14 additions & 0 deletions contracts/ITellorGetters.sol
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);
}
19 changes: 19 additions & 0 deletions contracts/Migrations.sol
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;
}
}
53 changes: 53 additions & 0 deletions contracts/TellorProvider.sol
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
Copy link
Member

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?

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, so retrieved will always be true when using the current Tellor contracts.

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){
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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);
}

}
5 changes: 5 additions & 0 deletions migrations/1_initial_migration.js
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);
};
Loading