Claim Stake Rewards
Enable the user to claim rewards from their staked position.
The following code example is in typescript. These smart contract integrations can be generalized to any codebase.
CLAIM (staking.claimRewards)
export async function claimRewards({ client, staking }: { client:any; staking:`0x${string}` }) {
await client.writeContract({
address: staking, abi: stakingErc20Abi, functionName: 'claimRewards', args: [],
});
}
READS for UI: balances, claimable
Total position to display, plus rewards claimable
export async function readTotalPosition(args:{
client:any; user:`0x${string}`; vault:`0x${string}`; staking:`0x${string}`;
}) {
const [{ assets, shares }, { stakedAssets, stakedShares, claimableRewards }] = await Promise.all([
readVaultBalances(args), readStakingBalances(args),
]);
return {
unstakedAssets: assets,
stakedAssets,
totalAssets: assets + stakedAssets,
unstakedShares: shares,
stakedShares,
totalShares: shares + stakedShares,
claimableRewards,
};
}
Last updated