Skip to content

Commit 56a00cd

Browse files
authored
comment stakes needed to preboost/unpreboost (#416)
* new comments * tweak * tweak * fix * tweaks * slight rewording * spelling * requested tweak to the comments * lint
1 parent dfaeeaf commit 56a00cd

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/proposal.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,25 +511,50 @@ export class Proposal implements IStateful<IProposalState> {
511511
const threshold = realMathToNumber(new BN(item.gpQueue.threshold))
512512
const stakesFor = new BN(item.stakesFor)
513513
const stakesAgainst = new BN(item.stakesAgainst)
514+
/**
515+
* for doing multiplication between floating point (threshold) and BN numbers
516+
*/
517+
const PRECISION = Math.pow(2, 40)
514518

515-
// upstakeNeededToPreBoost is the amount of tokens needed to upstake to move to the preboost queue
516-
// this is only non-zero for Queued proposals
517-
// note that the number can be negative!
519+
/**
520+
* The number of up-staking tokens (usually GEN) needed to qualify a queued proposal to move into the
521+
* pre-boosted queue.
522+
*
523+
* Only computed for queued proposals.
524+
*
525+
* The equation is derived from: threshold = (stakesFor + upstakeNeededToPreBoost) / stakesAgainst
526+
*
527+
* Where `upstakeNeededToPreBoost` is:
528+
*
529+
* >= 0 : then any number of up-staking tokens greater than upstakeNeededToPreBoost will qualify
530+
* to move the proposal to the preboost queue
531+
* < 0 : then the proposal ought already to be pre-boosted
532+
*/
518533
let upstakeNeededToPreBoost: BN = new BN(0)
519-
const PRECISION = Math.pow(2, 40)
520534
if (stage === IProposalStage.Queued) {
521-
522535
upstakeNeededToPreBoost = new BN(threshold * PRECISION)
523536
.mul(stakesAgainst)
524537
.div(new BN(PRECISION))
525538
.sub(stakesFor)
526539
}
527-
// upstakeNeededToPreBoost is the amount of tokens needed to upstake to move to the Queued queue
528-
// this is only non-zero for Preboosted proposals
529-
// note that the number can be negative!
540+
541+
/**
542+
* The number of down-staking tokens (usually GEN) needed to qualify a pre-boosted proposal to move back
543+
* to the Queued queue.
544+
* Only computed for PreBoosted proposals.
545+
*
546+
* The equation is derived from: threshold = stakesFor / (stakesAgainst + downStakeNeededToQueue)
547+
*
548+
* When `downStakeNeededToQueue` is:
549+
*
550+
* > 0 : then any number of down-staking tokens greater-than-or-equal to downStakeNeededToQueue will qualify
551+
* to move the proposal to the Queued queue
552+
* <= 0 : then the proposal ought to already be in the Queued queue
553+
*/
530554
let downStakeNeededToQueue: BN = new BN(0)
531555
if (stage === IProposalStage.PreBoosted) {
532-
downStakeNeededToQueue = stakesFor.mul(new BN(PRECISION))
556+
downStakeNeededToQueue = stakesFor
557+
.mul(new BN(PRECISION))
533558
.div(new BN(threshold * PRECISION))
534559
.sub(stakesAgainst)
535560
}

0 commit comments

Comments
 (0)