Skip to content

Commit

Permalink
Add ERC20 support to SplitPayment (OpenZeppelin#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
pw94 committed Apr 21, 2018
1 parent 77cc33f commit 3e3255f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/payment/SplitPayment.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.4.21;

import "../math/SafeMath.sol";
import "../token/ERC20/ERC20.sol";


/**
Expand Down Expand Up @@ -54,6 +55,26 @@ contract SplitPayment {
payee.transfer(payment);
}

/**
* @dev Claim your share of the balance through ERC20 token.
*/
function claim(ERC20 token) public {
address payee = msg.sender;

require(shares[payee] > 0);

uint256 totalReceived = token.balanceOf(address(this)).add(totalReleased);
uint256 payment = totalReceived.mul(shares[payee]).div(totalShares).sub(released[payee]);

require(payment != 0);
require(token.balanceOf(address(this)) >= payment);

released[payee] = released[payee].add(payment);
totalReleased = totalReleased.add(payment);

token.transfer(payee, payment);
}

/**
* @dev Add a new payee to the contract.
* @param _payee The address of the payee to add.
Expand Down

0 comments on commit 3e3255f

Please sign in to comment.