Magma Developer SDK
  • Getting started
  • Prerequisites
  • Features Available
  • Retrieve clmm pools
  • Retrieve positions
  • Retrieve reward
  • Retrieve ticks
  • Create clmm pool
  • Open position
  • Add liquidity
  • Remove liquidity
  • Close position
  • Collect fees
  • Collect rewards
  • Preswap
  • Swap
  • Partner swap
  • Smart router
  • Price impact
  • Minimum received & Maximum sold
  • Fee
  • Liquidity correlation calculation
  • APR correlation calculation
Powered by GitBook
On this page
  • 1. Retrieve all positions of one pool by ownerAddress
  • Example
  • 2. Retrieve all positions of one pool
  • Example
  • 3. Retrieve one position
  • Exmaple
  • 4. Batch retrieval of position fee
  • Example

Retrieve positions

1. Retrieve all positions of one pool by ownerAddress

Method: sdk.Position.getPositionList()

Params:

  • accountAddress: The user account address.

  • assignPoolIDs: An array of pool ID.

  • showDisplay: When some testnet rpc nodes can't return object's display data, you can set this option to false, avoid returning errors. Default set true.

Example

async function retrievalPositions() {
  const res = await TestnetSDK.Position.getPositionList(
    '0xd2e4df21b920fba945aa8ad148069a196f0680879c40118beabc3046e2cd8d24',
    ['0x0128aade80123e3f6c5c0eac1a2dee2512bbdc92c9c1b386b0fd66e6cddfaa72'],
    false
  )
  console.log('get positions of one pool by owner address', res)
}

2. Retrieve all positions of one pool

Method: sdk.Pool.getPositionList()

Params:

  • positionHandle: The position handle of pool.

Example

async function retrievalPositionOfOnePool() {
  const pool = await TestnetSDK.Pool.getPool('0xd2e4df21b920fba945aa8ad148069a196f0680879c40118beabc3046e2cd8d24')
  const res = await TestnetSDK.Pool.getPositionList(pool.position_manager.positions_handle)
  console.log('get positions of one pool, the length of positions is: ', res.length)
}

// retrievalPositionOfOnePool()
//get positions of one pool, the length of positions is:  35

3. Retrieve one position

Method: sdk.Position.getPositionById()

Params

  • positionID: The position object ID.

  • calculateRewarder: Whether to calculate the rewarder of the position.

  • showDisplay: When some testnet rpc nodes can't return object's display data, you can set this option to false, avoid returning errors. default set true.

Exmaple

async function retrievalPositionById() {
  const res = await TestnetSDK.Position.getPositionById('0xd2e4df21b920fba945aa8ad148069a196f0680879c40118beabc3046e2cd8d24')
  console.log('get position by id', res)
}

4. Batch retrieval of position fee

Method sdk.Position.batchFetchPositionFees()

Params:

  • positionIDs: An array of position ID.

Example

async function batchFetchPositionFees() {
  const positionIDs = [
    '0xd2e4df21b920fba945aa8ad148069a196f0680879c40118beabc3046e2cd8d24',
    '0xa3638d918aad92ba94b095e87a0f7227c9a4694d198429a3082f29cf62b927a9',
  ]
  const fees = await TestnetSDK.Position.batchFetchPositionFees(positionIDs)
  console.log('batch fetch position fees', fees)
}
PreviousRetrieve clmm poolsNextRetrieve reward

Last updated 4 months ago