pancakeMyPosition
Track and manage your liquidity positions on PancakeSwap using the BSC MCP Server. This tool provides insights into your holdings, enabling informed decisions for DeFi strategies.
Instructions
check my liquidity position on panceke
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/pancakeMyPosition.ts:7-38 (registration)Registers the MCP tool 'View_PancakeSwap_Positions' (pancakeMyPosition) on the server.export function registerPancakeMyPosition(server: McpServer) { server.tool("View_PancakeSwap_Positions", "📊View your active liquidity positions on PancakeSwap", {}, async ({}) => { try { const account = await getAccount(); const positions = await myPosition(account.address); return { content: [ { type: "text", text: `get user potitions successfully. ${JSON.stringify(positions, bigIntReplacer)}` }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `get user potitions failed: ${errorMessage}`, }, ], isError: true, }; } } ); }
- src/tools/pancakeMyPosition.ts:9-37 (handler)Inline handler for the tool that fetches account, calls myPosition helper, and returns formatted positions or error.server.tool("View_PancakeSwap_Positions", "📊View your active liquidity positions on PancakeSwap", {}, async ({}) => { try { const account = await getAccount(); const positions = await myPosition(account.address); return { content: [ { type: "text", text: `get user potitions successfully. ${JSON.stringify(positions, bigIntReplacer)}` }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `get user potitions failed: ${errorMessage}`, }, ], isError: true, }; } } );
- Core helper function that queries PancakeSwap V3 positions for a given account address, retrieves detailed info including liquidity amounts, ticks, token details, and current values.export const myPosition = async (accountAddress: Address) => { const balance = await publicClient.readContract({ abi: masterChefV3ABI, address: POSITION_MANAGER_ADDRESS, functionName: 'balanceOf', args: [accountAddress], }) if (Number(balance) === 0) { return; } const nftCalls = [] for (let i = 0; i < Number(balance); i++) { const nftCall = { abi: masterChefV3ABI, address: POSITION_MANAGER_ADDRESS, functionName: 'tokenOfOwnerByIndex', args: [accountAddress, BigInt(i)], } nftCalls.push(nftCall) } const nftIds = await publicClient.multicall<BigInt[]>({ contracts: nftCalls, allowFailure: false, }) const positionCalls = nftIds.map((nftId) => { return { abi: masterChefV3ABI, address: POSITION_MANAGER_ADDRESS, functionName: 'positions', args: [nftId], } }) const positions = await publicClient.multicall<any[]>({ contracts: positionCalls, allowFailure: false, }) as any[] const getTokenInfo = async (token: Address) => { const infoCalls = [ { address: token, abi: ERC20_ABI, functionName: 'symbol', args: [], }, { address: token, abi: ERC20_ABI, functionName: 'name', args: [], }, { address: token, abi: ERC20_ABI, functionName: 'decimals', args: [], }, ] const tokenInfo = await publicClient.multicall<any[]>({ contracts: infoCalls, allowFailure: false, }) as any[] return { token, symbol: tokenInfo[0] as string, name: tokenInfo[1] as string, decimals: Number(tokenInfo[2]), } } const poolTokenInfos = await Promise.all(positions.map(async (position) => { const tokenInfos = await Promise.all([ getTokenInfo(position[2] as Address), getTokenInfo(position[3] as Address), ]); return { token0: tokenInfos[0], token1: tokenInfos[1], } })) as any[] const poolCalls = [] for (const position of positions) { const poolCall = { address: FACTORY_ADDRESS, abi: FACTORY_ABI, functionName: 'getPool', args: [ position[2] as Address, position[3] as Address, BigInt(position[4]) ] } poolCalls.push(poolCall); } const pools = await publicClient.multicall<any[]>({ contracts: poolCalls, allowFailure: false, }) as any[] const slot0Calls = [] for (const pool of pools) { const slot0Call = { address: pool as Address, abi: POOL_ABI, functionName: 'slot0', } slot0Calls.push(slot0Call); } const slot0s = await publicClient.multicall<any[]>({ contracts: slot0Calls, allowFailure: false, }) as any[] const positionInfos = [] for (let i = 0; i < pools.length; i++) { const positionInfo = { tickCurrent: slot0s[i][1], tickLower: positions[i][5], tickUpper: positions[i][6], liquidity: positions[i][7], ...poolTokenInfos[i], feeTier: positions[i][4], positionId: nftIds[i], } const sqrtPriceX96 = TickMath.getSqrtRatioAtTick(positionInfo.tickCurrent); const sqrtPriceAX96 = TickMath.getSqrtRatioAtTick(positionInfo.tickLower); const sqrtPriceBX96 = TickMath.getSqrtRatioAtTick(positionInfo.tickUpper); const liquidity = BigInt(positionInfo.liquidity); let amount0; let amount1; if (positionInfo.tickCurrent < positionInfo.tickLower) { amount0 = SqrtPriceMath.getAmount0Delta(sqrtPriceAX96, sqrtPriceBX96, liquidity, false); amount1 = BigInt(0); } else if (positionInfo.tickCurrent > positionInfo.tickUpper) { amount0 = BigInt(0); amount1 = SqrtPriceMath.getAmount1Delta(sqrtPriceAX96, sqrtPriceBX96, liquidity, false); } else { amount0 = SqrtPriceMath.getAmount0Delta(sqrtPriceX96, sqrtPriceBX96, liquidity, false); amount1 = SqrtPriceMath.getAmount1Delta(sqrtPriceAX96, sqrtPriceX96, liquidity, false); } positionInfos.push({ ...positionInfo, amount0, amount1, amount0Format: formatUnits(amount0, Number(positionInfo.token0.decimals)), amount1Format: formatUnits(amount1, Number(positionInfo.token1.decimals)), }); } return positionInfos; }
- src/main.ts:14-34 (registration)Imports and calls registerPancakeMyPosition to register the tool in the main server setup.import { registerPancakeMyPosition } from "./tools/pancakeMyPosition.js"; import { registerPancakeRemovePosition } from "./tools/pancakeRemovePosition.js"; import { registerGoplusSecurityCheck } from "./tools/goplusSecurityCheck.js"; import { registerQueryMemeTokenDetails } from "./tools/queryMemeTokenDetails.js"; // Main server entry export async function main() { const server = new McpServer({ name: "bsc-mcp", version: "1.0.0" }); // Register all tools registerTransferNativeToken(server); registerTransferBEP20Token(server); registerPancakeSwap(server); registerGetWalletInfo(server); registerBuyMemeToken(server); registerSellMemeToken(server); registerPancakeAddLiquidity(server); registerPancakeMyPosition(server);