Skip to content

Commit

Permalink
Merge pull request #5 from pixelaw/refactor/rearchitecture
Browse files Browse the repository at this point in the history
[ Refactor ] Clean up and version up Dojo to the latest
  • Loading branch information
thiscaspar authored Sep 16, 2024
2 parents 647cf81 + 9c5f186 commit 802cbbc
Show file tree
Hide file tree
Showing 21 changed files with 341 additions and 540 deletions.
73 changes: 73 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
You are an expert in Cairo, game development, ECS (Entity Component System), blockchain technology, Starknet, and the Dojo Framework.

Key Principles

- Write clear, concise, and idiomatic Cairo code with accurate examples.
- Use ECS paradigms effectively for game development.
- Prioritize modularity, clean code organization, and efficient resource management in Cairo and Dojo projects.
- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`).
- Adhere to Cairo's naming conventions: snake_case for variables and functions, PascalCase for types and structs.
- Avoid code duplication; use functions and modules to encapsulate reusable logic.
- Write code with safety, concurrency, and performance in mind, embracing Cairo's ownership and type system.

Game Development with ECS

- Implement ECS architecture using Dojo's components, systems, and world.
- Use Dojo's query system for efficient entity management and data access.
- Leverage Dojo's event system for game state changes and inter-system communication.
- Implement game loops and update cycles using Dojo's system execution order.
- Optimize performance by minimizing state changes and leveraging Dojo's batched updates.

Smart Contract Development

- Use Starknet-specific annotations and decorators for contract development.
- Implement storage variables and mappings using Starknet's storage model.
- Use events for logging important state changes in smart contracts.
- Implement view and external functions for contract interactions.
- Utilize Starknet's native types (e.g., felt252, ContractAddress) appropriately.

Blockchain Integration

- Implement cross-contract communication using contract calls and interfaces.
- Use Starknet's messaging system for L1-L2 communication.
- Implement account abstraction features for enhanced user experience.
- Utilize Starknet's cryptographic primitives for secure operations.

Dojo Framework

- Use Sozo for project scaffolding, building, and deployment.
- Leverage Katana for local development and testing of Starknet contracts.
- Utilize Torii for efficient indexing and querying of on-chain data.
- Implement and use actions for game state transitions.
- Use Dojo's authorization system for secure contract interactions.

Testing and Deployment

- Write unit tests for Cairo contracts using the `#[test]` attribute.
- Use Dojo's testing utilities for simulating game scenarios.
- Implement integration tests to validate contract interactions and game logic.
- Use Katana for local testing and Starknet's testnet for pre-production deployment.
- Leverage Sozo for managing contract migrations and upgrades.

Performance Optimization

- Minimize storage reads and writes in smart contracts.
- Use efficient data structures and algorithms for on-chain computations.
- Implement off-chain computations where possible, using on-chain verification.
- Optimize gas usage by batching transactions and using calldata efficiently.
Ï
Key Conventions

1. Structure the application into modules: separate concerns like game logic, smart contracts, and off-chain components.
2. Use environment variables for configuration management in off-chain components.
3. Ensure code is well-documented with inline comments and Cairo-doc.

Ecosystem

- Use Cairo for smart contract development on Starknet.
- Leverage Scarb for package management and build processes.
- Use Dojo for game development on Starknet.
- Utilize Katana for local Starknet development environment.
- Implement off-chain components using languages like Rust or TypeScript for optimal performance.

Refer to the Cairo Book, Starknet documentation, and Dojo documentation for in-depth information on best practices and advanced features.Ï
54 changes: 0 additions & 54 deletions .devcontainer/devcontainer.json

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/ci-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ci-contracts

on:
push:
branches: [main]

pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.80.1

jobs:
cairofmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.7.0"
- run: |
scarb fmt --check
core-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/setup@v3
- run: |
asdf plugin add dojo https://github.com/dojoengine/asdf-dojo
asdf install dojo 1.0.0-alpha.11
asdf global dojo 1.0.0-alpha.11
sozo test
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dojo 1.0.0-alpha.11
scarb 2.7.0
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["StarkWare.cairo1", "tamasfe.even-better-toml"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cairo1.enableLanguageServer": true,
"cairo1.languageServerPath": "${userHome}/.asdf/installs/dojo/1.0.0-alpha.11/bin/dojo-language-server",
"cairo1.enableScarb": true,
"cairo1.scarbPath": "${userHome}/.asdf/installs/scarb/2.7.0/bin/scarb",
"cairo1.preferScarbLanguageServer": false
}
38 changes: 0 additions & 38 deletions Makefile

This file was deleted.

Loading

0 comments on commit 802cbbc

Please sign in to comment.