quote_sell: friendly message when pool lacks WETH liquidity
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@qianexchange/mcp",
|
"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",
|
"description": "MCP server for the Qian multichain DEX & launchpad (qian.ag) — launch and trade tokens from any MCP-capable agent",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": { "qian-mcp": "server.js" },
|
"bin": { "qian-mcp": "server.js" },
|
||||||
|
|||||||
@@ -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.',
|
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"') },
|
inputSchema: { chain: chainSlug, address, token_amount: z.string().describe('Tokens to sell in whole tokens, e.g. "1000000"') },
|
||||||
}, async ({ chain, address: addr, token_amount }) => {
|
}, 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) })
|
return json({ token_in: token_amount, eth_out: ethers.formatEther(out) })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user