Skip to content

Commit

Permalink
Merge branch 'main' into ft_add_template_quest
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 authored Apr 23, 2024
2 parents a9698d3 + e7ce8c1 commit ce19dd8
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,42 @@
"contributions": [
"code"
]
},
{
"login": "fishonamos",
"name": "Fishon Amos",
"avatar_url": "https://avatars.githubusercontent.com/u/43862685?v=4",
"profile": "https://fishonsnote.medium.com/",
"contributions": [
"code"
]
},
{
"login": "Xaxxoo",
"name": "Xaxxoo",
"avatar_url": "https://avatars.githubusercontent.com/u/51526246?v=4",
"profile": "https://github.com/Xaxxoo",
"contributions": [
"code"
]
},
{
"login": "manoahLinks",
"name": "Mano.dev",
"avatar_url": "https://avatars.githubusercontent.com/u/100848212?v=4",
"profile": "https://github.com/manoahLinks",
"contributions": [
"code"
]
},
{
"login": "Otaiki1",
"name": "Abdulsamad sadiq",
"avatar_url": "https://avatars.githubusercontent.com/u/38711713?v=4",
"profile": "https://github.com/Otaiki1",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Thanks goes to these wonderful people. Follow the [contributors guide](https://g
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/thomas192"><img src="https://avatars.githubusercontent.com/u/65908739?v=4?s=100" width="100px;" alt="0xK2"/><br /><sub><b>0xK2</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/art-peace/commits?author=thomas192" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://fishonsnote.medium.com/"><img src="https://avatars.githubusercontent.com/u/43862685?v=4?s=100" width="100px;" alt="Fishon Amos"/><br /><sub><b>Fishon Amos</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/art-peace/commits?author=fishonamos" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Xaxxoo"><img src="https://avatars.githubusercontent.com/u/51526246?v=4?s=100" width="100px;" alt="Xaxxoo"/><br /><sub><b>Xaxxoo</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/art-peace/commits?author=Xaxxoo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/manoahLinks"><img src="https://avatars.githubusercontent.com/u/100848212?v=4?s=100" width="100px;" alt="Mano.dev"/><br /><sub><b>Mano.dev</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/art-peace/commits?author=manoahLinks" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Otaiki1"><img src="https://avatars.githubusercontent.com/u/38711713?v=4?s=100" width="100px;" alt="Abdulsamad sadiq"/><br /><sub><b>Abdulsamad sadiq</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/art-peace/commits?author=Otaiki1" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
Expand Down
4 changes: 2 additions & 2 deletions configs/canvas.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"canvas": {
"width": 35,
"height": 24
"width": 256,
"height": 256
},
"colors": [
"010001",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ services:
- backend
- devnet
volumes:
- configs:/configs
- ./frontend/package.json:/app/package.json
- ./frontend/package-lock.json:/app/package-lock.json
- ./frontend/public/:/app/public
- ./frontend/src:/app/src
- configs:/app/src/configs

volumes:
redis:
Expand Down
3 changes: 2 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WORKDIR /app
COPY ./frontend/package.json ./frontend/package-lock.json ./
RUN npm install
COPY ./frontend ./
COPY ./configs/docker-backend.config.json ./src/backend.config.json
COPY ./configs/canvas.config.json ./src/configs/canvas.config.json
COPY ./configs/docker-backend.config.json ./src/configs/backend.config.json

SHELL ["/bin/bash", "-c"]
# Clear the entrypoint
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/canvas/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const Canvas = props => {
const maxScale = 40;


const canvasRef = useRef(null)
const canvasPositionRef = useRef(null)
const canvasScaleRef = useRef(null)

Expand Down Expand Up @@ -410,7 +409,7 @@ const Canvas = props => {
return null;
}
if (props.selectedColorId === -1) {
let color = canvasRef.current
let color = props.canvasRef.current
.getContext("2d")
.getImageData(
props.selectedPositionX,
Expand All @@ -434,7 +433,7 @@ const Canvas = props => {
return null;
}
if (props.selectedColorId === -1) {
let color = canvasRef.current
let color = props.canvasRef.current
.getContext("2d")
.getImageData(
props.selectedPositionX,
Expand Down Expand Up @@ -543,7 +542,7 @@ const Canvas = props => {
return () => {
window.removeEventListener("mousemove", setFromEvent);
};
}, [props.selectedColorId, pixelSelect, props.nftSelectionMode, nftSelectionStarted, nftSelectionPositionX, nftSelectionPositionY, nftSelectionWidth, nftSelectionHeight, height, width, props.canvasRef, nftSelectionEndX, nftSelectionEndY, nftSelectionStartX, nftSelectionStartY]);
}, [props.selectedColorId, pixelSelect, props.nftSelectionMode, nftSelectionStarted, nftSelectionPositionX, nftSelectionPositionY, nftSelectionWidth, nftSelectionHeight, height, width, props.canvasRef, nftSelectionEndX, nftSelectionEndY, nftSelectionStartX, nftSelectionStartY, props]);

// TODO: both place options
return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/configs/canvas.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"canvas": {
"width": 35,
"height": 24
"width": 256,
"height": 256
},
"colors": [
"010001",
Expand Down
10 changes: 8 additions & 2 deletions onchain/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ mod quests {
pub mod interfaces;
pub mod pixel_quest;
pub mod template_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 Expand Up @@ -44,7 +49,8 @@ mod username_store {
}

mod mocks {
pub mod erc20_mock;
pub(crate) mod erc20_mock;
pub(crate) mod unruggable_token;
}

#[cfg(test)]
Expand Down
52 changes: 52 additions & 0 deletions onchain/src/mocks/unruggable_token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// https://github.com/OpenZeppelin/cairo-contracts/blob/main/src/tests/mocks/erc20_mocks.cairo
//

#[starknet::contract]
pub mod UnruggableMock {
use art_peace::quests::interfaces::IUnruggableMemecoin;
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
is_launched: bool,
owner: ContractAddress,
#[substorage(v0)]
erc20: ERC20Component::Storage
}

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

#[constructor]
fn constructor(
ref self: ContractState, name: ByteArray, symbol: ByteArray, owner: ContractAddress
) {
self.erc20.initializer(name, symbol);
self.owner.write(owner);
self.is_launched.write(true);
}

#[abi(embed_v0)]
impl UnruggableImpl of IUnruggableMemecoin<ContractState> {
fn owner(self: @ContractState) -> ContractAddress {
self.owner.read()
}
fn is_launched(self: @ContractState) -> bool {
self.is_launched.read()
}
}
}
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
}
}
}

Loading

0 comments on commit ce19dd8

Please sign in to comment.