diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b86c06763..a510853e7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* `PaymentSplitter`: refactor payment into public `releasable` functions ([#3350](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3350)) * `Clones`: optimize clone creation ([#3329](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3329)) * `TimelockController`: Migrate `_call` to `_execute` and allow inheritance and overriding similar to `Governor`. ([#3317](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3317)) * `CrossChainEnabledPolygonChild`: replace the `require` statement with the custom error `NotCrossChainCall`. ([#3380](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3380)) diff --git a/contracts/finance/PaymentSplitter.sol b/contracts/finance/PaymentSplitter.sol index 94d2ab827c5..f6a8e39745a 100644 --- a/contracts/finance/PaymentSplitter.sol +++ b/contracts/finance/PaymentSplitter.sol @@ -120,6 +120,23 @@ contract PaymentSplitter is Context { return _payees[index]; } + /** + * @dev Getter for the amount of payee's unclaimed Ether. + */ + function releasable(address account) public view returns (uint256) { + uint256 totalReceived = address(this).balance + totalReleased(); + return _pendingPayment(account, totalReceived, released(account)); + } + + /** + * @dev Getter for the amount of payee's unclaimed `token` tokens. `token` should be the address of an + * IERC20 contract. + */ + function releasable(IERC20 token, address account) public view returns (uint256) { + uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token); + return _pendingPayment(account, totalReceived, released(token, account)); + } + /** * @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the * total shares and their previous withdrawals. @@ -127,8 +144,7 @@ contract PaymentSplitter is Context { function release(address payable account) public virtual { require(_shares[account] > 0, "PaymentSplitter: account has no shares"); - uint256 totalReceived = address(this).balance + totalReleased(); - uint256 payment = _pendingPayment(account, totalReceived, released(account)); + uint256 payment = releasable(account); require(payment != 0, "PaymentSplitter: account is not due payment"); @@ -147,8 +163,7 @@ contract PaymentSplitter is Context { function release(IERC20 token, address account) public virtual { require(_shares[account] > 0, "PaymentSplitter: account has no shares"); - uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token); - uint256 payment = _pendingPayment(account, totalReceived, released(token, account)); + uint256 payment = releasable(token, account); require(payment != 0, "PaymentSplitter: account is not due payment");