Skip to content

About

Sponsor-matched donation campaign: donations pass straight to the cause and are matched from a sponsor pool at a fixed ratio up to the pool cap (linear matching); sponsor reclaims the unused remainder after the deadline. Pool-conservation invariants. Foundry, unit + invariant tested.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

matched-donation

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).

Mechanics

  • constructor(token, recipient, sponsor, matchRatioBps, deadline) — matchRatioBps is 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().

Safety

  • 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.

Test

forge test
FOUNDRY_INVARIANT_FAIL_ON_REVERT=true forge test --match-path "test/MatchedDonation.invariant.t.sol"

Deploy

TOKEN=0x... RECIPIENT=0x... SPONSOR=0x... MATCH_RATIO_BPS=10000 DEADLINE=1750000000 \
  forge script script/Deploy.s.sol --rpc-url "$RPC_URL" --broadcast

Not audited. Reference implementation — review before any real deployment.

About

Sponsor-matched donation campaign: donations pass straight to the cause and are matched from a sponsor pool at a fixed ratio up to the pool cap (linear matching); sponsor reclaims the unused remainder after the deadline. Pool-conservation invariants. Foundry, unit + invariant tested.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages