You can use the collectFeeAndRewards()
function to collect the fees and the rewards of a specific position
Example
import { OnChainCalls, QueryChain } 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 collected
async function collectFeeAndRewards(privateKey: string, posID: string){
const keyPair = Ed25519Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));
let oc = new OnChainCalls(client,mainnet, {signer: keyPair});
let qc = new QueryChain(client);
let pos = await qc.getPositionDetails(posID);
let pool = await qc.getPool(pos.pool_id);
let resp = await oc.collectFeeAndRewards(pool,posID);
return resp
}
await collectFeeAndRewards("<private key>","0xdfb915d248674db372adfc3caba299bf0ce2ed216a6475498eabbd28c92b6c84")
Response
{
"digest":"GdqcY1UMFX8sHzXu9y3BYqtxr9pQoPtjesNN1qUKyg2t",
"transaction":{
"data":{
"messageVersion":"v1",
"transaction":{
"kind":"ProgrammableTransaction",
"inputs":[
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x0000000000000000000000000000000000000000000000000000000000000006",
"initialSharedVersion":"1",
"mutable":false
},
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
"initialSharedVersion":"406496849",
"mutable":false
},
{
"type":"object",
"objectType":"sharedObject",
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"initialSharedVersion":"406731547",
"mutable":true
},
{
"type":"object",
"objectType":"immOrOwnedObject",
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":"409729494",
"digest":"7Fn2K9ER2xyNY7S3JwbJVPFKwSWkxwYXnk9oGNWYr5nn"
}
],
"transactions":[
{
"MoveCall":{
"package":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"module":"gateway",
"function":"collect_fee",
"type_arguments":[
"0x2::sui::SUI",
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
],
"arguments":[
{
"Input":0
},
{
"Input":1
},
{
"Input":2
},
{
"Input":3
}
]
}
},
{
"MoveCall":{
"package":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"module":"gateway",
"function":"collect_reward",
"type_arguments":[
"0x2::sui::SUI",
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
"0xdd5c4badc89f08fb2ff3c1827411c9bafbed54c64c17d8ab969f637364ca8b4f::blue::BLUE"
],
"arguments":[
{
"Input":0
},
{
"Input":1
},
{
"Input":2
},
{
"Input":3
}
]
}
},
{
"MoveCall":{
"package":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"module":"gateway",
"function":"collect_reward",
"type_arguments":[
"0x2::sui::SUI",
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
"0x2::sui::SUI"
],
"arguments":[
{
"Input":0
},
{
"Input":1
},
{
"Input":2
},
{
"Input":3
}
]
}
}
]
},
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"gasData":{
"payment":[
{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729494,
"digest":"FefNAP8Aj4bEf8AojbJS5ataBGgGbDij2WeH9T4cKW6V"
}
],
"owner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"price":"750",
"budget":"3627924"
}
},
"txSignatures":[
"AA7ccb07lE6MGJzzYz8flDlcp0U4Npnh6KA8W6a9I4NROhtlXcZaRtmv8E2r52VBP6+B8JWH2iLhGi2/pxV1NgBwIesVczXTTL/3Q5yIJFnOVC24GMSqzrdNJIY1vK3z9w=="
]
},
"effects":{
"messageVersion":"v1",
"status":{
"status":"success"
},
"executedEpoch":"566",
"gasUsed":{
"computationCost":"750000",
"storageCost":"17168400",
"storageRebate":"16018596",
"nonRefundableStorageFee":"161804"
},
"modifiedAtVersions":[
{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"sequenceNumber":"409729494"
},
{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"sequenceNumber":"409729494"
},
{
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"sequenceNumber":"409729494"
},
{
"objectId":"0xb59155bc6b699a8856772264fb9d309dea9a03b7e10d1208bb0c62174b53576d",
"sequenceNumber":"409729493"
}
],
"sharedObjects":[
{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":409729494,
"digest":"HvHJ8M8aQhutyHq4MHvFc6zqVsMPVyPT6RhQ3XD7fyQe"
},
{
"objectId":"0x0000000000000000000000000000000000000000000000000000000000000006",
"version":158554559,
"digest":"479AV93WLDa9qb3LoJ8AJXa8XA5K9gBa9x4PDddm5kVi"
},
{
"objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
"version":409452196,
"digest":"cHY3mzy38rXW9RSBJZFvBuGA95wpNTjZet4NR136suv"
}
],
"transactionDigest":"GdqcY1UMFX8sHzXu9y3BYqtxr9pQoPtjesNN1qUKyg2t",
"created":[
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x2b39a1d95af059b5a539b9eb4b268af4d7abdc3bff40c29dcce39457fb61456d",
"version":409729495,
"digest":"6Z4oKGFymbEDHDG7dpePSA9QBHkSuu3jkFKmonxJ5xVC"
}
}
],
"mutated":[
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729495,
"digest":"HFzeoFVhEkzST79jsU8ZrjoqvWKX2m94YaA1XtQ2Gd6N"
}
},
{
"owner":{
"Shared":{
"initial_shared_version":406731547
}
},
"reference":{
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":409729495,
"digest":"5PTbbkytiA2JAGx3thGgqDtQsveaSts3snSKQt45Saw6"
}
},
{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":409729495,
"digest":"GbM1EmjH52218dVgEvGjnbQqyBsnnrCXqMsGfu1zKUJN"
}
},
{
"owner":{
"ObjectOwner":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa"
},
"reference":{
"objectId":"0xb59155bc6b699a8856772264fb9d309dea9a03b7e10d1208bb0c62174b53576d",
"version":409729495,
"digest":"A4R46bbuqdzUnkTwUoJPMrTvH5eJBPHDkm5eWE8YHHH8"
}
}
],
"gasObject":{
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"reference":{
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":409729495,
"digest":"HFzeoFVhEkzST79jsU8ZrjoqvWKX2m94YaA1XtQ2Gd6N"
}
},
"eventsDigest":"J3ZfKb9ghvc9LJnP6X2izncdMdtsTSbRTrQdXZiQpZga",
"dependencies":[
"49puDQZwHRnu7zYoARCjco1dFKMiK7LVSS8B5Si1yVdh",
"6iSTKc9MqGg17UnmdJfSJvbMuzcyS24emjMng1c4QduW",
"7DkJSrf5sPWGxqHbH2X1wXwFcftRm6myhJJnuTJbaMYr",
"7twEC8GzqF4k6WWtdkMFpkXMkKh2By5kqp2L96QUsBm2",
"CUQmrEssKtB8WxBYj3YQZJCrFTTDLqz3UWq1nRiWGCLS",
"GMvjrmN36uGquf1bMZFxeHzPUa4wTiMxNY2xZWVB69Pn",
"HzzEA9X29bCpPE7AJqoxN8zUgefPHztVJu1c73ScgxGa"
]
},
"events":[
{
"id":{
"txDigest":"GdqcY1UMFX8sHzXu9y3BYqtxr9pQoPtjesNN1qUKyg2t",
"eventSeq":"0"
},
"packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"transactionModule":"gateway",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"type":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::events::UserRewardCollected",
"parsedJson":{
"pool_id":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"position_id":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"reward_amount":"4690",
"reward_decimals":9,
"reward_symbol":"BLUE",
"reward_type":"dd5c4badc89f08fb2ff3c1827411c9bafbed54c64c17d8ab969f637364ca8b4f::blue::BLUE",
"sequence_number":"3626"
},
"bcs":"2yXCxUehEowt9saNgSMaJDa4KrUUfmmvKkM9jWbzVbYYZaaJAxHMpcSXEgTLD2VLk7WFuoo5csFz85rcwpkiEbATbhnWeFs7aT3uL5u2xQkweYnQEtHfBMVwvYcDoQnaC3trra9ppU32A5urukSeUMb7jXR84pupvAj73mXGfS5YMMhN9Sa8wFvmt4mTCFxtAsRrn5aPfaEckg5z75sbkmDsNoVSR4whtVSjwfK2Nj"
},
{
"id":{
"txDigest":"GdqcY1UMFX8sHzXu9y3BYqtxr9pQoPtjesNN1qUKyg2t",
"eventSeq":"1"
},
"packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
"transactionModule":"gateway",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"type":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::events::UserRewardCollected",
"parsedJson":{
"pool_id":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"position_id":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"reward_amount":"4690",
"reward_decimals":9,
"reward_symbol":"SUI",
"reward_type":"0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
"sequence_number":"3628"
},
"bcs":"2LFGoetGuXCknAbPHt1kSk1V3x3f7Z1MPubsXmdKLu8qs6Zrrnu5eRrFP6zaftGSGFV3nwj5KXGT4wE8zkr5mX98TYpnrDqWgCiqK4wxzDRNa3ssJ2ynKmuHb1ARbqMYLgWMrkqPYgC7jGooQTXBG3ifVU4pARaTM4TS7PuJbKEi9iGm15ZsoNDumSbSGpskwUhVRdJTbWfPWEaT36gJ85VYcbsNQRXUimX6By"
}
],
"objectChanges":[
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0x2::sui::SUI>",
"objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
"version":"409729495",
"previousVersion":"409729494",
"digest":"HFzeoFVhEkzST79jsU8ZrjoqvWKX2m94YaA1XtQ2Gd6N"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"Shared":{
"initial_shared_version":406731547
}
},
"objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::pool::Pool<0x2::sui::SUI, 0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
"objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
"version":"409729495",
"previousVersion":"409729494",
"digest":"5PTbbkytiA2JAGx3thGgqDtQsveaSts3snSKQt45Saw6"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::position::Position",
"objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
"version":"409729495",
"previousVersion":"409729494",
"digest":"GbM1EmjH52218dVgEvGjnbQqyBsnnrCXqMsGfu1zKUJN"
},
{
"type":"mutated",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"ObjectOwner":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa"
},
"objectType":"0x2::dynamic_field::Field<0x1::string::String, 0x2::balance::Balance<0x2::sui::SUI>>",
"objectId":"0xb59155bc6b699a8856772264fb9d309dea9a03b7e10d1208bb0c62174b53576d",
"version":"409729495",
"previousVersion":"409729493",
"digest":"A4R46bbuqdzUnkTwUoJPMrTvH5eJBPHDkm5eWE8YHHH8"
},
{
"type":"created",
"sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
"owner":{
"AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
},
"objectType":"0x2::coin::Coin<0x2::sui::SUI>",
"objectId":"0x2b39a1d95af059b5a539b9eb4b268af4d7abdc3bff40c29dcce39457fb61456d",
"version":"409729495",
"digest":"6Z4oKGFymbEDHDG7dpePSA9QBHkSuu3jkFKmonxJ5xVC"
}
],
"confirmedLocalExecution":false
}