123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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) private contributions_;
- mapping(address => uint256) private 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);
- }
- }
|