-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support increasing max mintable supply with method to disable (#58)
* Add ERC721MIncreasableSupply * add back deleted comment * update deploy script
- Loading branch information
Showing
7 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "./ERC721M.sol"; | ||
|
||
contract ERC721MIncreasableSupply is ERC721M { | ||
// Whether mintable supply can increase. Once set to false, _maxMintableSupply can never increase. | ||
bool private _canIncreaseMaxMintableSupply; | ||
|
||
event DisableIncreaseMaxMintableSupply(); | ||
|
||
constructor( | ||
string memory collectionName, | ||
string memory collectionSymbol, | ||
string memory tokenURISuffix, | ||
uint256 maxMintableSupply, | ||
uint256 globalWalletLimit, | ||
address cosigner, | ||
uint64 timestampExpirySeconds | ||
) | ||
ERC721M( | ||
collectionName, | ||
collectionSymbol, | ||
tokenURISuffix, | ||
maxMintableSupply, | ||
globalWalletLimit, | ||
cosigner, | ||
timestampExpirySeconds | ||
) | ||
{ | ||
_canIncreaseMaxMintableSupply = true; | ||
} | ||
|
||
/** | ||
* @dev Return true if max mintable supply can be increased. | ||
*/ | ||
function getCanIncreaseMaxMintableSupply() external view returns (bool) { | ||
return _canIncreaseMaxMintableSupply; | ||
} | ||
|
||
/** | ||
* @dev Makes _canIncreaseMaxMintableSupply false permanently. | ||
*/ | ||
function disableIncreaseMaxMintableSupply() external onlyOwner { | ||
_canIncreaseMaxMintableSupply = false; | ||
emit DisableIncreaseMaxMintableSupply(); | ||
} | ||
|
||
/** | ||
* @dev Sets maximum mintable supply. | ||
* | ||
* New supply cannot be larger than the old, unless _canIncreaseMaxMintableSupply is true. | ||
*/ | ||
function setMaxMintableSupply(uint256 maxMintableSupply) | ||
external | ||
override | ||
onlyOwner | ||
{ | ||
if ( | ||
!_canIncreaseMaxMintableSupply && | ||
maxMintableSupply > _maxMintableSupply | ||
) { | ||
revert CannotIncreaseMaxMintableSupply(); | ||
} | ||
_maxMintableSupply = maxMintableSupply; | ||
emit SetMaxMintableSupply(maxMintableSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ERC721MIncreasableSupply } from '../typechain-types'; | ||
import { ethers } from 'hardhat'; | ||
import { expect } from 'chai'; | ||
|
||
describe('ERC721MIncreasableSupply', () => { | ||
let contract: ERC721MIncreasableSupply; | ||
|
||
beforeEach(async () => { | ||
const factory = await ethers.getContractFactory('ERC721MIncreasableSupply'); | ||
contract = await factory.deploy( | ||
'test', | ||
'TEST', | ||
'.json', | ||
1000, | ||
0, | ||
ethers.constants.AddressZero, | ||
300, | ||
); | ||
const [owner] = await ethers.getSigners(); | ||
contract = contract.connect(owner); | ||
await contract.deployed(); | ||
}); | ||
|
||
it('can increase max mintable supply until disableIncreaseMaxMintableSupply called', async () => { | ||
const currentSupply = await contract.getMaxMintableSupply(); | ||
expect(await contract.getCanIncreaseMaxMintableSupply()).to.eq(true); | ||
await expect(contract.setMaxMintableSupply(currentSupply.add(1000))) | ||
.to.emit(contract, 'SetMaxMintableSupply') | ||
.withArgs(currentSupply.toNumber() + 1000); | ||
|
||
await expect(contract.disableIncreaseMaxMintableSupply()).to.emit( | ||
contract, | ||
'DisableIncreaseMaxMintableSupply', | ||
); | ||
expect(await contract.getCanIncreaseMaxMintableSupply()).to.eq(false); | ||
await expect( | ||
contract.setMaxMintableSupply(currentSupply.add(2000)), | ||
).to.be.revertedWith('CannotIncreaseMaxMintableSupply'); | ||
}); | ||
}); |