Skip to content

Commit

Permalink
✨ Create missing contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Nov 25, 2024
1 parent 9596534 commit 2cc5970
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 85 deletions.
17 changes: 17 additions & 0 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "achievement"
version = "0.0.0"
dependencies = [
"dojo",
]

[[package]]
name = "arcade"
version = "0.0.0"
dependencies = [
"achievement",
"controller",
"dojo",
"dojo_cairo_test",
"provider",
"registry",
"society",
]

[[package]]
Expand Down Expand Up @@ -53,3 +62,11 @@ version = "0.0.0"
dependencies = [
"dojo",
]

[[package]]
name = "society"
version = "0.0.0"
dependencies = [
"dojo",
"registry",
]
11 changes: 9 additions & 2 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ dev = "sozo clean && sozo build --typescript && sozo migrate plan && sozo migrat

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.1" }
achievement = { path = ".." }
controller = { path = ".." }
provider = { path = ".." }
registry = { path = ".." }
society = { path = ".." }
starknet = "2.8.4"
cairo_test = "2.8.4"

Expand All @@ -23,16 +25,21 @@ dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.1" }
[[target.starknet-contract]]
build-external-contracts = [
"dojo::world::world_contract::world",
"achievement::events::index::e_TrophyPinning",
"controller::models::index::m_Account",
"controller::models::index::m_Controller",
"controller::models::index::m_Member",
"controller::models::index::m_Signer",
"controller::models::index::m_Team",
"provider::models::index::m_Deployment",
"provider::models::index::m_Factory",
"provider::models::index::m_Team",
"provider::models::index::m_Teammate",
"registry::models::index::m_Access",
"registry::models::index::m_Achievement",
"registry::models::index::m_Game",
"society::models::index::m_Alliance",
"society::models::index::m_Guild",
"society::models::index::m_Member",
"society::events::index::e_Follow",
]

[profile.slot]
2 changes: 2 additions & 0 deletions contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod constants;

mod systems {
mod achievement;
mod controller;
mod registry;
mod slot;
mod society;
}
74 changes: 74 additions & 0 deletions contracts/src/systems/achievement.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Interfaces

#[starknet::interface]
trait IAchievement<TContractState> {
fn pin(self: @TContractState, achievement_id: felt252);
fn unpin(self: @TContractState, achievement_id: felt252);
}

// Contracts

#[dojo::contract]
mod Achievement {
// Dojo imports

use dojo::world::WorldStorage;

// Component imports

use achievement::components::pinnable::PinnableComponent;

// Internal imports

use arcade::constants::NAMESPACE;

// Local imports

use super::IAchievement;

// Components

component!(path: PinnableComponent, storage: pinnable, event: PinnableEvent);
impl PinnableInternalImpl = PinnableComponent::InternalImpl<ContractState>;

// Storage

#[storage]
struct Storage {
#[substorage(v0)]
pinnable: PinnableComponent::Storage,
}

// Events

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
PinnableEvent: PinnableComponent::Event,
}

// Implementations

#[abi(embed_v0)]
impl AchievementImpl of IAchievement<ContractState> {
fn pin(self: @ContractState, achievement_id: felt252) {
let world: WorldStorage = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.pinnable.pin(world, caller, achievement_id);
}

fn unpin(self: @ContractState, achievement_id: felt252) {
let world: WorldStorage = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.pinnable.unpin(world, caller, achievement_id);
}
}

#[generate_trait]
impl Private of PrivateTrait {
fn world_storage(self: @ContractState) -> WorldStorage {
self.world(@NAMESPACE())
}
}
}
60 changes: 44 additions & 16 deletions contracts/src/systems/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ mod Registry {
youtube: Option<ByteArray>,
website: Option<ByteArray>,
) {
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self
.registerable
.register(
self.world_storage(),
world,
caller,
world_address,
namespace,
project,
Expand Down Expand Up @@ -186,10 +189,13 @@ mod Registry {
youtube: Option<ByteArray>,
website: Option<ByteArray>,
) {
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self
.registerable
.update(
self.world_storage(),
world,
caller,
world_address,
namespace,
color,
Expand All @@ -206,23 +212,33 @@ mod Registry {
}

fn publish_game(self: @ContractState, world_address: felt252, namespace: felt252) {
self.registerable.publish(self.world_storage(), world_address, namespace);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.registerable.publish(world, caller, world_address, namespace);
}

fn hide_game(self: @ContractState, world_address: felt252, namespace: felt252) {
self.registerable.hide(self.world_storage(), world_address, namespace);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.registerable.hide(world, caller, world_address, namespace);
}

fn whitelist_game(self: @ContractState, world_address: felt252, namespace: felt252) {
self.registerable.whitelist(self.world_storage(), world_address, namespace);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.registerable.whitelist(world, caller, world_address, namespace);
}

fn blacklist_game(self: @ContractState, world_address: felt252, namespace: felt252) {
self.registerable.blacklist(self.world_storage(), world_address, namespace);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.registerable.blacklist(world, caller, world_address, namespace);
}

fn remove_game(self: @ContractState, world_address: felt252, namespace: felt252) {
self.registerable.remove(self.world_storage(), world_address, namespace);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.registerable.remove(world, caller, world_address, namespace);
}

fn register_achievement(
Expand All @@ -232,9 +248,9 @@ mod Registry {
identifier: felt252,
karma: u16,
) {
self
.trackable
.register(self.world_storage(), world_address, namespace, identifier, karma)
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.register(world, caller, world_address, namespace, identifier, karma)
}

fn update_achievement(
Expand All @@ -244,37 +260,49 @@ mod Registry {
identifier: felt252,
karma: u16,
) {
self.trackable.update(self.world_storage(), world_address, namespace, identifier, karma)
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.update(world, caller, world_address, namespace, identifier, karma)
}

fn publish_achievement(
self: @ContractState, world_address: felt252, namespace: felt252, identifier: felt252
) {
self.trackable.publish(self.world_storage(), world_address, namespace, identifier);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.publish(world, caller, world_address, namespace, identifier);
}

fn hide_achievement(
self: @ContractState, world_address: felt252, namespace: felt252, identifier: felt252
) {
self.trackable.hide(self.world_storage(), world_address, namespace, identifier);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.hide(world, caller, world_address, namespace, identifier);
}

fn whitelist_achievement(
self: @ContractState, world_address: felt252, namespace: felt252, identifier: felt252
) {
self.trackable.whitelist(self.world_storage(), world_address, namespace, identifier);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.whitelist(world, caller, world_address, namespace, identifier);
}

fn blacklist_achievement(
self: @ContractState, world_address: felt252, namespace: felt252, identifier: felt252
) {
self.trackable.blacklist(self.world_storage(), world_address, namespace, identifier);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.blacklist(world, caller, world_address, namespace, identifier);
}

fn remove_achievement(
self: @ContractState, world_address: felt252, namespace: felt252, identifier: felt252
) {
self.trackable.remove(self.world_storage(), world_address, namespace, identifier);
let world = self.world_storage();
let caller: felt252 = starknet::get_caller_address().into();
self.trackable.remove(world, caller, world_address, namespace, identifier);
}
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/src/systems/slot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ mod Slot {
impl SlotImpl of ISlot<ContractState> {
fn deploy(self: @ContractState, service: u8, project: felt252, tier: u8,) {
let world = self.world_storage();
self.deployable.deploy(world, service.into(), project, tier.into())
let caller: felt252 = starknet::get_caller_address().into();
self.deployable.deploy(world, caller, service.into(), project, tier.into())
}

fn remove(self: @ContractState, service: u8, project: felt252,) {
let world = self.world_storage();
self.deployable.remove(world, service.into(), project);
let caller: felt252 = starknet::get_caller_address().into();
self.deployable.remove(world, caller, service.into(), project);
}
}

Expand Down
Loading

0 comments on commit 2cc5970

Please sign in to comment.