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 minter role #4
Merged
marcomariscal
merged 45 commits into
feat/capped-minter-v2
from
feat/capped-minter-v2-minter-role
Dec 16, 2024
Merged
Changes from 17 commits
Commits
Show all changes
45 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 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 c462fbe
fix: remove unnecessary remapping
marcomariscal 9ee9e5b
fix: revert permish
marcomariscal d0798f7
fix: revert to original
marcomariscal 783cac7
fix: ci era test node version
marcomariscal d68fd3a
Merge branch 'feat/capped-minter-v2' into feat/capped-minter-v2-minte…
marcomariscal ad3713d
fix: revert
marcomariscal 67944e4
fix: copy root ci.yml to l2-contracts
marcomariscal 21dff29
Revert "fix: copy root ci.yml to l2-contracts"
marcomariscal b8fbe7e
chore: lock
marcomariscal 513a10d
fix: ci
marcomariscal 09308b6
fix: ci
marcomariscal 7edf867
fix: remove era node
marcomariscal 153717f
fix: ci
marcomariscal c2a3347
fix: no zk flag for now
marcomariscal b2ed160
fix: use build
marcomariscal 4a60adf
fix: ci
marcomariscal cb54f31
fix: cache
marcomariscal a38ef6b
fix: simplify
marcomariscal c37c3e1
fix: simplify
marcomariscal d15cfe7
fix: revert
marcomariscal 4a6edfd
chore: remove comment
marcomariscal 5cb22a6
fix: remove forge i to see if it works
marcomariscal 4f19a0a
Revert "fix: remove forge i to see if it works"
marcomariscal b3814ba
fix: building with forge
marcomariscal e769eca
fix: use npm scripts and re-add hardhat
marcomariscal 4068298
chore: name
marcomariscal 5adc73c
fix: match path
marcomariscal 6f17280
fix: remove unnecessary match path
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. Is this necessary? |
||
] | ||
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,58 +1,49 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.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 { | ||
/// @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"); | ||
|
||
/// @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 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); | ||
} | ||
|
||
/// @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(); | ||
_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 { | ||
|
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
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.
Also, why was this added?