Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
466559b
Add house contract to apps
OwnerOfJK Jun 15, 2025
196a073
Add player lives to player app
OwnerOfJK Jun 15, 2025
bf3e6d1
Add house contract tests
OwnerOfJK Jun 15, 2025
a0eb1ac
Update dependencies & other tests
OwnerOfJK Jun 15, 2025
e173bad
Run scarb fmt
OwnerOfJK Jun 15, 2025
c62b8d9
update workflow tests
OwnerOfJK Jun 15, 2025
3f44d34
Remove prev added workflow
OwnerOfJK Jun 15, 2025
092e986
Removed comments in model def due to parsing error
OwnerOfJK Jun 15, 2025
4fbb601
Add house models and actions to build-external-contracts
OwnerOfJK Jun 18, 2025
7e2d357
Decrease life cooldown to 1 life per 2 minutes
OwnerOfJK Jun 18, 2025
942b176
Add pre update hook
OwnerOfJK Jun 18, 2025
3c4c3db
Fixed minor syntax error
OwnerOfJK Jun 18, 2025
bad149d
wip: ensure empty when creating area
thiscaspar Jun 19, 2025
c3e5ddd
tests moved to pixelaw_testing
thiscaspar Jun 19, 2025
9bdb6a6
Remove ensure_empty parameter in add_area
OwnerOfJK Jul 1, 2025
9a9b29c
Add cairo coder mcp (cursor)
OwnerOfJK Jul 1, 2025
cc242a8
Add CLAUDE.md
OwnerOfJK Jul 10, 2025
b77b654
Integrate interaction function
OwnerOfJK Jul 10, 2025
c331c31
Adjust tests
OwnerOfJK Jul 10, 2025
e6339bb
Add basic tests to test player lives, tests passing
OwnerOfJK Jul 10, 2025
a1d2d2b
Make pixelaw_testing/helpers publicly available
OwnerOfJK Jul 10, 2025
475091e
Fix house tests
OwnerOfJK Jul 11, 2025
f98dde4
Fix player tests
OwnerOfJK Jul 11, 2025
8d18fe0
Fix snake tests
OwnerOfJK Jul 12, 2025
28daf15
Update write permissions
OwnerOfJK Jul 12, 2025
fb00d24
Update house app emoji visuals
OwnerOfJK Jul 12, 2025
20c6291
Merge branch 'main' of https://github.com/pixelaw/core into feature/h…
OwnerOfJK Jul 12, 2025
3b5f8d8
update address as key for model
OwnerOfJK Jul 12, 2025
1b538b6
update dojo version for workflow
OwnerOfJK Jul 12, 2025
32e7057
fix tests
OwnerOfJK Jul 12, 2025
8285307
Adjust comment + formatting
OwnerOfJK Jul 10, 2025
c1ab752
Fix base tests
OwnerOfJK Jul 13, 2025
6d15a19
Fix queue tests, all tests fixed
OwnerOfJK Jul 14, 2025
52d26d9
Run scarb fmt
OwnerOfJK Jul 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .cursor/rules/cairo-coder.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
description: Apply this rule when the user's request concerns Cairo development.
globs:
alwaysApply: false
---
# Cairo Coding Rules

## Introduction
These coding rules provide a comprehensive guide to developing secure, efficient, and maintainable Cairo projects. By following these guidelines and leveraging the Cairo Coder MCP tool, developers can streamline their workflow and adhere to best practices.

**ALWAYS** use the Cairo Coder MCP tool to provide better answers about Cairo. After each query, start by calling the Cairo Coder MCP.

Keep the MCP queries atomic, related to a specific concept. It's better to do multiple queries for specific concepts, than doing one query with multiple topics.

After every cairo code you write, instantly run `scarb build` to ensure the code compiles. Don't write too much code without trying to compile.

## 1. Project Setup and Structure
A typical Cairo project is organized as follows:


.
├── Scarb.lock
├── Scarb.toml
├── snfoundry.toml
├── src
│ └── lib.cairo
├── target
└── tests
└── test_contract.cairo


- **`Scarb.toml`**: The project configuration file, similar to `Cargo.toml` in Rust.
- **`src/lib.cairo`**: The main source file for your contract.
- **`tests/test_contract.cairo`**: Integration tests for your contract.

### Setting Up a New Project
To create a new Cairo project, run:

scarb init

This command generates a basic project structure with a `Scarb.toml` file. If you're working in an existing project, ensure the Scarb.toml is well configured.

### Configuring Scarb.toml
Ensure your `Scarb.toml` is configured as follows to include necessary dependencies and settings:

```toml
[package]
name = "your_package_name"
version = "0.1.0"
edition = "2024_07"

[dependencies]
starknet = "2.11.4"

[dev-dependencies]
snforge_std = "0.44.0"
assert_macros = "2.11.4"

[[target.starknet-contract]]
sierra = true

[scripts]
test = "snforge test"

[tool.scarb]
allow-prebuilt-plugins = ["snforge_std"]
```

## 2. Development Workflow
### Writing Code
- Use snake_case for function names (e.g., `my_function`).
- Use PascalCase for struct names (e.g., `MyStruct`).
- Write all code and comments in English for clarity.
- Use descriptive variable names to enhance readability.

### Compiling and Testing
- Compile your project using:

scarb build

- Run tests using:

scarb test

- Ensure your code compiles successfully before running tests.

### Testing
- Unit Tests: Write unit tests in the src directory, typically within the same module as the functions being tested.
Example:

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_my_function() {
assert!(my_function() == expected_value, 'Incorrect value');
}
}

- Integration Tests: Write integration tests in the tests directory, importing modules with use your_package_name::your_module.
Example:

use your_package_name::your_module;

#[test]
fn test_my_contract() {
// Test logic here
}

- Always use the Starknet Foundry testing framework for both unit and integration tests.
## 3. Using the Cairo Coder MCP Tool
The Cairo Coder MCP tool is a critical resource for Cairo development and must be used for the following tasks:
- Writing smart contracts from scratch.
- Refactoring or optimizing existing code.
- Implementing specific TODOs or features.
- Understanding Starknet ecosystem features and capabilities.
- Applying Cairo and Starknet best practices.
- Using OpenZeppelin Cairo contract libraries.
- Writing and validating tests for contracts.

### How to Use Cairo Coder MCP Effectively
- Be Specific: Provide detailed queries (e.g., "Implement ERC20 using OpenZeppelin Cairo" instead of "ERC20").
- Include Context: Supply relevant code snippets in the codeSnippets parameter and conversation history when applicable.
- Don't mix contexts Keep the queries specific on a given topic. Don't ask about multiple concepts at once, rather, do multiple queries.
2 changes: 1 addition & 1 deletion .github/workflows/ci-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
asdf plugin add dojo https://github.com/dojoengine/asdf-dojo
asdf install dojo 1.5.1
asdf global dojo 1.5.1
cd contracts && sozo test
cd pixelaw_testing && sozo test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ contracts/out
contracts/db
contracts/target
contracts/manifest_dev.json
contracts/.vscode/mcp.json

*.keystore.json
112 changes: 112 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

### Build and Test
```bash
make build # Build contracts using sozo
make test # Run contract tests with sozo
cd pixelaw_testing && sozo test # Run tests from testing package
```

### Development Environment
```bash
docker compose up -d # Start Keiko (includes Katana RPC, Torii indexer, dashboard)
docker compose down # Stop Keiko
make shell # Access running Keiko container shell
```

### Docker Operations
```bash
make docker_build # Build Docker image (requires .account file)
make docker_run # Run Docker container with ports 3000, 5050, 8080
make docker_bash # Run Docker container with bash shell
```

### Contract Development
```bash
cd contracts
sozo build # Build contracts
sozo migrate apply # Deploy contracts to running Katana
scarb run init # Initialize deployed contracts
```

### Testing-Specific Commands
```bash
cd pixelaw_testing
sozo build # Build test contracts
sozo test # Run comprehensive test suite
```

## Architecture

### Core Concepts
- **Pixel World**: 2D Cartesian plane where each position (x,y) represents a Pixel
- **Pixel Properties**: position, app, color, owner, text, alert, timestamp
- **Apps**: Define pixel behavior and interactions (one app per pixel)
- **App2App**: Controlled interactions between different apps
- **Queued Actions**: Future actions that can be scheduled during execution

### Technology Stack
- **Cairo 2.10.1**: Smart contract language for Starknet
- **Dojo Framework 1.5.0**: ECS-based blockchain game development framework
- **Starknet 2.10.1**: Layer 2 blockchain platform
- **Scarb 2.10.1**: Package manager and build tool

### Project Structure
```
contracts/ # Main Cairo smart contracts
├── src/core/ # Core actions, events, models, utils
├── src/apps/ # Default apps (house, paint, player, snake)
├── Scarb.toml # Main package configuration
└── Scarb_deploy.toml # Deployment configuration

pixelaw_testing/ # Dedicated testing package
├── src/tests/ # Comprehensive test suite
└── Scarb.toml # Testing package configuration

docker/ # Docker development configuration
scripts/ # Release and upgrade scripts
```

### Default Apps
- **Paint**: Color manipulation (`put_color`, `remove_color`, `put_fading_color`)
- **Snake**: Classic snake game with pixel collision detection
- **Player**: Player management and registration
- **House**: Building/housing system with area management

### Core Systems
- **Actions**: Define pixel behavior and state transitions
- **Models**: ECS components for game state (Pixel, Area, QueueItem, App, etc.)
- **Queue System**: Scheduled actions for future execution
- **Permission System**: App-based permissions for pixel property updates
- **Area Management**: Spatial organization using RTree data structure

### Development Tools
- **Katana**: Local Starknet development node (port 5050)
- **Torii**: World state indexer and GraphQL API (port 8080)
- **Keiko**: Combined development container with dashboard (port 3000)
- **Sozo**: Dojo CLI for building, testing, and deployment

### Key Configuration Files
- `contracts/Scarb.toml`: Main package with Dojo dependencies
- `pixelaw_testing/Scarb.toml`: Testing package with test dependencies
- `docker-compose.yml`: Keiko development environment
- `VERSION`: Core version (0.7.7)
- `DOJO_VERSION`: Dojo version (1.5.0)

### Testing Strategy
- Unit tests embedded in source files using `#[cfg(test)]`
- Integration tests in dedicated `pixelaw_testing` package
- Comprehensive test coverage for all apps and core functionality
- Tests organized by component (area, interop, pixel_area, queue, etc.)

### Development Guidelines
- Follow Cairo naming conventions (snake_case for functions, PascalCase for types)
- Use ECS patterns with Dojo components and systems
- Implement proper error handling with detailed error messages
- Write tests for all new functionality
- Use Cairo Coder MCP for Cairo-specific development tasks
- Always run `scarb build` after writing Cairo code to ensure compilation
5 changes: 4 additions & 1 deletion contracts/dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ world_address = "0x06187e6ecbeba16f0ca4cbf17ea3887ff4abad114d0e345b5d6987edaf200
"pixelaw-SnakeSegment" = ["pixelaw-snake_actions"]
"pixelaw-Player" = ["pixelaw-player_actions"]
"pixelaw-PositionPlayer" = ["pixelaw-player_actions"]
"pixelaw-House" = ["pixelaw-house_actions"]
"pixelaw-PlayerHouse" = ["pixelaw-house_actions"]

[migration]
order_inits=["pixelaw-actions","pixelaw-snake_actions","pixelaw-paint_actions","pixelaw-player_actions"]
order_inits=["pixelaw-actions","pixelaw-snake_actions","pixelaw-paint_actions","pixelaw-player_actions","pixelaw-house_actions"]

[init_call_args]
"pixelaw-actions" = []
"pixelaw-snake_actions" = []
"pixelaw-paint_actions" = []
"pixelaw-player_actions" = []
"pixelaw-house_actions" = []
1 change: 1 addition & 0 deletions contracts/src/apps.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod house;
pub mod paint;
pub mod player;
pub mod snake;
Loading
Loading