fetchBondOverlapsNewPosition
Checks whether a staker's existing bond membership overlaps a new position that starts at a given reward cycle. Wraps the pox-5 read-only bond-overlaps-new-position?.
Usage
import {
fetchBondOverlapsNewPosition,
fetchPoxInfo,
fetchProtocolBondMemberships,
} from '@stacks/bitcoin-staking';
async function bondBlocksStakeNextCycle(staker: string) {
const { rewardCycleId } = await fetchPoxInfo({ network: 'mainnet' });
const membership = await fetchProtocolBondMemberships({ address: staker, network: 'mainnet' });
return fetchBondOverlapsNewPosition({
membership,
newFirstRewardCycle: rewardCycleId + 1, // stake starts at the next cycle
network: 'mainnet',
});
}Notes
Returns
truewhen the bond's first reward cycle plus 12 (BOND_LENGTH_CYCLES) is greater thannewFirstRewardCycle, andfalsewhenmembershipisundefined(bond-overlaps-new-position?). Onlymembership.bondIndexaffects the result.register-for-bondreverts withERR_ALREADY_REGISTERED (u9)on overlap (register-for-bond), andstakereverts withERR_ALREADY_STAKED (u19)(stake).stakestarts at the next reward cycle (stake).Both functions pass the raw
protocol-bond-membershipsentry (L679, L993), which fetchProtocolBondMemberships returns.A non-2xx response throws an
Errorwhose message starts withError calling read-only function.and includes the status code and URL. If the node reports that the call failed, theErrormessage is the node'scause.
Signature
opts is a NetworkClientParam plus membership and newFirstRewardCycle.
Returns
Promise<boolean>
Resolves to true if the membership overlaps the new position.
Parameters
opts.membership (required)
Type:
BondMembership | undefined
The staker's existing BondMembership, or undefined for none.
opts.newFirstRewardCycle (required)
Type:
number
First reward cycle of the new position.
opts.network (optional)
Type:
StacksNetworkName | StacksNetwork
The network to query: a name such as 'mainnet' or 'testnet', or a StacksNetwork object. Defaults to 'mainnet'.
opts.client (optional)
Type:
{ baseUrl?: string; fetch?: FetchFn }
Overrides the API base URL or the fetch function, for example to query your own node. Fields you set replace the network's defaults.
Was this helpful?