-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeToken.sol
148 lines (135 loc) · 5.54 KB
/
EdgeToken.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* @title EdgeToken
* @author Team 3301 <[email protected]>
* @dev EdgeToken is a ERC20 token that is upgradable and pausable.
* User addresses require to be whitelisted for transfers
* to execute. Addresses can be frozen, and funds from
* particular addresses can be confiscated.
*/
pragma solidity 0.5.12;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Overload/ERC20.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Whitelist.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Pausable.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Freezable.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Mintable.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/ERC20/ERC20Burnable.sol";
import "@sygnum/solidity-base-contracts/contracts/helpers/Initializable.sol";
contract EdgeToken is
ERC20,
ERC20Detailed("Digital CHF", "DCHF", 2),
Initializable,
ERC20Pausable,
ERC20Whitelist,
ERC20Freezable,
ERC20Mintable,
ERC20Burnable
{
event Minted(address indexed minter, address indexed account, uint256 value);
event Burned(address indexed burner, uint256 value);
event BurnedFor(address indexed burner, address indexed account, uint256 value);
uint16 internal constant BATCH_LIMIT = 256;
/**
* @dev Initialization instead of constructor, only called once.
* @param _baseOperators Address of baseOperators contract.
*/
function initialize(address _baseOperators, address _whitelist) public initializer {
super.initialize(_baseOperators, _whitelist);
}
/**
* @dev Burn.
* @param _amount Amount of tokens to burn.
*/
function burn(uint256 _amount) public {
require(!isFrozen(msg.sender), "EdgeToken: Account must not be frozen");
super._burn(msg.sender, _amount);
emit Burned(msg.sender, _amount);
}
/**
* @dev BurnFor.
* @param _account Account to burn tokens from.
* @param _amount Amount of tokens to burn.
*/
function burnFor(address _account, uint256 _amount) public {
super._burnFor(_account, _amount);
emit BurnedFor(msg.sender, _account, _amount);
}
/**
* @dev burnFrom.
* @param _account Account to burn from.
* @param _amount Amount of tokens to burn.
*/
function burnFrom(address _account, uint256 _amount) public {
super._burnFrom(_account, _amount);
emit Burned(_account, _amount);
}
/**
* @dev Mint.
* @param _account Address to mint tokens to.
* @param _amount Amount to mint.
*/
function mint(address _account, uint256 _amount) public {
if (isSystem(msg.sender)) {
require(!isFrozen(_account), "EdgeToken: Account must be frozen if system calling.");
}
super._mint(_account, _amount);
emit Minted(msg.sender, _account, _amount);
}
/**
* @dev confiscate.
* @param _confiscatee Account to confiscate funds from.
* @param _receiver Account to transfer confiscated funds too.
* @param _amount Amount of tokens to burn.
*/
function confiscate(
address _confiscatee,
address _receiver,
uint256 _amount
) public onlyOperator whenNotPaused whenWhitelisted(_receiver) whenWhitelisted(_confiscatee) {
super._transfer(_confiscatee, _receiver, _amount);
}
/**
* @dev Batch burn from an operator or admin address.
* @param _recipients Array of recipient addresses.
* @param _values Array of amount to burn.
*/
function batchBurnFor(address[] memory _recipients, uint256[] memory _values) public {
require(_recipients.length == _values.length, "EdgeToken: values and recipients are not equal.");
require(_recipients.length <= BATCH_LIMIT, "EdgeToken: batch count is greater than BATCH_LIMIT.");
for (uint256 i = 0; i < _recipients.length; i++) {
burnFor(_recipients[i], _values[i]);
}
}
/**
* @dev Batch mint to a maximum of 255 addresses, for a custom amount for each address.
* @param _recipients Array of recipient addresses.
* @param _values Array of amount to mint.
*/
function batchMint(address[] memory _recipients, uint256[] memory _values) public {
require(_recipients.length == _values.length, "EdgeToken: values and recipients are not equal.");
require(_recipients.length <= BATCH_LIMIT, "EdgeToken: greater than BATCH_LIMIT.");
for (uint256 i = 0; i < _recipients.length; i++) {
mint(_recipients[i], _values[i]);
}
}
/**
* @dev Batch confiscate to a maximum of 255 addresses.
* @param _confiscatees array addresses who's funds are being confiscated
* @param _receivers array addresses who's receiving the funds
* @param _values array of values of funds being confiscated
*/
function batchConfiscate(
address[] memory _confiscatees,
address[] memory _receivers,
uint256[] memory _values
) public {
require(
_confiscatees.length == _values.length && _receivers.length == _values.length,
"EdgeToken: values and recipients are not equal"
);
require(_confiscatees.length <= BATCH_LIMIT, "EdgeToken: batch count is greater than BATCH_LIMIT");
for (uint256 i = 0; i < _confiscatees.length; i++) {
confiscate(_confiscatees[i], _receivers[i], _values[i]);
}
}
}