forked from EthereansOS/Organizations-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVotingToken.sol
146 lines (115 loc) · 5.44 KB
/
VotingToken.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
pragma solidity ^0.6.0;
import "./IMVDProxy.sol";
import "./IERC20.sol";
import "./IVotingToken.sol";
import "./IMVDFunctionalityProposalManager.sol";
import "./IMVDFunctionalitiesManager.sol";
contract VotingToken is IERC20, IVotingToken {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
uint256 private _decimals;
address private _proxy;
string private _name;
string private _symbol;
constructor(string memory name, string memory symbol, uint256 decimals, uint256 totalSupply) public {
if(totalSupply == 0) {
return;
}
init(name, symbol, decimals, totalSupply);
}
function init(string memory name, string memory symbol, uint256 decimals, uint256 totalSupply) public override {
require(_totalSupply == 0, "Init already called!");
_name = name;
_symbol = symbol;
_decimals = decimals;
_totalSupply = totalSupply * (10 ** decimals);
_balances[msg.sender] = _totalSupply;
emit Transfer(address(this), msg.sender, _totalSupply);
}
receive() external payable {
revert("ETH not accepted");
}
function getProxy() public override view returns(address) {
return _proxy;
}
function name() public override view returns(string memory) {
return _name;
}
function symbol() public override view returns(string memory) {
return _symbol;
}
function decimals() public override view returns(uint256) {
return _decimals;
}
function totalSupply() public override view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public override view returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) public override view returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
address txSender = msg.sender;
if(_proxy == address(0) || !(IMVDFunctionalityProposalManager(IMVDProxy(_proxy).getMVDFunctionalityProposalManagerAddress()).isValidProposal(txSender) && recipient == txSender)) {
_approve(sender, txSender, _allowances[sender][txSender] = sub(_allowances[sender][txSender], amount, "ERC20: transfer amount exceeds allowance"));
}
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public override returns (bool) {
_approve(msg.sender, spender, add(_allowances[msg.sender][spender], addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public override returns (bool) {
_approve(msg.sender, spender, sub(_allowances[msg.sender][spender], subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = sub(_balances[sender], amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = add(_balances[recipient], amount);
emit Transfer(sender, recipient, amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
require(c >= a, "SafeMath: addition overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256 c) {
require(b <= a, errorMessage);
c = a - b;
}
function setProxy() public override {
require(_totalSupply != 0, "Init not called!");
require(_proxy == address(0) || _proxy == msg.sender, _proxy != address(0) ? "Proxy already set!" : "Only Proxy can toggle itself!");
_proxy = _proxy == address(0) ? msg.sender : address(0);
}
function mint(uint256 amount) public override {
require(IMVDFunctionalitiesManager(IMVDProxy(_proxy).getMVDFunctionalitiesManagerAddress()).isAuthorizedFunctionality(msg.sender), "Unauthorized access!");
_totalSupply = add(_totalSupply, amount);
_balances[_proxy] = add(_balances[_proxy], amount);
emit Transfer(address(0), _proxy, amount);
}
function burn(uint256 amount) public override {
_balances[msg.sender] = sub(_balances[msg.sender], amount, "VotingToken: burn amount exceeds balance");
_totalSupply = sub(_totalSupply, amount, "VotingToken: burn amount exceeds total supply");
emit Transfer(msg.sender, address(0), amount);
}
}