Merge tag 'v2.1.1' of github.com:OpenZeppelin/openzeppelin-solidity

v2.1.1
This commit is contained in:
Francisco Giordano
2019-01-18 15:33:51 -03:00
237 changed files with 8562 additions and 4937 deletions

View File

@ -1,17 +1,19 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
import "../math/SafeMath.sol";
/**
* @title SplitPayment
* @title PaymentSplitter
* @dev This contract can be used when payments need to be received by a group
* of people and split proportionately to some number of shares they own.
*/
contract SplitPayment is Initializable {
contract PaymentSplitter {
using SafeMath for uint256;
event PayeeAdded(address account, uint256 shares);
event PaymentReleased(address to, uint256 amount);
event PaymentReceived(address from, uint256 amount);
uint256 private _totalShares;
uint256 private _totalReleased;
@ -22,7 +24,7 @@ contract SplitPayment is Initializable {
/**
* @dev Constructor
*/
function initialize(address[] payees, uint256[] shares) public payable initializer {
constructor (address[] memory payees, uint256[] memory shares) public payable {
require(payees.length == shares.length);
require(payees.length > 0);
@ -34,40 +36,42 @@ contract SplitPayment is Initializable {
/**
* @dev payable fallback
*/
function () external payable {}
function () external payable {
emit PaymentReceived(msg.sender, msg.value);
}
/**
* @return the total shares of the contract.
*/
function totalShares() public view returns(uint256) {
function totalShares() public view returns (uint256) {
return _totalShares;
}
/**
* @return the total amount already released.
*/
function totalReleased() public view returns(uint256) {
function totalReleased() public view returns (uint256) {
return _totalReleased;
}
/**
* @return the shares of an account.
*/
function shares(address account) public view returns(uint256) {
function shares(address account) public view returns (uint256) {
return _shares[account];
}
/**
* @return the amount already released to an account.
*/
function released(address account) public view returns(uint256) {
function released(address account) public view returns (uint256) {
return _released[account];
}
/**
* @return the address of a payee.
*/
function payee(uint256 index) public view returns(address) {
function payee(uint256 index) public view returns (address) {
return _payees[index];
}
@ -75,15 +79,11 @@ contract SplitPayment is Initializable {
* @dev Release one of the payee's proportional payment.
* @param account Whose payments will be released.
*/
function release(address account) public {
function release(address payable account) public {
require(_shares[account] > 0);
uint256 totalReceived = address(this).balance.add(_totalReleased);
uint256 payment = totalReceived.mul(
_shares[account]).div(
_totalShares).sub(
_released[account]
);
uint256 payment = totalReceived.mul(_shares[account]).div(_totalShares).sub(_released[account]);
require(payment != 0);
@ -91,6 +91,7 @@ contract SplitPayment is Initializable {
_totalReleased = _totalReleased.add(payment);
account.transfer(payment);
emit PaymentReleased(account, payment);
}
/**
@ -98,7 +99,7 @@ contract SplitPayment is Initializable {
* @param account The address of the payee to add.
* @param shares_ The number of shares owned by the payee.
*/
function _addPayee(address account, uint256 shares_) internal {
function _addPayee(address account, uint256 shares_) private {
require(account != address(0));
require(shares_ > 0);
require(_shares[account] == 0);
@ -106,7 +107,6 @@ contract SplitPayment is Initializable {
_payees.push(account);
_shares[account] = shares_;
_totalShares = _totalShares.add(shares_);
emit PayeeAdded(account, shares_);
}
uint256[50] private ______gap;
}

View File

@ -1,8 +1,8 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
import "./Escrow.sol";
import "./escrow/Escrow.sol";
/**
* @title PullPayment
@ -12,7 +12,7 @@ import "./Escrow.sol";
contract PullPayment is Initializable {
Escrow private _escrow;
function initialize() public initializer {
function initialize() internal initializer {
// conditional added to make initializer idempotent in case of diamond inheritance
if (address(_escrow) == address(0)) {
_escrow = new Escrow();
@ -24,7 +24,7 @@ contract PullPayment is Initializable {
* @dev Withdraw accumulated balance.
* @param payee Whose balance will be withdrawn.
*/
function withdrawPayments(address payee) public {
function withdrawPayments(address payable payee) public {
_escrow.withdraw(payee);
}

View File

@ -1,18 +1,13 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
import "./Escrow.sol";
/**
* @title ConditionalEscrow
* @dev Base abstract escrow to only allow withdrawal if a condition is met.
* @dev Intended usage: See Escrow.sol. Same usage guidelines apply here.
*/
contract ConditionalEscrow is Initializable, Escrow {
function initialize(address sender) public initializer {
Escrow.initialize(sender);
}
contract ConditionalEscrow is Escrow {
/**
* @dev Returns whether an address is allowed to withdraw their funds. To be
* implemented by derived contracts.
@ -20,10 +15,8 @@ contract ConditionalEscrow is Initializable, Escrow {
*/
function withdrawalAllowed(address payee) public view returns (bool);
function withdraw(address payee) public {
function withdraw(address payable payee) public {
require(withdrawalAllowed(payee));
super.withdraw(payee);
}
uint256[50] private ______gap;
}

View File

@ -1,18 +1,21 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
import "../math/SafeMath.sol";
import "../ownership/Secondary.sol";
import "../../math/SafeMath.sol";
import "../../ownership/Secondary.sol";
/**
/**
* @title Escrow
* @dev Base escrow contract, holds funds destinated to a payee until they
* withdraw them. The contract that uses the escrow as its payment method
* should be its primary, and provide public methods redirecting to the escrow's
* deposit and withdraw.
* @dev Base escrow contract, holds funds designated for a payee until they
* withdraw them.
* @dev Intended usage: This contract (and derived escrow contracts) should be a
* standalone contract, that only interacts with the contract that instantiated
* it. That way, it is guaranteed that all Ether will be handled according to
* the Escrow rules, and there is no need to check for payable functions or
* transfers in the inheritance tree. The contract that uses the escrow as its
* payment method should be its primary, and provide public methods redirecting
* to the escrow's deposit and withdraw.
*/
contract Escrow is Initializable, Secondary {
contract Escrow is Secondary {
using SafeMath for uint256;
event Deposited(address indexed payee, uint256 weiAmount);
@ -20,10 +23,6 @@ contract Escrow is Initializable, Secondary {
mapping(address => uint256) private _deposits;
function initialize(address sender) public initializer {
Secondary.initialize(sender);
}
function depositsOf(address payee) public view returns (uint256) {
return _deposits[payee];
}
@ -43,7 +42,7 @@ contract Escrow is Initializable, Secondary {
* @dev Withdraw accumulated balance for a payee.
* @param payee The address whose funds will be withdrawn and transferred to.
*/
function withdraw(address payee) public onlyPrimary {
function withdraw(address payable payee) public onlyPrimary {
uint256 payment = _deposits[payee];
_deposits[payee] = 0;
@ -52,6 +51,4 @@ contract Escrow is Initializable, Secondary {
emit Withdrawn(payee, payment);
}
uint256[50] private ______gap;
}

View File

@ -1,31 +1,32 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
import "./ConditionalEscrow.sol";
/**
* @title RefundEscrow
* @dev Escrow that holds funds for a beneficiary, deposited from multiple parties.
* The primary account may close the deposit period, and allow for either withdrawal
* by the beneficiary, or refunds to the depositors.
* @dev Escrow that holds funds for a beneficiary, deposited from multiple
* parties.
* @dev Intended usage: See Escrow.sol. Same usage guidelines apply here.
* @dev The primary account (that is, the contract that instantiates this
* contract) may deposit, close the deposit period, and allow for either
* withdrawal by the beneficiary, or refunds to the depositors. All interactions
* with RefundEscrow will be made through the primary contract. See the
* RefundableCrowdsale contract for an example of RefundEscrows use.
*/
contract RefundEscrow is Initializable, ConditionalEscrow {
contract RefundEscrow is ConditionalEscrow {
enum State { Active, Refunding, Closed }
event Closed();
event RefundsClosed();
event RefundsEnabled();
State private _state;
address private _beneficiary;
address payable private _beneficiary;
/**
* @dev Constructor.
* @param beneficiary The beneficiary of the deposits.
*/
function initialize(address beneficiary, address sender) public initializer {
ConditionalEscrow.initialize(sender);
constructor (address payable beneficiary) public {
require(beneficiary != address(0));
_beneficiary = beneficiary;
_state = State.Active;
@ -61,7 +62,7 @@ contract RefundEscrow is Initializable, ConditionalEscrow {
function close() public onlyPrimary {
require(_state == State.Active);
_state = State.Closed;
emit Closed();
emit RefundsClosed();
}
/**
@ -82,11 +83,10 @@ contract RefundEscrow is Initializable, ConditionalEscrow {
}
/**
* @dev Returns whether refundees can withdraw their deposits (be refunded).
* @dev Returns whether refundees can withdraw their deposits (be refunded). The overriden function receives a
* 'payee' argument, but we ignore it here since the condition is global, not per-payee.
*/
function withdrawalAllowed(address payee) public view returns (bool) {
function withdrawalAllowed(address) public view returns (bool) {
return _state == State.Refunding;
}
uint256[50] private ______gap;
}