-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Hadrien Croubois <[email protected]> Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Zack Reneau-Wedeen <[email protected]>
- Loading branch information
1 parent
ab967b8
commit 83330a6
Showing
9 changed files
with
487 additions
and
75 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
contracts/mocks/docs/access-control/AccessControlERC20MintBase.sol
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,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessControl} from "../../../access/AccessControl.sol"; | ||
import {ERC20} from "../../../token/ERC20/ERC20.sol"; | ||
|
||
contract AccessControlERC20MintBase is ERC20, AccessControl { | ||
// Create a new role identifier for the minter role | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
|
||
error CallerNotMinter(address caller); | ||
|
||
constructor(address minter) ERC20("MyToken", "TKN") { | ||
// Grant the minter role to a specified account | ||
_grantRole(MINTER_ROLE, minter); | ||
} | ||
|
||
function mint(address to, uint256 amount) public { | ||
// Check that the calling account has the minter role | ||
if (!hasRole(MINTER_ROLE, msg.sender)) { | ||
revert CallerNotMinter(msg.sender); | ||
} | ||
_mint(to, amount); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
contracts/mocks/docs/access-control/AccessControlERC20MintMissing.sol
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,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessControl} from "../../../access/AccessControl.sol"; | ||
import {ERC20} from "../../../token/ERC20/ERC20.sol"; | ||
|
||
contract AccessControlERC20MintMissing is ERC20, AccessControl { | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); | ||
|
||
constructor() ERC20("MyToken", "TKN") { | ||
// Grant the contract deployer the default admin role: it will be able | ||
// to grant and revoke any roles | ||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) { | ||
_mint(to, amount); | ||
} | ||
|
||
function burn(address from, uint256 amount) public onlyRole(BURNER_ROLE) { | ||
_burn(from, amount); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
contracts/mocks/docs/access-control/AccessControlERC20MintOnlyRole.sol
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,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessControl} from "../../../access/AccessControl.sol"; | ||
import {ERC20} from "../../../token/ERC20/ERC20.sol"; | ||
|
||
contract AccessControlERC20Mint is ERC20, AccessControl { | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); | ||
|
||
constructor(address minter, address burner) ERC20("MyToken", "TKN") { | ||
_grantRole(MINTER_ROLE, minter); | ||
_grantRole(BURNER_ROLE, burner); | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) { | ||
_mint(to, amount); | ||
} | ||
|
||
function burn(address from, uint256 amount) public onlyRole(BURNER_ROLE) { | ||
_burn(from, amount); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
contracts/mocks/docs/access-control/AccessManagedERC20MintBase.sol
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,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessManaged} from "../../../access/manager/AccessManaged.sol"; | ||
import {ERC20} from "../../../token/ERC20/ERC20.sol"; | ||
|
||
contract AccessManagedERC20Mint is ERC20, AccessManaged { | ||
constructor(address manager) ERC20("MyToken", "TKN") AccessManaged(manager) {} | ||
|
||
// Minting is restricted according to the manager rules for this function. | ||
// The function is identified by its selector: 0x40c10f19. | ||
// Calculated with bytes4(keccak256('mint(address,uint256)')) | ||
function mint(address to, uint256 amount) public restricted { | ||
_mint(to, amount); | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.