FixedPriceSale

Implementation 0xd97E71DAB49fb20F9b5d12DE3A49ce95fdfD086E · view on evm.now · Ethereum mainnet

Deployed per sale as an EIP-1167 clone of the implementation above through the sale CloneFactory; launch wires one to each new collection and Launched.sale records it. A sale has no canonical address of its own; substitute your sale address for <SALE_ADDRESS> in the examples below.

The v2 sale primitive: one EIP-1167 clone per sale through the sale CloneFactory, bound to one Surface (v2) collection at initialize. It holds this sale's rules and money and nothing about the artwork. Every mint pays exactly price * quantity; proceeds accrue as pull balances.

Config authority is borrowed from the collection's owner. Before the owner renounces, every setting is changeable; after, the sale is frozen and payouts keep flowing. A client that reads a collection's minter() can tell a canonical sale from a bespoke minter with supportsInterface on the IMinter interface id and version().

Concepts

Two mint paths

mint(quantity) mints to the caller, pays the referral share to the sale's fixed defaultReferrer (copied from the launcher at launch) and sends no gate data. mintWithReferral(to, quantity, referrer, data) is the full path: any recipient, an explicit referrer, and gate data. Zero, the sale itself, and the collection address all keep the whole payment for the payout recipient. The collector pays the same price on both; only the split changes.

The checks, in order

  1. not closed (SaleClosed)
  2. inside the window (MintNotStarted, MintEnded)
  3. totalMinted + quantity <= maxMints when set (MaxMintsExceeded)
  4. the gate's check returns true when a gate is set (GateRejected)
  5. mintedBy[to] + quantity <= walletCap when set (WalletCapExceeded)
  6. msg.value == price * quantity (WrongPayment)
  7. a contract recipient answers onERC721Received for every actual id about to be minted, before any exists (ReceiverRejected)
  8. the collection's mintTo
  9. totalMinted and mintedBy[to] grow on every mint, capped or not
  10. settle: REFERRAL_SHARE_BPS (500, 5%) to an eligible nonzero referrer, the rest to payoutRecipient, both as pull balances

The sale normalizes its own address and the collection address to a zero referrer before gate checks and settlement. Quantity zero reaches the collection's ZeroQuantity check if earlier sale checks pass. Receiver callbacks come from the sale with the payer as operator, zero as sender, and empty data; they are pre-mint checks, not post-mint notifications.

Referral share

A constant 5%, with no setter. It pays the referrer supplied to the mint. An artist's own site can pass the payout recipient as referrer, so that account receives both shares; anyone can name themselves when minting straight from the contract. It is a host reward, not a protocol fee. The sale and collection addresses cannot earn a referral: those inputs are treated as zero, avoiding an unwithdrawable referral credit. A 0.1 ETH mint credits 0.005 ETH to an eligible referrer and 0.095 ETH to payout; with no eligible referrer all 0.1 ETH accrues to payout. Rounding is downward in wei.

Write functions

mint

solidity
function mint(uint256 quantity) external payable

Access: permissionless (the mint checks above)

Mints quantity tokens to the caller with defaultReferrer as referrer and empty gate data. An AllowlistGate rejects that empty data with GateRejected; a custom gate decides whether to accept it. Payable; nonReentrant. Emits Sold and, for a nonzero referral amount, ReferralPaid.

mintWithReferral

solidity
function mintWithReferral(address to, uint256 quantity, address referrer, bytes data) external payable

Access: permissionless (the mint checks above)

Mints quantity tokens to to. to is both the recipient and the address the gate and wallet cap evaluate. referrer receives the referral share when nonzero and neither the sale nor collection address. data goes to the gate and nothing else (for AllowlistGate, an abi-encoded bytes32[] proof). Payable; nonReentrant.

withdraw

solidity
function withdraw(address account) external

Access: permissionless (funds go only to account)

Sends account its whole owed balance. Reverts ZeroAccount, NothingToWithdraw, or WithdrawFailed when the transfer fails (the balance is kept). Emits Withdrawn.

withdrawTo

solidity
function withdrawTo(address to) external

Access: permissionless (the caller's own balance only)

Sends the caller's owed balance to to. Same reverts as withdraw.

setPrice

solidity
function setPrice(uint256 price_) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets the price per token in wei. Emits PriceSet.

setMintWindow

solidity
function setMintWindow(uint64 start, uint64 end) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets the window. 0 start opens now, 0 end is open-ended; an end at or before a start reverts BadMintWindow. Emits MintWindowSet.

setMaxMints

solidity
function setMaxMints(uint256 maxMints_) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets this sale's ceiling; 0 is unlimited. Emits MaxMintsSet.

setWalletCap

solidity
function setWalletCap(uint256 walletCap_) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets the per-recipient cap; 0 is unlimited. Counts every earlier mint. Emits WalletCapSet.

setPayoutRecipient

solidity
function setPayoutRecipient(address payoutRecipient_) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets where the artist share accrues. Rejects zero (PayoutRecipientRequired). Balances already accrued stay with the old recipient. Emits PayoutRecipientSet.

setGate

solidity
function setGate(address gate_) external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

Sets the gate; 0 removes it. A nonzero address without code reverts NotAContract. Emits GateSet.

close

solidity
function close() external

Access: owner-only (the collection's owner, borrowed; NotAuthorized)

One-way: no mint succeeds afterwards. Another sale needs a new clone and the collection's setMinter. Emits Closed.

initialize

solidity
function initialize(address collection_, uint256 price_, uint64 mintStart_, uint64 mintEnd_, uint256 maxMints_, uint256 walletCap_, address payoutRecipient_, address gate_, address defaultReferrer_) external

Access: deployer one-shot (initializer, else InvalidInitialization); the collection already names this clone as its minter, or the caller is the collection's owner (NotAuthorized)

Binds the sale to a collection with its price, window, ceiling, wallet cap, payout recipient, gate and default referrer. Reverts CollectionRequired, NotAContract (collection or gate without code), PayoutRecipientRequired and BadMintWindow. Through the factory the caller is the factory, so only the first authority path applies: grant the predicted address (predictCreate or predict on the sale factory, both namespaced to the caller) as minter first, as the launcher does. Emits PriceSet, MintWindowSet, MaxMintsSet, WalletCapSet, PayoutRecipientSet and GateSet, so the sale's full initial config is in its logs.

Read functions

closed

solidity
function closed() external view returns (bool)

Whether close was called.

collection

solidity
function collection() external view returns (address)

The collection this sale mints.

defaultReferrer

solidity
function defaultReferrer() external view returns (address)

The referrer mint(quantity) pays. Fixed at initialize; may be zero.

gate

solidity
function gate() external view returns (address)

The gate consulted before each mint, or zero.

maxMints

solidity
function maxMints() external view returns (uint256)

This sale's ceiling; 0 is unlimited.

mintedBy

solidity
function mintedBy(address) external view returns (uint256)

Tokens minted to an address through this sale, counted on every mint.

mintEnd

solidity
function mintEnd() external view returns (uint64)

Window end in unix seconds; 0 is open-ended.

mintStart

solidity
function mintStart() external view returns (uint64)

Window start in unix seconds; 0 is open now.

payoutRecipient

solidity
function payoutRecipient() external view returns (address)

Where the artist share accrues. Never zero.

pendingWithdrawal

solidity
function pendingWithdrawal(address account) external view returns (uint256)

The owed balance of an address.

price

solidity
function price() external view returns (uint256)

Price per token in wei.

priceOf

solidity
function priceOf(address, uint256 quantity) external view returns (uint256)

price * quantity. Does not evaluate the gate or the window.

REFERRAL_SHARE_BPS

solidity
function REFERRAL_SHARE_BPS() external view returns (uint16)

The referral share, 500 (5%).

supportsInterface

solidity
function supportsInterface(bytes4 interfaceId) external pure returns (bool)

True for ERC-165 and the IMinter interface id.

totalMinted

solidity
function totalMinted() external view returns (uint256)

Tokens minted through this sale.

version

solidity
function version() external view returns (uint256)

2, the implementation lineage marker.

walletCap

solidity
function walletCap() external view returns (uint256)

The per-recipient cap; 0 is unlimited.

Events

Closed

solidity
event Closed()

The sale was closed for good.

GateSet

solidity
event GateSet(address indexed gate)

The gate changed, including at initialize.

Initialized

solidity
event Initialized(uint64 version)

Standard OpenZeppelin Initializable event, emitted once by initialize.

MaxMintsSet

solidity
event MaxMintsSet(uint256 maxMints)

The ceiling changed, including at initialize.

MintWindowSet

solidity
event MintWindowSet(uint64 mintStart, uint64 mintEnd)

The window changed, including at initialize.

PayoutRecipientSet

solidity
event PayoutRecipientSet(address indexed payoutRecipient)

The payout recipient changed, including at initialize.

PriceSet

solidity
event PriceSet(uint256 price)

The price changed, including at initialize.

ReferralPaid

solidity
event ReferralPaid(address indexed referrer, uint256 amount)

A nonzero referral amount accrued to a referrer.

Sold

solidity
event Sold(address indexed payer, address indexed to, address indexed referrer, uint256 quantity, uint256 paid, uint256 firstTokenId)

One per successful mint: payer, recipient, normalized referrer, quantity, exact payment and first token id. A supplied sale or collection address is recorded as the zero referrer.

WalletCapSet

solidity
event WalletCapSet(uint256 walletCap)

The wallet cap changed, including at initialize.

Withdrawn

solidity
event Withdrawn(address indexed account, address indexed to, uint256 amount)

An owed balance was paid out: the account it was owed to, where it went, and the amount.

Errors

BadMintWindow()

A window end at or before its start.

CollectionRequired()

initialize was given a zero collection.

GateRejected()

The gate's check returned false.

InvalidInitialization()

Standard OpenZeppelin Initializable error: initialize on an initialized clone or on the implementation.

MaxMintsExceeded(uint256 maxMints, uint256 attempted)

The mint would pass this sale's ceiling.

MintEnded()

At or after mintEnd.

MintNotStarted()

Before mintStart.

NotAContract(address account)

A collection or gate address without code.

NotAuthorized()

A setter from someone other than the collection's owner, or an initialize that neither authority path allows.

NothingToWithdraw()

The account has no owed balance.

NotInitializing()

Standard OpenZeppelin Initializable error, unreachable in normal use.

PayoutRecipientRequired()

A zero payout recipient.

ReceiverRejected(address to)

A contract recipient reverted or did not return the ERC721 receiver selector for an actual id about to be minted. Each id is checked before minting.

ReentrancyGuardReentrantCall()

Standard OpenZeppelin ReentrancyGuard error: a reentrant call into a mint or withdrawal.

SaleClosed()

The sale is closed.

WalletCapExceeded(uint256 cap, uint256 attempted)

The mint would pass the recipient's wallet cap.

WithdrawFailed()

The ETH transfer to the recipient failed; the balance is kept.

WrongPayment(uint256 required, uint256 sent)

msg.value is not exactly price * quantity.

ZeroAccount()

A withdrawal to the zero address.