bondPhaseRanges
Returns a bond's four lifecycle phases as consecutive ranges of Bitcoin block heights, for timelines and countdowns. Pure computation from poxInfo: it does not check whether the bond was set up.
Usage
import { bondPhaseRanges, fetchPoxInfo } from '@stacks/bitcoin-staking';
const poxInfo = await fetchPoxInfo({ network: 'mainnet' });
for (const phase of bondPhaseRanges({ bondIndex: 0, poxInfo })) {
console.log(phase.name, phase.startBurnHeight, phase.endBurnHeight);
}
// names in order: 'open', 'locked', 'unlocked', 'finished'Notes
With
start= bondPeriodToBurnHeight andend=start + 12 * rewardCycleLength, the ranges are:
Phase
startBurnHeight
endBurnHeight (exclusive)
Mainnet length
open
start - 2 * rewardCycleLength
start - prepareCycleLength
4,100 blocks
locked
start - prepareCycleLength
end - floor(rewardCycleLength / 2)
24,250 blocks
unlocked
end - floor(rewardCycleLength / 2)
end + 1
1,051 blocks
finished
end + 1
end + 12 * rewardCycleLength
25,199 blocks
openstarts whensetup-bondbecomes possible and ends where the final prepare phase before the start begins, after which registration fails. It still contains the prepare phase of the cycle two before the start, whereregister-for-bondfails withERR_STAKE_IN_PREPARE_PHASE (u47). Check with isInPreparePhase.unlockedstarts at the heightget-bond-l1-unlock-heightreturns for the bond. From there a member can roll into bondbondIndex + 6or an STX-only stake withoutERR_ROLLOVER_TOO_EARLY (u48). Each L1 output'sunlockBurnHeightis at or above this height, asregister-for-bondrequires.unlockedincludesendbecauseis-bond-active-at-heightcounts the end height as active.The
finishedrange is capped at 12 reward cycles so it has a finite end. The cap is a display convention. The contract never deletes a bond fromprotocol-bonds.For a bond that may not be set up, use bondStatus.
Throws an
Errorwhose message starts withpox-5 not activated yetifpoxInfo.contractVersionshas no pox-5 entry.
Signature
Returns
BondPhaseRange[]
Four BondPhaseRange entries in the order open, locked, unlocked, finished. Each range's endBurnHeight is the next range's startBurnHeight.
Parameters
opts.bondIndex (required)
Type:
number
The bond index.
opts.poxInfo (required)
Type:
PoxInfo
A PoxInfo, usually from fetchPoxInfo.
Was this helpful?