Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set royalties percentage on mint creation #21

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/MintERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,39 @@ contract MintERC1155 is ERC1155Upgradeable, OwnableUpgradeable, ERC2981Upgradeab
string calldata name_,
string calldata imageURI_,
string calldata description_,
Edition[] calldata editions_
Edition[] calldata editions_,
uint16 royaltyAmountBps
)
external
initializer
{
uint256 totalPercentChance = 0;
for (uint256 i = 0; i < editions_.length; i++) {
editions.push();
editions[i].name = editions_[i].name;
editions[i].imageURI = editions_[i].imageURI;
totalPercentChance += editions[i].percentChance = editions_[i].percentChance;

if (editions_[i].percentChance == 0) {
revert MintERC1155_PercentChance0();
}
{
uint256 totalPercentChance = 0;
for (uint256 i = 0; i < editions_.length; i++) {
editions.push();
editions[i].name = editions_[i].name;
editions[i].imageURI = editions_[i].imageURI;
totalPercentChance += editions[i].percentChance = editions_[i].percentChance;

if (editions_[i].percentChance == 0) {
revert MintERC1155_PercentChance0();
}

for (uint256 j = 0; j < editions_[i].attributes.length; j++) {
editions[i].attributes.push(editions_[i].attributes[j]);
for (uint256 j = 0; j < editions_[i].attributes.length; j++) {
editions[i].attributes.push(editions_[i].attributes[j]);
}
}
}

if (totalPercentChance != 100) {
revert MintERC1155_TotalPercentChanceNot100();
if (totalPercentChance != 100) {
revert MintERC1155_TotalPercentChanceNot100();
}
}

__Ownable_init(owner_);
name = name_;
imageURI = imageURI_;
description = description_;
_setDefaultRoyalty(owner_, 150);
__Ownable_init(owner_);
_setDefaultRoyalty(owner_, royaltyAmountBps);
}

function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) external {
Expand Down
3 changes: 2 additions & 1 deletion src/NFTMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract NFTMint is Ownable {
struct MintArgs {
uint96 pricePerMint;
uint96 feePerMint;
uint16 royaltyAmountBps;
address payable owner;
address payable feeRecipient;
uint40 mintExpiration;
Expand Down Expand Up @@ -82,7 +83,7 @@ contract NFTMint is Ownable {
MINT_NFT_LOGIC, keccak256(abi.encodePacked(block.chainid, msg.sender, block.timestamp))
)
);
newMint.initialize(args.owner, args.name, args.imageURI, args.description, args.editions);
newMint.initialize(args.owner, args.name, args.imageURI, args.description, args.editions, args.royaltyAmountBps);

MintInfo storage mintInfo = mints[newMint];
mintInfo.owner = args.owner;
Expand Down
6 changes: 3 additions & 3 deletions test/MintERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract MintERC1155Test is TestBase, LintJSON {
});

token = MintERC1155(Clones.clone(address(impl)));
token.initialize(address(this), "My Token Name", "image here", "This is a token", editions);
token.initialize(address(this), "My Token Name", "image here", "This is a token", editions, 150);

assertEq(token.name(), "My Token Name");
assertEq(token.imageURI(), "image here");
Expand Down Expand Up @@ -68,7 +68,7 @@ contract MintERC1155Test is TestBase, LintJSON {
MintERC1155 newToken = MintERC1155(Clones.clone(address(impl)));

vm.expectRevert(MintERC1155.MintERC1155_PercentChance0.selector);
newToken.initialize(address(this), "", "", "", editions);
newToken.initialize(address(this), "", "", "", editions, 150);
}

function test_initialize_totalPercentChanceNot100() external {
Expand All @@ -84,7 +84,7 @@ contract MintERC1155Test is TestBase, LintJSON {
MintERC1155 newToken = MintERC1155(Clones.clone(address(impl)));

vm.expectRevert(MintERC1155.MintERC1155_TotalPercentChanceNot100.selector);
newToken.initialize(address(this), "", "", "", editions);
newToken.initialize(address(this), "", "", "", editions, 150);
}

function test_mintBatch_unauthorized() external {
Expand Down
3 changes: 2 additions & 1 deletion test/NFTMint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ contract NFTMintTest is TestBase {
feeRecipient: payable(address(this)),
name: "My Token Name",
imageURI: "image here",
description: "This is a description"
description: "This is a description",
royaltyAmountBps: 150
});

return nftMint.createMint(mintArgs);
Expand Down
Loading