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

Tellor Oracle Implementation #184

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
87423a9
TellorAdditions
themandalore Oct 17, 2019
5f715bb
tellor2
themandalore Oct 17, 2019
135f75c
v0
themandalore Oct 18, 2019
020fbac
almost compiling
brendaloya Oct 25, 2019
ef1017b
payable issue
brendaloya Oct 25, 2019
a0106c3
added comments, payble function still not working
brendaloya Oct 26, 2019
fa1e027
payable function still not working
brendaloya Oct 26, 2019
3dd62d7
compiles but requestDataWithEther commented out on TellorFallbackOrac…
brendaloya Oct 26, 2019
81282e0
Tellor has too many linked libraries, json deployment might not work
brendaloya Oct 27, 2019
e2db9f2
test not up yet, tellor copied over
brendaloya Oct 27, 2019
b516086
nickFix
themandalore Oct 27, 2019
ca7229f
Merge branch 'brenda' into nick1
themandalore Oct 27, 2019
e601ebe
Merge pull request #1 from tellor-io/nick1
brendaloya Oct 28, 2019
7dc2f68
added tellor, not compiling yet
brendaloya Oct 28, 2019
0af8eca
tellor taken out but migration file stayed
brendaloya Oct 28, 2019
28cd97f
migration failing to get arifacts
brendaloya Oct 28, 2019
ee327cd
Merge branch 'brenda' into brenda2
brendaloya Oct 28, 2019
c7b3e81
test init
themandalore Oct 28, 2019
bd7a4a4
Merge branch 'master' into brenda2
brendaloya Nov 6, 2019
eccd570
Merge pull request #3 from tellor-io/brenda2
themandalore Nov 6, 2019
e67a078
nonworking tests
themandalore Nov 29, 2019
ba55208
linking contracts
themandalore Dec 2, 2019
4185bae
half tests
themandalore Dec 3, 2019
400ea19
1 passing
themandalore Dec 3, 2019
522e5f9
tests passing
themandalore Dec 4, 2019
4cbeee5
comments
brendaloya Dec 6, 2019
f6ff360
updated usingtellor version and uncommented other tests
brendaloya Dec 6, 2019
7d78749
Merge pull request #4 from tellor-io/brenda
themandalore Dec 6, 2019
83e3eb1
final test
themandalore Dec 6, 2019
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
171 changes: 171 additions & 0 deletions contracts/Oracles/TellorFallbackOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
//This takes an existing oracle and adds a Tellor fallback

//setOutcome takes a dispute period and then can fallback to Tellor

pragma solidity ^0.5.0;
import "../Oracles/Oracle.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

interface TellorInterface {
function getFirstVerifiedDataAfter(uint _requestId, uint _timestamp) external returns(bool,uint,uint);

}

/// @title Centralized oracle data - Allows to create centralized oracle contracts
/// @author Brenda Loya - <[email protected]>
contract TellorFallbackOracleData {

/*
* Events
*/
event OwnerReplacement(address indexed newOwner);
event OutcomeAssignment(int outcome);
event OracleDisputed();

/*
* Storage
*/
address payable public tellorContract;
uint public requestId;
uint public endDate;
uint public disputePeriod;
uint public setTime;
uint public disputeCost;
bool public isDisputed;
address payable public owner;
bool public isSet;
int public outcome;

/*
* Modifiers
*/
modifier isOwner () {
// Only owner is allowed to proceed
require(msg.sender == owner);
_;
}
}

contract TellorFallbackOracleProxy is Proxy, TellorFallbackOracleData {

/// @dev Sets the tellor contract, dispute period, type of data(requestId), end date and dispute cost
/// @param _proxied is the proxy address
/// @param _owner is the contract owner address
/// @param _tellorContract is the Tellor UserContract that should be used by the interface
/// @param _disputePeriod is the period when disputes are allowed
/// @param _requestId is the request ID for the type of data that is will be used by the contract
/// @param _endDate is the contract/market end date or the date to use for getFirstVerifiedDataAfter
/// @param _disputeCost is the cost in ETH to dispute a value
constructor(address proxied, address payable _owner,address payable _tellorContract,uint _disputePeriod, uint _requestId, uint _endDate, uint _disputeCost)
public
Proxy(proxied)
{
require(_requestId != 0, "Use a valid _requestId, it should not be zero");
require(_tellorContract != address(0), "_tellorContract address should not be 0");
require(_endDate > now, "_endDate is not greater than now");
tellorContract = _tellorContract;
requestId = _requestId;
endDate = _endDate;
disputeCost = _disputeCost;
disputePeriod = _disputePeriod;
owner = _owner;
}
}

/// @title TellorFallbackOracle - Allows the contract owners to initiate and settle a dispute on a value provided by the centralized oracle
contract TellorFallbackOracle is Proxied, Oracle, TellorFallbackOracleData {

/*
* Public functions
*/
/// @dev Replaces owner
/// @param newOwner New owner
function replaceOwner(address payable newOwner)
public
isOwner
{
owner = newOwner;
emit OwnerReplacement(newOwner);
}

/// @dev Sets event outcome
/// @param _outcome Event outcome
function setOutcome(int _outcome)
public
isOwner
{
// Result is not set yet
require(!isSet);
setTime = now;
isSet = true;
outcome = _outcome;
emit OutcomeAssignment(_outcome);
}

/// @dev Returns if winning outcome is set
/// @return Is outcome set? (only true if the dispute period has passed)
function isOutcomeSet()
public
view
returns (bool)
{
if (now > setTime + disputePeriod){
return isSet;
}
else{
return false;
}

}

/// @dev Returns outcome
/// @return Outcome
function getOutcome()
public
view
returns (int)
{
return outcome;
}


/// @dev Allows users to initiate a dispute
function dispute()
public
payable
{
require(msg.value >= disputeCost, "The msg.value submitted is not greater than the dispute cost");
require(!isDisputed, "The value has already been disputed");
isDisputed = true;
isSet = false;
emit OracleDisputed();

}

/// @dev Sets event outcome based on the Tellor Oracle only if there is a dispute open and if the data is not available, user has to go request it or wait for it.
function setTellorOutcome()
public
{
// Result is not set yet
require(!isSet, "The outcome is already set");
require(isDisputed, "This is not under dispute");
require(requestId != 0, "Use a valid _requestId, it should not be zero");
bool _didGet;
uint _value;
uint _time;
(_didGet,_value,_time) = TellorInterface(tellorContract).getFirstVerifiedDataAfter(requestId,endDate);
if(_didGet){
outcome = int(_value);
isSet = true;
emit OutcomeAssignment(outcome);
}
}

/// @dev Allows the owner to withdraw the dispute and data request fees
function withdraw()
public{
if(isSet){
owner.transfer(address(this).balance);
}
}
}
44 changes: 44 additions & 0 deletions contracts/Oracles/TellorFallbackOracleFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.5.0;
import "../Oracles/TellorFallbackOracle.sol";


/// @title Centralized oracle factory contract - Allows to create centralized oracle contracts
/// @author Nicholas Fett - <[email protected]>
contract TellorFallbackOracleFactory {

/*
* Events
*/
event TellorFallbackOracleCreation(address indexed creator, TellorFallbackOracle tellorFallbackOracle);

/*
* Storage
*/
TellorFallbackOracle public tellorFallbackOracleMasterCopy;

/*
* Public functions
*/
constructor(TellorFallbackOracle _tellorFallbackOracleMasterCopy)
public
{
tellorFallbackOracleMasterCopy = _tellorFallbackOracleMasterCopy;
}

/// @dev Creates a new centralized oracle contract
/// @param _tellorContract is the Tellor UserContract that should be used by the interface
/// @param _disputePeriod is the period when disputes are allowed
/// @param _requestId is the request ID for the type of data that is will be used by the contract
/// @param _endDate is the contract/market end date or the date to use for getFirstVerifiedDataAfter
/// @param _disputeCost is the cost in ETH to dispute a val
/// @return Oracle contract
function createTellorFallbackOracle(address payable _tellorContract,uint _disputePeriod, uint _requestId, uint _endDate, uint _disputeCost)
public
returns (TellorFallbackOracle tellorFallbackOracle)
{
tellorFallbackOracle = TellorFallbackOracle(address(new TellorFallbackOracleProxy(
address(tellorFallbackOracleMasterCopy),msg.sender, _tellorContract,_disputePeriod,_requestId,_endDate,_disputeCost)));

emit TellorFallbackOracleCreation(msg.sender, tellorFallbackOracle);
}
}
88 changes: 88 additions & 0 deletions contracts/Oracles/TellorOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
pragma solidity ^0.5.0;
import "../Oracles/Oracle.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";


interface TellorInterface {
function getFirstVerifiedDataAfter(uint _requestId, uint _timestamp) external returns (bool,uint,uint);
}


contract TellorOracleData{
/*
* Events
*/
event OutcomeAssignment(int outcome);

/*
* Storage
*/
address payable public tellorContract;
uint public requestId;
uint public endDate;
bool public isSet;
int public outcome;
}

contract TellorOracleProxy is Proxy,TellorOracleData{

/// @dev Sets the tellor contract, dispute period, type of data(requestId), end date and dispute cost
/// @param _proxied address
/// @param _tellorContract is the Tellor user contract that should be used by the interface
/// @param _requestId is the request ID for the type of data that is will be used by the contract
/// @param _endDate is the contract/market end date or the date to use for getFirstVerifiedDataAfter
constructor(address proxied,address payable _tellorContract, uint _requestId, uint _endDate)
public
Proxy(proxied)
{
require(_requestId != 0, "Use a valid _requestId, it should not be zero");
require(_tellorContract != address(0), "_tellorContract address should not be 0");
require(_endDate > now, "_endDate is not greater than now");
tellorContract = _tellorContract;
requestId = _requestId;
endDate = _endDate;
}
}

contract TellorOracle is Proxied, Oracle,TellorOracleData{

/*
* Public functions
*/
/// @dev Sets event outcome
function setOutcome()
public
{
// Result is not set yet
require(!isSet, "The outcome is already set");
bool _didGet;
uint _value;
uint _time;
(_didGet,_value,_time) = TellorInterface(tellorContract).getFirstVerifiedDataAfter(requestId,endDate);
if(_didGet){
outcome = int(_value);
isSet = true;
emit OutcomeAssignment(outcome);
}
}

/// @dev Returns if winning outcome is set
/// @return Is outcome set?
function isOutcomeSet()
public
view
returns (bool)
{
return isSet;
}

/// @dev Returns outcome
/// @return Outcome
function getOutcome()
public
view
returns (int)
{
return outcome;
}
}
40 changes: 40 additions & 0 deletions contracts/Oracles/TellorOracleFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pragma solidity ^0.5.0;
import "../Oracles/TellorOracle.sol";


/// @title Tellor oracle factory contract - Allows to create tellor oracle contracts
/// @author Brenda Loya- <[email protected]>
contract TellorOracleFactory {

/*
* Events
*/
event TellorOracleCreation(address indexed creator, TellorOracle tellorOracle);

/*
* Storage
*/
TellorOracle public tellorOracleMasterCopy;

/*
* Public functions
*/
constructor(TellorOracle _tellorOracleMasterCopy)
public
{
tellorOracleMasterCopy = _tellorOracleMasterCopy;
}

/// @dev Creates a new centralized oracle contract
/// @param _tellorContract is the Tellor user contract that should be used by the interface
/// @param _requestId is the request ID for the type of data that is will be used by the contract
/// @param _endDate is the contract/market end date or the date to use for getFirstVerifiedDataAfter
/// @return Oracle contract
function createTellorOracle(address payable _tellorContract, uint _requestId, uint _endDate)
public
returns (TellorOracle tellorOracle)
{
tellorOracle = TellorOracle(address(new TellorOracleProxy(address(tellorOracleMasterCopy), _tellorContract,_requestId,_endDate)));
emit TellorOracleCreation(msg.sender, tellorOracle);
}
}
Loading