Verified contractExactMIT
Lens
Address0x2ef71c4780e70f64507f04bd1fde35ec3713269e
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.24
- Same code
2 more contracts
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 10,000 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,330,997
- Creation transaction
- 0xc2912c581c…5564ea8ec9
3 files
- src/Lens.solmain3.11 KB
- src/interfaces/IOrgFactory.sol8.37 KB
- src/interfaces/IProjectHook.sol11.56 KB
src/Lens.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IOrgFactory} from "./interfaces/IOrgFactory.sol";
import {IProjectHook} from "./interfaces/IProjectHook.sol";
interface ILensOrg {
function ownerOf(uint256 tokenId) external view returns (address);
function tokenParam(uint256 tokenId, bytes32 key)
external
view
returns (bytes32 value, bool valueIsHash, bool isSet);
function tokenParamData(uint256 tokenId, bytes32 key) external view returns (bytes memory);
}
/// @title Lens
/// @notice Read-only convenience over a factory and its hook: the questions a gateway or crawler asks,
/// each answered in one `eth_call`. It holds no state and no authority, so it can be
/// redeployed or replaced without touching anything an org depends on. Nothing on-chain
/// should call it.
contract Lens {
bytes32 internal constant _KEY_CID = "abxfs.cid";
bytes32 internal constant _KEY_GATEWAY = "abxfs.gateway";
IOrgFactory public immutable factory;
IProjectHook public immutable hook;
/// @param registered the factory knows `org`. Everything else is zero when this is false, and
/// `org` is never called in that case: an unregistered address is not trusted to answer.
struct Resolution {
bool registered;
IProjectHook.ContentKind kind;
bytes32 cid;
address owner;
bytes gateway;
}
struct Published {
address org;
IProjectHook.PublishRecord record;
}
constructor(address factory_, address hook_) {
factory = IOrgFactory(factory_);
hook = IProjectHook(hook_);
}
/// @notice Everything a gateway needs to serve project `tokenId` of `org`: whether this factory
/// registered the org, the project's kind and current root, its owner, and its `abxfs.gateway`.
/// @dev Reverts (in `ownerOf`) for a token that does not exist in a registered org.
function resolve(address org, uint256 tokenId) external view returns (Resolution memory r) {
if (!factory.isOrg(org)) return r;
r.registered = true;
r.kind = hook.kindOf(org, tokenId);
r.owner = ILensOrg(org).ownerOf(tokenId);
(bytes32 value, bool valueIsHash, bool isSet) = ILensOrg(org).tokenParam(tokenId, _KEY_CID);
if (isSet && !valueIsHash) r.cid = value;
r.gateway = ILensOrg(org).tokenParamData(tokenId, _KEY_GATEWAY);
}
/// @notice A window of this hook's cross-org publish ledger, each record resolved. A crawler keeps
/// the next index to read and asks from there; `hook.globalPublishCount()` is the end. Clamps at
/// the end.
function publishRange(uint256 start, uint256 count) external view returns (Published[] memory out) {
(address[] memory orgs, uint256[] memory orgIndexes) = hook.globalPublishRange(start, count);
out = new Published[](orgs.length);
for (uint256 i; i < orgs.length; ++i) {
out[i] = Published({org: orgs[i], record: hook.publishAt(orgs[i], orgIndexes[i])});
}
}
}
src/interfaces/IOrgFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IOrgFactory — the canonical entry point for ABX FS orgs
/// @notice An **org** is its own ABX collection, deployed by this factory, and projects are tokens in
/// it. The factory renounces ABX ownership of every org at creation, so nobody but a
/// project's owner (`ownerOf`) — not ABX FS, not the org's admin — holds any power over that
/// project. The admin is a record here, not an ABX owner, and its powers are exactly three:
/// mint into the org, open or close it (while open, anyone may mint), and hand the role on.
///
/// @dev Org admin and project owner are different things. A project is governed by `ownerOf` and
/// nothing else; the admin only decides who can *create* projects in the org.
interface IOrgFactory {
error InvalidName();
error InvalidDescription();
/// @dev `predictOrg(bytes32(0))`: a zero salt is a plain deploy, which has no predictable address.
error NoDeterministicAddress();
error SaltSenderMismatch();
error NotAdmin(address org, address caller);
error NotOrg(address org);
error NotPendingAdmin(address org, address caller);
/// @notice `createOrg` before all five components (hook, enumeration hook, minter, card, traits renderer) have been
/// deployed at the addresses this factory names. Anyone can deploy them; see `componentsDeployed`.
error ComponentsNotDeployed();
event OrgCreated(
address indexed org, address indexed admin, uint256 indexed index, string name, uint64 createdBlock
);
event AdminTransferStarted(address indexed org, address indexed from, address indexed to);
event AdminTransferred(address indexed org, address indexed from, address indexed to);
event OpenSet(address indexed org, bool open);
// ─── Creation ─────────────────────────────────────────────────────────────
/// @notice Create an org administered by `msg.sender`, and mint its first project to them.
/// @param name_ Display name: printable ASCII only (bytes 0x20 to 0x7e), 1-64 bytes, with at least one
/// non-space character, else `InvalidName`. Immutable: it becomes the ABX collection name.
/// @param description_ The collection description marketplaces show: 0-1000 bytes of printable ASCII
/// (0x20 to 0x7e) and newlines (0x0a), not only whitespace unless empty, else
/// `InvalidDescription`. Immutable. Empty means none, and the collection document then
/// carries a standard text. It is also every project token's fallback `description`.
/// @param salt `bytes32(0)` for a plain deploy. Otherwise a deterministic address, and the first 20
/// bytes must be zero (anyone may use it) or `msg.sender` (only they may), else
/// `SaltSenderMismatch`.
///
/// SQUATTING: a zero-prefix salt is open to everyone, so anyone who sees your salt can
/// create an org at that address first, as its admin. A prefix-bound salt (the first 20
/// bytes equal your address) binds the org address to you only on chains where you
/// control your own address. The same salt names the same org address on every chain;
/// an EOA's key controls it everywhere, but a smart account (a Safe, say) exists only
/// where it was deployed, and on another chain that address may be unclaimed or someone
/// else's, who can then take the org address there. Only announce or pre-share a
/// predicted address for a prefix-bound salt, and only for chains where your address is
/// yours; a zero-prefix address is safe to rely on only once the org exists and
/// `adminOf` is you.
function createOrg(string calldata name_, string calldata description_, bytes32 salt)
external
returns (address org);
/// @notice The address `createOrg(_, _, salt)` would produce, if the salt is usable. Reverts with
/// `NoDeterministicAddress` for `bytes32(0)`: that is a plain deploy, with no predictable
/// address. It does not check the salt's creator prefix, so a prefix-bound salt of someone
/// else yields an address you cannot deploy to. See `createOrg` on squatting.
function predictOrg(bytes32 salt) external view returns (address);
/// @notice Whether every component exists at the address this factory computed for it. Each is deployed through
/// the keyless CREATE2 deployer with the factory's `COMPONENT_SALT` and its creation code with the
/// constructor arguments the factory used (both stores and this factory for the hook, this factory for the
/// enumeration hook and the minter, the hook for the card and the traits renderer), so only that exact
/// code can be there.
function componentsDeployed() external view returns (bool);
// ─── The registry ─────────────────────────────────────────────────────────
function isOrg(address org) external view returns (bool);
function orgCount() external view returns (uint256);
/// @notice Org `index` in creation order. Append-only. Reverts with an array-bounds panic past the end.
function orgAt(uint256 index) external view returns (address);
/// @notice Orgs `start .. start + count` in creation order, clamped to the end (an overrun is a shorter or empty
/// window, never a revert).
function orgsSlice(uint256 start, uint256 count) external view returns (address[] memory);
function createdBlockOf(address org) external view returns (uint64);
// ─── Admin ────────────────────────────────────────────────────────────────
function adminOf(address org) external view returns (address);
function pendingAdminOf(address org) external view returns (address);
/// @notice Orgs `admin` currently administers. Order is not stable across transfers. Unbounded: use
/// {orgsAdministeredSlice} to page.
function orgsAdministered(address admin) external view returns (address[] memory);
function orgsAdministeredCount(address admin) external view returns (uint256);
/// @notice A window of {orgsAdministered}, `start .. start + count`, clamped like {orgsSlice}. The order is not
/// stable across handovers, so a pager should read at one block.
function orgsAdministeredSlice(address admin, uint256 start, uint256 count)
external
view
returns (address[] memory);
/// @notice Offer the admin role to `to`. Nothing changes until they accept.
function transferAdmin(address org, address to) external;
/// @notice Take the role offered to you (`NotOrg`; `NotPendingAdmin` unless an offer to you is pending). This also
/// closes the org: a handover is how an org recovers from a compromised admin key, and an open door the
/// old admin left must not outlive the old admin. The new admin reopens deliberately.
function acceptAdmin(address org) external;
// ─── Mint rules ───────────────────────────────────────────────────────────
function isOpen(address org) external view returns (bool);
/// @notice Whether `caller` may mint into `org` through the minter: true for a registered org when
/// `caller` is this factory (how `createOrg` mints the first project), the org's admin, or
/// anyone while the org is open; false for any address that is not an org.
function mayMint(address org, address caller) external view returns (bool);
/// @notice Open (`true`: anyone may mint) or close `org`. Admin only (`NotOrg`, `NotAdmin`).
function setOpen(address org, bool open_) external;
}
src/interfaces/IProjectHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IProjectHook — ABX FS project integrity + history, as an ABX configure hook
/// @notice An ABX FS project is an ABX NFT. Its current root CID lives in the `abxfs.cid` PostParam,
/// so authorization is the schema's `TokenOwner` rule and needs nothing from this contract.
/// What the param layer alone cannot give is *integrity* and *queryable history*, and this
/// hook supplies both, vetoing bad writes and recording good ones at the moment they happen.
///
/// @dev State is namespaced by the calling collection (`msg.sender` inside the hook), so one
/// deployment serves every collection wired to it, each in its own namespace; only the
/// global publish ledger is shared, and it admits registered orgs only. Each factory has its
/// own hook: read an org through the hook of the factory that created it. Every read here
/// takes the collection address explicitly.
///
/// The history below lives in contract storage, which is never pruned, so any reader gets
/// it with `eth_call`s and no log scan. ABX's own `TokenParamConfigured` events carry the
/// same writes for anyone who indexes logs; both are written in the same transaction, so
/// they cannot disagree.
interface IProjectHook {
/// @notice What a project's root CID resolves to.
/// @dev `Unset` is 0 so "this token has never published" is distinguishable from
/// "this token's root is a directory".
enum ContentKind {
Unset,
Directory,
File
}
/// @param cid the root CID published.
/// @param publishedAt block timestamp of the publishing transaction.
/// @param publisher the address that satisfied the param's auth: the token owner (every org
/// disables token-owner delegation).
struct Version {
bytes32 cid;
uint40 publishedAt;
address publisher;
}
/// @notice One entry in a collection's append-only publish ledger.
///
/// @dev A {Version} answers "what did project N publish, in order?" — it is per token, so
/// answering "what did this whole collection publish most recently?" from it means reading
/// every token. This record answers the second question directly: one ordered sequence for
/// the entire collection, appended to on every publish and never mutated or removed.
///
/// Ordering is append order, which is block order, which is publish order. Index 0 is the
/// collection's first publish ever; the last index is its most recent.
///
/// The ledger stores only which token and which version (one slot per entry); the rest of the
/// record is read from that token's history, which is append-only too, so the two never disagree.
/// A token id above `2^224 - 1` does not fit the entry and is left out of both ledgers (its history
/// is still kept): an org's ids are below its supply cap, so only a caller that is not an org can
/// have one.
struct PublishRecord {
bytes32 cid;
address publisher;
uint40 publishedAt;
/// @dev The token's own version number for this publish — 1-based, matching {versionAt}.
uint32 version;
uint256 tokenId;
}
// ─── Errors ───────────────────────────────────────────────────────────────
/// @notice The published CID is in neither `DirectoryStore` nor `FileStore`.
/// @dev This is the guarantee that a project cannot point at nothing.
error RootNotFound(bytes32 cid);
/// @notice A project's root kind is fixed by its first publish and cannot change.
error RootKindLocked(ContentKind expected, ContentKind actual);
/// @notice Republishing the current head. Rejected so history holds no no-op entries.
error SameRoot(bytes32 cid);
/// @notice A `String`/`Bytes` payload exceeded this hook's cap for that key.
error BlobTooLarge(bytes32 key, uint256 length, uint256 max);
error NotProjectOwner(address token, uint256 tokenId, address caller);
error InvalidTagName(string tag);
error ReservedTag(string tag);
error TagNotFound(address token, uint256 tokenId, string tag);
error NoVersions(address token, uint256 tokenId);
error InvalidVersion(uint256 version, uint256 versionCount);
error IndexOutOfRange(uint256 index, uint256 count);
error RangeOutOfBounds(uint256 start, uint256 end, uint256 count);
// ─── Events ───────────────────────────────────────────────────────────────
/// @dev `cid` is indexed so a root's publishes can be filtered for. The ledgers above, not this event, are the
/// source of truth: providers prune logs.
event ProjectVersionPublished(
address indexed token,
uint256 indexed tokenId,
uint256 version,
bytes32 indexed cid,
ContentKind kind,
address publisher
);
event ProjectTagSet(address indexed token, uint256 indexed tokenId, string tag, uint256 version);
event ProjectTagMoved(
address indexed token, uint256 indexed tokenId, string tag, uint256 fromVersion, uint256 toVersion
);
event ProjectTagRemoved(address indexed token, uint256 indexed tokenId, string tag);
// ─── The global publish ledger ────────────────────────────────────────────
/// @notice The factory whose registered orgs are admitted to the global publish ledger. Fixed at
/// deployment.
function factory() external view returns (address);
/// @notice Publishes recorded across every registered org.
function globalPublishCount() external view returns (uint256);
/// @notice Entry `index`: which org, and the index of the full {PublishRecord} in that org's own
/// ledger (read it with {publishAt}). Append-only: an index means the same thing forever.
function globalPublishAt(uint256 index) external view returns (address org, uint256 orgIndex);
/// @notice A window of {globalPublishAt}. Clamps instead of reverting on an overrun.
function globalPublishRange(uint256 start, uint256 count)
external
view
returns (address[] memory orgs, uint256[] memory orgIndexes);
// ─── Tags ─────────────────────────────────────────────────────────────────
/// @notice Point `tag` at `version`. Caller MUST be the current token owner. `tag` must match
/// `^[a-z0-9][a-z0-9._-]{0,63}$` (`InvalidTagName`); `version` must be 1..`versionCount`
/// (`InvalidVersion`).
/// @dev Upsert: setting an existing tag moves it. `"latest"` is reserved and virtual.
/// ERC-721 only — an ERC-1155 edition id has no single owner to authorize against.
function setTag(address token, uint256 tokenId, string calldata tag, uint256 version) external;
/// @notice Remove a tag. Caller MUST be the current token owner.
function removeTag(address token, uint256 tokenId, string calldata tag) external;
/// @notice Resolve a tag to its version and CID. `"latest"` resolves to the current head.
function getTag(address token, uint256 tokenId, string calldata tag)
external
view
returns (uint256 version, bytes32 cid);
/// @notice Every tag set on a project. Excludes the virtual `"latest"`.
function listTags(address token, uint256 tokenId) external view returns (string[] memory tags);
function tagCount(address token, uint256 tokenId) external view returns (uint256 count);
/// @dev The tag list uses swap-and-pop on removal, so a removal can move the last tag into the
/// removed one's position. Snapshot at a block height when walking.
function getTagAt(address token, uint256 tokenId, uint256 index) external view returns (string memory tag);
function getTagsRange(address token, uint256 tokenId, uint256 start, uint256 end)
external
view
returns (string[] memory tags);
// ─── History ──────────────────────────────────────────────────────────────
function versionCount(address token, uint256 tokenId) external view returns (uint256 count);
/// @notice The record for a 1-indexed version number.
function versionAt(address token, uint256 tokenId, uint256 version)
external
view
returns (Version memory record);
/// @notice A contiguous window of history, half-open `[start, end)` over 0-based indices
/// (index `i` is version `i + 1`). Append-only, so any unchanged window is stable forever.
function versionsRange(address token, uint256 tokenId, uint256 start, uint256 end)
external
view
returns (Version[] memory records);
/// @notice The current head.
function latestVersion(address token, uint256 tokenId)
external
view
returns (uint256 version, bytes32 cid);
/// @notice A project's locked root kind, or `Unset` if it has never published.
function kindOf(address token, uint256 tokenId) external view returns (ContentKind kind);
// ─── The publish ledger ───────────────────────────────────────────────────
/// @notice How many publishes `token` has recorded, across every project in it.
function publishCount(address token) external view returns (uint256);
/// @notice The publish at `index` in `token`'s ledger. Index 0 is the oldest. Reverts with an
/// array-bounds panic past the end.
function publishAt(address token, uint256 index) external view returns (PublishRecord memory);
/// @notice A window of `token`'s ledger in publish order, oldest first.
/// @dev Clamps to the end rather than reverting, so a pager walking off the end gets an empty
/// tail instead of an error to special-case.
function publishRange(address token, uint256 start, uint256 count)
external
view
returns (PublishRecord[] memory);
/// @notice The most recent `count` publishes, newest first.
/// @dev This is the feed query. It is a single `eth_call` against contract state, which is what
/// makes it immune to log pruning and flat in cost as the chain ages.
function recentPublishes(address token, uint256 count)
external
view
returns (PublishRecord[] memory);
/// @notice The `count` publishes immediately older than `beforeIndex`, newest first.
/// @dev The paging cursor for {recentPublishes}. Pass the index of the oldest record you have
/// seen; pass {publishCount} to start from the newest.
function recentPublishesBefore(address token, uint256 beforeIndex, uint256 count)
external
view
returns (PublishRecord[] memory);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=../contracts-core/lib/forge-std/src/",
"solady/=../contracts-core/lib/solady/src/",
"@abxfs/core/=../contracts-core/src/",
"@abxfs/core-script/=../contracts-core/script/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.