A production-grade, pull-based payment splitter that distributes incoming
ETH and ERC-20 tokens among a fixed set of payees according to immutable shares.
Modeled on OpenZeppelin's classic finance/PaymentSplitter (removed in OZ v5),
modernized for Solidity 0.8.26 and hardened with a reentrancy guard, SafeERC20,
custom errors, and an extensive test + invariant suite.
-
Pull, not push. Nobody is paid automatically. Each payee's funds accrue in the contract, and a release must be pulled. Anyone may call
releasefor any payee — the funds always go to the payee, never to the caller. -
ETH arrives via
receive()(emitsPaymentReceived). ERC-20 tokens arrive by any ordinary transfer to the contract; no notification is needed. -
Owed amount for an account and asset:
owed = totalReceivedEver * shares[account] / totalShares - alreadyReleased[account]where
totalReceivedEver = currentBalance + totalReleased. This self-heals as more funds arrive: each release pulls only the newly-accrued delta, so there is no double-paying regardless of call ordering.
Release paths (guarded by ReentrancyGuard):
release(address payable account)— release ETH owed toaccount.release(IERC20 token, address payable account)— releasetokenowed.
Views:
releasable(account)/releasable(token, account)shares(account),released(account),released(token, account)payee(index),payeeCount(),totalShares()totalReleased(),totalReleased(token)
Reverts: NoShares(account) when the account holds no shares; NoPaymentDue
when nothing is owed. Constructor reverts on length mismatch, empty input, a zero
payee, a zero share, or a duplicate payee.
Fully non-custodial with a fixed split. There is no owner and no admin. The payees and their shares are set once in the constructor and can never be changed, paused, or clawed back. The contract can only ever forward funds to the configured payees in the configured proportions.
Integer division floors, so up to payeeCount - 1 wei of each asset may remain
unreleased as dust. This is intentional and safe: the contract never over-pays
and never pays more than it received. Dust simply stays in the contract and is
distributed once enough additional funds arrive to cross the next whole unit.
Because accounting is based on the balance that actually arrived
(currentBalance + totalReleased), fee-on-transfer tokens split the amount the
contract actually received — which is the correct behavior. (Note that any
fee on the outbound safeTransfer is borne by the payee, as with any recipient.)
Rebasing tokens whose balance changes without a transfer are out of scope:
their "received ever" figure moves under the accounting and payout proportions
are not guaranteed.
30 tests, all green:
- ETH and ERC-20 pro-rata correctness, incremental funding (no double-pay), release-by-stranger, nothing-due and no-shares reverts.
- Independent per-token accounting across two tokens; fee-on-transfer handling.
- Sum-of-releases never exceeds funded (dust
< payeeCount), including adversarial release ordering. - Constructor validation (mismatch, empty, zero payee, zero share, duplicate).
- Reentrancy: malicious ETH payee and malicious ERC-20 cannot double-collect.
- Fuzz tests for never-overpay on ETH and ERC-20.
- 3 stateful invariants (handler funds + releases in random order):
Σ released <= Σ received,released + balance == total funded, and released never exceeds current entitlement — 12,800 calls each, 0 reverts underfail_on_revert = true.
forge test # run everything
forge build --sizes # EIP-170 check
forge snapshot # regenerate .gas-snapshotA second adversarial pass focused on conservation/solvency, reentrancy across both assets, and rounding. No exploitable bug was found — the balance-based accounting conserves funds at every boundary examined. Documented as extra tests (30 → 35), not a source change:
- Forced ETH. ETH delivered via
selfdestruct(never touchingreceive()) is still split correctly, confirming accounting keys off live balance rather than thePaymentReceivedevent. - Shared reentrancy guard. The
nonReentrantguard is a single status, so it spans both release paths. A malicious ETH payee that re-enters the ERC-20 path from itsreceive()is blocked — the cross-asset re-entry reverts and bubbles up, leaving both assets untouched (no double-collect). - Interleaving & conservation. Alternating ETH and token releases across all
payees drains both assets exactly with no drift; a fuzz test asserts
released + residual == fundedfor both assets under a permuted release order. - Rounding. With seven payees, coprime shares, and an indivisible amount, the
unreleased dust stays strictly below
payeeCountand is never over-paid.
Assumptions unchanged: standard ERC-20 behavior for exact accounting; fee-on- transfer tokens split what actually arrived; rebasing tokens are out of scope.
MIT.