Skip to content

techlibs/ethglobalhackaton

Repository files navigation

DegenAdvisors

A collection of agents that have their own wallets for transactions query data, start trading strategies. Each with their own speciality.

Agents functionalities are enriched via Providers and their premium routes can be protected over 402.

Some providers allow for storing data offchain and syncing with data on periods, based on webhooks or cron jobs.

Onchain Agent Powered by AgentKit

This is a Next.js project bootstrapped with create-onchain-agent.

It integrates Coinbase AgentKit on Base to provide AI-driven, onchain interactions.

Getting Started

Install dependencies:

bun install

Configure environment variables (see .env.example):

cp .env.example .env

Start the dev server:

bun run dev

Open http://localhost:3000

Configuring Your Agent

You can customize the agent configuration. By default:

  • AgentKit wiring: app/api/agent/prepare-agentkit.ts
  • Agent instantiation: app/api/agent/create-agent.ts

1) Select Your LLM

Choose OpenAI or Groq via environment variables and model selection in code.

2) Select Your Wallet Provider

AgentKit requires a Wallet Provider to interact with EVM chains. This project uses CdpSmartWalletProvider on Base (defaults to base-sepolia).

3) Select Your Action Providers

Action Providers define capabilities (wallet, ERC-20, swaps, price feeds, strategies). Built-ins plus custom providers are registered.


Next Steps


Learn More


Contributing


API and Agent Overview

Overview

  • Onchain trading assistant powered by Coinbase AgentKit on Base.
  • Streams live prices via Pyth, evaluates triggers, and (optionally) executes swaps.
  • Persists strategies and trigger history to local JSON files.

Key Links

Environment

  • LLM: OPENAI_API_KEY or GROQ_API_KEY (one required)
  • CDP/AgentKit:
    • CDP_API_KEY_ID, CDP_API_KEY_SECRET (required)
    • CDP_WALLET_SECRET (recommended)
    • NETWORK_ID (default: base-sepolia)
    • PAYMASTER_URL, RPC_URL, IDEMPOTENCY_KEY (optional)
  • Smart wallet cache: wallet_data.txt (auto-created)

.env Example

# --- LLM (choose one) ---
# OPENAI_API_KEY= # Get from https://platform.openai.com/api-keys
# GROQ_API_KEY=   # Get from https://console.groq.com/keys

# --- Coinbase CDP / AgentKit ---
CDP_API_KEY_ID=
CDP_API_KEY_SECRET=
# Optional but recommended for managed wallet lifecycle
CDP_WALLET_SECRET=

# Network (default used by app if unset)
# Acceptable values: base, base-sepolia
NETWORK_ID=base-sepolia

# Optional advanced config
# PAYMASTER_URL=
# RPC_URL=
# IDEMPOTENCY_KEY=

# --- Convex (dev or prod) ---
# For local dev, after starting Convex with `bunx convex dev`,
# copy the printed values for URL and Site URL.
CONVEX_DEPLOYMENT=dev:your-project-slug  # team: <team>, project: <project>
NEXT_PUBLIC_CONVEX_URL=
NEXT_PUBLIC_CONVEX_SITE_URL=

# --- Cambrian / Deep42 MCP ---
# Request an API key from Cambrian/Deep42 or your admin.
# See CAMBRIAN_MCP_IMPLEMENTATION.md for details.
CAMBRIAN_API_KEY=

Where to get credentials

Data Files

  • Strategies: data/strategies.json
  • Trigger history: data/trigger_history.json

API Routes

  • POST api/agent
    • Sends a user message to the AgentKit-powered agent and returns the final response text.
    • Body: { "userMessage": "...", "agentId"?: "..." }{ "response": "..." }
    • Code: app/api/agent/route.ts
  • GET api/agents
    • Returns the list of available agents.
    • Code: app/api/agents/route.ts
  • GET api/assets
    • Returns wallet address and Base token balances (ETH, USDC, WETH, DAI).
    • Code: app/api/assets/route.ts
  • GET api/strategies?agentId=<id>
    • Returns strategies for the specified agent.
    • Code: app/api/strategies/route.ts
  • PATCH api/strategies
    • Updates a strategy by id with validated numeric fields.
    • Body: { "id": "...", "agentId": "...", "updates": { ... } }
    • Code: app/api/strategies/route.ts
  • GET api/strategy-stream?agentId=<id>
    • SSE stream of the current strategies list for the specified agent.
    • Code: app/api/strategy-stream/route.ts
  • GET api/prices-stream
    • SSE stream of live price updates.
    • Code: app/api/prices-stream/route.ts
  • GET api/trigger-history?agentId=<id>
    • JSON array of trigger events for the specified agent. Add ?stream=true to stream via SSE.
    • Code: app/api/trigger-history/route.ts
  • GET agents/[agentSlug]/agent.json
    • Returns agent metadata from local registry by slug.
    • Code: app/agents/[agentSlug]/agent.json/route.ts
  • GET .well-known/[agentSlug]/agent-card.json
    • Returns the agent card (fetches from Convex via CONVEX_SITE_URL).
    • Code: app/.well-known/[agentSlug]/agent-card.json/route.ts

Agent Setup

  • Agent init: app/api/agent/create-agent.ts:38
    • LLM: OpenAI gpt-4o-mini or Groq llama-3.3-70b-versatile
    • Tools: from AgentKit via getLangChainTools
    • Memory: MemorySaver
    • System prompt includes guidance, CDP/AgentKit links, and faucet hint on Base Sepolia
  • AgentKit + Wallet:
    • Config: app/api/agent/prepare-agentkit.ts:87
    • Wallet: CdpSmartWalletProvider (Base by default: base-sepolia)
    • Action providers registered:
      • Built-in: wallet, erc20, weth, cdpApi, cdpSmartWallet, x402
      • Custom:
        • pyth (live prices, SSE): app/providers/newPythActionProvider.ts:50
        • tradeStrategy (CRUD + subscriptions): app/providers/tradeStrategyActionProvider.ts:59
        • dexScreener (token discovery): app/providers/dexScreenerActionProvider.ts:47
        • dexSwap (CDP Trade API, smart account): app/providers/swapActionProvider.ts:151
    • Smart wallet info persisted to wallet_data.txt on first run

Trading Flow

  • Strategies persisted/managed via actions and API:
    • Create/list/update/remove: tradeStrategy provider
    • Broadcast updates via SSE: app/utils/strategyBroadcast.ts:1
  • Live Prices:
    • pyth.getPrice fetches feed ID; subscribeToPriceFeed streams live updates
    • Broadcast to SSE: app/utils/priceBroadcast.ts:1
  • Trigger Engine:
    • Evaluates thresholds and percentages (+ cooldown) per strategy on each price tick
    • Logs events and updates strategy state
    • Code: app/utils/priceTriggerEngine.ts:26
  • Swap Execution:
    • Hooked via setExecutionCallback to SwapActionProvider.executeAutomatedSwap
    • Currently logs parameters; modeled for CDP Trade API execution
    • Code: app/api/agent/prepare-agentkit.ts:32, app/providers/swapActionProvider.ts:163

Types

  • Agent request/response and price data: app/types/api.ts:1
  • Strategy/Trigger event: app/types/strategy.ts:1
  • Default Base tokens/metadata: app/types/asset.ts:21

Quick Examples

  • Agent call (optional agent selection):
curl -sX POST http://localhost:3000/api/agent \
  -H 'Content-Type: application/json' \
  -d '{"userMessage":"What is my smart wallet address?","agentId":"warren-debuffett"}'
  • List agents:
curl -s http://localhost:3000/api/agents | jq
  • Strategies (per agent):
curl -s 'http://localhost:3000/api/strategies?agentId=warren-debuffett'
curl -sX PATCH http://localhost:3000/api/strategies \
  -H 'Content-Type: application/json' \
  -d '{"id":"warren-eth-buy-fear","agentId":"warren-debuffett","updates":{"buyThreshold":24,"cooldownMinutes":1440}}'
  • SSE (terminal view):
curl -N 'http://localhost:3000/api/strategy-stream?agentId=warren-debuffett'
curl -N http://localhost:3000/api/prices-stream
curl -N 'http://localhost:3000/api/trigger-history?agentId=warren-debuffett&stream=true'
  • Agent metadata endpoints:
curl -s 'http://localhost:3000/agents/warren-debuffett/agent.json' | jq
curl -s 'http://localhost:3000/.well-known/warren-debuffett/agent-card.json' | jq

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •