-
Notifications
You must be signed in to change notification settings - Fork 9
/
AccountingToken.sol
60 lines (51 loc) · 1.83 KB
/
AccountingToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;
import {ERC20Snapshot, ERC20} from "openzeppelin-contracts/token/ERC20/extensions/ERC20Snapshot.sol";
import {AccessControl} from "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");
error Forbidden();
error NotImplemented();
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 {
if (!hasRole(MINTER_ROLE, msg.sender)) revert Forbidden();
_mint(to, amount);
}
function burn(address from, uint256 amount) external {
if (!hasRole(BURNER_ROLE, msg.sender)) revert Forbidden();
_burn(from, amount);
}
function snapshot() external returns (uint256) {
if (!hasRole(SNAPSHOT_ROLE, msg.sender)) revert Forbidden();
return _snapshot();
}
// Do not need transfer of this token
function _transfer(
address,
address,
uint256
) internal pure override {
revert NotImplemented();
}
// Do not need allowance of this token
function _approve(
address,
address,
uint256
) internal pure override {
revert NotImplemented();
}
}