feat(action): add GET_TOKEN_INFO action via GoldRush token search#28
feat(action): add GET_TOKEN_INFO action via GoldRush token search#28dinxsh wants to merge 3 commits intoelizaos-plugins:1.xfrom
Conversation
…hment Fixes elizaos-plugins#15 Extends WalletProvider to optionally fetch full token balances across all configured chains via GoldRush API when GOLDRUSH_API_KEY is set. Falls back to existing behavior if key is not present — zero breaking changes. Why GoldRush: - Single API covers 100+ EVM chains - Returns USD values, spam filtering, and decoded token metadata - Parallel fetching across chains in one provider call Configuration: GOLDRUSH_API_KEY=your_key_here # optional Without key: existing behavior unchanged With key: agent context includes full multi-chain token portfolio Tested on: eth-mainnet, base-mainnet, arbitrum-mainnet, matic-mainnet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds pre-transfer and pre-swap spam validation using GoldRush Enhanced Spam Lists, protecting agents from interacting with known rug tokens. - HIGH confidence spam (Confidence.YES): blocks transaction with a clear error - MEDIUM confidence spam (Confidence.MAYBE): warns via elizaLogger, allows transaction - Fully optional: requires GOLDRUSH_API_KEY, fails open if unavailable or unsupported chain - Zero breaking changes to existing transfer/swap behavior New file: src/utils/spamCheck.ts - checkTokenSpam(tokenAddress, chainName, apiKey) → SpamCheckResult - Maps viem chain names → goldrush-enhanced-spam-lists network identifiers - Skips native tokens (zero address / "native") automatically - Fail-open: any error in the spam check allows the transaction through Modified: src/actions/transfer.ts - Runs checkTokenSpam on params.token if it is an ERC20 address - Blocks HIGH risk; logs warn for MEDIUM risk Modified: src/actions/swap.ts - Runs checkTokenSpam on the resolved destination token address - Blocks HIGH risk; logs warn for MEDIUM risk New file: src/tests/spamCheck.test.ts - 13 vitest unit tests covering all behavior rules Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new GET_TOKEN_INFO action that resolves token names and symbols
to contract addresses using the GoldRush REST search API.
Solves the most common natural language swap failure:
User: "swap 1 ETH for Pepe"
Before: agent fails — doesn't know Pepe's contract address
After: agent calls GET_TOKEN_INFO → finds contract → calls SWAP
Supports:
- Token name: "Pepe", "Chainlink", "Wrapped Bitcoin"
- Token symbol: "PEPE", "LINK", "WBTC"
- Contract address: "0x698..." (pass-through with metadata)
- Swap intent: "swap 1 ETH for PEPE"
Returns top 3 matches with chain, contract, price (with 24h change),
and market cap. Results are injected into agent context as structured
content so subsequent swap/transfer actions can use topResult directly.
Implementation notes:
- The GoldRush SDK's BaseService has no search method; the action calls
GET https://api.covalenthq.com/v1/search/ directly with Bearer auth
- Handles both { result_type, item } and flat response shapes
- Fully optional: validate() returns false when GOLDRUSH_API_KEY is absent
- Zero changes to existing actions
New files:
src/actions/getTokenInfo.ts — action + extractTokenQuery helper
src/actions/__tests__/getTokenInfo.test.ts — 17 vitest unit tests
Modified:
src/index.ts — registered getTokenInfoAction, exported from package
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.OpenGrep is compatible with Semgrep configurations. Add an |
| ` Chain: ${token.chain_name ?? 'unknown'}\n` + | ||
| ` Contract: ${token.contract_address}\n` + | ||
| ` Price: ${price}${change}\n` + | ||
| ` Market Cap: $${formatMcap(token.market_cap_usd)}` |
There was a problem hiding this comment.
$N/A displayed when market cap is unavailable
When formatMcap returns 'N/A' (for null, undefined, or 0 market cap), this template literal produces Market Cap: $N/A, which is a display bug. The $ prefix should only appear for numeric values.
| ` Market Cap: $${formatMcap(token.market_cap_usd)}` | |
| ` Market Cap: ${formatMcap(token.market_cap_usd)}` |
And update formatMcap to include the $ prefix for numeric cases:
const formatMcap = (mcap: number | null | undefined): string => {
if (mcap == null || mcap === 0) return 'N/A';
if (mcap >= 1e9) return `$${(mcap / 1e9).toFixed(1)}B`;
if (mcap >= 1e6) return `$${(mcap / 1e6).toFixed(1)}M`;
if (mcap >= 1e3) return `$${(mcap / 1e3).toFixed(1)}K`;
return `$${mcap.toFixed(0)}`;
};| const SPAM_CHAIN_MAP: Record<string, string> = { | ||
| mainnet: 'eth-mainnet', | ||
| base: 'base-mainnet', | ||
| optimism: 'op-mainnet', | ||
| polygon: 'pol-mainnet', | ||
| bsc: 'bsc-mainnet', | ||
| gnosis: 'gnosis-mainnet', | ||
| }; |
There was a problem hiding this comment.
Spam chain identifiers may not match the package's Networks enum
The official GoldRush docs show that isERC20Spam should be called with Networks.POLYGON_MAINNET, Networks.ETHEREUM_MAINNET, etc. (from the Networks enum exported by the package). This code passes raw strings instead. Two values are notably inconsistent with GoldRush's standard chain naming:
optimism: 'op-mainnet'— GoldRush usesoptimism-mainneteverywhere else (includingCHAIN_MAPinwallet.ts)polygon: 'pol-mainnet'— GoldRush usesmatic-mainneteverywhere else (includingCHAIN_MAPinwallet.ts)
Since errors fail-open, this won't crash — but spam checks on Optimism and Polygon will silently return UNKNOWN instead of actually checking the token.
Consider importing and using the Networks enum directly:
import { Confidence, Networks, isERC20Spam } from '@covalenthq/goldrush-enhanced-spam-lists';
const SPAM_CHAIN_MAP: Record<string, string> = {
mainnet: Networks.ETHEREUM_MAINNET,
base: Networks.BASE_MAINNET,
optimism: Networks.OPTIMISM_MAINNET,
polygon: Networks.POLYGON_MAINNET,
bsc: Networks.BSC_MAINNET,
gnosis: Networks.GNOSIS_MAINNET,
};
Summary
GET_TOKEN_INFOaction that resolves token names/symbols/addresses using the GoldRush REST search APIGOLDRUSH_API_KEY)Motivation
Supported query formats
"What is the Pepe token?""Find USDC on Base""Look up 0x6982508145454ce325ddbe47a25d4ec3d2311933""swap 1 ETH for PEPE"Response injected into agent context
The callback
content.topResultgives subsequent actions the contract address directly.Implementation notes
The GoldRush SDK's
BaseServicehas no search method (the streaming-basedStreamingService.searchTokenrequires WebSocket — not suitable for a synchronous action). The action calls the GoldRush REST API directly:Handles both
{ result_type, item }wrapped and flat response shapes for forward-compatibility.Configuration
Files changed
src/actions/getTokenInfo.tsextractTokenQueryhelpersrc/actions/__tests__/getTokenInfo.test.tssrc/index.tsTest plan
validate()returns false when no API keytopResultin callback content matches first search result🤖 Generated with Claude Code
Greptile Summary
This PR adds GoldRush integration across three areas: a new
GET_TOKEN_INFOaction for token search/lookup, pre-transfer/swap spam detection viagoldrush-enhanced-spam-lists, and optional multi-chain token balance enrichment in the wallet provider. All features are gated behind the optionalGOLDRUSH_API_KEYsetting and include proper error handling with fail-safe patterns.GET_TOKEN_INFOaction (src/actions/getTokenInfo.ts): Resolves token names/symbols/addresses via the GoldRush REST search API, enabling natural language swap workflows (e.g., "swap 1 ETH for Pepe"). IncludesextractTokenQueryhelper for NLP extraction. Minor display bug:$N/Ashown when market cap is unavailable.src/utils/spamCheck.ts): Uses@covalenthq/goldrush-enhanced-spam-listswith a two-tier check (HIGH blocks, MEDIUM warns, errors fail-open). Integrated intoswap.tsandtransfer.ts. Chain identifier strings for Optimism and Polygon may not match the package's expectedNetworksenum values, potentially causing silent fail-open on those chains.src/providers/wallet.ts): Appends multi-chain token holdings (with USD values) to the agent context whenGOLDRUSH_API_KEYis set, using the official@covalenthq/client-sdk.Confidence Score: 3/5
$N/Adisplay bug in market cap formatting is a definite rendering issue, and (2) the spam check chain mapping uses raw strings (op-mainnet,pol-mainnet) that likely don't match theNetworksenum expected by the spam-lists package, which would silently disable spam protection on Optimism and Polygon (fail-open by design, so no crash).src/actions/getTokenInfo.ts(display bug with$N/A) andsrc/utils/spamCheck.ts(chain identifier mismatch may disable spam checks on Optimism and Polygon)Important Files Changed
$N/Ashown when market cap is unavailable due to$prefix in template literal combined withformatMcapreturning'N/A'.op-mainnet,pol-mainnet) instead of theNetworksenum, and values differ from GoldRush's standard naming, which may cause spam checks on Optimism/Polygon to silently fail-open.GoldRushClienton each invocation rather than caching it.checkTokenSpam. Properly gated behind API key availability and correctly skips native token (zero address). Throws on HIGH risk, warns on MEDIUM.getTokenInfoActionin the plugin's actions array and adds re-export. Clean, minimal change.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["User: 'swap 1 ETH for Pepe'"] --> B[GET_TOKEN_INFO Action] B --> C{extractTokenQuery} C -->|"query: 'PEPE'"| D[GoldRush REST Search API] D --> E{Results found?} E -->|Yes| F[Format & return token info\ncontract, chain, price, mcap] E -->|No| G[Return 'No token found'] F --> H[topResult injected into context] H --> I[EVM_SWAP_TOKENS Action] I --> J{GOLDRUSH_API_KEY set?} J -->|Yes| K[checkTokenSpam\nvia goldrush-enhanced-spam-lists] J -->|No| L[Skip spam check] K --> M{Spam risk?} M -->|HIGH| N[Block swap] M -->|MEDIUM| O[Warn & proceed] M -->|LOW/UNKNOWN| P[Proceed with swap] L --> P O --> P P --> Q[Execute swap via LiFi/Bebop]Last reviewed commit: 9cf2e09
(4/5) You can add custom instructions or style guidelines for the agent here!