From 6641a73aafa386c5ce11a8ec49944bd2a3affc9a Mon Sep 17 00:00:00 2001 From: TAdev0 Date: Mon, 22 Apr 2024 20:54:56 +0200 Subject: [PATCH] unruggable_memecoin_quest --- onchain/src/lib.cairo | 6 +- onchain/src/quests/interfaces.cairo | 22 ++++++ onchain/src/quests/unruggable_quest.cairo | 84 +++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 onchain/src/quests/unruggable_quest.cairo diff --git a/onchain/src/lib.cairo b/onchain/src/lib.cairo index 5c6a3325..6f1969ea 100644 --- a/onchain/src/lib.cairo +++ b/onchain/src/lib.cairo @@ -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 { diff --git a/onchain/src/quests/interfaces.cairo b/onchain/src/quests/interfaces.cairo index 5010679a..7d200194 100644 --- a/onchain/src/quests/interfaces.cairo +++ b/onchain/src/quests/interfaces.cairo @@ -26,3 +26,25 @@ pub trait IPixelQuest { fn is_color(self: @TContractState) -> bool; fn color(self: @TContractState) -> u8; } + +#[starknet::interface] +pub trait IUnruggableQuest { + fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool; +} + +#[starknet::interface] +pub trait IUnruggableMemecoin { + // ************************************ + // * 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; +} diff --git a/onchain/src/quests/unruggable_quest.cairo b/onchain/src/quests/unruggable_quest.cairo new file mode 100644 index 00000000..50cad795 --- /dev/null +++ b/onchain/src/quests/unruggable_quest.cairo @@ -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, + } + + #[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 { + fn is_claimed(self: @ContractState, user: ContractAddress) -> bool { + self.claimed.read(user) + } + } + + #[abi(embed_v0)] + impl UnruggableQuest of IQuest { + fn get_reward(self: @ContractState) -> u32 { + self.reward.read() + } + + fn is_claimable( + self: @ContractState, user: ContractAddress, calldata: Span + ) -> 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) -> 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 + } + } +} +