The formulae
The integer maths the contract runs, in the order it runs it.
| Property | Value |
|---|---|
| name | formulae |
| scale | 1e36 |
| mirror | packages/shared/src/streaming.ts |
All amounts are integers in wei. Division rounds down. Every remainder is carried forward, so nothing is created or lost in rounding.
Epochs
epoch(t) = (t - GENESIS) / STREAM_PERIOD
epochStart(e) = GENESIS + e * STREAM_PERIODRelease within an epoch
released(t) = streaming * (t - epochStart(epoch(t))) / STREAM_PERIOD
delta = released(t) - releasedSoFarAccumulator
eligible = totalSupply - excludedSupply
numerator = delta * SCALE + remainder
accPerToken += numerator / eligible
remainder = numerator % eligibleA holder's amount
owedScaled[a] += balance[a] * (accPerToken - accPaid[a]) // on every balance change
accPaid[a] = accPerToken
claimable(a) = owedScaled[a] / SCALE // whole weiConservation
After every call the tests check, exactly:
deposited * SCALE = claimed * SCALE + Σ owedScaled + (streaming - released + queued) * SCALE + remainderDust: what cannot be paid in whole wei stays in the contract, under 1 wei per holder plus under 1 wei overall.