Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dbf23b4
Oracle constructor with the update frequency and reward
miktam May 31, 2018
c1fd9c7
Added setter and getter
miktam May 31, 2018
3d717b0
Added caller constraint
miktam May 31, 2018
dc1f4e0
Refactored to use struct and statically allocated array
miktam May 31, 2018
a390520
Refactored - removed getter by index
miktam May 31, 2018
364eb21
Added activation
miktam May 31, 2018
d462fdb
Added activated flag
miktam May 31, 2018
6415e7d
Added block coinstraints
miktam May 31, 2018
ba3c230
Reorded imports
miktam May 31, 2018
5384547
Added time constraints
miktam May 31, 2018
1172b49
Added proper claim
miktam May 31, 2018
270beb1
Added tests
miktam May 31, 2018
18f730e
Cancel the reward if oracle violated the rules
miktam May 31, 2018
f863d96
Revert changes in test.sh
miktam May 31, 2018
4a97762
Fixed lint issues
miktam May 31, 2018
5343c84
Merge branch 'master' into better_oracle_interfaces_16
miktam Jun 11, 2018
01658e8
Merge branch 'master' into better_oracle_interfaces_16
miktam Jun 11, 2018
119b387
Merge branch 'better_oracle_interfaces_16' of github.com:miktam/openz…
miktam Jun 11, 2018
2f3b47d
Increased code coverage #16
miktam Jun 11, 2018
6a0cbf3
Do not update deps #16
miktam Jun 11, 2018
8684d5a
Kept only new files (oracle related) #16
miktam Jun 11, 2018
bacbf7a
Restored file fully #16
miktam Jun 11, 2018
e7a6715
Fixed lint issues #16
miktam Jun 11, 2018
08a0149
Improved tests #16
miktam Jun 11, 2018
6314d89
Merge branch 'master' into better_oracle_interfaces_16
miktam Jun 18, 2018
6c22c5f
Merge branch 'master' into better_oracle_interfaces_16
miktam Jul 28, 2018
3236421
Removed frequency restrictions
miktam Jul 29, 2018
2636470
Merge branch 'better_oracle_interfaces_16' of github.com:miktam/openz…
miktam Jul 29, 2018
647045b
Merge branch 'master' into better_oracle_interfaces_16
miktam Aug 10, 2018
6a30525
Implements draft version of EIP 1154
miktam Aug 10, 2018
26f83ec
Reverted extra new line
miktam Aug 10, 2018
6cfaf8c
Improved comments
miktam Aug 13, 2018
00ed63a
Renamed Oracle interfaces
miktam Aug 23, 2018
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
Prev Previous commit
Next Next commit
Added proper claim
  • Loading branch information
miktam committed May 31, 2018
commit 1172b49a1bd929aa71fe9cb5998d7a460c8ac739
11 changes: 11 additions & 0 deletions contracts/oracle/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ contract Oracle is Ownable {
* @param _value value to add
*/
function addOracleData(uint256 _value) public onlyOracle {
require(activated);
// solium-disable-next-line security/no-block-members
uint256 blockDifference = block.timestamp.sub(oracleStorage.lastUpdate);
require(blockDifference <= oracleStorage.maxFrequency);
Expand All @@ -101,4 +102,14 @@ contract Oracle is Ownable {
function getOracleData() public view returns (uint256[]) {
return oracleStorage.oracleData;
}

/**
* @dev Get a reward
* Prerequisite: all required updates happened
*/
function claimReward() public onlyOracle {
require(activated);
require(oracleStorage.updatedAmount == oracleStorage.amountOfUpdates);
oracleStorage.oracle.transfer(oracleStorage.reward);
}
}
24 changes: 23 additions & 1 deletion test/oracle/Oracle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract('Oracle', function ([owner, oracle, other]) {
const amount = web3.toWei(1.0, 'ether');

beforeEach(async function () {
const amountOfUpdates = 10;
const amountOfUpdates = 3;
// 24h
const minFrequencyInSeconds = 60 * 60 * 24;
// 25h
Expand Down Expand Up @@ -52,6 +52,9 @@ contract('Oracle', function ([owner, oracle, other]) {
const valueOne = 1;
const valueTwo = 2;

await web3.eth.sendTransaction({ from: owner, to: this.contract.address, value: amount });
await this.contract.activate({ from: owner });

increaseTime(60 * 60 * 24 + 1);

await this.contract.addOracleData(valueOne, { from: oracle });
Expand All @@ -66,6 +69,25 @@ contract('Oracle', function ([owner, oracle, other]) {
oracleData[1].should.be.bignumber.equal(valueTwo);
});

it('should reward the oracle if all updates happened properly', async function () {
const value = 1;

await web3.eth.sendTransaction({ from: owner, to: this.contract.address, value: amount });
await this.contract.activate({ from: owner });

increaseTime(60 * 60 * 24 + 1);
await this.contract.addOracleData(value, { from: oracle });

increaseTime(60 * 60 * 24 + 1);
await this.contract.addOracleData(value, { from: oracle });

increaseTime(60 * 60 * 24 + 1);
await this.contract.addOracleData(value, { from: oracle });

// claim reward by oracle
await this.contract.claimReward({ from: oracle });
});

it('should throw is updated more frequently than allowed', async function () {
const valueOne = 1;
// 1 day minus one second
Expand Down