Verified contractPartialMIT
ProtocolDirectory
Address0x0fa6f265b375ed6e13517e0a5be9ac5e8c0eff2b
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,244,092
- Creation transaction
- 0xf03b3797a1…799a1ee05f
src/ProtocolDirectory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @title ProtocolDirectory: every version of the core, side by side
/// @notice A new version of the protocol is a new vault (with its desks and its $YOLO modules) deployed next to the old
/// ones; nothing is replaced or migrated. This list says which vaults belong to the protocol and which one new
/// tasks go to. The site and off-chain readers read it; no contract of the core reads it, so it holds no money and
/// can stop nothing: tasks of every version keep running in their own vault to the end.
/// - Version 1 is written by the constructor (launch 3: the vault of launch 2 and the modules of launch 3).
/// - The owner (`safe`: the project wallet, an EOA) proposes a new version or a
/// new current version; either takes effect 48 h later (the timelock of ParamsRegistry), anyone executes it
/// then. The owner may cancel a pending proposal before that.
/// - A version is never removed or edited; the current one may only point to a listed version.
/// - The owner is fixed at deployment: no transfer, no other role.
/// Versions sit side by side, one $YOLO forever.
contract ProtocolDirectory {
uint256 public constant TIMELOCK = 48 hours;
uint256 public constant MAX_LABEL_BYTES = 32;
/// @notice One version of the core. Zero module = the version has no such module.
struct Version {
address vault; // the address users call; its desks are vault.caseDesk() / vault.disputeDesk()
address sweetener; // YoloSweetener of this vault
address trophy; // DareTrophy of this vault
uint64 fromBlock; // the vault's deployment block: indexers read its events from here
uint64 addedAt; // when it was listed
string label; // "v1", "v2", ...
}
address public immutable safe;
Version[] internal _versions; // version n is _versions[n - 1]
/// @notice The version new tasks are created in (1-based).
uint256 public current;
Version internal _pendingVersion;
uint64 public pendingVersionEta; // 0 = nothing pending
uint256 public pendingCurrent;
uint64 public pendingCurrentEta; // 0 = nothing pending
event VersionProposed(address indexed vault, string label, uint64 eta);
event VersionCancelled(address indexed vault);
event VersionAdded(uint256 indexed version, address indexed vault, address sweetener, address trophy, string label);
event CurrentProposed(uint256 indexed version, uint64 eta);
event CurrentCancelled(uint256 indexed version);
event CurrentChanged(uint256 indexed version);
error NotSafe();
error NothingPending();
error TimelockNotPassed();
error NoCode(address account);
error BadLabel();
error UnknownVersion(uint256 version);
error AlreadyListed(address vault);
modifier onlySafe() {
if (msg.sender != safe) revert NotSafe();
_;
}
/// @notice Lists version 1 ("v1") and makes it current.
/// @param fromBlock the block of the vault's deployment (launch 2)
constructor(address safe_, address vault, address sweetener, address trophy, uint64 fromBlock) {
if (safe_ == address(0)) revert NotSafe();
safe = safe_;
_add(Version(vault, sweetener, trophy, fromBlock, 0, "v1"));
current = 1;
emit CurrentChanged(1);
}
// ------------------------------------------------------------------ new version
/// @notice Proposes a new version (replaces a pending one). `addedAt` is set at execution.
function proposeVersion(Version calldata v) external onlySafe {
_check(v);
_pendingVersion = v;
pendingVersionEta = uint64(block.timestamp + TIMELOCK);
emit VersionProposed(v.vault, v.label, pendingVersionEta);
}
/// @notice Drops the pending proposal: `pendingVersion()` is empty again, not a stale copy of it.
function cancelVersion() external onlySafe {
if (pendingVersionEta == 0) revert NothingPending();
pendingVersionEta = 0;
address vault = _pendingVersion.vault;
delete _pendingVersion;
emit VersionCancelled(vault);
}
/// @notice Anyone lists the proposed version after the timelock. It does not become current by itself. The
/// proposal is consumed: `pendingVersion()` is empty afterwards.
// slither-disable-next-line incorrect-equality
function addVersion() external returns (uint256 n) {
uint64 eta = pendingVersionEta;
if (eta == 0) revert NothingPending();
if (block.timestamp < eta) revert TimelockNotPassed();
pendingVersionEta = 0;
Version memory v = _pendingVersion;
delete _pendingVersion;
return _add(v);
}
// ------------------------------------------------------------------ current version
/// @notice Proposes the version new tasks go to (replaces a pending one). It may be a version still pending in
/// `proposeVersion`: it has to be listed by the time this executes.
function proposeCurrent(uint256 n) external onlySafe {
if (n == 0) revert UnknownVersion(n);
pendingCurrent = n;
pendingCurrentEta = uint64(block.timestamp + TIMELOCK);
emit CurrentProposed(n, pendingCurrentEta);
}
function cancelCurrent() external onlySafe {
if (pendingCurrentEta == 0) revert NothingPending();
pendingCurrentEta = 0;
emit CurrentCancelled(pendingCurrent);
}
/// @notice Anyone switches the current version after the timelock.
// slither-disable-next-line incorrect-equality
function setCurrent() external {
uint64 eta = pendingCurrentEta;
if (eta == 0) revert NothingPending();
if (block.timestamp < eta) revert TimelockNotPassed();
uint256 v = pendingCurrent;
if (v > _versions.length) revert UnknownVersion(v);
pendingCurrentEta = 0;
current = v;
emit CurrentChanged(v);
}
// ------------------------------------------------------------------ views
function versionCount() external view returns (uint256) {
return _versions.length;
}
function version(uint256 n) external view returns (Version memory) {
if (n == 0 || n > _versions.length) revert UnknownVersion(n);
return _versions[n - 1];
}
/// @notice All versions, oldest first (version n at index n - 1).
function versions() external view returns (Version[] memory) {
return _versions;
}
/// @notice The proposal waiting for `addVersion` (empty, vault = address(0), when `pendingVersionEta` is 0:
/// nothing proposed, cancelled, or already listed).
function pendingVersion() external view returns (Version memory) {
return _pendingVersion;
}
// ------------------------------------------------------------------ internal
function _add(Version memory v) private returns (uint256 n) {
_check(v);
v.addedAt = uint64(block.timestamp);
_versions.push(v);
n = _versions.length;
emit VersionAdded(n, v.vault, v.sweetener, v.trophy, v.label);
}
/// @dev A listed vault is a contract and listed once; modules, when given, are contracts; the label is 1..32 bytes.
/// Checked at proposal (the owner learns at once) and at listing.
function _check(Version memory v) private view {
if (v.vault.code.length == 0 && _versions.length != 0) revert NoCode(v.vault); // v1: empty-chain floor
if (v.sweetener != address(0) && v.sweetener.code.length == 0) revert NoCode(v.sweetener);
if (v.trophy != address(0) && v.trophy.code.length == 0) revert NoCode(v.trophy);
uint256 n = bytes(v.label).length;
if (n == 0 || n > MAX_LABEL_BYTES) revert BadLabel();
for (uint256 i; i < _versions.length; ++i) {
if (_versions[i].vault == v.vault) revert AlreadyListed(v.vault);
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"/tmp/imd-attest-EGhqp2/repo/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"/tmp/imd-attest-EGhqp2/repo/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"/tmp/imd-attest-EGhqp2/repo/lib/v4-core/:openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"/tmp/imd-attest-EGhqp2/repo/lib/v4-core/:solmate/=lib/v4-core/lib/solmate/",
"/tmp/imd-attest-EGhqp2/repo/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"/tmp/imd-attest-EGhqp2/repo/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"/tmp/imd-attest-EGhqp2/repo/lib/v4-core/lib/solmate/:ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/",
":@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
":@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
":hardhat/=lib/v4-core/node_modules/hardhat/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":solmate/=lib/v4-core/lib/solmate/",
":v4-core/=lib/v4-core/",
"lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"lib/v4-core/:openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"lib/v4-core/:solmate/=lib/v4-core/lib/solmate/",
"lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"lib/v4-core/lib/solmate/:ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.