Skip to main content
Glama
Pavilion-devs

Saros MCP Server

get_lp_positions

Retrieve all liquidity pool positions for a Solana wallet address, including pool details, token balances, and LP token amounts.

Instructions

Get all liquidity pool positions for a wallet address. Returns pool details, token balances, and LP token amounts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletYesSolana wallet address (base58 encoded)

Implementation Reference

  • Main execution logic for the get_lp_positions tool. Validates input, fetches positions from poolService, formats response with position details.
    async function getLpPositionsTool(args, poolService) {
      const { wallet } = args;
    
      if (!wallet) {
        throw new Error("Wallet address is required");
      }
    
      try {
        const positions = await poolService.getLPPositions(wallet);
    
        if (positions.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No LP positions found for wallet: ${wallet}`,
              },
            ],
          };
        }
    
        // Format positions for display
        const positionsText = positions
          .map(
            (pos, idx) =>
              `\n**Position ${idx + 1}:**\n` +
              `- Pool: ${pos.poolAddress}\n` +
              `- LP Balance: ${pos.lpTokenBalance}\n` +
              `- Token 0: ${pos.token0}\n` +
              `- Token 1: ${pos.token1}\n`
          )
          .join("\n");
    
        return {
          content: [
            {
              type: "text",
              text:
                `Found ${positions.length} LP position(s) for wallet: ${wallet}\n` +
                positionsText +
                `\n\n**Summary:**\n` +
                `Total Positions: ${positions.length}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to get LP positions: ${error.message}`);
      }
    }
  • Input schema and description for the get_lp_positions tool, defined in the ListTools response.
      name: "get_lp_positions",
      description:
        "Get all liquidity pool positions for a wallet address. Returns pool details, token balances, and LP token amounts.",
      inputSchema: {
        type: "object",
        properties: {
          wallet: {
            type: "string",
            description: "Solana wallet address (base58 encoded)",
          },
        },
        required: ["wallet"],
      },
    },
  • src/index.js:156-157 (registration)
    Tool dispatch/registration in the CallToolRequestSchema handler switch statement.
    case "get_lp_positions":
      return await getLpPositionsTool(args, this.poolService);
  • Supporting method in SarosPoolService that retrieves LP token accounts for a wallet and constructs position objects.
    async getLPPositions(walletAddress) {
      try {
        const wallet = new PublicKey(walletAddress);
        const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(
          wallet,
          { programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }
        );
    
        const positions = [];
        for (const account of tokenAccounts.value) {
          const accountInfo = account.account.data.parsed.info;
          const balance = accountInfo.tokenAmount.uiAmount;
          if (balance > 0 && positions.length < 5) {
            positions.push({
              poolAddress: accountInfo.mint,
              lpTokenBalance: balance,
              lpTokenMint: accountInfo.mint,
              token0: "TokenA",
              token1: "TokenB",
            });
          }
        }
        return positions;
      } catch (error) {
        throw new Error(`Failed to get LP positions: ${error.message}`);
      }
    }
  • src/index.js:16-16 (registration)
    Import of the tool handler function.
    const { getLpPositionsTool } = require("./tools/get-lp-positions.js");

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pavilion-devs/saros-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server