generate_oracle
Generate Chainlink oracle integration code for Arbitrum dApps to implement price feeds, VRF, automation, or functions with optional Stylus and frontend components.
Instructions
Generate Chainlink oracle integration code for Arbitrum dApps.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Description of the oracle functionality needed | |
| oracle_type | No | Type of Chainlink oracle to integrate | |
| network | No | Network to deploy on | arbitrumSepolia |
| include_stylus | No | Include Stylus (Rust) implementation if available | |
| include_frontend | No | Include frontend React hooks |
Implementation Reference
- src/mcp/tools/generate_oracle.py:84-152 (handler)The 'execute' method of GenerateOracleTool handles the logic for generating oracle integration code based on the provided prompt and oracle_type. It selects a template, builds the necessary file content (contracts, scripts, config), and returns a dictionary containing the generated files and instructions.
def execute(self, **kwargs) -> dict[str, Any]: """Generate oracle integration code based on the request.""" prompt = kwargs.get("prompt", "") oracle_type = kwargs.get("oracle_type") network = kwargs.get("network", "arbitrumSepolia") price_pairs = kwargs.get("price_pairs", ["ETH/USD"]) include_stylus = kwargs.get("include_stylus", False) include_frontend = kwargs.get("include_frontend", True) # Validate inputs if not prompt: return {"error": "prompt is required"} # Select template if oracle_type: template = get_oracle_template(oracle_type) if not template: return {"error": f"Unknown oracle_type: {oracle_type}"} else: template = select_oracle_template(prompt) # Context retrieval (template-based generation doesn't require RAG) context = [] # Build files files = {} # Add Solidity contract files["contracts/OracleConsumer.sol"] = self._customize_solidity( template, network, price_pairs ) # Add Stylus implementation if available and requested if include_stylus and template.stylus_code: files["contracts/src/lib.rs"] = template.stylus_code # Add frontend hook if requested if include_frontend: files["src/hooks/useOracle.ts"] = template.frontend_hook # Add deployment script files["scripts/deploy.ts"] = self._generate_deploy_script(template, network) # Add Hardhat scaffold files files["hardhat.config.ts"] = self._generate_hardhat_config() files["package.json"] = self._generate_package_json(template, network) files[".env.example"] = "PRIVATE_KEY=your-private-key-without-0x-prefix\n" # Build response result = { "template_used": template.name, "oracle_type": template.oracle_type, "files": files, "dependencies": template.dependencies, "network_config": template.networks.get(network, {}), "features": template.features, "setup_instructions": self._get_setup_instructions(template, network), } if context: result["references"] = [ { "source": c.get("metadata", {}).get("source", "Unknown"), "relevance": c.get("distance", 0), } for c in context[:3] ] return result - The 'input_schema' defines the expected input parameters for the 'generate_oracle' tool, including 'prompt', 'oracle_type', 'network', 'price_pairs', 'include_stylus', and 'include_frontend'.
input_schema = { "type": "object", "properties": { "prompt": { "type": "string", "description": "Description of the oracle functionality needed", }, "oracle_type": { "type": "string", "enum": ["price_feed", "vrf", "automation", "functions"], "description": "Type of Chainlink oracle to integrate", }, "network": { "type": "string", "enum": ["arbitrum", "arbitrumSepolia"], "description": "Network to deploy on", "default": "arbitrumSepolia", }, "price_pairs": { "type": "array", "items": {"type": "string"}, "description": "Price pairs to include (e.g., ['ETH/USD', 'BTC/USD'])", }, "include_stylus": { "type": "boolean", "description": "Include Stylus (Rust) implementation if available", "default": False, }, "include_frontend": { "type": "boolean", "description": "Include frontend React hooks", "default": True, }, }, "required": ["prompt"], } - src/mcp/tools/generate_oracle.py:28-40 (registration)The 'GenerateOracleTool' class defines the 'generate_oracle' tool name, description, and input schema. It inherits from 'BaseTool'.
class GenerateOracleTool(BaseTool): """Generate Chainlink oracle integration code.""" name = "generate_oracle" description = """Generate Chainlink oracle integration code for Arbitrum dApps. Supports: - Price Feed: Real-time price data (ETH/USD, BTC/USD, etc.) - VRF: Verifiable Random Function for provably fair randomness - Automation: Chainlink Keepers for automated contract execution - Functions: Custom JavaScript execution on Chainlink's DON Generates both Solidity contracts and frontend integration hooks."""