Technical Architecture
How the Neuron repo fits together: Solidity vaults on Robinhood Chain testnet, a worker that trades every agent on live data and reports on-chain, an indexer that turns those reports into the site's numbers, and a Next.js app that reads both.
Stack
| Layer | Technology |
|---|---|
| App | Next.js 14 (App Router), TypeScript, Tailwind CSS |
| Wallets | Privy (email, social or external wallet, with embedded wallets) on wagmi and viem |
| Contracts | Solidity 0.8.24, Foundry, OpenZeppelin, ERC-4626 |
| Worker | Node and tsx, viem, one long-running loop |
| Indexer | Node and tsx, Postgres (pg), viem, a small HTTP API |
| AI | Anthropic SDK, used by loss reviews, post drafts and optional reasoning |
Repo layout
| Path | What lives there |
|---|---|
contracts/src | AgentVault, AgentRegistry, FeeCollector, strategies/, community/, mocks/MockUSDC.sol |
contracts/script | Deploy.s.sol, DeployCommunity.s.sol, MigrateStrategy.s.sol |
contracts/test | Forge unit and fuzz tests (AgentVault.t.sol, Community.t.sol) |
contracts/deployments | Per-chain address records, for example 46630.json and 46630.community.json |
src/app | Pages: /, /agents, /agents/[id], /c/[slug], /create, /portfolio, /docs, /architecture |
src/components | UI, including DepositPanel, TradeHistory, PortfolioBoard, creator/AgentStudio |
src/lib/agents | Strategy engines, rules and bounds, filters, backtests, runtime, notes, tools, personas |
src/lib/web3 | Network config, ABIs, deployments.json, deposit and vault hooks, report log reader |
worker | agent-worker.ts (the trading loop) and community.ts (agent discovery and rules) |
indexer | Launch indexer, report sync, holders, performance API, loss reviews, tools, X and clips |
scripts | Deploy, sync, house-agent launch and relaunch, tuning and simulation scripts |
Contracts
| Contract | Responsibility |
|---|---|
AgentVault | ERC-4626 vault per agent: non-transferable shares, high-water-mark performance fee (max 30%), on-chain cost basis, deposit cap and minimum, pause blocks deposits only |
VotingAgentVault | AgentVault plus ERC20Votes with timestamp checkpoints; used by every factory agent |
IStrategy, BaseStrategy | Pluggable execution modules bound to one vault and one asset |
SimulatedStrategy | Testnet only: the operator reports PnL in bps with a note; mints or burns test USDG; bounded and rate-limited |
IdleStrategy | Holds funds; used for real-asset deployments until audited strategies exist |
AgentFactory | Creates an agent in one transaction: vault, strategy, governor, token and curve |
AgentGovernor | Holds an agent's rules as JSON; daily epochs for proposals and votes |
FeeCollector | Redeems fee shares and splits them between the agent's operator or creator and the treasury |
AgentRegistry | Directory of agent ids to vaults for the original house deployment |
AgentToken, BondingCurve | 1B fixed-supply token on a curve; still deployed per agent but no longer used by the site |
MockUSDC | The test USDG: 6 decimals, a self-only faucet of 1,000 per wallet per UTC day, whitelisted minters |
Details are on Independent Agent Vaults.
Data flow
- 1A user deposits test USDG into an agent's vault from the app (approve, then
deposit). - 2Every 30 seconds the worker loads every agent from the
AgentFactory, skipping retired vaults, along with the rules it should trade on: a team-approved change from the indexer'sGET /rules/effectiveif there is one, otherwise the governor's current rules. - 3For each agent with deposits whose report interval has passed, the worker resumes from the state in the agent's last
Reportednote, pulls live data (launch tokens from the Neuron indexer; majors, perps, funding and yields from Hyperliquid and DefiLlama) and decides a move. - 4Trades are reported immediately with
SimulatedStrategy.report. Holds are reported at most every 15 minutes (HOLD_REPORT_SECONDS, 900) for launch traders and at most hourly for other engines. - 5The indexer syncs
Reportedevents every 15 seconds and vault share transfers for depositor counts, then computes returns, charts, win rates and fills. - 6The app reads the indexer for performance and reads the vaults directly through wagmi for deposits, balances and positions.
The worker loop
worker/agent-worker.ts ticks every TICK_SECONDS (30 by default) and never overlaps two ticks. Each tick it refreshes the agent list (every 2 minutes) and approved rules (every minute), runs runAgentTick from src/lib/agents/runtime.ts, logs a heartbeat every 20 ticks, and checks the operator's gas every 120 ticks, warning below 0.0005 ETH. A tick skips an agent when the configured key is not that strategy's operator, the vault is empty, the rate limit has not passed, or its rules fail validation. Shadow mode (AGENT_SHADOW_ENABLED=1) records what an experimental entry gate would have decided, without ever trading on it.
The indexer
indexer/index.ts creates its Postgres schema, starts the HTTP API and runs a set of independent loops:
| Loop | Interval | Job |
|---|---|---|
| Launch ingest | Continuous | Follows Pons launches and trades on Robinhood Chain mainnet for the token screener |
reports | 15 seconds | Syncs every agent's Reported events |
holders | 15 seconds | Syncs vault share transfers |
improve | 5 minutes | Loss reviews and backtested rule fixes |
snapshots | 20 seconds | Token snapshots used for backtests |
| Tools | 5 to 30 minutes | Smart money, DexScreener, security checks, positioning, X and news data |
The performance endpoints the app uses are GET /agents/live, /agents/performance, /agents/<id>/series, /agents/<id>/history, /agents/race, /agents/fills and /holders/<address>. See Blockchain Indexer.
Frontend data flow
- Server pages (
/agents,/agents/[id]) fetch/agents/livewith a 60 second revalidate and merge it into the profiles fromsrc/lib/agents.ts. - Client widgets poll the indexer (performance every 60 seconds, trade history every 30 seconds).
- Vault state (
totalAssets,pricePerShare, fee, cap, minimum, paused, your shares,maxWithdraw,costBasis, USDG balance and allowance) is one multicall, refreshed every 15 seconds. src/lib/web3/network.tspicks the network fromNEXT_PUBLIC_NEURON_NETWORK:testnet(default, Robinhood Chain testnet as the home chain) orlocal(anvil, chain 31337).
deployments.json
npm run sync:contracts copies contracts/deployments/<chainId>.json and the matching .community.json into src/lib/web3/deployments.json, and regenerates src/lib/web3/abis.ts from the Foundry build output. The shape, keyed by chain ID:
{
"46630": {
"chainId": 46630,
"chainKey": "robinhood",
"usdc": "0x...",
"usdcIsMock": true,
"registry": "0x...",
"feeCollector": "0x...",
"operator": "0x...",
"startBlock": 0,
"vaults": { "<agent-id>": { "vault": "0x...", "strategy": "0x..." } },
"legacyVaults": { "<agent-id>": [{ "vault": "0x...", "strategy": "0x...", "keepsRecord": true }] },
"community": { "factory": "0x...", "feeCollector": "0x...", "startBlock": 0 }
}
}vaults holds each house agent's current vault; legacyVaults lists older ones, oldest first, which the app treats as withdraw only.
Commands
npm install
npm run dev # app on http://localhost:3000, testnet config
npm run typecheck
npm run build
npm run contracts:build # forge build
npm run contracts:test # forge unit and fuzz testsFully local, with no accounts (needs Foundry):
npm run chain # anvil on port 8546, chain 31337
npm run deploy:local # MockUSDC, registry, fee collector, house vaults, factory; syncs the app
npm run dev:local # app on http://localhost:3100 against the local chain
ALCHEMY_API_KEY=... INDEXER_URL=... NEURON_RPC_URL=http://127.0.0.1:8546 npm run workerTestnet deploy and services:
npm run deploy:testnet # Deploy.s.sol on Robinhood Chain testnet, verified on Blockscout, then sync
npm run sync:contracts # after any deploy or launch script
npm run worker # needs OPERATOR_PRIVATE_KEY, ALCHEMY_API_KEY, INDEXER_URL
npm run indexer # needs DATABASE_URLOther variables you may set: NEXT_PUBLIC_PRIVY_APP_ID, NEXT_PUBLIC_INDEXER_URL, NEXT_PUBLIC_ROBINHOOD_TESTNET_RPC_URL, and on the indexer ANTHROPIC_API_KEY, REALM_LAUNCHER_KEY and REALM_NETWORK. .env.example lists them all; keep keys server-side.
Related
Neuron is on Robinhood Chain testnet. Testnet performance is not evidence of real-money profitability.
