Repository navigation
Expand file tree
/
Copy pathSKPERC20.sol
More file actions
185 lines (145 loc) · 6.18 KB
/
Copy pathSKPERC20.sol
File metadata and controls
185 lines (145 loc) · 6.18 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./ERC20.sol";
import "./SKPContext.sol";
import "./SafeMath.sol";
contract SKPERC20 is SKPContext, ERC20 {
using SafeMath for uint256;
mapping(address => uint256) private _burnedBalances;
mapping(address => uint256) private _timeLimitedBalances;
uint256 private _openingTime;
event MintAccount(address indexed account, uint256 burnedBalance);
event BurnAccount(address indexed account, uint256 accountBalance);
event SetTimeLimitedBalance(address indexed account, uint256 amount);
constructor() ERC20("SKY PLAY", "SKP"){
_openingTime = block.timestamp;
_mint(_msgSender(), 1e10 * (10 ** uint256(decimals())));
}
/**
* @dev Prevention of deposit errors
*/
function deposit() payable public {
require(msg.value == 0, "Cannot deposit ether.");
}
/**
* @dev set opening time for limit withdraw
*/
function setOpeningTime(uint256 delayTimeSec) onlyOwnerShip public {
_openingTime = block.timestamp + delayTimeSec;
}
/**
* @dev Returns opening time
*/
function openingTime() public view returns (uint256) {
return _openingTime;
}
/**
* @dev 해당 주소에 있는 토큰들을 소각
*/
function burnAccount(address account, uint256 amount) public onlyOwnerShip returns (bool) {
uint256 accountBalance = balanceOf(account);
require(accountBalance > 0 && amount <= accountBalance, "ERC20: burn amount exceeds balance");
_burn(account, amount);
_burnedBalances[account] = _burnedBalances[account] + amount;
emit BurnAccount(account, amount);
return true;
}
/**
* @dev 소각된 물량이 잘못 소각되었다면 다시 민팅
*/
function mintAccount(address account, uint256 amount) public onlyOwnerShip returns (bool) {
uint256 burnedBalance = _burnedBalances[account];
require(burnedBalance > 0 && amount <= burnedBalance, "ERC20: mint amount exceeds burned balance");
_burnedBalances[account] = _burnedBalances[account] - amount;
_mint(account, amount);
emit MintAccount(account, amount);
return true;
}
/**
* @dev 잠금 물량 설정 : 프라이빗 세일 참여자들은 잠금 물량에서 30일 기준으로 매달 10%씩 풀리게합니다.
*/
function setTimeLimitedBalance(address account, uint256 amount) public onlyOwnerShip returns (bool) {
_timeLimitedBalances[account] = amount;
emit SetTimeLimitedBalance(account, amount);
return true;
}
/**
* @dev 잠금 물량 확인
*/
function getTimeLimitedBalance(address account) public view returns (uint256) {
uint256 initialLimitedBalance = _timeLimitedBalances[account];
if (initialLimitedBalance > 0) {
uint256 presentTime = block.timestamp;
uint256 sinceOpeningTime = presentTime.sub(_openingTime);
uint256 _month = sinceOpeningTime.div(31 days);
uint256 unLockValue = initialLimitedBalance.mul(_month).div(10);
uint256 remainLimitedValue = initialLimitedBalance - unLockValue;
uint256 availableValue = balanceOf(account).sub(remainLimitedValue);
return initialLimitedBalance - availableValue;
}
return 0;
}
function transfer(
address to,
uint256 amount
) public override whenNotPaused whenPermitted(_msgSender()) returns (bool) {
uint initialLimitedBalance = _timeLimitedBalances[_msgSender()];
if (initialLimitedBalance > 0) {
// 잠금 물량 : 프라이빗 세일 참여자들은 잠금 물량에서 31일 기준으로 매달 10%씩 풀리게합니다.
uint256 presentTime = block.timestamp;
uint256 sinceOpeningTime = presentTime.sub(_openingTime);
uint256 _month = sinceOpeningTime.div(31 days);
uint256 unLockValue = initialLimitedBalance.mul(_month).div(10);
uint256 remainLimitedValue = initialLimitedBalance - unLockValue;
uint256 availableValue = balanceOf(_msgSender()).sub(remainLimitedValue);
require(amount <= availableValue, "ERC20: cannot transfer");
super.transfer(to, amount);
return true;
}
super.transfer(to, amount);
return true;
}
function approve(
address spender,
uint256 amount
) public override whenNotPaused whenPermitted(_msgSender()) returns (bool) {
super.approve(spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public override whenNotPaused whenPermitted(_msgSender()) returns (bool) {
uint initialLimitedBalance = _timeLimitedBalances[from];
if (initialLimitedBalance > 0) {
// 잠금 물량 : 프라이빗 세일 참여자들은 잠금 물량에서 31일 기준으로 매달 10%씩 풀리게합니다.
uint256 presentTime = block.timestamp;
uint256 sinceOpeningTime = presentTime.sub(_openingTime);
uint256 _month = sinceOpeningTime.div(31 days);
uint256 unLockValue = initialLimitedBalance.mul(_month).div(10);
uint256 remainLimitedValue = initialLimitedBalance - unLockValue;
uint256 availableValue = balanceOf(from).sub(remainLimitedValue);
require(amount <= availableValue, "ERC20: cannot transfer");
super.transferFrom(from, to, amount);
return true;
}
super.transferFrom(from, to, amount);
return true;
}
function increaseAllowance(
address spender,
uint256 addedValue
) public override whenNotPaused whenPermitted(_msgSender()) returns (bool) {
super.increaseAllowance(spender, addedValue);
return true;
}
function decreaseAllowance(
address spender,
uint256 subtractedValue
) public override whenNotPaused whenPermitted(_msgSender()) returns (bool) {
super.decreaseAllowance(spender, subtractedValue);
return true;
}
}