-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPresale.sol
51 lines (42 loc) · 1.43 KB
/
Presale.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import './Token.sol';
contract Presale {
Token _token = Token(0x5EF6b5ABaA7e9b75Fa4DaEBF0Fc722f9AFF12B40);
address payable public _admin = payable(0x1B8bc9eb46754CC8f9a889EBBB2ece9aE9757843);
uint256 public _round;
constructor() {
_round = 0;
}
receive() external payable {
getTokens(msg.sender);
}
function getTokens(address beneficiary) public payable {
require(_round > 0, 'presale inactive');
uint256 value = msg.value * getRate();
require(value <= _token.balanceOf(address(this)), 'amount is larger than token balance');
_token.approve(beneficiary, value);
_token.transfer(beneficiary, value);
_admin.transfer(msg.value);
}
function getRate() public view returns (uint256) {
if (_round > 0) return (600000 - (_round - 1) * 100000);
return 0;
}
function withdrawAll() public {
require(msg.sender == _admin, 'not admin');
_token.approve(_admin, _token.balanceOf(address(this)));
_token.transfer(_admin, _token.balanceOf(address(this)));
}
function withdraw(uint256 amount) public {
require(msg.sender == _admin, 'not admin');
require(amount <= _token.balanceOf(address(this)), 'amount is larger than token balance');
_token.approve(_admin, amount);
_token.transfer(_admin, amount);
}
function setRound(uint256 round) public {
require(msg.sender == _admin, 'not admin');
require(round <= 3, 'round must be between 0 and 3');
_round = round;
}
}