Skip to content

Commit e34b4a5

Browse files
authored
Split audit macro (#250)
* releasable functions in preset PaymentSplitterUpgradeable * remove inaccurate comments from distribute functions
1 parent 36d3395 commit e34b4a5

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

contracts/Split.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ contract Split is
126126
function distribute() public virtual {
127127
uint256 count = payeeCount();
128128
for (uint256 i = 0; i < count; i++) {
129-
// note: `_release` should not fail because payee always has shares, protected by `_appPay`
130129
_release(payable(payee(i)));
131130
}
132131
}
@@ -137,7 +136,6 @@ contract Split is
137136
function distribute(IERC20Upgradeable token) public virtual {
138137
uint256 count = payeeCount();
139138
for (uint256 i = 0; i < count; i++) {
140-
// note: `_release` should not fail because payee always has shares, protected by `_appPay`
141139
_release(token, payee(i));
142140
}
143141
}

contracts/openzeppelin-presets/finance/PaymentSplitterUpgradeable.sol

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
1414
* - `_totalReleased`, `_released`, `_erc20TotalReleased`, `_erc20Released`, `_pendingPayment`
1515
*
1616
* - Add `payeeCount`: returns the length of `_payees`
17+
* - Add `releasable` functions as per recent updates in OZ PaymentSplitterUpgradeable (v4.7.0)
1718
*/
1819

1920
/**
@@ -144,15 +145,31 @@ contract PaymentSplitterUpgradeable is Initializable, ContextUpgradeable {
144145
return _payees.length;
145146
}
146147

148+
/**
149+
* @dev Getter for the amount of payee's releasable Ether.
150+
*/
151+
function releasable(address account) public view returns (uint256) {
152+
uint256 totalReceived = address(this).balance + totalReleased();
153+
return _pendingPayment(account, totalReceived, released(account));
154+
}
155+
156+
/**
157+
* @dev Getter for the amount of payee's releasable `token` tokens. `token` should be the address of an
158+
* IERC20 contract.
159+
*/
160+
function releasable(IERC20Upgradeable token, address account) public view returns (uint256) {
161+
uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token);
162+
return _pendingPayment(account, totalReceived, released(token, account));
163+
}
164+
147165
/**
148166
* @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the
149167
* total shares and their previous withdrawals.
150168
*/
151169
function release(address payable account) public virtual {
152170
require(_shares[account] > 0, "PaymentSplitter: account has no shares");
153171

154-
uint256 totalReceived = address(this).balance + totalReleased();
155-
uint256 payment = _pendingPayment(account, totalReceived, released(account));
172+
uint256 payment = releasable(account);
156173

157174
require(payment != 0, "PaymentSplitter: account is not due payment");
158175

@@ -171,8 +188,7 @@ contract PaymentSplitterUpgradeable is Initializable, ContextUpgradeable {
171188
function release(IERC20Upgradeable token, address account) public virtual {
172189
require(_shares[account] > 0, "PaymentSplitter: account has no shares");
173190

174-
uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token);
175-
uint256 payment = _pendingPayment(account, totalReceived, released(token, account));
191+
uint256 payment = releasable(token, account);
176192

177193
require(payment != 0, "PaymentSplitter: account is not due payment");
178194

docs/PaymentSplitterUpgradeable.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,51 @@ function payeeCount() external view returns (uint256)
4343
*Get the number of payees*
4444

4545

46+
#### Returns
47+
48+
| Name | Type | Description |
49+
|---|---|---|
50+
| _0 | uint256 | undefined |
51+
52+
### releasable
53+
54+
```solidity
55+
function releasable(address account) external view returns (uint256)
56+
```
57+
58+
59+
60+
*Getter for the amount of payee&#39;s releasable Ether.*
61+
62+
#### Parameters
63+
64+
| Name | Type | Description |
65+
|---|---|---|
66+
| account | address | undefined |
67+
68+
#### Returns
69+
70+
| Name | Type | Description |
71+
|---|---|---|
72+
| _0 | uint256 | undefined |
73+
74+
### releasable
75+
76+
```solidity
77+
function releasable(contract IERC20Upgradeable token, address account) external view returns (uint256)
78+
```
79+
80+
81+
82+
*Getter for the amount of payee&#39;s releasable `token` tokens. `token` should be the address of an IERC20 contract.*
83+
84+
#### Parameters
85+
86+
| Name | Type | Description |
87+
|---|---|---|
88+
| token | contract IERC20Upgradeable | undefined |
89+
| account | address | undefined |
90+
4691
#### Returns
4792

4893
| Name | Type | Description |

docs/Split.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,51 @@ function payeeCount() external view returns (uint256)
309309
*Get the number of payees*
310310

311311

312+
#### Returns
313+
314+
| Name | Type | Description |
315+
|---|---|---|
316+
| _0 | uint256 | undefined |
317+
318+
### releasable
319+
320+
```solidity
321+
function releasable(address account) external view returns (uint256)
322+
```
323+
324+
325+
326+
*Getter for the amount of payee&#39;s releasable Ether.*
327+
328+
#### Parameters
329+
330+
| Name | Type | Description |
331+
|---|---|---|
332+
| account | address | undefined |
333+
334+
#### Returns
335+
336+
| Name | Type | Description |
337+
|---|---|---|
338+
| _0 | uint256 | undefined |
339+
340+
### releasable
341+
342+
```solidity
343+
function releasable(contract IERC20Upgradeable token, address account) external view returns (uint256)
344+
```
345+
346+
347+
348+
*Getter for the amount of payee&#39;s releasable `token` tokens. `token` should be the address of an IERC20 contract.*
349+
350+
#### Parameters
351+
352+
| Name | Type | Description |
353+
|---|---|---|
354+
| token | contract IERC20Upgradeable | undefined |
355+
| account | address | undefined |
356+
312357
#### Returns
313358

314359
| Name | Type | Description |

0 commit comments

Comments
 (0)