forked from zksync-association/zk-governance
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: capped minter v2 close #12
Merged
alexkeating
merged 53 commits into
feat/capped-minter-v2
from
feat/capped-minter-v2-close
Dec 17, 2024
Merged
Changes from 46 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
9f8ea6e
feat: inherit from AccessControl and update accordingly
marcomariscal 2aecdce
feat: update tests to handle new auth functionality
marcomariscal e293e2d
feat: add minter role
marcomariscal b7f4222
feat: test admin can't mint by default
marcomariscal 726d0bf
fix: name
marcomariscal 31d626f
fix: structure
marcomariscal fb88648
feat: basic pause functionality
marcomariscal 946dc79
feat: pause/unpause tests
marcomariscal d9b3dba
fix: assume cap is not zero
marcomariscal 1cfbef7
fix: check for pauser role
marcomariscal 3379852
fix: separate role errors
marcomariscal 004c789
feat: _revertIfNotPauser
marcomariscal 4f29f5c
feat: close with tests
marcomariscal edf05f6
fix: use _revertIfNotPauser
marcomariscal bceb0f7
chore: better comment for `close`
marcomariscal e680c31
chore: comment
marcomariscal 6ee3fb1
feat: _grantMinterRole helper
marcomariscal 72ef93c
fix: use _checkRole and remove unused unauth error
marcomariscal dd15cac
fix: assume cap
marcomariscal 61e7247
fix: toml
marcomariscal 1295f88
chore: format
marcomariscal 54315f5
fix: import
marcomariscal 2558249
fix: compile
marcomariscal 857ebc6
chore: name
marcomariscal 479ef77
fix: import
marcomariscal 007784b
fix: remove unnecessary
marcomariscal bfbac0e
feat: _revertIfClosed
marcomariscal 8a5f057
Merge branch 'feat/capped-minter-v2-minter-role' into feat/capped-min…
marcomariscal 493c1a6
feat: _formatAccessControlError
marcomariscal 7d84ebe
Merge branch 'feat/capped-minter-v2-pause' into feat/capped-minter-v2…
marcomariscal 6bb7d1a
fix: formatted error
marcomariscal fca3ffb
fix: remove assume cap greater than 0 in favor of bound
marcomariscal 93e4af3
fix: remove unnecessary assumptions
marcomariscal 225ba92
fix: use grant minter role
marcomariscal 1942a64
fix: remove redundant balance check
marcomariscal 77acf62
feat: refactor to set up capped minter in setup func
marcomariscal ecb275d
feat: testFuzz_CorrectlyPausesMintsWhenTogglingPause
marcomariscal 43fa666
fix: move func
marcomariscal 7da3772
Merge branch 'feat/capped-minter-v2-pause' into feat/capped-minter-v2…
marcomariscal 57e1f4f
fix: only admin can close, fix mint to zero addr receiver, and format…
marcomariscal ef8ca96
fix: remove unnecessary revert if closed when unpausing
marcomariscal 3fc7d3a
Update l2-contracts/src/ZkCappedMinterV2.sol
marcomariscal bb6854b
fix: test
marcomariscal 0b17e88
fix: remove unnecessary pause from close
marcomariscal 7631a29
fix: use global minter
marcomariscal 246efdc
feat: test_CorrectlyChangesClosedVarWhenCalledByAdmin
marcomariscal 91c0ca8
fix: foundry toml revert
marcomariscal aa47d27
Merge branch 'feat/capped-minter-v2' into feat/capped-minter-v2-close
marcomariscal 48c9ca6
fix: handle check balances before and after
marcomariscal fe1cac7
fix: assume not capped minter admin
marcomariscal c7bef58
fix: handle balance check before in test
marcomariscal 010e4c5
fix: rename
marcomariscal 960a751
chore: remove unused
marcomariscal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[profile.default] | ||
evm_version = "paris" | ||
fs_permissions = [{ access = "read", path = "./zkout" }] | ||
fuzz = { runs = 50 } | ||
optimizer = true | ||
optimizer_runs = 10_000_000 | ||
|
@@ -8,10 +9,10 @@ | |
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", | ||
"@openzeppelin/foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/", | ||
"@murky/=lib/murky/", | ||
"src/=src/", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
] | ||
solc_version = "0.8.24" | ||
verbosity = 3 | ||
fs_permissions = [{ access = "read", path = "./zkout" }] | ||
|
||
[profile.ci] | ||
fuzz = { runs = 5000 } | ||
|
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 |
---|---|---|
@@ -1,63 +1,92 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; | ||
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; | ||
import {IMintableAndDelegatable} from "src/interfaces/IMintableAndDelegatable.sol"; | ||
|
||
/// @title ZkCappedMinterV2 | ||
/// @author [ScopeLift](https://scopelift.co) | ||
/// @notice A contract to allow a permissioned entity to mint ZK tokens up to a given amount (the cap). | ||
/// @custom:security-contact [email protected] | ||
contract ZkCappedMinterV2 { | ||
contract ZkCappedMinterV2 is AccessControl, Pausable { | ||
/// @notice The contract where the tokens will be minted by an authorized minter. | ||
IMintableAndDelegatable public immutable TOKEN; | ||
|
||
/// @notice The address that is allowed to mint tokens. | ||
address public immutable ADMIN; | ||
|
||
/// @notice The maximum number of tokens that may be minted by the ZkCappedMinter. | ||
uint256 public immutable CAP; | ||
|
||
/// @notice The cumulative number of tokens that have been minted by the ZkCappedMinter. | ||
uint256 public minted = 0; | ||
|
||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | ||
|
||
/// @notice Whether the contract has been permanently closed. | ||
bool public closed; | ||
|
||
/// @notice Error for when the cap is exceeded. | ||
error ZkCappedMinterV2__CapExceeded(address minter, uint256 amount); | ||
|
||
/// @notice Error for when the caller is not the admin. | ||
error ZkCappedMinterV2__Unauthorized(address account); | ||
/// @notice Thrown when a mint action is taken while the contract is closed. | ||
error ZkCappedMinterV2__ContractClosed(); | ||
|
||
/// @notice Constructor for a new ZkCappedMinter contract | ||
/// @notice Constructor for a new ZkCappedMinterV2 contract | ||
/// @param _token The token contract where tokens will be minted. | ||
/// @param _admin The address that is allowed to mint tokens. | ||
/// @param _admin The address that will be granted the admin role. | ||
/// @param _cap The maximum number of tokens that may be minted by the ZkCappedMinter. | ||
constructor(IMintableAndDelegatable _token, address _admin, uint256 _cap) { | ||
TOKEN = _token; | ||
ADMIN = _admin; | ||
CAP = _cap; | ||
|
||
_grantRole(DEFAULT_ADMIN_ROLE, _admin); | ||
_grantRole(PAUSER_ROLE, _admin); | ||
} | ||
|
||
/// @notice Pauses token minting | ||
function pause() external { | ||
_checkRole(PAUSER_ROLE, msg.sender); | ||
_pause(); | ||
} | ||
|
||
/// @notice Unpauses token minting | ||
function unpause() external { | ||
_checkRole(PAUSER_ROLE, msg.sender); | ||
_unpause(); | ||
} | ||
|
||
/// @notice Mints a given amount of tokens to a given address, so long as the cap is not exceeded. | ||
/// @param _to The address that will receive the new tokens. | ||
/// @param _amount The quantity of tokens, in raw decimals, that will be created. | ||
function mint(address _to, uint256 _amount) external { | ||
_revertIfUnauthorized(); | ||
_revertIfClosed(); | ||
_requireNotPaused(); | ||
_checkRole(MINTER_ROLE, msg.sender); | ||
_revertIfCapExceeded(_amount); | ||
minted += _amount; | ||
TOKEN.mint(_to, _amount); | ||
} | ||
|
||
/// @notice Reverts if msg.sender is not the contract admin. | ||
function _revertIfUnauthorized() internal view { | ||
if (msg.sender != ADMIN) { | ||
revert ZkCappedMinterV2__Unauthorized(msg.sender); | ||
} | ||
} | ||
|
||
/// @notice Reverts if the amount of new tokens will increase the minted tokens beyond the mint cap. | ||
/// @param _amount The quantity of tokens, in raw decimals, that will checked against the cap. | ||
function _revertIfCapExceeded(uint256 _amount) internal view { | ||
if (minted + _amount > CAP) { | ||
revert ZkCappedMinterV2__CapExceeded(msg.sender, _amount); | ||
} | ||
} | ||
|
||
/// @notice Reverts if the contract is closed. | ||
function _revertIfClosed() internal view { | ||
if (closed) { | ||
revert ZkCappedMinterV2__ContractClosed(); | ||
} | ||
} | ||
|
||
/// @notice Permanently closes the contract, preventing any future minting. | ||
/// @dev Once closed, the contract cannot be reopened and all minting operations will be permanently blocked. | ||
/// @dev Only callable by the admin. | ||
function close() external { | ||
_checkRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
closed = true; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
91c0ca8