Skip to content

Commit

Permalink
Add totalSupply check in setMaxMintableSupply + change to Ownable2Step
Browse files Browse the repository at this point in the history
  • Loading branch information
channing-magiceden committed Jul 10, 2024
1 parent bb91f5b commit fb51208
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
15 changes: 8 additions & 7 deletions contracts/ERC1155M.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/token/common/ERC2981.sol";
Expand All @@ -23,7 +23,7 @@ import "./IERC1155M.sol";
* - whitelist
* - variable wallet limit
*/
contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable, ReentrancyGuard {
contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable2Step, ReentrancyGuard {
using ECDSA for bytes32;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -179,9 +179,7 @@ contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable, ReentrancyGuard
}

/**
* @dev Sets maximum mintable supply.
*
* New supply cannot be larger than the old.
* @dev Sets maximum mintable supply. New supply cannot be larger than the old or the supply alraedy minted.
*/
function setMaxMintableSupply(
uint256 tokenId,
Expand All @@ -193,6 +191,9 @@ contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable, ReentrancyGuard
if (_maxMintableSupply[tokenId] != 0 && maxMintableSupply > _maxMintableSupply[tokenId]) {
revert CannotIncreaseMaxMintableSupply();
}
if (maxMintableSupply < totalSupply(tokenId)) {
revert NewSupplyLessThanTotalSupply();
}
_maxMintableSupply[tokenId] = maxMintableSupply;
emit SetMaxMintableSupply(tokenId, maxMintableSupply);
}
Expand Down Expand Up @@ -419,12 +420,12 @@ contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable, ReentrancyGuard
function withdraw() external onlyOwner {
(bool success, ) = MINT_FEE_RECEIVER.call{value: _totalMintFee}("");
if (!success) revert TransferFailed();
_totalMintFee = 0;

uint256 remainingValue = address(this).balance;
(success, ) = FUND_RECEIVER.call{value: remainingValue}("");
if (!success) revert WithdrawFailed();

_totalMintFee = 0;
emit Withdraw(_totalMintFee + remainingValue);
}

Expand All @@ -435,11 +436,11 @@ contract ERC1155M is IERC1155M, ERC1155Supply, ERC2981, Ownable, ReentrancyGuard
if (_mintCurrency == address(0)) revert WrongMintCurrency();

IERC20(_mintCurrency).safeTransfer(MINT_FEE_RECEIVER, _totalMintFee);
_totalMintFee = 0;

uint256 remaining = IERC20(_mintCurrency).balanceOf(address(this));
IERC20(_mintCurrency).safeTransfer(FUND_RECEIVER, remaining);

_totalMintFee = 0;
emit WithdrawERC20(_mintCurrency, _totalMintFee + remaining);
}

Expand Down
1 change: 1 addition & 0 deletions contracts/IERC1155M.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.4;

interface IERC1155M {
error CannotIncreaseMaxMintableSupply();
error NewSupplyLessThanTotalSupply();
error GlobalWalletLimitOverflow();
error InsufficientStageTimeGap();
error InvalidLimitArgsLength();
Expand Down
10 changes: 8 additions & 2 deletions test/ERC1155M.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('ERC1155M', function () {
).to.be.revertedWith('ReentrancyGuardReentrantCall');
});

it('can set max mintable supply', async () => {
it('set max mintable supply', async () => {
await contract.setMaxMintableSupply(0, 99);
expect(await contract.getMaxMintableSupply(0)).to.equal(99);

Expand All @@ -464,12 +464,18 @@ describe('ERC1155M', function () {
// can not set the mintable supply for a non-existent token
await expect(contract.setMaxMintableSupply(1, 100)).to.be.rejectedWith(
'InvalidTokenId',
)
);

// readonlyContract should not be able to set max mintable supply
await expect(
readonlyContract.setMaxMintableSupply(0, 99),
).to.be.revertedWith('Ownable');

// can not set the mintable supply lower than the total supply
await contract.ownerMint(owner.address, 0, 10);
await expect(contract.setMaxMintableSupply(0, 9)).to.be.rejectedWith(
'NewSupplyLessThanTotalSupply',
);
});

it('enforces max mintable supply', async () => {
Expand Down

0 comments on commit fb51208

Please sign in to comment.