-
Notifications
You must be signed in to change notification settings - Fork 0
/
Presale.sol
106 lines (80 loc) · 2.72 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
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
100
101
102
103
104
105
106
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.5;
import "./IERC20Mintable.sol";
import "./IERC20Burnable.sol";
import "./FullMath.sol";
import "./SafeERC20.sol";
import "./Ownable.sol";
contract Presale is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
address public aSBR;
address public MIM;
address public addressToSendMIM;
uint256 public endOfSale;
uint256 public saleStartTimestamp;
uint256 public purchaseMIMAmount; // This is 30 MIM
uint256 public allocatedaSBRPerUser; // This is hardcoded to be 100 aSBR
mapping(address => bool) public boughtSBR;
mapping(address => bool) public whiteListed;
function whiteListBuyers(address[] memory _buyers)
external
onlyOwner()
returns (bool)
{
for (uint256 i; i < _buyers.length; i++) {
whiteListed[_buyers[i]] = true;
}
return true;
}
function initialize(
address _addressToSendMIM,
address _aSBR,
address _MIM,
uint256 _saleLength,
uint256 _purchaseMIMAmount,
uint256 _allocatedaSBRPerUser,
uint256 _saleStartTimestamp
) external onlyOwner() returns (bool) {
require(saleStarted() == false, "Already initialized");
aSBR = _aSBR;
MIM = _MIM;
endOfSale = _saleLength.add(_saleStartTimestamp);
saleStartTimestamp = _saleStartTimestamp;
purchaseMIMAmount = _purchaseMIMAmount;
addressToSendMIM = _addressToSendMIM;
allocatedaSBRPerUser = _allocatedaSBRPerUser;
return true;
}
function saleStarted() public view returns (bool){
if (saleStartTimestamp != 0){
return block.timestamp > saleStartTimestamp;
} else{
return false;
}
}
function purchaseaSBRWithMIM() external returns (bool) {
require(saleStarted() == true, "Not started");
require(whiteListed[msg.sender] == true, "Not whitelisted");
require(boughtSBR[msg.sender] == false, "Already participated");
require(block.timestamp < endOfSale, "Sale over");
boughtSBR[msg.sender] = true;
IERC20(MIM).safeTransferFrom(msg.sender, addressToSendMIM, purchaseMIMAmount);
IERC20(aSBR).safeTransfer(msg.sender, allocatedaSBRPerUser);
return true;
}
/**
* @notice Burn the remaining aSBR
* @return true if it works
*/
function burnRemainingaSBR()
external
onlyOwner()
returns (bool)
{
require(saleStarted() == true, "Not started");
require(block.timestamp >= endOfSale, "Not ended");
IERC20Burnable(aSBR).burn(IERC20(aSBR).balanceOf(address(this)));
return true;
}
}