-
Notifications
You must be signed in to change notification settings - Fork 1
/
LibCrowdsale.sol
81 lines (65 loc) · 1.81 KB
/
LibCrowdsale.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
pragma solidity >=0.4.22 <0.6.0;
pragma experimental ABIEncoderV2;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
contract LibCrowdsale {
using SafeMath for uint256;
struct Crowdsale {
uint256 startBlock;
uint256 endBlock;
uint256 hardCap;
uint256 leftAmount;
uint256 tokenRatio;
uint256 minContribution;
uint256 maxContribution;
uint256 weiRaised;
address wallet;
}
enum ContributionStatus {
CROWDSALE_NOT_OPEN,
MIN_CONTRIBUTION,
MAX_CONTRIBUTION,
HARDCAP_REACHED,
VALID
}
enum CrowdsaleStatus {
INVALID_START_BLOCK,
INVALID_END_BLOCK,
INVALID_TOKEN_RATIO,
INVALID_LEFT_AMOUNT,
VALID
}
function getCrowdsaleStatus(Crowdsale memory crowdsale)
public
view
returns (CrowdsaleStatus)
{
if(crowdsale.startBlock < block.number) {
return CrowdsaleStatus.INVALID_START_BLOCK;
}
if(crowdsale.endBlock < crowdsale.startBlock) {
return CrowdsaleStatus.INVALID_END_BLOCK;
}
if(crowdsale.tokenRatio == 0) {
return CrowdsaleStatus.INVALID_TOKEN_RATIO;
}
uint256 tokenForSale = crowdsale.hardCap.mul(crowdsale.tokenRatio);
if(tokenForSale != crowdsale.leftAmount) {
return CrowdsaleStatus.INVALID_LEFT_AMOUNT;
}
return CrowdsaleStatus.VALID;
}
function isOpened(uint256 startBlock, uint256 endBlock)
internal
view
returns (bool)
{
return (block.number >= startBlock && block.number <= endBlock);
}
function isFinished(uint256 endBlock)
internal
view
returns (bool)
{
return block.number > endBlock;
}
}