Skip to content
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

Migrate Ownable to Roles #1287

Merged
merged 5 commits into from
Sep 6, 2018
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
1 change: 1 addition & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"rules": {
"error-reason": "off",
"indentation": ["error", 2],
"lbrace": "off",
"linebreak-style": ["error", "unix"],
"max-len": ["error", 79],
"no-constant": ["error"],
Expand Down
94 changes: 0 additions & 94 deletions contracts/access/Whitelist.sol

This file was deleted.

35 changes: 35 additions & 0 deletions contracts/access/rbac/CapperRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.4.24;

import "./Roles.sol";


contract CapperRole {
using Roles for Roles.Role;

Roles.Role private cappers;

constructor() public {
cappers.add(msg.sender);
}

modifier onlyCapper() {
require(isCapper(msg.sender));
_;
}

function isCapper(address _account) public view returns (bool) {
return cappers.has(_account);
}

function addCapper(address _account) public onlyCapper {
cappers.add(_account);
}

function renounceCapper() public {
cappers.remove(msg.sender);
}

function _removeCapper(address _account) internal {
cappers.remove(_account);
}
}
11 changes: 5 additions & 6 deletions contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
pragma solidity ^0.4.24;

import "../../math/SafeMath.sol";
import "../../ownership/Ownable.sol";
import "../validation/TimedCrowdsale.sol";


/**
* @title FinalizableCrowdsale
* @dev Extension of Crowdsale where an owner can do extra work
* after finishing.
* @dev Extension of Crowdsale with a one-off finalization action, where one
* can do extra work after finishing.
*/
contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
contract FinalizableCrowdsale is TimedCrowdsale {
using SafeMath for uint256;

bool private finalized_ = false;
Expand All @@ -20,15 +19,15 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
/**
* @return true if the crowdsale is finalized, false otherwise.
*/
function finalized() public view returns(bool) {
function finalized() public view returns (bool) {
return finalized_;
}

/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() public onlyOwner {
function finalize() public {
require(!finalized_);
require(hasClosed());

Expand Down
2 changes: 1 addition & 1 deletion contracts/crowdsale/distribution/RefundableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
}

/**
* @dev escrow finalization task, called when owner calls finalize()
* @dev escrow finalization task, called when finalize() is called
*/
function _finalization() internal {
if (goalReached()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ pragma solidity ^0.4.24;

import "../../math/SafeMath.sol";
import "../Crowdsale.sol";
import "../../ownership/Ownable.sol";
import "../../access/rbac/CapperRole.sol";


/**
* @title IndividuallyCappedCrowdsale
* @dev Crowdsale with per-user caps.
*/
contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
using SafeMath for uint256;

mapping(address => uint256) private contributions_;
Expand All @@ -20,7 +20,7 @@ contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
* @param _beneficiary Address to be capped
* @param _cap Wei limit for individual contribution
*/
function setUserCap(address _beneficiary, uint256 _cap) external onlyOwner {
function setUserCap(address _beneficiary, uint256 _cap) external onlyCapper {
caps_[_beneficiary] = _cap;
}

Expand All @@ -34,7 +34,7 @@ contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
uint256 _cap
)
external
onlyOwner
onlyCapper
{
for (uint256 i = 0; i < _beneficiaries.length; i++) {
caps_[_beneficiaries[i]] = _cap;
Expand Down
27 changes: 0 additions & 27 deletions contracts/crowdsale/validation/WhitelistedCrowdsale.sol

This file was deleted.

18 changes: 18 additions & 0 deletions contracts/mocks/CapperRoleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.4.24;

import "../access/rbac/CapperRole.sol";


contract CapperRoleMock is CapperRole {
function removeCapper(address _account) public {
_removeCapper(_account);
}

function onlyCapperMock() public view onlyCapper {
}

// Causes a compilation error if super._removeCapper is not internal
function _removeCapper(address _account) internal {
super._removeCapper(_account);
}
}
7 changes: 4 additions & 3 deletions contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ pragma solidity ^0.4.24;

import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
import "./CapperRoleMock.sol";


contract IndividuallyCappedCrowdsaleImpl is IndividuallyCappedCrowdsale {
contract IndividuallyCappedCrowdsaleImpl
is IndividuallyCappedCrowdsale, CapperRoleMock {

constructor (
constructor(
uint256 _rate,
address _wallet,
IERC20 _token
Expand All @@ -15,5 +17,4 @@ contract IndividuallyCappedCrowdsaleImpl is IndividuallyCappedCrowdsale {
Crowdsale(_rate, _wallet, _token)
{
}

}
14 changes: 0 additions & 14 deletions contracts/mocks/WhitelistMock.sol

This file was deleted.

19 changes: 0 additions & 19 deletions contracts/mocks/WhitelistedCrowdsaleImpl.sol

This file was deleted.

14 changes: 7 additions & 7 deletions contracts/payment/RefundEscrow.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pragma solidity ^0.4.23;

import "./ConditionalEscrow.sol";
import "../ownership/Ownable.sol";
import "../ownership/Secondary.sol";


/**
* @title RefundEscrow
* @dev Escrow that holds funds for a beneficiary, deposited from multiple parties.
* The contract owner may close the deposit period, and allow for either withdrawal
* The primary account may close the deposit period, and allow for either withdrawal
* by the beneficiary, or refunds to the depositors.
*/
contract RefundEscrow is Ownable, ConditionalEscrow {
contract RefundEscrow is Secondary, ConditionalEscrow {
enum State { Active, Refunding, Closed }

event Closed();
Expand All @@ -32,14 +32,14 @@ contract RefundEscrow is Ownable, ConditionalEscrow {
/**
* @return the current state of the escrow.
*/
function state() public view returns(State) {
function state() public view returns (State) {
return state_;
}

/**
* @return the beneficiary of the escrow.
*/
function beneficiary() public view returns(address) {
function beneficiary() public view returns (address) {
return beneficiary_;
}

Expand All @@ -56,7 +56,7 @@ contract RefundEscrow is Ownable, ConditionalEscrow {
* @dev Allows for the beneficiary to withdraw their funds, rejecting
* further deposits.
*/
function close() public onlyOwner {
function close() public onlyPrimary {
require(state_ == State.Active);
state_ = State.Closed;
emit Closed();
Expand All @@ -65,7 +65,7 @@ contract RefundEscrow is Ownable, ConditionalEscrow {
/**
* @dev Allows for refunds to take place, rejecting further deposits.
*/
function enableRefunds() public onlyOwner {
function enableRefunds() public onlyPrimary {
require(state_ == State.Active);
state_ = State.Refunding;
emit RefundsEnabled();
Expand Down
Loading