-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOZ_forum_Payroles.sol
96 lines (77 loc) · 3.23 KB
/
OZ_forum_Payroles.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
// Code review from https://forum.openzeppelin.com/t/high-gas-fee-on-withdrawn-function/29985/5
// Original code from https://bscscan.com/address/0xA9ECd08c0faeBFaFdDD0A701eDE23fA08AeB4CF3#code
// Modified original code to fix issues
contract PayRole{
address owner;
IERC20 immutable BUSD;
mapping(address => bool) allowed;
mapping(address => uint) allowance;
mapping(address => uint) moment;
event devAdded(address);
event allowanceAdded(address, uint);
event allowanceRemoved(address, uint);
event allowanceChanged(address, uint);
event deposited(address, uint);
event claimed(address, uint);
event ownershipTransfered(address);
event ownerClaimned(uint);
constructor (address _address) {
owner = msg.sender;
BUSD = IERC20(_address);
}
modifier onlyOwner() {
require(
msg.sender == owner, "This function is restricted to the contract's owner");
_;
}
function transferOwnership(address _address) external onlyOwner {
owner = _address;
}
function addDev(address _address, uint _allowance) external onlyOwner {
allowed[_address] = true;
moment[_address] = block.timestamp;
allowance[_address] = _allowance;
emit devAdded(_address);
emit allowanceAdded(_address, _allowance);
}
function addAllowance(address _address, uint _amount) external onlyOwner {
allowance[_address] += _amount;
emit allowanceAdded(_address, _amount);
}
function removeAllowance(address _address, uint _amount) external onlyOwner {
allowance[_address] -= _amount;
emit allowanceRemoved(_address, _amount);
}
function setAllowance(address _address, uint _amount) external onlyOwner{
allowance[_address] = _amount;
emit allowanceChanged(_address, _amount);
}
function deposit(uint256 _amount) external {
require(_amount > 0, 'You need to send some tokens!');
BUSD.transferFrom(msg.sender, address(this), _amount);
emit deposited(msg.sender, _amount);
}
function getReward() external view returns(uint){
require(allowed[msg.sender] == true, 'This address is not allowed to check getReward');
return (block.timestamp - moment[msg.sender]) * allowance[msg.sender];
}
function claim() external {
require(allowed[msg.sender] == true, 'This address is not allowed to perform withdrawns');
uint256 _moment = moment[msg.sender];
require(BUSD.balanceOf(address(this)) >= (block.timestamp - _moment) * allowance[msg.sender], 'Not enough balance');
uint amount = _moment * allowance[msg.sender];
BUSD.transferFrom(address(this), msg.sender, amount);
allowance[msg.sender] = 0;
emit claimed(msg.sender, amount);
}
function ownerClaim(uint _amount) external onlyOwner {
BUSD.transferFrom(address(this), msg.sender, _amount);
emit ownerClaimned(_amount);
}
function ownerCheckReward(address _address) external view onlyOwner returns(uint){
return block.timestamp - moment[_address] * allowance[_address];
}
}