Skip to content

Commit

Permalink
Emit the Write event and Oracle -> OpenOracle in contract names
Browse files Browse the repository at this point in the history
  • Loading branch information
jflatow committed Jun 21, 2019
1 parent 3ad9093 commit 6e9123c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
12 changes: 6 additions & 6 deletions contracts/DelFiPrice.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./OraclePriceData.sol";
import "./OracleView.sol";
import "./OpenOraclePriceData.sol";
import "./OpenOracleView.sol";

/**
* @notice The DelFi Price Feed View
* @author Compound Labs, Inc.
*/
contract DelFiPrice is OracleView {
contract DelFiPrice is OpenOracleView {
/**
* @notice The mapping of medianized prices per symbol
*/
Expand All @@ -19,7 +19,7 @@ contract DelFiPrice is OracleView {
*/
uint public constant expiration = 48 hours;

constructor(OraclePriceData data_, address[] memory sources_) public OracleView(data_, sources_) {}
constructor(OpenOraclePriceData data_, address[] memory sources_) public OpenOracleView(data_, sources_) {}

/**
* @notice Primary entry point to post and recalculate prices
Expand All @@ -33,7 +33,7 @@ contract DelFiPrice is OracleView {

// Post the messages, whatever they are
for (uint i = 0; i < messages.length; i++) {
OraclePriceData(address(data)).put(messages[i], signatures[i]);
OpenOraclePriceData(address(data)).put(messages[i], signatures[i]);
}

// Recalculate the asset prices
Expand All @@ -56,7 +56,7 @@ contract DelFiPrice is OracleView {
function medianPrice(string memory symbol, address[] memory sources_, uint expiration_) public view returns (uint median, uint count) {
uint[] memory postedPrices = new uint[](sources_.length);
for (uint i = 0; i < sources_.length; i++) {
(uint timestamp, uint price) = OraclePriceData(address(data)).get(sources_[i], symbol);
(uint timestamp, uint price) = OpenOraclePriceData(address(data)).get(sources_[i], symbol);
if (block.timestamp < timestamp + expiration_) {
postedPrices[count] = price;
count++;
Expand Down
7 changes: 6 additions & 1 deletion contracts/OracleData.sol → contracts/OpenOracleData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ pragma experimental ABIEncoderV2;
* @title The Open Oracle Data Base Contract
* @author Compound Labs, Inc.
*/
contract OracleData {
contract OpenOracleData {
/**
* @notice The event emitted when a source writes to its storage
*/
//event Write(address indexed source, <Key> indexed key, uint timestamp, <Value> value);

/**
* @notice Write a bunch of signed datum to the authenticated storage mapping
* @param message The payload containing the timestamp, and (key, value) pairs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./OracleData.sol";
import "./OpenOracleData.sol";

/**
* @title The Open Oracle Price Data Contract
* @author Compound Labs, Inc.
*/
contract OraclePriceData is OracleData {
contract OpenOraclePriceData is OpenOracleData {
/**
* @notice The event emitted when a source writes to its storage
*/
event Write(address indexed source, string indexed key, uint timestamp, uint value);

/**
* @notice The fundamental unit of storage for a reporter source
*/
Expand Down Expand Up @@ -44,6 +49,7 @@ contract OraclePriceData is OracleData {

// Update storage
data[source][key] = Datum(timestamp, value);
emit Write(source, key, timestamp, value);
}
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/OracleView.sol → contracts/OpenOracleView.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "./OracleData.sol";
import "./OpenOracleData.sol";

/**
* @title The Open Oracle View Base Contract
* @author Compound Labs, Inc.
*/
contract OracleView {
contract OpenOracleView {
/**
* @notice The Oracle Data Contract backing this View
*/
OracleData public data;
OpenOracleData public data;

/**
* @notice The static list of sources used by this View
Expand All @@ -26,7 +26,7 @@ contract OracleView {
* @param data_ The address of the oracle data contract which is backing the view
* @param sources_ The list of source addresses to include in the aggregate value
*/
constructor(OracleData data_, address[] memory sources_) public {
constructor(OpenOracleData data_, address[] memory sources_) public {
data = data_;
sources = sources_;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/DelFiPriceTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('Oracle', () => {
describe('DelFiPrice', () => {
it('sanity checks the delfi price view', async () => {
const {
address,
Expand All @@ -22,7 +22,7 @@ describe('Oracle', () => {
'0x177ee777e72b8c042e05ef41d1db0f17f1fcb0e8150b37cfad6993e4373bdf18',
'0x177ee777e72b8c042e05ef41d1db0f17f1fcb0e8150b37cfad6993e4373bdf19'
].map(web3.eth.accounts.privateKeyToAccount);
const priceData = await deploy('OraclePriceData', []);
const priceData = await deploy('OpenOraclePriceData', []);
const delfi = await deploy('DelFiPrice', [priceData.address, sources.map(a => a.address)]);
const now = new Date - 0;

Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Oracle', () => {
['ETH', 255]
]
], ['ETH']);
expect(post2.gasUsed).toBeLessThan(240000);
expect(post2.gasUsed).toBeLessThan(250000);

expect(await getPrice('BTC')).numEquals(0); // not added to list of symbols to update
expect(await getPrice('ETH')).numEquals(257);
Expand All @@ -100,7 +100,7 @@ describe('Oracle', () => {
['ETH', 255]
]
], ['BTC', 'ETH']);
expect(post3a.gasUsed).toBeLessThan(300000);
expect(post3a.gasUsed).toBeLessThan(320000);

expect(await getPrice('BTC')).numEquals(8500);
expect(await getPrice('ETH')).numEquals(256);
Expand Down
12 changes: 6 additions & 6 deletions tests/OracleDataTest.js → tests/OpenOracleDataTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

describe('OracleData', () => {
describe('OpenOracleData', () => {
// XXX describe cant be async with jest :(
// all things considered, havent found a nice way to do setup
it('sets up the oracle data and tests some stuff', async () => {
Expand All @@ -14,8 +14,8 @@ describe('OracleData', () => {
} = saddle; // XXX this kinda sucks

const privateKey = '0x177ee777e72b8c042e05ef41d1db0f17f1fcb0e8150b37cfad6993e4373bdf10';
const oracleData = await deploy('OracleData', [], {from: account});
const priceData = await deploy('OraclePriceData', [], {from: account});
const oracleData = await deploy('OpenOracleData', [], {from: account});
const priceData = await deploy('OpenOraclePriceData', [], {from: account});

// gets default data
let {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('OracleData', () => {
} = sign(encode(now, [[K, V]]), privateKey));

const wrote1 = await priceData.methods.put(message, signature).send({from: account, gas: 1000000});
expect(wrote1.gasUsed).toBeLessThan(80000);
expect(wrote1.gasUsed).toBeLessThan(82000);

// reads 1 pair
({
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('OracleData', () => {
]), privateKey));

const wrote2a = await priceData.methods.put(message, signature).send({from: account, gas: 1000000});
expect(wrote2a.gasUsed).toBeLessThan(125000);
expect(wrote2a.gasUsed).toBeLessThan(130000);

({
0: timestamp,
Expand All @@ -117,7 +117,7 @@ describe('OracleData', () => {
]), privateKey));

const wrote2b = await priceData.methods.put(message, signature).send({from: account, gas: 1000000});
expect(wrote2b.gasUsed).toBeLessThan(65000);
expect(wrote2b.gasUsed).toBeLessThan(70000);

}, 30000);
});
9 changes: 9 additions & 0 deletions tests/OpenOracleViewTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

describe('OpenOracleView', () => {
it('is a valid view', async () => {
const oracleData = await saddle.deploy('OpenOracleData', []);
const oracleView = await saddle.deploy('OpenOracleView', [oracleData.address, []]);

expect(await oracleView.methods.data.call()).toEqual(oracleData.address);
});
});
9 changes: 0 additions & 9 deletions tests/OracleViewTest.js

This file was deleted.

0 comments on commit 6e9123c

Please sign in to comment.