Time-decayed, staking-based funding — Commons Stack / 1Hive Gardens style.
Stakers back proposals with token. A proposal's conviction accrues from its currently staked support but
decays every period, so support that is held over time accumulates toward a steady state while support
that is withdrawn fades away. When a proposal's conviction reaches the threshold for its requested amount,
anyone can execute it and the request is paid from the shared treasury. Staking is non-custodial — you can
unstake anytime, which lowers the proposal's future conviction.
With per-period retention a = decay / 1e18 ∈ (0, 1), conviction follows the recurrence
C_n = a · C_{n-1} + stake
whose closed form over t whole periods is
C(t) = aᵗ · C₀ + stake · (1 − aᵗ) / (1 − a), steady state = stake / (1 − a)
Example with a = 0.9, stake = 100: conviction climbs 100 → 190 → 271 → … toward 1000, and if the
stake is removed it decays × 0.9 each period. The contract computes aᵗ with WAD fixed-point binary
exponentiation and advances conviction lazily over whole elapsed periods; the unit tests pin these exact
values.
donate(amount)— fund the shared treasury.propose(beneficiary, requested)— open a funding proposal.stake(id, amount)/unstake(id, amount)— add or remove staked support (non-custodial).execute(id)— onceconviction ≥ requested · weight / 1e18and the treasury can cover it, pay the request.- Views:
convictionOf(id),requiredConviction(requested),getProposal(id).
ReentrancyGuard+SafeERC20; stake pulls credit the actual amount received (fee-on-transfer safe).- Conviction is advanced before every stake/unstake/execute, so the curve is always evaluated on the correct
history;
aᵗ ∈ (0, WAD]keeps the fixed-point math bounded. - Fully tested: unit tests pinning the conviction curve to exact reference values (accrual, steady state,
post-unstake decay), threshold execution, treasury limits, and every guard, plus two stateful invariants
(
fail_on_revert = true):- conservation — the token balance always equals total staked plus the treasury;
- stake accounting — the sum of every proposal's
totalStakeequalstotalStaked.
forge test
FOUNDRY_INVARIANT_FAIL_ON_REVERT=true forge test --match-path "test/ConvictionVoting.invariant.t.sol"TOKEN=0x... DECAY=900000000000000000 PERIOD_LENGTH=86400 WEIGHT=1000000000000000000 \
forge script script/Deploy.s.sol --rpc-url "$RPC_URL" --broadcastNot audited. Reference implementation — review before any real deployment. The linear threshold is a
simplification of the Commons Stack 1/(1−r)² curve; tune decay, periodLength, and weight to your DAO.