Skip to content

Commit

Permalink
feat: cleanup repo
Browse files Browse the repository at this point in the history
  • Loading branch information
posaune0423 committed Sep 16, 2024
1 parent 9527dc9 commit 7affe51
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 208 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.Ï
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
132 changes: 35 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,67 @@
<picture>
<img alt="Dojo logo" align="right" width="100" src="https://avatars.githubusercontent.com/u/140254228?s=200&v=4">
</picture>

<a href="https://twitter.com/0xpixelaw">
<img src="https://img.shields.io/twitter/follow/0xpixelaw?style=social"/>
</a>
<a href="https://github.com/pixelaw/core">
<img src="https://img.shields.io/github/stars/pixelaw/core?style=social"/>
</a>

[![discord](https://img.shields.io/badge/join-pixelaw-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4)

# PixeLAW App Template

Contracts written in Cairo using Dojo to showcase a Pixel World with app interoperability. Its interoperability is made possible with core actions. Apps are any other contracts that are deployed to the Pixel World.

## Development

### Prerequisites
## Prerequisites

- [asdf](https://asdf-vm.com/)
- [scarb](https://docs.swmansion.com/scarb/)
- [dojo](https://github.com/dojoengine/dojo)

### Install asdf
## Install asdf

Follow the asdf installation instructions.

### Install dojo
## Install dojo

```
asdf plugin add dojo https://github.com/dojoengine/asdf-dojo
asdf install dojo 1.0.0-alpha.11
```

### Install scarb
## Install scarb

```
asdf plugin add scarb
asdf install scarb 2.7.0-rc.4
asdf install scarb 2.7.0
```

And after moving into contracts directory, the versions for these libs are set in the .tool-versions file.

## Default Apps

These are apps developed by PixeLAW

## Paint

### Overview

The Paint App is a collection of functions that allow players to manipulate the color of a Pixel.

### Properties

None, Paint is just behavior.

### Behavior

- public `put_color(color)`
- context: position
- both `put_fading_color(color)`
- context: position
- public `remove_color()`
- context: position

## Snake

### Overview
## Running Locally

It it basically the game "snake", but with Pixels not necessarily available to move on/over. It is a player-initialized instance that coordinates pixel's color and text being overriden and reverted (if allowed).
If hitting an unowned Pixel, the snake will move, if Pixel is owned by player, Snake grows, and if Pixel is not owned but it's App allows Snake, it shrinks. In all other cases, Snake dies.
#### Terminal one (Make sure this is running)

### Properties

- position
- color
- text
- direction

### Behavior

- public `spawn(color, text, direction)`
- context: position
- public `turn(snake_id, direction)`
- context: player
- private `move(snake_id)`

## Rock Paper Scissors

### Overview

Each Pixel can contain an instance of the RPS App, where it holds a commitment (rock, paper or scissors) from player1. Any other player can now "join" and submit their move. Player1 can then reveal, the winner is decided then. Winner gains ownership of the losing RPS pixel. In case of a draw, the pixel is reset.
The App is also tracking score for each Player.

### Global Properties

- player+wins

### Game-based Properties

- player1
- player2

### Behavior

- create (position, player1, commit1)
- join (position, player2, move2)
- finish (position, move1, salt1)
- reset (position)
```bash
# Run Katana
katana --disable-fee --allowed-origins "*"
```

## CommitReveal inputs
#### Terminal two

### Param of the action
```bash
# Build the example
sozo build

- (Hashed Commit)
- parametername of action has structure: "PREFIX_TYPE_NAME"
- PREFIX is "cr\_"
- TYPE for now is the name of an int, felt or Enum declared in the manifest
- NAME is a chosen name to refer to the param.
- (Value+Salt reveal)
- parametername of action has structure: "PREFIX_NAME"
- PREFIX shall always be "rv\_"
- NAME is the same name user during sending the commit
# Migrate the example
sozo migrate apply

### Clientside functioning
# Initialize the pixelaw app
scarb run init_auth

- If client finds a param starting with "cr\_"
- It will prompt user for a param with TYPE
- example:
- The game RPS needs player1 to choose one option, but only send the hashedcommit
- Then, during a next stage of the game, the plaintext move and the salt will be requested
- The challenge is that the UI needsto be capable of doing this without knowing about the specific application. Reveal/Commit is a feature of the platform.
- Commit
- RpsMove is an enum with 3 fields, so ui presents user with 3 choices
- UI stores this clientside related to the pixel/app
- UI then hashes this with a salt, and also stores the salt with the choice
- UI then calls the functions with only the hash value
- Reveal
- there will be 2 params: "rv_NAME" (the actual param) and "rs_NAME" (the used salt)
# Start Torii
torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 --allowed-origins "*"
```
2 changes: 2 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ source = "git+https://github.com/dojoengine/dojo?rev=f15def33#f15def330c0d099e79
name = "myapp"
version = "0.0.0"
dependencies = [
"dojo",
"pixelaw",
]

[[package]]
name = "pixelaw"
version = "0.3.50"
source = "git+https://github.com/pixelaw/core?tag=v0.3.50#78abcff1835740411f785b65e84941c3f7ee59b6"
dependencies = [
"dojo",
]
32 changes: 28 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@ version = "0.0.0"
sierra-replace-ids = true

[dependencies]
pixelaw = { path = "/Users/asumayamada/Private/pixelaw/core/contracts" }
# pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.50" }
pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.50" }
# Added explicitly for https://github.com/dojoengine/dojo/issues/2430
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" }

[[target.dojo]]
build-external-contracts = []
build-external-contracts = [
"pixelaw::core::models::pixel::pixel",
"pixelaw::core::models::pixel::Pixel",
"pixelaw::core::models::pixel::PixelUpdate",
"pixelaw::core::models::queue::queue_item",
"pixelaw::core::models::registry::app",
"pixelaw::core::models::registry::app_name",
"pixelaw::core::models::registry::app_user",
"pixelaw::core::models::registry::app_instruction",
"pixelaw::core::models::registry::instruction",
"pixelaw::core::models::registry::core_actions_address",
"pixelaw::core::models::permissions::permissions",
"pixelaw::core::utils::get_core_actions",
"pixelaw::core::utils::Direction",
"pixelaw::core::utils::Position",
"pixelaw::core::utils::DefaultParameters",
"pixelaw::core::actions::actions",
"pixelaw::core::actions::IActionsDispatcher",
"pixelaw::core::actions::IActionsDispatcherTrait",
]

[tool.fmt]
sort-module-level-items = true
sort-module-level-items = true


[scripts]
init_auth = "./scripts/init_auth.sh"
49 changes: 0 additions & 49 deletions scripts/default_auth.sh

This file was deleted.

Loading

0 comments on commit 7affe51

Please sign in to comment.