Verified contractExactMIT
SerfieDrop
Address0xa1f13ab5243d46719e2b6e9ffeaa22cbbf0f5f66
- Balance
0.138 ETH
- Transactions
250
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- 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,040,395
- Creation transaction
- 0xa193ed20c0…3cc055aab3
2 files
- src/SerfieDrop.solmain42.54 KB
- node_modules/solady/src/utils/MerkleProofLib.sol14.71 KB
src/SerfieDrop.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {MerkleProofLib} from "solady/src/utils/MerkleProofLib.sol";
interface ISeeds {
function seedOf(uint256 tokenId) external view returns (uint256);
function count() external view returns (uint256);
function isSealed() external view returns (bool);
}
interface IRenderer {
function tokenURI(uint256 tokenId, uint256 seed) external view returns (string memory);
}
/// @dev The ERC-721C integration point. Limit Break's Creator Token Standards work by
/// asking a validator whether a transfer is allowed; that is what actually
/// enforces royalties, because it is what stops a marketplace that does not pay
/// from moving the token. Leaving this unset means transfers are unrestricted --
/// set it to a real validator and the collection becomes enforcing without the
/// token changing.
interface ITransferValidator {
function applyCollectionTransferPolicy(address caller, address from, address to)
external
view;
}
/// @notice delegate.xyz's registry, the standard place a cold wallet records
/// that a hot wallet may act for it.
/// @dev Both checks are called rather than one, because the registry's exact
/// fallback behaviour -- whether a contract-level query also honours an
/// ALL-level delegation -- is not stated in its documentation. Asking both
/// questions costs nothing when the first says yes (|| short-circuits) and
/// removes a dependency on behaviour that could not be verified from the
/// docs. Most people delegate at the ALL level, so getting this wrong
/// would have locked out the common case.
interface IDelegateRegistry {
function checkDelegateForContract(
address to, address from, address contract_, bytes32 rights
) external view returns (bool);
function checkDelegateForAll(
address to, address from, bytes32 rights
) external view returns (bool);
}
/// @notice delegate.cash v1 -- die aeltere Registry, und die mit den meisten
/// Eintraegen.
/// @dev Sie kennt kein `rights`-Feld. Das ist der Grund, warum sie zusaetzlich
/// gefragt werden muss: wer ueber die klassische Oberflaeche von
/// delegate.cash "delegate all" gesetzt hat, steht hier -- und nur hier.
///
/// Gemessen am 22.09.2026 auf Mainnet an einer echten Delegation
/// (dasbankerl.eth -> heast.eth):
///
/// v1 checkDelegateForAll(to, from) true
/// v2 checkDelegateForAll(to, from, bytes32(0)) false
///
/// In v2 liegt derselbe Vorgang zwar als Typ "all" vor, aber mit
/// `rights = 0xffffffffff` (= 2^40-1, von irgendeinem Werkzeug
/// hineingeschrieben). Eine Abfrage nach `rights = 0` trifft ihn nicht.
/// Die Aufzaehlung `getIncomingDelegations` zeigt ihn dagegen an -- weshalb
/// Holder-Listen und Vault-Scans die Delegation FINDEN, waehrend der Mint
/// sie ablehnte. Eine Seite, die etwas verspricht, das die Kette nicht
/// haelt, ist schlimmer als eine, die nichts anbietet.
interface IDelegateRegistryV1 {
function checkDelegateForAll(address delegate, address vault)
external view returns (bool);
function checkDelegateForContract(address delegate, address vault, address contract_)
external view returns (bool);
}
interface IERC721Receiver {
function onERC721Received(address, address, uint256, bytes calldata)
external
returns (bytes4);
}
/// @notice SERFIE: 4,269 tokens, art rebuilt from SerfieData on every read.
/// @dev Deliberately dependency-free so it can be read end to end and deployed on a
/// bare Anvil with no package install. Everything that matters is here:
///
/// - phases, each with its own Merkle root, price, window and caps
/// - a per-token seed fixed at mint, so the drop reveals instantly
/// - per-token URI overrides an admin can set, until the admins are revoked
/// - EIP-2981 pointing at a splitter, plus the ERC-721C validator hook
contract SerfieDrop {
// ------------------------------------------------------------------ errors
error NotOwner();
error NotPendingOwner();
error FundsStillHere();
error NothingToWithdraw();
error BadRoyalty();
error BadWindow();
error NotAdmin();
error Frozen();
error BadPhase();
error PhaseClosed();
error NotOnList();
/// @notice A tiered phase was minted through the entry point that carries
/// no allowance. Refused loudly rather than silently treated as an
/// allowance of zero, because "you may mint nothing" and "you used
/// the wrong function" deserve different messages.
error NeedsAllowance();
/// @notice `vault` has not delegated to the caller, so its allowance is not
/// the caller's to spend.
error NotDelegated();
error OverWalletCap();
error OverPhaseCap();
error SoldOut();
error WrongPayment();
error Paused();
error NoSuchToken();
error NotAuthorised();
error BadReceiver();
error TransferFailed();
error SupplyFinal();
error SupplyBelowMinted();
error SupplyWouldGrow();
error TransfersPaused();
error ZeroAddress();
error TransferLockGone();
error SeedsNotReady();
// ------------------------------------------------------------------ events
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
event PhaseSet(uint256 indexed id, bytes32 root, uint96 price, uint32 start, uint32 end, uint16 walletCap, uint16 supplyCap, bool tiered);
event TokenURIOverridden(uint256 indexed tokenId, string uri);
event AdminSet(address indexed who, bool ok);
event OwnershipTransferStarted(address indexed from, address indexed to);
event OwnershipTransferred(address indexed from, address indexed to);
event Withdrawn(address indexed to, uint256 amount);
event DelegateRegistrySet(address registry);
event DelegateRegistryV1Set(address registry);
/// @notice A mint that was not simply "caller for caller": either a
/// delegated wallet spent a vault's allowance, or the tokens went
/// somewhere other than the caller, or both. Indexed so a vault can
/// find everything minted on its behalf.
event MintedFor(
address indexed vault,
address indexed by,
address indexed to,
uint256 phaseId,
uint256 qty
);
event MetadataFrozen();
event MaxSupplySet(uint256 supply);
event SupplyFinalised(uint256 supply);
event TransfersPausedSet(bool paused);
event TransferLockRenounced();
event PausedSet(bool paused);
event RoyaltySet(address receiver, uint96 bps);
event TransferValidatorSet(address validator);
event SeedsSet(address seeds);
event BatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId);
// ------------------------------------------------------------------ config
string public name = "SERFIE";
string public symbol = "SERFIE";
/// @notice The cap on how many tokens can ever exist. Adjustable while the
/// drop runs, then closed for good with `finalizeSupply()`.
/// @dev Not immutable, on purpose: a drop that undersells needs to be able to
/// shrink to what it actually sold rather than leave a permanent gap
/// between supply and reality. It can only ever move DOWN once minting
/// has started -- see `setMaxSupply` -- so no holder can be diluted.
uint256 public MAX_SUPPLY;
/// @notice once true, MAX_SUPPLY can never move again
bool public supplyFinal;
address public owner;
/// @notice Proposed next owner. Nothing changes until it calls `acceptOwnership`.
/// @dev Two steps, because `withdraw` is owner-only and the mint's proceeds sit
/// in this contract. A one-step transfer to a mistyped address would send
/// the money's only key somewhere nobody holds, with no way back. Here a
/// wrong address simply never accepts, and the current owner stays in
/// charge until a key that provably works has answered.
address public pendingOwner;
mapping(address => bool) public isAdmin;
/// @notice once true, no URI override and no renderer change can ever happen again
bool public metadataFrozen;
/// @notice stops MINTING. Transfers are a separate switch.
bool public paused;
/// @notice stops every transfer. Intended for a sunset: freeze the book so a
/// successor collection can be airdropped against a holder list that
/// cannot move underneath it.
bool public transfersPaused;
/// @notice once true, `transfersPaused` can never be set again -- the promise
/// that this switch is gone for good
bool public transferLockRenounced;
IRenderer public renderer;
/// @notice The curated seed table. Every token's face comes from here.
ISeeds public seeds;
address public transferValidator;
/// @notice Where delegations are looked up. Zero means delegation is off
/// and only a wallet's own allowance is reachable.
/// @dev Owner-only to change, for the same reason as setRoyalty: a registry
/// that lies about who delegated to whom is a way to spend somebody
/// else's allocation. It is not a routine setting either -- it is set
/// once per chain, to a known address.
address public delegateRegistry;
/// @notice delegate.cash v1. Null schaltet sie ab.
address public delegateRegistryV1;
address public royaltyReceiver;
uint96 public royaltyBps;
// ------------------------------------------------------------------ supply
uint256 public totalSupply;
mapping(uint256 => address) private _ownerOf;
mapping(address => uint256) private _balanceOf;
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
mapping(uint256 => string) private _uriOverride;
// ------------------------------------------------------------------ phases
struct Phase {
bytes32 root; // 0x0 = open to anyone
uint96 price; // wei per token
uint32 start; // unix, inclusive
uint32 end; // unix, exclusive
uint16 walletCap; // per wallet, per phase -- the ceiling, always
uint16 supplyCap; // tokens this phase may sell
uint16 minted; // tokens this phase has sold
bool exists;
// A tiered phase reads each wallet's allowance out of its own merkle
// leaf instead of giving everyone walletCap. That is what lets one
// list hand some wallets 1 and others 2 without splitting the phase
// in two -- and splitting it would mean a wallet on both halves takes
// the sum of both.
//
// walletCap still applies. The effective limit is min(walletCap,
// allowance), so a mistake in the tree cannot hand anybody more than
// the phase was ever meant to give.
bool tiered;
}
mapping(uint256 => Phase) public phases;
uint256 public phaseCount;
mapping(uint256 => mapping(address => uint16)) public claimed;
/// @param maxSupply the cap, 4269 for this collection
/// @param royaltyReceiver_ the splitter, not a wallet -- EIP-2981 has room for
/// one address and this collection pays two
/// @param royaltyBps_ hundredths of a percent, 200 = 2%
constructor(uint256 maxSupply, address royaltyReceiver_, uint96 royaltyBps_) {
owner = msg.sender;
isAdmin[msg.sender] = true;
MAX_SUPPLY = maxSupply;
// deploying with no royalty receiver would have marketplaces pay royalties
// to address(0) until someone noticed
if (royaltyReceiver_ == address(0)) revert ZeroAddress();
// the same ceiling setRoyalty enforces. Without it here, the one royalty
// value nobody re-checks -- the one it launches with -- was the only one
// that could be absurd.
if (royaltyBps_ > 1000) revert BadRoyalty();
royaltyReceiver = royaltyReceiver_;
royaltyBps = royaltyBps_;
emit AdminSet(msg.sender, true);
// ERC-173 says the owner is whatever `owner()` returns, and OpenSea reads
// exactly that for creator attribution. Announcing the first owner here
// as well means an indexer that only reads logs -- never calling the
// getter -- still sees who this collection belongs to from block one.
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
modifier onlyAdmin() {
if (!isAdmin[msg.sender]) revert NotAdmin();
_;
}
// ------------------------------------------------------------------ admin
function setAdmin(address who, bool ok) external onlyOwner {
isAdmin[who] = ok;
emit AdminSet(who, ok);
}
/// @notice Propose a new owner. Takes effect only when that address accepts.
/// @dev The intended use is deploying from whatever key is convenient and then
/// handing the collection to a wallet worth trusting with the proceeds.
/// Passing address(0) cancels a pending handover.
function transferOwnership(address to) external onlyOwner {
pendingOwner = to;
emit OwnershipTransferStarted(owner, to);
}
/// @notice Take ownership that was offered to you.
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
address old = owner;
owner = msg.sender;
pendingOwner = address(0);
// the new owner needs the admin powers too, or it owns a collection whose
// metadata only the previous key can fix
isAdmin[msg.sender] = true;
emit AdminSet(msg.sender, true);
emit OwnershipTransferred(old, msg.sender);
}
/// @notice Give up ownership for good. There is no way back.
/// @dev Refused while there is a balance. `withdraw` is owner-only, so
/// renouncing with money still inside would strand it permanently -- and
/// renouncing is exactly the sort of thing done at the end of a mint,
/// when the balance is at its highest. Empty the contract first.
///
/// This also actually drops the caller's admin rights, which the previous
/// version only claimed to: it emitted AdminSet(caller,false) without
/// touching the mapping, leaving the ex-owner able to swap the renderer
/// and rewrite token URIs on a collection it no longer owned.
function renounceOwnership() external onlyOwner {
if (address(this).balance != 0) revert FundsStillHere();
address old = owner;
owner = address(0);
pendingOwner = address(0);
isAdmin[old] = false;
emit AdminSet(old, false);
emit OwnershipTransferred(old, address(0));
}
function setRenderer(address r) external onlyAdmin {
if (metadataFrozen) revert Frozen();
renderer = IRenderer(r);
emit BatchMetadataUpdate(1, MAX_SUPPLY);
}
/// @dev No zero-check here on purpose: address(0) is how the validator is
/// switched OFF, which is the collection's default and normal state.
/// @notice Point at the seed table.
/// @dev Same lifetime as the renderer: changeable while the collection is
/// still being corrected, gone for good at `freezeMetadata`. It is not a
/// new trust surface -- an admin who can swap the renderer can already
/// change what every token looks like.
///
/// The table must be sealed on its own side before it can be adopted, so
/// a half-written one can never go live.
function setSeeds(address s_) external onlyAdmin {
if (metadataFrozen) revert Frozen();
if (s_ == address(0)) revert ZeroAddress();
if (!ISeeds(s_).isSealed()) revert SeedsNotReady();
if (ISeeds(s_).count() < MAX_SUPPLY) revert SeedsNotReady();
seeds = ISeeds(s_);
emit SeedsSet(s_);
emit BatchMetadataUpdate(1, MAX_SUPPLY);
}
function setTransferValidator(address v) external onlyAdmin {
transferValidator = v;
emit TransferValidatorSet(v);
}
/// @notice Where royalties are paid, and how much.
/// @dev onlyOwner, not onlyAdmin. Where the money goes is an ownership
/// decision, and this is the one admin power that could move future
/// income to another address permanently -- an admin who is not the
/// owner could point it at themselves, and the metadata freeze does
/// not stop it. It is also not routine: the constructor sets it, and
/// after that it is only touched to repair a wrong splitter.
///
/// Deliberately NOT gated on metadataFrozen. The splitter's payees are
/// immutable, so re-pointing the token at a corrected splitter is the
/// only repair path there is; sealing it behind the freeze would trade
/// a real remedy for the appearance of one.
function setRoyalty(address receiver, uint96 bps) external onlyOwner {
if (bps > 1000) revert BadRoyalty(); // 10% ceiling
if (receiver == address(0)) revert ZeroAddress();
royaltyReceiver = receiver;
royaltyBps = bps;
emit RoyaltySet(receiver, bps);
}
/// @notice Point the drop at a delegation registry, or at nothing.
/// @dev Zero switches delegation off entirely: mintFor then only accepts a
/// vault equal to the caller. That is the safe default for a chain
/// where no registry is deployed, and it is why the mint path never
/// depends on an external call succeeding.
function setDelegateRegistry(address r) external onlyOwner {
delegateRegistry = r;
emit DelegateRegistrySet(r);
}
/// @notice Dasselbe fuer delegate.cash v1.
/// @dev Getrennt settable, weil die beiden Registries auf verschiedenen
/// Chains verschieden vorhanden sind. Null heisst: nicht fragen.
function setDelegateRegistryV1(address r) external onlyOwner {
delegateRegistryV1 = r;
emit DelegateRegistryV1Set(r);
}
/// @notice May `caller` spend `vault`'s allocation?
/// @dev A wallet always may spend its own. Otherwise the registry has to
/// say so. Asked as a view so the mint page can grey out a button
/// instead of offering a transaction that reverts.
///
/// staticcall rather than a plain call, and the result is only trusted
/// when the call succeeded and returned exactly one word. A registry
/// address that turns out to hold no code -- the wrong chain, a typo --
/// then reads as "no delegation" instead of reverting the mint.
function canMintFor(address caller, address vault) public view returns (bool) {
if (caller == vault) return true;
address reg = delegateRegistry;
if (reg != address(0)) {
if (_ask(reg, abi.encodeCall(
IDelegateRegistry.checkDelegateForContract,
(caller, vault, address(this), bytes32(0))))
|| _ask(reg, abi.encodeCall(
IDelegateRegistry.checkDelegateForAll,
(caller, vault, bytes32(0))))) return true;
}
/* Und dann v1, wo die meisten "delegate all" tatsaechlich liegen.
Siehe die Messung am Kopf von IDelegateRegistryV1: eine Delegation,
die v1 bejaht, kann v2 verneinen -- und die Holder-Listen zeigen sie
trotzdem an. Ohne diese Abfrage waere die Seite im Recht und der
Mint im Unrecht. */
address v1 = delegateRegistryV1;
if (v1 == address(0)) return false;
return _ask(v1, abi.encodeCall(
IDelegateRegistryV1.checkDelegateForContract,
(caller, vault, address(this))))
|| _ask(v1, abi.encodeCall(
IDelegateRegistryV1.checkDelegateForAll,
(caller, vault)));
}
/// @notice May `caller` mint `vault`'s allocation and send it to `to`?
///
/// @dev Two ways to be allowed, and they permit different things:
///
/// 1. The caller may spend the allowance -- it is their own, or the
/// vault delegated to them. Then `to` is free: mint from a hot
/// wallet straight into a vault, or to anyone.
///
/// 2. Anyone at all may pay for an eligible wallet's allocation,
/// PROVIDED the tokens go to that wallet: `to == vault`. Nothing
/// can be taken this way -- the payer buys, the eligible wallet
/// receives. It is a gift, and it is why no permission is needed.
///
/// The pairing is what makes it safe. Spending someone's allowance
/// and choosing the recipient are two powers; either one alone is
/// harmless, and only together would they be theft.
///
/// Asked as a view so the page can grey out a button instead of
/// offering a transaction that reverts, and so the rule lives in one
/// place rather than being restated in JavaScript.
function mintAllowed(address caller, address vault, address to)
public view returns (bool)
{
if (to == address(0)) return false;
return to == vault || canMintFor(caller, vault);
}
function _ask(address reg, bytes memory data) private view returns (bool) {
(bool ok, bytes memory out) = reg.staticcall(data);
return ok && out.length == 32 && abi.decode(out, (bool));
}
function setPaused(bool p) external onlyAdmin {
paused = p;
emit PausedSet(p);
}
/// @notice Freeze or unfreeze all transfers.
/// @dev A heavy switch, and holders are right to dislike it: while it is on,
/// nobody can sell. It exists for one job -- taking a holder snapshot
/// that cannot shift while an airdrop goes out -- and `renounceTransferLock`
/// is here so it can be given up for good once that job is done. Minting
/// is unaffected; this only gates transferFrom.
function setTransfersPaused(bool p) external onlyOwner {
if (transferLockRenounced) revert TransferLockGone();
transfersPaused = p;
emit TransfersPausedSet(p);
}
/// @notice Give up the ability to ever pause transfers again. One way.
function renounceTransferLock() external onlyOwner {
transfersPaused = false;
transferLockRenounced = true;
emit TransfersPausedSet(false);
emit TransferLockRenounced();
}
/// @notice Move the cap. Only ever downwards once a token has been sold.
/// @dev Raising it after people have bought would change the odds they bought
/// into, so it is refused outright rather than left to good intentions.
function setMaxSupply(uint256 n) external onlyOwner {
if (supplyFinal) revert SupplyFinal();
if (n < totalSupply) revert SupplyBelowMinted();
if (totalSupply > 0 && n > MAX_SUPPLY) revert SupplyWouldGrow();
MAX_SUPPLY = n;
emit MaxSupplySet(n);
}
/// @notice End the drop here: the cap becomes what has actually been sold, and
/// nothing can move it again. This is the "the mint is over" button.
function finalizeSupply() external onlyOwner {
if (supplyFinal) revert SupplyFinal();
MAX_SUPPLY = totalSupply;
supplyFinal = true;
paused = true;
emit MaxSupplySet(totalSupply);
emit SupplyFinalised(totalSupply);
}
/// @notice Override one token's metadata. This is the whole point of keeping admin
/// keys after mint: a token that renders wrong can be pointed elsewhere.
function setTokenURI(uint256 tokenId, string calldata uri) external onlyAdmin {
if (metadataFrozen) revert Frozen();
if (_ownerOf[tokenId] == address(0)) revert NoSuchToken();
_uriOverride[tokenId] = uri;
emit TokenURIOverridden(tokenId, uri);
}
/// @notice Close the door: no override, no renderer swap, ever again.
function freezeMetadata() external onlyOwner {
metadataFrozen = true;
emit MetadataFrozen();
}
// ------------------------------------------------------------------ phases
function setPhase(
uint256 id,
bytes32 root,
uint96 price,
uint32 start,
uint32 end,
uint16 walletCap,
uint16 supplyCap,
bool tiered
) external onlyAdmin {
if (end <= start) revert BadWindow();
// A tiered phase reads allowances out of leaves, and a leaf cannot be
// proved against a root that is not there. Without this the phase
// would look configured and refuse every mint.
if (tiered && root == bytes32(0)) revert BadPhase();
Phase storage p = phases[id];
if (!p.exists) {
p.exists = true;
if (id + 1 > phaseCount) phaseCount = id + 1;
}
p.root = root;
p.price = price;
p.start = start;
p.end = end;
p.walletCap = walletCap;
p.supplyCap = supplyCap;
p.tiered = tiered;
emit PhaseSet(id, root, price, start, end, walletCap, supplyCap, tiered);
}
/// @notice Everything the front end needs about a phase, in one call.
function phaseInfo(uint256 id)
external
view
returns (
bytes32 root,
uint96 price,
uint32 start,
uint32 end,
uint16 walletCap,
uint16 supplyCap,
uint16 minted,
bool live,
bool tiered
)
{
Phase storage p = phases[id];
root = p.root;
price = p.price;
start = p.start;
end = p.end;
walletCap = p.walletCap;
supplyCap = p.supplyCap;
minted = p.minted;
live = p.exists && block.timestamp >= p.start && block.timestamp < p.end;
// Appended, not inserted: a decoder that reads the first eight words
// by position keeps working and simply does not see the ninth.
tiered = p.tiered;
}
/// @notice The phase a mint would land in right now, or type(uint256).max.
function livePhase() public view returns (uint256) {
for (uint256 i; i < phaseCount; ++i) {
Phase storage p = phases[i];
if (p.exists && block.timestamp >= p.start && block.timestamp < p.end) return i;
}
return type(uint256).max;
}
/// @notice How many `who` may still mint in `id`, allowlist aside.
function remainingFor(uint256 id, address who) external view returns (uint256) {
Phase storage p = phases[id];
if (!p.exists) return 0;
uint256 byWallet = p.walletCap > claimed[id][who] ? p.walletCap - claimed[id][who] : 0;
uint256 byPhase = p.supplyCap > p.minted ? p.supplyCap - p.minted : 0;
uint256 byTotal = MAX_SUPPLY - totalSupply;
uint256 m = byWallet < byPhase ? byWallet : byPhase;
return m < byTotal ? m : byTotal;
}
// ------------------------------------------------------------------ minting
/// @notice Mint from your own allowance, to yourself.
/// @dev Unchanged on purpose: this is the signature the mint page, the
/// documentation and the testnet rehearsal all use.
function mint(uint256 phaseId, uint256 qty, bytes32[] calldata proof) external payable {
_mintPhase(phaseId, qty, 0, proof, msg.sender, msg.sender);
}
/// @notice Mint from a tiered phase, where the list says how many YOU may
/// take rather than giving everyone the same number.
/// @param allowance the number your leaf carries. It is not a request --
/// it is proved against the root, so naming a bigger one simply
/// fails to verify.
/// @dev An overload rather than a replacement: the three-argument mint is
/// the signature the page, the documentation and every existing test
/// use, and a phase that is not tiered has no allowance to name.
function mint(uint256 phaseId, uint256 qty, uint256 allowance, bytes32[] calldata proof)
external
payable
{
_mintPhase(phaseId, qty, allowance, proof, msg.sender, msg.sender);
}
/// @notice Mint using `vault`'s allowance and send the tokens to `to`.
///
/// @param vault whose allowance and whose allowlist entry is spent. Either
/// the caller, or a wallet that has delegated to the caller.
/// @param to who receives the tokens. Anywhere -- this is how you mint with
/// a hot wallet straight into a vault.
///
/// @dev The allowance is counted against `vault`, never against the caller.
/// That is what makes a delegated group share one allocation: a vault
/// listed for three tokens has three, whether the vault mints them or
/// any wallet it delegated to does, in any mixture.
///
/// Who may call this, and with what:
///
/// * the vault itself, or a wallet it delegated to -- and then the
/// tokens may be sent anywhere;
/// * anybody at all, as long as `to == vault`, so the eligible
/// wallet is the one that receives them.
///
/// The second is the useful one and it needs no permission: a stranger
/// pays the price and the gas, and the eligible wallet gets the
/// tokens. It is also how a hot wallet mints into its own vault
/// without either being on a list or setting up a delegation.
///
/// What is refused is the combination: spending someone else's
/// allowance AND naming yourself as the recipient. Either half alone
/// is harmless; only together are they theft. In the public phase,
/// where there is no allowlist at all, without that check the second
/// half would work on any wallet in the world.
function mintFor(
uint256 phaseId,
uint256 qty,
bytes32[] calldata proof,
address vault,
address to
) external payable {
_mintPhase(phaseId, qty, 0, proof, vault, to);
}
/// @notice mintFor on a tiered phase. `allowance` is the vault's, proved
/// against the root like everything else here.
function mintFor(
uint256 phaseId,
uint256 qty,
uint256 allowance,
bytes32[] calldata proof,
address vault,
address to
) external payable {
_mintPhase(phaseId, qty, allowance, proof, vault, to);
}
function _mintPhase(
uint256 phaseId,
uint256 qty,
uint256 allowance,
bytes32[] calldata proof,
address vault,
address to
) private {
// minting to nobody creates tokens ownerOf reports as unowned and that
// nobody can ever move -- supply burned by a typo
if (to == address(0)) revert ZeroAddress();
if (!mintAllowed(msg.sender, vault, to)) revert NotDelegated();
if (paused) revert Paused();
// a token whose seed does not exist is a token with no artwork; refuse to
// create one rather than sell a promise
if (address(seeds) == address(0)) revert SeedsNotReady();
Phase storage p = phases[phaseId];
if (!p.exists) revert BadPhase();
if (block.timestamp < p.start || block.timestamp >= p.end) revert PhaseClosed();
if (qty == 0) revert OverWalletCap();
// How many this wallet may take in this phase. For a plain phase that
// is walletCap; for a tiered one it is the allowance the leaf carries,
// never more than walletCap. Keeping walletCap in the comparison means
// a wrong tree cannot hand out more than the phase was meant to give.
uint256 cap = p.walletCap;
if (p.tiered) {
// setPhase refuses a tiered phase without a root, so a missing root
// here would mean the struct was written some other way. Refuse
// rather than fall back to walletCap and quietly give everyone the
// maximum.
if (p.root == bytes32(0)) revert BadPhase();
// Said before the proof is checked, so the three-argument mint on a
// tiered phase reports the real reason instead of "not on the list"
// -- the leaf for allowance 0 simply does not exist, and that error
// would send people looking in the wrong place.
if (allowance == 0) revert NeedsAllowance();
// uint16 in the leaf: a value that does not survive the cast would
// prove a different leaf than the caller named
if (allowance > type(uint16).max) revert NotOnList();
}
if (p.root != bytes32(0)) {
// the VAULT's leaf, not the caller's: the list names the wallet that
// owns the allocation, and a delegate is not on it
// sorted-pair hashing, so any standard tree generator's proofs verify
//
// The two leaf shapes are never both accepted for one phase. If
// they were, a wallet listed for 1 could also prove the bare-address
// leaf and pick its own allowance.
bytes32 leaf = p.tiered
? keccak256(abi.encodePacked(vault, uint16(allowance)))
: keccak256(abi.encodePacked(vault));
if (!MerkleProofLib.verifyCalldata(proof, p.root, leaf)) revert NotOnList();
if (p.tiered && allowance < cap) cap = allowance;
}
if (claimed[phaseId][vault] + qty > cap) revert OverWalletCap();
// SoldOut before OverPhaseCap: when a phase's cap and the collection are
// both exhausted, "sold out" is the truthful terminal answer. Telling a
// buyer the phase is full invites them to wait for the next one, which
// will never open.
if (totalSupply + qty > MAX_SUPPLY) revert SoldOut();
if (p.minted + qty > p.supplyCap) revert OverPhaseCap();
if (msg.value != p.price * qty) revert WrongPayment();
// one counter for the whole group, keyed by the wallet that holds the
// allocation
claimed[phaseId][vault] += uint16(qty);
p.minted += uint16(qty);
_mintMany(to, qty);
if (vault != msg.sender || to != msg.sender) {
emit MintedFor(vault, msg.sender, to, phaseId, qty);
}
}
/// @notice The team's allocation. Bounded by MAX_SUPPLY like everything else.
function ownerMint(address to, uint256 qty) external onlyOwner {
if (address(seeds) == address(0)) revert SeedsNotReady();
// minting to nobody would create tokens that ownerOf reports as unowned
// and that no one can ever move -- supply burned by a typo
if (to == address(0)) revert ZeroAddress();
if (qty == 0) revert OverWalletCap();
if (totalSupply + qty > MAX_SUPPLY) revert SoldOut();
_mintMany(to, qty);
}
function _mintMany(address to, uint256 qty) private {
uint256 id = totalSupply;
for (uint256 i; i < qty; ++i) {
unchecked { ++id; }
_ownerOf[id] = to;
// Nothing else to record. The token's seed is already sitting in the
// seed table, has been since before the drop opened, and is fixed for
// as long as the chain exists. There is no second step, no window to
// miss and nothing that has to happen later for the artwork to be
// there -- which is the whole reason the table exists.
emit Transfer(address(0), to, id);
}
totalSupply = id;
unchecked { _balanceOf[to] += qty; }
}
/// @notice Send the mint's proceeds to `to`. Owner only.
/// @dev This is the only way ether leaves this contract, and there is no
/// `receive`, so the only ether that can ever be in here is what buyers
/// paid. Royalties are not part of this: those go to the splitter, which
/// pays its two wallets independently.
///
/// An empty balance reverts rather than succeeding silently -- a
/// withdrawal that appears to work but moves nothing is how people
/// conclude the money is gone.
function withdraw(address to) external onlyOwner {
// the whole balance goes out in one call; a zero address here sends it
// nowhere and there is no second chance
if (to == address(0)) revert ZeroAddress();
uint256 bal = address(this).balance;
if (bal == 0) revert NothingToWithdraw();
(bool ok,) = to.call{value: bal}("");
if (!ok) revert TransferFailed();
emit Withdrawn(to, bal);
}
// ------------------------------------------------------------------ seeds
// ------------------------------------------------------------------ seeds
/// @notice A token's seed. The artwork is a pure function of it.
///
/// @dev Read straight out of the table, which was written before the drop
/// opened and sealed before anyone could mint. Three things follow, and
/// each of them was asked for by name:
///
/// 1. The face exists the moment the token does. No wait, no reveal, no
/// placeholder.
/// 2. It never changes. It does not depend on a block hash the chain will
/// forget, so it does not matter whether the next sale is a minute or
/// five years away.
/// 3. Nobody has to do anything for either of those to hold -- not the
/// buyer, not the next buyer, not us.
///
/// The price of all three is that the table is public, so which token
/// carries which face is public. That is a deliberate trade, not an
/// oversight: see SerfieSeeds.
function seedOf(uint256 tokenId) public view returns (uint256) {
if (_ownerOf[tokenId] == address(0)) revert NoSuchToken();
return seeds.seedOf(tokenId);
}
// ------------------------------------------------------------------ metadata
function tokenURI(uint256 tokenId) external view returns (string memory) {
if (_ownerOf[tokenId] == address(0)) revert NoSuchToken();
// a per-token override always wins
string memory over = _uriOverride[tokenId];
if (bytes(over).length != 0) return over;
if (address(renderer) == address(0) || address(seeds) == address(0)) return "";
return renderer.tokenURI(tokenId, seedOf(tokenId));
}
function royaltyInfo(uint256, uint256 salePrice)
external
view
returns (address, uint256)
{
return (royaltyReceiver, (salePrice * royaltyBps) / 10_000);
}
// ------------------------------------------------------------------ ERC-721
function balanceOf(address who) external view returns (uint256) {
return _balanceOf[who];
}
function ownerOf(uint256 tokenId) public view returns (address o) {
o = _ownerOf[tokenId];
if (o == address(0)) revert NoSuchToken();
}
function approve(address to, uint256 tokenId) external {
address o = ownerOf(tokenId);
if (msg.sender != o && !isApprovedForAll[o][msg.sender]) revert NotAuthorised();
getApproved[tokenId] = to;
emit Approval(o, to, tokenId);
}
function setApprovalForAll(address op, bool ok) external {
isApprovedForAll[msg.sender][op] = ok;
emit ApprovalForAll(msg.sender, op, ok);
}
function transferFrom(address from, address to, uint256 tokenId) public {
if (transfersPaused) revert TransfersPaused();
if (from != _ownerOf[tokenId]) revert NotAuthorised();
if (to == address(0)) revert BadReceiver();
if (
msg.sender != from && !isApprovedForAll[from][msg.sender]
&& msg.sender != getApproved[tokenId]
) revert NotAuthorised();
// the ERC-721C hook: whatever policy the validator implements applies here
address v = transferValidator;
if (v != address(0)) {
ITransferValidator(v).applyCollectionTransferPolicy(msg.sender, from, to);
}
unchecked {
--_balanceOf[from];
++_balanceOf[to];
}
_ownerOf[tokenId] = to;
delete getApproved[tokenId];
emit Transfer(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId) external {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
public
{
transferFrom(from, to, tokenId);
if (to.code.length != 0) {
bytes4 got = IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, data);
if (got != IERC721Receiver.onERC721Received.selector) revert BadReceiver();
}
}
/// @dev ERC-173 (0x7f5828d0) is deliberately NOT claimed here. `owner()` is
/// the ERC-173 getter and marketplaces read it directly -- OpenSea's own
/// docs name it as the source of creator attribution, and OpenZeppelin's
/// Ownable does not register the id either. But ERC-173 also specifies
/// that `transferOwnership` MOVES ownership, and ours only proposes it.
/// Claiming the interface would tell a tool it can hand this collection
/// to someone in one call, which is exactly what the two-step design is
/// there to prevent.
function supportsInterface(bytes4 id) external pure returns (bool) {
return id == 0x01ffc9a7 // ERC-165
|| id == 0x80ac58cd // ERC-721
|| id == 0x5b5e139f // ERC-721Metadata
|| id == 0x2a55205a // ERC-2981
|| id == 0x49064906; // ERC-4906, the metadata-update events below
}
}
node_modules/solady/src/utils/MerkleProofLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
library MerkleProofLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MERKLE PROOF VERIFICATION OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
internal
pure
returns (bool isValid)
{
/// @solidity memory-safe-assembly
assembly {
if mload(proof) {
// Initialize `offset` to the offset of `proof` elements in memory.
let offset := add(proof, 0x20)
// Left shift by 5 is equivalent to multiplying by 0x20.
let end := add(offset, shl(5, mload(proof)))
// Iterate over proof elements to compute root hash.
for {} 1 {} {
// Slot of `leaf` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(leaf, mload(offset)))
// Store elements to hash contiguously in scratch space.
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
mstore(scratch, leaf)
mstore(xor(scratch, 0x20), mload(offset))
// Reuse `leaf` to store the hash to reduce stack operations.
leaf := keccak256(0x00, 0x40)
offset := add(offset, 0x20)
if iszero(lt(offset, end)) { break }
}
}
isValid := eq(leaf, root)
}
}
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
internal
pure
returns (bool isValid)
{
/// @solidity memory-safe-assembly
assembly {
if proof.length {
// Left shift by 5 is equivalent to multiplying by 0x20.
let end := add(proof.offset, shl(5, proof.length))
// Initialize `offset` to the offset of `proof` in the calldata.
let offset := proof.offset
// Iterate over proof elements to compute root hash.
for {} 1 {} {
// Slot of `leaf` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(leaf, calldataload(offset)))
// Store elements to hash contiguously in scratch space.
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
mstore(scratch, leaf)
mstore(xor(scratch, 0x20), calldataload(offset))
// Reuse `leaf` to store the hash to reduce stack operations.
leaf := keccak256(0x00, 0x40)
offset := add(offset, 0x20)
if iszero(lt(offset, end)) { break }
}
}
isValid := eq(leaf, root)
}
}
/// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
/// given `proof` and `flags`.
///
/// Note:
/// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
/// will always return false.
/// - The sum of the lengths of `proof` and `leaves` must never overflow.
/// - Any non-zero word in the `flags` array is treated as true.
/// - The memory offset of `proof` must be non-zero
/// (i.e. `proof` is not pointing to the scratch space).
function verifyMultiProof(
bytes32[] memory proof,
bytes32 root,
bytes32[] memory leaves,
bool[] memory flags
) internal pure returns (bool isValid) {
// Rebuilds the root by consuming and producing values on a queue.
// The queue starts with the `leaves` array, and goes into a `hashes` array.
// After the process, the last element on the queue is verified
// to be equal to the `root`.
//
// The `flags` array denotes whether the sibling
// should be popped from the queue (`flag == true`), or
// should be popped from the `proof` (`flag == false`).
/// @solidity memory-safe-assembly
assembly {
// Cache the lengths of the arrays.
let leavesLength := mload(leaves)
let proofLength := mload(proof)
let flagsLength := mload(flags)
// Advance the pointers of the arrays to point to the data.
leaves := add(0x20, leaves)
proof := add(0x20, proof)
flags := add(0x20, flags)
// If the number of flags is correct.
for {} eq(add(leavesLength, proofLength), add(flagsLength, 1)) {} {
// For the case where `proof.length + leaves.length == 1`.
if iszero(flagsLength) {
// `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
isValid := eq(mload(xor(leaves, mul(xor(proof, leaves), proofLength))), root)
break
}
// The required final proof offset if `flagsLength` is not zero, otherwise zero.
let proofEnd := add(proof, shl(5, proofLength))
// We can use the free memory space for the queue.
// We don't need to allocate, since the queue is temporary.
let hashesFront := mload(0x40)
// Copy the leaves into the hashes.
// Sometimes, a little memory expansion costs less than branching.
// Should cost less, even with a high free memory offset of 0x7d00.
leavesLength := shl(5, leavesLength)
for { let i := 0 } iszero(eq(i, leavesLength)) { i := add(i, 0x20) } {
mstore(add(hashesFront, i), mload(add(leaves, i)))
}
// Compute the back of the hashes.
let hashesBack := add(hashesFront, leavesLength)
// This is the end of the memory for the queue.
// We recycle `flagsLength` to save on stack variables (sometimes save gas).
flagsLength := add(hashesBack, shl(5, flagsLength))
for {} 1 {} {
// Pop from `hashes`.
let a := mload(hashesFront)
// Pop from `hashes`.
let b := mload(add(hashesFront, 0x20))
hashesFront := add(hashesFront, 0x40)
// If the flag is false, load the next proof,
// else, pops from the queue.
if iszero(mload(flags)) {
// Loads the next proof.
b := mload(proof)
proof := add(proof, 0x20)
// Unpop from `hashes`.
hashesFront := sub(hashesFront, 0x20)
}
// Advance to the next flag.
flags := add(flags, 0x20)
// Slot of `a` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(a, b))
// Hash the scratch space and push the result onto the queue.
mstore(scratch, a)
mstore(xor(scratch, 0x20), b)
mstore(hashesBack, keccak256(0x00, 0x40))
hashesBack := add(hashesBack, 0x20)
if iszero(lt(hashesBack, flagsLength)) { break }
}
isValid :=
and(
// Checks if the last value in the queue is same as the root.
eq(mload(sub(hashesBack, 0x20)), root),
// And whether all the proofs are used, if required.
eq(proofEnd, proof)
)
break
}
}
}
/// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
/// given `proof` and `flags`.
///
/// Note:
/// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
/// will always return false.
/// - Any non-zero word in the `flags` array is treated as true.
/// - The calldata offset of `proof` must be non-zero
/// (i.e. `proof` is from a regular Solidity function with a 4-byte selector).
function verifyMultiProofCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32[] calldata leaves,
bool[] calldata flags
) internal pure returns (bool isValid) {
// Rebuilds the root by consuming and producing values on a queue.
// The queue starts with the `leaves` array, and goes into a `hashes` array.
// After the process, the last element on the queue is verified
// to be equal to the `root`.
//
// The `flags` array denotes whether the sibling
// should be popped from the queue (`flag == true`), or
// should be popped from the `proof` (`flag == false`).
/// @solidity memory-safe-assembly
assembly {
// If the number of flags is correct.
for {} eq(add(leaves.length, proof.length), add(flags.length, 1)) {} {
// For the case where `proof.length + leaves.length == 1`.
if iszero(flags.length) {
// `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
// forgefmt: disable-next-item
isValid := eq(
calldataload(
xor(leaves.offset, mul(xor(proof.offset, leaves.offset), proof.length))
),
root
)
break
}
// The required final proof offset if `flagsLength` is not zero, otherwise zero.
let proofEnd := add(proof.offset, shl(5, proof.length))
// We can use the free memory space for the queue.
// We don't need to allocate, since the queue is temporary.
let hashesFront := mload(0x40)
// Copy the leaves into the hashes.
// Sometimes, a little memory expansion costs less than branching.
// Should cost less, even with a high free memory offset of 0x7d00.
calldatacopy(hashesFront, leaves.offset, shl(5, leaves.length))
// Compute the back of the hashes.
let hashesBack := add(hashesFront, shl(5, leaves.length))
// This is the end of the memory for the queue.
// We recycle `flagsLength` to save on stack variables (sometimes save gas).
flags.length := add(hashesBack, shl(5, flags.length))
// We don't need to make a copy of `proof.offset` or `flags.offset`,
// as they are pass-by-value (this trick may not always save gas).
for {} 1 {} {
// Pop from `hashes`.
let a := mload(hashesFront)
// Pop from `hashes`.
let b := mload(add(hashesFront, 0x20))
hashesFront := add(hashesFront, 0x40)
// If the flag is false, load the next proof,
// else, pops from the queue.
if iszero(calldataload(flags.offset)) {
// Loads the next proof.
b := calldataload(proof.offset)
proof.offset := add(proof.offset, 0x20)
// Unpop from `hashes`.
hashesFront := sub(hashesFront, 0x20)
}
// Advance to the next flag offset.
flags.offset := add(flags.offset, 0x20)
// Slot of `a` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(a, b))
// Hash the scratch space and push the result onto the queue.
mstore(scratch, a)
mstore(xor(scratch, 0x20), b)
mstore(hashesBack, keccak256(0x00, 0x40))
hashesBack := add(hashesBack, 0x20)
if iszero(lt(hashesBack, flags.length)) { break }
}
isValid :=
and(
// Checks if the last value in the queue is same as the root.
eq(mload(sub(hashesBack, 0x20)), root),
// And whether all the proofs are used, if required.
eq(proofEnd, proof.offset)
)
break
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EMPTY CALLDATA HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an empty calldata bytes32 array.
function emptyProof() internal pure returns (bytes32[] calldata proof) {
/// @solidity memory-safe-assembly
assembly {
proof.length := 0
}
}
/// @dev Returns an empty calldata bytes32 array.
function emptyLeaves() internal pure returns (bytes32[] calldata leaves) {
/// @solidity memory-safe-assembly
assembly {
leaves.length := 0
}
}
/// @dev Returns an empty calldata bool array.
function emptyFlags() internal pure returns (bool[] calldata flags) {
/// @solidity memory-safe-assembly
assembly {
flags.length := 0
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"solady/=node_modules/solady/",
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.