Skip to content

Sacura1/cryptrix

Repository files navigation

Cryptrix

Cryptrix is a conversational AI agent for launching and trading meme coins on BNB Chain, built on top of four.meme's agentic SDK. Instead of navigating forms and dashboards, users talk to the agent — it handles token creation, autonomous trading, and X marketing entirely through chat.


What it does

Launch — tell the agent to launch a token. It picks a meme concept, generates the name, symbol, description, and artwork, deploys it on four.meme, and immediately posts the launch announcement to X. No forms. One conversation.

Trade — tell the agent to start trading. It presents your current strategy config (take profit, stop loss, trade size), confirms with you, then runs an autonomous scanner every 15 minutes. It sources candidates from four.meme new launches (primary) and Nansen's Token Screener (secondary), then evaluates each one with a three-factor signal pipeline before buying. Sells execute on the bonding curve or on PancakeSwap after graduation.

Market — every token you launch gets an autonomous marketing agent. It posts to X at launch, at 50% and 90% bonding curve milestones, when Nansen-tracked smart money wallets are detected buying, on graduation to DEX, and on a 4-hour scheduled cadence. All generated by GPT-4o Mini, all posted without user action.

Portfolio — ask the agent anything: current positions, P&L, win rate, which tokens are being marketed, trading config. It answers in chat with structured cards.


four.meme integration

Cryptrix uses the @four-meme/four-meme-ai agentic SDK as its execution layer. Every on-chain action goes through it.

SDK commands used

Command What we use it for
create-instant Deploy a token on-chain — passes name, symbol, description, image, and presale amount
token-get Fetch live token detail — bonding curve progress %, current price in BNB, creator wallet address
token-rankings Pull the latest tokens ordered by creation time for the scanner to evaluate
token-info Read on-chain metadata — tokenManager address, version, price feed
buy Execute a buy on the bonding curve using the agent wallet's BNB
sell Execute a sell on the bonding curve — used for take-profit and stop-loss exits
quote-buy Get a price quote before executing, used for slippage checks
events Read recent TokenManager2 on-chain events — used to find early buyer wallet addresses for Nansen analysis

Agent wallet

Each user gets a dedicated BSC wallet generated on first login. The flow:

  1. On dashboard load, getOrCreateAgentWallet(userId) runs server-side
  2. A fresh private key is generated via viem's generatePrivateKey()
  3. The key is encrypted with AES-256-GCM using a 32-byte server secret (WALLET_ENCRYPTION_KEY) and stored in Vercel KV — the plaintext key never reaches the client
  4. Only the wallet address is returned to the frontend
  5. When an on-chain action is needed (buy, sell, deploy token), getAgentPrivateKey(userId) decrypts it server-side and passes it directly to the four.meme SDK or viem wallet client

Users fund the wallet by sending BNB to the displayed address. The wallet can be swept back to any address via withdrawAgentWallet (exposed in the dashboard). The trust model is the same as giving a bot exchange API keys — only deposit what you're willing to have the agent trade.

Trading signal pipeline

Every candidate token (from four.meme or Nansen) runs through three checks before the bot buys:

  1. Bonding curve velocity (40–100% of score depending on X availability) — calculated from token-get progress % divided by token age in minutes. A token filling fast has genuine demand.

  2. X sentiment (40% of score when available) — GPT-4o Mini analyses recent tweets mentioning the contract address and returns a 0–100 sentiment score. Falls back to velocity-only if X API is unconfigured.

  3. Nansen dev reputation (binary gate) — the creator wallet from token-get is checked against Nansen's wallet labels. Known ruggers are hard-blocked regardless of score. Smart money wallets among early buyers add a +15 bonus to the combined score.

Score-based position sizing

Rather than buying the same fixed amount on every signal, the bot sizes positions based on conviction:

Combined score Trade size
85+ (strong signal) 100% of maxTradeSizeBNB
70–84 (medium) 60% of maxTradeSizeBNB
60–69 (borderline) 30% of maxTradeSizeBNB

The default maxTradeSizeBNB is 0.05 BNB (~$30 at current prices). Users can change it anytime by telling the agent — e.g. "set trade size to 0.01 BNB". There's no enforced minimum but keep it above ~0.005 BNB to ensure the buy covers gas costs on BSC. The default minimum signal score is 45/100 — intentionally permissive so the bot finds trades; raise it if you want stricter filters.

Candidate sources

Source Description Priority
four.meme token-rankings All tokens ordered by creation time — no age filter Primary
Nansen Token Screener BSC tokens with ≥2 smart money wallets buying in the last hour Secondary

four.meme launches always run first. Nansen-screened tokens that aren't already in the four.meme list are appended as extras. There is no age filter — any token on four.meme is eligible and the combined score alone determines whether the bot buys. The trade log marks each entry's source.

Post-graduation handling

When a token's bonding curve reaches 100%, it migrates liquidity to PancakeSwap. At that point the four.meme sell command no longer applies. Cryptrix detects graduation by monitoring the progress field from token-get, confirms PancakeSwap liquidity via the V2 router's getAmountsOut, then switches the position to DEX tracking. Take-profit and stop-loss sells after graduation execute via PancakeSwap's swapExactTokensForETH.


Architecture

app/
  agent/          — chat interface (main screen)
  live/           — public live trades feed (no auth required)
  dashboard/      — wallet balances, agent wallet funding
  trade/          — personal trade logs and position history
  social/         — X account connection

api/
  agent/chat/     — GPT-4o Mini processes chat messages, returns structured actions
  agent/history/  — KV-backed chat persistence per user
  create-token/   — token preview + four.meme launch (DEMO_MODE skips chain unless real mode on)
  settings/
    real-mode/    — per-user real mode toggle (overrides DEMO_MODE for that user)
  public/
    live-trades/  — public aggregate of all positions + agents (no auth)
  trader/
    config/       — read/write trading strategy settings
    scan/         — streaming live scan (used in chat)
    run/          — cron endpoint, calls runTraderForUser per active trader
    positions/    — position and trade log retrieval
  social/
    generate/     — GPT-4o Mini writes X posts for a token
    post/         — posts to X via Twitter API v2
    status/       — checks if user has X connected

lib/
  fourmeme.ts     — four.meme SDK wrapper
  trader.ts       — full trading loop: signal scoring, position sizing, buy/sell lifecycle
  nansen.ts       — Nansen API: dev reputation, smart money analysis, token screener
  pancakeswap.ts  — PancakeSwap V2 integration for post-graduation sells
  agent.ts        — marketing agent loop, post generation, KV storage
  agent-wallet.ts — AES-256-GCM encrypted agent wallet per user
  guest-mode.ts   — guest/demo mode helpers (localStorage flag + demo token)

Cron jobs (vercel.json):

  • /api/trader/run — every 15 minutes, runs the trading scanner for all enabled users
  • /api/agent/run — every 30 minutes, runs the marketing agent for all active tokens

Guest / demo mode

The landing page has a "Try Demo — no signup" button. It sets a localStorage flag and uses a special demo-guest auth token server-side. All API routes work normally with a guest_demo_user namespace. AI calls (chat, image generation) are fully real. On-chain transactions are simulated when DEMO_MODE=true — a realistic fake tx hash is returned without touching the chain.

Real Mode toggle

When DEMO_MODE=true is set globally (e.g. on a hackathon deployment), authenticated users can opt into real on-chain execution from the Dashboard. The toggle saves a realmode:{userId} flag in KV. When enabled, that user's token launches submit actual transactions to BSC regardless of the global DEMO_MODE setting. Guest users cannot enable real mode.


AI models

Task Model
Chat interface GPT-4o Mini
Token concept + metadata generation GPT-4o Mini
X post generation GPT-4o Mini
X sentiment analysis GPT-4o Mini
Meme image generation DALL-E 3 (primary) / Replicate Flux Schnell (fallback)

External integrations

  • four.meme — token launch and bonding curve trading (primary execution layer)
  • Nansen — dev wallet reputation, smart money detection, token screener (agents.nansen.ai)
  • PancakeSwap V2 — post-graduation token sells
  • Twitter API v2 — posting to X on behalf of connected accounts
  • DALL-E 3 / Replicate (Flux Schnell) — meme image generation (DALL-E 3 primary, Flux fallback)
  • Privy — embedded wallets and authentication
  • Vercel KV — chat history, agent state, trading positions, X tokens

Environment variables

OPENAI_API_KEY=             # AI (chat, token gen, X posts, sentiment) + DALL-E 3 image generation
PRIVY_APP_ID=
PRIVY_APP_SECRET=
NEXT_PUBLIC_PRIVY_APP_ID=
BSC_RPC_URL=
WALLET_ENCRYPTION_KEY=      # 64-char hex string (32 bytes) for AES-256-GCM wallet encryption
REPLICATE_API_KEY=          # meme image generation (fallback if DALL-E 3 fails)
X_CLIENT_ID=                # Twitter OAuth 2.0
X_CLIENT_SECRET=
X_BEARER_TOKEN=             # for sentiment analysis
NANSEN_API_KEY=             # optional — enables dev reputation + smart money + token screener
KV_REST_API_URL=
KV_REST_API_TOKEN=
KV_REST_API_READ_ONLY_TOKEN=
CRON_SECRET=                # secures cron endpoints
DEMO_MODE=false             # set true to simulate launches without on-chain tx for all users
NEXT_PUBLIC_DEMO_MODE=false # must match DEMO_MODE — shows Real Mode toggle in dashboard

Local development

npm install
cp .env.example .env.local   # fill in your keys
npm run dev

Open http://localhost:3000. Sign in, fund the agent wallet with a small amount of BNB on BSC mainnet, then start chatting.

Set DEMO_MODE=true and NEXT_PUBLIC_DEMO_MODE=true in .env.local to skip actual on-chain transactions and return fake tx hashes — useful for testing the full UI flow without spending gas. Authenticated users can still opt into real transactions via the Real Mode toggle in the Dashboard.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors