Skip to content

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.

agent-sniper: shrink trade size to fit the wallet instead of skipping

nirholasa5f4115e1045
diff --git a/workers/agent-sniper/config.js b/workers/agent-sniper/config.js
index 92a115a07..be552be4b 100644
--- a/workers/agent-sniper/config.js
+++ b/workers/agent-sniper/config.js
@@ -121,6 +121,12 @@ export function loadConfig() {
feedWatchdogMs: Math.max(30_000, num('SNIPER_FEED_WATCHDOG_MS', 180_000)),
// Confirmation timeout for a broadcast trade.
confirmTimeoutMs: Math.max(15_000, num('SNIPER_CONFIRM_TIMEOUT_MS', 60_000)),
+ // Owner directive: the fleet is a learning experiment, not a profit desk — a
+ // wallet too poor for its strategy's configured per_trade_lamports should
+ // shrink the trade to whatever it actually has left rather than sit idle.
+ // This is the floor below that shrink: once even a dust-sized buy wouldn't
+ // clear it, THEN skip with insufficient_sol. Default 0.00001 SOL.
+ minTradeLamports: BigInt(Math.max(1, Math.round(num('SNIPER_MIN_TRADE_LAMPORTS', 10_000)))),
// ── liveness + alerting ──────────────────────────────────────────────────
// How often the worker upserts its bot_heartbeat row. /api/sniper/status
// (and /status) read this to answer "is the sniper alive?" without SSH.
diff --git a/workers/agent-sniper/executor.js b/workers/agent-sniper/executor.js
index 9c0f4d779..df5acaff7 100644
--- a/workers/agent-sniper/executor.js
+++ b/workers/agent-sniper/executor.js
@@ -235,7 +235,7 @@ function makeTipGuard({ strat, network, alreadyCommittedLamports, dailySpentLamp
*/
export async function executeBuy({ cfg, strat, mint, throttle }) {
return withAgentLock(strat.agent_id, async () => {
- const perTrade = BigInt(strat.per_trade_lamports);
+ let perTrade = BigInt(strat.per_trade_lamports);
const tag = { agent: strat.agent_id, mint: mint.mint, symbol: mint.symbol };
// 0. Mayhem exclusion (owner rule) — NEVER buy pump.fun Mayhem tokens, only
@@ -319,7 +319,17 @@ export async function executeBuy({ cfg, strat, mint, throttle }) {
return skip(tag, 'wallet_precheck_failed');
}
const headroom = checkSolHeadroom(preBalance, perTrade, SOL_FEE_HEADROOM_LAMPORTS);
- if (headroom) return skip(tag, headroom.reason);
+ if (headroom) {
+ // Learning > profit (owner directive): a wallet too poor for the
+ // strategy's configured size still trades, shrunk to whatever is left
+ // after the fee/rent headroom — it only sits out once even a
+ // cfg.minTradeLamports-sized buy wouldn't fit. Safe to shrink here: every
+ // check already passed above (budget, spend policy) is a ceiling a
+ // smaller trade only clears more easily, never less.
+ const dustCapable = preBalance - SOL_FEE_HEADROOM_LAMPORTS;
+ if (dustCapable < cfg.minTradeLamports) return skip(tag, headroom.reason);
+ perTrade = dustCapable;
+ }
// 5. idempotency lock — claim the (agent,mint,network) slot BEFORE the tx.
// The wallet is known now, so it's written on the claim (no later UPDATE).