repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | """Configuration loader for Solana Trading Agent""" |
| #2 | |
| #3 | import os |
| #4 | from pathlib import Path |
| #5 | from dataclasses import dataclass |
| #6 | from typing import Optional |
| #7 | from dotenv import load_dotenv |
| #8 | |
| #9 | |
| #10 | @dataclass |
| #11 | class SolanaAgentConfig: |
| #12 | """Configuration for the Solana Trading Agent""" |
| #13 | |
| #14 | # REQUIRED FIELDS (must come first) |
| #15 | # Helius RPC |
| #16 | helius_api_key: str |
| #17 | helius_rpc_url: str |
| #18 | helius_wss_url: str |
| #19 | |
| #20 | # Birdeye |
| #21 | birdeye_api_key: str |
| #22 | |
| #23 | # Wallet |
| #24 | wallet_address: str |
| #25 | |
| #26 | # OPTIONAL FIELDS (with defaults) |
| #27 | # Jupiter Trading (preferred) |
| #28 | jupiter_api_key: Optional[str] = None |
| #29 | jupiter_referral_account: Optional[str] = None |
| #30 | |
| #31 | # Bags Trading (legacy, optional) |
| #32 | bags_api_key: Optional[str] = None |
| #33 | bags_config_key: Optional[str] = None |
| #34 | bags_ref_code: Optional[str] = None |
| #35 | |
| #36 | # Optional configurations |
| #37 | birdeye_wss_url: Optional[str] = None |
| #38 | private_key: Optional[str] = None |
| #39 | |
| #40 | # LLM (OpenRouter) |
| #41 | openrouter_api_key: Optional[str] = None |
| #42 | openrouter_model: str = "minimax/minimax-m2-her" |
| #43 | |
| #44 | # LLM (Ollama - local) |
| #45 | ollama_base_url: str = "http://localhost:11434/v1" |
| #46 | ollama_model: str = "minimax-m2.1:cloud" |
| #47 | llm_provider: str = "openrouter" # "openrouter" or "ollama" |
| #48 | |
| #49 | # Twitter/X API (optional) |
| #50 | twitter_consumer_key: Optional[str] = None |
| #51 | twitter_consumer_secret: Optional[str] = None |
| #52 | twitter_access_token: Optional[str] = None |
| #53 | twitter_access_token_secret: Optional[str] = None |
| #54 | twitter_bearer_token: Optional[str] = None |
| #55 | twitter_client_id: Optional[str] = None |
| #56 | twitter_client_secret: Optional[str] = None |
| #57 | |
| #58 | # MiniMax API (optional - for image, music, video, speech generation) |
| #59 | minimax_api_key: Optional[str] = None |
| #60 | |
| #61 | # Search API (optional - for real-time web search) |
| #62 | search_api_key: Optional[str] = None |
| #63 | xai_api_key: Optional[str] = None |
| #64 | |
| #65 | # CoinGecko API (optional - for real-time crypto market data) |
| #66 | coingecko_api_key: Optional[str] = None |
| #67 | |
| #68 | # Aster DEX (optional - for perpetual and spot trading) |
| #69 | aster_api_key: Optional[str] = None |
| #70 | aster_user_address: Optional[str] = None |
| #71 | aster_signer_address: Optional[str] = None |
| #72 | aster_private_key: Optional[str] = None |
| #73 | |
| #74 | # Hyperliquid DEX (optional - for perpetual and spot trading on Hyperliquid L1) |
| #75 | hyperliquid_wallet: Optional[str] = None |
| #76 | hyperliquid_private_key: Optional[str] = None |
| #77 | hyperliquid_use_testnet: bool = False |
| #78 | |
| #79 | # CDP (Coinbase Developer Platform) - for managed Solana accounts |
| #80 | cdp_api_key_id: Optional[str] = None |
| #81 | cdp_api_key_secret: Optional[str] = None |
| #82 | cdp_wallet_secret: Optional[str] = None |
| #83 | cdp_rpc_url: str = "https://api.mainnet-beta.solana.com" |
| #84 | cdp_network: str = "solana-mainnet" |
| #85 | |
| #86 | # Agent settings |
| #87 | max_steps: int = 50 |
| #88 | workspace_dir: str = "./workspace" |
| #89 | |
| #90 | @classmethod |
| #91 | def from_env(cls, env_path: Optional[str] = None) -> "SolanaAgentConfig": |
| #92 | """Load configuration from environment variables or .env file.""" |
| #93 | |
| #94 | # Load .env file if provided |
| #95 | if env_path: |
| #96 | load_dotenv(env_path) |
| #97 | else: |
| #98 | # Try common locations |
| #99 | for path in [".env.local", ".env", "../.env.local", "../.env"]: |
| #100 | if Path(path).exists(): |
| #101 | load_dotenv(path) |
| #102 | break |
| #103 | |
| #104 | # Required configurations |
| #105 | helius_api_key = os.getenv("HELIUS_API_KEY") |
| #106 | helius_rpc_url = os.getenv("HELIUS_RPC_URL") |
| #107 | helius_wss_url = os.getenv("HELIUS_WSS_URL") |
| #108 | |
| #109 | # Jupiter (preferred trading API) |
| #110 | jupiter_api_key = os.getenv("JUPITER_API_KEY") |
| #111 | jupiter_referral_account = os.getenv("JUPITER_REFERRAL_ACCOUNT") |
| #112 | |
| #113 | # Bags (legacy, optional) |
| #114 | bags_api_key = os.getenv("BAGS_API_KEY") |
| #115 | bags_config_key = os.getenv("BAGS_CONFIG_KEY") |
| #116 | bags_ref_code = os.getenv("BAGS_REF_CODE", "") |
| #117 | |
| #118 | birdeye_api_key = os.getenv("BIRDEYE_API_KEY") |
| #119 | birdeye_wss_url = os.getenv("BIRDEYE_WSS_URL") |
| #120 | |
| #121 | twitter_consumer_key = os.getenv("TWITTER_CONSUMER_KEY") |
| #122 | twitter_consumer_secret = os.getenv("TWITTER_CONSUMER_SECRET") |
| #123 | twitter_access_token = os.getenv("TWITTER_ACCESS_TOKEN") |
| #124 | twitter_access_token_secret = os.getenv("TWITTER_ACCESS_TOKEN_SECRET") |
| #125 | twitter_bearer_token = os.getenv("TWITTER_BEARER_TOKEN") |
| #126 | twitter_client_id = os.getenv("TWITTER_CLIENT_ID") |
| #127 | twitter_client_secret = os.getenv("TWITTER_CLIENT_SECRET") |
| #128 | |
| #129 | minimax_api_key = os.getenv("MINIMAX_API_KEY") |
| #130 | |
| #131 | search_api_key = os.getenv("SEARCH_API_KEY") or os.getenv("SERP_API_KEY") |
| #132 | xai_api_key = os.getenv("XAI_API_KEY") |
| #133 | |
| #134 | coingecko_api_key = os.getenv("COINGECKO_API_KEY") |
| #135 | |
| #136 | aster_api_key = os.getenv("ASTER_API_KEY") |
| #137 | aster_user_address = os.getenv("ASTER_USER_ADDRESS") |
| #138 | aster_signer_address = os.getenv("ASTER_SIGNER_ADDRESS") |
| #139 | aster_private_key = os.getenv("ASTER_PRIVATE_KEY") |
| #140 | |
| #141 | # Hyperliquid DEX |
| #142 | hyperliquid_wallet = os.getenv("HYPERLIQUID_WALLET") |
| #143 | hyperliquid_private_key = os.getenv("HYPERLIQUID_PRIVATE_KEY") |
| #144 | hyperliquid_use_testnet = os.getenv("HYPERLIQUID_USE_TESTNET", "false").lower() == "true" |
| #145 | |
| #146 | # CDP (Coinbase Developer Platform) - defaults to mainnet |
| #147 | cdp_api_key_id = os.getenv("CDP_API_KEY_ID") |
| #148 | cdp_api_key_secret = os.getenv("CDP_API_KEY_SECRET") |
| #149 | cdp_wallet_secret = os.getenv("CDP_WALLET_SECRET") |
| #150 | cdp_rpc_url = os.getenv("CDP_RPC_URL") or helius_rpc_url or "https://api.mainnet-beta.solana.com" |
| #151 | cdp_network = os.getenv("CDP_NETWORK", "solana-mainnet") |
| #152 | |
| #153 | wallet_address = os.getenv("MAWD_WALLET") |
| #154 | private_key = os.getenv("MAWD_PRIVATE_KEY") |
| #155 | |
| #156 | openrouter_api_key = os.getenv("OPENROUTER_API_KEY") |
| #157 | # Try OPENROUTER_MODEL first, then OPENROUTER_CLAUDE for backwards compatibility |
| #158 | openrouter_model = os.getenv("OPENROUTER_MODEL") or os.getenv("OPENROUTER_CLAUDE", "minimax/minimax-m2-her") |
| #159 | |
| #160 | # Ollama configuration |
| #161 | ollama_base_url = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434/v1") |
| #162 | ollama_model = os.getenv("OLLAMA_MODEL", "minimax-m2.1:cloud") |
| #163 | llm_provider = os.getenv("LLM_PROVIDER", "openrouter") # "openrouter" or "ollama" |
| #164 | |
| #165 | # Validate required fields |
| #166 | missing = [] |
| #167 | if not helius_api_key: |
| #168 | missing.append("HELIUS_API_KEY") |
| #169 | if not helius_rpc_url: |
| #170 | missing.append("HELIUS_RPC_URL") |
| #171 | if not birdeye_api_key: |
| #172 | missing.append("BIRDEYE_API_KEY") |
| #173 | if not wallet_address: |
| #174 | missing.append("MAWD_WALLET") |
| #175 | |
| #176 | # Require at least one trading API (Jupiter preferred) |
| #177 | if not jupiter_api_key and not bags_api_key: |
| #178 | missing.append("JUPITER_API_KEY or BAGS_API_KEY") |
| #179 | if bags_api_key and not bags_config_key: |
| #180 | missing.append("BAGS_CONFIG_KEY (required if using BAGS_API_KEY)") |
| #181 | |
| #182 | if missing: |
| #183 | raise ValueError(f"Missing required environment variables: {', '.join(missing)}") |
| #184 | |
| #185 | return cls( |
| #186 | helius_api_key=helius_api_key, |
| #187 | helius_rpc_url=helius_rpc_url, |
| #188 | helius_wss_url=helius_wss_url or f"wss://mainnet.helius-rpc.com/?api-key={helius_api_key}", |
| #189 | jupiter_api_key=jupiter_api_key, |
| #190 | jupiter_referral_account=jupiter_referral_account, |
| #191 | bags_api_key=bags_api_key, |
| #192 | bags_config_key=bags_config_key, |
| #193 | bags_ref_code=bags_ref_code, |
| #194 | birdeye_api_key=birdeye_api_key, |
| #195 | birdeye_wss_url=birdeye_wss_url or f"wss://public-api.birdeye.so/socket/solana?x-api-key={birdeye_api_key}", |
| #196 | twitter_consumer_key=twitter_consumer_key, |
| #197 | twitter_consumer_secret=twitter_consumer_secret, |
| #198 | twitter_access_token=twitter_access_token, |
| #199 | twitter_access_token_secret=twitter_access_token_secret, |
| #200 | twitter_bearer_token=twitter_bearer_token, |
| #201 | twitter_client_id=twitter_client_id, |
| #202 | twitter_client_secret=twitter_client_secret, |
| #203 | minimax_api_key=minimax_api_key, |
| #204 | search_api_key=search_api_key, |
| #205 | xai_api_key=xai_api_key, |
| #206 | coingecko_api_key=coingecko_api_key, |
| #207 | aster_api_key=aster_api_key, |
| #208 | aster_user_address=aster_user_address, |
| #209 | aster_signer_address=aster_signer_address, |
| #210 | aster_private_key=aster_private_key, |
| #211 | hyperliquid_wallet=hyperliquid_wallet, |
| #212 | hyperliquid_private_key=hyperliquid_private_key, |
| #213 | hyperliquid_use_testnet=hyperliquid_use_testnet, |
| #214 | cdp_api_key_id=cdp_api_key_id, |
| #215 | cdp_api_key_secret=cdp_api_key_secret, |
| #216 | cdp_wallet_secret=cdp_wallet_secret, |
| #217 | cdp_rpc_url=cdp_rpc_url, |
| #218 | cdp_network=cdp_network, |
| #219 | wallet_address=wallet_address, |
| #220 | private_key=private_key, |
| #221 | openrouter_api_key=openrouter_api_key, |
| #222 | openrouter_model=openrouter_model, |
| #223 | ollama_base_url=ollama_base_url, |
| #224 | ollama_model=ollama_model, |
| #225 | llm_provider=llm_provider, |
| #226 | ) |
| #227 | |
| #228 | |
| #229 | def load_config(env_path: Optional[str] = None) -> SolanaAgentConfig: |
| #230 | """Load configuration from environment.""" |
| #231 | return SolanaAgentConfig.from_env(env_path) |
| #232 |