diff --git a/.cursor/rules/@graph-tooling.mdc b/.cursor/rules/@graph-tooling.mdc new file mode 100644 index 000000000..bce91681b --- /dev/null +++ b/.cursor/rules/@graph-tooling.mdc @@ -0,0 +1,324 @@ +--- +description: +globs: +alwaysApply: true +--- +--- +description: Monorepo for The Graph Protocol tooling including CLI and TypeScript bindings for subgraph development +globs: ["**/*.ts", "**/*.js", "**/*.json", "**/*.yaml", "**/*.md", "**/subgraph.yaml", "**/schema.graphql"] +--- + +# The Graph Tooling + +@context { + "type": "monorepo", + "purpose": "subgraph_development_tools", + "organization": "graphprotocol", + "license": "(Apache-2.0 OR MIT)", + "node_version": ">=20.0.0", + "package_manager": "pnpm" +} + +@structure { + "workspace": { + "packages": ["packages/*", "examples/*", "website"], + "main_tools": [ + "@graphprotocol/graph-cli", + "@graphprotocol/graph-ts" + ] + }, + "architecture": { + "monorepo": "pnpm workspace", + "build_system": "TypeScript + AssemblyScript", + "testing": "vitest", + "release": "changesets" + } +} + +## Core Packages + +### @graphprotocol/graph-cli + +@package_info { + "name": "@graphprotocol/graph-cli", + "description": "CLI for building and deploying subgraphs to The Graph", + "version": "0.97.1", + "bin": "graph", + "main_commands": [ + "add", + "auth", + "build", + "clean", + "codegen", + "create", + "deploy", + "init", + "local", + "publish", + "remove", + "test" + ] +} + +The primary CLI tool for subgraph developers providing: +- Project initialization and scaffolding +- Contract ABI integration +- Code generation from GraphQL schema +- Local development server +- Deployment to The Graph Network +- Authentication and authorization +- Testing and validation + +### @graphprotocol/graph-ts + +@package_info { + "name": "@graphprotocol/graph-ts", + "description": "TypeScript/AssemblyScript library for writing subgraph mappings", + "version": "0.38.1", + "language": "AssemblyScript", + "target": "WebAssembly" +} + +TypeScript bindings and runtime for subgraph mapping development: +- Type-safe blockchain data access +- Entity store operations +- Event handler utilities +- Built-in helper functions + +## Development Environment + +@development_setup { + "requirements": { + "node": ">=20.18.1", + "pnpm": "9.x", + "typescript": "^5.7.2" + }, + "commands": { + "install": "pnpm install", + "build": "pnpm build", + "test": "pnpm test", + "lint": "pnpm lint" + } +} + +### Project Structure + +@project_structure { + "packages/cli/": "Graph CLI implementation", + "packages/ts/": "TypeScript/AssemblyScript bindings", + "examples/": "Example subgraphs for various chains", + "website/": "Documentation website", + "patches/": "Package patches for dependencies" +} + +## Supported Networks + +@supported_networks [ + "ethereum", + "polygon", + "near", + "cosmos", + "arweave", + "substreams" +] + +## Examples + +@examples { + "ethereum": [ + "ethereum-gravatar", + "ethereum-basic-event-handlers", + "example-subgraph" + ], + "polygon": [ + "matic-lens-protocol-posts-subgraph" + ], + "near": [ + "near-blocks", + "near-receipts" + ], + "cosmos": [ + "cosmos-validator-rewards", + "cosmos-validator-delegations", + "cosmos-osmosis-token-swaps", + "cosmos-block-filtering" + ], + "arweave": [ + "arweave-blocks-transactions" + ], + "advanced": [ + "substreams-powered-subgraph", + "aggregations" + ] +} + +## CLI Usage Patterns + +@cli_patterns { + "initialization": { + "command": "graph init", + "purpose": "Create new subgraph project", + "options": ["--product", "--network", "--contract-name"] + }, + "development": { + "command": "graph codegen && graph build", + "purpose": "Generate code and build subgraph", + "watch": "graph build --watch" + }, + "deployment": { + "hosted_service": "graph deploy --product hosted-service", + "decentralized_network": "graph deploy --product subgraph-studio" + }, + "testing": { + "command": "graph test", + "purpose": "Run subgraph tests" + }, + "local_development": { + "command": "graph local", + "purpose": "Start local development environment" + } +} + +## TypeScript Integration + +@typescript_usage { + "mapping_files": { + "location": "src/mapping.ts", + "imports": ["@graphprotocol/graph-ts"], + "exports": ["event handlers", "block handlers"] + }, + "schema_types": { + "generation": "graph codegen", + "location": "generated/schema.ts", + "usage": "Import entity classes" + } +} + +```typescript +// Example mapping function +import { Transfer } from '../generated/Contract/Contract' +import { User, Transfer as TransferEntity } from '../generated/schema' + +export function handleTransfer(event: Transfer): void { + let user = User.load(event.params.to.toHex()) + if (user == null) { + user = new User(event.params.to.toHex()) + user.save() + } + + let transfer = new TransferEntity(event.transaction.hash.toHex()) + transfer.from = event.params.from + transfer.to = event.params.to + transfer.value = event.params.value + transfer.save() +} +``` + +## Configuration Files + +@configuration { + "subgraph.yaml": { + "purpose": "Subgraph manifest", + "sections": ["specVersion", "schema", "dataSources"], + "required": true + }, + "schema.graphql": { + "purpose": "GraphQL schema definition", + "contains": ["entities", "types", "relationships"], + "required": true + }, + "networks.json": { + "purpose": "Network configuration", + "optional": true, + "usage": "Multi-network deployments" + } +} + +## Release Process + +@release_process { + "tool": "@changesets/cli", + "workflow": [ + "Author creates PR with changeset file", + "PR merged to main", + "Bot creates version bump PR", + "Version PR merged triggers npm publish" + ], + "commands": { + "create_changeset": "pnpm changeset", + "release": "pnpm release" + } +} + +## Testing + +@testing_setup { + "framework": "vitest", + "test_files": "tests/**/*.test.ts", + "commands": { + "all": "pnpm test", + "cli_specific": "pnpm test:cli", + "ts_specific": "pnpm test:ts" + } +} + +## Build System + +@build_configuration { + "typescript": { + "config": "tsconfig.build.json", + "target": "ESNext", + "module": "ESNext" + }, + "assemblyscript": { + "cli_version": "0.19.23", + "ts_version": "0.27.31", + "runtime": "stub", + "optimization": "size" + }, + "bundling": { + "cli": "TypeScript compilation + oclif manifest", + "ts": "AssemblyScript to WebAssembly" + } +} + +## Common Issues & Solutions + +@troubleshooting [ + { + "issue": "Node version compatibility", + "solution": "Use Node.js >=20.18.1", + "severity": "error" + }, + { + "issue": "AssemblyScript compilation errors", + "solution": "Check graph-ts version compatibility", + "severity": "warning" + }, + { + "issue": "Subgraph deployment failures", + "solution": "Verify network config and API keys", + "severity": "error" + } +] + +## Contributing + +@contribution_guidelines { + "repository": "https://github.com/graphprotocol/graph-tooling", + "requirements": [ + "Node.js >=20.x", + "pnpm package manager", + "Changeset file for PRs" + ], + "workflow": [ + "Fork repository", + "Create feature branch", + "Add changeset with `pnpm changeset`", + "Submit PR with tests" + ] +} + +@version "0.97.1" +@last_updated "2024-12-19" + diff --git a/.cursor/rules/mdc.mdc b/.cursor/rules/mdc.mdc new file mode 100644 index 000000000..9b3c5bf5c --- /dev/null +++ b/.cursor/rules/mdc.mdc @@ -0,0 +1,355 @@ +--- +description: +globs: +alwaysApply: true +--- +--- +description: Guidelines and best practices for creating .mdc (Markdown Configuration) files in Cursor, including structure, metadata annotations, and formatting rules +globs: ["**/*.mdc"] +--- + +# Cursor MDC File Guidelines + +@context { + "type": "documentation", + "purpose": "cursor_rules", + "format_version": "1.0.0", + "supported_content_types": [ + "guidelines", + "api_docs", + "examples", + "implementations" + ] +} + +@structure { + "required_sections": [ + "frontmatter", + "title", + "context", + "content_sections" + ], + "optional_sections": [ + "version", + "last_updated", + "examples", + "implementations", + "related_files" + ], + "recommended_sections": [ + "practical_examples", + "common_patterns", + "type_definitions" + ] +} + +## File Structure + +### 1. Frontmatter + +@frontmatter_rules [ + { + "id": "position", + "rule": "Must be at the very top of the file", + "severity": "error" + }, + { + "id": "description", + "rule": "Single sentence, clear purpose", + "severity": "error" + }, + { + "id": "globs", + "rule": "Array of relevant file patterns", + "severity": "error" + }, + { + "id": "related_docs", + "rule": "Optional array of related documentation files - MUST only reference existing files", + "severity": "error" + }, + { + "id": "file_validation", + "rule": "All referenced files must exist in the workspace", + "severity": "error" + } +] + +Example frontmatter: +```yaml +--- +description: Guidelines for implementing feature X +globs: ["**/*.{ts,tsx}"] +related_docs: ["docs/architecture/feature-x.md"] +--- +``` + +### 2. Metadata Annotations + +@annotations { + "syntax": "@annotation_name JSON_content", + "placement": "Before relevant sections", + "format": "Valid JSON with proper indentation", + "types": { + "context": "Project and document context", + "rules": "List of rules or requirements", + "format": "Format specifications", + "options": "Available options", + "examples": "Implementation examples", + "implementations": "Full implementation details", + "related": "Related documentation or code" + } +} + +### 3. Content Structure + +@content_rules { + "headings": { + "h1": "Single main title", + "h2": "Major sections", + "h3": "Subsections", + "h4": "Detailed points" + }, + "code_blocks": { + "syntax": "Always specify language", + "examples": "Include practical examples", + "formatting": "Use proper indentation", + "context": "Add explanatory comments" + }, + "implementation_blocks": { + "structure": "Group related implementations", + "documentation": "Include inline documentation", + "types": "Specify type information", + "validation": "Include validation rules" + } +} + +## Best Practices + +@best_practices { + "organization": { + "sections": "Use clear hierarchical structure", + "annotations": "Place before relevant content", + "examples": "Include practical examples" + }, + "formatting": { + "json": "Properly formatted, valid JSON", + "markdown": "Clean, consistent spacing", + "code": "Language-specific syntax highlighting" + }, + "metadata": { + "annotations": "Use semantic names", + "context": "Provide clear scope", + "versioning": "Include version information" + }, + "implementation": { + "examples": "Provide complete, working examples", + "types": "Include type definitions", + "validation": "Specify validation rules", + "error_handling": "Document error cases" + } +} + +## Implementation Guidelines + +@implementation_rules { + "code_examples": { + "completeness": "Must be fully functional", + "types": "Include all necessary type information", + "imports": "Show all required imports", + "context": "Provide setup and usage context" + }, + "documentation": { + "inline": "Add explanatory comments", + "types": "Document type constraints", + "errors": "Document error conditions", + "usage": "Show usage patterns" + } +} + +## Example Structure + +### Basic Example +```markdown +--- +description: Example implementation of feature X +globs: ["src/features/**/*.ts"] +--- + +# Feature X Implementation + +@context { + "type": "implementation", + "feature": "X", + "version": "1.0.0" +} + +## Overview +[Feature description] + +## Implementation + +@implementation { + "language": "typescript", + "dependencies": ["dep1", "dep2"], + "types": { + "TypeX": "Description of TypeX" + } +} + +```typescript +// Implementation code with types and validation +``` + +## Usage Examples +[Usage examples with code] +``` + +### Full Implementation Example +See the `examples` section in related .mdc files for complete implementation examples. + +## Common Patterns + +@patterns { + "rules_section": { + "format": "array of objects", + "properties": ["id", "severity", "description"], + "example": [ + { + "id": "rule_name", + "severity": "error", + "description": "Clear description" + } + ] + }, + "implementation_section": { + "format": "object with implementation details", + "required": [ + "language", + "types", + "validation" + ], + "example": { + "language": "typescript", + "types": { + "Type1": "Description" + }, + "validation": { + "rule1": "Description" + } + } + } +} + +## Examples + +### Minimal Valid MDC File +```markdown +--- +description: A simple example MDC file +globs: ["**/*.example"] +--- + +# Example Rules + +@context { + "type": "example", + "version": "1.0.0" +} + +## Section One + +@rules [ + { + "id": "rule_one", + "severity": "error", + "description": "Description of rule one" + } +] +``` + +### Common Section Examples + +#### Rules Section +```markdown +@rules [ + { + "id": "unique_identifier", + "severity": "error|warning|info", + "description": "Clear description of the rule" + } +] +``` + +#### Options Section +```markdown +@options { + "option_name": "What this option does", + "another_option": "Description of another option" +} +``` + +#### Format Section +```markdown +@format { + "base": "Template with {placeholders}", + "options": ["array", "of", "options"], + "paths": { + "key": "value" + } +} +``` + +### Common Mistakes to Avoid + +@mistakes [ + { + "id": "missing_frontmatter", + "wrong": "Starting directly with content", + "correct": "Include frontmatter at top", + "reason": "Frontmatter is required for Cursor to properly parse the file" + }, + { + "id": "invalid_json", + "wrong": "Malformed JSON in annotations", + "correct": "Properly formatted JSON with quotes around keys", + "reason": "Annotations must contain valid JSON for proper parsing" + }, + { + "id": "inconsistent_structure", + "wrong": "Mixed levels of headings", + "correct": "Clear hierarchical structure", + "reason": "Consistent structure helps with readability and parsing" + }, + { + "id": "nonexistent_files", + "wrong": "Referencing files that don't exist in the workspace", + "correct": "Only reference files that exist and have been verified", + "reason": "Prevents broken links and maintains documentation integrity" + } +] + +## Validation + +@validation { + "required": [ + "Frontmatter must be present and valid", + "All JSON must be properly formatted", + "Main title must be present", + "At least one content section", + "Complete implementation examples when relevant", + "All referenced files must exist in the workspace" + ], + "recommended": [ + "Version information", + "Last updated date", + "Clear examples", + "Proper code formatting", + "Type definitions", + "Validation rules", + "Verify file existence before referencing" + ] +} + +@version "1.1.0" +@last_updated "2024-03-19" \ No newline at end of file