-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
# Conflicts: # .devcontainer/devcontainer.json # Scarb.lock # Scarb.toml # dojo_dev.toml
- Loading branch information
Showing
19 changed files
with
285 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Ï |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.12 | ||
asdf global dojo 1.0.0-alpha.12 | ||
sozo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dojo 1.0.0-alpha.12 | ||
scarb 2.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["StarkWare.cairo1", "tamasfe.even-better-toml"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.12/bin/dojo-language-server", | ||
"cairo1.enableScarb": true, | ||
"cairo1.scarbPath": "${userHome}/.asdf/installs/scarb/2.7.0/bin/scarb", | ||
"cairo1.preferScarbLanguageServer": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,105 @@ | ||
# PixeLAW App template | ||
## Documents | ||
For additional step-by-step explanations on how to build and deploy your own PixeLAW app follow along [PixeLAW book](https://pixelaw.github.io/book/getting-started/quick-start.html)! | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://avatars.githubusercontent.com/u/140254228?s=200&v=4"> | ||
<img alt="Dojo logo" align="right" width="100" src="https://avatars.githubusercontent.com/u/140254228?s=200&v=4"> | ||
</picture> | ||
|
||
<a href="https://x.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://t.co/jKDjNbFdZ5) | ||
|
||
# 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. | ||
|
||
## Prerequisites | ||
### Dojo | ||
PixeLAW is built on top of Dojo. Refer to this [page](https://book.dojoengine.org/getting-started/quick-start) to get it installed. | ||
|
||
## Getting started | ||
### Clone this repository | ||
#### Via GitHub | ||
Use this template to create a new repository or clone this repository locally. | ||
- [asdf](https://asdf-vm.com/) | ||
- [scarb](https://docs.swmansion.com/scarb/) | ||
- [dojo](https://github.com/dojoengine/dojo) | ||
|
||
## Run this code | ||
### Run the tests made for this app | ||
````console | ||
sozo test | ||
```` | ||
## Install asdf | ||
|
||
### Local Development | ||
#### Run [Pixelaw/core](https://github.com/pixelaw/core) | ||
We are using [devcontainer](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) environments. Please open this code with vscode and launch the container with devcontainer. | ||
Follow the asdf installation instructions. | ||
|
||
This is the easiest way to get PixeLAW core up and running in http://localhost:3000. We recommend you to use incognito mode to browse. | ||
## Install dojo | ||
|
||
``` | ||
asdf plugin add dojo https://github.com/dojoengine/asdf-dojo | ||
asdf install dojo 1.0.0-alpha.11 | ||
``` | ||
|
||
--- | ||
### Check the status | ||
If you succesfully start up PixeLAW core, it will take a while for all the core contracts to get deployed | ||
and start running. Wait until http://localhost:3000/manifests/core stops returning NOT FOUND. To check if you can | ||
start deploying your app, use the following script (this will print out "Ready for app deployment" when the core | ||
contracts have finished initialization): | ||
## Install scarb | ||
|
||
````console | ||
scarb run ready_for_deployment | ||
```` | ||
``` | ||
asdf plugin add scarb | ||
asdf install scarb 2.7.0 | ||
``` | ||
|
||
After which you can start deploying your app onto your local PixeLAW via: | ||
And after moving into contracts directory, the versions for these libs are set in the .tool-versions file. | ||
|
||
--- | ||
### Build and Deploy your contracts locally | ||
#### Building | ||
````console | ||
sozo build | ||
```` | ||
|
||
#### Deploying your contracts | ||
This will deploy your app to the local PixeLAW using sozo migrate. | ||
````console | ||
sozo migrate apply --name pixelaw | ||
```` | ||
|
||
#### Initializing your contracts | ||
This will grant writer permission to your app for any custom models made. | ||
````console | ||
scarb run initialize | ||
```` | ||
|
||
#### Uploading your manifest | ||
````console | ||
scarb run upload_manifest | ||
```` | ||
|
||
--- | ||
### Deploying to Demo | ||
Deploying to demo is almost the same as local development. The only difference is needing | ||
the RPC_URL of the Demo environment, the DEMO_URL (NOTE: this must end in a slash i.e. '/') | ||
of the Demo App to upload your manifest to, and the world name. Both URLs and world name can be provided by us. | ||
Please reach out through discord. Currently, sozo checks first if an environment variable was set in Scarb.toml for | ||
rpc-url. So, comment that out before beginning with the following steps. | ||
|
||
#### Build your contracts | ||
````console | ||
## Running Locally | ||
|
||
#### Terminal one (Make sure this is running) | ||
|
||
```bash | ||
# Run Katana | ||
katana --disable-fee --allowed-origins "*" | ||
``` | ||
|
||
#### Terminal two | ||
|
||
```bash | ||
# Build the example | ||
sozo build | ||
```` | ||
|
||
#### Deploy your contracts | ||
This will deploy your app to the local PixeLAW using sozo migrate. | ||
````console | ||
sozo migrate apply --name <replace-this-with-provided-world-name> --rpc-url <replace-this-with-provided-rpc-url> | ||
```` | ||
# Migrate the example | ||
sozo migrate apply | ||
|
||
# Initialize the pixelaw app | ||
scarb run init_auth | ||
|
||
# Start Torii | ||
torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 --allowed-origins "*" | ||
``` | ||
|
||
### How to deploy | ||
|
||
#### Initializing your contracts | ||
This will grant writer permission to your app for any custom models made. | ||
````console | ||
scarb run initialize <replace-this-with-provided-rpc-url> | ||
```` | ||
you can deploy your app to our katana testnet by running the following commands: | ||
|
||
#### Uploading your manifest | ||
````console | ||
scarb run upload_manifest <replace-this-with-provided-demo-url> | ||
```` | ||
```bash | ||
# Deploy the pixelaw app | ||
sozo build -P release | ||
sozo migrate apply -P release | ||
``` | ||
|
||
|
||
### FAQs | ||
#### error when deploying to rpc-url | ||
## Troubleshooting | ||
|
||
Please check the `[[tool.dojo.env]]` in your `Sarb.toml`. You have to modify it correctly. | ||
If you want to use latest dojo version, you need to clone core by yourself and modify the path in `Scarb.toml` file. | ||
|
||
Also, please verify `account_address` and `private_key`. | ||
1. Clone core repo | ||
```bash | ||
git clone https://github.com/pixelaw/core | ||
``` | ||
|
||
For dojo problems, please check the version is correct. | ||
2. Modify the path in `Scarb.toml` file | ||
```Scarb.toml | ||
pixelaw = { path = "../pixelaw/core/contracts" } | ||
``` | ||
|
||
3. Modify version in `Scarb.toml` file in core repo | ||
```Scarb.toml | ||
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" } | ||
``` | ||
|
||
4. Build and run core | ||
```bash | ||
cd contracts | ||
sozo build | ||
sozo migrate apply | ||
``` |
Oops, something went wrong.