-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoredTownTokenDistributor.sol
71 lines (61 loc) · 2.38 KB
/
BoredTownTokenDistributor.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract BoredTownTokenDistributor is Ownable {
IERC20 public token;
mapping(address => uint256) public claimableTokens;
uint256 public totalClaimable = 0;
bool public claimEnabled = false;
uint256 public claimLimit = 15_000000000000000000; // 15
// events
event CanClaim(address indexed recipient, uint256 amount);
event HasClaimed(address indexed recipient, uint256 amount);
event Withdrawal(address indexed recipient, uint256 amount);
// setup contract (owner)
function setToken(address newToken) external onlyOwner {
token = IERC20(newToken);
}
function setClaimLimit(uint256 newLimit) external onlyOwner {
claimLimit = newLimit;
}
function setRecipients(address[] calldata _recipients, uint256[] calldata _claimableAmount)
external
onlyOwner
{
require(
_recipients.length == _claimableAmount.length, "invalid array length"
);
uint256 sum = totalClaimable;
for (uint256 i = 0; i < _recipients.length; i++) {
claimableTokens[_recipients[i]] = _claimableAmount[i];
emit CanClaim(_recipients[i], _claimableAmount[i]);
unchecked {
sum += _claimableAmount[i];
}
}
totalClaimable = sum;
}
function toggleClaim() external onlyOwner {
claimEnabled = !claimEnabled;
}
function resetTotalClaimable() external onlyOwner {
totalClaimable = 0;
}
function withdraw(uint256 amount) external onlyOwner {
require(token.transfer(msg.sender, amount), "fail transfer token");
emit Withdrawal(msg.sender, amount);
}
// claim token
function claim() external {
require(claimEnabled, "claim is not enabled");
uint256 amount = claimableTokens[msg.sender];
require(amount > 0, "nothing to claim");
require(amount <= claimLimit, "over claim limit");
require(amount <= token.balanceOf(address(this)), "not enough token");
claimableTokens[msg.sender] = 0;
// we don't use safeTransfer since impl is assumed to be OZ
require(token.transfer(msg.sender, amount), "fail token transfer");
emit HasClaimed(msg.sender, amount);
}
}