A sponsor-matched donation campaign.
Donations flow straight to the cause and are matched from a sponsor-funded pool at a fixed ratio (e.g.
1:1) until the pool is exhausted — the classic "every dollar you give is doubled" drive. A donation of x
sends x to the recipient and min(x · ratio, poolLeft) more from the pool. After the deadline the sponsor
reclaims any unused match. Matching is linear and capped (contrast quadratic-funding, which matches by the
square-root of contributions).
constructor(token, recipient, sponsor, matchRatioBps, deadline)—matchRatioBpsis match per donation (10_000= 1:1).fundMatch(amount)— sponsor tops up the matching pool (before the deadline).donate(amount)— donation goes directly donor→recipient; the match is paid from the pool (capped by what's left). Returns the matched amount.reclaim()— after the deadline, sponsor withdraws the unused pool. Once.- Views:
matchFor(amount),isActive().
ReentrancyGuard+SafeERC20; the sponsor's funding credits the actual amount received (fee-on-transfer safe), and donations pass straight through so their accounting can't be gamed.- The match is
min(want, matchRemaining), so the pool is never overspent — no donation can pull more than the pool holds. - Fully tested: unit tests for 1:1 and fractional ratios, pool-capped matching, reclaim, accounting, and every
guard, plus two stateful invariants (
fail_on_revert = true):- pool conservation — the token balance always equals
matchRemaining(only the unmatched pool is held); - match accounting — while the campaign is live,
totalMatched + matchRemaining == totalMatchFunded.
- pool conservation — the token balance always equals
forge test
FOUNDRY_INVARIANT_FAIL_ON_REVERT=true forge test --match-path "test/MatchedDonation.invariant.t.sol"TOKEN=0x... RECIPIENT=0x... SPONSOR=0x... MATCH_RATIO_BPS=10000 DEADLINE=1750000000 \
forge script script/Deploy.s.sol --rpc-url "$RPC_URL" --broadcastNot audited. Reference implementation — review before any real deployment.