Operation - Claim rewards
Key Steps
Example
import { satoshiClient } from 'satoshi-sdk';
async function claimCollateralGains() {
// Retrieve the current collateral configurations
const collaterals = satoshiClient.getCollateralConfig();
// Get the collateral gains from the Stability Pool
const collateralGains = await satoshiClient.StabilityPool.getCollateralGains();
// Initialize a flag to check if there is any claimable collateral
let hasCollateralClaimable = false;
// Check each type of collateral for any gains
for (let i = 0; i < collaterals.length; i++) {
const collateral = collaterals[i];
const gain = collateralGains[i];
console.log({
name: collateral.NAME, // Log the name and gain of the collateral
gain: gain.toString(), // Convert gain to a string for logging
});
// Check if there is a gain and set the flag if true
if (gain > 0n) {
hasCollateralClaimable = true;
}
}
// If there is claimable collateral, proceed to claim it
if (hasCollateralClaimable) {
const receipt = await satoshiClient.StabilityPool.doClaim();
console.log('Claim successful:', receipt);
} else {
console.log('No collateral gains to claim.');
}
}
claimCollateralGains();Last updated