From 1c157b00956621c510a40a7c773ce960efcc91fb Mon Sep 17 00:00:00 2001 From: Jemiiah Date: Thu, 21 Nov 2024 18:05:31 +0100 Subject: [PATCH 1/3] updated dev deps and tool-versions --- .tool-versions | 4 ++-- Scarb.toml | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.tool-versions b/.tool-versions index 9bd3df5..992abf3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.6.4 -starknet-foundry 0.22.0 +scarb 2.8.3 +starknet-foundry 0.31.0 \ No newline at end of file diff --git a/Scarb.toml b/Scarb.toml index 4a343c8..5e4caea 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,7 +1,9 @@ [package] name = "tokengiver" version = "0.1.0" -edition = "2023_10" +edition = "2024_07" +cairo-version = "2.8.3" +scarb-version = "2.8.3" authors = ["Oshioke Salaki & Stephanie Egbuonu"] description = "Decentralized Charity Dapp" keywords = ["SocialFi", "tokenbound", "cairo", "contracts", "starknet"] @@ -9,12 +11,18 @@ keywords = ["SocialFi", "tokenbound", "cairo", "contracts", "starknet"] # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet = "2.6.3" +starknet = "2.8.3" +openzeppelin_access = "0.18.0" +openzeppelin_introspection = "0.18.0" +openzeppelin_token = "0.18.0" openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.12.0" } token_bound_accounts= { git = "https://github.com/Starknet-Africa-Edu/TBA", tag = "v0.3.0" } [dev-dependencies] -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.22.0" } +assert_macros = "2.8.3" +openzeppelin_utils = "0.18.0" +openzeppelin_testing = "0.18.0" +snforge_std = "0.31.0" [[target.starknet-contract]] casm = true From e3f2cfa92e330660566d1b7fa458c06fef607f8d Mon Sep 17 00:00:00 2001 From: Jemiiah Date: Fri, 22 Nov 2024 04:01:08 +0100 Subject: [PATCH 2/3] updated contract --- .tool-versions | 2 +- Scarb.lock | 14 +++++++-- Scarb.toml | 12 ++------ src/base/types.cairo | 6 ++-- src/campaign.cairo | 61 ++++++++++++++++++++------------------ src/presets/campaign.cairo | 6 ++-- src/token_giver_nft.cairo | 24 ++++++++------- 7 files changed, 67 insertions(+), 58 deletions(-) diff --git a/.tool-versions b/.tool-versions index 992abf3..8b889c2 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.8.3 +scarb 2.8.2 starknet-foundry 0.31.0 \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock index 4a8a52b..0ea4b25 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -6,10 +6,20 @@ name = "openzeppelin" version = "0.12.0" source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.12.0#0697004db74502ce49900edef37331dd03531356" +[[package]] +name = "snforge_scarb_plugin" +version = "0.31.0" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:1fce075fcbf7fce1b0935f6f9a034549704837fb221da212d3b6e9134cebfdaa" + [[package]] name = "snforge_std" -version = "0.22.0" -source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.22.0#9b215944c6c5871c738381b4ded61bbf06e7ba35" +version = "0.31.0" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:60ac980b297281f9a59a5f1668cb56bdea1b28fd2f8008008270f9a3c91ad3ba" +dependencies = [ + "snforge_scarb_plugin", +] [[package]] name = "token_bound_accounts" diff --git a/Scarb.toml b/Scarb.toml index 5e4caea..794e932 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -2,8 +2,8 @@ name = "tokengiver" version = "0.1.0" edition = "2024_07" -cairo-version = "2.8.3" -scarb-version = "2.8.3" +cairo-version = "2.8.2" +scarb-version = "2.8.2" authors = ["Oshioke Salaki & Stephanie Egbuonu"] description = "Decentralized Charity Dapp" keywords = ["SocialFi", "tokenbound", "cairo", "contracts", "starknet"] @@ -11,17 +11,11 @@ keywords = ["SocialFi", "tokenbound", "cairo", "contracts", "starknet"] # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet = "2.8.3" -openzeppelin_access = "0.18.0" -openzeppelin_introspection = "0.18.0" -openzeppelin_token = "0.18.0" +starknet = "2.8.2" openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.12.0" } token_bound_accounts= { git = "https://github.com/Starknet-Africa-Edu/TBA", tag = "v0.3.0" } [dev-dependencies] -assert_macros = "2.8.3" -openzeppelin_utils = "0.18.0" -openzeppelin_testing = "0.18.0" snforge_std = "0.31.0" [[target.starknet-contract]] diff --git a/src/base/types.cairo b/src/base/types.cairo index 8f5d971..ae91d5e 100644 --- a/src/base/types.cairo +++ b/src/base/types.cairo @@ -12,7 +12,7 @@ use starknet::ContractAddress; // displayed name, description, beneficiary, etc. #[derive(Drop, Serde, starknet::Store)] pub struct Campaign { - campaign_address: ContractAddress, - campaign_owner: ContractAddress, - metadata_URI: ByteArray, + pub campaign_address: ContractAddress, + pub campaign_owner: ContractAddress, + pub metadata_URI: ByteArray, } diff --git a/src/campaign.cairo b/src/campaign.cairo index 5eb2d6b..fe76ac3 100644 --- a/src/campaign.cairo +++ b/src/campaign.cairo @@ -1,12 +1,15 @@ -use starknet::ContractAddress; - #[starknet::component] -mod CampaignComponent { +pub mod CampaignComponent { // ************************************************************************* // IMPORT // ************************************************************************* use core::traits::TryInto; - use starknet::{ContractAddress, get_caller_address}; + use starknet::{ + ContractAddress, get_caller_address, + storage::{ + Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess + } + }; use tokengiver::interfaces::ITokenGiverNft::{ ITokenGiverNftDispatcher, ITokenGiverNftDispatcherTrait }; @@ -23,13 +26,13 @@ mod CampaignComponent { // STORAGE // ************************************************************************* #[storage] - struct Storage { - campaign: LegacyMap, - campaigns: LegacyMap, - withdrawal_balance: LegacyMap, + pub struct Storage { + campaign: Map, + campaigns: Map, + withdrawal_balance: Map, count: u16, - donations: LegacyMap, - donation_count: LegacyMap + donations: Map, + donation_count: Map } // ************************************************************************* @@ -37,12 +40,12 @@ mod CampaignComponent { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { CreateCampaign: CreateCampaign } #[derive(Drop, starknet::Event)] - struct CreateCampaign { + pub struct CreateCampaign { #[key] owner: ContractAddress, #[key] @@ -82,8 +85,8 @@ mod CampaignComponent { let new_campaign = Campaign { campaign_address, campaign_owner: recipient, metadata_URI: "", }; - self.campaign.write(campaign_address, new_campaign); - self.campaigns.write(count, campaign_address); + self.campaign.entry(campaign_address).write(new_campaign); + self.campaigns.entry(count).write(campaign_address); self.count.write(count); self.emit(CreateCampaign { owner: recipient, campaign_address, token_id }); campaign_address @@ -98,18 +101,18 @@ mod CampaignComponent { campaign_address: ContractAddress, metadata_uri: ByteArray ) { - let mut campaign: Campaign = self.campaign.read(campaign_address); + let mut campaign: Campaign = self.campaign.entry(campaign_address).read(); assert(get_caller_address() == campaign.campaign_owner, NOT_CAMPAIGN_OWNER); campaign.metadata_URI = metadata_uri; - self.campaign.write(campaign_address, campaign); + self.campaign.entry(campaign_address).write(campaign); } fn set_donation_count( ref self: ComponentState, campaign_address: ContractAddress ) { - let prev_count: u16 = self.donation_count.read(campaign_address); - self.donation_count.write(campaign_address, prev_count + 1); + let prev_count: u16 = self.donation_count.entry(campaign_address).read(); + self.donation_count.entry(campaign_address).write(prev_count + 1); } fn set_donations( @@ -117,7 +120,7 @@ mod CampaignComponent { campaign_address: ContractAddress, amount: u256 ) { - self.donations.write(campaign_address, amount); + self.donations.entry(campaign_address).write(amount); } fn set_available_withdrawal( @@ -125,7 +128,7 @@ mod CampaignComponent { campaign_address: ContractAddress, amount: u256 ) { - self.withdrawal_balance.write(campaign_address, amount); + self.withdrawal_balance.entry(campaign_address).write(amount); } // ************************************************************************* @@ -135,12 +138,12 @@ mod CampaignComponent { fn get_donations( self: @ComponentState, campaign_address: ContractAddress ) -> u256 { - self.donations.read(campaign_address) + self.donations.entry(campaign_address).read() } fn get_available_withdrawal( self: @ComponentState, campaign_address: ContractAddress ) -> u256 { - self.withdrawal_balance.read(campaign_address) + self.withdrawal_balance.entry(campaign_address).read() } @@ -149,13 +152,13 @@ mod CampaignComponent { fn get_campaign( self: @ComponentState, campaign_address: ContractAddress ) -> Campaign { - self.campaign.read(campaign_address) + self.campaign.entry(campaign_address).read() } fn get_campaign_metadata( self: @ComponentState, campaign_address: ContractAddress ) -> ByteArray { - let campaign: Campaign = self.campaign.read(campaign_address); + let campaign: Campaign = self.campaign.entry(campaign_address).read(); campaign.metadata_URI } @@ -167,8 +170,8 @@ mod CampaignComponent { while i < count + 1 { - let campaignAddress: ContractAddress = self.campaigns.read(i); - let campaign: Campaign = self.campaign.read(campaignAddress); + let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); + let campaign: Campaign = self.campaign.entry(campaignAddress).read(); campaigns.append(campaign.metadata_URI); i += 1; }; @@ -184,8 +187,8 @@ mod CampaignComponent { while i < count + 1 { - let campaignAddress: ContractAddress = self.campaigns.read(i); - let campaign: Campaign = self.campaign.read(campaignAddress); + let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); + let campaign: Campaign = self.campaign.entry(campaignAddress).read(); if campaign.campaign_owner == user { campaigns.append(campaign.metadata_URI); } @@ -197,7 +200,7 @@ mod CampaignComponent { fn get_donation_count( self: @ComponentState, campaign_address: ContractAddress ) -> u16 { - self.donation_count.read(campaign_address) + self.donation_count.entry(campaign_address).read() } } } diff --git a/src/presets/campaign.cairo b/src/presets/campaign.cairo index 2c46b66..572690c 100644 --- a/src/presets/campaign.cairo +++ b/src/presets/campaign.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -mod TokenGiverCampaign { +pub mod TokenGiverCampaign { use starknet::{ContractAddress, get_caller_address}; use tokengiver::campaign::CampaignComponent; @@ -9,14 +9,14 @@ mod TokenGiverCampaign { impl CampaignImpl = CampaignComponent::TokenGiverCampaign; #[storage] - struct Storage { + pub struct Storage { #[substorage(v0)] campaign: CampaignComponent::Storage } #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { #[flat] CampaignEvent: CampaignComponent::Event } diff --git a/src/token_giver_nft.cairo b/src/token_giver_nft.cairo index 2fb8b44..a2d3faf 100644 --- a/src/token_giver_nft.cairo +++ b/src/token_giver_nft.cairo @@ -1,5 +1,3 @@ -use starknet::ContractAddress; - // ************************************************************************* // OZ IMPORTS // ************************************************************************* @@ -38,7 +36,11 @@ pub mod TokenGiverNFT { // IMPORTS // ************************************************************************* use openzeppelin::token::erc721::interface::IERC721Metadata; - use starknet::{ContractAddress, get_caller_address, get_block_timestamp}; + use starknet::{ContractAddress, get_caller_address, get_block_timestamp, + storage::{ + Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess + } + }; use core::num::traits::zero::Zero; use tokengiver::interfaces::ITokenGiverNft; use openzeppelin::{ @@ -75,7 +77,7 @@ pub mod TokenGiverNFT { // STORAGE // ************************************************************************* #[storage] - struct Storage { + pub struct Storage { #[substorage(v0)] erc721: ERC721Component::Storage, #[substorage(v0)] @@ -84,8 +86,8 @@ pub mod TokenGiverNFT { ownable: OwnableComponent::Storage, admin: ContractAddress, last_minted_id: u256, - mint_timestamp: LegacyMap, - user_token_id: LegacyMap, + mint_timestamp: Map, + user_token_id: Map, } // ************************************************************************* @@ -93,7 +95,7 @@ pub mod TokenGiverNFT { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { #[flat] ERC721Event: ERC721Component::Event, #[flat] @@ -122,17 +124,17 @@ pub mod TokenGiverNFT { self.erc721._mint(address, token_id); let timestamp: u64 = get_block_timestamp(); - self.user_token_id.write(address, token_id); + self.user_token_id.entry(address).write(token_id); self.last_minted_id.write(token_id); - self.mint_timestamp.write(token_id, timestamp); + self.mint_timestamp.entry(token_id).write(timestamp); } fn get_user_token_id(self: @ContractState, user: ContractAddress) -> u256 { - self.user_token_id.read(user) + self.user_token_id.entry(user).read() } fn get_token_mint_timestamp(self: @ContractState, token_id: u256) -> u64 { - self.mint_timestamp.read(token_id) + self.mint_timestamp.entry(token_id).read() } fn get_last_minted_id(self: @ContractState) -> u256 { From ae7e80bd20a6ce2a1822373f707b3ecafd8f9abf Mon Sep 17 00:00:00 2001 From: Jemiiah Date: Fri, 22 Nov 2024 08:59:29 +0100 Subject: [PATCH 3/3] format --- src/campaign.cairo | 36 ++++++++++++++++-------------------- src/token_giver_nft.cairo | 7 +++---- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/campaign.cairo b/src/campaign.cairo index fe76ac3..0d1e58f 100644 --- a/src/campaign.cairo +++ b/src/campaign.cairo @@ -5,10 +5,8 @@ pub mod CampaignComponent { // ************************************************************************* use core::traits::TryInto; use starknet::{ - ContractAddress, get_caller_address, - storage::{ - Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess - } + ContractAddress, get_caller_address, + storage::{Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess} }; use tokengiver::interfaces::ITokenGiverNft::{ ITokenGiverNftDispatcher, ITokenGiverNftDispatcherTrait @@ -168,13 +166,12 @@ pub mod CampaignComponent { let count = self.count.read(); let mut i: u16 = 1; - while i < count - + 1 { - let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); - let campaign: Campaign = self.campaign.entry(campaignAddress).read(); - campaigns.append(campaign.metadata_URI); - i += 1; - }; + while i < count + 1 { + let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); + let campaign: Campaign = self.campaign.entry(campaignAddress).read(); + campaigns.append(campaign.metadata_URI); + i += 1; + }; campaigns } @@ -185,15 +182,14 @@ pub mod CampaignComponent { let count = self.count.read(); let mut i: u16 = 1; - while i < count - + 1 { - let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); - let campaign: Campaign = self.campaign.entry(campaignAddress).read(); - if campaign.campaign_owner == user { - campaigns.append(campaign.metadata_URI); - } - i += 1; - }; + while i < count + 1 { + let campaignAddress: ContractAddress = self.campaigns.entry(i).read(); + let campaign: Campaign = self.campaign.entry(campaignAddress).read(); + if campaign.campaign_owner == user { + campaigns.append(campaign.metadata_URI); + } + i += 1; + }; campaigns } diff --git a/src/token_giver_nft.cairo b/src/token_giver_nft.cairo index a2d3faf..f6fb2c1 100644 --- a/src/token_giver_nft.cairo +++ b/src/token_giver_nft.cairo @@ -36,10 +36,9 @@ pub mod TokenGiverNFT { // IMPORTS // ************************************************************************* use openzeppelin::token::erc721::interface::IERC721Metadata; - use starknet::{ContractAddress, get_caller_address, get_block_timestamp, - storage::{ - Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess - } + use starknet::{ + ContractAddress, get_caller_address, get_block_timestamp, + storage::{Map, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess} }; use core::num::traits::zero::Zero; use tokengiver::interfaces::ITokenGiverNft;