Skip to content

Add reputation admin scheme #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions contracts/schemes/ReputationAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
pragma solidity 0.6.10;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "../controller/Controller.sol";
import "./ArcScheme.sol";

/**
* @title A scheme for reputation minting/burning by an authorized account
*/

contract ReputationAdmin is OwnableUpgradeSafe, ArcScheme {
using SafeMath for uint256;

uint256 public activationStartTime;
uint256 public activationEndTime;
uint256 public repRewardLeft;
uint256 public limitRepReward;

/**
* @dev initialize
* @param _avatar the avatar to mint reputation from
* @param _activationStartTime start time for allowing minting
* @param _activationEndTime end time for allowing minting
* @param _maxRepReward maximum reputation mintable by this scheme
*/
function initialize(
Avatar _avatar,
uint256 _activationStartTime,
uint256 _activationEndTime,
uint256 _maxRepReward,
address _owner
) external {
require(_activationStartTime < _activationEndTime, "_activationStartTime < _activationEndTime");
super._initialize(_avatar);
activationStartTime = _activationStartTime;
activationEndTime = _activationEndTime;
repRewardLeft = _maxRepReward;
limitRepReward = _maxRepReward;
__Ownable_init_unchained();
transferOwnership(_owner);
}

/**
* @dev reputationBurn function
* @param _beneficiaries the beneficiaries address to mint reputation from
* @param _amounts the amounts of reputation to mint for beneficiaries
*/
function reputationMint(address[] calldata _beneficiaries, uint256[] calldata _amounts) external onlyOwner {
require(_beneficiaries.length == _amounts.length, "Arrays length mismatch");
for (uint256 i=0; i < _beneficiaries.length; i++) {
_reputationMint(_beneficiaries[i], _amounts[i]);
}
}

/**
* @dev reputationBurn function
* @param _beneficiaries the beneficiaries address to burm reputation from
* @param _amounts the amounts of reputation to burn for beneficiaries
*/
function reputationBurn(address[] calldata _beneficiaries, uint256[] calldata _amounts) external onlyOwner {
require(_beneficiaries.length == _amounts.length, "Arrays length mismatch");
for (uint256 i=0; i < _beneficiaries.length; i++) {
_reputationBurn(_beneficiaries[i], _amounts[i]);
}
}

/**
* @dev reputationMint function
* @param _beneficiary the beneficiary address to mint reputation for
* @param _amount the amount of reputation to mint the the beneficirary
*/
function _reputationMint(address _beneficiary, uint256 _amount) private {
// solhint-disable-next-line not-rely-on-time
require(now >= activationStartTime, "Minting period did not start yet");
// solhint-disable-next-line not-rely-on-time
require(now < activationEndTime, "Minting period ended.");

if (limitRepReward > 0) {
repRewardLeft = repRewardLeft.sub(_amount);
}

require(
Controller(avatar.owner()).mintReputation(_amount, _beneficiary),
"Minting reputation should succeed"
);
}

/**
* @dev reputationBurn function
* @param _beneficiary the beneficiary address to burm reputation from
* @param _amount the amount of reputation to burn for a beneficirary
*/
function _reputationBurn(address _beneficiary, uint256 _amount) private {
// solhint-disable-next-line not-rely-on-time
require(now >= activationStartTime, "Burning period did not start yet");
// solhint-disable-next-line not-rely-on-time
require(now < activationEndTime, "Burning period ended.");

if (limitRepReward > 0) {
require(_amount <= limitRepReward.sub(repRewardLeft), "Cannot burn more than minted");
repRewardLeft = repRewardLeft.add(_amount);
}

require(
Controller(avatar.owner()).burnReputation(_amount, _beneficiary),
"Burn reputation should succeed"
);
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc-experimental",
"version": "0.1.2-rc.1",
"version": "0.1.2-rc.2",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand Down
3 changes: 3 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ARCVotingMachineCallbacksMock = artifacts.require("./ARCVotingMachineCallb
const JoinAndQuit = artifacts.require("./JoinAndQuit.sol");
const FundingRequest = artifacts.require("./FundingRequest.sol");
const Dictator = artifacts.require("./Dictator.sol");
const ReputationAdmin = artifacts.require("./ReputationAdmin.sol");


const MAX_UINT_256 = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
Expand Down Expand Up @@ -157,6 +158,7 @@ const SOME_ADDRESS = '0x1000000000000000000000000000000000000000';
registration.fundingRequest = await FundingRequest.new();
registration.rewarderMock = await RewarderMock.new();
registration.dictator = await Dictator.new();
registration.reputationAdmin = await ReputationAdmin.new();


await implementationDirectory.setImplementation("DAOToken",registration.daoToken.address);
Expand Down Expand Up @@ -188,6 +190,7 @@ const SOME_ADDRESS = '0x1000000000000000000000000000000000000000';
await implementationDirectory.setImplementation("JoinAndQuit",registration.joinAndQuit.address);
await implementationDirectory.setImplementation("FundingRequest",registration.fundingRequest.address);
await implementationDirectory.setImplementation("Dictator",registration.dictator.address);
await implementationDirectory.setImplementation("ReputationAdmin",registration.reputationAdmin.address);


registration.implementationDirectory = implementationDirectory;
Expand Down
Loading