From 6e9123ca5003022f4d0d5f8f49ef3b38de806725 Mon Sep 17 00:00:00 2001 From: Jared Flatow Date: Fri, 21 Jun 2019 13:35:15 -0700 Subject: [PATCH] Emit the Write event and Oracle -> OpenOracle in contract names --- contracts/DelFiPrice.sol | 12 ++++++------ contracts/{OracleData.sol => OpenOracleData.sol} | 7 ++++++- .../{OraclePriceData.sol => OpenOraclePriceData.sol} | 10 ++++++++-- contracts/{OracleView.sol => OpenOracleView.sol} | 8 ++++---- tests/DelFiPriceTest.js | 8 ++++---- tests/{OracleDataTest.js => OpenOracleDataTest.js} | 12 ++++++------ tests/OpenOracleViewTest.js | 9 +++++++++ tests/OracleViewTest.js | 9 --------- 8 files changed, 43 insertions(+), 32 deletions(-) rename contracts/{OracleData.sol => OpenOracleData.sol} (89%) rename contracts/{OraclePriceData.sol => OpenOraclePriceData.sol} (86%) rename contracts/{OracleView.sol => OpenOracleView.sol} (84%) rename tests/{OracleDataTest.js => OpenOracleDataTest.js} (90%) create mode 100644 tests/OpenOracleViewTest.js delete mode 100644 tests/OracleViewTest.js diff --git a/contracts/DelFiPrice.sol b/contracts/DelFiPrice.sol index 99208f8d..292e2230 100644 --- a/contracts/DelFiPrice.sol +++ b/contracts/DelFiPrice.sol @@ -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 */ @@ -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 @@ -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 @@ -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++; diff --git a/contracts/OracleData.sol b/contracts/OpenOracleData.sol similarity index 89% rename from contracts/OracleData.sol rename to contracts/OpenOracleData.sol index 8802adc9..9fa7fde6 100644 --- a/contracts/OracleData.sol +++ b/contracts/OpenOracleData.sol @@ -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, indexed key, uint timestamp, value); + /** * @notice Write a bunch of signed datum to the authenticated storage mapping * @param message The payload containing the timestamp, and (key, value) pairs diff --git a/contracts/OraclePriceData.sol b/contracts/OpenOraclePriceData.sol similarity index 86% rename from contracts/OraclePriceData.sol rename to contracts/OpenOraclePriceData.sol index 683225c8..2436cdf0 100644 --- a/contracts/OraclePriceData.sol +++ b/contracts/OpenOraclePriceData.sol @@ -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 */ @@ -44,6 +49,7 @@ contract OraclePriceData is OracleData { // Update storage data[source][key] = Datum(timestamp, value); + emit Write(source, key, timestamp, value); } } diff --git a/contracts/OracleView.sol b/contracts/OpenOracleView.sol similarity index 84% rename from contracts/OracleView.sol rename to contracts/OpenOracleView.sol index 88215dc5..4a9c19ec 100644 --- a/contracts/OracleView.sol +++ b/contracts/OpenOracleView.sol @@ -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 @@ -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_; } diff --git a/tests/DelFiPriceTest.js b/tests/DelFiPriceTest.js index 4291330c..ab79a3cf 100644 --- a/tests/DelFiPriceTest.js +++ b/tests/DelFiPriceTest.js @@ -1,4 +1,4 @@ -describe('Oracle', () => { +describe('DelFiPrice', () => { it('sanity checks the delfi price view', async () => { const { address, @@ -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; @@ -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); @@ -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); diff --git a/tests/OracleDataTest.js b/tests/OpenOracleDataTest.js similarity index 90% rename from tests/OracleDataTest.js rename to tests/OpenOracleDataTest.js index 31143c4f..5e30f645 100644 --- a/tests/OracleDataTest.js +++ b/tests/OpenOracleDataTest.js @@ -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 () => { @@ -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 { @@ -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 ({ @@ -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, @@ -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); }); diff --git a/tests/OpenOracleViewTest.js b/tests/OpenOracleViewTest.js new file mode 100644 index 00000000..baf26314 --- /dev/null +++ b/tests/OpenOracleViewTest.js @@ -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); + }); +}); diff --git a/tests/OracleViewTest.js b/tests/OracleViewTest.js deleted file mode 100644 index a1520db7..00000000 --- a/tests/OracleViewTest.js +++ /dev/null @@ -1,9 +0,0 @@ - -describe('View', () => { - it('is a valid view', async () => { - const oracleData = await saddle.deploy('OracleData', []); - const oracleView = await saddle.deploy('OracleView', [oracleData.address, []]); - - expect(await oracleView.methods.data.call()).toEqual(oracleData.address); - }); -});