quote_sell: friendly message when pool lacks WETH liquidity

This commit is contained in:
Qian
2026-07-17 08:13:18 +00:00
parent 9aac4b1925
commit 94fe128640
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@qianexchange/mcp",
"version": "0.1.2",
"version": "0.1.3",
"description": "MCP server for the Qian multichain DEX & launchpad (qian.ag) — launch and trade tokens from any MCP-capable agent",
"type": "module",
"bin": { "qian-mcp": "server.js" },
+8 -1
View File
@@ -219,7 +219,14 @@ server.registerTool('quote_sell', {
description: 'Preview selling a token for ETH via QianSwapRouter (1% router fee included). Read-only — no wallet, key, or approval needed. Returns expected ETH out.',
inputSchema: { chain: chainSlug, address, token_amount: z.string().describe('Tokens to sell in whole tokens, e.g. "1000000"') },
}, async ({ chain, address: addr, token_amount }) => {
const out = await quoteOut(chain, addr, 'sell', ethers.parseEther(token_amount))
let out
try {
out = await quoteOut(chain, addr, 'sell', ethers.parseEther(token_amount))
} catch (e) {
// Quoters revert when the pool can't cover the WETH out (thin/one-sided liquidity).
if (e?.code === 'CALL_EXCEPTION') throw new Error(`can't sell ${token_amount} tokens — the pool doesn't have enough WETH liquidity for a sell this size (try a smaller amount)`)
throw e
}
return json({ token_in: token_amount, eth_out: ethers.formatEther(out) })
})