Verified contractExactMIT
DemoDriverClock
Address0x11aaa0614af8e708db4d8673cad74339bbe47cf2
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.30
- Same code
1 more contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- No
- EVM version
- osaka
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,364,415
- Creation transaction
- 0xd4c17ee122…214a950c51
src/DemoDriverClock.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IDriverClock} from "./interfaces/IDriverClock.sol";
/// @title Demo Driver clock
/// @notice Demo clock. {currentTime} returns `block.timestamp` plus an owner-controlled offset.
/// @dev The offset only increases. {advanceTime} is owner-only and rejects zero and any step above
/// {MAX_ADVANCE}. Addition uses checked math. This contract never calls another contract, so it does
/// not use `ReentrancyGuard`. Renouncing ownership freezes the offset.
contract DemoDriverClock is IDriverClock, Ownable2Step {
/// @notice Largest single step {advanceTime} accepts.
/// @dev Hard-coded because an advance cannot be undone, and later contracts narrow timestamps with `SafeCast`.
uint256 public constant MAX_ADVANCE = 365 days;
uint256 private s_offset;
/// @notice Emitted when the owner advances the demo clock.
/// @param secondsForward Seconds added to the offset.
/// @param newOffset Offset after this advance.
event TimeAdvanced(uint256 secondsForward, uint256 newOffset);
/// @notice The advance was zero.
error DemoDriverClock__ZeroSeconds();
/// @notice The advance was above {MAX_ADVANCE}.
/// @param secondsForward Seconds the caller tried to add.
/// @param maxSeconds The largest accepted step.
error DemoDriverClock__AdvanceTooLarge(uint256 secondsForward, uint256 maxSeconds);
/// @notice Sets the owner. The offset starts at zero.
/// @param initialOwner Account allowed to advance the clock. The zero address is rejected.
constructor(address initialOwner) Ownable(initialOwner) {}
/// @notice Moves the demo clock forward by `secondsForward`.
/// @dev Reverts with {DemoDriverClock__ZeroSeconds} when `secondsForward` is zero, and with
/// {DemoDriverClock__AdvanceTooLarge} when it is above {MAX_ADVANCE}. The offset is increased with
/// checked math. Only the owner may call this.
/// @param secondsForward Seconds to add to the offset. Must be greater than zero and at most {MAX_ADVANCE}.
function advanceTime(uint256 secondsForward) external onlyOwner {
if (secondsForward == 0) {
revert DemoDriverClock__ZeroSeconds();
}
if (secondsForward > MAX_ADVANCE) {
revert DemoDriverClock__AdvanceTooLarge(secondsForward, MAX_ADVANCE);
}
uint256 newOffset = s_offset + secondsForward;
s_offset = newOffset;
emit TimeAdvanced(secondsForward, newOffset);
}
/// @notice Returns `block.timestamp` plus the offset.
/// @return currentTime_ Demo time in seconds.
function currentTime() external view returns (uint256 currentTime_) {
currentTime_ = block.timestamp + s_offset;
}
/// @notice Returns the seconds added on top of `block.timestamp`.
/// @return offset_ The stored offset. Zero until the first advance.
function offset() external view returns (uint256 offset_) {
offset_ = s_offset;
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/interfaces/IDriverClock.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
/// @title Driver clock
/// @notice Read interface for the shared clock.
/// @dev Later contracts store this interface and call {currentTime} instead of `block.timestamp`.
interface IDriverClock {
/// @notice Returns the time later contracts should use.
/// @return currentTime_ Timestamp in seconds.
function currentTime() external view returns (uint256 currentTime_);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "osaka",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.