Skip to content

Commit

Permalink
Merge branch 'rbac-migration' of github.com:OpenZeppelin/openzeppelin…
Browse files Browse the repository at this point in the history
…-solidity into feat/mintable-erc721
  • Loading branch information
frangio committed Sep 6, 2018
2 parents 3948f46 + bf4a211 commit 3e181f2
Show file tree
Hide file tree
Showing 81 changed files with 904 additions and 1,077 deletions.
22 changes: 9 additions & 13 deletions contracts/access/rbac/MinterRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@ contract MinterRole {

Roles.Role private minters;

constructor(address[] _minters) public {
minters.addMany(_minters);
constructor() public {
minters.add(msg.sender);
}

function transferMinter(address _account) public {
minters.transfer(_account);
}

function renounceMinter() public {
minters.renounce();
modifier onlyMinter() {
require(isMinter(msg.sender));
_;
}

function isMinter(address _account) public view returns (bool) {
return minters.has(_account);
}

modifier onlyMinter() {
require(isMinter(msg.sender));
_;
function addMinter(address _account) public onlyMinter {
minters.add(_account);
}

function _addMinter(address _account) internal {
minters.add(_account);
function renounceMinter() public {
minters.remove(msg.sender);
}

function _removeMinter(address _account) internal {
Expand Down
35 changes: 35 additions & 0 deletions contracts/access/rbac/PauserRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.4.24;

import "./Roles.sol";


contract PauserRole {
using Roles for Roles.Role;

Roles.Role private pausers;

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

modifier onlyPauser() {
require(isPauser(msg.sender));
_;
}

function isPauser(address _account) public view returns (bool) {
return pausers.has(_account);
}

function addPauser(address _account) public onlyPauser {
pausers.add(_account);
}

function renouncePauser() public {
pausers.remove(msg.sender);
}

function _removePauser(address _account) internal {
pausers.remove(_account);
}
}
22 changes: 0 additions & 22 deletions contracts/access/rbac/Roles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,13 @@ library Roles {
_role.bearer[_account] = true;
}

/**
* @dev give multiple accounts access to this role
*/
function addMany(Role storage _role, address[] _accounts) internal {
for (uint256 i = 0; i < _accounts.length; ++i) {
add(_role, _accounts[i]);
}
}

/**
* @dev remove an account's access to this role
*/
function remove(Role storage _role, address _account) internal {
_role.bearer[_account] = false;
}

function transfer(Role storage _role, address _account) internal {
require(_account != address(0));
require(!has(_role, _account));
require(has(_role, msg.sender));

remove(_role, msg.sender);
add(_role, _account);
}

function renounce(Role storage _role) internal {
remove(_role, msg.sender);
}

/**
* @dev check if an account has this role
* @return bool
Expand Down
18 changes: 13 additions & 5 deletions contracts/bounties/BreakInvariantBounty.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ import "../ownership/Ownable.sol";
* @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
*/
contract BreakInvariantBounty is PullPayment, Ownable {
bool public claimed;
mapping(address => address) public researchers;
bool private claimed_;
mapping(address => address) private researchers;

event TargetCreated(address createdAddress);

/**
* @dev Fallback function allowing the contract to receive funds, if they haven't already been claimed.
*/
function() external payable {
require(!claimed);
require(!claimed_);
}

/**
* @dev Determine if the bounty was claimed.
* @return true if the bounty was claimed, false otherwise.
*/
function claimed() public view returns(bool) {
return claimed_;
}

/**
Expand All @@ -44,14 +52,14 @@ contract BreakInvariantBounty is PullPayment, Ownable {
// Check Target contract invariants
require(!_target.checkInvariant());
_asyncTransfer(researcher, address(this).balance);
claimed = true;
claimed_ = true;
}

/**
* @dev Transfers the current balance to the owner and terminates the contract.
*/
function destroy() public onlyOwner {
selfdestruct(owner);
selfdestruct(owner());
}

/**
Expand Down
55 changes: 43 additions & 12 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ contract Crowdsale {
using SafeERC20 for IERC20;

// The token being sold
IERC20 public token;
IERC20 private token_;

// Address where funds are collected
address public wallet;
address private wallet_;

// How many token units a buyer gets per wei.
// The rate is the conversion between wei and the smallest and indivisible token unit.
// So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK
// 1 wei will give you 1 unit, or 0.001 TOK.
uint256 public rate;
uint256 private rate_;

// Amount of wei raised
uint256 public weiRaised;
uint256 private weiRaised_;

/**
* Event for token purchase logging
Expand All @@ -52,6 +52,9 @@ contract Crowdsale {

/**
* @param _rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
Expand All @@ -60,9 +63,9 @@ contract Crowdsale {
require(_wallet != address(0));
require(_token != address(0));

rate = _rate;
wallet = _wallet;
token = _token;
rate_ = _rate;
wallet_ = _wallet;
token_ = _token;
}

// -----------------------------------------
Expand All @@ -76,6 +79,34 @@ contract Crowdsale {
buyTokens(msg.sender);
}

/**
* @return the token being sold.
*/
function token() public view returns(IERC20) {
return token_;
}

/**
* @return the address where funds are collected.
*/
function wallet() public view returns(address) {
return wallet_;
}

/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns(uint256) {
return rate_;
}

/**
* @return the mount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return weiRaised_;
}

/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
Expand All @@ -89,7 +120,7 @@ contract Crowdsale {
uint256 tokens = _getTokenAmount(weiAmount);

// update state
weiRaised = weiRaised.add(weiAmount);
weiRaised_ = weiRaised_.add(weiAmount);

_processPurchase(_beneficiary, tokens);
emit TokensPurchased(
Expand All @@ -113,7 +144,7 @@ contract Crowdsale {
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(_beneficiary, _weiAmount);
* require(weiRaised.add(_weiAmount) <= cap);
* require(weiRaised().add(_weiAmount) <= cap);
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
Expand Down Expand Up @@ -152,7 +183,7 @@ contract Crowdsale {
)
internal
{
token.safeTransfer(_beneficiary, _tokenAmount);
token_.safeTransfer(_beneficiary, _tokenAmount);
}

/**
Expand Down Expand Up @@ -191,13 +222,13 @@ contract Crowdsale {
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate);
return _weiAmount.mul(rate_);
}

/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
wallet.transfer(msg.value);
wallet_.transfer(msg.value);
}
}
13 changes: 10 additions & 3 deletions contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@ import "../validation/TimedCrowdsale.sol";
contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
using SafeMath for uint256;

bool public isFinalized = false;
bool private finalized_ = false;

event CrowdsaleFinalized();

/**
* @return true if the crowdsale is finalized, false otherwise.
*/
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 {
require(!isFinalized);
require(!finalized_);
require(hasClosed());

_finalization();
emit CrowdsaleFinalized();

isFinalized = true;
finalized_ = true;
}

/**
Expand Down
20 changes: 14 additions & 6 deletions contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ import "../../math/SafeMath.sol";
contract PostDeliveryCrowdsale is TimedCrowdsale {
using SafeMath for uint256;

mapping(address => uint256) public balances;
mapping(address => uint256) private balances_;

/**
* @dev Withdraw tokens only after crowdsale ends.
* @param _beneficiary Whose tokens will be withdrawn.
*/
function withdrawTokens() public {
function withdrawTokens(address _beneficiary) public {
require(hasClosed());
uint256 amount = balances[msg.sender];
uint256 amount = balances_[_beneficiary];
require(amount > 0);
balances[msg.sender] = 0;
_deliverTokens(msg.sender, amount);
balances_[_beneficiary] = 0;
_deliverTokens(_beneficiary, amount);
}

/**
* @return the balance of an account.
*/
function balanceOf(address _account) public view returns(uint256) {
return balances_[_account];
}

/**
Expand All @@ -36,7 +44,7 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
)
internal
{
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
balances_[_beneficiary] = balances_[_beneficiary].add(_tokenAmount);
}

}
Loading

0 comments on commit 3e181f2

Please sign in to comment.