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

Add getter for number of unclaimed tokens in PaymentSplitter #3350

Merged
merged 7 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor release functions
move payment to unclaimed functions
  • Loading branch information
alonbg authored and SgrA committed May 31, 2022
commit ec3b1cf10845f971951bf1bbcb369bf22a74b8ca
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 19 additions & 4 deletions contracts/finance/PaymentSplitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,31 @@ 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.
*/
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");

Expand All @@ -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");

Expand Down