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. Meteora

Get All Fees Claimed by a User

Fetch all Fees claimed in Meteora DLMM for a user

Along with percentage of ownership, positions also determine the rewards and fees earned by the liquidity providers for their participation. We can also find out the fees claimed by the liquidity provider. This again involves two simple steps:

  1. We fetch all the position address for the liquidity provider (or the user)

  2. Once we have the position address, we can fetch all transactions for each position address, and look for transactions of the 'CLAIMFEE' type. The actions array in each of these parsed (by SHYFT) 'CLAIMFEE' transactions will contain the details of the fees claimed.

You can directly copy paste this code on replit and see it in action.

import { ShyftSdk,Network } from "@shyft-to/js";

const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";

const shyft = new ShyftSdk({ apiKey: SHYFT_API_KEY, network: Network.Mainnet });

async function getClaimfeeDetails(positionAddress: string) {

    let genesisTxnReached = false;
    let claimFeeTxns:any[] = [];
    let lastSignature = undefined;

    while (!genesisTxnReached) {
        const transactions:any = await shyft.transaction.history({
            account: positionAddress,
            network: Network.Mainnet,
            txNum: 10,
            beforeTxSignature: lastSignature
        });
        transactions.map((txn:any) => {
            if(txn.type === "CLAIMFEE")
                claimFeeTxns.push(txn);
        });

        if(transactions.length < 10){
            genesisTxnReached = true;
            break;
        }
        lastSignature = transactions[transactions.length - 1].signatures[0];
    }
    const amountClaimedDetails:any = [];
    claimFeeTxns.map((claimFeeTxn) => {
        const tokenX = claimFeeTxn.actions[0].info.tokenXMint;
        const tokenY = claimFeeTxn.actions[0].info.tokenYMint;

        let eachAddedTxn:any = {
            "txn_id":claimFeeTxn.signatures[0],
            "onchain_timestamp": claimFeeTxn.timestamp,
        };
        claimFeeTxn.actions.map((action:any) => {
            
            if(action.type === "TOKEN_TRANSFER"){
                if(action.info.token_address === tokenX){
                    eachAddedTxn = {
                        ...eachAddedTxn,
                        "tokenX_amount":action.info.amount_raw,
                        "tokenX_address":action.info.token_address
                    }
                }
                if(action.info.token_address === tokenY){
                    eachAddedTxn = {
                        ...eachAddedTxn,
                        "tokenY_amount":action.info.amount_raw,
                        "tokenY_address":action.info.token_address
                    }
                }
                if(eachAddedTxn.tokenX_amount && eachAddedTxn.tokenY_amount)
                    amountClaimedDetails.push(eachAddedTxn);
            }
        })
    })
    console.log(amountClaimedDetails);

}
// getClaimfeeDetails("CFUjqVgyzNfW88FxR3npGBNoPsyceec8CU3778rJ4F8b")


async function getPositionLiquidityDetails(ownerAddress:string) {
	//querying both position and positionV2 for the owner, or user wallet
    const operationsDoc = `
        query MyQuery {
          meteora_dlmm_PositionV2(
            where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
          ) {
                lbPair
                owner
                pubkey
            }
          meteora_dlmm_Position(
            where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
          ) {
                lbPair
                owner
                pubkey
            }
        }
    `; //you can cherrypick the fields as per your requirement
      const result = await fetch(
        `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
        {
          method: "POST",
          body: JSON.stringify({
            query: operationsDoc,
            variables: {},
            operationName: "MyQuery",
          }),
        }
      );
    
      const { errors, data } = await result.json();
    
      //adding a delay of 2 seconds to avoid rate limiting, only for free API Keys.
      await new Promise((resolve) => setTimeout(resolve, 2000));
    
      if (data.meteora_dlmm_Position.length > 0) {
        for (let index = 0; index < data.meteora_dlmm_Position.length; index++) {
          const position = data.meteora_dlmm_Position[index];

          //get fee claims for each position
          await getClaimfeeDetails(position.pubkey)
        }
      }
    
      //adding a delay of 2 seconds to avoid rate limiting, only for free API Keys.
      await new Promise((resolve) => setTimeout(resolve, 2000));
    
      if (data.meteora_dlmm_PositionV2.length > 0) {
        for (let index = 0; index < data.meteora_dlmm_PositionV2.length; index++) {
          const position = data.meteora_dlmm_PositionV2[index];
        
          //get fee claims for each positionV2
          await getClaimfeeDetails(position.pubkey)
        }
     }
}

getPositionLiquidityDetails("5sJKcYqCWNPJ25PriinfeH7PbFsHxzQhe8kspg2UFexK")
[
  {
    "txn_id": "ckavTmfvkCTjzLRgt6bsPgexgHcRU1WxXub82u8FrYnnaf37PiTtsHEx54CGhtGhocrUDtAz9LLGX3Hy7VyLBPg",
    "onchain_timestamp": "2024-05-10T18:30:51.000Z",
    "tokenX_amount": 3326268,
    "tokenY_address": "So11111111111111111111111111111111111111112",
    "tokenY_amount": 68527528,
    "tokenY_address": "So11111111111111111111111111111111111111112"
  },
  {
    "txn_id": "2j6iT9yUQyq94xsvZJE3zftZUJfb8LvLcxvRFNDPtzKzHrjsLVsuMU17xiNEcWzNe1dnJJaoyZMoCySqecMn7qSR",
    "onchain_timestamp": "2024-05-08T09:30:47.000Z",
    "tokenX_amount": 4023164.0000000005,
    "tokenY_address": "So11111111111111111111111111111111111111112",
    "tokenY_amount": 71484212,
    "tokenY_address": "So11111111111111111111111111111111111111112"
  }
] //sample response, shortened

The above function getClaimfeeDetails can also be used to fetch all claim rewards when only the position address in known.

PreviousGet All Withdraws for a UserNextGet All User Positions and Deposits for a Pool

Last updated 18 days ago

Was this helpful?

📀