You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
pragma solidity ^0.5.2;
|
|
|
|
import "../../math/SafeMath.sol";
|
|
import "../Crowdsale.sol";
|
|
|
|
/**
|
|
* @title CappedCrowdsale
|
|
* @dev Crowdsale with a limit for total contributions.
|
|
*/
|
|
contract CappedCrowdsale is Crowdsale {
|
|
using SafeMath for uint256;
|
|
|
|
uint256 private _cap;
|
|
|
|
/**
|
|
* @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
|
|
* @param cap Max amount of wei to be contributed
|
|
*/
|
|
constructor (uint256 cap) public {
|
|
require(cap > 0);
|
|
_cap = cap;
|
|
}
|
|
|
|
/**
|
|
* @return the cap of the crowdsale.
|
|
*/
|
|
function cap() public view returns (uint256) {
|
|
return _cap;
|
|
}
|
|
|
|
/**
|
|
* @dev Checks whether the cap has been reached.
|
|
* @return Whether the cap was reached
|
|
*/
|
|
function capReached() public view returns (bool) {
|
|
return weiRaised() >= _cap;
|
|
}
|
|
|
|
/**
|
|
* @dev Extend parent behavior requiring purchase to respect the funding cap.
|
|
* @param beneficiary Token purchaser
|
|
* @param weiAmount Amount of wei contributed
|
|
*/
|
|
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
|
|
super._preValidatePurchase(beneficiary, weiAmount);
|
|
require(weiRaised().add(weiAmount) <= _cap);
|
|
}
|
|
}
|
|
|