These docs are for v2.0.1. Click to read the latest docs for v3.0.2.

Get Accrued Fee and Rewards

You can use the getAccruedFeeAndRewards() function to view the current fees and rewards for a given position.

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 fee and rewards are being queried

async function getAccruedFeeAndRewards(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.getAccruedFeeAndRewards(pool, posID);

    return {
        "rewards": resp.rewards,
        "fee" :{
            "coinA": resp.fee.coinA.toString(),
            "coinB": resp.fee.coinB.toString(),
        }
    }
}

await getAccrcuedFeeAndRewards("<private key>","0x202ca4622f4902d671b37ba8d65fd0418351ce5ac7e7e432ddff13c2236333d1")

Response

{
   "rewards":[
      {
         "coinAmount":"1636",
         "coinSymbol":"BLUE",
         "coinType":"dd5c4badc89f08fb2ff3c1827411c9bafbed54c64c17d8ab969f637364ca8b4f::blue::BLUE",
         "coinDecimals":9
      },
      {
         "coinAmount":"1636",
         "coinSymbol":"SUI",
         "coinType":"0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
         "coinDecimals":9
      }
   ],
   "fee":{
      "coinA":"0",
      "coinB":"0"
   }
}