Verified contractExactMIT
CollectionRegistry
Address0x0469bb805b193ba1deb554a0788d935c083c7702
- Balance
0 ETH
- Transactions
22
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,423,406
- Creation transaction
- 0xc803728a3a…1bc1840d17
6 files
- ethereum/CollectionRegistry.solmain56.03 KB
- @openzeppelin/contracts/access/Ownable.sol2.62 KB
- @openzeppelin/contracts/access/Ownable2Step.sol1.94 KB
- @openzeppelin/contracts/utils/Context.sol844 B
- @openzeppelin/contracts/utils/introspection/IERC165.sol853 B
- ethereum/interfaces/ICollectionRegistry.sol6.94 KB
ethereum/CollectionRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {
ICollectionRegistry,
ICollectionRegistrar,
COLLECTION_STANDARD_ERC721,
COLLECTION_STANDARD_ERC1155,
COLLECTION_ADAPTER_SEAPORT,
COLLECTION_ROUTE_FACTORY,
COLLECTION_ROUTE_APPROVER,
COLLECTION_ROUTE_OWNER
} from "./interfaces/ICollectionRegistry.sol";
/// @title CollectionRegistry
/// @notice The on-chain admission boundary for UnVault settlement rails. A rail asks `admitted(collection, standard)`
/// before any funds move and refuses a collection the registry does not admit. One registry per chain.
///
/// Admission routes:
/// 1. Trusted factories. The owner lists a factory behind the admission delay. A collection the factory deploys
/// registers itself in its deploy transaction (`registerFromFactory`) and is admitted at once, with the factory
/// as its source and its live codehash pinned. The factory is trusted for what it deploys, so this route does not
/// scan the code (EIP-1167 clones of an immutable template contain a DELEGATECALL to a fixed target).
/// 2. Approvers. The owner grants the role behind the delay. `propose` puts a collection in Pending with
/// `effectiveAt = now + approverAdmissionDelay`; the owner may `veto` during it; anyone may `apply` after it. The
/// approver delay is its own owner setting (default `LAUNCH_ADMISSION_DELAY`; 0 allowed, so an approval bot admits
/// in its own transaction), and approver proposals are capped per rolling hour (`approverHourlyCap`, 0 = route
/// closed, the default).
/// 3. The owner. The same `propose`, behind `admissionDelay`, unless the registry was deployed with
/// `ownerAdmissionImmediate` (an owner decision), in which case the owner's proposal is admitted at once.
/// The owner resumes a paused collection at once while its code is unchanged (see `resume`).
///
/// Every record keeps the route (factory, approver, owner) and the time of the admission that pinned its current code
/// (`record().route`, `record().admittedAt`), so a consumer can later require an owner admission or a minimum age.
///
/// Code policy (routes 2 and 3):
/// - Immutable collections (`propose`, `resume`): the collection must have code; an EIP-7702 delegation is refused;
/// the runtime code may not contain a reachable DELEGATECALL, CALLCODE or SELFDESTRUCT (PUSH data and dead code
/// after a terminating instruction are skipped), so no proxy of any kind (EIP-1967, beacon, custom slot, clone) is
/// admitted on `propose`, except that a byte-exact EIP-1167 clone is judged by its target (see
/// `_scanCodeOrCloneTarget`); the collection must answer exactly one of the ERC-721 and ERC-1155 interfaces. The
/// EXTCODEHASH is pinned at admission. Externally linked Solidity libraries are reached by DELEGATECALL, so a
/// collection built with linked libraries is refused on `propose`. Bugz (deployed as Bugz and DeBugz) contains none
/// of the three opcodes (bugz `feature/testing` 8f1edf1, forge build).
/// - Upgradeable collections (`proposeUpgradeable`, `resumeUpgradeable`): because a contract cannot read another
/// contract's storage slots, the approver or owner attests the proxy's current `implementation` and
/// `upgradeAuthority`. The registry enforces on-chain that `collection` has non-7702 code and answers the declared
/// standard only, `implementation` has non-7702 code and passes the reachable-code scan (`_scanCode`), and
/// `upgradeAuthority` has non-7702 code (refusing EOAs). The proxy's own EXTCODEHASH is pinned, and both
/// `implementation` and `upgradeAuthority` are recorded and bound into `policyId`. Plain `resume` is refused for
/// upgradeable records (`UpgradeableRequiresAttestation`), so a paused upgradeable collection never resumes without
/// a fresh attestation.
///
/// Check time (`admitted`): Admitted status, matching standard, live codehash equal to the pinned one, and the
/// collection does not answer the other standard's interface. Anything else answers not-admitted without a
/// governance action.
///
/// `policyEpoch` increases on every record change and never resets. Pause and removal block new exposure only: no
/// function here gates an exit, and consumers must never consult the registry on cancel, claim, reclaim, withdraw or
/// refund paths.
contract CollectionRegistry is ICollectionRegistry, ICollectionRegistrar, IERC165, Ownable2Step {
// ── Delay (same shape as MarketplaceFeePolicy) ─────────────────────────────────────────────────
//
// Every action that widens admission (a factory trust, an approver grant, an owner proposal, a resume with changed
// code, a shorter approver delay, a higher approver cap) waits `admissionDelay`; an approver's proposal waits
// `approverAdmissionDelay` instead (see below). The delay is a ONE-WAY RATCHET: `0` (immediate, the deploy default, so the launch set can be
// admitted in the deploy run) can be raised by the owner up to `MAX_ADMISSION_DELAY`, never lowered. Production
// deploys set `LAUNCH_ADMISSION_DELAY` before handing ownership to the Safe. Narrowing actions (veto, pause,
// removal, untrust, revoke) are immediate.
/// @notice Hard ceiling on `admissionDelay` so a mistyped value cannot freeze admissions.
uint64 public constant MAX_ADMISSION_DELAY = 30 days;
/// @notice The delay production deploys set before the ownership hand-off.
uint64 public constant LAUNCH_ADMISSION_DELAY = 2 days;
/// @notice Gas forwarded to each ERC-165 probe of a collection.
uint256 public constant PROBE_GAS = 30_000;
bytes4 private constant ERC721_INTERFACE_ID = 0x80ac58cd;
bytes4 private constant ERC1155_INTERFACE_ID = 0xd9b67a26;
/// @notice Seconds an admission-widening action waits. `0` = immediate.
uint64 public admissionDelay;
// ── Approver route: own delay and rolling-hour cap ─────────────────────────────────────────────
//
// Both are owner settings under the registry's rule: a narrowing change (a longer approver delay, a lower cap)
// applies at once and clears any scheduled widening; a widening change (a shorter delay, a higher cap) is
// scheduled behind `admissionDelay` and applied by anyone after it (at once while `admissionDelay` is 0, i.e. in
// the deploy run). The cap counts approver proposals (with a zero approver delay a proposal is the admission);
// `applyAdmission` stays permissionless and uncounted.
/// @notice Upper bound on `approverHourlyCap` (the timestamp ring's length).
uint16 public constant MAX_APPROVER_HOURLY_CAP = 256;
/// @notice The cap's window: a proposal counts for exactly this many seconds.
uint64 public constant APPROVER_CAP_WINDOW = 1 hours;
/// @notice Seconds an approver's proposal waits before it may be applied. `0` = admitted in the proposing call.
uint64 public approverAdmissionDelay;
/// @notice Approver proposals allowed in any rolling `APPROVER_CAP_WINDOW`. `0` = the approver route is closed.
uint16 public approverHourlyCap;
/// @notice Total approver proposals ever made (the ring's write index).
uint64 public approverProposalCount;
/// @notice Scheduled widening of the approver delay and when it may be applied (0 = nothing scheduled).
uint64 public pendingApproverDelay;
uint64 public pendingApproverDelayAt;
/// @notice Scheduled widening of the cap and when it may be applied (0 = nothing scheduled).
uint16 public pendingApproverCap;
uint64 public pendingApproverCapAt;
/// @dev Timestamps of the last `MAX_APPROVER_HOURLY_CAP` approver proposals; entry `i % 256` is proposal `i`.
uint64[256] private _approverRing;
/// @notice When true, the owner's own proposals and resumes are admitted at once (routes 2 and 3 stay delayed for
/// approvers). Fixed at deployment.
bool public immutable ownerAdmissionImmediate;
struct Rec {
// slot 0
uint8 standard;
uint8 adapter;
Status status;
bool everAdmitted;
uint64 policyEpoch;
uint64 effectiveAt;
uint8 route;
uint64 admittedAt;
// slot 1
address factory;
// slot 2
address implementation;
// slot 3
address upgradeAuthority;
// slot 4, 5
bytes32 codehash;
bytes32 policyId;
}
mapping(address => Rec) private _rec;
/// @notice Trusted factories.
mapping(address => bool) public trustedFactory;
/// @notice Scheduled factory trust: when it may be applied (0 = nothing scheduled).
mapping(address => uint64) public pendingFactoryAt;
/// @notice Approvers.
mapping(address => bool) public approver;
/// @notice Scheduled approver grant: when it may be applied (0 = nothing scheduled).
mapping(address => uint64) public pendingApproverAt;
/// @notice Who paused a collection (cleared on resume). Lets a later policy treat an approver's pause differently
/// from the owner's without a redeploy.
mapping(address => address) public pausedBy;
/// @notice True when the owner of the time paused a collection (cleared on resume and removal). Recorded at pause
/// time, so an owner pause stays the owner's after ownership moves (deployer to Safe, Safe to Safe).
mapping(address => bool) public pausedByOwner;
// ── Unverified lane ────────────────────────────────────────────────────────────────────────────
/// @notice True while unrecorded collections may trade with the unverified marker. Open at deploy; any approver or
/// the owner closes it at once, only the owner reopens it.
bool public unverifiedLaneOpen;
/// @notice Who closed `unverifiedLaneOpen` (zero while open).
address public unverifiedLaneClosedBy;
/// @notice True when criteria-based (collection/trait) offers are allowed on unrecorded collections. Off at deploy;
/// owner only.
bool public unverifiedCollectionOffersOpen;
/// @notice True when a never-recorded collection (`policyEpoch == 0`) has been blocked by an approver or the owner.
mapping(address => bool) public unrecordedBlocked;
/// @notice Who blocked a never-recorded collection (cleared on unblock).
mapping(address => address) public blockedBy;
event AdmissionDelayUpdated(uint64 oldDelay, uint64 newDelay);
event FactoryTrustScheduled(address indexed factory, uint64 effectiveAt);
event FactoryTrustCancelled(address indexed factory);
event ApproverScheduled(address indexed account, uint64 effectiveAt);
event ApproverCancelled(address indexed account);
event ApproverGranted(address indexed account);
event ApproverRevoked(address indexed account);
event ApproverAdmissionDelayUpdated(uint64 oldDelay, uint64 newDelay);
event ApproverAdmissionDelayScheduled(uint64 newDelay, uint64 effectiveAt);
event ApproverAdmissionDelayCancelled(uint64 newDelay);
event ApproverHourlyCapUpdated(uint16 oldCap, uint16 newCap);
event ApproverHourlyCapScheduled(uint16 newCap, uint64 effectiveAt);
event ApproverHourlyCapCancelled(uint16 newCap);
/// @notice Every approver proposal, admitted at once or Pending. `count` is the running total.
event ApproverProposal(address indexed collection, address indexed approver, uint64 count);
error ZeroAddress();
error InvalidDelay();
error NotAuthorized();
error NotTrustedFactory();
error InvalidStandard();
error UnsupportedAdapter();
error InvalidStatus(Status status);
error DelayNotElapsed(uint64 effectiveAt);
error NothingScheduled();
error AlreadySet();
error NoCode();
error DelegatedAccount();
error ForbiddenOpcode(uint256 offset, uint8 opcode);
error StandardNotAnswered();
error AnswersBothStandards();
error CodehashChanged(bytes32 pinned, bytes32 live);
error InvalidCap();
/// @notice An approver proposed a collection whose record holds an owner decision (vetoed or removed); only the
/// owner may propose it again.
error OwnerDecisionStands(Status status);
/// @notice The approver route is closed (`approverHourlyCap` is 0).
error ApproverRouteClosed();
/// @notice `cap` approver proposals already in the last hour; the next fits at `retryAt`.
error ApproverHourlyCapReached(uint16 cap, uint64 retryAt);
/// @notice Plain `resume` is refused for an upgradeable record because a proxy's own codehash does not change on
/// upgrade; use `resumeUpgradeable` with a fresh attestation.
error UpgradeableRequiresAttestation();
/// @notice Renouncing is disabled, as on the fee policy: a renounce would end every owner power for good.
error RenounceDisabled();
function renounceOwnership() public pure override {
revert RenounceDisabled();
}
constructor(address initialOwner, bool ownerAdmissionImmediate_) {
if (initialOwner == address(0)) revert ZeroAddress();
_transferOwnership(initialOwner);
ownerAdmissionImmediate = ownerAdmissionImmediate_;
approverAdmissionDelay = LAUNCH_ADMISSION_DELAY;
unverifiedLaneOpen = true;
}
// ── ERC-165 ─────────────────────────────────────────────────────────────────────────────────────
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
return interfaceId == type(ICollectionRegistry).interfaceId
|| interfaceId == type(ICollectionRegistrar).interfaceId || interfaceId == type(IERC165).interfaceId;
}
// ── Delay ──────────────────────────────────────────────────────────────────────────────────────
/// @notice Raise the admission delay (one-way ratchet, max `MAX_ADMISSION_DELAY`).
function setAdmissionDelay(uint64 newDelay) external onlyOwner {
if (newDelay <= admissionDelay || newDelay > MAX_ADMISSION_DELAY) revert InvalidDelay();
uint64 old = admissionDelay;
admissionDelay = newDelay;
emit AdmissionDelayUpdated(old, newDelay);
}
// ── Approver delay and cap ─────────────────────────────────────────────────────────────────────
/// @notice Set the approver route's delay (0 allowed, max `MAX_ADMISSION_DELAY`). A longer delay applies at once
/// and clears a scheduled shorter one; a shorter delay is scheduled behind `admissionDelay` (at once while
/// `admissionDelay` is 0).
function setApproverAdmissionDelay(uint64 newDelay) external onlyOwner {
if (newDelay > MAX_ADMISSION_DELAY) revert InvalidDelay();
uint64 cur = approverAdmissionDelay;
if (newDelay == cur) revert AlreadySet();
if (newDelay > cur || admissionDelay == 0) {
_applyApproverDelay(newDelay);
return;
}
uint64 at = uint64(block.timestamp) + admissionDelay;
pendingApproverDelay = newDelay;
pendingApproverDelayAt = at;
emit ApproverAdmissionDelayScheduled(newDelay, at);
}
/// @notice Apply a scheduled shorter approver delay once its wait has elapsed. Permissionless.
function applyApproverAdmissionDelay() external {
uint64 at = pendingApproverDelayAt;
if (at == 0) revert NothingScheduled();
if (block.timestamp < at) revert DelayNotElapsed(at);
_applyApproverDelay(pendingApproverDelay);
}
function cancelApproverAdmissionDelay() external onlyOwner {
if (pendingApproverDelayAt == 0) revert NothingScheduled();
uint64 d = pendingApproverDelay;
delete pendingApproverDelay;
delete pendingApproverDelayAt;
emit ApproverAdmissionDelayCancelled(d);
}
/// @notice Set the approver route's rolling-hour cap (0 closes the route, max `MAX_APPROVER_HOURLY_CAP`). A lower
/// cap applies at once and clears a scheduled higher one; a higher cap is scheduled behind
/// `admissionDelay` (at once while `admissionDelay` is 0).
function setApproverHourlyCap(uint16 newCap) external onlyOwner {
if (newCap > MAX_APPROVER_HOURLY_CAP) revert InvalidCap();
uint16 cur = approverHourlyCap;
if (newCap == cur) revert AlreadySet();
if (newCap < cur || admissionDelay == 0) {
_applyApproverCap(newCap);
return;
}
uint64 at = uint64(block.timestamp) + admissionDelay;
pendingApproverCap = newCap;
pendingApproverCapAt = at;
emit ApproverHourlyCapScheduled(newCap, at);
}
/// @notice Apply a scheduled higher cap once its wait has elapsed. Permissionless.
function applyApproverHourlyCap() external {
uint64 at = pendingApproverCapAt;
if (at == 0) revert NothingScheduled();
if (block.timestamp < at) revert DelayNotElapsed(at);
_applyApproverCap(pendingApproverCap);
}
function cancelApproverHourlyCap() external onlyOwner {
if (pendingApproverCapAt == 0) revert NothingScheduled();
uint16 c = pendingApproverCap;
delete pendingApproverCap;
delete pendingApproverCapAt;
emit ApproverHourlyCapCancelled(c);
}
function _applyApproverDelay(uint64 newDelay) private {
delete pendingApproverDelay;
delete pendingApproverDelayAt;
uint64 old = approverAdmissionDelay;
approverAdmissionDelay = newDelay;
emit ApproverAdmissionDelayUpdated(old, newDelay);
}
function _applyApproverCap(uint16 newCap) private {
delete pendingApproverCap;
delete pendingApproverCapAt;
uint16 old = approverHourlyCap;
approverHourlyCap = newCap;
emit ApproverHourlyCapUpdated(old, newCap);
}
// ── Trusted factories ──────────────────────────────────────────────────────────────────────────
/// @notice Schedule trust for `factory`; applied at once while the delay is 0.
function scheduleFactoryTrust(address factory) external onlyOwner {
if (factory == address(0)) revert ZeroAddress();
if (factory.code.length == 0) revert NoCode();
if (trustedFactory[factory]) revert AlreadySet();
uint64 at = uint64(block.timestamp) + admissionDelay;
if (admissionDelay == 0) {
_trustFactory(factory);
} else {
pendingFactoryAt[factory] = at;
emit FactoryTrustScheduled(factory, at);
}
}
/// @notice Apply a scheduled factory trust once its delay has elapsed. Permissionless.
function applyFactoryTrust(address factory) external {
uint64 at = pendingFactoryAt[factory];
if (at == 0) revert NothingScheduled();
if (block.timestamp < at) revert DelayNotElapsed(at);
_trustFactory(factory);
}
function cancelFactoryTrust(address factory) external onlyOwner {
if (pendingFactoryAt[factory] == 0) revert NothingScheduled();
delete pendingFactoryAt[factory];
emit FactoryTrustCancelled(factory);
}
/// @notice Stop trusting `factory` at once. Collections it already registered keep their records; the owner pauses
/// or removes them one by one if needed.
function untrustFactory(address factory) external onlyOwner {
if (!trustedFactory[factory] && pendingFactoryAt[factory] == 0) revert NothingScheduled();
delete pendingFactoryAt[factory];
if (trustedFactory[factory]) {
trustedFactory[factory] = false;
emit FactoryUntrusted(factory);
} else {
emit FactoryTrustCancelled(factory);
}
}
function _trustFactory(address factory) private {
delete pendingFactoryAt[factory];
trustedFactory[factory] = true;
emit FactoryTrusted(factory);
}
// ── Approvers ──────────────────────────────────────────────────────────────────────────────────
/// @notice Schedule the approver role for `account`; granted at once while the delay is 0.
function scheduleApprover(address account) external onlyOwner {
if (account == address(0)) revert ZeroAddress();
if (approver[account]) revert AlreadySet();
uint64 at = uint64(block.timestamp) + admissionDelay;
if (admissionDelay == 0) {
_grantApprover(account);
} else {
pendingApproverAt[account] = at;
emit ApproverScheduled(account, at);
}
}
/// @notice Apply a scheduled approver grant once its delay has elapsed. Permissionless.
function applyApprover(address account) external {
uint64 at = pendingApproverAt[account];
if (at == 0) revert NothingScheduled();
if (block.timestamp < at) revert DelayNotElapsed(at);
_grantApprover(account);
}
function cancelApprover(address account) external onlyOwner {
if (pendingApproverAt[account] == 0) revert NothingScheduled();
delete pendingApproverAt[account];
emit ApproverCancelled(account);
}
/// @notice Revoke the approver role at once (also cancels a scheduled grant).
function revokeApprover(address account) external onlyOwner {
if (!approver[account] && pendingApproverAt[account] == 0) revert NothingScheduled();
delete pendingApproverAt[account];
if (approver[account]) {
approver[account] = false;
emit ApproverRevoked(account);
} else {
emit ApproverCancelled(account);
}
}
function _grantApprover(address account) private {
delete pendingApproverAt[account];
approver[account] = true;
emit ApproverGranted(account);
}
// ── Route 1: trusted factory ───────────────────────────────────────────────────────────────────
/// @inheritdoc ICollectionRegistrar
/// @dev The registry cannot check that the factory created `collection`; that guarantee is the factory's (it calls
/// this only for an address it has just created with CREATE or CREATE2), and factory reviews check it.
function registerFromFactory(address collection, uint8 standard)
external
returns (bytes32 policyId, uint64 epoch)
{
if (!trustedFactory[msg.sender]) revert NotTrustedFactory();
Rec storage r = _rec[collection];
if (r.status != Status.None || unrecordedBlocked[collection]) revert InvalidStatus(r.status);
_checkStandard(standard);
bytes32 live = _liveCodehash(collection);
_checkInterfaces(collection, standard);
r.standard = standard;
r.adapter = COLLECTION_ADAPTER_SEAPORT;
r.factory = msg.sender;
r.implementation = address(0);
r.upgradeAuthority = address(0);
r.codehash = live;
policyId = _policyId(collection, standard, COLLECTION_ADAPTER_SEAPORT, msg.sender, address(0), address(0), live);
r.policyId = policyId;
_pin(r, COLLECTION_ROUTE_FACTORY);
epoch = _admit(collection, r);
}
// ── Routes 2 and 3: approver and owner ─────────────────────────────────────────────────────────
/// @notice Propose `collection` for admission. It lands in Pending until `effectiveAt = now + delay`; the owner may
/// veto it meanwhile and anyone may apply it after. The delay is `admissionDelay` for the owner (admitted at
/// once while it is 0 or with `ownerAdmissionImmediate`) and `approverAdmissionDelay` for an approver
/// (admitted at once while it is 0). An approver's proposal also counts against `approverHourlyCap`.
/// Who may propose from which status: None with epoch 0 (never recorded): owner or approver. None with epoch
/// > 0 (vetoed before any admission) and Removed (removed, or vetoed after an earlier admission): owner only,
/// `OwnerDecisionStands` for an approver. Pending, Admitted, Paused: nobody (`InvalidStatus`).
/// @param adapter Settlement adapter id; only `COLLECTION_ADAPTER_SEAPORT` exists at launch.
function propose(address collection, uint8 standard, uint8 adapter) external returns (uint64 epoch) {
bool byOwner = msg.sender == owner();
if (!byOwner && !approver[msg.sender]) revert NotAuthorized();
Rec storage r = _rec[collection];
if (r.status != Status.None && r.status != Status.Removed) revert InvalidStatus(r.status);
// An approver proposes only a collection the registry has never recorded (epoch 0) and that is not blocked. A
// record with history in None or Removed, or a blocked unrecorded collection, holds a protective decision that
// an approver may not override.
if (!byOwner && (r.policyEpoch != 0 || unrecordedBlocked[collection])) revert OwnerDecisionStands(r.status);
if (unrecordedBlocked[collection]) revert InvalidStatus(r.status);
_checkStandard(standard);
if (adapter != COLLECTION_ADAPTER_SEAPORT) revert UnsupportedAdapter();
bytes32 live = _liveCodehash(collection);
_scanCodeOrCloneTarget(collection);
_checkInterfaces(collection, standard);
r.standard = standard;
r.adapter = adapter;
r.factory = address(0);
r.implementation = address(0);
r.upgradeAuthority = address(0);
r.codehash = live;
r.policyId = _policyId(collection, standard, adapter, address(0), address(0), address(0), live);
uint64 delay;
if (byOwner) {
_pin(r, COLLECTION_ROUTE_OWNER);
if (_ownerImmediate()) return _admit(collection, r);
delay = admissionDelay;
} else {
_pin(r, COLLECTION_ROUTE_APPROVER);
_countApproverProposal(collection);
delay = approverAdmissionDelay;
if (delay == 0) return _admit(collection, r);
}
uint64 at = uint64(block.timestamp) + delay;
r.status = Status.Pending;
r.effectiveAt = at;
epoch = _advance(r);
emit CollectionProposed(collection, msg.sender, standard, adapter, live, at, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Pending);
}
/// @notice Propose or re-attest an upgradeable `collection` with an attested `implementation` and contract
/// `upgradeAuthority` (approver or owner route). A contract cannot read another contract's storage, so the
/// caller attests the current implementation and upgrade authority; this function enforces on-chain that
/// `collection` has non-7702 code and answers `standard` only, `implementation` has non-7702 code and
/// passes the reachable-code scan, and `upgradeAuthority` has non-7702 code (refusing EOAs). Both
/// `implementation` and `upgradeAuthority` are stored on the record and bound into `policyId`, so a
/// re-attestation advances `policyEpoch` and rotates `policyId`.
function proposeUpgradeable(
address collection,
uint8 standard,
uint8 adapter,
address implementation,
address upgradeAuthority
) external returns (uint64 epoch) {
bool byOwner = msg.sender == owner();
if (!byOwner && !approver[msg.sender]) revert NotAuthorized();
Rec storage r = _rec[collection];
Status s = r.status;
if (s == Status.None || s == Status.Removed) {
if (!byOwner && (r.policyEpoch != 0 || unrecordedBlocked[collection])) revert OwnerDecisionStands(s);
if (unrecordedBlocked[collection]) revert InvalidStatus(s);
} else if (s == Status.Admitted || s == Status.Pending) {
if (r.upgradeAuthority == address(0)) revert InvalidStatus(s);
if (!byOwner && r.route == COLLECTION_ROUTE_OWNER) revert OwnerDecisionStands(s);
} else {
revert InvalidStatus(s);
}
bytes32 live = _inspectUpgradeable(collection, standard, adapter, implementation, upgradeAuthority);
r.standard = standard;
r.adapter = adapter;
r.factory = address(0);
r.implementation = implementation;
r.upgradeAuthority = upgradeAuthority;
r.codehash = live;
r.policyId = _policyId(collection, standard, adapter, address(0), implementation, upgradeAuthority, live);
uint64 delay;
if (byOwner) {
_pin(r, COLLECTION_ROUTE_OWNER);
if (_ownerImmediate()) return _admit(collection, r);
delay = admissionDelay;
} else {
_pin(r, COLLECTION_ROUTE_APPROVER);
_countApproverProposal(collection);
delay = approverAdmissionDelay;
if (delay == 0) return _admit(collection, r);
}
uint64 at = uint64(block.timestamp) + delay;
r.status = Status.Pending;
r.effectiveAt = at;
epoch = _advance(r);
emit UpgradeableCollectionAttested(collection, implementation, upgradeAuthority, epoch);
emit CollectionProposed(collection, msg.sender, standard, adapter, live, at, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Pending);
}
/// @notice Admit a Pending collection once its delay has elapsed. Permissionless. Reverts if its code changed.
function applyAdmission(address collection) external returns (uint64) {
Rec storage r = _rec[collection];
if (r.status != Status.Pending) revert InvalidStatus(r.status);
if (block.timestamp < r.effectiveAt) revert DelayNotElapsed(r.effectiveAt);
bytes32 live = collection.codehash;
if (live != r.codehash) revert CodehashChanged(r.codehash, live);
if (r.upgradeAuthority != address(0)) {
_liveCodehash(r.implementation);
_liveCodehash(r.upgradeAuthority);
}
return _admit(collection, r);
}
/// @notice Veto a Pending collection. It returns to None, or to Removed if it was ever admitted.
function veto(address collection) external onlyOwner returns (uint64 epoch) {
Rec storage r = _rec[collection];
if (r.status != Status.Pending) revert InvalidStatus(r.status);
Status next = r.everAdmitted ? Status.Removed : Status.None;
r.status = next;
epoch = _advance(r);
emit CollectionVetoed(collection, epoch);
emit PolicyEpochAdvanced(collection, epoch, next);
}
// ── Pause, resume, removal ─────────────────────────────────────────────────────────────────────
/// @notice Pause an Admitted collection: no new authorization or settlement. Owner or an approver. An owner pause
/// is recorded (`pausedByOwner`) and only the owner undoes it.
function pause(address collection) external returns (uint64 epoch) {
bool byOwner = msg.sender == owner();
if (!byOwner && !approver[msg.sender]) revert NotAuthorized();
Rec storage r = _rec[collection];
if (r.status != Status.Admitted) revert InvalidStatus(r.status);
r.status = Status.Paused;
pausedBy[collection] = msg.sender;
if (byOwner) pausedByOwner[collection] = true;
epoch = _advance(r);
emit CollectionPaused(collection, msg.sender, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Paused);
}
/// @notice Resume a Paused collection (owner). If its live codehash still equals the pinned one, it is admitted at
/// once: that restores a state that already passed review, so one approver's pause costs one owner
/// transaction, not a delay. If the code changed, the new code is judged like a new proposal (full launch
/// policy, the same standard, codehash and policy id re-pinned, factory source dropped) and waits in Pending
/// behind the delay (at once while the delay is 0 or with `ownerAdmissionImmediate`). Refused for
/// upgradeable records (`UpgradeableRequiresAttestation`); use `resumeUpgradeable` instead.
function resume(address collection) external onlyOwner returns (uint64 epoch) {
Rec storage r = _rec[collection];
if (r.status != Status.Paused) revert InvalidStatus(r.status);
if (r.upgradeAuthority != address(0) || r.implementation != address(0)) {
revert UpgradeableRequiresAttestation();
}
delete pausedBy[collection];
delete pausedByOwner[collection];
bytes32 live = collection.codehash;
if (live == r.codehash) {
emit CollectionResumed(collection, uint64(block.timestamp), r.policyEpoch + 1);
return _admit(collection, r);
}
live = _liveCodehash(collection);
_scanCodeOrCloneTarget(collection);
_checkInterfaces(collection, r.standard);
r.factory = address(0);
r.implementation = address(0);
r.upgradeAuthority = address(0);
r.codehash = live;
r.policyId = _policyId(collection, r.standard, r.adapter, address(0), address(0), address(0), live);
_pin(r, COLLECTION_ROUTE_OWNER);
if (_ownerImmediate()) {
emit CollectionResumed(collection, uint64(block.timestamp), r.policyEpoch + 1);
return _admit(collection, r);
}
uint64 at = uint64(block.timestamp) + admissionDelay;
r.status = Status.Pending;
r.effectiveAt = at;
epoch = _advance(r);
emit CollectionResumed(collection, at, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Pending);
}
/// @notice Resume a Paused upgradeable collection with a fresh attestation (`implementation` and contract
/// `upgradeAuthority`). Required for every paused upgradeable record because a proxy's own codehash does
/// not change on upgrade. Same guards as `proposeUpgradeable`: the paused record must already be
/// upgradeable (`InvalidStatus` otherwise, for the owner too; an immutable record resumes through `resume`).
/// The owner may resume any paused upgradeable record. An approver may resume only an approver-routed
/// record that the owner did not pause; an owner-routed record or an owner pause refuses it
/// (`OwnerDecisionStands`).
function resumeUpgradeable(
address collection,
address implementation,
address upgradeAuthority
) external returns (uint64 epoch) {
bool byOwner = msg.sender == owner();
if (!byOwner && !approver[msg.sender]) revert NotAuthorized();
Rec storage r = _rec[collection];
if (r.status != Status.Paused) revert InvalidStatus(r.status);
if (r.upgradeAuthority == address(0)) revert InvalidStatus(Status.Paused);
if (!byOwner && (r.route == COLLECTION_ROUTE_OWNER || pausedByOwner[collection])) {
revert OwnerDecisionStands(Status.Paused);
}
bytes32 live = _inspectUpgradeable(collection, r.standard, r.adapter, implementation, upgradeAuthority);
delete pausedBy[collection];
delete pausedByOwner[collection];
r.factory = address(0);
r.implementation = implementation;
r.upgradeAuthority = upgradeAuthority;
r.codehash = live;
r.policyId = _policyId(collection, r.standard, r.adapter, address(0), implementation, upgradeAuthority, live);
uint64 delay;
if (byOwner) {
_pin(r, COLLECTION_ROUTE_OWNER);
if (_ownerImmediate()) {
emit CollectionResumed(collection, uint64(block.timestamp), r.policyEpoch + 1);
return _admit(collection, r);
}
delay = admissionDelay;
} else {
_pin(r, COLLECTION_ROUTE_APPROVER);
_countApproverProposal(collection);
delay = approverAdmissionDelay;
if (delay == 0) {
emit CollectionResumed(collection, uint64(block.timestamp), r.policyEpoch + 1);
return _admit(collection, r);
}
}
uint64 at = uint64(block.timestamp) + delay;
r.status = Status.Pending;
r.effectiveAt = at;
epoch = _advance(r);
emit UpgradeableCollectionAttested(collection, implementation, upgradeAuthority, epoch);
emit CollectionResumed(collection, at, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Pending);
}
/// @notice Remove a collection: no new exposure of any kind. From Pending, Admitted or Paused. Re-admission is a new
/// proposal.
function remove(address collection) external onlyOwner returns (uint64 epoch) {
Rec storage r = _rec[collection];
Status s = r.status;
if (s != Status.Pending && s != Status.Admitted && s != Status.Paused) revert InvalidStatus(s);
r.status = Status.Removed;
delete pausedBy[collection];
delete pausedByOwner[collection];
epoch = _advance(r);
emit CollectionRemoved(collection, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Removed);
}
// ── Unverified lane controls ───────────────────────────────────────────────────────────────────
/// @notice Block a never-recorded collection (`policyEpoch == 0`) at once. Owner or an approver. Does not advance
/// `policyEpoch`, so `unblockCollection` by the owner returns the collection to the unverified group.
function blockCollection(address collection) external {
if (msg.sender != owner() && !approver[msg.sender]) revert NotAuthorized();
if (collection == address(0)) revert ZeroAddress();
Rec storage r = _rec[collection];
if (r.policyEpoch != 0 || unrecordedBlocked[collection]) revert InvalidStatus(r.status);
unrecordedBlocked[collection] = true;
blockedBy[collection] = msg.sender;
emit CollectionBlocked(collection, msg.sender);
}
/// @notice Unblock a collection that was blocked while unrecorded. Owner only, consistent with `OwnerDecisionStands`.
function unblockCollection(address collection) external onlyOwner {
if (!unrecordedBlocked[collection]) revert InvalidStatus(_rec[collection].status);
delete unrecordedBlocked[collection];
delete blockedBy[collection];
emit CollectionUnblocked(collection);
}
/// @notice Close the global unverified lane at once. Owner or any approver.
function closeUnverifiedLane() external {
if (msg.sender != owner() && !approver[msg.sender]) revert NotAuthorized();
if (!unverifiedLaneOpen) revert AlreadySet();
unverifiedLaneOpen = false;
unverifiedLaneClosedBy = msg.sender;
emit UnverifiedLaneClosed(msg.sender);
}
/// @notice Reopen the global unverified lane. Owner only.
function openUnverifiedLane() external onlyOwner {
if (unverifiedLaneOpen) revert AlreadySet();
unverifiedLaneOpen = true;
delete unverifiedLaneClosedBy;
emit UnverifiedLaneOpened(msg.sender);
}
/// @notice Enable or disable criteria-based (collection/trait) offers on unverified collections. Owner only.
function setUnverifiedCollectionOffersOpen(bool open) external onlyOwner {
if (unverifiedCollectionOffersOpen == open) revert AlreadySet();
unverifiedCollectionOffersOpen = open;
emit UnverifiedCollectionOffersUpdated(open);
}
// ── Views ──────────────────────────────────────────────────────────────────────────────────────
/// @inheritdoc ICollectionRegistry
function admitted(address collection, uint8 standard)
external
view
returns (bool ok, bytes32 policyId, uint64 epoch)
{
Rec storage r = _rec[collection];
epoch = r.policyEpoch;
policyId = r.policyId;
if (r.status != Status.Admitted || r.standard != standard || r.effectiveAt > block.timestamp) {
return (false, policyId, epoch);
}
if (collection.codehash != r.codehash) return (false, policyId, epoch);
bytes4 other = standard == COLLECTION_STANDARD_ERC721 ? ERC1155_INTERFACE_ID : ERC721_INTERFACE_ID;
if (_answers(collection, other)) return (false, policyId, epoch);
ok = true;
}
/// @inheritdoc ICollectionRegistry
function unverifiedStatus(address collection, bool criteriaOffer)
external
view
returns (
bool ok,
bool blocked,
bool laneOpen,
bool criteriaOffersOpen,
bytes32 currentPolicyId,
uint64 currentEpoch
)
{
Rec storage r = _rec[collection];
currentPolicyId = r.policyId;
currentEpoch = r.policyEpoch;
blocked = unrecordedBlocked[collection];
laneOpen = unverifiedLaneOpen;
criteriaOffersOpen = unverifiedCollectionOffersOpen;
ok = currentEpoch == 0
&& !blocked
&& laneOpen
&& (!criteriaOffer || criteriaOffersOpen)
&& collection.code.length != 0;
}
/// @inheritdoc ICollectionRegistry
function policyEpoch(address collection) external view returns (uint64) {
return _rec[collection].policyEpoch;
}
/// @inheritdoc ICollectionRegistry
function record(address collection) external view returns (CollectionRecord memory rec) {
Rec storage r = _rec[collection];
rec = CollectionRecord({
standard: r.standard,
adapter: r.adapter,
status: r.status,
policyEpoch: r.policyEpoch,
effectiveAt: r.effectiveAt,
factory: r.factory,
implementation: r.implementation,
upgradeAuthority: r.upgradeAuthority,
codehash: r.codehash,
policyId: r.policyId,
route: r.route,
admittedAt: r.admittedAt
});
}
/// @notice Approver proposals in the last `APPROVER_CAP_WINDOW` (at most `MAX_APPROVER_HOURLY_CAP`).
function approverProposalsInLastHour() external view returns (uint256 count) {
uint64 n = approverProposalCount;
uint256 back = n < MAX_APPROVER_HOURLY_CAP ? n : MAX_APPROVER_HOURLY_CAP;
while (count < back) {
uint64 t = _approverRing[(n - 1 - count) % MAX_APPROVER_HOURLY_CAP];
if (t + APPROVER_CAP_WINDOW <= block.timestamp) break;
unchecked {
++count;
}
}
}
/// @notice When the next approver proposal fits under the cap: 0 = now; `type(uint64).max` = the route is closed.
function approverCapRetryAt() external view returns (uint64) {
uint16 cap = approverHourlyCap;
if (cap == 0) return type(uint64).max;
uint64 n = approverProposalCount;
if (n < cap) return 0;
uint64 free = _approverRing[(n - cap) % MAX_APPROVER_HOURLY_CAP] + APPROVER_CAP_WINDOW;
return free > block.timestamp ? free : 0;
}
/// @notice The policy id for an immutable collection (`implementation` and `upgradeAuthority` are zero).
function computePolicyId(address collection, uint8 standard, uint8 adapter, address factory, bytes32 codehash)
external
pure
returns (bytes32)
{
return _policyId(collection, standard, adapter, factory, address(0), address(0), codehash);
}
/// @notice The policy id for an upgradeable collection (`factory` is zero; `implementation` and `upgradeAuthority`
/// are bound).
function computeUpgradeablePolicyId(
address collection,
uint8 standard,
uint8 adapter,
address implementation,
address upgradeAuthority,
bytes32 codehash
) external pure returns (bytes32) {
return _policyId(collection, standard, adapter, address(0), implementation, upgradeAuthority, codehash);
}
/// @notice Run the launch code policy on `collection` without writing anything. Reverts with the reason a
/// proposal would be refused. For admission scripts and reviewers.
function checkCodePolicy(address collection, uint8 standard) external view returns (bytes32 codehash) {
_checkStandard(standard);
codehash = _liveCodehash(collection);
_scanCodeOrCloneTarget(collection);
_checkInterfaces(collection, standard);
}
/// @notice Run the upgradeable code policy on `(collection, implementation, upgradeAuthority)` without writing
/// anything. Reverts with the reason `proposeUpgradeable` would refuse it.
function checkUpgradeableCodePolicy(
address collection,
uint8 standard,
address implementation,
address upgradeAuthority
) external view returns (bytes32 codehash) {
return _inspectUpgradeable(collection, standard, COLLECTION_ADAPTER_SEAPORT, implementation, upgradeAuthority);
}
// ── Internals ──────────────────────────────────────────────────────────────────────────────────
function _ownerImmediate() private view returns (bool) {
return admissionDelay == 0 || ownerAdmissionImmediate;
}
/// @dev A new code was pinned on `r`: record its route and clear the admission time until it is admitted.
function _pin(Rec storage r, uint8 route) private {
r.route = route;
r.admittedAt = 0;
}
/// @dev Count one approver proposal against the rolling-hour cap, exactly: with cap N, the N-th most recent
/// proposal must be at least `APPROVER_CAP_WINDOW` old. The ring holds the last 256, and N <= 256.
function _countApproverProposal(address collection) private {
uint16 cap = approverHourlyCap;
if (cap == 0) revert ApproverRouteClosed();
uint64 n = approverProposalCount;
if (n >= cap) {
uint64 free = _approverRing[(n - cap) % MAX_APPROVER_HOURLY_CAP] + APPROVER_CAP_WINDOW;
if (free > block.timestamp) revert ApproverHourlyCapReached(cap, free);
}
_approverRing[n % MAX_APPROVER_HOURLY_CAP] = uint64(block.timestamp);
unchecked {
++n;
}
approverProposalCount = n;
emit ApproverProposal(collection, msg.sender, n);
}
function _admit(address collection, Rec storage r) private returns (uint64 epoch) {
r.status = Status.Admitted;
r.everAdmitted = true;
r.effectiveAt = uint64(block.timestamp);
if (r.admittedAt == 0) r.admittedAt = uint64(block.timestamp);
epoch = _advance(r);
if (r.upgradeAuthority != address(0)) {
emit UpgradeableCollectionAttested(collection, r.implementation, r.upgradeAuthority, epoch);
}
emit CollectionAdmitted(collection, r.factory, r.standard, r.adapter, r.codehash, r.policyId, epoch);
emit PolicyEpochAdvanced(collection, epoch, Status.Admitted);
}
function _advance(Rec storage r) private returns (uint64 epoch) {
unchecked {
epoch = r.policyEpoch + 1;
}
r.policyEpoch = epoch;
}
function _policyId(
address collection,
uint8 standard,
uint8 adapter,
address factory,
address implementation,
address upgradeAuthority,
bytes32 codehash
) private pure returns (bytes32) {
return keccak256(
abi.encode(collection, standard, adapter, factory, implementation, upgradeAuthority, codehash)
);
}
function _inspectUpgradeable(
address collection,
uint8 standard,
uint8 adapter,
address implementation,
address upgradeAuthority
) private view returns (bytes32 live) {
_checkStandard(standard);
if (adapter != COLLECTION_ADAPTER_SEAPORT) revert UnsupportedAdapter();
live = _liveCodehash(collection);
_liveCodehash(implementation);
_scanCode(implementation);
_liveCodehash(upgradeAuthority);
_checkInterfaces(collection, standard);
}
function _checkStandard(uint8 standard) private pure {
if (standard != COLLECTION_STANDARD_ERC721 && standard != COLLECTION_STANDARD_ERC1155) {
revert InvalidStandard();
}
}
/// @dev Code must exist and must not be an EIP-7702 delegation indicator (0xef0100 ‖ address, 23 bytes).
function _liveCodehash(address collection) private view returns (bytes32) {
uint256 size = collection.code.length;
if (size == 0) revert NoCode();
if (size == 23) {
bytes memory head = collection.code;
if (head[0] == 0xef && head[1] == 0x01 && head[2] == 0x00) revert DelegatedAccount();
}
return collection.codehash;
}
/// @dev Must answer its own standard's ERC-165 id and not the other's.
function _checkInterfaces(address collection, uint8 standard) private view {
bool is721 = _answers(collection, ERC721_INTERFACE_ID);
bool is1155 = _answers(collection, ERC1155_INTERFACE_ID);
if (is721 && is1155) revert AnswersBothStandards();
if (standard == COLLECTION_STANDARD_ERC721 ? !is721 : !is1155) revert StandardNotAnswered();
}
/// @dev Approver and owner routes. A runtime that is byte-exact the 45-byte EIP-1167 clone
/// (`363d3d373d3d3d363d73 ‖ target ‖ 5af43d82803e903d91602b57fd5bf3`) is judged by its target: the target must
/// have code, must not be a 7702 delegation and must pass the opcode scan. A target with no reachable
/// DELEGATECALL, CALLCODE or SELFDESTRUCT cannot change, and the clone's pinned codehash fixes the target
/// address, so the clone is as immutable as its target. Any other code, including a clone with another prefix
/// or length, is scanned itself (and a clone's DELEGATECALL refuses it). The interface probes run on the
/// collection itself, which is what consumers read. Reason: Bugz and DeBugz off their home chain are bridge
/// copies made as EIP-1167 clones of the bridge's collection templates, and the bridge does not call the
/// registrar.
function _scanCodeOrCloneTarget(address collection) private view {
address target = _cloneTarget(collection);
if (target == address(0)) {
_scanCode(collection);
} else {
_liveCodehash(target);
_scanCode(target);
}
}
/// @dev The target of a byte-exact EIP-1167 minimal proxy, or zero.
function _cloneTarget(address collection) private view returns (address target) {
if (collection.code.length != 45) return address(0);
bytes memory c = collection.code;
bytes32 head;
bytes32 tail;
assembly ("memory-safe") {
head := mload(add(c, 32)) // bytes 0..31
tail := mload(add(c, 62)) // bytes 30..61 (only 30..44 are code)
target := shr(96, mload(add(c, 42))) // bytes 10..29
}
// bytes 0..9 and 30..44
if (bytes10(head) != bytes10(0x363d3d373d3d3d363d73)) return address(0);
if (bytes15(tail) != bytes15(0x5af43d82803e903d91602b57fd5bf3)) return address(0);
}
/// @dev Refuse DELEGATECALL (0xf4), CALLCODE (0xf2) and SELFDESTRUCT (0xff) wherever they can run. The sweep is the
/// EVM's own instruction split (PUSH1..PUSH32 immediates skipped; a byte inside PUSH data can never run or be a
/// jump destination) with dead-code tracking: code is live from offset 0 and from every JUMPDEST on an
/// instruction boundary, and dead after STOP, RETURN, REVERT, INVALID, JUMP or SELFDESTRUCT until the next such
/// JUMPDEST. Execution reaches a byte only by falling through or by jumping to a JUMPDEST, so a byte in a dead
/// run can never execute. This skips the metadata trailer and data a compiler appends after the code, and still
/// sees every reachable opcode. Externally linked Solidity libraries are reached by DELEGATECALL, so a
/// collection built with linked libraries is refused on this route.
function _scanCode(address collection) private view {
bytes memory code = collection.code;
uint256 size = code.length;
uint256 badAt = type(uint256).max;
uint256 badOp;
assembly ("memory-safe") {
let base := add(code, 32)
let live := 1
for { let i := 0 } lt(i, size) {} {
let op := byte(0, mload(add(base, i)))
if eq(op, 0x5b) { live := 1 }
if and(live, or(or(eq(op, 0xf4), eq(op, 0xf2)), eq(op, 0xff))) {
badAt := i
badOp := op
break
}
// STOP, JUMP, RETURN, REVERT, INVALID (SELFDESTRUCT is refused above while live)
if or(or(iszero(op), eq(op, 0x56)), or(or(eq(op, 0xf3), eq(op, 0xfd)), or(eq(op, 0xfe), eq(op, 0xff)))) {
live := 0
}
i := add(i, 1)
if and(gt(op, 0x5f), lt(op, 0x80)) { i := add(i, sub(op, 0x5f)) }
}
}
if (badAt != type(uint256).max) revert ForbiddenOpcode(badAt, uint8(badOp));
}
/// @dev ERC-165 probe that never reverts: a bounded staticcall reading at most 32 bytes. Any failure, short return
/// or value other than 1 counts as not answering.
function _answers(address collection, bytes4 interfaceId) private view returns (bool yes) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(ptr, shl(224, 0x01ffc9a7))
mstore(add(ptr, 4), interfaceId)
let success := staticcall(PROBE_GAS, collection, ptr, 36, ptr, 32)
yes := and(and(success, iszero(lt(returndatasize(), 32))), eq(mload(ptr), 1))
}
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../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.
*
* By default, the owner account will be the one that deploys the contract. 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;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @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 {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
}
@openzeppelin/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./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.
*
* By default, the owner account will be the one that deploys the contract. 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.
*/
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() external {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
ethereum/interfaces/ICollectionRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @dev Asset standards. 0 is never admitted.
uint8 constant COLLECTION_STANDARD_ERC721 = 1;
uint8 constant COLLECTION_STANDARD_ERC1155 = 2;
/// @dev Settlement adapter ids. The launch rail is the plain Seaport transfer path; other ids are reserved.
uint8 constant COLLECTION_ADAPTER_SEAPORT = 1;
/// @dev Admission routes, as recorded on each record (`CollectionRecord.route`).
uint8 constant COLLECTION_ROUTE_NONE = 0;
uint8 constant COLLECTION_ROUTE_FACTORY = 1;
uint8 constant COLLECTION_ROUTE_APPROVER = 2;
uint8 constant COLLECTION_ROUTE_OWNER = 3;
/// @dev Reserved `policyId` signed in a zone authorization (with `policyEpoch = 0`) for an unrecorded collection
/// trading on the unverified lane (listings and concrete item offers).
bytes32 constant UNVERIFIED_POLICY_ID = keccak256("unvault.collection.unverified.v1");
/// @dev Reserved `policyId` signed in a zone authorization (with `policyEpoch = 0`) for a criteria-based offer on an
/// unrecorded collection trading on the unverified lane.
bytes32 constant UNVERIFIED_CRITERIA_POLICY_ID = keccak256("unvault.collection.unverified.criteria.v1");
/// @title Collection admission registry (consumer interface)
/// @notice The on-chain admission boundary for every UnVault settlement rail. A rail asks `admitted` before any
/// funds move and refuses a collection it does not admit. Exit paths (cancel, claim, reclaim, withdraw,
/// refund) never consult it.
/// @dev Consumers check at construction: `code.length > 0` and
/// `IERC165(registry).supportsInterface(type(ICollectionRegistry).interfaceId)`.
interface ICollectionRegistry {
enum Status {
None,
Pending,
Admitted,
Paused,
Removed
}
struct CollectionRecord {
uint8 standard; // COLLECTION_STANDARD_*
uint8 adapter; // COLLECTION_ADAPTER_*
Status status;
uint64 policyEpoch; // per collection; increases on every record change, never resets
uint64 effectiveAt; // Pending: when it may be applied; Admitted: when it was admitted
address factory; // the trusted factory that registered it, or zero (source = the pinned codehash)
address implementation; // attested implementation for an upgradeable collection, or zero (immutable)
address upgradeAuthority; // attested contract upgrade authority for an upgradeable collection, or zero (immutable)
bytes32 codehash; // EXTCODEHASH pinned at admission
bytes32 policyId; // keccak256(abi.encode(collection, standard, adapter, factory, implementation, upgradeAuthority, codehash))
// How and when the current code was admitted. Set when a code is pinned (factory registration, proposal, resume
// with changed code); a resume with unchanged code keeps both. `admittedAt` is 0 until the first admission of
// the pinned code. Not part of the policy id.
uint8 route; // COLLECTION_ROUTE_*
uint64 admittedAt; // block timestamp of that admission
}
event UpgradeableCollectionAttested(
address indexed collection,
address indexed implementation,
address indexed upgradeAuthority,
uint64 policyEpoch
);
event CollectionProposed(
address indexed collection,
address indexed proposer,
uint8 standard,
uint8 adapter,
bytes32 codehash,
uint64 effectiveAt,
uint64 policyEpoch
);
event CollectionAdmitted(
address indexed collection,
address indexed factory,
uint8 standard,
uint8 adapter,
bytes32 codehash,
bytes32 policyId,
uint64 policyEpoch
);
event CollectionVetoed(address indexed collection, uint64 policyEpoch);
event CollectionPaused(address indexed collection, address indexed by, uint64 policyEpoch);
event CollectionResumed(address indexed collection, uint64 effectiveAt, uint64 policyEpoch);
event CollectionRemoved(address indexed collection, uint64 policyEpoch);
/// @notice Emitted on every record change, after the specific event. Signers drop cached pairs on it.
event PolicyEpochAdvanced(address indexed collection, uint64 policyEpoch, Status status);
event FactoryTrusted(address indexed factory);
event FactoryUntrusted(address indexed factory);
event CollectionBlocked(address indexed collection, address indexed by);
event CollectionUnblocked(address indexed collection);
event UnverifiedLaneClosed(address indexed by);
event UnverifiedLaneOpened(address indexed by);
event UnverifiedCollectionOffersUpdated(bool open);
/// @notice Whether `collection` is admitted for `standard` right now, with its current policy pair.
/// @dev Never reverts. `ok` is true only when the status is Admitted, `effectiveAt <= block.timestamp`,
/// `standard` matches the record, the live EXTCODEHASH equals the pinned one, and the collection does not
/// answer the other standard's ERC-165 interface. On `ok == false` the pair is still the current one
/// (zero for an unknown collection).
function admitted(address collection, uint8 standard)
external
view
returns (bool ok, bytes32 policyId, uint64 policyEpoch);
/// @notice Whether `collection` may trade on the unverified lane right now (and with a criteria-based offer when
/// `criteriaOffer` is true).
/// @dev Never reverts. `ok` is true only when `collection` has contract code, has never been recorded
/// (`currentEpoch == 0`), is not blocked (`!blocked`), `laneOpen` is true, and either `!criteriaOffer` or
/// `criteriaOffersOpen` is true.
function unverifiedStatus(address collection, bool criteriaOffer)
external
view
returns (
bool ok,
bool blocked,
bool laneOpen,
bool criteriaOffersOpen,
bytes32 currentPolicyId,
uint64 currentEpoch
);
function policyEpoch(address collection) external view returns (uint64);
function record(address collection) external view returns (CollectionRecord memory);
}
/// @title Factory hook of the collection registry
/// @notice A factory the registry trusts registers each collection it deploys, in the deploy transaction, after the
/// collection's code is in place. The collection is admitted at once with the factory as its source and its
/// live codehash pinned. Requirement on every trusted factory: call this only for an address it has just
/// created with CREATE or CREATE2 in the same call, never as a pass-through for an address supplied by a caller.
interface ICollectionRegistrar {
function registerFromFactory(address collection, uint8 standard)
external
returns (bytes32 policyId, uint64 policyEpoch);
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.