Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/migrate 2.8.3 #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.6.4
starknet-foundry 0.22.0
scarb 2.8.2
starknet-foundry 0.31.0
14 changes: 12 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
[package]
name = "tokengiver"
version = "0.1.0"
edition = "2023_10"
edition = "2024_07"
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"]

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.6.3"
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]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.22.0" }
snforge_std = "0.31.0"

[[target.starknet-contract]]
casm = true
Expand Down
6 changes: 3 additions & 3 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
61 changes: 32 additions & 29 deletions src/campaign.cairo
Original file line number Diff line number Diff line change
@@ -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
};
Expand All @@ -23,26 +26,26 @@ mod CampaignComponent {
// STORAGE
// *************************************************************************
#[storage]
struct Storage {
campaign: LegacyMap<ContractAddress, Campaign>,
campaigns: LegacyMap<u16, ContractAddress>,
withdrawal_balance: LegacyMap<ContractAddress, u256>,
pub struct Storage {
campaign: Map<ContractAddress, Campaign>,
campaigns: Map<u16, ContractAddress>,
withdrawal_balance: Map<ContractAddress, u256>,
count: u16,
donations: LegacyMap<ContractAddress, u256>,
donation_count: LegacyMap<ContractAddress, u16>
donations: Map<ContractAddress, u256>,
donation_count: Map<ContractAddress, u16>
}

// *************************************************************************
// EVENT
// *************************************************************************
#[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]
Expand Down Expand Up @@ -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
Expand All @@ -98,34 +101,34 @@ 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<TContractState>, 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(
ref self: ComponentState<TContractState>,
campaign_address: ContractAddress,
amount: u256
) {
self.donations.write(campaign_address, amount);
self.donations.entry(campaign_address).write(amount);
}

fn set_available_withdrawal(
ref self: ComponentState<TContractState>,
campaign_address: ContractAddress,
amount: u256
) {
self.withdrawal_balance.write(campaign_address, amount);
self.withdrawal_balance.entry(campaign_address).write(amount);
}

// *************************************************************************
Expand All @@ -135,12 +138,12 @@ mod CampaignComponent {
fn get_donations(
self: @ComponentState<TContractState>, campaign_address: ContractAddress
) -> u256 {
self.donations.read(campaign_address)
self.donations.entry(campaign_address).read()
}
fn get_available_withdrawal(
self: @ComponentState<TContractState>, campaign_address: ContractAddress
) -> u256 {
self.withdrawal_balance.read(campaign_address)
self.withdrawal_balance.entry(campaign_address).read()
}


Expand All @@ -149,13 +152,13 @@ mod CampaignComponent {
fn get_campaign(
self: @ComponentState<TContractState>, campaign_address: ContractAddress
) -> Campaign {
self.campaign.read(campaign_address)
self.campaign.entry(campaign_address).read()
}

fn get_campaign_metadata(
self: @ComponentState<TContractState>, campaign_address: ContractAddress
) -> ByteArray {
let campaign: Campaign = self.campaign.read(campaign_address);
let campaign: Campaign = self.campaign.entry(campaign_address).read();
campaign.metadata_URI
}

Expand All @@ -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;
};
Expand All @@ -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);
}
Expand All @@ -197,7 +200,7 @@ mod CampaignComponent {
fn get_donation_count(
self: @ComponentState<TContractState>, campaign_address: ContractAddress
) -> u16 {
self.donation_count.read(campaign_address)
self.donation_count.entry(campaign_address).read()
}
}
}
6 changes: 3 additions & 3 deletions src/presets/campaign.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[starknet::contract]
mod TokenGiverCampaign {
pub mod TokenGiverCampaign {
use starknet::{ContractAddress, get_caller_address};
use tokengiver::campaign::CampaignComponent;

Expand All @@ -9,14 +9,14 @@ mod TokenGiverCampaign {
impl CampaignImpl = CampaignComponent::TokenGiverCampaign<ContractState>;

#[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
}
Expand Down
24 changes: 13 additions & 11 deletions src/token_giver_nft.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use starknet::ContractAddress;

// *************************************************************************
// OZ IMPORTS
// *************************************************************************
Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -75,7 +77,7 @@ pub mod TokenGiverNFT {
// STORAGE
// *************************************************************************
#[storage]
struct Storage {
pub struct Storage {
#[substorage(v0)]
erc721: ERC721Component::Storage,
#[substorage(v0)]
Expand All @@ -84,16 +86,16 @@ pub mod TokenGiverNFT {
ownable: OwnableComponent::Storage,
admin: ContractAddress,
last_minted_id: u256,
mint_timestamp: LegacyMap<u256, u64>,
user_token_id: LegacyMap<ContractAddress, u256>,
mint_timestamp: Map<u256, u64>,
user_token_id: Map<ContractAddress, u256>,
}

// *************************************************************************
// EVENTS
// *************************************************************************
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
pub enum Event {
#[flat]
ERC721Event: ERC721Component::Event,
#[flat]
Expand Down Expand Up @@ -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 {
Expand Down
Loading