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

Tellorhardhat #2

Open
wants to merge 6 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
cache
artifacts/
.env
slither
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
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){
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);
}

}
88 changes: 88 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

/**
* @type import('hardhat/config').HardhatUserConfig
*/
require("@nomiclabs/hardhat-waffle");
require("hardhat-gas-reporter");
require("solidity-coverage");
require("hardhat-gas-reporter");
require('hardhat-contract-sizer');
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-etherscan");
require("dotenv").config();


module.exports = {
solidity: {
compilers: [
{
version: "0.4.24",
settings: {
optimizer: {
enabled: true,
runs: 300
}
}
},
{
version: "0.7.4",
settings: {
optimizer: {
enabled: true,
runs: 300
}
}
}
]
},
networks: {
hardhat: {
hardfork: process.env.CODE_COVERAGE ? "berlin" : "london",
initialBaseFeePerGas: 0,
accounts: {
mnemonic:
"nick lucian brenda kevin sam fiscal patch fly damp ocean produce wish",
count: 40,
},
forking: {
url: "https://eth-mainnet.alchemyapi.io/v2/7dW8KCqWwKa1vdaitq-SxmKfxWZ4yPG6"
},
allowUnlimitedContractSize: true
},
rinkeby: {
url: `${process.env.NODE_URL_RINKEBY}`,
seeds: [process.env.TESTNET_PK],
gas: 1000000 ,
gasPrice: 40000000000
} //,
// mainnet: {
// url: `${process.env.NODE_URL_MAINNET}`,
// accounts: [process.env.PRIVATE_KEY],
// gas: 10000000 ,
// gasPrice: 50000000000
// }
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: process.env.ETHERSCAN
},

contractSizer: {
alphaSort: true,
runOnCompile: true,
disambiguatePaths: false,
},

mocha: {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
}




}



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