For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 Error with the message burnHeight is before first-burnchain-block-height when burnHeight is below poxInfo.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?