-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup cairo / starknet (#1490)
Co-authored-by: hieu.ha <[email protected]> Co-authored-by: ๖ۣۜDadidou <[email protected]>
- Loading branch information
1 parent
30e9edd
commit 5a99dd5
Showing
45 changed files
with
4,455 additions
and
86 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,40 @@ | ||
name: Cairo | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
merge_group: | ||
|
||
jobs: | ||
check-cairo: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: foundry-rs/setup-snfoundry@v4 | ||
- uses: software-mansion/setup-scarb@v1 | ||
with: | ||
scarb-version: "2.9.2" | ||
|
||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: wasm32-unknown-unknown | ||
|
||
- name: Install cairo-lint | ||
run: cargo install scarb-cairo-lint --git https://github.com/software-mansion/cairo-lint | ||
|
||
- name: Format | ||
run: make fmt.cairo | ||
|
||
- name: Lint | ||
run: make lint.cairo | ||
|
||
- name: Test | ||
run: make test.cairo | ||
|
||
- name: Build | ||
run: make build.cairo | ||
|
||
- name: Check diff | ||
run: git diff --exit-code |
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 |
---|---|---|
|
@@ -112,3 +112,7 @@ cypress/screenshots | |
# multi-app | ||
/app-selector.js | ||
/app.config.js | ||
|
||
# starknet / cairo | ||
cairo/keystore.json | ||
.cairo |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
{ | ||
"version": 1, | ||
"variant": { | ||
"type": "open_zeppelin", | ||
"version": 1, | ||
"public_key": "0x5865f50c819ded17adf5e75af231419c458987526583d0e7d03fa22b577bd3f", | ||
"legacy": false | ||
}, | ||
"deployment": { | ||
"status": "deployed", | ||
"class_hash": "0x4a444ef8caf8fa0db05da60bf0ad9bae264c73fa7e32c61d245406f5523174b", | ||
"address": "0x5592f41259100b2e67112545aa55f1c93007ea2a7fab02132d75fa69f268b5d" | ||
} | ||
} |
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 @@ | ||
target | ||
.snfoundry_cache/ |
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,24 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "snforge_scarb_plugin" | ||
version = "0.35.1" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:1b6d50abc7f306a06abf90649bcd60a3bc1cdf6d0dc21a9725c71b014a334bab" | ||
|
||
[[package]] | ||
name = "snforge_std" | ||
version = "0.35.1" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:e25cbeb9cbed6da8e14ab19ad0e7c1d888055dfee62978a845ce669cfaba5d93" | ||
dependencies = [ | ||
"snforge_scarb_plugin", | ||
] | ||
|
||
[[package]] | ||
name = "todo_list" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"snforge_std", | ||
] |
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,49 @@ | ||
[package] | ||
name = "todo_list" | ||
version = "0.1.0" | ||
edition = "2024_07" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] | ||
starknet = "2.9.2" | ||
|
||
[dev-dependencies] | ||
snforge_std = "0.35.1" | ||
assert_macros = "2.9.2" | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[scripts] | ||
test = "snforge test" | ||
|
||
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/scarb-toml.html for more information | ||
|
||
# [tool.snforge] # Define `snforge` tool section | ||
# exit_first = true # Stop tests execution immediately upon the first failure | ||
# fuzzer_runs = 1234 # Number of runs of the random fuzzer | ||
# fuzzer_seed = 1111 # Seed for the random fuzzer | ||
|
||
# [[tool.snforge.fork]] # Used for fork testing | ||
# name = "SOME_NAME" # Fork name | ||
# url = "http://your.rpc.url" # Url of the RPC provider | ||
# block_id.tag = "latest" # Block to fork from (block tag) | ||
|
||
# [[tool.snforge.fork]] | ||
# name = "SOME_SECOND_NAME" | ||
# url = "http://your.second.rpc.url" | ||
# block_id.number = "123" # Block to fork from (block number) | ||
|
||
# [[tool.snforge.fork]] | ||
# name = "SOME_THIRD_NAME" | ||
# url = "http://your.third.rpc.url" | ||
# block_id.hash = "0x123" # Block to fork from (block hash) | ||
|
||
# [profile.dev.cairo] # Configure Cairo compiler | ||
# unstable-add-statements-code-locations-debug-info = true # Should be used if you want to use coverage | ||
# unstable-add-statements-functions-debug-info = true # Should be used if you want to use coverage/profiler | ||
# inlining-strategy = "avoid" # Should be used if you want to use coverage | ||
|
||
# [features] # Used for conditional compilation | ||
# enable_for_tests = [] # Feature name and list of other features that should be enabled with it |
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,11 @@ | ||
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html | ||
# and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information | ||
|
||
# [sncast.default] # Define a profile name | ||
# url = "https://free-rpc.nethermind.io/sepolia-juno/v0_7" # Url of the RPC provider | ||
# accounts-file = "../account-file" # Path to the file with the account data | ||
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions | ||
# keystore = "~/keystore" # Path to the keystore file | ||
# wait-params = { timeout = 300, retry-interval = 10 } # Wait for submitted transaction parameters | ||
# block-explorer = "StarkScan" # Block explorer service used to display links to transaction details | ||
# show-explorer-links = true # Print links pointing to pages with transaction details in the chosen block explorer |
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,54 @@ | ||
#[derive(Drop, Serde, Copy)] | ||
pub struct Todo { | ||
pub title: felt252, | ||
pub done: bool, | ||
} | ||
|
||
#[starknet::interface] | ||
pub trait ITodoList<TContractState> { | ||
fn add_todo(ref self: TContractState, title: felt252); | ||
fn set_todo_done(ref self: TContractState, index: u64); | ||
fn get_todos(self: @TContractState) -> Array<Todo>; | ||
} | ||
|
||
#[starknet::contract] | ||
mod TodoList { | ||
use core::starknet::storage::{ | ||
StoragePointerWriteAccess, StoragePointerReadAccess, VecTrait, MutableVecTrait, Vec, | ||
}; | ||
use super::Todo; | ||
|
||
#[storage] | ||
struct Storage { | ||
todos_title: Vec<felt252>, | ||
todos_done: Vec<bool>, | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl TodoListImpl of super::ITodoList<ContractState> { | ||
fn add_todo(ref self: ContractState, title: felt252) { | ||
assert(title != '', 'Title cannot be empty'); | ||
|
||
self.todos_title.append().write(title); | ||
self.todos_done.append().write(false); | ||
} | ||
|
||
fn set_todo_done(ref self: ContractState, index: u64) { | ||
// assert(index < self.todos_title.len(), 'Index out of bounds'); | ||
|
||
self.todos_done.at(index).write(true); | ||
} | ||
|
||
fn get_todos(self: @ContractState) -> Array<Todo> { | ||
let mut result = ArrayTrait::new(); | ||
|
||
for i in 0..self.todos_title.len() { | ||
let title = self.todos_title.at(i).read(); | ||
let done = self.todos_done.at(i).read(); | ||
result.append(Todo { title, done }); | ||
}; | ||
|
||
result | ||
} | ||
} | ||
} |
Oops, something went wrong.