-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_Keran.sol
More file actions
65 lines (48 loc) · 1.98 KB
/
Copy path3_Keran.sol
File metadata and controls
65 lines (48 loc) · 1.98 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
// contracts/Keran.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IERC20 {
function transfer(address to, uint256 amount) external view returns (bool);
function balanceOf(address account) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract Keran {
address payable owner;
IERC20 public token;
uint256 public withdrawalAmount = 50 * (10**10);
uint256 public lockTime = 1 minutes;
event Withdrawal(address indexed to, uint256 indexed amount);
event Deposit(address indexed from, uint256 indexed amount);
mapping(address => uint256) nextAccessTime;
constructor(address tokenAddress) payable {
token = IERC20(tokenAddress);
owner = payable(msg.sender);
}
function requestTokens() public {
require(msg.sender != address(0), "Request must not originate from a zero account");
require(token.balanceOf(address(this)) >= withdrawalAmount, "Insuficient balance in faucet for withdrawal request.");
require(block.timestamp >=nextAccessTime[msg.sender], "Insuficient time elapsed since last withdrawal - try again later.");
nextAccessTime[msg.sender] = block.timestamp + lockTime;
token.transfer(msg.sender, withdrawalAmount);
}
receive() external payable {
emit Deposit(msg.sender, msg.value);
}
function getBalance() external view returns (uint256) {
return token.balanceOf(address(this));
}
function setWithdrawalAmount(uint256 amount) public onlyOwner {
withdrawalAmount = amount * (10**10);
}
function setLockTime(uint256 amount) public onlyOwner {
lockTime = amount * 1 minutes;
}
function withdrawal() external onlyOwner {
emit Withdrawal (msg.sender, token.balanceOf(address(this)));
token.transfer(msg.sender, token.balanceOf(address(this)));
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the contract owner can call this function");
_;
}
}