Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
Agent Sniper: cover signed virtual-reserve depth cases
nirholasbfe69b1ab74f
diff --git a/docs/pumpfun-program/UPSTREAM-pumpswap-virtual-quote-reserves.md b/docs/pumpfun-program/UPSTREAM-pumpswap-virtual-quote-reserves.mdindex 2fd797ace..82698a33c 100644--- a/docs/pumpfun-program/UPSTREAM-pumpswap-virtual-quote-reserves.md+++ b/docs/pumpfun-program/UPSTREAM-pumpswap-virtual-quote-reserves.md@@ -151,7 +151,11 @@ Surfaces updated to price on effective reserves:reserves, so a pool holding real quote-side depth virtually is not failed as`pool_reserves_empty`.- `workers/agent-sniper/amm-exit.js` — position exits and their price-impact- circuit breaker.+ circuit breaker. Because the virtual figure is signed, a quote here refuses a+ pool whose effective depth is non-positive (`amm_quote_depth_empty`) instead of+ pricing it. The refusal is load-bearing: the impact math reports a non-positive+ reserve as 0% impact, i.e. as the safest possible trade, so without it the+ breaker would wave through exactly the pool it exists to stop.- `workers/agent-mm/market.js`, `workers/agent-orders/market.js` — the marketmaker's price and the order book's derived market cap.diff --git a/tests/agent-sniper-amm-exit.test.js b/tests/agent-sniper-amm-exit.test.jsindex 1b6a9924c..10a08805d 100644--- a/tests/agent-sniper-amm-exit.test.js+++ b/tests/agent-sniper-amm-exit.test.js@@ -164,6 +164,43 @@ describe('quoteAmmSell — re-quote a graduated position off the AMM', () => {expect(call.virtualQuoteReserves.toString()).toBe('250000000');});+ // `Pool.virtual_quote_reserves` is a signed i128, so a large negative can put+ // effective depth at or below zero. Such a pool cannot absorb a sale, and the+ // impact math would score it 0% (the safest possible trade) — so the quote has+ // to refuse outright rather than hand the breaker a reassuring number.+ it('refuses a pool whose effective quote depth is wiped out by a negative virtual', async () => {+ mockGetAmmPoolState.mockResolvedValueOnce(+ poolState({ quoteReserve: 1_000_000, virtualQuoteReserves: -1_000_000 }),+ );+ await expect(+ quoteAmmSell({ network: 'mainnet', mint: MINT, baseAmount: new BN(10_000), slippagePct: 5 }),+ ).rejects.toMatchObject({ code: 'amm_quote_depth_empty' });+ expect(mockSellBaseInput).not.toHaveBeenCalled();+ });++ // A negative virtual that only reduces depth is still a tradable pool: it must+ // price normally, against the reduced effective reserve.+ it('prices normally when a negative virtual only reduces depth', async () => {+ mockGetAmmPoolState.mockResolvedValueOnce(+ poolState({ baseReserve: 1_000_000, quoteReserve: 2_000_000, virtualQuoteReserves: -1_000_000 }),+ );+ mockSellBaseInput.mockReturnValueOnce({ uiQuote: new BN(90_000), minQuote: new BN(85_000) });++ const r = await quoteAmmSell({+ network: 'mainnet',+ mint: MINT,+ baseAmount: new BN(100_000),+ slippagePct: 5,+ });+ // effective quote = 2e6 - 1e6 = 1e6; spot value of 100k base = 100k.+ // netting 90k is a 10% impact.+ expect(r.priceImpactPct).toBeCloseTo(10, 5);+ // The SDK still receives the RAW vault balance plus the signed virtual.+ const call = mockSellBaseInput.mock.calls[0][0];+ expect(call.quoteReserve.toString()).toBe('2000000');+ expect(call.virtualQuoteReserves.toString()).toBe('-1000000');+ });+// Impact is measured against the spot price implied by EFFECTIVE reserves.// Virtual liquidity deepens the pool, so the same sale moves it less.it('measures price impact against effective (vault + virtual) reserves', async () => {