API Reference

Open Position

You can use the openPosition() function to open a new position without providing any liquidity. This option is available as from a contract-implementation perspective it's a good practice to have it separated from the functions for providing liquidity, but from a user-perspective the best option will be to use openPositionWithFixedAmount() (explained in the following section) to directly provide liquidity when opening the position and start accruing fees and rewards.

Only the range of the price (lower and upper) you're providing liquidity for has to be set.

Example

import { OnChainCalls, QueryChain } from "@firefly-exchange/library-sui/dist/src/spot";
import { TickMath } from "@firefly-exchange/library-sui/dist/src/spot/clmm";
import { Ed25519Keypair, SuiClient } from "@firefly-exchange/library-sui";
import { Decimal} from 'decimal.js'
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
/// - poolID          	: The id of the the pool ex: 0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa 
/// - lowerPrice				: The lower price boundary. 
///												This should be a decimal such as 1.6 as the decimal places are handled internally
/// - upperPrice				: The upper price boundary. 
///                       This should be a decimal such as 1.7 as the decimal places are handled internally

async function openPosition(privateKey: string, poolID: string, lowerPrice: number, upperPrice: number){
    const keyPair = Ed25519Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));

    let oc = new OnChainCalls(client, mainnet, {signer: keyPair});
    let qc = new QueryChain(client);
    let pool = await qc.getPool(poolID);

    let lowerTickBits = TickMath.priceToInitializableTickIndex(new Decimal(lowerPrice),pool.coin_a.decimals,pool.coin_b.decimals,pool.ticks_manager.tick_spacing);
    let upperTickBits = TickMath.priceToInitializableTickIndex(new Decimal(upperPrice),pool.coin_a.decimals,pool.coin_b.decimals,pool.ticks_manager.tick_spacing);

    let resp = await oc.openPosition(pool,lowerTickBits,upperTickBits);
    return resp
}

await openPosition("<private key>","0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",1.765,2.123)

Response

{
   "digest":"G8bfecxuKSH4aUvt1R7SGRoKe77Mif63RvY3SZ5Kcgn7",
   "transaction":{
      "data":{
         "messageVersion":"v1",
         "transaction":{
            "kind":"ProgrammableTransaction",
            "inputs":[
               {
                  "type":"object",
                  "objectType":"sharedObject",
                  "objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
                  "initialSharedVersion":"406496849",
                  "mutable":false
               },
               {
                  "type":"object",
                  "objectType":"sharedObject",
                  "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
                  "initialSharedVersion":"406731547",
                  "mutable":true
               },
               {
                  "type":"pure",
                  "valueType":"u32",
                  "value":4294904096
               },
               {
                  "type":"pure",
                  "valueType":"u32",
                  "value":4294905176
               },
               {
                  "type":"pure",
                  "valueType":"address",
                  "value":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
               }
            ],
            "transactions":[
               {
                  "MoveCall":{
                     "package":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
                     "module":"pool",
                     "function":"open_position",
                     "type_arguments":[
                        "0x2::sui::SUI",
                        "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
                     ],
                     "arguments":[
                        {
                           "Input":0
                        },
                        {
                           "Input":1
                        },
                        {
                           "Input":2
                        },
                        {
                           "Input":3
                        }
                     ]
                  }
               },
               {
                  "TransferObjects":[
                     [
                        {
                           "NestedResult":[
                              0,
                              0
                           ]
                        }
                     ],
                     {
                        "Input":4
                     }
                  ]
               }
            ]
         },
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "gasData":{
            "payment":[
               {
                  "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
                  "version":409729489,
                  "digest":"AqUCa6kwrYrYTPuvhejmezMvTzLGfVXweUq4H4gyBhBK"
               },
               {
                  "objectId":"0xfb6a2f020347f4fdfed73287456bdf50c7604a53ec8f3322e8238981019ceed3",
                  "version":409729489,
                  "digest":"HnMoFYrNdKNmBzsx8rCMCfQz37h7F6cjpwaVuwmmiaPk"
               }
            ],
            "owner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
            "price":"750",
            "budget":"7496628"
         }
      },
      "txSignatures":[
         "AFIiTg3wY+ZJItth+Vm2GkPkMsGSTkuWQRE+r4mfs4Jq95caTdGftpjPUsXp5Nogg/TnuJit7wWGUfWxi8RYFANwIesVczXTTL/3Q5yIJFnOVC24GMSqzrdNJIY1vK3z9w=="
      ]
   },
   "effects":{
      "messageVersion":"v1",
      "status":{
         "status":"success"
      },
      "executedEpoch":"566",
      "gasUsed":{
         "computationCost":"750000",
         "storageCost":"12790800",
         "storageRebate":"8750412",
         "nonRefundableStorageFee":"88388"
      },
      "modifiedAtVersions":[
         {
            "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
            "sequenceNumber":"409729489"
         },
         {
            "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
            "sequenceNumber":"409719165"
         },
         {
            "objectId":"0xfb6a2f020347f4fdfed73287456bdf50c7604a53ec8f3322e8238981019ceed3",
            "sequenceNumber":"409729489"
         }
      ],
      "sharedObjects":[
         {
            "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
            "version":409719165,
            "digest":"GorZj6vDMa3n4fS65SCQbyRksoE3Jrb5csnb5u44rD4T"
         },
         {
            "objectId":"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
            "version":409452196,
            "digest":"cHY3mzy38rXW9RSBJZFvBuGA95wpNTjZet4NR136suv"
         }
      ],
      "transactionDigest":"G8bfecxuKSH4aUvt1R7SGRoKe77Mif63RvY3SZ5Kcgn7",
      "created":[
         {
            "owner":{
               "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
            },
            "reference":{
               "objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
               "version":409729490,
               "digest":"4JPLXTrmK17aVDexxKgC5sEXj1aWwQPNVh4xw2hGYcFt"
            }
         }
      ],
      "mutated":[
         {
            "owner":{
               "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
            },
            "reference":{
               "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
               "version":409729490,
               "digest":"9pjqoMBXq3n8LcxSusfQEHPdCdc3ykNfA5teyRwGdpRJ"
            }
         },
         {
            "owner":{
               "Shared":{
                  "initial_shared_version":406731547
               }
            },
            "reference":{
               "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
               "version":409729490,
               "digest":"4q5LDhCbMz22vtP4QbXSAJu51LuL591QCJJay7QEbUwT"
            }
         }
      ],
      "deleted":[
         {
            "objectId":"0xfb6a2f020347f4fdfed73287456bdf50c7604a53ec8f3322e8238981019ceed3",
            "version":409729490,
            "digest":"7gyGAp71YXQRoxmFBaHxofQXAipvgHyBKPyxmdSJxyvz"
         }
      ],
      "gasObject":{
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "reference":{
            "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
            "version":409729490,
            "digest":"9pjqoMBXq3n8LcxSusfQEHPdCdc3ykNfA5teyRwGdpRJ"
         }
      },
      "eventsDigest":"3SqvkbaNt6z3PsQhNWZGLC7VbGQjymbRtiq8WR5AXVVy",
      "dependencies":[
         "49puDQZwHRnu7zYoARCjco1dFKMiK7LVSS8B5Si1yVdh",
         "7DkJSrf5sPWGxqHbH2X1wXwFcftRm6myhJJnuTJbaMYr",
         "7L5AgPDJLWSvu6jTuDzhBn4rXQSuGVJP7ktqzDjxai8U",
         "9PNJrhnL9mh66bRUoaFsBhNCrDpsQLHRxkL7KAWyD8y5",
         "CUQmrEssKtB8WxBYj3YQZJCrFTTDLqz3UWq1nRiWGCLS",
         "HzzEA9X29bCpPE7AJqoxN8zUgefPHztVJu1c73ScgxGa"
      ]
   },
   "events":[
      {
         "id":{
            "txDigest":"G8bfecxuKSH4aUvt1R7SGRoKe77Mif63RvY3SZ5Kcgn7",
            "eventSeq":"0"
         },
         "packageId":"0xb104ecc75397f3a65735ef26c85a037da1d197e26f4f275a9990a577ba0e6c4c",
         "transactionModule":"pool",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "type":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::events::PositionOpened",
         "parsedJson":{
            "pool_id":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
            "position_id":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
            "tick_lower":{
               "bits":4294904096
            },
            "tick_upper":{
               "bits":4294905176
            }
         },
         "bcs":"sohCoDyvLf4CQipTnodRTEH58h9JKxAg9YRJF2pWjgcWwju9NCgDaUqnWGtebnNqkhcKkbfpYMGj1DRn6poGoTtpBgmtXD66nJ"
      }
   ],
   "objectChanges":[
      {
         "type":"mutated",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "objectType":"0x2::coin::Coin<0x2::sui::SUI>",
         "objectId":"0x10611c2158f9d0456e6eb47b8b4168fd0fcab2102a1338cededb8cfbfc764367",
         "version":"409729490",
         "previousVersion":"409729489",
         "digest":"9pjqoMBXq3n8LcxSusfQEHPdCdc3ykNfA5teyRwGdpRJ"
      },
      {
         "type":"mutated",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "Shared":{
               "initial_shared_version":406731547
            }
         },
         "objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::pool::Pool<0x2::sui::SUI, 0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC>",
         "objectId":"0x3b585786b13af1d8ea067ab37101b6513a05d2f90cfe60e8b1d9e1b46a63c4fa",
         "version":"409729490",
         "previousVersion":"409719165",
         "digest":"4q5LDhCbMz22vtP4QbXSAJu51LuL591QCJJay7QEbUwT"
      },
      {
         "type":"created",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "owner":{
            "AddressOwner":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269"
         },
         "objectType":"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267::position::Position",
         "objectId":"0x75857c5d605a7f6c09a84052f04915495906464e8947a9e3a83df7575afd405e",
         "version":"409729490",
         "digest":"4JPLXTrmK17aVDexxKgC5sEXj1aWwQPNVh4xw2hGYcFt"
      },
      {
         "type":"deleted",
         "sender":"0xa2d6fcd5ed2ae13fe527a96c96100120d519900599f33e38ee112d80e51f9269",
         "objectType":"0x2::coin::Coin<0x2::sui::SUI>",
         "objectId":"0xfb6a2f020347f4fdfed73287456bdf50c7604a53ec8f3322e8238981019ceed3",
         "version":"409729490"
      }
   ],
   "confirmedLocalExecution":false
}