-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDpxEthToken.sol
63 lines (54 loc) · 1.7 KB
/
DpxEthToken.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
61
62
63
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ERC20Burnable } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import { Pausable } from "../helper/Pausable.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { IDpxEthToken } from "./IDpxEthToken.sol";
/// @title Dopex Synthetic ETH token contract
/// @author Dopex
contract DpxEthToken is
ERC20,
ERC20Burnable,
Pausable,
AccessControl,
IDpxEthToken
{
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
constructor() ERC20("Dopex Synthetic ETH", "dpxETH") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(PAUSER_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
}
function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}
function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount);
}
function burn(
uint256 _amount
) public override(ERC20Burnable, IDpxEthToken) onlyRole(BURNER_ROLE) {
_burn(_msgSender(), _amount);
}
function burnFrom(
address account,
uint256 amount
) public override onlyRole(BURNER_ROLE) {
_spendAllowance(account, _msgSender(), amount);
_burn(account, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
_whenNotPaused();
super._beforeTokenTransfer(from, to, amount);
}
}