// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/BitMaps.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
* Largely inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
*/
library BitMaps {
struct BitMap {
mapping(uint256 => uint256) _data;
}
/**
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
/**
* @dev Sets the bit at `index` to the boolean `value`.
*/
function setTo(BitMap storage bitmap, uint256 index, bool value) internal {
if (value) {
set(bitmap, index);
} else {
unset(bitmap, index);
}
}
/**
* @dev Sets the bit at `index`.
*/
function set(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] |= mask;
}
/**
* @dev Unsets the bit at `index`.
*/
function unset(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] &= ~mask;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.4;
abstract contract EIP712Base {
/// -----------------------------------------------------------------------
/// Structs
/// -----------------------------------------------------------------------
/// -----------------------------------------------------------------------
/// Immutable parameters
/// -----------------------------------------------------------------------
/// @notice The chain ID used by EIP-712
uint256 internal immutable INITIAL_CHAIN_ID;
/// @notice The domain separator used by EIP-712
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
/// -----------------------------------------------------------------------
/// Constructor
/// -----------------------------------------------------------------------
constructor() {
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = _computeDomainSeparator();
}
/// -----------------------------------------------------------------------
/// Packet verification
/// -----------------------------------------------------------------------
function _verifySig(bytes memory data, uint8 v, bytes32 r, bytes32 s) internal virtual returns (address) {
// verify signature
address recoveredAddress =
ecrecover(keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), keccak256(data))), v, r, s);
return recoveredAddress;
}
/// -----------------------------------------------------------------------
/// EIP-712 compliance
/// -----------------------------------------------------------------------
/// @notice The domain separator used by EIP-712
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : _computeDomainSeparator();
}
/// @notice Computes the domain separator used by EIP-712
function _computeDomainSeparator() internal view virtual returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256("SealedArtMarket"),
keccak256("1"),
block.chainid,
address(this)
)
);
}
}
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.4;
import "../shared/EIP712Base.sol";
abstract contract EIP712Editions is EIP712Base {
struct MintOffer {
uint8 v;
bytes32 r;
bytes32 s;
address nftContract;
string uri;
uint256 cost;
uint256 startDate;
uint256 endDate;
uint256 maxToMint;
uint256 maxPerWallet;
address paymentReceiver;
bytes32 merkleRoot;
uint256 deadline;
uint256 counter;
uint256 nonce;
}
function _verifySellMintOffer(MintOffer calldata packet) internal virtual returns (address) {
return _verifySig(
abi.encode(
keccak256(
"SellOffer(address nftContract,string uri,uint256 cost,uint256 startDate,uint256 endDate,uint256 maxToMint,uint256 maxPerWallet,address paymentReceiver,bytes32 merkleRoot,uint256 deadline,uint256 counter,uint256 nonce)"
),
packet.nftContract,
keccak256(abi.encodePacked(packet.uri)),
packet.cost,
packet.startDate,
packet.endDate,
packet.maxToMint,
packet.maxPerWallet,
packet.paymentReceiver,
packet.merkleRoot,
packet.deadline,
packet.counter,
packet.nonce
),
packet.v,
packet.r,
packet.s
);
}
struct MintOfferAttestation {
uint8 v;
bytes32 r;
bytes32 s;
uint256 deadline;
bytes32 offerHash;
}
function _verifyAttestation(MintOfferAttestation calldata packet) internal virtual returns (address) {
return _verifySig(
abi.encode(
keccak256(
"MintOfferAttestation(uint256 deadline,bytes32 offerHash)"
),
packet.deadline,
packet.offerHash
),
packet.v,
packet.r,
packet.s
);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.2) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates merkle trees that are safe
* against this attack out of the box.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*
* _Available since v4.7._
*/
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*
* _Available since v4.7._
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* _Available since v4.7._
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
pragma solidity ^0.8.4;
import {BitMaps} from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
abstract contract Nonces {
mapping(address => uint256) public accountCounter;
event CounterIncreased(address account, uint256 newCounter);
function increaseCounter(uint256 newCounter) external {
require(newCounter > accountCounter[msg.sender], "too low");
accountCounter[msg.sender] = newCounter;
emit CounterIncreased(msg.sender, newCounter);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
pragma solidity ^0.8.7;
import "./EIP712Editions.sol";
import "../shared/Nonces.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
interface UserCollection {
function mintExtensionNew(address[] calldata to, uint256[] calldata amounts, string[] calldata uris) external returns (uint256[] memory);
function mintExtensionExisting(address[] calldata to, uint256[] calldata tokenIds, uint256[] calldata amounts) external;
function isAdmin(address admin) external view returns (bool);
}
interface IDelegationRegistry {
function checkDelegateForContract(address to, address from, address contract_, bytes32 rights) external view returns (bool valid);
}
contract SealedEditions is EIP712Editions, Ownable, Nonces {
mapping(bytes32 => uint256) public editionsMinted;
mapping(address => mapping(uint256 => uint256)) public nonceToNftId;
mapping(address => mapping(uint256 => mapping(address => uint256))) public nftsMintedByAddress;
address public sequencer; // Invariant: always different than address(0)
uint256 internal constant MIN_WITHOUT_FEE = 0.9e18; // 90%
uint256 public feeMultiplier = 0.98e18; // Invariant: between 90% and 100%
constructor(address _sequencer) {
require(_sequencer != address(0), "0x0 sequencer not allowed");
sequencer = _sequencer;
}
event AdminConfigChanged(address sequencer, uint feeMultiplier);
function changeAdminConfig(address _sequencer, uint _feeMultiplier) external onlyOwner {
require(_sequencer != address(0), "0x0 sequencer not allowed");
sequencer = _sequencer;
require(_feeMultiplier >= MIN_WITHOUT_FEE && _feeMultiplier <= 1e18, ">MAX_PROTOCOL_FEE");
feeMultiplier = _feeMultiplier;
emit AdminConfigChanged(_sequencer, _feeMultiplier);
}
event FeesWithdrawn(address receiver);
function withdrawFees(address payable receiver) external onlyOwner {
_transferETH(receiver, address(this).balance);
emit FeesWithdrawn(receiver);
}
function _transferETH(address payable receiver, uint256 amount) internal {
(bool success,) = receiver.call{value: amount}("");
require(success, "eth send"); // if it fails to send then reverting is ok since its receiver thats causing it to fail
}
function _distributePrimarySale(uint256 cost, uint256 amount, address payable paymentReceiver) internal {
if(cost > 0){
uint total = amount * cost;
require(msg.value == total, "msg.value");
uint256 amountWithoutFee = (total * feeMultiplier) / 1e18;
_transferETH(paymentReceiver, amountWithoutFee);
}
}
function calculateEditionHash(address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot) pure public returns (bytes32) {
return keccak256(abi.encode(nftContract, nftId, cost, startDate, endDate, maxToMint, maxPerWallet, paymentReceiver, merkleRoot));
}
modifier nftAdmin(address nftContract) {
require(UserCollection(nftContract).isAdmin(msg.sender), "Wallet is not an administrator for contract");
_;
}
/*
We could add a function to reject a specific signature onchain by setting:
nonceToNftId[msg.sender][nonce] = 1;
However this would create a potential attack where:
1. Seller creates a mint for a bad NFT with nftId = 0
2. Seller lists another more appealing NFT through a signature
3. User sends a tx calling mintNew()
4. Seller finds the tx in mempool and frontruns it by calling cancelOffer() to set nonceToNftId to 1
5. User's tx is executed and mints nft with nftId = 0 instead of the new NFT
There's very little incentive for this attack, because seller is already selling an NFT and by doing this attack they'd be ruining their own reputation,
however it's still bad, so for that reason we didn't add this function.
Instead, on-chain rejections will be handled with increaseCounter(), but we expect most rejections to be handled off-chain through the sequencer.
*/
event MintCreated(address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot, address seller);
event Mint(address nftContract, uint tokenId, uint amount, uint price, address buyer);
function verifyNewMint(MintOffer calldata offer, MintOfferAttestation calldata attestation, uint amount, address seller, uint realCost) internal returns (uint nftId){
require(amount > 0, "amount != 0");
require(attestation.deadline > block.timestamp && offer.deadline > block.timestamp && offer.endDate > block.timestamp, ">deadline");
nonceToNftId[seller][offer.nonce] = type(uint).max; // temporary value to avoid reentrancy
require(seller != address(0) && UserCollection(offer.nftContract).isAdmin(seller), "!auth");
require(offer.counter > accountCounter[seller], "<counter");
require(attestation.offerHash == keccak256(abi.encode(
msg.sender,
seller,
offer.nftContract,
offer.uri,
offer.cost,
offer.startDate,
offer.endDate,
offer.maxToMint,
offer.maxPerWallet,
offer.paymentReceiver,
offer.merkleRoot,
offer.deadline,
offer.counter,
offer.nonce
)), "!offerHash");
require(_verifyAttestation(attestation) == sequencer, "!sequencer"); // No need to check against address(0) because sequencer will never be 0x0
address[] memory to = new address[](1);
to[0] = msg.sender;
uint[] memory amounts = new uint[](1);
amounts[0] = amount;
string[] memory uris = new string[](1);
uris[0] = offer.uri;
uint[] memory nftIds = UserCollection(offer.nftContract).mintExtensionNew(to, amounts, uris); // if its an ipfs uri, separating prefix doesnt improve gas
nftId = nftIds[0];
nonceToNftId[seller][offer.nonce] = (nftId << 1) | 1; // assumes nftId will always be < 2**254
bytes32 editionHash = calculateEditionHash(offer.nftContract, nftId, offer.cost, offer.startDate, offer.endDate, offer.maxToMint, offer.maxPerWallet, offer.paymentReceiver, offer.merkleRoot);
editionsMinted[editionHash] += amount;
require(editionsMinted[editionHash] <= offer.maxToMint, ">maxToMint");
_distributePrimarySale(realCost, amount, payable(offer.paymentReceiver));
emit MintCreated(offer.nftContract, nftId, offer.cost, offer.startDate, offer.endDate, offer.maxToMint, offer.maxPerWallet, offer.paymentReceiver, offer.merkleRoot, seller);
emit Mint(offer.nftContract, nftId, amount, realCost, msg.sender);
}
function checkMaxPerWallet(address nftContract, uint nftId, uint amount, uint maxPerWallet) internal {
if(maxPerWallet != 0){
uint newMinted = nftsMintedByAddress[nftContract][nftId][msg.sender] + amount;
nftsMintedByAddress[nftContract][nftId][msg.sender] = newMinted;
require(newMinted <= maxPerWallet, ">maxPerWallet");
}
}
// IMPORTANT: All modifications to the same offer should reuse the same nonce
function mintNew(MintOffer calldata offer, MintOfferAttestation calldata attestation, uint amount) external payable {
require(offer.startDate < block.timestamp, "startDate");
address seller = _verifySellMintOffer(offer);
uint nftId = nonceToNftId[seller][offer.nonce];
if(nftId != 0){
mint(amount, offer.nftContract, nftId >> 1, offer.cost, offer.startDate, offer.endDate, offer.maxToMint, offer.maxPerWallet, offer.paymentReceiver, offer.merkleRoot);
return;
}
uint mintedNftId = verifyNewMint(offer, attestation, amount, seller, offer.cost);
checkMaxPerWallet(offer.nftContract, mintedNftId, amount, offer.maxPerWallet);
}
function mintNewWithMerkle(MintOffer calldata offer, MintOfferAttestation calldata attestation, uint amount,
bytes32[] calldata merkleProof, MerkleLeaf calldata merkleLeaf) external payable {
require(merkleLeaf.startDate < block.timestamp, "startDate");
address seller = _verifySellMintOffer(offer);
uint nftId = nonceToNftId[seller][offer.nonce];
if(nftId != 0){
mintWithMerkle(amount, offer.nftContract, nftId >> 1, offer.cost, offer.startDate, offer.endDate, offer.maxToMint, offer.maxPerWallet, offer.paymentReceiver, offer.merkleRoot,
merkleProof, merkleLeaf);
return;
}
uint mintedNftId = verifyNewMint(offer, attestation, amount, seller, merkleLeaf.cost);
checkMerkle(offer.nftContract, mintedNftId, amount, offer.merkleRoot, merkleProof, merkleLeaf);
}
function editMint(address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot,
uint newCost, uint newStartDate, uint newEndDate, uint newMaxToMint, uint newMaxPerWallet, address newPaymentReceiver, bytes32 newMerkleRoot) external nftAdmin(nftContract) {
bytes32 oldEditionHash = calculateEditionHash(nftContract, nftId, cost, startDate, endDate, maxToMint, maxPerWallet, paymentReceiver, merkleRoot);
uint minted = editionsMinted[oldEditionHash];
require(minted > 0, "0 minted");
editionsMinted[oldEditionHash] = type(uint256).max;
// To disable mint just set newMaxToMint = 0
bytes32 editionHash = calculateEditionHash(nftContract, nftId, newCost, newStartDate, newEndDate, newMaxToMint, newMaxPerWallet, newPaymentReceiver, newMerkleRoot);
editionsMinted[editionHash] = minted;
emit MintCreated(nftContract, nftId, newCost, newStartDate, newEndDate, newMaxToMint, newMaxPerWallet, newPaymentReceiver, newMerkleRoot, msg.sender);
}
struct MerkleLeaf {
address mintFor;
uint startDate;
uint cost;
uint maxMint;
}
function checkMerkle(address nftContract, uint nftId, uint amount,
bytes32 merkleRoot, bytes32[] calldata merkleProof, MerkleLeaf calldata merkleLeaf) internal {
if (merkleLeaf.mintFor != msg.sender) {
IDelegationRegistry dr = IDelegationRegistry(0x00000000000000447e69651d841bD8D104Bed493);
require(dr.checkDelegateForContract(msg.sender, merkleLeaf.mintFor, address(this), ""), "Invalid delegate");
}
bytes32 leaf = keccak256(abi.encode(merkleLeaf));
require(MerkleProof.verifyCalldata(merkleProof, merkleRoot, leaf), "bad merkle proof");
uint minted = nftsMintedByAddress[nftContract][nftId][merkleLeaf.mintFor];
minted += amount;
nftsMintedByAddress[nftContract][nftId][merkleLeaf.mintFor] = minted;
require(minted <= merkleLeaf.maxMint, ">maxMint");
}
function mintWithMerkle(uint amount, address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot,
bytes32[] calldata merkleProof, MerkleLeaf calldata merkleLeaf) payable public {
bytes32 editionHash = calculateEditionHash(nftContract, nftId, cost, startDate, endDate, maxToMint, maxPerWallet, paymentReceiver, merkleRoot);
mintExisting(editionHash, amount, nftContract, nftId, merkleLeaf.cost, merkleLeaf.startDate, endDate, maxToMint, paymentReceiver);
checkMerkle(nftContract, nftId, amount, merkleRoot, merkleProof, merkleLeaf);
}
function mintExisting(bytes32 editionHash, uint amount, address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, address paymentReceiver) internal {
uint minted = editionsMinted[editionHash];
uint newMinted = minted + amount;
require(newMinted <= maxToMint && minted > 0, ">maxToMint"); // not doing require() after write to save gas for ppl that go over limit
require(block.timestamp > startDate, "<startDate");
require(block.timestamp <= endDate, ">endDate");
editionsMinted[editionHash] = newMinted;
_distributePrimarySale(cost, amount, payable(paymentReceiver));
address[] memory to = new address[](1);
to[0] = msg.sender;
uint[] memory tokenIds = new uint[](1);
tokenIds[0] = nftId;
uint[] memory amounts = new uint[](1);
amounts[0] = amount;
UserCollection(nftContract).mintExtensionExisting(to, tokenIds, amounts);
emit Mint(nftContract, nftId, amount, cost, msg.sender);
}
function mint(uint amount, address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot) payable public {
bytes32 editionHash = calculateEditionHash(nftContract, nftId, cost, startDate, endDate, maxToMint, maxPerWallet, paymentReceiver, merkleRoot);
mintExisting(editionHash, amount, nftContract, nftId, cost, startDate, endDate, maxToMint, paymentReceiver);
checkMaxPerWallet(nftContract, nftId, amount, maxPerWallet);
}
event Airdropped(address nftContract, uint nftId, address paymentReceiver, address[] recipients, uint256[] amounts);
function airdrop(address nftContract, uint nftId, uint cost, uint startDate, uint endDate, uint maxToMint, uint maxPerWallet, address paymentReceiver, bytes32 merkleRoot,
address[] calldata recipients, uint256[] calldata amounts) external nftAdmin(nftContract) {
require(recipients.length == amounts.length, "Unequal number of recipients and amounts provided");
uint256 totalAmount;
for (uint256 i; i < amounts.length;) {
totalAmount += amounts[i];
unchecked{ ++i; }
}
bytes32 editionHash = calculateEditionHash(nftContract, nftId, cost, startDate, endDate, maxToMint, maxPerWallet, paymentReceiver, merkleRoot);
uint minted = editionsMinted[editionHash];
uint newMinted = minted + totalAmount;
require(newMinted <= maxToMint && minted > 0, ">maxToMint");
editionsMinted[editionHash] = newMinted;
uint256[] memory tokenIds = new uint256[](1);
tokenIds[0] = nftId;
UserCollection(nftContract).mintExtensionExisting(recipients, tokenIds, amounts);
emit Airdropped(nftContract, nftId, msg.sender, recipients, amounts);
}
}
{
"compilationTarget": {
"contracts/editions/SealedEditions.sol": "SealedEditions"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 4294967
},
"remappings": [],
"viaIR": true
}
[{"inputs":[{"internalType":"address","name":"_sequencer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sequencer","type":"address"},{"indexed":false,"internalType":"uint256","name":"feeMultiplier","type":"uint256"}],"name":"AdminConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"nftContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"},{"indexed":false,"internalType":"address","name":"paymentReceiver","type":"address"},{"indexed":false,"internalType":"address[]","name":"recipients","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"Airdropped","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"newCounter","type":"uint256"}],"name":"CounterIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"nftContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"nftContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cost","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startDate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endDate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxToMint","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"indexed":false,"internalType":"address","name":"paymentReceiver","type":"address"},{"indexed":false,"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"address","name":"seller","type":"address"}],"name":"MintCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accountCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"address[]","name":"recipients","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"airdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"calculateEditionHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_sequencer","type":"address"},{"internalType":"uint256","name":"_feeMultiplier","type":"uint256"}],"name":"changeAdminConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"uint256","name":"newCost","type":"uint256"},{"internalType":"uint256","name":"newStartDate","type":"uint256"},{"internalType":"uint256","name":"newEndDate","type":"uint256"},{"internalType":"uint256","name":"newMaxToMint","type":"uint256"},{"internalType":"uint256","name":"newMaxPerWallet","type":"uint256"},{"internalType":"address","name":"newPaymentReceiver","type":"address"},{"internalType":"bytes32","name":"newMerkleRoot","type":"bytes32"}],"name":"editMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"editionsMinted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newCounter","type":"uint256"}],"name":"increaseCounter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"counter","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct EIP712Editions.MintOffer","name":"offer","type":"tuple"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes32","name":"offerHash","type":"bytes32"}],"internalType":"struct EIP712Editions.MintOfferAttestation","name":"attestation","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mintNew","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"counter","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct EIP712Editions.MintOffer","name":"offer","type":"tuple"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes32","name":"offerHash","type":"bytes32"}],"internalType":"struct EIP712Editions.MintOfferAttestation","name":"attestation","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"components":[{"internalType":"address","name":"mintFor","type":"address"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"maxMint","type":"uint256"}],"internalType":"struct SealedEditions.MerkleLeaf","name":"merkleLeaf","type":"tuple"}],"name":"mintNewWithMerkle","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"uint256","name":"maxToMint","type":"uint256"},{"internalType":"uint256","name":"maxPerWallet","type":"uint256"},{"internalType":"address","name":"paymentReceiver","type":"address"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"components":[{"internalType":"address","name":"mintFor","type":"address"},{"internalType":"uint256","name":"startDate","type":"uint256"},{"internalType":"uint256","name":"cost","type":"uint256"},{"internalType":"uint256","name":"maxMint","type":"uint256"}],"internalType":"struct SealedEditions.MerkleLeaf","name":"merkleLeaf","type":"tuple"}],"name":"mintWithMerkle","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"nftsMintedByAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"nonceToNftId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sequencer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"receiver","type":"address"}],"name":"withdrawFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]