Skip to content

Commit

Permalink
unruggable_memecoin_quest
Browse files Browse the repository at this point in the history
  • Loading branch information
TAdev0 committed Apr 22, 2024
1 parent 3fa4ac8 commit 6641a73
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
6 changes: 5 additions & 1 deletion onchain/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ use interfaces::{IArtPeace, IArtPeaceDispatcher, IArtPeaceDispatcherTrait, Pixel
mod quests {
pub mod interfaces;
pub mod pixel_quest;
pub mod unruggable_quest;

use interfaces::{IQuest, IPixelQuest, QuestClaimed, IQuestDispatcher, IQuestDispatcherTrait};
use interfaces::{
IQuest, IPixelQuest, IUnruggableQuest, QuestClaimed, IQuestDispatcher,
IQuestDispatcherTrait, IUnruggableMemecoin, IUnruggableMemecoinDispatcher, IUnruggableMemecoinDispatcherTrait
};
}

mod templates {
Expand Down
22 changes: 22 additions & 0 deletions onchain/src/quests/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ pub trait IPixelQuest<TContractState> {
fn is_color(self: @TContractState) -> bool;
fn color(self: @TContractState) -> u8;
}

#[starknet::interface]
pub trait IUnruggableQuest<TContractState> {
fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool;
}

#[starknet::interface]
pub trait IUnruggableMemecoin<TState> {
// ************************************
// * Ownership
// ************************************
fn owner(self: @TState) -> ContractAddress;

// ************************************
// * Additional functions
// ************************************
/// Checks whether token has launched
///
/// # Returns
/// bool: whether token has launched
fn is_launched(self: @TState) -> bool;
}
84 changes: 84 additions & 0 deletions onchain/src/quests/unruggable_quest.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#[starknet::contract]
pub mod UnruggableQuest {
use starknet::{ContractAddress, get_caller_address};
use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait};
use art_peace::quests::{
IQuest, IUnruggableQuest, IUnruggableMemecoinDispatcher, IUnruggableMemecoinDispatcherTrait,
QuestClaimed
};

#[storage]
struct Storage {
art_peace: ContractAddress,
reward: u32,
claimed: LegacyMap<ContractAddress, bool>,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
QuestClaimed: QuestClaimed,
}

#[derive(Drop, Serde)]
pub struct UnruggableQuestInitParams {
pub art_peace: ContractAddress,
pub reward: u32,
}

#[constructor]
fn constructor(ref self: ContractState, init_params: UnruggableQuestInitParams) {
self.art_peace.write(init_params.art_peace);
self.reward.write(init_params.reward);
}

#[abi(embed_v0)]
impl UnruggableQuestImpl of IUnruggableQuest<ContractState> {
fn is_claimed(self: @ContractState, user: ContractAddress) -> bool {
self.claimed.read(user)
}
}

#[abi(embed_v0)]
impl UnruggableQuest of IQuest<ContractState> {
fn get_reward(self: @ContractState) -> u32 {
self.reward.read()
}

fn is_claimable(
self: @ContractState, user: ContractAddress, calldata: Span<felt252>
) -> bool {
if self.claimed.read(user) {
return false;
}

let coin_address_as_felt252: felt252 = *calldata.at(0);
let coin = IUnruggableMemecoinDispatcher {
contract_address: coin_address_as_felt252.try_into().unwrap()
};

if coin.owner() != user {
return false;
}

if coin.is_launched() != true {
return false;
}

true
}

fn claim(ref self: ContractState, user: ContractAddress, calldata: Span<felt252>) -> u32 {
assert(get_caller_address() == self.art_peace.read(), 'Only ArtPeace can claim quests');

assert(self.is_claimable(user, calldata), 'quest not claimable');

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

reward
}
}
}

0 comments on commit 6641a73

Please sign in to comment.