Shyft
Start BuildingSupportWebsite
  • Welcome
    • 👋Introducing Shyft
    • 🏗️Start Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚡gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • 📔Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • 🔥Pause a callback
      • 🔥Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • 📀Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • 🔥Pumpswap
        • 🔥Get Pool by Address
        • 🔥Get Pool by Creator Address
        • 🔥Get Pools by Token Addresses
      • 🔥Raydium Launchpad
        • 🔥Get Bonding Curve Details by Pool Address
        • 🔥Get All Pools for a Creator
        • 🔥Get Pools by Token Addresses
        • 🔥Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • 🔥Create Gasless
      • Create
      • Read All
      • Burn
      • 🔥Burn Multiple NFTs V2
      • Update
      • 🔥Create NFT from Metadata
      • 🔥Read Wallet Nfts
      • 🔥Read Selected NFTs
      • 🔥Get NFT Owners
      • 🔥Update NFT Metadata Uri
      • 🔥Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • 🔥Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page

Was this helpful?

  1. Solana Super Indexers
  2. Case Studies
  3. Orca Whirlpool

Get Positions for a Wallet

Fetch a wallet's open positions in Orca pools.

When combined with SHYFT APIs/SDK or DAS, we can also query all the position details with respect to a pool using graphQl. This involves two simple steps,

  • We use SHYFT's APIs/SDK to get all the Orca position mints from a users wallet.

  • We use the position mint to query Orca's position accounts using GraphQL.

The steps are illustrated below.


import { gql, GraphQLClient } from 'graphql-request';

const endpoint = `https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY`; //Shyft's gQl endpoint

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
}); //Initialize gQL Client

async function getFeesOwedbyWallet(walletAddr) {
    const token = await getWhirlpoolPositionToken(walletAddr);

    const query = gql`
    query MyQuery {
        ORCA_WHIRLPOOLS_position(
          where: {positionMint: {_eq: ${JSON.stringify(token.address)}}}
        ) {
          feeOwedB
          feeOwedA
          liquidity
          positionMint
          pubkey
          whirlpool
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}
getFeesOwedbyWallet('2v112XbwQXFrdqX438HUrfZF91qCZb7QRP4bwUiN7JF5')
{
  "data": {
    "ORCA_WHIRLPOOLS_position": [
      {
        "feeOwedB": 188,
        "feeOwedA": 2216,
        "liquidity": 54882,
        "positionMint": "E27sJ6dYK4nkWdZPaPYDdmSeYgbJSTaPDfTUMKXqst64",
        "pubkey": "6qQRFMwX6LFeYbXYpobRF28gqg7ZPtGKwj7zQGRWn3Gq",
        "whirlpool": "67S6KLCtgFZmRYzy6dCDc1v754mmcpK33pZd7Hg2yeVj"
      }
    ]
  }
}

Please note that, the Orca Whirlpool position token can be fetched from a users wallet using multiple ways, one of which is illustrated below

import { Network, ShyftSdk } from '@shyft-to/js';
const shyft = new ShyftSdk({ apiKey: "YOUR-API-KEY", network: Network.Mainnet }); //Initialize Shyft SDK
async function getWhirlpoolPositionToken(walletAddress)
{
    const getAllTokens = await shyft.nft.getNftByOwner(walletAddress);
    //using SHYFT SDK to get all Tokens
    console.log("Total Tokens: ",getAllTokens.length);

    for(let i = 0; i < getAllTokens.length; i++){
        const token = getAllTokens[i];

        if(token.update_authority === "3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr" && token.name.includes("Orca Whirlpool Position")){
            return {
                success: true,
                address: token.mint
            }
        }
    }
    return {
        success: false,
        address: ""
    }
}

All whirlpool position tokens have the update_authority as 3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr and the name as 'Orca Whirlpool Position'. Also, please note that in this case we have considered the wallet address has only one Position token. A wallet can have multiple position token, and in that case, we would have to query with each position token in the users wallet in order to get the desired Whirlpool position details.

PreviousGet Positions for a PoolNextGet Liquidity Details of a Pool

Last updated 1 year ago

Was this helpful?

📀