diff --git a/onchain/src/art_peace.cairo b/onchain/src/art_peace.cairo index d1ce12b0..a78012a8 100644 --- a/onchain/src/art_peace.cairo +++ b/onchain/src/art_peace.cairo @@ -636,7 +636,8 @@ pub mod ArtPeace { } let member_metadata = self.users_faction_meta.read(user); if member_metadata.member_pixels > 0 { - // TODO: If member_pixels > 0 && < allocation && enough time has passed, return allocation instead of member_pixels + // TODO: If member_pixels > 0 && < allocation && enough time has passed, return + // allocation instead of member_pixels return member_metadata.member_pixels; } else { let time_since_last_pixel = now - member_metadata.member_placed_time; @@ -821,11 +822,10 @@ pub mod ArtPeace { self.daily_quests.read((day_index, 0)) == zero_address, 'Daily quests already set' ); let mut i = 0; - while i < quests - .len() { - self.daily_quests.write((day_index, i), *quests.at(i)); - i += 1; - }; + while i < quests.len() { + self.daily_quests.write((day_index, i), *quests.at(i)); + i += 1; + }; } fn add_main_quests(ref self: ContractState, quests: Span) { @@ -1136,29 +1136,27 @@ pub mod ArtPeace { let canvas_width = self.canvas_width.read(); let (mut x, mut y) = (0, 0); let mut matches = 0; - while y < template_metadata - .height { - x = 0; - while x < template_metadata - .width { - let _pos = template_pos_x + x + (template_pos_y + y) * canvas_width; - let _color = *template_image - .at((x + y * template_metadata.width).try_into().unwrap()); - // TODO: Check if the color is transparent - // TODO: Add back - // if color == self.canvas.read(pos).color { - if false { - matches += 1; - } - x += 1; - }; - y += 1; + while y < template_metadata.height { + x = 0; + while x < template_metadata.width { + let _pos = template_pos_x + x + (template_pos_y + y) * canvas_width; + let _color = *template_image + .at((x + y * template_metadata.width).try_into().unwrap()); + // TODO: Check if the color is transparent + // TODO: Add back + // if color == self.canvas.read(pos).color { + if false { + matches += 1; + } + x += 1; }; + y += 1; + }; // TODO: Allow some threshold? if matches == template_metadata.width * template_metadata.height { self.templates.completed_templates.write(template_id, true); - // self.emit(Event::TemplateEvent::TemplateCompleted { template_id }); + // self.emit(Event::TemplateEvent::TemplateCompleted { template_id }); } } @@ -1190,73 +1188,69 @@ pub mod ArtPeace { let canvas_width = self.canvas_width.read(); let (mut x, mut y) = (0, 0); let mut matches = 0; - while y < template_metadata - .height { - x = 0; - while x < template_metadata - .width { - let _pos = template_pos_x + x + (template_pos_y + y) * canvas_width; - let _color = *template_image - .at((x + y * template_metadata.width).try_into().unwrap()); - // TODO: Check if the color is transparent - // TODO: Add back - // if color == self.canvas.read(pos).color { - if false { - matches += 1; - - let mut pixel_owner = starknet::contract_address_const::< - 0 - >(); // TODO: self.canvas.read(pos).owner; - let user_index = pixel_contributors_indexes.get(pixel_owner.into()); - - if user_index == 0 { - let new_index = pixel_contributors.len() + 1; - - pixel_contributors.append(pixel_owner); - pixel_contributors_indexes - .insert(pixel_owner.into(), new_index); - total_pixels_by_user.insert(new_index.into(), 1); - } else { - let count = total_pixels_by_user.get(user_index.into()); - total_pixels_by_user.insert(user_index.into(), count + 1); - } - } - x += 1; - }; - y += 1; + while y < template_metadata.height { + x = 0; + while x < template_metadata.width { + let _pos = template_pos_x + x + (template_pos_y + y) * canvas_width; + let _color = *template_image + .at((x + y * template_metadata.width).try_into().unwrap()); + // TODO: Check if the color is transparent + // TODO: Add back + // if color == self.canvas.read(pos).color { + if false { + matches += 1; + + let mut pixel_owner = starknet::contract_address_const::< + 0 + >(); // TODO: self.canvas.read(pos).owner; + let user_index = pixel_contributors_indexes.get(pixel_owner.into()); + + if user_index == 0 { + let new_index = pixel_contributors.len() + 1; + + pixel_contributors.append(pixel_owner); + pixel_contributors_indexes.insert(pixel_owner.into(), new_index); + total_pixels_by_user.insert(new_index.into(), 1); + } else { + let count = total_pixels_by_user.get(user_index.into()); + total_pixels_by_user.insert(user_index.into(), count + 1); + } + } + x += 1; }; + y += 1; + }; // TODO: Allow some threshold? if matches == template_metadata.width * template_metadata.height { self.templates.completed_templates.write(template_id, true); // Distribute rewards let mut i = 0; - while i < pixel_contributors - .len() { - let reward_token = template_metadata.reward_token; - let reward_amount = template_metadata.reward; - let total_pixels_in_template = template_metadata.width - * template_metadata.height; - - let mut user = *pixel_contributors.at(i).into(); - let user_index = (i + 1); - let user_total_pixels = total_pixels_by_user.get(user_index.into()); - - // TODO: Handle remainder of funds - let user_reward = (reward_amount * user_total_pixels.into()) - / total_pixels_in_template.into(); - - assert( - IERC20Dispatcher { contract_address: reward_token } - .balance_of(contract) >= user_reward, - 'insufficient funds' - ); - let success = IERC20Dispatcher { contract_address: reward_token } - .transfer(user, user_reward); - assert(success, 'ERC20 transfer fail!'); - i += 1; - }; - // self.emit(Event::TemplateEvent::TemplateCompleted { template_id }); + while i < pixel_contributors.len() { + let reward_token = template_metadata.reward_token; + let reward_amount = template_metadata.reward; + let total_pixels_in_template = template_metadata.width + * template_metadata.height; + + let mut user = *pixel_contributors.at(i).into(); + let user_index = (i + 1); + let user_total_pixels = total_pixels_by_user.get(user_index.into()); + + // TODO: Handle remainder of funds + let user_reward = (reward_amount * user_total_pixels.into()) + / total_pixels_in_template.into(); + + assert( + IERC20Dispatcher { contract_address: reward_token } + .balance_of(contract) >= user_reward, + 'insufficient funds' + ); + let success = IERC20Dispatcher { contract_address: reward_token } + .transfer(user, user_reward); + assert(success, 'ERC20 transfer fail!'); + i += 1; + }; + // self.emit(Event::TemplateEvent::TemplateCompleted { template_id }); } } } @@ -1296,11 +1290,10 @@ pub mod ArtPeace { // find threshold let mut threshold: u32 = 0; let mut min_index = daily_new_colors_count; - while threshold == 0 - && min_index > 0 { - min_index -= 1; - threshold = max_scores.get(min_index.into()); - }; + while threshold == 0 && min_index > 0 { + min_index -= 1; + threshold = max_scores.get(min_index.into()); + }; if threshold == 0 { // No votes threshold = 1; diff --git a/onchain/src/nfts/canvas_nft.cairo b/onchain/src/nfts/canvas_nft.cairo index c733130b..690b3140 100644 --- a/onchain/src/nfts/canvas_nft.cairo +++ b/onchain/src/nfts/canvas_nft.cairo @@ -70,7 +70,9 @@ mod CanvasNFT { #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray, round_number: felt252) { + fn constructor( + ref self: ContractState, name: ByteArray, symbol: ByteArray, round_number: felt252 + ) { let base_uri = format!("https://api.art-peace.net/round-{}/metadata/", round_number); self.erc721.initializer(name, symbol, base_uri); } diff --git a/onchain/src/quests/authority_quest.cairo b/onchain/src/quests/authority_quest.cairo index 218f500f..ec3551f1 100644 --- a/onchain/src/quests/authority_quest.cairo +++ b/onchain/src/quests/authority_quest.cairo @@ -37,11 +37,10 @@ pub mod AuthorityQuest { fn mark_claimable(ref self: ContractState, calldata: Span) { assert(get_caller_address() == self.authority.read(), 'Only authority address allowed'); let mut i = 0; - while i < calldata - .len() { - self.claimable.write((*calldata[i]).try_into().unwrap(), true); - i += 1; - } + while i < calldata.len() { + self.claimable.write((*calldata[i]).try_into().unwrap(), true); + i += 1; + } } } diff --git a/onchain/src/quests/rainbow_quest.cairo b/onchain/src/quests/rainbow_quest.cairo index 86c59220..9cc53d67 100644 --- a/onchain/src/quests/rainbow_quest.cairo +++ b/onchain/src/quests/rainbow_quest.cairo @@ -48,15 +48,14 @@ pub mod RainbowQuest { let mut result = true; let mut i = 0; - while i < art_piece - .get_color_count() { - if (art_piece.get_user_pixels_placed_color(user, i) == 0) { - result = false; - break; - } - - i += 1; - }; + while i < art_piece.get_color_count() { + if (art_piece.get_user_pixels_placed_color(user, i) == 0) { + result = false; + break; + } + + i += 1; + }; result } diff --git a/onchain/src/templates/component.cairo b/onchain/src/templates/component.cairo index 7fb27ce8..b33d65bf 100644 --- a/onchain/src/templates/component.cairo +++ b/onchain/src/templates/component.cairo @@ -32,7 +32,7 @@ pub mod TemplateStoreComponent { struct TemplateCompleted { #[key] id: u32, - // TODO: Users rewarded, ... + // TODO: Users rewarded, ... } #[embeddable_as(TemplateStoreImpl)] diff --git a/onchain/src/tests/art_peace.cairo b/onchain/src/tests/art_peace.cairo index 5e211af3..9a427ffe 100644 --- a/onchain/src/tests/art_peace.cairo +++ b/onchain/src/tests/art_peace.cairo @@ -133,16 +133,15 @@ pub(crate) fn deploy_with_quests_contract( let mut i = 0; let mut dayId = 0; let mut days_quests: Array = array![]; - while i < daily_quests - .len() { - days_quests.append(*daily_quests.at(i)); - i += 1; - if i % daily_quests_count == 0 { - art_peace.add_daily_quests(dayId, days_quests.span()); - dayId += 1; - days_quests = array![]; - } - }; + while i < daily_quests.len() { + days_quests.append(*daily_quests.at(i)); + i += 1; + if i % daily_quests_count == 0 { + art_peace.add_daily_quests(dayId, days_quests.span()); + dayId += 1; + days_quests = array![]; + } + }; if days_quests.len() > 0 { art_peace.add_daily_quests(dayId, days_quests.span()); } diff --git a/onchain/src/tests/rainbow_quest.cairo b/onchain/src/tests/rainbow_quest.cairo index 8ef9c5cd..3df78887 100644 --- a/onchain/src/tests/rainbow_quest.cairo +++ b/onchain/src/tests/rainbow_quest.cairo @@ -56,13 +56,12 @@ fn rainbow_quest_test() { ); let mut i: u8 = 0; - while i < art_peace - .get_color_count() { - art_peace.place_pixel_blocktime(i.into(), i); - warp_to_next_available_time(art_peace); + while i < art_peace.get_color_count() { + art_peace.place_pixel_blocktime(i.into(), i); + warp_to_next_available_time(art_peace); - i += 1; - }; + i += 1; + }; let calldata = array![].span(); art_peace.claim_main_quest(0, calldata); @@ -88,13 +87,12 @@ fn rainbow_quest_color_missing_test() { ); let mut i: u8 = 0; - while i < art_peace.get_color_count() - - 1 { - art_peace.place_pixel_blocktime(i.into(), i); - warp_to_next_available_time(art_peace); + while i < art_peace.get_color_count() - 1 { + art_peace.place_pixel_blocktime(i.into(), i); + warp_to_next_available_time(art_peace); - i += 1; - }; + i += 1; + }; let calldata = array![].span(); art_peace.claim_main_quest(0, calldata); diff --git a/onchain/src/tests/vote_quest.cairo b/onchain/src/tests/vote_quest.cairo index e1b3b6d6..11e43d58 100644 --- a/onchain/src/tests/vote_quest.cairo +++ b/onchain/src/tests/vote_quest.cairo @@ -97,7 +97,7 @@ fn vote_quest_double_claim_test() { art_peace_dispatcher.claim_main_quest(0, utils::EMPTY_CALLDATA()); } -// When the `votable_colors` storage variable is not set for a particular day index, trying to +// When the `votable_colors` storage variable is not set for a particular day index, trying to // vote for a color at that day panics with 'Color out of bounds' error #[test] #[should_panic(expected: 'Color out of bounds')]