diff --git a/examples/solana_token_analysis/README.md b/examples/solana_token_analysis/README.md new file mode 100644 index 0000000..2c3daae --- /dev/null +++ b/examples/solana_token_analysis/README.md @@ -0,0 +1,29 @@ +# Solana Token Analysis with OpenGradient LLM + +Analyzes Solana tokens using verifiable LLM inference on OpenGradient's +decentralized network. Fetches live data from DexScreener and returns +a risk assessment with an onchain transaction hash as proof of execution. + +## Setup + +pip install -r requirements.txt + +## Configure + +export OG_PRIVATE_KEY="0x..." + +## Run + +python main.py + +## Output + +Wallet: 0x... +Token: BONK | Price: $0.000012 +Liquidity: $2,500,000 | Volume 24h: $890,000 + +Running verifiable inference on OpenGradient network... + +--- Analysis: BONK --- +TX Hash: 0x... +BONK shows strong liquidity and healthy buy pressure... diff --git a/examples/solana_token_analysis/main.py b/examples/solana_token_analysis/main.py new file mode 100644 index 0000000..20c3e43 --- /dev/null +++ b/examples/solana_token_analysis/main.py @@ -0,0 +1,86 @@ +""" +Solana Token Analysis using OpenGradient Verifiable LLM Inference +Fetches live token data from DexScreener and analyzes it using +an LLM running on OpenGradient's decentralized network. +""" + +import os +import json +import requests +import opengradient as og + + +def init_client(): + private_key = os.environ.get("OG_PRIVATE_KEY") + if not private_key: + raise ValueError("Please set OG_PRIVATE_KEY environment variable") + og.init(private_key=private_key) + print(f"Wallet: {og.global_client.wallet_address}") + + +def fetch_token_data(token_address: str) -> dict: + """Fetch live Solana token data from DexScreener API.""" + url = f"https://api.dexscreener.com/latest/dex/tokens/{token_address}" + response = requests.get(url, timeout=10) + data = response.json() + pairs = data.get("pairs", []) + if not pairs: + return {} + pair = pairs[0] + return { + "symbol": pair.get("baseToken", {}).get("symbol", "UNKNOWN"), + "name": pair.get("baseToken", {}).get("name", "UNKNOWN"), + "price_usd": pair.get("priceUsd", "0"), + "volume_24h": pair.get("volume", {}).get("h24", 0), + "liquidity_usd": pair.get("liquidity", {}).get("usd", 0), + "price_change_24h": pair.get("priceChange", {}).get("h24", 0), + "txns_buys_24h": pair.get("txns", {}).get("h24", {}).get("buys", 0), + "txns_sells_24h": pair.get("txns", {}).get("h24", {}).get("sells", 0), + } + + +def analyze_token(token_address: str): + """Analyze a Solana token using OpenGradient LLM inference.""" + print(f"\nFetching data for {token_address}...") + token_data = fetch_token_data(token_address) + + if not token_data: + print("Could not fetch token data.") + return + + print(f"Token: {token_data['symbol']} | Price: ${token_data['price_usd']}") + print(f"Liquidity: ${token_data['liquidity_usd']:,} | Volume 24h: ${token_data['volume_24h']:,}") + + messages = [ + { + "role": "system", + "content": ( + "You are a Solana DeFi analyst. Analyze the token data provided " + "and give a concise risk assessment. Highlight liquidity, volume, " + "buy/sell pressure, and any red flags. Be direct and actionable. " + "Keep response under 100 words." + ) + }, + { + "role": "user", + "content": f"Analyze this Solana token:\n{json.dumps(token_data, indent=2)}" + } + ] + + print("\nRunning verifiable inference on OpenGradient network...") + result = og.global_client.llm.chat( + model=og.TEE_LLM.GEMINI_2_0_FLASH, + messages=messages, + max_tokens=150 + ) + + print(f"\n--- Analysis: {token_data['symbol']} ---") + print(f"TX Hash: {result.transaction_hash}") + print(f"\n{result.choices[0].message.content}") + + +if __name__ == "__main__": + init_client() + # BONK token on Solana + BONK = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" + analyze_token(BONK) diff --git a/examples/solana_token_analysis/requirements.txt b/examples/solana_token_analysis/requirements.txt new file mode 100644 index 0000000..2d13165 --- /dev/null +++ b/examples/solana_token_analysis/requirements.txt @@ -0,0 +1,2 @@ +opengradient>=0.7.4 +requests>=2.28.0