UNPKG

uniderp-mcp

Version:

> A plug-and-play MCP tool server to **send ETH**, **transfer ERC-20 tokens**, **deploy tokens**, and **interact with smart contracts** on the **UNICHAIN** — built for **Claude Desktop**, **AI agents**, and **developers.**

105 lines (104 loc) 3.15 kB
import { parseAbi, zeroAddress } from "viem"; import { publicClient } from "../config.js"; import { positionManagerAbi } from "../lib/abi/positionManagerAbi.js"; import { AddressConfig } from "../addressConfig.js"; const ERC20_ABI = parseAbi([ "function decimals() external view returns (uint256)", "function symbol() external view returns (string)", "function name() external view returns (string)", ]); const fetchOwnedPositions = async (owner) => { const query = ` query GetPositionsByOwner($owner: String!) { positions(where: { owner: $owner }) { id } } `; const res = await fetch("https://api.thegraph.com/subgraphs/id/Qmd78a3BJf4TzD3H3QPQpBgUrzWZErSmJtFrsvUW6c3M6u", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query, variables: { owner }, }), }); const { data } = await res.json(); return data.positions.map((pos) => BigInt(pos.id)); }; const getTokenInfo = async (token) => { if (token === zeroAddress) { return { token, symbol: "ETH", name: "ETH", decimals: 18, }; } 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({ contracts: infoCalls, allowFailure: false, })); return { token, symbol: tokenInfo[0], name: tokenInfo[1], decimals: Number(tokenInfo[2]), }; }; export const myPosition = async (accountAddress) => { const balance = await publicClient.readContract({ abi: positionManagerAbi, address: AddressConfig.UniswapPositionManagerContract, functionName: "balanceOf", args: [accountAddress], }); if (Number(balance) === 0) { return; } // Read thegraphs get list position NFTs const nftIds = await fetchOwnedPositions(accountAddress.toLowerCase()); // Read contract getPoolAndPositionInfo const nftCalls = nftIds.map((i) => ({ abi: positionManagerAbi, address: AddressConfig.UniswapPositionManagerContract, functionName: "getPoolAndPositionInfo", args: [i], })); const poolAndPositionInfos = await publicClient.multicall({ contracts: nftCalls, allowFailure: false, }); const poolTokenInfos = (await Promise.all(poolAndPositionInfos.map(async ([pool]) => { const tokenInfos = await Promise.all([ getTokenInfo(pool.currency0), getTokenInfo(pool.currency1), ]); return { ...pool, token0: tokenInfos[0], token1: tokenInfos[1], }; }))); return poolTokenInfos; };