-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathReservationFund.sol
109 lines (88 loc) · 3.45 KB
/
ReservationFund.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
107
108
109
pragma solidity ^0.4.21;
import './fund/ICrowdsaleReservationFund.sol';
import './ISimpleCrowdsale.sol';
import './ownership/Ownable.sol';
import './math/SafeMath.sol';
contract ReservationFund is ICrowdsaleReservationFund, Ownable, SafeMath {
bool public crowdsaleFinished = false;
mapping(address => uint256) contributions;
mapping(address => uint256) tokensToIssue;
mapping(address => uint256) bonusTokensToIssue;
ISimpleCrowdsale public crowdsale;
event RefundPayment(address contributor, uint256 etherAmount);
event TransferToFund(address contributor, uint256 etherAmount);
event FinishCrowdsale();
function ReservationFund(address _owner) public Ownable(_owner) {
}
modifier onlyCrowdsale() {
require(msg.sender == address(crowdsale));
_;
}
function setCrowdsaleAddress(address crowdsaleAddress) public onlyOwner {
require(crowdsale == address(0));
crowdsale = ISimpleCrowdsale(crowdsaleAddress);
}
function onCrowdsaleEnd() external onlyCrowdsale {
crowdsaleFinished = true;
FinishCrowdsale();
}
function canCompleteContribution(address contributor) external returns(bool) {
if(crowdsaleFinished) {
return false;
}
if(!crowdsale.isContributorInLists(contributor)) {
return false;
}
if(contributions[contributor] == 0) {
return false;
}
return true;
}
/**
* @dev Function to check contributions by address
*/
function contributionsOf(address contributor) external returns(uint256) {
return contributions[contributor];
}
/**
* @dev Process crowdsale contribution without whitelist
*/
function processContribution(
address contributor,
uint256 _tokensToIssue,
uint256 _bonusTokensToIssue
) external payable onlyCrowdsale {
contributions[contributor] = safeAdd(contributions[contributor], msg.value);
tokensToIssue[contributor] = safeAdd(tokensToIssue[contributor], _tokensToIssue);
bonusTokensToIssue[contributor] = safeAdd(bonusTokensToIssue[contributor], _bonusTokensToIssue);
}
/**
* @dev Complete contribution after if user is whitelisted
*/
function completeContribution(address contributor) external {
require(!crowdsaleFinished);
require(crowdsale.isContributorInLists(contributor));
require(contributions[contributor] > 0);
uint256 etherAmount = contributions[contributor];
uint256 tokenAmount = tokensToIssue[contributor];
uint256 tokenBonusAmount = bonusTokensToIssue[contributor];
contributions[contributor] = 0;
tokensToIssue[contributor] = 0;
bonusTokensToIssue[contributor] = 0;
crowdsale.processReservationFundContribution.value(etherAmount)(contributor, tokenAmount, tokenBonusAmount);
TransferToFund(contributor, etherAmount);
}
/**
* @dev Refund payments if crowdsale is finalized
*/
function refundPayment(address contributor) public {
require(crowdsaleFinished);
require(contributions[contributor] > 0 || tokensToIssue[contributor] > 0);
uint256 amountToRefund = contributions[contributor];
contributions[contributor] = 0;
tokensToIssue[contributor] = 0;
bonusTokensToIssue[contributor] = 0;
contributor.transfer(amountToRefund);
RefundPayment(contributor, amountToRefund);
}
}