Skip to content

Commit

Permalink
Fix ERC20 Minter ETH Fee To Be Per Mint (#394)
Browse files Browse the repository at this point in the history
* fix: apply eth fee per mint

* feat: add invalidETHValue error
  • Loading branch information
IsabellaSmallcombe authored May 16, 2024
1 parent 2475a4c commit d9b8a71
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/1155-contracts/src/interfaces/IERC20Minter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ interface IERC20Minter is IMinterPremintSetup {
/// @notice Failed to send ETH reward
error FailedToSendEthReward();

/// @notice Invalid value for ETH reward
/// @param expectedValue The expected value
/// @param actualValue The actual value
error InvalidETHValue(uint256 expectedValue, uint256 actualValue);

/// @notice Invalid value
error InvalidValue();

Expand Down
4 changes: 2 additions & 2 deletions packages/1155-contracts/src/minters/erc20/ERC20Minter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ contract ERC20Minter is ReentrancyGuard, IERC20Minter, SaleStrategy, LimitedMint
address mintReferral,
string calldata comment
) external payable nonReentrant {
if (msg.value != minterConfig.ethReward) {
revert InvalidValue();
if (msg.value != minterConfig.ethReward * quantity) {
revert InvalidETHValue(minterConfig.ethReward * quantity, msg.value);
}

SalesConfig storage config = salesConfigs[tokenAddress][tokenId];
Expand Down
62 changes: 52 additions & 10 deletions packages/1155-contracts/test/minters/erc20/ERC20Minter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,19 @@ contract ERC20MinterTest is Test {
vm.prank(tokenRecipient);
currency.approve(address(minter), totalValue);

vm.deal(tokenRecipient, ethReward);
vm.deal(tokenRecipient, ethReward * quantity);

vm.startPrank(tokenRecipient);
minter.mint{value: ethReward}(tokenRecipient, quantity, address(target), newTokenId, pricePerToken * quantity, address(currency), mintReferral, "");
minter.mint{value: ethReward * quantity}(
tokenRecipient,
quantity,
address(target),
newTokenId,
pricePerToken * quantity,
address(currency),
mintReferral,
""
);
vm.stopPrank();

assertEq(target.balanceOf(tokenRecipient, newTokenId), quantity);
Expand All @@ -297,15 +306,15 @@ contract ERC20MinterTest is Test {
currency.balanceOf(createReferral),
totalValue
);
assertEq(address(zora).balance, ethReward);
assertEq(address(zora).balance, ethReward * quantity);
}

function test_ERC20MinterSaleWithRewardsAddresses() external {
uint96 pricePerToken = 100000000000000000; // 0.1 when converted from wei
uint256 quantity = 5;
uint256 newTokenId = setUpTargetSale(pricePerToken, fundsRecipient, address(currency), quantity, minter);

vm.deal(tokenRecipient, ethReward);
vm.deal(tokenRecipient, ethReward * quantity);
vm.prank(admin);
uint256 totalValue = pricePerToken * quantity;
currency.mint(address(tokenRecipient), totalValue);
Expand All @@ -314,7 +323,16 @@ contract ERC20MinterTest is Test {
currency.approve(address(minter), totalValue);

vm.startPrank(tokenRecipient);
minter.mint{value: ethReward}(tokenRecipient, quantity, address(target), newTokenId, pricePerToken * quantity, address(currency), mintReferral, "");
minter.mint{value: ethReward * quantity}(
tokenRecipient,
quantity,
address(target),
newTokenId,
pricePerToken * quantity,
address(currency),
mintReferral,
""
);
vm.stopPrank();

assertEq(target.balanceOf(tokenRecipient, newTokenId), quantity);
Expand All @@ -330,6 +348,7 @@ contract ERC20MinterTest is Test {
currency.balanceOf(admin),
totalValue
);
assertEq(address(zora).balance, ethReward * quantity);
}

function test_ERC20MinterSaleFuzz(uint96 pricePerToken, uint256 quantity, uint8 rewardPct, uint256 zoraEthReward) external {
Expand Down Expand Up @@ -371,10 +390,10 @@ contract ERC20MinterTest is Test {
firstMinterReward,
zoraReward
);
vm.deal(tokenRecipient, zoraEthReward);
vm.deal(tokenRecipient, zoraEthReward * quantity);

uint256 amount = pricePerToken * quantity;
newMinter.mint{value: zoraEthReward}(tokenRecipient, quantity, address(target), tokenId, amount, address(currency), mintReferral, "");
newMinter.mint{value: zoraEthReward * quantity}(tokenRecipient, quantity, address(target), tokenId, amount, address(currency), mintReferral, "");
vm.stopPrank();

assertEq(target.balanceOf(tokenRecipient, tokenId), quantity);
Expand All @@ -391,7 +410,7 @@ contract ERC20MinterTest is Test {
currency.balanceOf(admin),
totalValue
);
assertEq(address(zora).balance, zoraEthReward);
assertEq(address(zora).balance, zoraEthReward * quantity);
}

function test_ERC20MinterCreateReferral() public {
Expand All @@ -418,11 +437,11 @@ contract ERC20MinterTest is Test {
vm.prank(admin);
currency.mint(collector, totalValue);

vm.deal(collector, ethReward);
vm.deal(collector, ethReward * quantity);

vm.startPrank(collector);
currency.approve(address(minter), totalValue);
minter.mint{value: ethReward}(collector, quantity, address(target), tokenId, totalValue, address(currency), address(0), "");
minter.mint{value: ethReward * quantity}(collector, quantity, address(target), tokenId, totalValue, address(currency), address(0), "");
vm.stopPrank();

address firstMinter = minter.getFirstMinter(address(target), tokenId);
Expand Down Expand Up @@ -522,6 +541,29 @@ contract ERC20MinterTest is Test {
minter.setERC20MinterConfig(newConfig);
}

function test_ERC20MinterEthRewardTooLow(uint256 ethRewardLow) public {
vm.assume(ethRewardLow >= 0 ether && ethRewardLow < 0.000111 ether);

uint96 pricePerToken = 10_000;
uint256 quantity = 2;
uint256 newTokenId = setUpTargetSale(pricePerToken, fundsRecipient, address(currency), quantity, minter);

vm.deal(tokenRecipient, 1 ether);
vm.prank(admin);
uint256 totalValue = pricePerToken * quantity;
currency.mint(address(tokenRecipient), totalValue);

vm.prank(tokenRecipient);
currency.approve(address(minter), totalValue);

vm.deal(tokenRecipient, ethRewardLow);

vm.startPrank(tokenRecipient);
vm.expectRevert(abi.encodeWithSelector(IERC20Minter.InvalidETHValue.selector, 0.000111 ether * quantity, ethRewardLow));
minter.mint{value: ethRewardLow}(tokenRecipient, quantity, address(target), newTokenId, pricePerToken * quantity, address(currency), mintReferral, "");
vm.stopPrank();
}

function test_ERC20MinterSetPremintSale() public {
IERC20Minter.PremintSalesConfig memory newConfig = IERC20Minter.PremintSalesConfig({
duration: 3000,
Expand Down

0 comments on commit d9b8a71

Please sign in to comment.