Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements of the Scarb package #26

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.6.3
starknet-foundry 0.20.0
starknet-foundry 0.21.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the Dockerfiles to reflect this change, like here

RUN /bin/bash /root/.local/bin/snfoundryup --version 0.20.0

Either manually change them to 0.21.0 or set up a way for the Dockerfile to properly import the changed value if you'd find that interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-j-roberts will change manually for now if this is ok for you

1 change: 1 addition & 0 deletions onchain/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "art_peace"
version = "0.1.0"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

Expand Down
11 changes: 9 additions & 2 deletions onchain/src/art_peace.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#[starknet::contract]
pub mod ArtPeace {
use starknet::ContractAddress;

use art_peace::{IArtPeace, Pixel};
use art_peace::quests::{IQuestDispatcher, IQuestDispatcherTrait};
use art_peace::quests::interfaces::{IQuestDispatcher, IQuestDispatcherTrait};
use art_peace::templates::component::TemplateStoreComponent;
use art_peace::templates::{ITemplateVerifier, TemplateMetadata};
use art_peace::templates::interfaces::{ITemplateVerifier, TemplateMetadata};

component!(path: TemplateStoreComponent, storage: templates, event: TemplateEvent);

Expand Down Expand Up @@ -242,6 +243,7 @@ pub mod ArtPeace {
colors.append(self.color_palette.read(i));
i += 1;
};

colors
}

Expand Down Expand Up @@ -285,6 +287,7 @@ pub mod ArtPeace {
quests.append(self.daily_quests.read((day_index, i)));
i += 1;
};

quests.span()
}

Expand All @@ -297,6 +300,7 @@ pub mod ArtPeace {
quests.append(self.daily_quests.read((day, i)));
i += 1;
};

quests.span()
}

Expand All @@ -316,6 +320,7 @@ pub mod ArtPeace {
quests.append(self.main_quests.read(i));
i += 1;
};

quests.span()
}

Expand Down Expand Up @@ -381,6 +386,7 @@ pub mod ArtPeace {
};
i += 1;
};

total
}

Expand All @@ -394,6 +400,7 @@ pub mod ArtPeace {
total += self.user_pixels_placed.read((day, user, i));
i += 1;
};

total
}

Expand Down
4 changes: 2 additions & 2 deletions onchain/src/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[derive(Drop, Serde, starknet::Store)]
pub struct Pixel {
// Color index in the palette
color: u8,
pub color: u8,
// The person that placed the pixel
owner: starknet::ContractAddress,
pub owner: starknet::ContractAddress,
}

// TODO: Tests for all
Expand Down
11 changes: 6 additions & 5 deletions onchain/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ use art_peace::ArtPeace;
use interface::{IArtPeace, IArtPeaceDispatcher, IArtPeaceDispatcherTrait, Pixel};

mod quests {
pub mod interface;
pub mod interfaces;
mod pixel_quest;

use interface::{IQuest, QuestClaimed, IQuestDispatcher, IQuestDispatcherTrait};
use interfaces::{IQuest, IQuestDispatcher, IQuestDispatcherTrait};
use pixel_quest::PixelQuest::QuestClaimed;
}

mod templates {
pub mod interface;
mod component;
pub mod interfaces;
pub mod component;

use interface::{
use interfaces::{
TemplateMetadata, ITemplateVerifier, ITemplateStoreDispatcher,
ITemplateStoreDispatcherTrait, ITemplateVerifierDispatcher, ITemplateVerifierDispatcherTrait
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use starknet::ContractAddress;

#[derive(Drop, starknet::Event)]
pub struct QuestClaimed {
TAdev0 marked this conversation as resolved.
Show resolved Hide resolved
pub user: ContractAddress,
pub reward: u32,
}

#[starknet::interface]
pub trait IQuest<TContractState> {
// Return the reward for the quest.
fn get_reward(self: @TContractState) -> u32;
// Return if the user can claim the quest.
// Return true if the user can claim the quest.
fn is_claimable(self: @TContractState, user: ContractAddress) -> bool;
// Claim the quest.
fn claim(ref self: TContractState, user: ContractAddress) -> u32;
}

#[starknet::interface]
pub trait IPixelQuest<TContractState> {
fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool;
fn get_pixels_needed(self: @TContractState) -> u32;
fn is_daily(self: @TContractState) -> bool;
fn claim_day(self: @TContractState) -> u32;
}
35 changes: 18 additions & 17 deletions onchain/src/quests/pixel_quest.cairo
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#[starknet::interface]
trait IPixelQuest<TContractState> {
fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool;
fn get_pixels_needed(self: @TContractState) -> u32;
fn is_daily(self: @TContractState) -> bool;
fn claim_day(self: @TContractState) -> u32;
}

#[starknet::contract]
mod PixelQuest {
pub mod PixelQuest {
use starknet::{ContractAddress, get_caller_address};
use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait};
use art_peace::quests::{IQuest, QuestClaimed};
use super::IPixelQuest;
use art_peace::quests::interfaces::{IQuest, IPixelQuest};

#[storage]
struct Storage {
Expand All @@ -24,6 +15,12 @@ mod PixelQuest {
claim_day: u32,
}

#[derive(Drop, starknet::Event)]
pub struct QuestClaimed {
pub user: ContractAddress,
pub reward: u32,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Expand All @@ -49,34 +46,36 @@ mod PixelQuest {
#[abi(embed_v0)]
impl PixelQuestImpl of IPixelQuest<ContractState> {
fn is_claimed(self: @ContractState, user: ContractAddress) -> bool {
return self.claimed.read(user);
self.claimed.read(user)
}

fn get_pixels_needed(self: @ContractState) -> u32 {
return self.pixels_needed.read();
self.pixels_needed.read()
}

fn is_daily(self: @ContractState) -> bool {
return self.is_daily.read();
self.is_daily.read()
}

fn claim_day(self: @ContractState) -> u32 {
return self.claim_day.read();
self.claim_day.read()
}
}

// TODO: Test all
#[abi(embed_v0)]
impl PixelQuest of IQuest<ContractState> {
fn get_reward(self: @ContractState) -> u32 {
return self.reward.read();
self.reward.read()
}

fn is_claimable(self: @ContractState, user: ContractAddress) -> bool {
let art_peace = self.art_peace.read();

if self.claimed.read(user) {
return false;
}

if self.is_daily.read() {
// Daily Pixel Quest
let day = art_peace.get_day();
Expand All @@ -97,14 +96,16 @@ mod PixelQuest {
get_caller_address() == self.art_peace.read().contract_address,
'Only ArtPeace can claim quests'
);

if !self.is_claimable(user) {
return 0;
}

self.claimed.write(user, true);
let reward = self.reward.read();
self.emit(QuestClaimed { user: user, reward: reward });
return reward;

reward
}
}
}
15 changes: 8 additions & 7 deletions onchain/src/templates/component.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[starknet::component]
mod TemplateStoreComponent {
use art_peace::templates::interface::{ITemplateStore, TemplateMetadata};
pub mod TemplateStoreComponent {
use art_peace::templates::interfaces::{ITemplateStore, TemplateMetadata};

#[storage]
struct Storage {
Expand All @@ -13,7 +13,7 @@ mod TemplateStoreComponent {

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
pub enum Event {
TemplateAdded: TemplateAdded,
TemplateCompleted: TemplateCompleted,
}
Expand All @@ -37,18 +37,19 @@ mod TemplateStoreComponent {
TContractState, +HasComponent<TContractState>
> of ITemplateStore<ComponentState<TContractState>> {
fn get_templates_count(self: @ComponentState<TContractState>) -> u32 {
return self.templates_count.read();
self.templates_count.read()
}

fn get_template(
self: @ComponentState<TContractState>, template_id: u32
) -> TemplateMetadata {
return self.templates.read(template_id);
self.templates.read(template_id)
}

fn get_template_hash(self: @ComponentState<TContractState>, template_id: u32) -> felt252 {
let metadata: TemplateMetadata = self.templates.read(template_id);
return metadata.hash;

metadata.hash
}

// TODO: Return idx of the template?
Expand All @@ -62,7 +63,7 @@ mod TemplateStoreComponent {
}

fn is_template_complete(self: @ComponentState<TContractState>, template_id: u32) -> bool {
return self.completed_templates.read(template_id);
self.completed_templates.read(template_id)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[derive(Drop, Copy, Serde, starknet::Store)]
pub struct TemplateMetadata {
hash: felt252,
position: u128,
width: u128,
height: u128,
reward: u256,
reward_token: starknet::ContractAddress
pub hash: felt252,
pub position: u128,
pub width: u128,
pub height: u128,
pub reward: u256,
pub reward_token: starknet::ContractAddress
}

#[starknet::interface]
Expand Down
2 changes: 1 addition & 1 deletion onchain/src/tests/art_peace.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait};
use art_peace::ArtPeace::InitParams;
use art_peace::templates::{
use art_peace::templates::interfaces::{
ITemplateStoreDispatcher, ITemplateStoreDispatcherTrait, ITemplateVerifierDispatcher,
ITemplateVerifierDispatcherTrait, TemplateMetadata
};
Expand Down