API Reference

Collect Fee

You can use the collectFee() function to receive all the accrued fees related to 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 is being collected

async function collectFee(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.collectFee(pool,posID);
    return resp
}

await collectFee("<private key>","0xdfb915d248674db372adfc3caba299bf0ce2ed216a6475498eabbd28c92b6c84")

Response

{
   "digest":"7twEC8GzqF4k6WWtdkMFpkXMkKh2By5kqp2L96QUsBm2",
   "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":"409729493",
                  "digest":"GTJmAFfYiWMMpgpGyAeWa5XGbRZgJA5AiPGECiuw4Cy1"
               }
            ],
            "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
                        }
                     ]
                  }
               }
            ]
         },
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "gasData":{
            "payment":[
               {
                  "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
                  "version":409729493,
                  "digest":"AWiyhLxiMfyK4Ky9HEkaF5Ssdv665PhVxJUqcw2P8LoV"
               },
               {
                  "objectId":"0xf7ab534ee9fe76a5408b43d2a708402e1e25dae337415770f71d86ea37c79097",
                  "version":409729493,
                  "digest":"3Mrk6L38aJMWAsAnXrTkDdyVsAKiByJarmUwo5Yf3mh4"
               },
               {
                  "objectId":"0x9f7b58e35999081521c53de1c721c5329d7e1f7c7e4b1b47f85c67772e8f71c7",
                  "version":409729493,
                  "digest":"EePsUFh65PDrxS3LfssHSsfCUQ8yF6C4GPw6HSiwVSYw"
               }
            ],
            "owner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
            "price":"750",
            "budget":"2609676"
         }
      },
      "txSignatures":[
         "AAja29/3rbknG+DnTGP87jNEw1PC9vssqOkGfiRzisCwW1Yyxkh4oB5+0iG5/p4BKlIH7gJN3lwzp4GVvpq/7wtwIesVczXTTL/3Q5yIJFnOVC24GMSqzrdNJIY1vK3z9w=="
      ]
   },
   "effects":{
      "messageVersion":"v1",
      "status":{
         "status":"success"
      },
      "executedEpoch":"566",
      "gasUsed":{
         "computationCost":"750000",
         "storageCost":"13155600",
         "storageRebate":"14980284",
         "nonRefundableStorageFee":"151316"
      },
      "modifiedAtVersions":[
         {
            "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
            "sequenceNumber":"409729493"
         },
         {
            "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
            "sequenceNumber":"409729493"
         },
         {
            "objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
            "sequenceNumber":"409729493"
         },
         {
            "objectId":"0x9f7b58e35999081521c53de1c721c5329d7e1f7c7e4b1b47f85c67772e8f71c7",
            "sequenceNumber":"409729493"
         },
         {
            "objectId":"0xf7ab534ee9fe76a5408b43d2a708402e1e25dae337415770f71d86ea37c79097",
            "sequenceNumber":"409729493"
         }
      ],
      "sharedObjects":[
         {
            "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
            "version":409729493,
            "digest":"J2LNLm1azXu2KGHq9ZuamSLuAhs3eSzfrE13YcVLZkd1"
         },
         {
            "objectId":"0x0000000000000000000000000000000000000000000000000000000000000006",
            "version":158553797,
            "digest":"7BXqfn3E8CDsfzX67JiLWV3ct4ohRU65g1PNhq9uLczP"
         },
         {
            "objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
            "version":409452196,
            "digest":"cHY3mzy38rXW9RSBJZFvBuGA95wpNTjZet4NR136suv"
         }
      ],
      "transactionDigest":"7twEC8GzqF4k6WWtdkMFpkXMkKh2By5kqp2L96QUsBm2",
      "mutated":[
         {
            "owner":{
               "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
            },
            "reference":{
               "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
               "version":409729494,
               "digest":"FefNAP8Aj4bEf8AojbJS5ataBGgGbDij2WeH9T4cKW6V"
            }
         },
         {
            "owner":{
               "Shared":{
                  "initial_shared_version":406731547
               }
            },
            "reference":{
               "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
               "version":409729494,
               "digest":"HvHJ8M8aQhutyHq4MHvFc6zqVsMPVyPT6RhQ3XD7fyQe"
            }
         },
         {
            "owner":{
               "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
            },
            "reference":{
               "objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
               "version":409729494,
               "digest":"7Fn2K9ER2xyNY7S3JwbJVPFKwSWkxwYXnk9oGNWYr5nn"
            }
         }
      ],
      "deleted":[
         {
            "objectId":"0x9f7b58e35999081521c53de1c721c5329d7e1f7c7e4b1b47f85c67772e8f71c7",
            "version":409729494,
            "digest":"7gyGAp71YXQRoxmFBaHxofQXAipvgHyBKPyxmdSJxyvz"
         },
         {
            "objectId":"0xf7ab534ee9fe76a5408b43d2a708402e1e25dae337415770f71d86ea37c79097",
            "version":409729494,
            "digest":"7gyGAp71YXQRoxmFBaHxofQXAipvgHyBKPyxmdSJxyvz"
         }
      ],
      "gasObject":{
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "reference":{
            "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
            "version":409729494,
            "digest":"FefNAP8Aj4bEf8AojbJS5ataBGgGbDij2WeH9T4cKW6V"
         }
      },
      "dependencies":[
         "3SjzbYsqVccUf2XZmHBTcg7GZbfW3NSihQYfDg1Z2wRB",
         "3Zphsgy6XW9SzmD3rKK4fPpwCX2QMMEsSFWXqdrnC8xU",
         "49puDQZwHRnu7zYoARCjco1dFKMiK7LVSS8B5Si1yVdh",
         "7DkJSrf5sPWGxqHbH2X1wXwFcftRm6myhJJnuTJbaMYr",
         "CUQmrEssKtB8WxBYj3YQZJCrFTTDLqz3UWq1nRiWGCLS",
         "HzzEA9X29bCpPE7AJqoxN8zUgefPHztVJu1c73ScgxGa"
      ]
   },
   "events":[
      
   ],
   "objectChanges":[
      {
         "type":"mutated",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "objectType":"0x2::coin::Coin<0x2::sui::SUI>",
         "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
         "version":"409729494",
         "previousVersion":"409729493",
         "digest":"FefNAP8Aj4bEf8AojbJS5ataBGgGbDij2WeH9T4cKW6V"
      },
      {
         "type":"mutated",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "Shared":{
               "initial_shared_version":406731547
            }
         },
         "objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::pool::Pool<0x2::sui::SUI, 0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
         "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
         "version":"409729494",
         "previousVersion":"409729493",
         "digest":"HvHJ8M8aQhutyHq4MHvFc6zqVsMPVyPT6RhQ3XD7fyQe"
      },
      {
         "type":"mutated",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::position::Position",
         "objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
         "version":"409729494",
         "previousVersion":"409729493",
         "digest":"7Fn2K9ER2xyNY7S3JwbJVPFKwSWkxwYXnk9oGNWYr5nn"
      },
      {
         "type":"deleted",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "objectType":"0x2::coin::Coin<0x2::sui::SUI>",
         "objectId":"0x9f7b58e35999081521c53de1c721c5329d7e1f7c7e4b1b47f85c67772e8f71c7",
         "version":"409729494"
      },
      {
         "type":"deleted",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "objectType":"0x2::coin::Coin<0x2::sui::SUI>",
         "objectId":"0xf7ab534ee9fe76a5408b43d2a708402e1e25dae337415770f71d86ea37c79097",
         "version":"409729494"
      }
   ],
   "confirmedLocalExecution":false
}