Skip to main content
Glama
BaseStock Guard

BaseStock Guard

by Bfat-6z
README.md
# BaseStock Guard (`base-stock-agent`)

Zero-dependency **Agentic Stock Finance** SDK, CLI pre-trade guardrail, Live Web Verifier, and MCP Server (`stdio` + HTTP `POST /mcp`) for **Coinbase Tokenized Stocks on Base (Chain 8453)**.

- **Live Web App (Chainlink Direct RPC):** https://bfat-6z.github.io/base-stock-agent/
- **Sample Live Onchain Audit:** [sample-output/base-stocks-audit.md](./sample-output/base-stocks-audit.md)

Built for **Base Stocks Maxxing Season — Agentic Stock Finance Track**.

## Why Autonomous Stock Agents Need This

When integrating Coinbase's B20 tokenized stocks (`/v1/tokenized-stocks`), naive swap or portfolio bots fail on four real production edge cases:
1. **`total_supply` vs underlying share equivalents:** Corporate actions (dividends, splits) update each contract's B20/ERC-8056 `multiplier` (e.g. `SNDKc` at `8.0000x`, `NVDAc` at `1.0005x`, `GOOGLc` at `1.0004x`). Raw `balanceOf` and raw `total_supply` do not equal 1:1 shares.
2. **Omitted `nav_price` fields:** `/v1/tokenized-stocks` omits `nav_price` on many responses; you must join `/nav-feeds` (normalizing EIP-55 checksums) and read Chainlink `decimals()` + `latestRoundData()` directly from Base RPC (`eth_call` batch).
3. **Unpriced long-tail stocks:** Only a subset of live positive-supply tokens (e.g. 13 out of 236) have configured Chainlink NAV feeds; trading unpriced tokens blindly risks unbounded slippage.
4. **US Equity Off-Hours Holds vs Stale Oracles + B20 Pauses:** Distinguish normal weekend/overnight NAV holds from genuine oracle staleness and detect `paused_features` before routing orders.

## Quickstart (Zero API Keys, Zero Gas, Node >= 20)

```bash
# Scan live Base tokenized stocks + batched Base RPC Chainlink NAV verification
node ./bin/base-stock-agent.mjs scan

# Pre-trade safety guardrail for an AI trading agent
node ./bin/base-stock-agent.mjs guard SNDKc --json

# Check a Base wallet's tokenized stock exposure (multiplier-adjusted)
node ./bin/base-stock-agent.mjs wallet 0xYourBaseAddress

# Launch live dashboard + REST API + HTTP MCP endpoint (http://127.0.0.1:4790)
node ./bin/base-stock-agent.mjs serve --port 4790

# Run as a stdio MCP server for Claude / Cursor / AgentKit
node ./bin/base-stock-agent.mjs mcp
```

## MCP Tools Exposed (`tools/list`)

- `scan_base_tokenized_stocks` — Live paginated Coinbase API + batched Chainlink `latestRoundData()` scan.
- `guard_tokenized_stock_trade` — Deterministic PASS/BLOCK check before agent trade execution.
- `inspect_wallet_stock_exposure` — Zero-key Base `balanceOf` batch with corporate-action multiplier math.

## Verification

```bash
npm test
```