Verified contractPartial
OSM
Address0x5b89ff2decd360aa01cbd453aa2ced4f23b674b6
- Balance
0 ETH
- Transactions
1,141
- Compiler
solc 0.6.7
- Same code
1 more contract
Details
- Compiler
- solc 0.6.7+commit.b8d736ae
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 11,120,902
- Creation transaction
- 0x9141c508a2…09a57e159a
OSM.sol
pragma solidity >=0.6.7;
abstract contract DSValueLike {
function getResultWithValidity() virtual external view returns (uint256, bool);
}
contract OSM {
// --- Auth ---
mapping (address => uint) public authorizedAccounts;
/**
* @notice Add auth to an account
* @param account Account to add auth to
*/
function addAuthorization(address account) external isAuthorized {
authorizedAccounts[account] = 1;
emit AddAuthorization(account);
}
/**
* @notice Remove auth from an account
* @param account Account to remove auth from
*/
function removeAuthorization(address account) external isAuthorized {
authorizedAccounts[account] = 0;
emit RemoveAuthorization(account);
}
/**
* @notice Checks whether msg.sender can call an authed function
**/
modifier isAuthorized {
require(authorizedAccounts[msg.sender] == 1, "OSM/account-not-authorized");
_;
}
// --- Stop ---
uint256 public stopped;
modifier stoppable { require(stopped == 0, "OSM/is-stopped"); _; }
// --- Math ---
function add(uint64 x, uint64 y) internal pure returns (uint64 z) {
z = x + y;
require(z >= x);
}
address public priceSource;
uint16 constant ONE_HOUR = uint16(3600);
uint16 public updateDelay = ONE_HOUR;
uint64 public lastUpdateTime;
struct Feed {
uint128 value;
uint128 isValid;
}
Feed currentFeed;
Feed nextFeed;
// --- Events ---
event AddAuthorization(address account);
event RemoveAuthorization(address account);
event Start();
event Stop();
event ChangePriceSource(address priceSource);
event ChangeDelay(uint16 delay);
event RestartValue();
event UpdateResult(uint256 newMedian, uint256 lastUpdateTime);
constructor (address priceSource_) public {
authorizedAccounts[msg.sender] = 1;
priceSource = priceSource_;
if (priceSource != address(0)) {
(uint256 priceFeedValue, bool hasValidValue) = getPriceSourceUpdate();
if (hasValidValue) {
nextFeed = Feed(uint128(uint(priceFeedValue)), 1);
currentFeed = nextFeed;
lastUpdateTime = latestUpdateTime(currentTime());
emit UpdateResult(uint(currentFeed.value), lastUpdateTime);
}
}
emit AddAuthorization(msg.sender);
emit ChangePriceSource(priceSource);
}
function stop() external isAuthorized {
stopped = 1;
emit Stop();
}
function start() external isAuthorized {
stopped = 0;
emit Start();
}
function changePriceSource(address priceSource_) external isAuthorized {
priceSource = priceSource_;
emit ChangePriceSource(priceSource);
}
function currentTime() internal view returns (uint) {
return block.timestamp;
}
function latestUpdateTime(uint timestamp) internal view returns (uint64) {
require(updateDelay != 0, "OSM/update-delay-is-zero");
return uint64(timestamp - (timestamp % updateDelay));
}
function changeDelay(uint16 delay) external isAuthorized {
require(delay > 0, "OSM/delay-is-zero");
updateDelay = delay;
emit ChangeDelay(updateDelay);
}
function restartValue() external isAuthorized {
currentFeed = nextFeed = Feed(0, 0);
stopped = 1;
emit RestartValue();
}
function passedDelay() public view returns (bool ok) {
return currentTime() >= add(lastUpdateTime, updateDelay);
}
function getPriceSourceUpdate() internal view returns (uint256, bool) {
try DSValueLike(priceSource).getResultWithValidity() returns (uint256 priceFeedValue, bool hasValidValue) {
return (priceFeedValue, hasValidValue);
}
catch(bytes memory) {
return (0, false);
}
}
function updateResult() external stoppable {
require(passedDelay(), "OSM/not-passed");
(uint256 priceFeedValue, bool hasValidValue) = getPriceSourceUpdate();
if (hasValidValue) {
currentFeed = nextFeed;
nextFeed = Feed(uint128(uint(priceFeedValue)), 1);
lastUpdateTime = latestUpdateTime(currentTime());
emit UpdateResult(uint(currentFeed.value), lastUpdateTime);
}
}
function getResultWithValidity() external view returns (uint256,bool) {
return (uint(currentFeed.value), currentFeed.isValid == 1);
}
function getNextResultWithValidity() external view returns (uint256,bool) {
return (nextFeed.value, nextFeed.isValid == 1);
}
function read() external view returns (uint256) {
require(currentFeed.isValid == 1, "OSM/no-current-value");
return currentFeed.value;
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.