burnHeightToDistributionIndex
Returns the distribution cycle that contains a Bitcoin block height. Distribution cycles are half a reward cycle long and drive the sBTC reward calculation. Pure computation that mirrors the pox-5 read-only burn-height-to-distribution-index.
Usage
import { burnHeightToDistributionIndex, fetchPoxInfo } from '@stacks/bitcoin-staking';
const poxInfo = await fetchPoxInfo({ network: 'mainnet' });
const index = burnHeightToDistributionIndex({ burnHeight: poxInfo.currentBurnchainBlockHeight, poxInfo });Notes
Computes
floor((burnHeight - firstBurnchainBlockHeight) / floor(rewardCycleLength / 2)). On mainnet a distribution cycle is 1,050 Bitcoin blocks.Index 0 starts at
firstBurnchainBlockHeight, the start of PoX, not at pox-5 activation.Throws an
Errorwith the messageburnHeight is before first-burnchain-block-heightwhenburnHeightis belowpoxInfo.firstBurnchainBlockHeight.
Signature
function burnHeightToDistributionIndex(opts: {
burnHeight: number;
poxInfo: PoxInfo;
}): number;Returns
number
The distribution cycle index.
Parameters
opts.burnHeight (required)
Type:
number
A Bitcoin block height at or above poxInfo.firstBurnchainBlockHeight.
opts.poxInfo (required)
Type:
PoxInfo
A PoxInfo, usually from fetchPoxInfo.
Was this helpful?