Проверенный контрактТочноеGPL-2.0-or-later
OperatorTimelock
Адрес0xa9d8a71b2f66bb0cf4e8b127bf7d08d841133b22
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.28
- Тот же код
ещё 3 контракта
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- GPL-2.0-or-later
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 429 738
- Транзакция создания
- 0xaacb9e5a25…03d53f4a0d
3 файла
- src/governance/OperatorTimelock.solглавный7,36 КБ
- src/governance/interfaces/IOperatorTimelock.sol6,53 КБ
- src/libraries/PendingLib.sol5,49 КБ
src/governance/OperatorTimelock.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.28;
import {PendingLib} from "../libraries/PendingLib.sol";
import {IOperatorTimelock} from "./interfaces/IOperatorTimelock.sol";
/// @title OperatorTimelock
/// @notice Calldata-based timelock controller for module operator actions.
/// @dev Uses calldata-based pending operations keyed by `keccak256(callData)` per module,
/// so it works with any module type without per-function wrappers. The OperatorTimelock
/// is set as the `operator` of each module it governs.
///
/// Timelock tiers:
/// - TIMELOCK (24h default): parameter changes (setRiskEngineParams, setLiquidationParams, etc.)
/// - LONG_TIMELOCK (72h default): operator transfer (transferOperator), guardian/ownership changes
///
/// The Guardian can revoke any pending operation but cannot submit or accept.
contract OperatorTimelock is IOperatorTimelock {
using PendingLib for PendingLib.PendingAddress;
/* CONSTANTS */
/// @inheritdoc IOperatorTimelock
uint256 public constant MIN_TIMELOCK = 1 days;
/// @inheritdoc IOperatorTimelock
uint256 public constant MIN_LONG_TIMELOCK = 3 days;
/* IMMUTABLES */
/// @inheritdoc IOperatorTimelock
uint256 public immutable TIMELOCK;
/// @inheritdoc IOperatorTimelock
uint256 public immutable LONG_TIMELOCK;
/* STORAGE */
/// @inheritdoc IOperatorTimelock
address public owner;
/// @inheritdoc IOperatorTimelock
address public guardian;
/// @dev Pending operations per module, keyed by operationKey = keccak256(callData).
/// @dev Stores validAt timestamp. The callData itself is re-supplied at accept time and verified.
mapping(address module => mapping(bytes32 operationKey => uint64)) public pendingOperations;
/// @dev Pending ownership transfer (2-step, 72h).
PendingLib.PendingAddress public pendingOwner;
/// @dev Pending guardian change (72h).
PendingLib.PendingAddress public pendingGuardian;
/* CONSTRUCTOR */
/// @param initialOwner The initial owner allowed to submit and execute operations.
/// @param initialGuardian The initial guardian allowed to revoke pending operations.
/// @param timelock The standard timelock for module operations. Must be at least `MIN_TIMELOCK`.
/// @param longTimelock The long timelock for operator transfers. Must be at least `MIN_LONG_TIMELOCK` and no
/// shorter than `timelock`.
constructor(address initialOwner, address initialGuardian, uint256 timelock, uint256 longTimelock) {
if (initialOwner == address(0)) revert ZeroAddress();
if (timelock < MIN_TIMELOCK || longTimelock < MIN_LONG_TIMELOCK || longTimelock < timelock) {
revert InvalidTimelock();
}
TIMELOCK = timelock;
LONG_TIMELOCK = longTimelock;
owner = initialOwner;
guardian = initialGuardian;
emit OwnerUpdated(initialOwner);
emit GuardianUpdated(initialGuardian);
}
/* MODIFIERS */
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
modifier onlyOwnerOrGuardian() {
if (msg.sender != owner && msg.sender != guardian) revert NotOwnerOrGuardian();
_;
}
modifier onlyGuardian() {
if (msg.sender != guardian) revert NotGuardian();
_;
}
/* OPERATION LIFECYCLE */
/// @dev The selector for `transferOperator(address)`, which uses LONG_TIMELOCK.
bytes4 private constant _TRANSFER_OPERATOR_SELECTOR = 0x29605e77;
/// @inheritdoc IOperatorTimelock
function submit(address module, bytes calldata callData) external onlyOwner {
bytes32 key = keccak256(callData);
if (pendingOperations[module][key] != 0) revert AlreadyPending();
// Enforce timelock per selector: transferOperator uses LONG_TIMELOCK, all others use TIMELOCK.
bytes4 selector = bytes4(callData[:4]);
uint256 delay = selector == _TRANSFER_OPERATOR_SELECTOR ? LONG_TIMELOCK : TIMELOCK;
uint64 validAt = uint64(block.timestamp + delay);
pendingOperations[module][key] = validAt;
emit OperationSubmitted(module, key, callData, validAt);
}
/// @inheritdoc IOperatorTimelock
function accept(address module, bytes calldata callData) external onlyOwner {
bytes32 key = keccak256(callData);
uint64 validAt = pendingOperations[module][key];
if (validAt == 0) revert NoPendingOperation();
if (block.timestamp < validAt) revert TimelockNotExpired(validAt);
delete pendingOperations[module][key];
// Forward the call to the module. The OperatorTimelock IS the module's operator,
// so msg.sender will be this contract which passes the onlyOperator check.
(bool success, bytes memory returndata) = module.call(callData);
if (!success) {
// Preserve module revert data so queued operation failures remain debuggable.
assembly {
revert(add(returndata, 32), mload(returndata))
}
}
emit OperationAccepted(module, key);
}
/// @inheritdoc IOperatorTimelock
function revoke(address module, bytes32 operationKey) external onlyOwnerOrGuardian {
if (pendingOperations[module][operationKey] == 0) revert NoPendingOperation();
delete pendingOperations[module][operationKey];
emit OperationRevoked(module, operationKey, msg.sender);
}
/* OWNERSHIP TRANSFER (2-STEP, 72H) */
/// @inheritdoc IOperatorTimelock
function submitTransferOwnership(address newOwner) external onlyOwner {
PendingLib.assertNotPending(pendingOwner.validAt);
pendingOwner.update(newOwner, LONG_TIMELOCK);
emit OwnershipTransferSubmitted(newOwner, pendingOwner.validAt);
}
/// @inheritdoc IOperatorTimelock
/// @dev Must be called by the pending new owner (2-step acceptance).
function acceptTransferOwnership() external {
PendingLib.assertExecutable(pendingOwner.validAt);
if (msg.sender != pendingOwner.value) revert NotPendingOwner();
owner = pendingOwner.value;
pendingOwner.clear();
emit OwnerUpdated(owner);
}
/// @inheritdoc IOperatorTimelock
function revokeTransferOwnership() external onlyGuardian {
PendingLib.assertIsPending(pendingOwner.validAt);
pendingOwner.clear();
emit OwnershipTransferRevoked(msg.sender);
}
/* GUARDIAN CHANGE (72H) */
/// @inheritdoc IOperatorTimelock
function submitSetGuardian(address newGuardian) external onlyOwner {
PendingLib.assertNotPending(pendingGuardian.validAt);
pendingGuardian.update(newGuardian, LONG_TIMELOCK);
emit GuardianSubmitted(newGuardian, pendingGuardian.validAt);
}
/// @inheritdoc IOperatorTimelock
function acceptSetGuardian() external onlyOwner {
PendingLib.assertExecutable(pendingGuardian.validAt);
guardian = pendingGuardian.value;
pendingGuardian.clear();
emit GuardianUpdated(guardian);
}
/// @inheritdoc IOperatorTimelock
function revokeSetGuardian() external onlyOwnerOrGuardian {
PendingLib.assertIsPending(pendingGuardian.validAt);
pendingGuardian.clear();
emit GuardianRevoked(msg.sender);
}
}
src/governance/interfaces/IOperatorTimelock.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @title IOperatorTimelock
/// @notice Interface for a generic operator timelock that wraps module operator functions
/// (risk engine params, liquidation params, etc.) with submit/accept/revoke semantics.
/// @dev Uses calldata-based pending operations so it works with any module type without
/// needing per-function wrappers.
interface IOperatorTimelock {
/* ERRORS */
/// @notice Caller is not the operator timelock owner.
error NotOwner();
/// @notice Caller is neither the owner nor the guardian.
error NotOwnerOrGuardian();
/// @notice Caller is not the guardian.
error NotGuardian();
/// @notice Zero address provided for a required argument.
error ZeroAddress();
/// @notice Constructor received a timelock below its minimum or `longTimelock < timelock`.
error InvalidTimelock();
/// @notice Pending owner does not match the caller in the two-step transfer.
error NotPendingOwner();
/// @notice Operation is already pending for the given module and key.
error AlreadyPending();
/// @notice No pending operation exists to accept or revoke.
error NoPendingOperation();
/// @notice Operation accepted before the timelock has elapsed.
/// @param validAt The timestamp at which the operation becomes executable.
error TimelockNotExpired(uint64 validAt);
/// @notice Pending calldata does not match the accept call.
error CalldataMismatch();
/* EVENTS */
/// @notice Emitted when the owner submits a timelocked module operation.
/// @param module The target module contract.
/// @param operationKey The operation key, computed as `keccak256(callData)`.
/// @param callData The submitted calldata that must be matched at acceptance.
/// @param validAt The timestamp when the operation becomes executable.
event OperationSubmitted(address indexed module, bytes32 indexed operationKey, bytes callData, uint64 validAt);
/// @notice Emitted when a pending module operation is executed.
/// @param module The target module contract.
/// @param operationKey The accepted operation key.
event OperationAccepted(address indexed module, bytes32 indexed operationKey);
/// @notice Emitted when a pending module operation is cancelled.
/// @param module The target module contract.
/// @param operationKey The revoked operation key.
/// @param caller The owner or guardian that cancelled the operation.
event OperationRevoked(address indexed module, bytes32 indexed operationKey, address indexed caller);
/// @notice Emitted when an ownership transfer is submitted.
/// @param newOwner The proposed new owner.
/// @param validAt The timestamp when the transfer can be accepted.
event OwnershipTransferSubmitted(address indexed newOwner, uint64 validAt);
/// @notice Emitted when a pending ownership transfer is cancelled.
/// @param caller The guardian that cancelled the transfer.
event OwnershipTransferRevoked(address indexed caller);
/// @notice Emitted when ownership is transferred.
/// @param newOwner The new owner address.
event OwnerUpdated(address indexed newOwner);
/// @notice Emitted when a guardian change is submitted.
/// @param newGuardian The proposed new guardian.
/// @param validAt The timestamp when the guardian change can be accepted.
event GuardianSubmitted(address indexed newGuardian, uint64 validAt);
/// @notice Emitted when a pending guardian change is cancelled.
/// @param caller The owner or guardian that cancelled the guardian change.
event GuardianRevoked(address indexed caller);
/// @notice Emitted when the guardian is updated.
/// @param newGuardian The new guardian address.
event GuardianUpdated(address indexed newGuardian);
/* VIEW FUNCTIONS */
/// @return The minimum permitted standard timelock, in seconds.
function MIN_TIMELOCK() external view returns (uint256);
/// @return The minimum permitted long timelock, in seconds.
function MIN_LONG_TIMELOCK() external view returns (uint256);
/// @return The default timelock for module operations, in seconds.
function TIMELOCK() external view returns (uint256);
/// @return The longer timelock used for operator transfers, in seconds.
function LONG_TIMELOCK() external view returns (uint256);
/// @return The owner allowed to submit and execute operations.
function owner() external view returns (address);
/// @return The guardian allowed to revoke pending operations.
function guardian() external view returns (address);
/* OPERATION FUNCTIONS */
/// @notice Submits a timelocked operation on a module.
/// @param module The target module contract.
/// @param callData The encoded function call (e.g., abi.encodeCall(IRiskEngine.setRiskEngineParams, (id, config))).
/// @dev Timelock is enforced per selector: `setOperator(address)` uses LONG_TIMELOCK, all others use TIMELOCK.
function submit(address module, bytes calldata callData) external;
/// @notice Executes a pending operation after the timelock has elapsed.
/// @param module The target module contract.
/// @param callData The same encoded function call that was submitted. Must match exactly.
function accept(address module, bytes calldata callData) external;
/// @notice Cancels a pending operation.
/// @param module The target module contract.
/// @param operationKey The key of the pending operation (keccak256 of submitted callData).
function revoke(address module, bytes32 operationKey) external;
/* GOVERNANCE */
/// @notice Submits a two-step ownership transfer.
/// @param newOwner The pending owner that must later accept.
function submitTransferOwnership(address newOwner) external;
/// @notice Accepts a submitted ownership transfer after the long timelock.
function acceptTransferOwnership() external;
/// @notice Cancels a pending ownership transfer. Guardian only.
function revokeTransferOwnership() external;
/// @notice Submits a guardian change.
/// @param newGuardian The pending guardian.
function submitSetGuardian(address newGuardian) external;
/// @notice Accepts a submitted guardian change after the long timelock.
function acceptSetGuardian() external;
/// @notice Cancels a pending guardian change.
function revokeSetGuardian() external;
}
src/libraries/PendingLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @title PendingLib
/// @notice Types and helpers for per-parameter timelocked pending values.
/// @dev A `validAt` of 0 means "no pending value". Non-zero means the value
/// becomes executable at `block.timestamp >= validAt`.
library PendingLib {
/* TYPES */
/// @notice Pending address value with an execution timestamp.
struct PendingAddress {
/// @notice The submitted address value.
address value;
/// @notice The timestamp when the value can be accepted, or zero when no value is pending.
uint64 validAt;
}
/// @notice Pending uint64 value with an execution timestamp.
struct PendingUint64 {
/// @notice The submitted uint64 value.
uint64 value;
/// @notice The timestamp when the value can be accepted, or zero when no value is pending.
uint64 validAt;
}
/// @notice Pending uint128 value with an execution timestamp.
struct PendingUint128 {
/// @notice The submitted uint128 value.
uint128 value;
/// @notice The timestamp when the value can be accepted, or zero when no value is pending.
uint64 validAt;
}
/// @notice Pending market hook configuration with an execution timestamp.
struct PendingMarketHook {
/// @notice The submitted hook address.
address hook;
/// @notice The timestamp when the value can be accepted, or zero when no value is pending.
uint64 validAt;
/// @notice The submitted hook permissions bitmap.
uint256 permissions;
}
/// @notice Pending UUPS implementation upgrade with an execution timestamp.
struct PendingUpgrade {
/// @notice The submitted implementation address.
address newImplementation;
/// @notice The timestamp when the value can be accepted, or zero when no value is pending.
uint64 validAt;
/// @notice The expected calldata hash supplied at acceptance.
bytes32 dataHash;
}
/* ERRORS */
/// @notice Timelocked action accepted before the delay has elapsed.
/// @param validAt The timestamp when the pending value becomes executable.
error TimelockNotExpired(uint64 validAt);
/// @notice No pending timelocked action exists to accept or revoke.
error NoPendingValue();
/// @notice Pending value already exists and has not been revoked.
error AlreadyPending();
/* HELPERS */
/// @dev Returns true if a pending value exists (validAt != 0).
function isPending(uint64 validAt) internal pure returns (bool) {
return validAt != 0;
}
/// @dev Reverts if the pending value is not yet executable.
/// @dev Reverts with `NoPendingValue` if nothing is pending, or `TimelockNotExpired` if too early.
function assertExecutable(uint64 validAt) internal view {
if (validAt == 0) revert NoPendingValue();
if (block.timestamp < validAt) revert TimelockNotExpired(validAt);
}
/// @dev Reverts if a pending value already exists.
function assertNotPending(uint64 validAt) internal pure {
if (validAt != 0) revert AlreadyPending();
}
/// @dev Reverts if no pending value exists.
function assertIsPending(uint64 validAt) internal pure {
if (validAt == 0) revert NoPendingValue();
}
/* UPDATE HELPERS */
function update(PendingAddress storage self, address value, uint256 timelock) internal returns (uint64 validAt) {
validAt = uint64(block.timestamp + timelock);
self.value = value;
self.validAt = validAt;
}
function update(PendingUint64 storage self, uint64 value, uint256 timelock) internal returns (uint64 validAt) {
validAt = uint64(block.timestamp + timelock);
self.value = value;
self.validAt = validAt;
}
function update(PendingUint128 storage self, uint128 value, uint256 timelock) internal returns (uint64 validAt) {
validAt = uint64(block.timestamp + timelock);
self.value = value;
self.validAt = validAt;
}
function update(PendingMarketHook storage self, address hook, uint256 permissions, uint256 timelock)
internal
returns (uint64 validAt)
{
validAt = uint64(block.timestamp + timelock);
self.hook = hook;
self.permissions = permissions;
self.validAt = validAt;
}
function update(PendingUpgrade storage self, address newImplementation, bytes32 dataHash, uint256 timelock)
internal
returns (uint64 validAt)
{
validAt = uint64(block.timestamp + timelock);
self.newImplementation = newImplementation;
self.dataHash = dataHash;
self.validAt = validAt;
}
/* CLEAR HELPERS */
function clear(PendingAddress storage self) internal {
self.value = address(0);
self.validAt = 0;
}
function clear(PendingUint64 storage self) internal {
self.value = 0;
self.validAt = 0;
}
function clear(PendingUint128 storage self) internal {
self.value = 0;
self.validAt = 0;
}
function clear(PendingMarketHook storage self) internal {
self.hook = address(0);
self.permissions = 0;
self.validAt = 0;
}
function clear(PendingUpgrade storage self) internal {
self.newImplementation = address(0);
self.dataHash = bytes32(0);
self.validAt = 0;
}
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"solady/=lib/solady/",
"bundler3/=lib/bundler3/",
"ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/bundler3/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"morpho-blue/=lib/bundler3/lib/morpho-blue/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"prb-math/=lib/prb-math/src/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.