fetchNewRewards
Reads the sBTC, in sats, that pox-5 has received as rewards since the last calculate-rewards. Wraps the pox-5 read-only get-new-rewards.
Usage
import { fetchLastAccountedRewards, fetchNewRewards, fetchRewards } from '@stacks/bitcoin-staking';
const [rewards, lastAccounted, newRewards] = await Promise.all([
fetchRewards({ network: 'mainnet' }),
fetchLastAccountedRewards({ network: 'mainnet' }),
fetchNewRewards({ network: 'mainnet' }),
]);
// At the same chain tip: newRewards === rewards - lastAccountedNotes
get-new-rewardsreturnsget-rewardsminus thelast-accounted-rewards-onlydata-var (get-new-rewards).The next
calculate-rewardsdistributes this amount (calculate-rewards). The protocol bond tranche is paid first, each bond up to its target yield (calculate-bond-rewards). The reserve fund tranche takes 15% of the remainder (RESERVE_RATIO, 1,500 basis points), and the STX-only staking tranche gets the rest. When no STX is staked in the cycle, the STX-only staking tranche's part also goes to the reserve fund tranche (calculate-rewards).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.
Returns
Promise<bigint>
Resolves to an amount of sBTC in sats.
Parameters
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?