Skip to content

Commit

Permalink
fix: update createSeries and add more requires
Browse files Browse the repository at this point in the history
Signed-off-by: Campion Fellin <[email protected]>
  • Loading branch information
campionfellin committed Feb 12, 2024
1 parent 95914b0 commit 1909ba6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IManifoldERC721Edition {
/**
* @dev Create a new series. Returns the series id.
*/
function createSeries(address creatorCore, uint256 maxSupply, string calldata prefix, uint256 instanceId, address[] memory recipients) external returns(uint256);
function createSeries(address creatorCore, uint256 maxSupply, string calldata prefix, uint256 instanceId, address[] memory recipients, uint16 count) external returns(uint256);

/**
* @dev Set the token uri prefix
Expand Down
12 changes: 9 additions & 3 deletions packages/manifold/contracts/edition/ManifoldERC721Edition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ contract ManifoldERC721Edition is CreatorExtension, ICreatorExtensionTokenURI, I
/**
* @dev See {IManifoldERC721Edition-createSeries}.
*/
function createSeries(address creatorCore, uint256 maxSupply_, string calldata prefix, uint256 instanceId, address[] memory recipients) external override creatorAdminRequired(creatorCore) returns(uint256) {
function createSeries(address creatorCore, uint256 maxSupply_, string calldata prefix, uint256 instanceId, address[] memory recipients, uint16 count) external override creatorAdminRequired(creatorCore) returns(uint256) {
if (instanceId == 0 || maxSupply_ == 0 || _maxSupply[creatorCore][instanceId] != 0) revert("Invalid instance");
_maxSupply[creatorCore][instanceId] = maxSupply_;
_tokenPrefix[creatorCore][instanceId] = prefix;
_creatorInstanceIds[creatorCore].push(instanceId);
emit SeriesCreated(msg.sender, creatorCore, instanceId, maxSupply_);

// Mint to recipients
if (recipients.length > 0) {
// If non-zero count, then mint this count all to the 1 recipient
if (count != 0) {
if (recipients.length != 1) revert("Must have 1 recipient");
if (_totalSupply[creatorCore][instanceId]+count > _maxSupply[creatorCore][instanceId]) revert ("Too many requested");
uint256[] memory tokenIds = IERC721CreatorCore(creatorCore).mintExtensionBatch(recipients[0], count);
_updateIndexRanges(creatorCore, instanceId, tokenIds[0], count);
} else if (recipients.length > 0) {
if (_totalSupply[creatorCore][instanceId]+recipients.length > _maxSupply[creatorCore][instanceId]) revert("Too many requested");
_mintTokens(creatorCore, recipients, instanceId);
}

Expand Down
35 changes: 22 additions & 13 deletions packages/manifold/test/edition/ManifoldERC721Edition.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract ManifoldERC721EditionTest is Test {
vm.startPrank(operator);

vm.expectRevert("Must be owner or admin of creator contract");
example.createSeries(address(creatorCore1), 1, "", 1, new address[](0));
example.createSeries(address(creatorCore1), 1, "", 1, new address[](0), 0);
vm.expectRevert("Must be owner or admin of creator contract");
example.setTokenURIPrefix(address(creatorCore1), 1, "");
vm.stopPrank();
Expand All @@ -67,7 +67,7 @@ contract ManifoldERC721EditionTest is Test {
vm.expectRevert("Too many requested");
example.mint(address(creatorCore1), 1, operator, 1);

example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0));
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0), 0);

example.mint(address(creatorCore1), 1, operator, 2);

Expand All @@ -88,10 +88,10 @@ contract ManifoldERC721EditionTest is Test {

function testEditionIndex() public {
vm.startPrank(owner);
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0));
example.createSeries(address(creatorCore1), 20, "http://creator1series2/", 2, new address[](0));
example.createSeries(address(creatorCore2), 200, "http://creator1series2/", 3, new address[](0));
example.createSeries(address(creatorCore3), 300, "http://creator1series2/", 4, new address[](0));
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0), 0);
example.createSeries(address(creatorCore1), 20, "http://creator1series2/", 2, new address[](0), 0);
example.createSeries(address(creatorCore2), 200, "http://creator1series2/", 3, new address[](0), 0);
example.createSeries(address(creatorCore3), 300, "http://creator1series2/", 4, new address[](0), 0);

assertEq(10, example.maxSupply(address(creatorCore1), 1));
assertEq(20, example.maxSupply(address(creatorCore1), 2));
Expand Down Expand Up @@ -145,7 +145,7 @@ contract ManifoldERC721EditionTest is Test {

function testMintingNone() public {
vm.startPrank(owner);
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0));
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0), 0);

vm.expectRevert("Invalid amount requested");
example.mint(address(creatorCore1), 1, operator, 0);
Expand All @@ -159,7 +159,7 @@ contract ManifoldERC721EditionTest is Test {

function testMintingTooMany() public {
vm.startPrank(owner);
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0));
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, new address[](0), 0);

vm.expectRevert("Too many requested");
example.mint(address(creatorCore1), 1, operator, 11);
Expand All @@ -178,15 +178,15 @@ contract ManifoldERC721EditionTest is Test {
vm.startPrank(owner);

vm.expectRevert("Invalid instance");
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 0, new address[](0));
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 0, new address[](0), 0);

vm.expectRevert("Invalid instance");
example.createSeries(address(creatorCore1), 0, "hi", 1, new address[](0));
example.createSeries(address(creatorCore1), 0, "hi", 1, new address[](0), 0);

example.createSeries(address(creatorCore1), 10, "hi", 1, new address[](0));
example.createSeries(address(creatorCore1), 10, "hi", 1, new address[](0), 0);

vm.expectRevert("Invalid instance");
example.createSeries(address(creatorCore1), 10, "hi", 1, new address[](0));
example.createSeries(address(creatorCore1), 10, "hi", 1, new address[](0), 0);

vm.stopPrank();
}
Expand All @@ -198,7 +198,16 @@ contract ManifoldERC721EditionTest is Test {
address[] memory recipients = new address[](1);
recipients[0] = operator;

example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, recipients);
example.createSeries(address(creatorCore1), 10, "http://creator1series1/", 1, recipients, 0);

vm.stopPrank();
}

function testMaxSupplyNonInitializedMint() public {
vm.startPrank(owner);

vm.expectRevert("Invalid instanceId");
example.maxSupply(address(creatorCore1), 69);

vm.stopPrank();
}
Expand Down

0 comments on commit 1909ba6

Please sign in to comment.