12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- pragma solidity ^0.4.24;
- import "../../math/SafeMath.sol";
- import "../Crowdsale.sol";
- import "../../ownership/Ownable.sol";
- /**
- * @title IndividuallyCappedCrowdsale
- * @dev Crowdsale with per-user caps.
- */
- contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
- using SafeMath for uint256;
- mapping(address => uint256) public contributions;
- mapping(address => uint256) public caps;
- /**
- * @dev Sets a specific user's maximum contribution.
- * @param _beneficiary Address to be capped
- * @param _cap Wei limit for individual contribution
- */
- function setUserCap(address _beneficiary, uint256 _cap) external onlyOwner {
- caps[_beneficiary] = _cap;
- }
- /**
- * @dev Sets a group of users' maximum contribution.
- * @param _beneficiaries List of addresses to be capped
- * @param _cap Wei limit for individual contribution
- */
- function setGroupCap(
- address[] _beneficiaries,
- uint256 _cap
- )
- external
- onlyOwner
- {
- for (uint256 i = 0; i < _beneficiaries.length; i++) {
- caps[_beneficiaries[i]] = _cap;
- }
- }
- /**
- * @dev Returns the cap of a specific user.
- * @param _beneficiary Address whose cap is to be checked
- * @return Current cap for individual user
- */
- function getUserCap(address _beneficiary) public view returns (uint256) {
- return caps[_beneficiary];
- }
- /**
- * @dev Returns the amount contributed so far by a sepecific user.
- * @param _beneficiary Address of contributor
- * @return User contribution so far
- */
- function getUserContribution(address _beneficiary)
- public view returns (uint256)
- {
- return contributions[_beneficiary];
- }
- /**
- * @dev Extend parent behavior requiring purchase to respect the user's funding cap.
- * @param _beneficiary Token purchaser
- * @param _weiAmount Amount of wei contributed
- */
- function _preValidatePurchase(
- address _beneficiary,
- uint256 _weiAmount
- )
- internal
- {
- super._preValidatePurchase(_beneficiary, _weiAmount);
- require(contributions[_beneficiary].add(_weiAmount) <= caps[_beneficiary]);
- }
- /**
- * @dev Extend parent behavior to update user contributions
- * @param _beneficiary Token purchaser
- * @param _weiAmount Amount of wei contributed
- */
- function _updatePurchasingState(
- address _beneficiary,
- uint256 _weiAmount
- )
- internal
- {
- super._updatePurchasingState(_beneficiary, _weiAmount);
- contributions[_beneficiary] = contributions[_beneficiary].add(_weiAmount);
- }
- }
|