collect Rewards
When you provide liquidity within a valid price range, rewards are distributed every second for transactions that occur within this range. The rewards are based on the proportional share of effective liquidity from all positions in the current range. To harvest rewards separately, please follow the steps outlined below.
Signature
async collectReward(options: Pool.CollectRewardOptions): Promise
Params
export interface CollectRewardOptions
extends Pick<Pool.MintParams, 'pool' | 'txb' | 'address' | 'deadline'> {
/**
* Position NFT ID
*/
nft: string;
rewardAmounts: (string | number)[];
}
Examples
Get Pool Reward Info
const pool = await turbosSdk.pool.getPool(poolId);
console.log(pool.reward_infos);
Response
[
{
type: '0x3526c88f5304c78fb93ed1cc1961d56b8517108550c9938b8a5a0e6c90fbe2a5::pool::PoolRewardInfo',
fields: {
emissions_per_second: '38424567905536996016128',
growth_global: '749293748415772256605',
id: [Object],
manager: '0x9563578937da5bd33657306871057dbe50c18900d300ecd97c93c3cbda2262ed',
vault: '0xefabda0d649f5c963ceee5a2371983ad83cce0ee6676af793e37b3800672d94f',
vault_coin_type: '3f90cccd711bcfb4d8e41d4464fc851dcddfee4e69c5debba4ddbb54f14e3c38::ttest::TTEST'
}
}
]
Get Unclaimed Rewards
const turbosSdk = new TurbosSdk(Network.testnet, {
url: 'https://fullnode.testnet.sui.io',
});
const signer = turbosSdk.account.getKeypairFromMnemonics("your mnemonic");
const poolId = '0x328572f9d3c99bdb0a2da46fa61ef7917e1d35e67ec9472d412aa82b4a5222b2';
const positionId =
'0xa6db73a23c6f5eedd9e49530986d247e04745b97ef4715c8bd452413fe73cdba';
const pool = await turbosSdk.pool.getPool(poolId);
const txb = await turbosSdk.pool.collectReward({
pool: poolId,
nft: positionId,
rewardAmounts: pool.reward_infos.map(() => MAX_UINT_64.toString()),
address: signer.toSuiAddress(),
});
const result = await turbosSdk.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: signer.toSuiAddress(),
});
const collectEvents = result.events.filter((event) =>
event.type.endsWith('::pool::CollectRewardEvent'),
);
const collectRewards = pool.reward_infos.map((rewardInfo) => {
const collectEvent = collectEvents.find(
(event) => event.parsedJson!.vault === rewardInfo.fields.vault,
);
return {
rewardCoinType: rewardInfo.fields.vault_coin_type,
vault: rewardInfo.fields.vault,
amount: collectEvent?.parsedJson!.amount,
};
});
console.log(collectRewards);
Reponse
[
{
rewardCoinType: '99964a9e90b1ef11ab0cdfc9a05ebde29c7f13cb8786a84c2f0a686b710526f7::turbos::TURBOS',
vault: '0x47fd451811de8a857f80fde5b886f2b76e1369a7a3211b9021c6dbae3cdb15b3',
amount: '42269151402'
}
]
Collect Rewards
const turbosSdk = new TurbosSdk(Network.testnet, {
url: 'https://fullnode.testnet.sui.io',
});
const signer = turbosSdk.account.getKeypairFromMnemonics("your mnemonic");
const poolId = '0x328572f9d3c99bdb0a2da46fa61ef7917e1d35e67ec9472d412aa82b4a5222b2';
const positionId =
'0xa6db73a23c6f5eedd9e49530986d247e04745b97ef4715c8bd452413fe73cdba';
const pool = await turbosSdk.pool.getPool(poolId);
const txb = await turbosSdk.pool.collectReward({
pool: poolId,
nft: positionId,
rewardAmounts: pool.reward_infos.map(() => MAX_UINT_64.toString()),
address: signer.toSuiAddress(),
});
const result = await turbosSdk.provider.signAndExecuteTransaction({
transaction: txb,
signer,
});
console.log(result);
Last updated