You can use the collectRewards()
function to collect the rewards of a specific position.
If there are no rewards to collect, this function will revert.
Example
import { QueryChain, OnChainCalls } from "@firefly-exchange/library-sui/dist/src/spot";
import { Ed25519Keypair, SuiClient } from "@firefly-exchange/library-sui";
import { mainnet } from '../config'
const client = new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" });
/// Parameters:
/// - privateKey : The private key of the user making the blockchain call
/// - posID : The position ID of the position whose rewards are being collected
async function collectRewards(privateKey: string, posID: string){
let qc = new QueryChain(client);
const keyPair = Ed25519Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));
let oc = new OnChainCalls(client,mainnet, {signer: keyPair});
let pos = await qc.getPositionDetails(posID);
let pool = await qc.getPool(pos.pool_id);
let resp = await oc.collectRewards(pool, posID);
return resp;
}
await collectRewards("<private key>","0xdfb915d248674db372adfc3caba299bf0ce2ed216a6475498eabbd28c92b6c84")