Skip to content

About

Transferable ERC-20 whose holders accrue a reward token pro-rata, correct across transfers via the magnified-dividend-per-share algorithm. O(1) distributions, conservation + solvency invariants. Foundry, unit + invariant tested.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

dividend-token

A transferable ERC-20 whose holders accrue a reward token pro-rata.

Every holder of this share token continuously earns a proportional slice of any rewardToken distributed to the pool — and, crucially, that accrual follows the shares through transfers, mints, and burns. Sell your shares and you keep the dividends you earned while holding them; buy shares and you earn only from that point on. Distributions are O(1) no matter how many holders there are.

How it stays correct across transfers

Naively splitting each distribution across holders would be O(holders) and would mis-handle transfers. Instead the contract keeps a single running accumulator magnifiedDividendPerShare (scaled by 2¹²⁸ for precision). A holder's lifetime entitlement is perShare · balance, adjusted by a per-holder correction term that is updated on every mint / burn / transfer:

  • on transfer of v shares from → to: correction[from] += perShare·v (preserve what from already earned) and correction[to] -= perShare·v (to earns only from now on).

This is the canonical "magnified dividend" algorithm (Roberto Bayardo / PoolTogether / Cometh). Unlike a fixed-share splitter, the shares here are ordinary transferable balances and dividends track them exactly.

Mechanics

  • distributeDividends(amount) — anyone pushes amount of rewardToken to all current shareholders pro-rata. Crediting is the actual amount received (fee-on-transfer safe).
  • withdrawDividend() — caller pulls their accrued-but-unwithdrawn dividends.
  • Views: withdrawableDividendOf(a), accumulativeDividendOf(a); plus the full ERC-20 surface (the shares).

Safety

  • ReentrancyGuard + SafeERC20 on the reward paths; SafeCast for the signed correction arithmetic.
  • Magnitude scaling (2¹²⁸) makes per-share rounding negligible; rounding only ever leaves dust in the contract, never an over-payment.
  • Fully tested: unit tests for equal splits, "dividends before you join aren't yours", "a transfer carries future accrual but not the past", double-withdraw, and conservation, plus two stateful invariants (fail_on_revert = true):
    • conservation — the reward balance held always equals lifetime distributed minus lifetime withdrawn;
    • solvency — the sum of every holder's withdrawable dividend never exceeds the reward balance.

Test

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

Deploy

NAME="Share" SYMBOL="SHR" REWARD_TOKEN=0x... INITIAL_SUPPLY=1000000000000000000000000 \
  forge script script/Deploy.s.sol --rpc-url "$RPC_URL" --broadcast

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

About

Transferable ERC-20 whose holders accrue a reward token pro-rata, correct across transfers via the magnified-dividend-per-share algorithm. O(1) distributions, conservation + solvency invariants. Foundry, unit + invariant tested.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages