-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathERC20Staking
More file actions
99 lines (71 loc) · 3.52 KB
/
ERC20Staking
File metadata and controls
99 lines (71 loc) · 3.52 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
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.6.0
pragma solidity ^0.8.27;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
разделить логику
– initialize() — базовая инициализация
– startVesting() — запуск вестинга (только после пополнения контракта
contract ERC20Staking is Ownable {
function initialize(address[] memory _beneficiary, uint256 _totalAmount, uint256 _cliff, uint256 _startTime, uint256 _endTime, uint256 _minimalAmountToClaim) public {
struct Staking {
address beneficiary;
uint256 totalAmount;
uint256 cliff;
uint256 startTime;
uint256 endTime;
uint256 minimalAmountToClaim;
}
beneficiary = _beneficiary;
totalAmount = _totalAmount;
cliff = _cliff;
startTime = _startTime;
endTime = _endTime;
minimalAmountToClaim = _minimalAmountToClaim;
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
}
function startVesting(address[] memory _beneficiary, uint256 _totalAmount, uint256 _cliff, uint256 _startTime, uint256 _endTime, uint256 _minimalAmountToClaim) external, onlyOwner() {
struct Staking {
address beneficiary = _beneficiary;
uint256 totalAmount = _totalAmount;
uint256 cliff = _cliff;
uint256 startTime = _startTime;
uint256 endTime = _endTime;
uint256 minimalAmountToClaim = _minimalAmountToClaim;
}
}
constructor(address _beneficiary, uint256 _totalAmount, uint256 _cliff, uint256 _startTime, uint256 _endTime, uint256 _minimalAmountToClaim) Ownable(msg.sender) {
beneficiary = _beneficiary;
totalAmount = _totalAmount;
cliff = _cliff;
startTime = _startTime;
endTime = _endTime;
minimalAmountToClaim = _minimalAmountToClaim;
}
function claim(uint256 _amount) public {
если юыло заклеймлено то пояаляетмя таймер до возможности заклеймить еще
таймер возможности заклеймить в днях
Добавить поддержку нескольких получателей
маппинги стракты
mapping (address(benefeciary) => struct )
uint256 timer = block.timestamp + 1 days
if CoolDownTimer > 0 ,error timerNotEnded
if msg.sender != beneficiary, error not beneficiary
if block.timestamp < startTime, error rano start ne nastupil
if block.timestamp < cliff, error rano cliff ne nastupil
if block.timestamp >= endTime ,error claimTimeEnded
uint256 amountToClaim = (totalAmount * (block.timestamp - (startTime + cliff))) / Duration;
if amountToClaim < minimalAmountToClaim, error not enough amount to claim
if amountToClaim > amount , error overmnoga
amount -= amountToClaim
claimed += amountToClaim
require(ERC20(token).transfer(benefeciary, amountToClaim))
CoolDownTimer = block.timestamp + 1 day
emit Claimed(amountToClaim)
emit CoolDownTimerSet(CoolDownTimer)
}
}