Verified contractExactMIT
BOOAPaint
Address0x959d71debcd8bdd9f8dc1e77dfbecddf81ca8305
- Balance
0 ETH
- Transactions
33
- Compiler
solc 0.8.33
- Same code
Only this contract
Details
- Compiler
- solc 0.8.33+commit.64118f21
- 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,118,632
- Creation transaction
- 0x5996d6fc80…8f7444ce15
contracts/v2-eth/BOOAPaint.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {SSTORE2} from "solady/src/utils/SSTORE2.sol";
import {IERC721Minimal, IAdapterBindings, IDelegateRegistry} from "./BOOAConfig.sol";
interface IBOOAStorageEthMinimal {
function getImageData(uint256 tokenId) external view returns (bytes memory);
}
/// @title BOOAPaint
/// @notice Holder-painted background pixels for a BOOA. Each entry is a uint16
/// `pos << 4 | slot`: a 64x64 position and a palette slot. Only pixels that
/// are background in the original art and reachable from the border can be
/// painted, never more of them than the figure has pixels. The figure itself
/// is never touched: writes reject figure pixels, the renderer ignores enclosed
/// background. Paint is active only while its author owns the token.
contract BOOAPaint is Ownable {
struct Cfg {
address setBy;
address ptr;
}
IERC721Minimal public immutable booa;
IAdapterBindings public immutable adapter;
IDelegateRegistry public immutable delegateRegistry;
IBOOAStorageEthMinimal public immutable dataStore;
bytes32 public constant DELEGATE_RIGHTS = keccak256("adapter8004.manage");
mapping(uint256 => Cfg) private _cfg;
mapping(uint256 => bool) public paintFlag;
event MetadataUpdate(uint256 _tokenId);
event PaintSet(uint256 indexed tokenId, address indexed owner, address indexed writer, uint256 pixels);
event PaintCleared(uint256 indexed tokenId, address indexed by);
event PaintFlagged(uint256 indexed tokenId, bool flagged);
error NotHolder();
error NotBound();
error ZeroAddress();
error BadPaint();
error TooMany();
error NothingToSet();
constructor(address _booa, address _delegateRegistry, address _adapter, address _dataStore) Ownable(msg.sender) {
if (_booa == address(0) || _adapter == address(0) || _dataStore == address(0)) revert ZeroAddress();
booa = IERC721Minimal(_booa);
adapter = IAdapterBindings(_adapter);
delegateRegistry = IDelegateRegistry(_delegateRegistry);
dataStore = IBOOAStorageEthMinimal(_dataStore);
}
function setPaint(uint256 tokenId, uint32 agentId, bytes calldata paint) external {
address owner = _requireControl(tokenId);
_requireBound(tokenId, agentId);
if (paint.length == 0) revert NothingToSet();
if (paint.length % 2 != 0) revert BadPaint();
bytes memory bitmap = dataStore.getImageData(tokenId);
(uint8 bgColor, uint256 cap) = _figure(bitmap);
uint256 n = paint.length / 2;
if (n > cap) revert TooMany();
uint256 last;
for (uint256 i; i < n; ++i) {
uint256 v = (uint256(uint8(paint[i * 2])) << 8) | uint256(uint8(paint[i * 2 + 1]));
uint256 pos = v >> 4;
if (i != 0 && pos <= last) revert BadPaint();
if (_getPixel(bitmap, (pos >> 6) * 32, pos & 63) != bgColor) revert BadPaint();
if ((v & 0x0F) == bgColor) revert BadPaint();
last = pos;
}
address ptr = SSTORE2.write(paint);
if (ptr == address(0)) revert ZeroAddress();
if (_cfg[tokenId].setBy != owner) delete paintFlag[tokenId];
_cfg[tokenId] = Cfg({setBy: owner, ptr: ptr});
emit PaintSet(tokenId, owner, msg.sender, n);
emit MetadataUpdate(tokenId);
}
function clearPaint(uint256 tokenId) external {
_requireControl(tokenId);
delete _cfg[tokenId];
emit PaintCleared(tokenId, msg.sender);
emit MetadataUpdate(tokenId);
}
function getPaint(uint256 tokenId) external view returns (bytes memory paint, bool active) {
Cfg memory c = _cfg[tokenId];
if (c.ptr == address(0) || paintFlag[tokenId]) return (paint, false);
address currentOwner;
try booa.ownerOf(tokenId) returns (address a) {
currentOwner = a;
} catch {
return (paint, false);
}
if (c.setBy != currentOwner) return (paint, false);
return (SSTORE2.read(c.ptr), true);
}
function raw(uint256 tokenId) external view returns (Cfg memory) {
return _cfg[tokenId];
}
/// @notice Pixels a holder may paint: 1 where the original art is border-reachable
/// background, the background slot, and the cap (number of figure pixels).
function paintable(uint256 tokenId) external view returns (bytes memory mask, uint8 bgColor, uint256 cap) {
bytes memory bitmap = dataStore.getImageData(tokenId);
(bgColor, cap) = _figure(bitmap);
mask = _outside(bitmap, bgColor);
}
function _figure(bytes memory bitmap) internal pure returns (uint8 bgColor, uint256 cap) {
if (bitmap.length != 2048) revert BadPaint();
uint16[16] memory counts;
for (uint256 i; i < 2048; ++i) {
uint8 b = uint8(bitmap[i]);
counts[b >> 4]++;
counts[b & 0x0F]++;
}
uint16 maxCount;
for (uint8 c; c < 16; ++c) {
if (counts[c] > maxCount) {
maxCount = counts[c];
bgColor = c;
}
}
cap = 4096 - maxCount;
}
function setPaintFlag(uint256 tokenId, bool flagged) external onlyOwner {
paintFlag[tokenId] = flagged;
emit PaintFlagged(tokenId, flagged);
emit MetadataUpdate(tokenId);
}
function renounceOwnership() public pure override {
revert("Cannot renounce");
}
function _requireControl(uint256 tokenId) internal view returns (address owner) {
owner = booa.ownerOf(tokenId);
if (owner == msg.sender) return owner;
address reg = address(delegateRegistry);
if (reg != address(0) && reg.code.length != 0) {
if (delegateRegistry.checkDelegateForERC721(msg.sender, owner, address(booa), tokenId, DELEGATE_RIGHTS)) {
return owner;
}
}
revert NotHolder();
}
function _requireBound(uint256 tokenId, uint32 agentId) internal view {
if (agentId == 0) revert NotBound();
try adapter.bindingOf(agentId) returns (IAdapterBindings.Binding memory b) {
if (b.standard != 0 || b.tokenContract != address(booa) || b.tokenId != tokenId) revert NotBound();
} catch {
revert NotBound();
}
}
function _outside(bytes memory bitmap, uint8 bg) internal pure returns (bytes memory mask) {
mask = new bytes(4096);
uint16[] memory stack = new uint16[](4096);
uint256 sp;
for (uint256 i; i < 64; ++i) {
sp = _visit(bitmap, bg, mask, stack, sp, i);
sp = _visit(bitmap, bg, mask, stack, sp, 4032 + i);
sp = _visit(bitmap, bg, mask, stack, sp, i * 64);
sp = _visit(bitmap, bg, mask, stack, sp, i * 64 + 63);
}
while (sp > 0) {
uint256 c = stack[--sp];
uint256 y = c >> 6;
uint256 rowOffset = y * 32;
uint256 l = c & 63;
uint256 rgt = l;
while (l > 0 && mask[c - (c & 63) + l - 1] == 0 && _getPixel(bitmap, rowOffset, l - 1) == bg) {
--l;
mask[y * 64 + l] = 0x01;
}
while (rgt < 63 && mask[y * 64 + rgt + 1] == 0 && _getPixel(bitmap, rowOffset, rgt + 1) == bg) {
++rgt;
mask[y * 64 + rgt] = 0x01;
}
if (y > 0) sp = _seedSpan(bitmap, bg, mask, stack, sp, y - 1, l, rgt);
if (y < 63) sp = _seedSpan(bitmap, bg, mask, stack, sp, y + 1, l, rgt);
}
}
function _seedSpan(
bytes memory bitmap,
uint8 bg,
bytes memory mask,
uint16[] memory stack,
uint256 sp,
uint256 y,
uint256 l,
uint256 r
) internal pure returns (uint256) {
uint256 rowOffset = y * 32;
bool inRun;
for (uint256 x = l; x <= r; ++x) {
uint256 c = y * 64 + x;
bool ok = mask[c] == 0 && _getPixel(bitmap, rowOffset, x) == bg;
if (ok && !inRun) {
mask[c] = 0x01;
stack[sp++] = uint16(c);
inRun = true;
} else if (!ok) {
inRun = false;
}
}
return sp;
}
function _visit(bytes memory bitmap, uint8 bg, bytes memory mask, uint16[] memory stack, uint256 sp, uint256 c)
internal
pure
returns (uint256)
{
if (mask[c] != 0) return sp;
if (_getPixel(bitmap, (c >> 6) * 32, c & 63) != bg) return sp;
mask[c] = 0x01;
stack[sp] = uint16(c);
return sp + 1;
}
function _getPixel(bytes memory bitmap, uint256 rowOffset, uint256 x) internal pure returns (uint8) {
uint8 b = uint8(bitmap[rowOffset + (x >> 1)]);
return (x & 1 == 0) ? (b >> 4) : (b & 0x0F);
}
}
contracts/v2-eth/BOOAConfig.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {SSTORE2} from "solady/src/utils/SSTORE2.sol";
interface IERC721Minimal {
function ownerOf(uint256 tokenId) external view returns (address);
}
interface IAdapterBindings {
struct Binding {
uint8 standard;
address tokenContract;
uint256 tokenId;
}
function bindingOf(uint256 agentId) external view returns (Binding memory);
}
interface IDelegateRegistry {
function checkDelegateForERC721(
address to,
address from,
address contract_,
uint256 tokenId,
bytes32 rights
) external view returns (bool);
}
/// @title BOOAConfig
/// @notice Holder-owned overrides for the behavioural half of a BOOA's metadata.
/// Identity and artwork traits are not representable here and can never
/// be changed. Taxonomy tables are append-only, so a stored index always
/// resolves to the same label.
/// @dev Writes are permanent public onchain data and cannot be reversed by
/// the deployer or any operator. Content is the writing holder's
/// responsibility. `contentFlag` suppresses display only.
contract BOOAConfig is Ownable {
// ─── Types ──────────────────────────────────────────────────────────
enum Table {
Personality,
Boundary,
Skill,
Domain
}
struct Override {
uint8 version;
uint8 palette;
uint8 levels;
uint32 agentId;
uint32 bg;
uint8 keep;
string vibe;
uint16[] personality;
uint16[] boundaries;
uint16[] skills;
uint16[] domains;
}
struct Cfg {
address setBy;
address ptr;
}
// ─── Constants ──────────────────────────────────────────────────────
uint8 public constant SCHEMA_VERSION = 1;
uint256 public constant MAX_PERSONALITY = 6;
uint256 public constant MAX_BOUNDARIES = 5;
uint256 public constant MAX_SKILLS = 80;
uint256 public constant MAX_DOMAINS = 80;
uint256 public constant MAX_VIBE_BYTES = 200;
uint256 public constant PALETTE_BYTES = 48;
uint32 public constant BG_TRANSPARENT = 0x2000000;
uint8 public constant KEEP_PERSONALITY = 1;
uint8 public constant KEEP_BOUNDARIES = 2;
uint8 public constant KEEP_SKILLS = 4;
uint8 public constant KEEP_DOMAINS = 8;
// ─── Storage ────────────────────────────────────────────────────────
IERC721Minimal public immutable booa;
IAdapterBindings public immutable adapter;
IDelegateRegistry public immutable delegateRegistry;
bytes32 public constant DELEGATE_RIGHTS = keccak256("adapter8004.manage");
mapping(Table => address[]) private _chunks;
mapping(Table => uint16[]) private _chunkBase;
mapping(Table => uint16) private _counts;
mapping(uint256 => Cfg) private _cfg;
mapping(uint256 => bool) public contentFlag;
bytes[] private _palettes;
string[] private _paletteNames;
// ─── Events ─────────────────────────────────────────────────────────
event MetadataUpdate(uint256 _tokenId);
event ConfigSet(uint256 indexed tokenId, address indexed owner, address indexed writer);
event ConfigCleared(uint256 indexed tokenId, address indexed by);
event TaxonomyAppended(Table indexed table, uint16 fromIndex, uint16 count, address pointer);
event ContentFlagged(uint256 indexed tokenId, bool flagged);
event PaletteAppended(uint256 indexed index, string name);
// ─── Errors ─────────────────────────────────────────────────────────
error NotHolder();
error TooMany();
error BadIndex();
error NotSorted();
error VibeTooLong();
error BadCharacter();
error BadVersion();
error ZeroAddress();
error EmptyBatch();
error BadPalette();
error BadLevels();
error BadBackground();
error NotBound();
error NothingToSet();
error BadKeep();
error BadChunk();
constructor(address _booa, address _delegateRegistry, address _adapter) Ownable(msg.sender) {
if (_booa == address(0) || _adapter == address(0)) revert ZeroAddress();
booa = IERC721Minimal(_booa);
adapter = IAdapterBindings(_adapter);
delegateRegistry = IDelegateRegistry(_delegateRegistry);
_palettes.push(
hex"000000626262898989ADADADFFFFFF"
hex"9F4E44CB7E756D5412A1683CC9D487"
hex"9AE29B5CAB5E6ABFC6887ECB50459B"
hex"A057A3"
);
_paletteNames.push("C64");
}
// ─── Holder writes ──────────────────────────────────────────────────
/// @notice Replace this token's behavioural metadata. Empty fields keep the
/// original mint values; a list whose KEEP_* bit is set is added to
/// the mint values instead of replacing them. Only a BOOA bound to
/// an onchain agent can be configured.
function setConfig(uint256 tokenId, Override calldata o) external {
address owner = _requireControl(tokenId);
_requireBound(tokenId, o.agentId);
_validate(o);
address ptr = SSTORE2.write(abi.encode(o));
if (ptr == address(0)) revert ZeroAddress();
if (_cfg[tokenId].setBy != owner) delete contentFlag[tokenId];
_cfg[tokenId] = Cfg({setBy: owner, ptr: ptr});
emit ConfigSet(tokenId, owner, msg.sender);
emit MetadataUpdate(tokenId);
}
/// @notice Drop this token's overrides and fall back to the mint values.
function clearConfig(uint256 tokenId) external {
_requireControl(tokenId);
delete _cfg[tokenId];
emit ConfigCleared(tokenId, msg.sender);
emit MetadataUpdate(tokenId);
}
// ─── Reads ──────────────────────────────────────────────────────────
/// @notice Returns the override and whether it is active. An override is
/// active only while its author still owns the token.
function getConfig(uint256 tokenId) external view returns (Override memory o, bool active) {
Cfg memory c = _cfg[tokenId];
if (c.ptr == address(0)) return (o, false);
address currentOwner;
try booa.ownerOf(tokenId) returns (address a) {
currentOwner = a;
} catch {
return (o, false);
}
if (c.setBy != currentOwner) return (o, false);
bytes memory blob = SSTORE2.read(c.ptr);
o = abi.decode(blob, (Override));
if (o.version != SCHEMA_VERSION) {
Override memory empty;
return (empty, false);
}
if (contentFlag[tokenId]) o.vibe = "";
return (o, true);
}
function raw(uint256 tokenId) external view returns (Cfg memory) {
return _cfg[tokenId];
}
function tableCount(Table t) external view returns (uint16) {
return _counts[t];
}
function chunkCount(Table t) external view returns (uint256) {
return _chunks[t].length;
}
/// @notice Label for an index.
function labelAt(Table t, uint16 index) public view returns (string memory) {
if (index >= _counts[t]) revert BadIndex();
address[] storage cs = _chunks[t];
uint16[] storage bases = _chunkBase[t];
uint256 ci = cs.length;
unchecked {
while (ci > 0) {
--ci;
if (bases[ci] <= index) break;
}
}
uint16 local = index - bases[ci];
address ptr = cs[ci];
uint256 start;
if (local > 0) {
start = _u16At(ptr, 2 + (uint256(local) - 1) * 2);
}
uint256 end = _u16At(ptr, 2 + uint256(local) * 2);
uint256 n = _u16At(ptr, 0);
uint256 dataBase = 2 + n * 2;
return string(SSTORE2.read(ptr, dataBase + start, dataBase + end));
}
function paletteAt(uint8 index) external view returns (bytes memory rgb, string memory name) {
if (index >= _palettes.length) revert BadIndex();
return (_palettes[index], _paletteNames[index]);
}
function paletteCount() external view returns (uint256) {
return _palettes.length;
}
function labelsFor(Table t, uint16[] memory idx) external view returns (string[] memory out) {
out = new string[](idx.length);
for (uint256 i; i < idx.length; ++i) {
out[i] = labelAt(t, idx[i]);
}
}
// ─── Admin ──────────────────────────────────────────────────────────
/// @notice Append labels to a taxonomy. Append is the only mutation;
/// existing indices never move.
function appendTaxonomy(Table t, bytes calldata chunk) external onlyOwner {
uint16 n = uint16(bytes2(chunk[0:2]));
if (n == 0) revert EmptyBatch();
uint256 head = 2 + uint256(n) * 2;
if (chunk.length < head) revert BadChunk();
uint256 prev;
for (uint256 i; i < n; ++i) {
uint256 off = 2 + i * 2;
uint256 end = (uint256(uint8(chunk[off])) << 8) | uint256(uint8(chunk[off + 1]));
if (end < prev) revert BadChunk();
prev = end;
}
if (chunk.length != head + prev) revert BadChunk();
uint16 base = _counts[t];
address ptr = SSTORE2.write(chunk);
if (ptr == address(0)) revert ZeroAddress();
_chunks[t].push(ptr);
_chunkBase[t].push(base);
_counts[t] = base + n;
emit TaxonomyAppended(t, base, n, ptr);
}
/// @notice Append a curated 16-colour palette. Index 0 is always the mint
/// palette.
function appendPalette(string calldata name, bytes calldata rgb) external onlyOwner {
if (rgb.length != PALETTE_BYTES) revert BadPalette();
if (_palettes.length >= 256) revert TooMany();
_palettes.push(rgb);
_paletteNames.push(name);
emit PaletteAppended(_palettes.length - 1, name);
}
/// @notice Suppress display of one token's free-text field.
function setContentFlag(uint256 tokenId, bool flagged) external onlyOwner {
contentFlag[tokenId] = flagged;
emit ContentFlagged(tokenId, flagged);
emit MetadataUpdate(tokenId);
}
function renounceOwnership() public pure override {
revert("Cannot renounce");
}
// ─── Internal ───────────────────────────────────────────────────────
function _requireControl(uint256 tokenId) internal view returns (address owner) {
owner = booa.ownerOf(tokenId);
if (owner == msg.sender) return owner;
address reg = address(delegateRegistry);
if (reg != address(0) && reg.code.length != 0) {
if (
delegateRegistry.checkDelegateForERC721(
msg.sender, owner, address(booa), tokenId, DELEGATE_RIGHTS
)
) {
return owner;
}
}
revert NotHolder();
}
function _requireBound(uint256 tokenId, uint32 agentId) internal view {
if (agentId == 0) revert NotBound();
try adapter.bindingOf(agentId) returns (IAdapterBindings.Binding memory b) {
if (b.standard != 0 || b.tokenContract != address(booa) || b.tokenId != tokenId) revert NotBound();
} catch {
revert NotBound();
}
}
function _validate(Override calldata o) internal view {
if (o.version != SCHEMA_VERSION) revert BadVersion();
if (o.bg != 0 && o.bg != BG_TRANSPARENT && (o.bg >> 24) != 1) revert BadBackground();
if (
bytes(o.vibe).length == 0 && o.personality.length == 0 && o.boundaries.length == 0
&& o.skills.length == 0 && o.domains.length == 0 && o.palette == 0
&& (o.levels == 0 || o.levels >= 16) && o.bg == 0
) revert NothingToSet();
if (o.personality.length > MAX_PERSONALITY) revert TooMany();
if (o.boundaries.length > MAX_BOUNDARIES) revert TooMany();
if (o.skills.length > MAX_SKILLS) revert TooMany();
if (o.domains.length > MAX_DOMAINS) revert TooMany();
if (o.palette >= _palettes.length) revert BadIndex();
if (o.levels != 0 && o.levels != 2 && o.levels != 4 && o.levels != 8 && o.levels != 16) revert BadLevels();
uint8 present;
if (o.personality.length != 0) present |= KEEP_PERSONALITY;
if (o.boundaries.length != 0) present |= KEEP_BOUNDARIES;
if (o.skills.length != 0) present |= KEEP_SKILLS;
if (o.domains.length != 0) present |= KEEP_DOMAINS;
if ((o.keep & ~present) != 0) revert BadKeep();
_checkIndices(Table.Personality, o.personality);
_checkIndices(Table.Boundary, o.boundaries);
_checkIndices(Table.Skill, o.skills);
_checkIndices(Table.Domain, o.domains);
_checkVibe(bytes(o.vibe));
}
function _checkIndices(Table t, uint16[] calldata idx) internal view {
uint16 count = _counts[t];
uint256 len = idx.length;
for (uint256 i; i < len; ++i) {
if (idx[i] >= count) revert BadIndex();
if (i > 0 && idx[i] <= idx[i - 1]) revert NotSorted();
}
}
function _checkVibe(bytes memory v) internal pure {
uint256 len = v.length;
if (len > MAX_VIBE_BYTES) revert VibeTooLong();
uint256 i;
while (i < len) {
uint8 b = uint8(v[i]);
if (b < 0x80) {
if (b < 0x20 || b == 0x7F) revert BadCharacter();
unchecked { ++i; }
continue;
}
uint256 extra;
if (b >= 0xC2 && b <= 0xDF) {
extra = 1;
} else if (b >= 0xE0 && b <= 0xEF) {
extra = 2;
} else if (b >= 0xF0 && b <= 0xF4) {
extra = 3;
} else {
revert BadCharacter();
}
if (i + extra >= len) revert BadCharacter();
for (uint256 k = 1; k <= extra; ++k) {
uint8 c = uint8(v[i + k]);
if (c < 0x80 || c > 0xBF) revert BadCharacter();
}
uint8 b1 = uint8(v[i + 1]);
if (extra == 1) {
if (b == 0xC2 && (b1 <= 0x9F || b1 == 0xAD)) revert BadCharacter();
if (b == 0xD8 && b1 == 0x9C) revert BadCharacter();
} else if (extra == 2) {
if (b == 0xE0 && b1 < 0xA0) revert BadCharacter();
if (b == 0xED && b1 >= 0xA0) revert BadCharacter();
uint8 b2 = uint8(v[i + 2]);
if (b == 0xE2 && b1 == 0x80 && ((b2 >= 0x8B && b2 <= 0x8F) || (b2 >= 0xA8 && b2 <= 0xAE))) revert BadCharacter();
if (b == 0xE2 && b1 == 0x81 && b2 >= 0xA0 && b2 <= 0xAF) revert BadCharacter();
if (b == 0xEF && b1 == 0xBB && b2 == 0xBF) revert BadCharacter();
} else if (extra == 3) {
if (b == 0xF0 && b1 < 0x90) revert BadCharacter();
if (b == 0xF4 && b1 >= 0x90) revert BadCharacter();
if (b == 0xF3 && b1 == 0xA0) revert BadCharacter();
}
unchecked { i += extra + 1; }
}
}
function _u16At(address ptr, uint256 offset) internal view returns (uint256) {
bytes memory two = SSTORE2.read(ptr, offset, offset + 2);
return (uint256(uint8(two[0])) << 8) | uint256(uint8(two[1]));
}
}
node_modules/@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
node_modules/@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
node_modules/solady/src/utils/SSTORE2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Read and write to persistent storage at a fraction of the cost.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SSTORE2.sol)
/// @author Saw-mon-and-Natalie (https://github.com/Saw-mon-and-Natalie)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)
/// @author Modified from SSTORE3 (https://github.com/Philogy/sstore3)
library SSTORE2 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The proxy initialization code.
uint256 private constant _CREATE3_PROXY_INITCODE = 0x67363d3d37363d34f03d5260086018f3;
/// @dev Hash of the `_CREATE3_PROXY_INITCODE`.
/// Equivalent to `keccak256(abi.encodePacked(hex"67363d3d37363d34f03d5260086018f3"))`.
bytes32 internal constant CREATE3_PROXY_INITCODE_HASH =
0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Unable to deploy the storage contract.
error DeploymentFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE LOGIC */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Writes `data` into the bytecode of a storage contract and returns its address.
function write(bytes memory data) internal returns (address pointer) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(data) // Let `l` be `n + 1`. +1 as we prefix a STOP opcode.
/**
* ---------------------------------------------------+
* Opcode | Mnemonic | Stack | Memory |
* ---------------------------------------------------|
* 61 l | PUSH2 l | l | |
* 80 | DUP1 | l l | |
* 60 0xa | PUSH1 0xa | 0xa l l | |
* 3D | RETURNDATASIZE | 0 0xa l l | |
* 39 | CODECOPY | l | [0..l): code |
* 3D | RETURNDATASIZE | 0 l | [0..l): code |
* F3 | RETURN | | [0..l): code |
* 00 | STOP | | |
* ---------------------------------------------------+
* @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called.
* Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16.
*/
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
// Deploy a new contract with the generated creation code.
pointer := create(0, add(data, 0x15), add(n, 0xb))
if iszero(pointer) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Writes `data` into the bytecode of a storage contract with `salt`
/// and returns its normal CREATE2 deterministic address.
function writeCounterfactual(bytes memory data, bytes32 salt)
internal
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
// Deploy a new contract with the generated creation code.
pointer := create2(0, add(data, 0x15), add(n, 0xb), salt)
if iszero(pointer) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Writes `data` into the bytecode of a storage contract and returns its address.
/// This uses the so-called "CREATE3" workflow,
/// which means that `pointer` is agnostic to `data, and only depends on `salt`.
function writeDeterministic(bytes memory data, bytes32 salt)
internal
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
mstore(0x00, _CREATE3_PROXY_INITCODE) // Store the `_PROXY_INITCODE`.
let proxy := create2(0, 0x10, 0x10, salt)
if iszero(proxy) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(0x14, proxy) // Store the proxy's address.
// 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
mstore(0x00, 0xd694)
mstore8(0x34, 0x01) // Nonce of the proxy contract (1).
pointer := keccak256(0x1e, 0x17)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
if iszero(
mul( // The arguments of `mul` are evaluated last to first.
extcodesize(pointer),
call(gas(), proxy, 0, add(data, 0x15), add(n, 0xb), codesize(), 0x00)
)
) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ADDRESS CALCULATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the initialization code hash of the storage contract for `data`.
/// Used for mining vanity addresses with create2crunch.
function initCodeHash(bytes memory data) internal pure returns (bytes32 hash) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
returndatacopy(returndatasize(), returndatasize(), gt(n, 0xfffe))
mstore(data, add(0x61000180600a3d393df300, shl(0x40, n)))
hash := keccak256(add(data, 0x15), add(n, 0xb))
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Equivalent to `predictCounterfactualAddress(data, salt, address(this))`
function predictCounterfactualAddress(bytes memory data, bytes32 salt)
internal
view
returns (address pointer)
{
pointer = predictCounterfactualAddress(data, salt, address(this));
}
/// @dev Returns the CREATE2 address of the storage contract for `data`
/// deployed with `salt` by `deployer`.
/// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
function predictCounterfactualAddress(bytes memory data, bytes32 salt, address deployer)
internal
pure
returns (address predicted)
{
bytes32 hash = initCodeHash(data);
/// @solidity memory-safe-assembly
assembly {
// Compute and store the bytecode hash.
mstore8(0x00, 0xff) // Write the prefix.
mstore(0x35, hash)
mstore(0x01, shl(96, deployer))
mstore(0x15, salt)
predicted := keccak256(0x00, 0x55)
// Restore the part of the free memory pointer that has been overwritten.
mstore(0x35, 0)
}
}
/// @dev Equivalent to `predictDeterministicAddress(salt, address(this))`.
function predictDeterministicAddress(bytes32 salt) internal view returns (address pointer) {
pointer = predictDeterministicAddress(salt, address(this));
}
/// @dev Returns the "CREATE3" deterministic address for `salt` with `deployer`.
function predictDeterministicAddress(bytes32 salt, address deployer)
internal
pure
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, deployer) // Store `deployer`.
mstore8(0x0b, 0xff) // Store the prefix.
mstore(0x20, salt) // Store the salt.
mstore(0x40, CREATE3_PROXY_INITCODE_HASH) // Store the bytecode hash.
mstore(0x14, keccak256(0x0b, 0x55)) // Store the proxy's address.
mstore(0x40, m) // Restore the free memory pointer.
// 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
mstore(0x00, 0xd694)
mstore8(0x34, 0x01) // Nonce of the proxy contract (1).
pointer := keccak256(0x1e, 0x17)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* READ LOGIC */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `read(pointer, 0, 2 ** 256 - 1)`.
function read(address pointer) internal view returns (bytes memory data) {
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
let n := and(0xffffffffff, sub(extcodesize(pointer), 0x01))
extcodecopy(pointer, add(data, 0x1f), 0x00, add(n, 0x21))
mstore(data, n) // Store the length.
mstore(0x40, add(n, add(data, 0x40))) // Allocate memory.
}
}
/// @dev Equivalent to `read(pointer, start, 2 ** 256 - 1)`.
function read(address pointer, uint256 start) internal view returns (bytes memory data) {
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
let n := and(0xffffffffff, sub(extcodesize(pointer), 0x01))
let l := sub(n, and(0xffffff, mul(lt(start, n), start)))
extcodecopy(pointer, add(data, 0x1f), start, add(l, 0x21))
mstore(data, mul(sub(n, start), lt(start, n))) // Store the length.
mstore(0x40, add(data, add(0x40, mload(data)))) // Allocate memory.
}
}
/// @dev Returns a slice of the data on `pointer` from `start` to `end`.
/// `start` and `end` will be clamped to the range `[0, args.length]`.
/// The `pointer` MUST be deployed via the SSTORE2 write functions.
/// Otherwise, the behavior is undefined.
/// Out-of-gas reverts if `pointer` does not have any code.
function read(address pointer, uint256 start, uint256 end)
internal
view
returns (bytes memory data)
{
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
if iszero(lt(end, 0xffff)) { end := 0xffff }
let d := mul(sub(end, start), lt(start, end))
extcodecopy(pointer, add(data, 0x1f), start, add(d, 0x01))
if iszero(and(0xff, mload(add(data, d)))) {
let n := sub(extcodesize(pointer), 0x01)
returndatacopy(returndatasize(), returndatasize(), shr(40, n))
d := mul(gt(n, start), sub(d, mul(gt(end, n), sub(end, n))))
}
mstore(data, d) // Store the length.
mstore(add(add(data, 0x20), d), 0) // Zeroize the slot after the bytes.
mstore(0x40, add(add(data, 0x40), d)) // Allocate memory.
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"solady/=node_modules/solady/",
"murky/=lib/murky/",
"ds-test/=lib/murky/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/murky/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/murky/lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.