Skip to content

About

Commons-Stack/1Hive-style conviction voting: stakers back proposals, conviction accrues with exponential per-period decay (C=a*C+stake), and crossing the requested-amount threshold funds it from the treasury. Exact WAD conviction math + 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

conviction-voting

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.

The conviction curve

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.

Mechanics

  • 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) — once conviction ≥ requested · weight / 1e18 and the treasury can cover it, pay the request.
  • Views: convictionOf(id), requiredConviction(requested), getProposal(id).

Safety

  • 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 totalStake equals totalStaked.

Test

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

Deploy

TOKEN=0x... DECAY=900000000000000000 PERIOD_LENGTH=86400 WEIGHT=1000000000000000000 \
  forge script script/Deploy.s.sol --rpc-url "$RPC_URL" --broadcast

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

About

Commons-Stack/1Hive-style conviction voting: stakers back proposals, conviction accrues with exponential per-period decay (C=a*C+stake), and crossing the requested-amount threshold funds it from the treasury. Exact WAD conviction math + conservation invariants. Foundry, unit + invariant tested.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages