@rushr/mcp 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,34 @@ The trading logic and its guards come from [Talos](../agents/examples/test-agent
26
26
  | `sell` | Sells `percent` (default 100) or an exact `amount`. It sends the approvals the build asks for, then the trade (and on a curve, the fee transfer), and returns the hashes and explorer links. |
27
27
  | `post_callout` | Posts a bullish or bearish call. A disclosure is appended saying an AI agent posted it and whether it holds the token. |
28
28
  | `delete_callout` | Deletes one of your own callouts. |
29
+ | `journal` | Lists outcomes worth remembering, newest first: positions the agent fully sold (realized PnL, hold time) and how its calls moved since posting. |
30
+
31
+ ## Journal
32
+
33
+ `buy`, `sell` and `post_callout` also return a `journal` entry, and the `journal` tool lists outcomes later. Each entry is a small, stable record an agent can save to its memory (for example with [Memoria](https://www.memoriaagent.site)):
34
+
35
+ ```json
36
+ {
37
+ "v": 1,
38
+ "kind": "trade",
39
+ "id": "rushr:trade:0x…",
40
+ "at": "2026-11-24T09:00:00.000Z",
41
+ "agent": { "handle": "my_agent", "wallet": "0x…" },
42
+ "token": { "chainId": 4663, "address": "0x…", "symbol": "NEARL" },
43
+ "context": { "symbol": "NEARL", "marketCapUsd": 12100, "priceUsd": 0.0000121, "riskLevel": "low", "flags": [], "venue": "pons-curve" },
44
+ "action": { "side": "buy", "usd": 25, "tx": "0x…" },
45
+ "outcome": null,
46
+ "summary": "Bought $25 of $NEARL at $12.1K market cap, risk low, on the PONS curve.",
47
+ "memory": { "note": "Bought $25 of $NEARL at $12.1K market cap, risk low, on the PONS curve.", "topic": "rushr/trades", "reason": null, "confidence": null },
48
+ "links": { "token": "https://app.rushr.trade/token/0x…", "tx": "https://robinhoodchain.blockscout.com/tx/0x…" }
49
+ }
50
+ ```
51
+
52
+ - `kind` is `trade`, `call`, `position_closed` (with `outcome: { realizedUsd, pnlPct, boughtUsd, soldUsd, holdMinutes }`) or `call_result` (with `outcome: { movePct, peakPct, ageHours, wentRight }`).
53
+ - `id` is stable, so saving the same entry twice can be skipped.
54
+ - `memory` is ready for a memory tool that stores a note with a topic (`rushr/trades`, `rushr/calls`, `rushr/lessons`). Fill in `reason` and `confidence` yourself before saving: only your agent knows why it acted.
55
+ - In dry run (`RUSHR_DRY_RUN=1`), trades return an entry with `dryRun: true` and a "Simulated…" summary.
56
+ - The MCP only returns entries. It never sends them anywhere.
29
57
 
30
58
  ## Install
31
59
 
package/dist/index.js CHANGED
@@ -138,7 +138,7 @@ function createApi(o) {
138
138
  // src/guards.ts
139
139
  import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
140
140
  import { dirname } from "node:path";
141
- import { decodeFunctionData, erc20Abi as erc20Abi2, parseEther as parseEther2 } from "viem";
141
+ import { decodeFunctionData, erc20Abi as erc20Abi2, parseAbi as parseAbi3, parseEther as parseEther2 } from "viem";
142
142
 
143
143
  // ../trade/src/abis.ts
144
144
  import { parseAbi } from "viem";
@@ -182,6 +182,8 @@ var ponsCurveAbi = parseAbi([
182
182
  "function token() view returns (address)",
183
183
  "function factory() view returns (address)",
184
184
  "function isNativeQuote() view returns (bool)",
185
+ /** The ERC-20 a non-native curve is priced in (e.g. ANT); pulled with transferFrom on buy, paid out on sell. */
186
+ "function pairToken() view returns (address)",
185
187
  "function realQuoteReserve() view returns (uint256)",
186
188
  "function graduationThreshold() view returns (uint256)",
187
189
  "function sellableTokens() view returns (uint256)"
@@ -298,6 +300,10 @@ var INFRA_ADDRESSES = [
298
300
  UNISWAP.permit2,
299
301
  "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789",
300
302
  // ERC-4337 EntryPoint v0.6
303
+ // Routers the FOMO app trades through (curve and pool trades): they receive the token and forward it to
304
+ // the user in the same tx, so they are never the trader. Seen on NEARL, 24 Nov 2026.
305
+ "0x0005ea38eb0a69d1253508ebdbdb9ea8cb26b5ef",
306
+ "0x8f10b468b06c6fd214b65f87778827f7d113f996",
301
307
  "0x0000000000000000000000000000000000000000",
302
308
  "0x000000000000000000000000000000000000dead"
303
309
  ];
@@ -337,11 +343,20 @@ var TRADE_ADDRESSES = {
337
343
  import { getAddress, isAddress } from "viem";
338
344
  var RUSHR_TREASURY = "0x2Ae062C61A757b66D3039154a6e965aa48Cd75F3";
339
345
  var BETA_FEE_BPS = 25;
346
+ var RUSHR_TOKEN = "0xa8ceeeb747fcf136947c35c5de6187ee90d6bfed";
347
+ var RUSHR = 10n ** 18n;
348
+ var HOLDER_TIERS = [
349
+ { min: 50000000n * RUSHR, discountBps: 5e3 },
350
+ { min: 10000000n * RUSHR, discountBps: 2500 },
351
+ { min: 1000000n * RUSHR, discountBps: 1e3 }
352
+ ];
340
353
  var DEFAULT_TRADE_CONFIG = {
341
354
  feeBps: BETA_FEE_BPS,
342
355
  // beta rate; STANDARD_FEE_BPS after the beta
343
356
  referralDiscountBps: 1e3,
344
357
  referrerShareBps: 2e3,
358
+ holderTiers: HOLDER_TIERS,
359
+ rushrToken: RUSHR_TOKEN,
345
360
  feeRecipient: RUSHR_TREASURY,
346
361
  universalRouter: TRADE_ADDRESSES.universalRouter,
347
362
  ponsRouter: null,
@@ -363,6 +378,7 @@ var GuardError = class extends Error {
363
378
  }
364
379
  };
365
380
  var isCurve = (q) => q.pool.venue === "pons-curve";
381
+ var isPairCurve = (b) => b.route?.kind === "pair-curve";
366
382
  var ROUTERS = /* @__PURE__ */ new Set([TRADE_ADDRESSES.universalRouter.toLowerCase()]);
367
383
  var PERMIT2 = TRADE_ADDRESSES.permit2.toLowerCase();
368
384
  var CHAIN_ID = TRADE_ADDRESSES.chainId;
@@ -370,6 +386,8 @@ var SELECTOR_ERC20_APPROVE = "0x095ea7b3";
370
386
  var SELECTOR_PERMIT2_APPROVE = "0x87517c45";
371
387
  var MAX_FEE_BPS = 25;
372
388
  function vetBuild(b, side, token, amountIn, opts = {}) {
389
+ if (isPairCurve(b)) return vetPairCurveBuild(b, side, token, amountIn, { trader: opts.trader, curveOnChain: opts.curveOnChain, requireSimulation: opts.requireSimulation });
390
+ if (!b.tx) throw new GuardError("refused_unsafe_build", "refusing to sign: the build has no transaction", { problems: ["tx is null"] });
373
391
  if (isCurve(b.quote)) return vetCurveBuild(b, side, token, amountIn, { trader: opts.trader, curveOnChain: opts.curveOnChain, requireSimulation: opts.requireSimulation });
374
392
  const problems = [];
375
393
  if (b.followUp) problems.push("a Uniswap build asked for a follow-up transaction");
@@ -433,8 +451,8 @@ var SpendLedger = class {
433
451
  spent24h(now = Date.now()) {
434
452
  return this.spentSince(864e5, now);
435
453
  }
436
- record(usd2, hash, now = Date.now()) {
437
- this.entries = [...this.entries.filter((e) => e.at >= now - 864e5), { at: now, usd: usd2, hash }];
454
+ record(usd3, hash, now = Date.now()) {
455
+ this.entries = [...this.entries.filter((e) => e.at >= now - 864e5), { at: now, usd: usd3, hash }];
438
456
  if (this.path) {
439
457
  mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
440
458
  writeFileSync(this.path, `${JSON.stringify({ entries: this.entries })}
@@ -458,6 +476,7 @@ function feeTxProblems(tx, value, label) {
458
476
  return p;
459
477
  }
460
478
  function vetCurveBuild(b, side, token, amountIn, opts = {}) {
479
+ if (!b.tx) throw new GuardError("refused_unsafe_build", "refusing to sign: the curve build has no transaction", { problems: ["tx is null"] });
461
480
  const problems = [];
462
481
  const curve = (b.quote.pool.curve ?? b.quote.pool.id ?? "").toLowerCase();
463
482
  if (!/^0x[0-9a-f]{40}$/.test(curve)) problems.push("quote names no curve address");
@@ -504,6 +523,111 @@ function vetCurveBuild(b, side, token, amountIn, opts = {}) {
504
523
  if (opts.requireSimulation !== false && !b.simulation?.ok) problems.push(`simulation failed: ${b.simulation?.error ?? "missing"}`);
505
524
  if (problems.length) throw new GuardError("refused_unsafe_build", `refusing to sign: ${problems.join("; ")}`, { problems });
506
525
  }
526
+ var universalRouterAbi = parseAbi3(["function execute(bytes commands, bytes[] inputs, uint256 deadline) payable"]);
527
+ function vetPairCurveBuild(b, side, token, amountIn, opts = {}) {
528
+ const problems = [];
529
+ const r = b.route;
530
+ const steps = b.steps ?? [];
531
+ const fail = () => {
532
+ throw new GuardError("refused_unsafe_build", `refusing to sign: ${problems.join("; ")}`, { problems });
533
+ };
534
+ if (!r || r.kind !== "pair-curve") problems.push("build has no pair-curve route");
535
+ if (b.tx) problems.push("a pair-curve build also has a tx");
536
+ if (b.followUp) problems.push("a pair-curve build asked for a follow-up transaction");
537
+ if (b.approvals?.length) problems.push("a pair-curve build has top-level approvals (they belong in steps)");
538
+ if (!steps.length) problems.push("build has no steps");
539
+ if (problems.length) fail();
540
+ const route = r;
541
+ const pair = route.pairToken?.toLowerCase() ?? "";
542
+ const curve = route.curve?.toLowerCase() ?? "";
543
+ if (!/^0x[0-9a-f]{40}$/.test(pair)) problems.push("route names no pair token");
544
+ if (!/^0x[0-9a-f]{40}$/.test(curve)) problems.push("route names no curve");
545
+ if (sameAddr(pair, token)) problems.push("pair token is the traded token");
546
+ const quoted = b.quote.pool.curve ?? b.quote.pool.id;
547
+ if (!sameAddr(quoted, curve)) problems.push(`route.curve ${route.curve} is not the quoted curve ${quoted}`);
548
+ if (!opts.curveOnChain) problems.push("couldn't confirm the token's PONS curve on-chain");
549
+ else if (!sameAddr(curve, opts.curveOnChain)) problems.push(`route curve ${route.curve} is not the token's PONS curve ${opts.curveOnChain}`);
550
+ let minPair = 0n;
551
+ try {
552
+ minPair = BigInt(route.minPairAmount);
553
+ } catch {
554
+ problems.push("route.minPairAmount is not an amount");
555
+ }
556
+ if (minPair <= 0n) problems.push("route.minPairAmount is not positive");
557
+ steps.forEach((s, i) => {
558
+ if (s.step !== i + 1) problems.push(`step ${i + 1} is numbered ${s.step}`);
559
+ });
560
+ const trades = steps.filter((s) => s.kind !== "approve");
561
+ const order = side === "buy" ? ["swap", "curve"] : ["curve", "swap"];
562
+ if (trades.length !== 2 || trades[0].kind !== order[0] || trades[1].kind !== order[1]) problems.push(`trading steps are [${trades.map((s) => s.kind).join(", ")}], expected [${order.join(", ")}]`);
563
+ if (steps.length < 2 || steps.slice(0, -2).some((s) => s.kind !== "approve")) problems.push("approvals must all come before the two trading steps");
564
+ const swap = steps.find((s) => s.kind === "swap");
565
+ const curveStep = steps.find((s) => s.kind === "curve");
566
+ if (swap && route.swapStep !== swap.step) problems.push(`route.swapStep ${route.swapStep} is not the swap step ${swap.step}`);
567
+ if (curveStep && route.curveStep !== curveStep.step) problems.push(`route.curveStep ${route.curveStep} is not the curve step ${curveStep.step}`);
568
+ for (const s of steps) {
569
+ const label = `step ${s.step} (${s.kind})`;
570
+ if (!s.tx) {
571
+ problems.push(`${label}: missing tx`);
572
+ continue;
573
+ }
574
+ if (s.tx.chainId !== void 0 && s.tx.chainId !== CHAIN_ID) problems.push(`${label}: chainId ${s.tx.chainId}`);
575
+ if (s.kind === "approve") problems.push(...pairApprovalProblems(s.tx, side, token, pair, curve, label));
576
+ }
577
+ if (swap?.tx) {
578
+ if (!ROUTERS.has(swap.tx.to.toLowerCase())) problems.push(`swap step: sends to ${swap.tx.to}, not the Universal Router`);
579
+ const want = side === "buy" ? amountIn : 0n;
580
+ if (BigInt(swap.tx.value) !== want) problems.push(`swap step: value ${swap.tx.value} != ${want}`);
581
+ try {
582
+ const d = decodeFunctionData({ abi: universalRouterAbi, data: swap.tx.data });
583
+ const deadline = d.args[2];
584
+ if (b.deadline === null || deadline !== BigInt(b.deadline)) problems.push(`swap step: deadline ${deadline} != build deadline ${b.deadline}`);
585
+ } catch {
586
+ problems.push("swap step: calldata is not Universal Router execute(commands, inputs, deadline)");
587
+ }
588
+ }
589
+ if (curveStep?.tx) {
590
+ if (!sameAddr(curveStep.tx.to, curve)) problems.push(`curve step: sends to ${curveStep.tx.to}, not route.curve ${route.curve}`);
591
+ if (BigInt(curveStep.tx.value) !== 0n) problems.push(`curve step: value ${curveStep.tx.value}`);
592
+ try {
593
+ const call = decodeFunctionData({ abi: ponsCurveAbi, data: curveStep.tx.data });
594
+ if (call.functionName !== side) problems.push(`curve step: calls ${call.functionName}, expected ${side}`);
595
+ else {
596
+ const [amt, , recipient] = call.args;
597
+ const want = side === "buy" ? minPair : amountIn;
598
+ if (amt !== want) problems.push(`curve step: amount ${amt} != ${side === "buy" ? "route.minPairAmount" : "amountIn"} ${want}`);
599
+ if (!opts.trader || !sameAddr(recipient, opts.trader)) problems.push(`curve step: recipient ${recipient} is not this wallet`);
600
+ }
601
+ } catch {
602
+ problems.push("curve step: calldata is not a PONS curve buy or sell");
603
+ }
604
+ }
605
+ if (b.deadline === null) problems.push("pair-curve build has no deadline");
606
+ if (BigInt(b.quote.amountIn) !== amountIn) problems.push("quote.amountIn differs from the request");
607
+ if (b.quote.fee.feeBps > MAX_FEE_BPS) problems.push(`fee ${b.quote.fee.feeBps} bps (max ${MAX_FEE_BPS})`);
608
+ if (opts.requireSimulation !== false && !b.simulation?.ok) problems.push(`simulation failed: ${b.simulation?.error ?? "missing"}`);
609
+ if (problems.length) fail();
610
+ }
611
+ function pairApprovalProblems(tx, side, token, pair, curve, label) {
612
+ if (BigInt(tx.value) !== 0n) return [`${label}: approval with value`];
613
+ const to = tx.to.toLowerCase();
614
+ try {
615
+ if (to === PERMIT2) {
616
+ const d2 = decodeFunctionData({ abi: permit2Abi, data: tx.data });
617
+ const [t, spender2] = d2.args;
618
+ if (side === "sell" && d2.functionName === "approve" && sameAddr(t, pair) && ROUTERS.has(spender2.toLowerCase())) return [];
619
+ return [`${label}: unexpected Permit2 call ${d2.functionName}`];
620
+ }
621
+ const d = decodeFunctionData({ abi: erc20Abi2, data: tx.data });
622
+ if (d.functionName !== "approve") return [`${label}: calls ${d.functionName}, not approve`];
623
+ const spender = d.args[0].toLowerCase();
624
+ if (to === pair && (spender === curve || side === "sell" && spender === PERMIT2)) return [];
625
+ if (side === "sell" && sameAddr(to, token) && spender === curve) return [];
626
+ return [`${label}: unexpected approval on ${tx.to} for ${spender}`];
627
+ } catch {
628
+ return [`${label}: calldata is not an approval`];
629
+ }
630
+ }
507
631
  function checkFeeUnpaid(e, i) {
508
632
  const owed = BigInt(e.owed);
509
633
  const problems = feeTxProblems(e.feeTx, owed, "feeTx");
@@ -539,11 +663,11 @@ function checkEthUsd(rushr, dex) {
539
663
  if (!(rushr > 500 && rushr < 2e4)) throw new GuardError("refused_price_out_of_band", `ETH/USD ${rushr} is outside $500-20,000`);
540
664
  return rushr;
541
665
  }
542
- var usdToWei = (usd2, ethUsd) => parseEther3((usd2 / ethUsd).toFixed(18));
666
+ var usdToWei = (usd3, ethUsd) => parseEther3((usd3 / ethUsd).toFixed(18));
543
667
  var weiToUsd = (wei, ethUsd) => Number(formatEther(wei)) * ethUsd;
544
668
 
545
669
  // src/rushr.ts
546
- import { createPublicClient, createWalletClient, erc20Abi as erc20Abi3, formatEther as formatEther2, http, parseEther as parseEther4, zeroAddress } from "viem";
670
+ import { createPublicClient, createWalletClient, decodeFunctionData as decodeFunctionData2, encodeFunctionData, erc20Abi as erc20Abi3, formatEther as formatEther2, formatUnits, http, parseEther as parseEther4, zeroAddress } from "viem";
547
671
 
548
672
  // ../trade/src/chain.ts
549
673
  import { defineChain } from "viem";
@@ -622,6 +746,98 @@ function createWalletFile(path) {
622
746
  return address2;
623
747
  }
624
748
 
749
+ // src/journal.ts
750
+ var JOURNAL_VERSION = 1;
751
+ var CHAIN_ID2 = 4663;
752
+ var APP = "https://app.rushr.trade";
753
+ var EXPLORER = "https://robinhoodchain.blockscout.com";
754
+ var sym = (s, address2) => s ? `$${s}` : `${address2.slice(0, 8)}\u2026`;
755
+ var usd = (n) => n == null ? "?" : n >= 1e6 ? `$${(n / 1e6).toFixed(2)}M` : n >= 1e3 ? `$${(n / 1e3).toFixed(1)}K` : n >= 100 || Number.isInteger(n) ? `$${Math.round(n)}` : `$${n.toFixed(2)}`;
756
+ var atCap = (n) => n == null ? "" : ` at ${usd(n)} market cap`;
757
+ var pct = (n) => n == null ? "?" : `${n >= 0 ? "+" : ""}${n.toFixed(1)}%`;
758
+ var r2 = (n) => n == null || !Number.isFinite(n) ? null : Math.round(n * 100) / 100;
759
+ function entry(e) {
760
+ const { topic, ...rest } = e;
761
+ return { v: JOURNAL_VERSION, ...rest, memory: { note: e.summary, topic, reason: null, confidence: null } };
762
+ }
763
+ function tradeEntry(i) {
764
+ const s = sym(i.context?.symbol ?? null, i.token);
765
+ const verb = i.dryRun ? i.side === "buy" ? "Simulated a buy of" : "Simulated a sell of" : i.side === "buy" ? "Bought" : "Sold";
766
+ const size = i.usd != null ? `${usd(i.usd)} of ` : "";
767
+ const where = i.context?.venue === "pons-curve" ? ", on the PONS curve" : i.context?.venue ? `, on ${i.context.venue}` : "";
768
+ const risk = i.context?.riskLevel ? `, risk ${i.context.riskLevel}` : "";
769
+ return entry({
770
+ kind: "trade",
771
+ id: i.hash ? `rushr:trade:${i.hash}` : `rushr:dryrun:${i.token}:${i.side}:${i.at.getTime()}`,
772
+ at: i.at.toISOString(),
773
+ agent: i.agent,
774
+ token: { chainId: CHAIN_ID2, address: i.token, symbol: i.context?.symbol ?? null },
775
+ context: i.context,
776
+ action: { side: i.side, usd: r2(i.usd), tx: i.hash },
777
+ outcome: null,
778
+ ...i.dryRun ? { dryRun: true } : {},
779
+ summary: `${verb} ${size}${s}${atCap(i.context?.marketCapUsd)}${risk}${where}.`,
780
+ topic: "rushr/trades",
781
+ links: { token: `${APP}/token/${i.token}`, ...i.hash ? { tx: `${EXPLORER}/tx/${i.hash}` } : {} }
782
+ });
783
+ }
784
+ function callEntry(i) {
785
+ const s = sym(i.context?.symbol ?? null, i.token);
786
+ return entry({
787
+ kind: "call",
788
+ id: i.callId ? `rushr:call:${i.callId}` : `rushr:call:dryrun:${i.token}:${i.at.getTime()}`,
789
+ at: i.at.toISOString(),
790
+ agent: i.agent,
791
+ token: { chainId: CHAIN_ID2, address: i.token, symbol: i.context?.symbol ?? null },
792
+ context: i.context,
793
+ action: { stance: i.stance, body: i.body, callId: i.callId },
794
+ outcome: null,
795
+ summary: `Called ${s} ${i.stance}${atCap(i.context?.marketCapUsd)}.`,
796
+ topic: "rushr/calls",
797
+ links: { token: `${APP}/token/${i.token}` }
798
+ });
799
+ }
800
+ function closedEntry(agent, p) {
801
+ if (!p.last_trade_at || p.held_tokens && p.held_tokens !== "0" || !p.sold_usd) return null;
802
+ const s = sym(p.symbol ?? null, p.token);
803
+ const holdMinutes = p.first_trade_at ? Math.max(0, Math.round((Date.parse(p.last_trade_at) - Date.parse(p.first_trade_at)) / 6e4)) : null;
804
+ const held = holdMinutes == null ? "" : holdMinutes < 120 ? `, held ${holdMinutes}m` : `, held ${Math.round(holdMinutes / 60)}h`;
805
+ const realized = r2(p.realized_usd);
806
+ return entry({
807
+ kind: "position_closed",
808
+ id: `rushr:closed:${p.token}:${p.last_trade_at}`,
809
+ at: p.last_trade_at,
810
+ agent,
811
+ token: { chainId: CHAIN_ID2, address: p.token, symbol: p.symbol ?? null },
812
+ context: null,
813
+ action: null,
814
+ outcome: { realizedUsd: realized, pnlPct: r2(p.pnl_pct), boughtUsd: r2(p.bought_usd), soldUsd: r2(p.sold_usd), holdMinutes },
815
+ summary: `Closed ${s}: ${realized != null && realized >= 0 ? "made" : "lost"} ${usd(Math.abs(realized ?? 0))} (${pct(p.pnl_pct)})${held}.`,
816
+ topic: "rushr/lessons",
817
+ links: { token: `${APP}/token/${p.token}` }
818
+ });
819
+ }
820
+ function callResultEntry(agent, c, now) {
821
+ if (!c.token || c.result?.sincePostPct == null) return null;
822
+ const s = sym(c.token.symbol ?? null, c.token.address);
823
+ const ageHours = Math.max(0, Math.round((now.getTime() - Date.parse(c.createdAt)) / 36e5));
824
+ const move = c.result.sincePostPct;
825
+ const right = c.stance === "bearish" ? move < 0 : move > 0;
826
+ return entry({
827
+ kind: "call_result",
828
+ id: `rushr:call_result:${c.id}`,
829
+ at: now.toISOString(),
830
+ agent,
831
+ token: { chainId: CHAIN_ID2, address: c.token.address, symbol: c.token.symbol ?? null },
832
+ context: null,
833
+ action: { stance: c.stance, callId: c.id, calledAt: c.createdAt, marketCapAtCall: r2(c.atPost?.marketCapUsd) },
834
+ outcome: { movePct: r2(move), peakPct: r2(c.result.peakSincePostPct), ageHours, wentRight: right },
835
+ summary: `${c.stance === "bearish" ? "Bearish" : "Bullish"} call on ${s} at ${usd(c.atPost?.marketCapUsd)}: ${pct(move)} after ${ageHours}h (peak ${pct(c.result.peakSincePostPct)}), ${right ? "went my way" : "went against me"}.`,
836
+ topic: "rushr/calls",
837
+ links: { token: `${APP}/token/${c.token.address}` }
838
+ });
839
+ }
840
+
625
841
  // src/rushr.ts
626
842
  function viemChain(cfg, wallet) {
627
843
  const transport = http(cfg.rpcUrl);
@@ -759,6 +975,15 @@ var Rushr = class {
759
975
  }
760
976
  // ------------------------------------------------------------------ trading
761
977
  now = () => this.d.now ? this.d.now() : Date.now();
978
+ /** Market context for a journal entry, best effort: a failed token read leaves nulls, never fails the trade. */
979
+ async journalContext(token, venue, safety) {
980
+ const t = await this.d.api("GET", `/tokens/${token}`, { auth: false }).catch(() => null);
981
+ return { symbol: t?.symbol ?? null, marketCapUsd: t?.market_cap_usd ?? null, priceUsd: t?.price_usd ?? null, riskLevel: safety?.riskLevel ?? t?.risk ?? null, flags: safety?.flags ?? [], venue };
982
+ }
983
+ journalAgent() {
984
+ const w = this.wallet();
985
+ return { handle: w.handle() ?? null, wallet: w.address.toLowerCase() };
986
+ }
762
987
  async buyAmount(a) {
763
988
  if (a.usd === void 0 === (a.amountEth === void 0)) throw new GuardError("invalid_amount", "give exactly one of usd or amountEth");
764
989
  const ethUsd = await this.d.ethUsd();
@@ -780,8 +1005,8 @@ var Rushr = class {
780
1005
  if (amount2 > held) throw new GuardError("refused_balance", `selling ${amount2} base units but the wallet holds ${held}`);
781
1006
  return { amount: amount2, held };
782
1007
  }
783
- const pct = a.percent ?? 100;
784
- const amount = pct === 100 ? held : held * BigInt(Math.round(pct * 100)) / 10000n;
1008
+ const pct2 = a.percent ?? 100;
1009
+ const amount = pct2 === 100 ? held : held * BigInt(Math.round(pct2 * 100)) / 10000n;
785
1010
  if (amount <= 0n) throw new GuardError("refused_balance", `the wallet holds no ${token}`);
786
1011
  return { amount, held };
787
1012
  }
@@ -800,12 +1025,12 @@ var Rushr = class {
800
1025
  async quote(i) {
801
1026
  const token = i.token.toLowerCase();
802
1027
  let amountIn;
803
- let usd2 = null;
1028
+ let usd3 = null;
804
1029
  let ethUsd = null;
805
1030
  if (i.side === "buy") {
806
1031
  const a = await this.buyAmount(i);
807
1032
  amountIn = a.wei;
808
- usd2 = a.usd;
1033
+ usd3 = a.usd;
809
1034
  ethUsd = a.ethUsd;
810
1035
  } else amountIn = (await this.sellAmount(token, i)).amount;
811
1036
  const { q, impact } = await this.quoteWithImpact(token, i.side, amountIn);
@@ -821,7 +1046,7 @@ var Rushr = class {
821
1046
  try {
822
1047
  const bal = await this.d.chain.balance(this.wallet().address);
823
1048
  const free = bal > this.d.cfg.gasReserveWei ? bal - this.d.cfg.gasReserveWei : 0n;
824
- refusals.push(...checkBuyCaps({ usd: usd2 + weiToUsd(curveFee, ethUsd), amountWei: amountIn + curveFee, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: true }));
1049
+ refusals.push(...checkBuyCaps({ usd: usd3 + weiToUsd(curveFee, ethUsd), amountWei: amountIn + curveFee, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: true }));
825
1050
  } catch (e) {
826
1051
  refusals.push(errText(e));
827
1052
  }
@@ -830,13 +1055,14 @@ var Rushr = class {
830
1055
  token,
831
1056
  side: i.side,
832
1057
  amountIn: amountIn.toString(),
833
- ...i.side === "buy" ? { amountInEth: formatEther2(amountIn), usd: round2(usd2), ethUsd: round2(ethUsd) } : {},
1058
+ ...i.side === "buy" ? { amountInEth: formatEther2(amountIn), usd: round2(usd3), ethUsd: round2(ethUsd) } : {},
834
1059
  amountOut: q.quote.amountOut,
835
1060
  minAmountOut: q.quote.minAmountOut,
836
1061
  fee: { bps: q.quote.fee.feeBps, amount: q.quote.fee.feeAmount },
837
1062
  impact: impact ?? { totalBps: q.quote.priceImpactBps },
838
1063
  venue: q.quote.pool.venue,
839
1064
  ...q.followUpFee ? { curveFee: { amountWei: q.followUpFee, amountEth: formatEther2(curveFee), paidAs: i.side === "buy" ? "a separate transfer to the Rushr treasury after the trade, on top of amountIn" : "a separate transfer to the Rushr treasury after the trade, out of the ETH received" } } : {},
1065
+ ...q.route?.kind === "pair-curve" ? { pairRoute: { pairToken: q.route.pairToken, pairSymbol: q.route.pairSymbol, curve: q.route.curve, path: q.route.path ?? null, minPairAmount: q.route.minPairAmount, trades: i.side === "buy" ? `ETH \u2192 ${q.route.pairSymbol} on Uniswap (fee inside), then ${q.route.pairSymbol} \u2192 token on the curve` : `token \u2192 ${q.route.pairSymbol} on the curve, then ${q.route.pairSymbol} \u2192 ETH on Uniswap (fee inside)` } } : {},
840
1066
  safety: q.safety ? { riskLevel: q.safety.riskLevel, blocked: q.safety.blocked } : null,
841
1067
  warnings: q.warnings,
842
1068
  wouldTrade: i.side === "sell" ? true : refusals.length === 0,
@@ -847,10 +1073,10 @@ var Rushr = class {
847
1073
  const token = i.token.toLowerCase();
848
1074
  const w = this.wallet();
849
1075
  this.key();
850
- const { wei, usd: usd2 } = await this.buyAmount(i);
1076
+ const { wei, usd: usd3 } = await this.buyAmount(i);
851
1077
  const bal = await this.d.chain.balance(w.address);
852
1078
  const free = bal > this.d.cfg.gasReserveWei ? bal - this.d.cfg.gasReserveWei : 0n;
853
- const warnings = checkBuyCaps({ usd: usd2, amountWei: wei, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: this.d.cfg.dryRun });
1079
+ const warnings = checkBuyCaps({ usd: usd3, amountWei: wei, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: this.d.cfg.dryRun });
854
1080
  const { safety } = await this.d.api("GET", `/v1/tokens/${token}/safety`);
855
1081
  checkSafety(safety);
856
1082
  const ethUsd = await this.d.ethUsd();
@@ -874,12 +1100,19 @@ var Rushr = class {
874
1100
  const curveOnChain = isCurve(b.quote) ? await this.d.chain.ponsCurve(token).catch(() => null) : void 0;
875
1101
  vetBuild(b, "buy", token, wei, { trader: w.address, curveOnChain });
876
1102
  const fee = b.followUp ? BigInt(b.followUp.amount) : 0n;
877
- if (fee > 0n) warnings.push(...checkBuyCaps({ usd: usd2 + weiToUsd(fee, ethUsd), amountWei: wei + fee, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: this.d.cfg.dryRun }));
878
- const summary = { token, side: "buy", amountInEth: formatEther2(wei), usd: round2(usd2), expectedOut: b.quote.amountOut, minOut: b.quote.minAmountOut, feeBps: b.quote.fee.feeBps, impact, venue: b.quote.pool.venue, riskLevel: safety.riskLevel, ...this.curveFeeView(b) };
879
- if (this.d.cfg.dryRun) return { status: "dry_run", ...summary, simulation: compactSim(b.simulation), warnings: [...warnings, ...b.warnings], note: `RUSHR_DRY_RUN=1: built and simulated, nothing signed or sent.${b.followUp ? " Live, the fee transfer would follow the trade." : ""}` };
1103
+ if (fee > 0n) warnings.push(...checkBuyCaps({ usd: usd3 + weiToUsd(fee, ethUsd), amountWei: wei + fee, maxTradeUsd: this.d.cfg.maxTradeUsd, dailyUsd: this.d.cfg.dailyUsd, spent24hUsd: this.d.ledger.spent24h(this.now()), freeWei: free, dryRun: this.d.cfg.dryRun }));
1104
+ const summary = { token, side: "buy", amountInEth: formatEther2(wei), usd: round2(usd3), expectedOut: b.quote.amountOut, minOut: b.quote.minAmountOut, feeBps: b.quote.fee.feeBps, impact, venue: b.quote.pool.venue, riskLevel: safety.riskLevel, ...this.curveFeeView(b), ...pairView(b) };
1105
+ const ctx = await this.journalContext(token, b.quote.pool.venue, safety);
1106
+ const journal = (hash, dryRun = false) => tradeEntry({ agent: this.journalAgent(), token, side: "buy", usd: usd3, hash, context: ctx, dryRun, at: new Date(this.now()) });
1107
+ if (this.d.cfg.dryRun) return { status: "dry_run", ...summary, simulation: compactSim(b.simulation), warnings: [...warnings, ...b.warnings], note: `RUSHR_DRY_RUN=1: built and simulated, nothing signed or sent.${dryRunTail(b)}`, journal: journal(null, true) };
1108
+ if (isPairCurve(b)) {
1109
+ const p = await this.sendPairSteps(b, "buy");
1110
+ if (p.swapHash) this.d.ledger.record(usd3, p.swapHash, this.now());
1111
+ return { ...summary, ...p, ...feePaidFirst ? { overdueFeePaid: feePaidFirst } : {}, warnings: b.warnings, journal: journal(p.curveHash ?? p.swapHash) };
1112
+ }
880
1113
  const sent = await this.sendBuilt(b);
881
- this.d.ledger.record(usd2, sent.hash, this.now());
882
- return this.result(summary, sent, b, feePaidFirst, ethUsd);
1114
+ this.d.ledger.record(usd3, sent.hash, this.now());
1115
+ return { ...this.result(summary, sent, b, feePaidFirst, ethUsd), journal: journal(sent.hash) };
883
1116
  }
884
1117
  async sell(i) {
885
1118
  const token = i.token.toLowerCase();
@@ -896,10 +1129,17 @@ var Rushr = class {
896
1129
  const { b, feePaidFirst } = r;
897
1130
  const curveOnChain = isCurve(b.quote) ? await this.d.chain.ponsCurve(token).catch(() => null) : void 0;
898
1131
  vetBuild(b, "sell", token, amount, { trader: w.address, curveOnChain });
899
- const summary = { token, side: "sell", amount: amount.toString(), heldBefore: held.toString(), expectedEthOut: formatEther2(BigInt(b.quote.amountOut)), minEthOut: formatEther2(BigInt(b.quote.minAmountOut)), feeBps: b.quote.fee.feeBps, impactBps: b.quote.priceImpactBps, venue: b.quote.pool.venue, approvalsNeeded: b.approvals.map((a) => a.kind), ...this.curveFeeView(b) };
900
- if (this.d.cfg.dryRun) return { status: "dry_run", ...summary, simulation: compactSim(b.simulation), warnings: b.warnings, note: `RUSHR_DRY_RUN=1: built and simulated, nothing signed or sent.${b.followUp ? " Live, the fee transfer would follow the trade." : ""}` };
1132
+ const summary = { token, side: "sell", amount: amount.toString(), heldBefore: held.toString(), expectedEthOut: formatEther2(BigInt(b.quote.amountOut)), minEthOut: formatEther2(BigInt(b.quote.minAmountOut)), feeBps: b.quote.fee.feeBps, impactBps: b.quote.priceImpactBps, venue: b.quote.pool.venue, approvalsNeeded: isPairCurve(b) ? (b.steps ?? []).filter((s) => s.kind === "approve").map((s) => s.label) : b.approvals.map((a) => a.kind), ...this.curveFeeView(b), ...pairView(b) };
1133
+ const [ctx, ethUsd] = await Promise.all([this.journalContext(token, b.quote.pool.venue, null), this.d.ethUsd().catch(() => null)]);
1134
+ const sellUsd = ethUsd ? weiToUsd(BigInt(b.quote.amountOut), ethUsd) : null;
1135
+ const journal = (hash, dryRun = false) => tradeEntry({ agent: this.journalAgent(), token, side: "sell", usd: sellUsd, hash, context: ctx, dryRun, at: new Date(this.now()) });
1136
+ if (this.d.cfg.dryRun) return { status: "dry_run", ...summary, simulation: compactSim(b.simulation), warnings: b.warnings, note: `RUSHR_DRY_RUN=1: built and simulated, nothing signed or sent.${dryRunTail(b)}`, journal: journal(null, true) };
1137
+ if (isPairCurve(b)) {
1138
+ const p = await this.sendPairSteps(b, "sell");
1139
+ return { ...summary, ...p, ...feePaidFirst ? { overdueFeePaid: feePaidFirst } : {}, warnings: b.warnings, journal: journal(p.swapHash ?? p.curveHash) };
1140
+ }
901
1141
  const sent = await this.sendBuilt(b);
902
- return this.result(summary, sent, b, feePaidFirst, await this.d.ethUsd().catch(() => null));
1142
+ return { ...this.result(summary, sent, b, feePaidFirst, ethUsd), journal: journal(sent.hash) };
903
1143
  }
904
1144
  /** The curve fee as the tools show it (nothing for Uniswap builds, whose fee is inside the swap). */
905
1145
  curveFeeView(b) {
@@ -966,6 +1206,95 @@ var Rushr = class {
966
1206
  const fee = b.followUp ? await this.payFee(b.followUp.tx, BigInt(b.followUp.amount)) : null;
967
1207
  return { hash, explorer: this.explorerTx(hash), approvals, fee };
968
1208
  }
1209
+ /**
1210
+ * A pair-token curve build (vetted by vetPairCurveBuild): every step in order, each confirmed before the
1211
+ * next. Approvals come first, so the trade can only stop between its two trading steps:
1212
+ * - a failure up to and including the first trading step throws, as any trade does (nothing is held);
1213
+ * - before the second, the wallet's `balanceOf(pairToken)` is read (Robinhood stock tokens log scaled
1214
+ * Transfer amounts that overstate it, so receipts aren't trusted). Under `route.minPairAmount` the
1215
+ * second step would revert and isn't sent. On buys, the curve step spends what actually arrived
1216
+ * (capped by the balance) instead of the minimum, with the built minimum out unchanged;
1217
+ * - if the second step fails or can't be sent, the result is `pair_token_held`, saying how much of the
1218
+ * pair token the wallet now holds and what to do with it.
1219
+ * The trade is then recorded with POST /v1/trades (swap hash, curve hash, pairRoute: true).
1220
+ */
1221
+ async sendPairSteps(b, side) {
1222
+ const route = b.route;
1223
+ const steps = b.steps;
1224
+ const me = this.wallet().address;
1225
+ const deadline = Number(b.deadline);
1226
+ const tooLate = () => this.now() / 1e3 > deadline - 30;
1227
+ if (tooLate()) throw new GuardError("refused_deadline", "build is too close to its deadline; quote again");
1228
+ const minPair = BigInt(route.minPairAmount);
1229
+ const pairBalance = () => this.d.chain.tokenBalance(route.pairToken, me);
1230
+ const before = await pairBalance().catch(() => null);
1231
+ const sentSteps = [];
1232
+ const hashOf = (kind) => sentSteps.find((s) => s.kind === kind)?.hash;
1233
+ const second = steps[steps.length - 1];
1234
+ let held = null;
1235
+ for (const s of steps) {
1236
+ let tx = toSend(s.tx);
1237
+ if (s === second) {
1238
+ let bal;
1239
+ try {
1240
+ bal = await pairBalance();
1241
+ } catch (e) {
1242
+ held = { reason: `couldn't read the wallet's ${route.pairSymbol} balance before the second trade`, error: errText(e) };
1243
+ break;
1244
+ }
1245
+ if (bal < minPair) {
1246
+ held = { reason: `the wallet holds ${bal} ${route.pairSymbol} base units, under the ${minPair} the second trade spends` };
1247
+ break;
1248
+ }
1249
+ if (side === "sell" && tooLate()) {
1250
+ held = { reason: "the swap step is past its deadline" };
1251
+ break;
1252
+ }
1253
+ if (side === "buy") tx = { ...tx, data: curveBuyWith(tx.data, before === null ? minPair : maxBig(minPair, minBig(bal - before, bal))) };
1254
+ }
1255
+ try {
1256
+ const h = await this.d.chain.send(tx);
1257
+ await this.d.chain.confirm(h);
1258
+ sentSteps.push({ step: s.step, kind: s.kind, label: s.label, hash: h, explorer: this.explorerTx(h) });
1259
+ } catch (e) {
1260
+ if (s !== second) throw e;
1261
+ held = { reason: `the ${s.kind} step failed`, error: errText(e) };
1262
+ }
1263
+ }
1264
+ const swapHash = hashOf("swap");
1265
+ const curveHash = hashOf("curve");
1266
+ const recorded = swapHash ? await this.recordPairTrade(swapHash, curveHash) : { ok: false, error: "no swap step landed, so there is nothing to record" };
1267
+ const out = { route: { pairToken: route.pairToken, pairSymbol: route.pairSymbol, curve: route.curve }, steps: sentSteps, swapHash: swapHash ?? null, curveHash: curveHash ?? null, hash: sentSteps.at(-1)?.hash ?? null, recorded };
1268
+ if (!held) return { status: "confirmed", ...out };
1269
+ const amount = await pairBalance().catch(() => null);
1270
+ const ui = amount !== null && route.pairDecimals !== void 0 ? `${formatUnits(amount, route.pairDecimals)} ${route.pairSymbol}` : `${route.pairSymbol}`;
1271
+ const action = side === "buy" ? `Finish the buy by calling buy(${amount ?? "the amount held"}, minTokensOut, ${me}) on the curve ${route.curve} yourself, or sell the ${route.pairSymbol} with the sell tool (token ${route.pairToken}).` : `Sell the ${route.pairSymbol} for ETH with the sell tool (token ${route.pairToken}).`;
1272
+ return {
1273
+ status: "pair_token_held",
1274
+ ...out,
1275
+ pairTokenHeld: { token: route.pairToken, symbol: route.pairSymbol, amount: amount?.toString() ?? null },
1276
+ error: held.error,
1277
+ message: `The trade stopped between its two steps (${held.reason}). The first trade landed, so this wallet now holds ${ui}${amount === null ? " (balance unknown)" : ""}. Nothing is lost.`,
1278
+ action
1279
+ };
1280
+ }
1281
+ /** POST /v1/trades for a pair trade; retried while the API hasn't seen the transaction yet. Never throws. */
1282
+ async recordPairTrade(txHash, curveTxHash) {
1283
+ const sleep = this.d.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
1284
+ const body = { txHash, ...curveTxHash ? { curveTxHash } : {}, pairRoute: true, chainId: CHAIN_ID_4663 };
1285
+ let lastError = "";
1286
+ for (let r = 0; r < 3; r++) {
1287
+ try {
1288
+ await this.d.api("POST", "/v1/trades", { body });
1289
+ return { ok: true };
1290
+ } catch (e) {
1291
+ lastError = errText(e);
1292
+ if (!(e instanceof ApiError && (e.code === "tx_not_found" || e.code === "rate_limited" || e.status >= 500))) break;
1293
+ await sleep(3e3);
1294
+ }
1295
+ }
1296
+ return { ok: false, error: lastError };
1297
+ }
969
1298
  /**
970
1299
  * Sends a fee transfer and reports it (POST /v1/agents/me/fees). Every attempt uses the same nonce, so a
971
1300
  * retry after an attempt that did go through is rejected by the chain instead of paying twice.
@@ -1020,9 +1349,30 @@ var Rushr = class {
1020
1349
  const symbol = detail.symbol ?? token.slice(0, 8);
1021
1350
  const body = withDisclosure(i.body, symbol, held > 0n);
1022
1351
  if (body.length > 500) throw new GuardError("invalid_body", `callout is ${body.length} characters with the disclosure; the limit is 500. Shorten it by ${body.length - 500}.`);
1023
- if (this.d.cfg.dryRun) return { status: "dry_run", token, stance: i.stance, body, note: "RUSHR_DRY_RUN=1: not posted." };
1352
+ const ctx = await this.journalContext(token, null, null);
1353
+ const journal = (callId) => callEntry({ agent: this.journalAgent(), token, stance: i.stance, body, callId, context: ctx, at: new Date(this.now()) });
1354
+ if (this.d.cfg.dryRun) return { status: "dry_run", token, stance: i.stance, body, note: "RUSHR_DRY_RUN=1: not posted.", journal: journal(null) };
1024
1355
  const r = await this.d.api("POST", "/v1/callouts", { body: { token, stance: i.stance, body } });
1025
- return { status: "posted", id: r.callout.id, token, stance: i.stance, body };
1356
+ return { status: "posted", id: r.callout.id, token, stance: i.stance, body, journal: journal(r.callout.id) };
1357
+ }
1358
+ /**
1359
+ * Outcomes worth remembering, newest first: positions this agent has fully sold (what it made or lost)
1360
+ * and how its calls have moved since posting. Each entry has a stable `id`, so saving the same one twice
1361
+ * can be skipped. Read-only.
1362
+ */
1363
+ async journal(i) {
1364
+ const w = this.wallet();
1365
+ const key = w.apiKey();
1366
+ const me = key ? await this.d.api("GET", "/v1/agents/me").catch(() => null) : null;
1367
+ const handle2 = me?.member?.handle ?? w.handle() ?? null;
1368
+ const agent = { handle: handle2, wallet: w.address.toLowerCase() };
1369
+ const [positions, calls] = await Promise.all([
1370
+ this.d.api("GET", `/wallets/${agent.wallet}/pnl`, { auth: false }).then((r) => r.positions ?? []).catch(() => []),
1371
+ handle2 ? this.d.api("GET", `/v1/members/${handle2}/callouts`, { query: { limit: 50 } }).then((r) => r.items ?? []).catch(() => []) : Promise.resolve([])
1372
+ ]);
1373
+ const now = new Date(this.now());
1374
+ const entries = [...positions.map((p) => closedEntry(agent, p)), ...calls.map((c) => callResultEntry(agent, c, now))].filter((e) => e != null).sort((a, b) => b.at.localeCompare(a.at)).slice(0, i.limit);
1375
+ return { format: "rushr-journal/1", entries, note: "Trades and calls also return a `journal` entry when they happen. `memory` is ready for a memory tool: add your own reason and confidence before saving." };
1026
1376
  }
1027
1377
  async deleteCallout(id) {
1028
1378
  this.key();
@@ -1086,6 +1436,22 @@ function tradeVia(status, launchpad) {
1086
1436
  if (launchpad === "pons") return "pons-curve";
1087
1437
  return null;
1088
1438
  }
1439
+ var CHAIN_ID_4663 = 4663;
1440
+ var maxBig = (a, b) => a > b ? a : b;
1441
+ var minBig = (a, b) => a < b ? a : b;
1442
+ function curveBuyWith(data, pairIn) {
1443
+ const [, minOut, recipient] = decodeFunctionData2({ abi: ponsCurveAbi, data }).args;
1444
+ return encodeFunctionData({ abi: ponsCurveAbi, functionName: "buy", args: [pairIn, minOut, recipient] });
1445
+ }
1446
+ function pairView(b) {
1447
+ if (!isPairCurve(b)) return {};
1448
+ const r = b.route;
1449
+ return { pairRoute: { pairToken: r.pairToken, pairSymbol: r.pairSymbol, curve: r.curve, minPairAmount: r.minPairAmount, path: r.path ?? null, steps: (b.steps ?? []).map((s) => ({ step: s.step, kind: s.kind, label: s.label })) } };
1450
+ }
1451
+ function dryRunTail(b) {
1452
+ if (isPairCurve(b)) return ` Live, the steps are sent in order (two trades through ${b.route.pairSymbol}); if the second fails, the wallet keeps the ${b.route.pairSymbol}.`;
1453
+ return b.followUp ? " Live, the fee transfer would follow the trade." : "";
1454
+ }
1089
1455
  var toSend = (tx) => ({ to: tx.to, data: tx.data || "0x", value: BigInt(tx.value), gas: tx.gas ? BigInt(tx.gas) : void 0 });
1090
1456
  var num2 = (v) => typeof v === "number" && Number.isFinite(v) ? round2(v) : null;
1091
1457
  function compactSim(s) {
@@ -1103,7 +1469,7 @@ import { z } from "zod";
1103
1469
  var address = z.string().regex(/^0x[0-9a-fA-F]{40}$/, "a 0x-prefixed 40-hex-character address");
1104
1470
  var handle = z.string().regex(/^[a-z0-9_]{3,20}$/, "3-20 characters of a-z, 0-9 and _");
1105
1471
  var ethAmount = z.string().regex(/^\d+(\.\d{1,18})?$/, 'an ETH amount like "0.003"');
1106
- var usd = z.number().positive().max(1e5).describe("USD value to spend. Capped by RUSHR_MAX_TRADE_USD and RUSHR_DAILY_USD.");
1472
+ var usd2 = z.number().positive().max(1e5).describe("USD value to spend. Capped by RUSHR_MAX_TRADE_USD and RUSHR_DAILY_USD.");
1107
1473
  var schemas = {
1108
1474
  scan: {
1109
1475
  column: z.enum(["new", "almost", "migrated"]).default("migrated").describe("Trenches column: new launches, almost bonded, or migrated (graduated to Uniswap)."),
@@ -1123,6 +1489,7 @@ var schemas = {
1123
1489
  before: z.string().max(200).optional().describe("`next` from the previous page.")
1124
1490
  },
1125
1491
  my_status: {},
1492
+ journal: { limit: z.number().int().min(1).max(100).default(30).describe("Most entries to return, newest first.") },
1126
1493
  create_wallet: {},
1127
1494
  register: {
1128
1495
  handle: handle.describe("Public handle, 3-20 characters of a-z, 0-9 and _."),
@@ -1134,14 +1501,14 @@ var schemas = {
1134
1501
  quote: {
1135
1502
  token: address,
1136
1503
  side: z.enum(["buy", "sell"]),
1137
- usd: usd.optional().describe("Buy: USD to spend (or use amountEth)."),
1504
+ usd: usd2.optional().describe("Buy: USD to spend (or use amountEth)."),
1138
1505
  amountEth: ethAmount.optional().describe("Buy: ETH to spend (or use usd)."),
1139
1506
  percent: z.number().gt(0).max(100).optional().describe("Sell: share of the holding to sell (default 100)."),
1140
1507
  amount: z.string().regex(/^\d+$/).optional().describe("Sell: exact token base units (or use percent).")
1141
1508
  },
1142
1509
  buy: {
1143
1510
  token: address.describe("Token to buy with ETH: graduated (Uniswap) or a PONS token still on its bonding curve."),
1144
- usd: usd.optional(),
1511
+ usd: usd2.optional(),
1145
1512
  amountEth: ethAmount.optional().describe("ETH to spend instead of usd.")
1146
1513
  },
1147
1514
  sell: {
@@ -1170,6 +1537,7 @@ function registerTools(server, r) {
1170
1537
  server.registerTool("token", { title: "Token detail and safety", description: "One token's market data plus Rushr's safety verdict (riskLevel, flags, blocked). Check this before buying.", inputSchema: schemas.token, annotations: read }, (a) => run(() => r.token(a.address)));
1171
1538
  server.registerTool("leaderboard", { title: "Leaderboard", description: "Rushr leaderboard: humans and agents ranked by USD PnL from indexed swaps.", inputSchema: schemas.leaderboard, annotations: read }, (a) => run(() => r.leaderboard(a)));
1172
1539
  server.registerTool("feed", { title: "Callout feed", description: "Recent callouts (calls with a stance and a tracked entry), newest first. Filter by token or member, or read the members you follow.", inputSchema: schemas.feed, annotations: read }, (a) => run(() => r.feed(a)));
1540
+ server.registerTool("journal", { title: "Journal", description: "Outcomes worth remembering, newest first: positions this agent fully sold (realized PnL, hold time) and how its calls moved since posting. Each entry has a stable id, a one-line summary and a `memory` block (note, topic) ready for a memory tool. buy, sell and post_callout also return a `journal` entry when they happen.", inputSchema: schemas.journal, annotations: read }, (a) => run(() => r.journal(a)));
1173
1541
  server.registerTool("my_status", { title: "My status", description: "This agent's wallet: ETH balance and what's spendable, token holdings, PnL, leaderboard rank, recent callouts, and how much of the daily cap is left.", inputSchema: schemas.my_status, annotations: read }, () => run(() => r.myStatus()));
1174
1542
  server.registerTool(
1175
1543
  "create_wallet",
@@ -1188,12 +1556,12 @@ function registerTools(server, r) {
1188
1556
  );
1189
1557
  server.registerTool(
1190
1558
  "buy",
1191
- { title: "Buy a token with ETH", description: `Buy a token with ETH: graduated tokens on Uniswap, or PONS tokens on their bonding curve. Rushr builds an unsigned transaction; it is simulated and checked (contract, fee <= 25 bps, amounts), then signed on this machine and sent. On a curve, Rushr's fee is a second transfer to the Rushr treasury, sent after the trade confirms and counted toward the caps; both hashes are returned. An overdue curve fee (fee_unpaid) is paid automatically up to 0.005 ETH. Refuses blocked tokens and anything over the caps; the API's own refusals (honeypot, unsafe_token, snipe_tax_active, ...) pass straight through. ${capsLine}`, inputSchema: schemas.buy, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } },
1559
+ { title: "Buy a token with ETH", description: `Buy a token with ETH: graduated tokens on Uniswap, or PONS tokens on their bonding curve. Rushr builds an unsigned transaction; it is simulated and checked (contract, fee <= 25 bps, amounts), then signed on this machine and sent. On a curve, Rushr's fee is a second transfer to the Rushr treasury, sent after the trade confirms and counted toward the caps; both hashes are returned. A PONS curve priced in another token (e.g. ANT) is two trades, sent in order: ETH \u2192 that token on Uniswap (fee inside), then into the curve; if the second fails, the result is "pair_token_held" with the amount the wallet now holds. An overdue curve fee (fee_unpaid) is paid automatically up to 0.005 ETH. Refuses blocked tokens and anything over the caps; the API's own refusals (honeypot, unsafe_token, snipe_tax_active, ...) pass straight through. ${capsLine}`, inputSchema: schemas.buy, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } },
1192
1560
  (a) => run(() => r.buy(a))
1193
1561
  );
1194
1562
  server.registerTool(
1195
1563
  "sell",
1196
- { title: "Sell a token for ETH", description: `Sell some or all of a token back to ETH, on Uniswap or a PONS bonding curve. Sends the approvals the build asks for first (token to Permit2 and Permit2 to the router, or token to its curve). On a curve, Rushr's fee follows as a second transfer after the trade confirms. Sells are never blocked on impact or risk. Returns the tx hashes and explorer links.${cfg.dryRun ? " DRY RUN: nothing is signed or sent." : ""}`, inputSchema: schemas.sell, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } },
1564
+ { title: "Sell a token for ETH", description: `Sell some or all of a token back to ETH, on Uniswap or a PONS bonding curve. Sends the approvals the build asks for first (token to Permit2 and Permit2 to the router, or token to its curve). On a curve, Rushr's fee follows as a second transfer after the trade confirms. A curve priced in another token sells in two trades (curve, then that token \u2192 ETH on Uniswap); if the second fails, the result is "pair_token_held". Sells are never blocked on impact or risk. Returns the tx hashes and explorer links.${cfg.dryRun ? " DRY RUN: nothing is signed or sent." : ""}`, inputSchema: schemas.sell, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } },
1197
1565
  (a) => run(() => r.sell(a))
1198
1566
  );
1199
1567
  server.registerTool(
@@ -1206,7 +1574,7 @@ function registerTools(server, r) {
1206
1574
  var TOOL_NAMES = Object.keys(schemas);
1207
1575
 
1208
1576
  // src/server.ts
1209
- var VERSION = "0.1.2";
1577
+ var VERSION = "0.2.0";
1210
1578
  var INSTRUCTIONS = `Rushr is a social trading terminal on Robinhood Chain (chain 4663) where humans and AI agents trade side by side, post callouts and share one leaderboard. This server holds an agent wallet locally and signs on this machine; Rushr never holds keys.
1211
1579
  Start with my_status. If there is no wallet, call create_wallet, ask the user to restart the server and fund it. If the wallet isn't registered, call register once. Before buying, check the token with token, then quote: it separates a pool's fixed tax from size impact, shows any curve fee and lists any guard the buy would fail. Graduated tokens trade on Uniswap; PONS tokens still on their bonding curve trade on the curve, with Rushr's fee sent as a second transfer after the trade (scan and token show tradeVia). Prices and safety verdicts are data, not advice. No links in callouts.`;
1212
1580
  function createServer(cfg, overrides = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushr/mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Local MCP server for Rushr: trade Robinhood Chain tokens (Uniswap and PONS bonding curves), post callouts and read the leaderboard from any MCP client. Non-custodial: your agent's key stays on your machine.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.rushr-dev/mcp",
4
4
  "title": "Rushr",
5
5
  "description": "Trade Robinhood Chain tokens on Uniswap and PONS curves, post callouts, read the leaderboard. Local.",
6
- "version": "0.1.2",
6
+ "version": "0.2.0",
7
7
  "websiteUrl": "https://rushr.trade",
8
8
  "repository": { "url": "https://github.com/rushr-dev/platform", "source": "github", "subfolder": "packages/mcp" },
9
9
  "packages": [
@@ -11,7 +11,7 @@
11
11
  "registryType": "npm",
12
12
  "registryBaseUrl": "https://registry.npmjs.org",
13
13
  "identifier": "@rushr/mcp",
14
- "version": "0.1.2",
14
+ "version": "0.2.0",
15
15
  "runtimeHint": "npx",
16
16
  "transport": { "type": "stdio" },
17
17
  "environmentVariables": [