|
| 1 | +pragma solidity 0.5.13; |
| 2 | + |
| 3 | +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; |
| 4 | +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; |
| 5 | +import "../controller/Controller.sol"; |
| 6 | + |
| 7 | +/** |
| 8 | + * @title A scheme for reputation allocation by an authorized account |
| 9 | + */ |
| 10 | + |
| 11 | +contract AuthorizedMintRep is Ownable { |
| 12 | + using SafeMath for uint256; |
| 13 | + |
| 14 | + Avatar public avatar; |
| 15 | + uint256 public activationStartTime; |
| 16 | + uint256 public activationEndTime; |
| 17 | + uint256 public repRewardLeft; |
| 18 | + bool public limitRepReward; |
| 19 | + |
| 20 | + /** |
| 21 | + * @dev initialize |
| 22 | + * @param _avatar the avatar to mint reputation from |
| 23 | + * @param _activationStartTime start time for allowing minting |
| 24 | + * @param _activationEndTime end time for allowing minting |
| 25 | + * @param _maxRepReward maximum reputation mintable by this scheme |
| 26 | + */ |
| 27 | + function initialize( |
| 28 | + Avatar _avatar, |
| 29 | + uint256 _activationStartTime, |
| 30 | + uint256 _activationEndTime, |
| 31 | + uint256 _maxRepReward |
| 32 | + ) external onlyOwner { |
| 33 | + require(avatar == Avatar(0), "can be called only one time"); |
| 34 | + require(_avatar != Avatar(0), "avatar cannot be zero"); |
| 35 | + require(_activationStartTime < _activationEndTime, "_activationStartTime < _activationEndTime"); |
| 36 | + avatar = _avatar; |
| 37 | + activationStartTime = _activationStartTime; |
| 38 | + activationEndTime = _activationEndTime; |
| 39 | + repRewardLeft = _maxRepReward; |
| 40 | + limitRepReward = _maxRepReward != 0; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @dev reputationMint function |
| 45 | + * @param _beneficiary the beneficiary address to mint reputation for |
| 46 | + * @param _amount the amount of reputation to mint the the beneficirary |
| 47 | + */ |
| 48 | + function reputationMint(address _beneficiary, uint256 _amount) external onlyOwner { |
| 49 | + // solhint-disable-next-line not-rely-on-time |
| 50 | + require(now >= activationStartTime, "Minting period did not start yet"); |
| 51 | + // solhint-disable-next-line not-rely-on-time |
| 52 | + require(now < activationEndTime, "Minting period ended."); |
| 53 | + |
| 54 | + if (limitRepReward) { |
| 55 | + repRewardLeft = repRewardLeft.sub(_amount); |
| 56 | + } |
| 57 | + |
| 58 | + require( |
| 59 | + Controller(avatar.owner()).mintReputation(_amount, _beneficiary, address(avatar)), |
| 60 | + "Minting reputation should succeed" |
| 61 | + ); |
| 62 | + } |
| 63 | +} |
0 commit comments