Skip to content

Commit

Permalink
Add FixedPricePublicSaleMinter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Jul 21, 2022
1 parent 4d770b6 commit c9a21d2
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 187 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
path = lib/ERC721A-Upgradeable
url = https://github.com/chiru-labs/ERC721A-Upgradeable
branch = main
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
40 changes: 0 additions & 40 deletions contracts/SoundEdition/ISoundNftV1.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/SoundEdition/SoundEditionV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract SoundEditionV1 is ERC721AUpgradeable, IERC2981Upgradeable, OwnableUpgra
__ERC721A_init(_name, _symbol);
__Ownable_init();
__AccessControl_init();

// Set ownership to owner
transferOwnership(_owner);

Expand Down
65 changes: 0 additions & 65 deletions contracts/SoundEdition/SoundNftV1.sol

This file was deleted.

54 changes: 0 additions & 54 deletions contracts/modules/Minting/EditionMintControllers.sol

This file was deleted.

60 changes: 60 additions & 0 deletions contracts/modules/Minting/EditionMinter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.15;

contract EditionMinter {
error MintControllerUnauthorized();

error MintControllerSetToZeroAddress();

error MintNotFound();

error MintAlreadyExists();

event MintControllerUpdated(address indexed edition, address indexed controller);

mapping(address => address) private _controllers;

modifier onlyEditionMintController(address edition) virtual {
address controller = _controllers[edition];
if (controller == address(0)) revert MintNotFound();
if (msg.sender != controller) revert MintControllerUnauthorized();
_;
}

function _createEditionMint(address edition) internal {
_createEditionMint(edition, msg.sender);
}

function _createEditionMint(address edition, address controller) internal {
if (controller == address(0)) revert MintControllerSetToZeroAddress();
if (_controllers[edition] != address(0)) revert MintAlreadyExists();

_controllers[edition] = controller;

emit MintControllerUpdated(edition, controller);
}

function _deleteEditionMint(address edition) internal {
address controller = _controllers[edition];
if (controller == address(0)) revert MintNotFound();
if (msg.sender != controller) revert MintControllerUnauthorized();
delete _controllers[edition];
emit MintControllerUpdated(edition, address(0));
}

function editionMintController(address edition) public view returns (address) {
return _controllers[edition];
}

function setEditionMintController(address edition, address controller)
public
virtual
onlyEditionMintController(edition)
{
if (controller == address(0)) revert MintControllerSetToZeroAddress();

_controllers[edition] = controller;
emit MintControllerUpdated(edition, controller);
}
}
56 changes: 43 additions & 13 deletions contracts/modules/Minting/FixedPricePermissionedSaleMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

pragma solidity ^0.8.15;

import "./EditionMintControllers.sol";
import "./EditionMinter.sol";
import "../../SoundEdition/ISoundEditionV1.sol";
import "solady/utils/ECDSA.sol";

contract FixedPricePermissionedMinter is EditionMintControllers {
contract FixedPricePermissionedMinter is EditionMinter {
using ECDSA for bytes32;

error MintWithWrongEtherValue();

error MintOutOfStock();

error MintWithInvalidSignature();

// prettier-ignore
event FixedPricePermissionedMintCreated(
address indexed edition,
uint256 price,
address signer,
uint32 maxMinted
);

struct EditionMintData {
// The price at which each token will be sold, in ETH.
Expand All @@ -19,31 +35,45 @@ contract FixedPricePermissionedMinter is EditionMintControllers {
}

mapping(address => EditionMintData) public editionMintData;

function createEditionMint(
address edition,
uint256 price,
address signer,
uint32 maxMinted
) public {
_initEditionMintController(edition);
_createEditionMint(edition);
EditionMintData storage data = editionMintData[edition];
data.price = price;
data.signer = signer;
data.maxMinted = maxMinted;
// prettier-ignore
emit FixedPricePermissionedMintCreated(
edition,
price,
signer,
maxMinted
);
}

function deleteMintee(address edition) public onlyEditionMintController(edition) {
_deleteEditionMintController();
function deleteEditionMint(address edition) public {
_deleteEditionMint(edition);
delete editionMintData[edition];
}

function mint(address edition, uint256 quantity) public payable {
// EditionMintData storage data = editionMintData[edition];
// require(data.startTime <= block.timestamp, "Mint not started.");
// require(data.endTime > block.timestamp, "Mint has ended.");
// require(data.price * quantity == msg.value, "Wrong ether value.");
// require((data.totalMinted += quantity) <= data.maxMinted, "No more mints.");
ISoundEditionV1(edition).mint{value: msg.value}(edition, quantity);
function mint(
address edition,
uint32 quantity,
bytes calldata signature
) public payable {
EditionMintData storage data = editionMintData[edition];
if ((data.totalMinted += quantity) > data.maxMinted) revert MintOutOfStock();
if (data.price * quantity != msg.value) revert MintWithWrongEtherValue();

bytes32 hash = keccak256(abi.encode(msg.sender, edition));
hash = hash.toEthSignedMessageHash();
if (hash.recover(signature) != data.signer) revert MintWithInvalidSignature();

ISoundEditionV1(edition).mint{ value: msg.value }(edition, quantity);
}
}
Loading

0 comments on commit c9a21d2

Please sign in to comment.