Created
July 14, 2022 22:00
-
-
Save JuanXavier/6536e5a96ee67c9710b61ff267515014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| import '@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol'; | |
| import '@openzeppelin/contracts/access/AccessControl.sol'; | |
| /** | |
| * @title AccountingToken | |
| * @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz) | |
| * @notice A limited pseudo-ERC20 token to keep track of deposits and withdrawals | |
| * with snapshotting capabilities | |
| */ | |
| contract AccountingToken is ERC20Snapshot, AccessControl { | |
| bytes32 public constant MINTER_ROLE = keccak256('MINTER_ROLE'); | |
| bytes32 public constant SNAPSHOT_ROLE = keccak256('SNAPSHOT_ROLE'); | |
| bytes32 public constant BURNER_ROLE = keccak256('BURNER_ROLE'); | |
| constructor() ERC20('rToken', 'rTKN') { | |
| _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); | |
| _setupRole(MINTER_ROLE, msg.sender); | |
| _setupRole(SNAPSHOT_ROLE, msg.sender); | |
| _setupRole(BURNER_ROLE, msg.sender); | |
| } | |
| function mint(address to, uint256 amount) external { | |
| require(hasRole(MINTER_ROLE, msg.sender), 'Forbidden'); | |
| _mint(to, amount); | |
| } | |
| function burn(address from, uint256 amount) external { | |
| require(hasRole(BURNER_ROLE, msg.sender), 'Forbidden'); | |
| _burn(from, amount); | |
| } | |
| function snapshot() external returns (uint256) { | |
| require(hasRole(SNAPSHOT_ROLE, msg.sender), 'Forbidden'); | |
| return _snapshot(); | |
| } | |
| // Do not need transfer of this token | |
| function _transfer( | |
| address, | |
| address, | |
| uint256 | |
| ) internal pure override { | |
| revert('Not implemented'); | |
| } | |
| // Do not need allowance of this token | |
| function _approve( | |
| address, | |
| address, | |
| uint256 | |
| ) internal pure override { | |
| revert('Not implemented'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment