|
| 1 | +--- |
| 2 | +title: "SafeAgent (Token Safety)" |
| 3 | +description: "Pre-trade token safety oracle, push-based wallet alerts, and on-chain SafeRouter for ElizaOS agents trading crypto" |
| 4 | +--- |
| 5 | + |
| 6 | +The SafeAgent plugin gives ElizaOS agents a complete safety stack for trading crypto: pre-trade scoring, continuous wallet monitoring with HMAC-signed webhook alerts, and on-chain `SafeRouter` contracts (Base + Optimism) that revert unsafe swaps atomically with a structured custom error. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- **27 scam pattern detection** across 6 EVM chains (Base, Ethereum, Arbitrum, Optimism, Polygon, BSC) |
| 11 | +- **Real DEX swap simulation** for honeypot detection — not just static code analysis |
| 12 | +- **Push-based safety alerts** with HMAC-SHA256 signed webhooks (verifiable cryptographic proof for the agent's principal) |
| 13 | +- **On-chain SafeRouter** wraps Aerodrome (Base) and Velodrome (Optimism); atomic revert with `TokenUnsafe(token, score, flags, minRequired)` custom error if oracle says no |
| 14 | +- **Custody-safe**: the plugin returns swap calldata only — your agent retains its private key |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +npm install safeagent-elizaos-plugin |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +```typescript |
| 25 | +import safeAgentPlugin from "safeagent-elizaos-plugin"; |
| 26 | +import { AgentRuntime } from "@elizaos/core"; |
| 27 | + |
| 28 | +const agent = new AgentRuntime({ |
| 29 | + plugins: [safeAgentPlugin], |
| 30 | + // ...rest of your runtime config |
| 31 | +}); |
| 32 | +``` |
| 33 | + |
| 34 | +## Actions |
| 35 | + |
| 36 | +### `SHIELD` — pre-trade safety check |
| 37 | + |
| 38 | +HTTP-based safety query. Returns `GO`/`CAUTION`/`BLOCKED` with safety score (0-100), honeypot test result, and scam-pattern flags. |
| 39 | + |
| 40 | +Example prompts: |
| 41 | +- "Buy 0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed on base" |
| 42 | +- "Is 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 safe on base?" |
| 43 | +- "Check this token for honeypots: 0x..." |
| 44 | + |
| 45 | +### `WATCH_WALLET` — push-based alerts |
| 46 | + |
| 47 | +Register a wallet for continuous monitoring. SafeAgent polls the wallet's holdings every 60min (free tier) or 10min (premium), scores each token, and POSTs a signed HMAC-SHA256 webhook to the agent's callback URL when: |
| 48 | +- A held token's safety score drops 20+ points, OR |
| 49 | +- A new risky holding (score < 50) is detected |
| 50 | + |
| 51 | +Each alert includes a `signature` field — the agent forwards it to its principal as cryptographic proof. |
| 52 | + |
| 53 | +Example prompts: |
| 54 | +- "Watch my wallet 0x... on base, callback https://my-agent.com/alerts" |
| 55 | + |
| 56 | +Public key fingerprint to pin in your verifier: |
| 57 | +```bash |
| 58 | +GET https://cryptogenesis.duckdns.org/watch/public-key |
| 59 | +``` |
| 60 | + |
| 61 | +### `SAFE_CHECK` — on-chain verdict (view-only, no gas) |
| 62 | + |
| 63 | +Reads SafeRouter's `checkBeforeBuy` view function. Returns `SAFE`/`MODERATE`/`CAUTION`/`RISKY`/`DANGEROUS`. Use BEFORE building a swap to avoid wasting gas on a guaranteed revert. |
| 64 | + |
| 65 | +Example prompts: |
| 66 | +- "Check on-chain if 0x... is safe to swap on base" |
| 67 | + |
| 68 | +### `SAFE_SWAP_CALLDATA` — atomic-protected swap calldata |
| 69 | + |
| 70 | +Builds calldata for `SafeRouter.safeSwap`. Returns `{ to, data, gas_estimate }`. The agent signs and broadcasts itself. |
| 71 | + |
| 72 | +If the destination token's score is below 40 on the oracle, the contract reverts with `TokenUnsafe(token, score, flags, minRequired)` — a structured custom error decodable without string parsing. |
| 73 | + |
| 74 | +Example prompts: |
| 75 | +- "Prepare a safe swap of 1000000 from 0x833589fCD6... to 0x4ed4E862... on base" |
| 76 | + |
| 77 | +## On-chain contracts |
| 78 | + |
| 79 | +| Component | Base | Optimism | |
| 80 | +|---|---|---| |
| 81 | +| SafeRouter V2 | `0xF6EFc5D5902d1a0ce58D9ab1715Cf30f077D8f6e` | `0x38be6AA1044e866FcDFE34d4B4273F703668B80E` | |
| 82 | +| Safety oracle (ERC-draft) | `0x37b9e9B8789181f1AaaD1cD51A5f00A887fa9b8e` | `0x3B8A6D696f2104A9aC617bB91e6811f489498047` | |
| 83 | +| DEX wrapped | Aerodrome `0xcf77a3ba9a5ca399b7c97c74d54e5b1beb874e43` | Velodrome `0xa062aE8A9c5e11aaA026fc2670B0D65cCc8B2858` | |
| 84 | + |
| 85 | +ERC standardization in flight: [ethereum/ERCs#1729](https://github.com/ethereum/ERCs/pull/1729) (Token Safety Score). |
| 86 | + |
| 87 | +## Verifying webhook signatures |
| 88 | + |
| 89 | +```typescript |
| 90 | +import crypto from "node:crypto"; |
| 91 | + |
| 92 | +function verify(payload: any, secret: Buffer): boolean { |
| 93 | + const { signature, ...rest } = payload; |
| 94 | + const canonical = JSON.stringify(rest, Object.keys(rest).sort()); |
| 95 | + const expected = crypto.createHmac("sha256", secret).update(canonical).digest("hex"); |
| 96 | + return crypto.timingSafeEqual(Buffer.from(signature, "hex"), Buffer.from(expected, "hex")); |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Live proof transactions |
| 101 | + |
| 102 | +- First on-chain swap through SafeRouter: [basescan.org/tx/0x83a0384a…](https://basescan.org/tx/0x83a0384af90362b4ac7aaccc46436646c42832833d6be59d5c39c852d8c09cab) |
| 103 | +- Block-path proof (revert with `TokenUnsafe` custom error): [basescan.org/tx/0xc68b1ef6…](https://basescan.org/tx/0xc68b1ef67c45f0164683b336cf2b593c1f0ae05f02cc3336f9cddc6f5f2bc8f8) |
| 104 | + |
| 105 | +## Cost |
| 106 | + |
| 107 | +Free during beta. No auth required. Live stats: https://cryptogenesis.duckdns.org/stats |
| 108 | + |
| 109 | +## Source |
| 110 | + |
| 111 | +- npm: https://www.npmjs.com/package/safeagent-elizaos-plugin |
| 112 | +- Plugin source: https://github.com/Aigen-Protocol/plugin-safeagent |
| 113 | +- AIGEN Protocol: https://github.com/Aigen-Protocol/aigen-protocol |
| 114 | +- Solidity SafeGuard library: https://github.com/Aigen-Protocol/safeguard |
| 115 | + |
| 116 | +## License |
| 117 | + |
| 118 | +MIT |
0 commit comments