Operation - Claim rewards

The doClaim operation allows users to claim accumulated collateral gains from the Stability Pool. This function is crucial for users who have contributed to the pool and have earned returns as the pool liquidates troves that fall below the required collateral-to-debt ratio.

Key Steps

  1. Retrieve Collateral Configurations:

    • Begin by fetching the current configurations of collaterals used in the Stability Pool. This includes details like collateral types and their respective settings.

  2. Get Collateral Gains:

    • Check for any gains associated with each type of collateral the user might have accumulated through their participation in the pool.

  3. Check for Claimable Collateral:

    • Iterate through the list of collaterals to determine if there are any gains that can be claimed. If any collateral has a gain greater than zero, it is flagged as claimable.

  4. Execute Claim Operation:

    • If there is claimable collateral, execute the doClaim method to retrieve these gains. This operation finalizes the claim and transfers the earned collateral to the user's account.

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