UNPKG

@levelk/token-price-oracles

Version:

tools for creating token price data feeds and oracles that integrate with on-chain dex's

904 lines 323 kB
{ "contractName": "DataFeedOracleBase", "abi": [ { "constant": true, "inputs": [], "name": "dataSource", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "_result", "type": "bytes32" }, { "indexed": false, "name": "_date", "type": "uint256" }, { "indexed": false, "name": "_index", "type": "uint256" }, { "indexed": false, "name": "_sender", "type": "address" } ], "name": "ResultSet", "type": "event" }, { "constant": false, "inputs": [ { "name": "_dataSource", "type": "address" } ], "name": "initialize", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "name": "_result", "type": "bytes32" }, { "name": "_date", "type": "uint256" } ], "name": "setResult", "outputs": [ { "name": "index", "type": "uint256" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "totalResults", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "_index", "type": "uint256" } ], "name": "resultByIndex", "outputs": [ { "name": "", "type": "bytes32" }, { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "_date", "type": "uint256" } ], "name": "resultByDate", "outputs": [ { "name": "", "type": "bytes32" }, { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "latestResultDate", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "latestResult", "outputs": [ { "name": "", "type": "bytes32" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "_index", "type": "uint256" } ], "name": "indexHasResult", "outputs": [ { "name": "", "type": "bool" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "_date", "type": "uint256" } ], "name": "dateHasResult", "outputs": [ { "name": "", "type": "bool" } ], "payable": false, "stateMutability": "view", "type": "function" } ], "bytecode": "0x608060405234801561001057600080fd5b50610b5c806100206000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631a0ba4f2146100a95780631b076edc146100ee57806330adb55d146101455780636a2ea57e146101955780636e4aa4d0146101c857806392549bf2146101f3578063a25fa35c14610242578063c0a6ab7914610292578063c4d66de8146102bd578063dab21b6314610300575b600080fd5b3480156100b557600080fd5b506100d460048036038101908080359060200190929190505050610345565b604051808215151515815260200191505060405180910390f35b3480156100fa57600080fd5b50610103610364565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561015157600080fd5b506101706004803603810190808035906020019092919050505061038a565b6040518083600019166000191681526020018281526020019250505060405180910390f35b3480156101a157600080fd5b506101aa61045a565b60405180826000191660001916815260200191505060405180910390f35b3480156101d457600080fd5b506101dd610495565b6040518082815260200191505060405180910390f35b3480156101ff57600080fd5b5061022c6004803603810190808035600019169060200190929190803590602001909291905050506104bd565b6040518082815260200191505060405180910390f35b34801561024e57600080fd5b5061026d6004803603810190808035906020019092919050505061067b565b6040518083600019166000191681526020018281526020019250505060405180910390f35b34801561029e57600080fd5b506102a761072c565b6040518082815260200191505060405180910390f35b3480156102c957600080fd5b506102fe600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061073c565b005b34801561030c57600080fd5b5061032b60048036038101908080359060200190929190505050610994565b604051808215151515815260200191505060405180910390f35b6000806035600084815260200190815260200160002054119050919050565b603660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008061039683610994565b151561040a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f4e6f20726573756c742073657420666f72205f696e646578000000000000000081525060200191505060405180910390fd5b6034600060338581548110151561041d57fe5b906000526020600020015481526020019081526020016000205460338481548110151561044657fe5b906000526020600020015491509150915091565b600060346000603361046a61072c565b81548110151561047657fe5b9060005260206000200154815260200190815260200160002054905090565b600060336104a161072c565b8154811015156104ad57fe5b9060005260206000200154905090565b6000603660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001807f5468652063616c6c6572206973206e6f7420746865206461746120736f75726381526020017f650000000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b81428111151515610623576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f446174652063616e6e6f7420626520696e20746865206675747572650000000081525060200191505060405180910390fd5b6000603380549050111561066057603361063b61072c565b81548110151561064757fe5b90600052602060002001548311151561065f57600080fd5b5b61066a8484610a1c565b61067261072c565b91505092915050565b60008061068783610345565b15156106fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f4e6f20726573756c742073657420666f72205f6461746500000000000000000081525060200191505060405180910390fd5b6034600084815260200190815260200160002054603560008581526020019081526020016000205491509150915091565b6000600160338054905003905090565b60008060019054906101000a900460ff168061075c575061075b610b1b565b5b8061077357506000809054906101000a900460ff16155b151561080d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001807f436f6e747261637420696e7374616e63652068617320616c726561647920626581526020017f656e20696e697469616c697a656400000000000000000000000000000000000081525060400191505060405180910390fd5b600060019054906101000a900460ff16159050801561085c576001600060016101000a81548160ff02191690831515021790555060016000806101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614151515610901576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f5f64617461536f757263652063616e6e6f74206265206164647265737328302981525060200191505060405180910390fd5b81603660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060336000908060018154018082558091505090600182039060005260206000200160009091929091909150555080156109905760008060016101000a81548160ff0219169083151502179055505b5050565b60008082111515610a0d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f5f696e646578206d7573742062652067726561746572207468616e203000000081525060200191505060405180910390fd5b81603380549050119050919050565b816034600083815260200190815260200160002081600019169055506033819080600181540180825580915050906001820390600052602060002001600090919290919091505550610a6c61072c565b6035600083815260200190815260200160002081905550610a8d8282610b2c565b7f441cd35745cc95136f39641bf16b52089bd7e481d97d7db059792befa3caec198282610ab861072c565b336040518085600019166000191681526020018481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200194505050505060405180910390a15050565b600080303b90506000811491505090565b50505600a165627a7a723058207db639b2d2abde073de1658f9b7c053e7088f7da36fe140f79db45cf84a2ca600029", "deployedBytecode": "0x6080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631a0ba4f2146100a95780631b076edc146100ee57806330adb55d146101455780636a2ea57e146101955780636e4aa4d0146101c857806392549bf2146101f3578063a25fa35c14610242578063c0a6ab7914610292578063c4d66de8146102bd578063dab21b6314610300575b600080fd5b3480156100b557600080fd5b506100d460048036038101908080359060200190929190505050610345565b604051808215151515815260200191505060405180910390f35b3480156100fa57600080fd5b50610103610364565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561015157600080fd5b506101706004803603810190808035906020019092919050505061038a565b6040518083600019166000191681526020018281526020019250505060405180910390f35b3480156101a157600080fd5b506101aa61045a565b60405180826000191660001916815260200191505060405180910390f35b3480156101d457600080fd5b506101dd610495565b6040518082815260200191505060405180910390f35b3480156101ff57600080fd5b5061022c6004803603810190808035600019169060200190929190803590602001909291905050506104bd565b6040518082815260200191505060405180910390f35b34801561024e57600080fd5b5061026d6004803603810190808035906020019092919050505061067b565b6040518083600019166000191681526020018281526020019250505060405180910390f35b34801561029e57600080fd5b506102a761072c565b6040518082815260200191505060405180910390f35b3480156102c957600080fd5b506102fe600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061073c565b005b34801561030c57600080fd5b5061032b60048036038101908080359060200190929190505050610994565b604051808215151515815260200191505060405180910390f35b6000806035600084815260200190815260200160002054119050919050565b603660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008061039683610994565b151561040a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f4e6f20726573756c742073657420666f72205f696e646578000000000000000081525060200191505060405180910390fd5b6034600060338581548110151561041d57fe5b906000526020600020015481526020019081526020016000205460338481548110151561044657fe5b906000526020600020015491509150915091565b600060346000603361046a61072c565b81548110151561047657fe5b9060005260206000200154815260200190815260200160002054905090565b600060336104a161072c565b8154811015156104ad57fe5b9060005260206000200154905090565b6000603660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001807f5468652063616c6c6572206973206e6f7420746865206461746120736f75726381526020017f650000000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b81428111151515610623576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f446174652063616e6e6f7420626520696e20746865206675747572650000000081525060200191505060405180910390fd5b6000603380549050111561066057603361063b61072c565b81548110151561064757fe5b90600052602060002001548311151561065f57600080fd5b5b61066a8484610a1c565b61067261072c565b91505092915050565b60008061068783610345565b15156106fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f4e6f20726573756c742073657420666f72205f6461746500000000000000000081525060200191505060405180910390fd5b6034600084815260200190815260200160002054603560008581526020019081526020016000205491509150915091565b6000600160338054905003905090565b60008060019054906101000a900460ff168061075c575061075b610b1b565b5b8061077357506000809054906101000a900460ff16155b151561080d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001807f436f6e747261637420696e7374616e63652068617320616c726561647920626581526020017f656e20696e697469616c697a656400000000000000000000000000000000000081525060400191505060405180910390fd5b600060019054906101000a900460ff16159050801561085c576001600060016101000a81548160ff02191690831515021790555060016000806101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614151515610901576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f5f64617461536f757263652063616e6e6f74206265206164647265737328302981525060200191505060405180910390fd5b81603660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060336000908060018154018082558091505090600182039060005260206000200160009091929091909150555080156109905760008060016101000a81548160ff0219169083151502179055505b5050565b60008082111515610a0d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f5f696e646578206d7573742062652067726561746572207468616e203000000081525060200191505060405180910390fd5b81603380549050119050919050565b816034600083815260200190815260200160002081600019169055506033819080600181540180825580915050906001820390600052602060002001600090919290919091505550610a6c61072c565b6035600083815260200190815260200160002081905550610a8d8282610b2c565b7f441cd35745cc95136f39641bf16b52089bd7e481d97d7db059792befa3caec198282610ab861072c565b336040518085600019166000191681526020018481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200194505050505060405180910390a15050565b600080303b90506000811491505090565b50505600a165627a7a723058207db639b2d2abde073de1658f9b7c053e7088f7da36fe140f79db45cf84a2ca600029", "sourceMap": "275:4304:10:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;275:4304:10;;;;;;;", "deployedSourceMap": "275:4304:10:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3824:109;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3824:109:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;460:25;;8:9:-1;5:2;;;30:1;27;20:12;5:2;460:25:10;;;;;;;;;;;;;;;;;;;;;;;;;;;2276:209;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2276:209:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3279:123;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3279:123:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3051:114;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3051:114:10;;;;;;;;;;;;;;;;;;;;;;;1575:290;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1575:290:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2722:203;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2722:203:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1947:90;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1947:90:10;;;;;;;;;;;;;;;;;;;;;;;1138:238;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1138:238:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;3526:167;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3526:167:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3824:109;3883:4;3926:1;3903:13;:20;3917:5;3903:20;;;;;;;;;;;;:24;3896:31;;3824:109;;;:::o;460:25::-;;;;;;;;;;;;;:::o;2276:209::-;2336:7;2345;2369:22;2384:6;2369:14;:22::i;:::-;2361:59;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2435:13;:28;2449:5;2455:6;2449:13;;;;;;;;;;;;;;;;;;2435:28;;;;;;;;;;;;2465:5;2471:6;2465:13;;;;;;;;;;;;;;;;;;2427:52;;;;2276:209;;;:::o;3279:123::-;3334:7;3360:13;:36;3374:5;3380:14;:12;:14::i;:::-;3374:21;;;;;;;;;;;;;;;;;;3360:36;;;;;;;;;;;;3353:43;;3279:123;:::o;3051:114::-;3110:7;3137:5;3143:14;:12;:14::i;:::-;3137:21;;;;;;;;;;;;;;;;;;3129:30;;3051:114;:::o;1575:290::-;1697:13;942:10;;;;;;;;;;;928:24;;:10;:24;;;920:70;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1676:5;761:3;752:5;:12;;744:53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1741:1;1726:5;:12;;;;:16;1722:77;;;1769:5;1775:14;:12;:14::i;:::-;1769:21;;;;;;;;;;;;;;;;;;1761:5;:29;1753:38;;;;;;;;1722:77;1805:26;1816:7;1825:5;1805:10;:26::i;:::-;1845:14;:12;:14::i;:::-;1838:21;;997:1;1575:290;;;;:::o;2722:203::-;2780:7;2789;2813:20;2827:5;2813:13;:20::i;:::-;2805:56;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2876:13;:20;2890:5;2876:20;;;;;;;;;;;;2898:13;:20;2912:5;2898:20;;;;;;;;;;;;2868:51;;;;2722:203;;;:::o;1947:90::-;1992:7;2030:1;2015:5;:12;;;;:16;2008:23;;1947:90;:::o;1138:238::-;601:19:12;496:12;;;;;;;;;;;:31;;;;512:15;:13;:15::i;:::-;496:31;:47;;;;532:11;;;;;;;;;;;531:12;496:47;488:106;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;624:12;;;;;;;;;;;623:13;601:35;;646:14;642:80;;;685:4;670:12;;:19;;;;;;;;;;;;;;;;;;711:4;697:11;;:18;;;;;;;;;;;;;;;;;;642:80;1236:1:10;1213:25;;:11;:25;;;;1205:70;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1295:11;1282:10;;:24;;;;;;;;;;;;;;;;;;1313:5;1324:1;1313:13;;39:1:-1;33:3;27:10;23:18;57:10;52:3;45:23;79:10;72:17;;0:93;1313:13:10;;;;;;;;;;;;;;;;;;;;;;740:14:12;736:55;;;779:5;764:12;;:20;;;;;;;;;;;;;;;;;;736:55;1138:238:10;;:::o;3526:167::-;3587:4;3617:1;3608:6;:10;3600:52;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3681:6;3666:5;:12;;;;:21;3659:28;;3526:167;;;:::o;4102:277::-;4193:7;4170:13;:20;4184:5;4170:20;;;;;;;;;;;:30;;;;;;;4207:5;4218;4207:17;;39:1:-1;33:3;27:10;23:18;57:10;52:3;45:23;79:10;72:17;;0:93;4207:17:10;;;;;;;;;;;;;;;;;;;;;;4254:14;:12;:14::i;:::-;4231:13;:20;4245:5;4231:20;;;;;;;;;;;:37;;;;4277:29;4291:7;4300:5;4277:13;:29::i;:::-;4320:53;4330:7;4339:5;4346:14;:12;:14::i;:::-;4362:10;4320:53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4102:277;;:::o;881:467:12:-;928:4;1269:10;1314:7;1302:20;1296:26;;1342:1;1336:2;:7;1329:14;;881:467;;:::o;4470:104:10:-;;;:::o", "source": "pragma solidity ^0.4.24;\r\n\r\nimport \"./IDataFeedOracle.sol\";\r\nimport \"../Initializer.sol\";\r\n\r\n/**\r\n * @title DataFeedOracleBase\r\n * @dev Allows a data source address to set bytes32 result values by date. Result values\r\n * can be publicly read by date and by index.\r\n */\r\ncontract DataFeedOracleBase is Initializer, IDataFeedOracle {\r\n\r\n uint256[] dates;\r\n\r\n mapping(uint256 => bytes32) resultsByDate;\r\n\r\n mapping(uint256 => uint256) indicesByDate;\r\n\r\n address public dataSource;\r\n\r\n event ResultSet(bytes32 _result, uint256 _date, uint256 _index, address _sender);\r\n\r\n /**\r\n * @dev Throws if _date is not current or past.\r\n * @param _date Date to check against the `now` value.\r\n */\r\n modifier onlyBefore(uint256 _date) {\r\n require(_date <= now, \"Date cannot be in the future\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Throws if the data source is not the caller.\r\n */\r\n modifier onlyDataSource() {\r\n require(msg.sender == dataSource, \"The caller is not the data source\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Initializes DataFeedOracleBase.\r\n * @param _dataSource The address that is allowed to set results.\r\n */\r\n function initialize(address _dataSource) public initializer {\r\n require(_dataSource != address(0), \"_dataSource cannot be address(0)\");\r\n dataSource = _dataSource;\r\n dates.push(0); // The first valid result index starts at 1\r\n }\r\n\r\n /**\r\n * @dev Sets a bytes32 result for the given date.\r\n * @param _result The result being set.\r\n * @param _date The date for the result.\r\n * @return The index of the result.\r\n */\r\n function setResult(bytes32 _result, uint256 _date)\r\n public\r\n onlyDataSource()\r\n onlyBefore(_date)\r\n returns (uint256 index)\r\n {\r\n if (dates.length > 0) {\r\n require(_date > dates[totalResults()]);\r\n }\r\n _setResult(_result, _date);\r\n return totalResults();\r\n }\r\n\r\n /**\r\n * @return The total number of results that have been set.\r\n */\r\n function totalResults() public view returns (uint256) {\r\n return dates.length - 1;\r\n }\r\n\r\n /**\r\n * @dev Returns a result and a date, given an index. Throws if no result exists for\r\n * the given index.\r\n * @param _index The index of the result.\r\n * @return The result value and the date of the result.\r\n */\r\n function resultByIndex(uint256 _index) public view returns (bytes32, uint256) {\r\n require(indexHasResult(_index), \"No result set for _index\");\r\n return (resultsByDate[dates[_index]], dates[_index]);\r\n }\r\n\r\n /**\r\n * @dev Returns a result and an index, given a date. Throws if no result exists for\r\n * the given date.\r\n * @param _date The date of the result.\r\n * @return The result value and the index of the result.\r\n */\r\n function resultByDate(uint256 _date) public view returns (bytes32, uint256) {\r\n require(dateHasResult(_date), \"No result set for _date\");\r\n return (resultsByDate[_date], indicesByDate[_date]);\r\n }\r\n\r\n /**\r\n * @notice Throws if no results have been set.\r\n * @return The date of the last result that was set.\r\n */\r\n function latestResultDate()\r\n public view\r\n returns (uint256)\r\n {\r\n return (dates[totalResults()]);\r\n }\r\n\r\n /**\r\n * @notice Throws if no results have been set.\r\n * @return The last result that was set.\r\n */\r\n function latestResult()\r\n public view\r\n returns (bytes32)\r\n {\r\n return resultsByDate[dates[totalResults()]];\r\n }\r\n\r\n /**\r\n * @param _index The index of a result.\r\n * @return `true` if a result for the given index exists.\r\n */\r\n function indexHasResult(uint256 _index) public view returns (bool) {\r\n require(_index > 0, \"_index must be greater than 0\");\r\n return dates.length > _index;\r\n }\r\n\r\n /**\r\n * @param _date The date of the data feed\r\n * @return `true` if a result has been set for the given date.\r\n */\r\n function dateHasResult(uint256 _date) public view returns (bool) {\r\n return indicesByDate[_date] > 0;\r\n }\r\n\r\n /**\r\n * @dev Sets a bytes32 result value and a date for the result.\r\n * @param _result The result to set.\r\n * @param _date The date of the result.\r\n */\r\n function _setResult(bytes32 _result, uint256 _date) internal {\r\n resultsByDate[_date] = _result;\r\n dates.push(_date);\r\n indicesByDate[_date] = totalResults();\r\n\r\n _resultWasSet(_result, _date);\r\n\r\n emit ResultSet(_result, _date, totalResults(), msg.sender);\r\n }\r\n\r\n /**\r\n * @dev Unimplemented function meant to be overidden in subclasses.\r\n */\r\n function _resultWasSet(bytes32 /*_result*/, uint256 /*_date*/) internal {\r\n // optional override\r\n }\r\n\r\n}\r\n", "sourcePath": "@levelk/tidbit/contracts/DataFeedOracles/DataFeedOracleBase.sol", "ast": { "absolutePath": "@levelk/tidbit/contracts/DataFeedOracles/DataFeedOracleBase.sol", "exportedSymbols": { "DataFeedOracleBase": [ 1649 ] }, "id": 1650, "nodeType": "SourceUnit", "nodes": [ { "id": 1358, "literals": [ "solidity", "^", "0.4", ".24" ], "nodeType": "PragmaDirective", "src": "0:24:10" }, { "absolutePath": "@levelk/tidbit/contracts/DataFeedOracles/IDataFeedOracle.sol", "file": "./IDataFeedOracle.sol", "id": 1359, "nodeType": "ImportDirective", "scope": 1650, "sourceUnit": 1700, "src": "28:31:10", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "@levelk/tidbit/contracts/Initializer.sol", "file": "../Initializer.sol", "id": 1360, "nodeType": "ImportDirective", "scope": 1650, "sourceUnit": 1763, "src": "61:28:10", "symbolAliases": [], "unitAlias": "" }, { "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 1361, "name": "Initializer", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 1762, "src": "306:11:10", "typeDescriptions": { "typeIdentifier": "t_contract$_Initializer_$1762", "typeString": "contract Initializer" } }, "id": 1362, "nodeType": "InheritanceSpecifier", "src": "306:11:10" }, { "arguments": null, "baseName": { "contractScope": null, "id": 1363, "name": "IDataFeedOracle", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 1699, "src": "319:15:10", "typeDescriptions": { "typeIdentifier": "t_contract$_IDataFeedOracle_$1699", "typeString": "contract IDataFeedOracle" } }, "id": 1364, "nodeType": "InheritanceSpecifier", "src": "319:15:10" } ], "contractDependencies": [ 1699, 1762 ], "contractKind": "contract", "documentation": "@title DataFeedOracleBase\r\n@dev Allows a data source address to set bytes32 result values by date. Result values\r\n can be publicly read by date and by index.\r", "fullyImplemented": true, "id": 1649, "linearizedBaseContracts": [ 1649, 1699, 1762 ], "name": "DataFeedOracleBase", "nodeType": "ContractDefinition", "nodes": [ { "constant": false, "id": 1367, "name": "dates", "nodeType": "VariableDeclaration", "scope": 1649, "src": "342:15:10", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_storage", "typeString": "uint256[]" }, "typeName": { "baseType": { "id": 1365, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "342:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 1366, "length": null, "nodeType": "ArrayTypeName", "src": "342:9:10", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_storage_ptr", "typeString": "uint256[]" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1371, "name": "resultsByDate", "nodeType": "VariableDeclaration", "scope": 1649, "src": "364:41:10", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_uint256_$_t_bytes32_$", "typeString": "mapping(uint256 => bytes32)" }, "typeName": { "id": 1370, "keyType": { "id": 1368, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "372:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Mapping", "src": "364:27:10", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_uint256_$_t_bytes32_$", "typeString": "mapping(uint256 => bytes32)" }, "valueType": { "id": 1369, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "383:7:10", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1375, "name": "indicesByDate", "nodeType": "VariableDeclaration", "scope": 1649, "src": "412:41:10", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_uint256_$_t_uint256_$", "typeString": "mapping(uint256 => uint256)" }, "typeName": { "id": 1374, "keyType": { "id": 1372, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "420:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Mapping", "src": "412:27:10", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_uint256_$_t_uint256_$", "typeString": "mapping(uint256 => uint256)" }, "valueType": { "id": 1373, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "431:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1377, "name": "dataSource", "nodeType": "VariableDeclaration", "scope": 1649, "src": "460:25:10", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1376, "name": "address", "nodeType": "ElementaryTypeName", "src": "460:7:10", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "public" }, { "anonymous": false, "documentation": null, "id": 1387, "name": "ResultSet", "nodeType": "EventDefinition", "parameters": { "id": 1386, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1379, "indexed": false, "name": "_result", "nodeType": "VariableDeclaration", "scope": 1387, "src": "508:15:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 1378, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "508:7:10", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1381, "indexed": false, "name": "_date", "nodeType": "VariableDeclaration", "scope": 1387, "src": "525:13:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1380, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "525:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1383, "indexed": false, "name": "_index", "nodeType": "VariableDeclaration", "scope": 1387, "src": "540:14:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1382, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "540:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1385, "indexed": false, "name": "_sender", "nodeType": "VariableDeclaration", "scope": 1387, "src": "556:15:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1384, "name": "address", "nodeType": "ElementaryTypeName", "src": "556:7:10", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "507:65:10" }, "src": "492:81:10" }, { "body": { "id": 1399, "nodeType": "Block", "src": "737:74:10", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 1394, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 1392, "name": "_date", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1389, "src": "752:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "<=", "rightExpression": { "argumentTypes": null, "id": 1393, "name": "now", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1779, "src": "761:3:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "752:12:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "446174652063616e6e6f7420626520696e2074686520667574757265", "id": 1395, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "766:30:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_c5ce101592d43d6975cd11aa5067af7ece3e737baf5bad4dbe2ce99fe0f5be84", "typeString": "literal_string \"Date cannot be in the future\"" }, "value": "Date cannot be in the future" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_c5ce101592d43d6975cd11aa5067af7ece3e737baf5bad4dbe2ce99fe0f5be84", "typeString": "literal_string \"Date cannot be in the future\"" } ], "id": 1391, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 1780, 1781 ], "referencedDeclaration": 1781, "src": "744:7:10", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 1396, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "744:53:10", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 1397, "nodeType": "ExpressionStatement", "src": "744:53:10" }, { "id": 1398, "nodeType": "PlaceholderStatement", "src": "804:1:10" } ] }, "documentation": "@dev Throws if _date is not current or past.\r\n@param _date Date to check against the `now` value.\r", "id": 1400, "name": "onlyBefore", "nodeType": "ModifierDefinition", "parameters": { "id": 1390, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1389, "name": "_date", "nodeType": "VariableDeclaration", "scope": 1400, "src": "722:13:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1388, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "722:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "src": "721:15:10" }, "src": "702:109:10", "visibility": "internal" }, { "body": { "id": 1411, "nodeType": "Block", "src": "913:91:10", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_address", "typeString": "address" }, "id": 1406, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "expression": { "argumentTypes": null, "id": 1403, "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1777, "src": "928:3:10", "typeDescriptions": { "typeIdentifier": "t_magic_message", "typeString": "msg" } }, "id": 1404, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "sender", "nodeType": "MemberAccess", "referencedDeclaration": null, "src": "928:10:10", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "id": 1405, "name": "dataSource", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1377, "src": "942:10:10", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "src": "928:24:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "5468652063616c6c6572206973206e6f7420746865206461746120736f75726365", "id": 1407, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "954:35:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_825460d4deee1d7fb1f86f54a2b94b615b8a7bd7146ca8df42d8ddb2ca90f7c6", "typeString": "literal_string \"The caller is not the data source\"" }, "value": "The caller is not the data source" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_825460d4deee1d7fb1f86f54a2b94b615b8a7bd7146ca8df42d8ddb2ca90f7c6", "typeString": "literal_string \"The caller is not the data source\"" } ], "id": 1402, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 1780, 1781 ], "referencedDeclaration": 1781, "src": "920:7:10", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 1408, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "920:70:10", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 1409, "nodeType": "ExpressionStatement", "src": "920:70:10" }, { "id": 1410, "nodeType": "PlaceholderStatement", "src": "997:1:10" } ] }, "documentation": "@dev Throws if the data source is not the caller.\r", "id": 1412, "name": "onlyDataSource", "nodeType": "ModifierDefinition", "parameters": { "id": 1401, "nodeType": "ParameterList", "parameters": [], "src": "910:2:10" }, "src": "887:117:10", "visibility": "internal" }