Skip to content

Commit

Permalink
ft: integrate community & channel to publication
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed Oct 18, 2024
1 parent 4534390 commit b1e00cf
Show file tree
Hide file tree
Showing 21 changed files with 1,289 additions and 1,030 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ Check out the contract architecture below, and join our [working group](https://
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
- check that only members can post to a community_channel - add test for this in publication
- check that banned profiles in a community/channel cannot post to that community/channel - add test for this in publication add community, channel and jolt components to hub

- if they are censored - we want to set approved to false for publications and if they are not, set approved to true.
50 changes: 47 additions & 3 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ pub struct Publication {
pub root_pub_id: u256,
pub upvote: u256,
pub downvote: u256,
pub channel_id: felt252,
pub channel_id: u256,
pub collect_nft: ContractAddress,
pub tipped_amount: u256
pub tipped_amount: u256,
pub community_id: u256,
pub approved: bool
}

// /**
Expand Down Expand Up @@ -103,7 +105,8 @@ pub enum PublicationType {
pub struct PostParams {
pub content_URI: ByteArray,
pub profile_address: ContractAddress,
pub channel_id: felt252
pub channel_id: u256,
pub community_id: u256,
}

///**
Expand All @@ -121,6 +124,8 @@ pub struct CommentParams {
pub pointed_profile_address: ContractAddress,
pub pointed_pub_id: u256,
pub reference_pub_type: PublicationType,
pub channel_id: u256,
pub community_id: u256,
}

///**
Expand Down Expand Up @@ -153,6 +158,8 @@ pub struct RepostParams {
pub profile_address: ContractAddress,
pub pointed_profile_address: ContractAddress,
pub pointed_pub_id: u256,
pub channel_id: u256,
pub community_id: u256,
}

// /**
Expand Down Expand Up @@ -409,3 +416,40 @@ pub enum JoltStatus {
REJECTED,
FAILED
}

#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct UpVoteParams {
pub profile_address: ContractAddress,
pub channel_id: u256,
pub community_id: u256,
pub pub_id: u256
}

#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct DownVoteParams {
pub profile_address: ContractAddress,
pub channel_id: u256,
pub community_id: u256,
pub pub_id: u256
}

#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct TipParams {
pub profile_address: ContractAddress,
pub channel_id: u256,
pub community_id: u256,
pub pub_id: u256,
pub amount: u256,
pub erc20_contract_address: ContractAddress
}

#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct CollectParams {
pub profile_address: ContractAddress,
pub channel_id: u256,
pub community_id: u256,
pub pub_id: u256,
pub salt: felt252,
pub collect_nft_impl_class_hash: felt252,
pub karst_hub: ContractAddress,
}
16 changes: 8 additions & 8 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ pub mod ChannelComponent {
ContractAddress, contract_address_const, get_caller_address, get_block_timestamp, ClassHash,
syscalls::deploy_syscall, SyscallResultTrait
};
use openzeppelin::access::ownable::OwnableComponent;
use starknet::storage::{
StoragePointerReadAccess, StoragePointerWriteAccess, Map, StorageMapReadAccess,
StorageMapWriteAccess
};
use openzeppelin::access::ownable::OwnableComponent;

use karst::jolt::jolt::JoltComponent;
use karst::community::community::CommunityComponent;
use karst::interfaces::IChannel::IChannel;
use karst::interfaces::{
IChannel::IChannel, ICommunity::ICommunity,
ICommunityNft::{ICommunityNftDispatcher, ICommunityNftDispatcherTrait}
ICommunity::ICommunity, ICustomNFT::{ICustomNFTDispatcher, ICustomNFTDispatcherTrait}
};
use karst::community::community::CommunityComponent;
use karst::jolt::jolt::JoltComponent;

use karst::base::{
constants::errors::Errors::{
NOT_CHANNEL_OWNER, ALREADY_MEMBER, NOT_CHANNEL_MEMBER, NOT_COMMUNITY_MEMBER,
Expand Down Expand Up @@ -606,7 +606,7 @@ pub mod ChannelComponent {
profile: ContractAddress,
channel_nft_address: ContractAddress
) -> u256 {
let token_id = ICommunityNftDispatcher { contract_address: channel_nft_address }
let token_id = ICustomNFTDispatcher { contract_address: channel_nft_address }
.mint_nft(profile);
token_id
}
Expand All @@ -619,7 +619,7 @@ pub mod ChannelComponent {
channel_nft_address: ContractAddress,
token_id: u256
) {
ICommunityNftDispatcher { contract_address: channel_nft_address }
ICustomNFTDispatcher { contract_address: channel_nft_address }
.burn_nft(get_caller_address(), token_id);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/channel/channelNFT.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod ChannelNFT {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};

use karst::interfaces::ICommunityNft::ICommunityNft;
use karst::interfaces::ICustomNFT::ICustomNFT;

use karst::base::{
constants::errors::Errors::{ALREADY_MINTED, NOT_TOKEN_OWNER, TOKEN_DOES_NOT_EXIST},
Expand Down Expand Up @@ -66,7 +66,7 @@ pub mod ChannelNFT {
}

#[abi(embed_v0)]
impl ChannelNFT of ICommunityNft<ContractState> {
impl ChannelNFT of ICustomNFT<ContractState> {
// *************************************************************************
// EXTERNAL
// *************************************************************************
Expand Down
1 change: 0 additions & 1 deletion src/collectnft.cairo

This file was deleted.

11 changes: 6 additions & 5 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ pub mod CommunityComponent {
}
};
use openzeppelin::access::ownable::OwnableComponent;

use karst::jolt::jolt::JoltComponent;
use karst::interfaces::{
ICommunity::ICommunity, IJolt::IJolt, IERC721::{IERC721Dispatcher, IERC721DispatcherTrait},
ICommunityNft::{ICommunityNftDispatcher, ICommunityNftDispatcherTrait}
ICustomNFT::{ICustomNFTDispatcher, ICustomNFTDispatcherTrait}
};
use karst::base::constants::types::{
CommunityDetails, GateKeepType, CommunityType, CommunityMember, CommunityGateKeepDetails,
Expand Down Expand Up @@ -422,7 +421,9 @@ pub mod CommunityComponent {
/// @notice gets total members for a community
/// @param community_id id of community to be returned
/// @return u256 total members in the community
fn get_total_members(self: @ComponentState<TContractState>, community_id: u256) -> u256 {
fn get_total_community_members(
self: @ComponentState<TContractState>, community_id: u256
) -> u256 {
let community = self.communities.read(community_id);
community.community_total_members
}
Expand Down Expand Up @@ -909,7 +910,7 @@ pub mod CommunityComponent {
profile: ContractAddress,
community_nft_address: ContractAddress
) -> u256 {
let token_id = ICommunityNftDispatcher { contract_address: community_nft_address }
let token_id = ICustomNFTDispatcher { contract_address: community_nft_address }
.mint_nft(profile);
token_id
}
Expand All @@ -923,7 +924,7 @@ pub mod CommunityComponent {
profile: ContractAddress,
token_id: u256
) {
ICommunityNftDispatcher { contract_address: community_nft_address }
ICustomNFTDispatcher { contract_address: community_nft_address }
.burn_nft(profile, token_id);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/community/communitynft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod CommunityNFT {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};

use karst::interfaces::ICommunityNft::ICommunityNft;
use karst::interfaces::ICustomNFT::ICustomNFT;

use karst::base::{
constants::errors::Errors::{ALREADY_MINTED, NOT_TOKEN_OWNER, TOKEN_DOES_NOT_EXIST},
Expand Down Expand Up @@ -66,7 +66,7 @@ pub mod CommunityNFT {
}

#[abi(embed_v0)]
impl CommunityNft of ICommunityNft<ContractState> {
impl CommunityNft of ICustomNFT<ContractState> {
// *************************************************************************
// EXTERNAL
// *************************************************************************
Expand Down
34 changes: 33 additions & 1 deletion src/hub/hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub mod KarstHub {
};
use karst::profile::profile::ProfileComponent;
use karst::publication::publication::PublicationComponent;
use openzeppelin::access::ownable::OwnableComponent;
use karst::community::community::CommunityComponent;
use karst::channel::channel::ChannelComponent;
use karst::jolt::jolt::JoltComponent;
use karst::interfaces::IFollowNFT::{IFollowNFTDispatcher, IFollowNFTDispatcherTrait};
use karst::interfaces::IHandle::{IHandleDispatcher, IHandleDispatcherTrait};
use karst::interfaces::IHandleRegistry::{
Expand All @@ -47,6 +51,10 @@ pub mod KarstHub {
// *************************************************************************
component!(path: ProfileComponent, storage: profile, event: ProfileEvent);
component!(path: PublicationComponent, storage: publication, event: PublicationEvent);
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: JoltComponent, storage: jolt, event: JoltEvent);
component!(path: ChannelComponent, storage: channel, event: ChannelEvent);
component!(path: CommunityComponent, storage: community, event: CommunityEvent);

#[abi(embed_v0)]
impl ProfileImpl = ProfileComponent::KarstProfile<ContractState>;
Expand All @@ -55,6 +63,14 @@ pub mod KarstHub {

impl ProfilePrivateImpl = ProfileComponent::Private<ContractState>;


#[abi(embed_v0)]
impl communityImpl = CommunityComponent::KarstCommunity<ContractState>;
impl communityPrivateImpl = CommunityComponent::Private<ContractState>;

#[abi(embed_v0)]
impl channelImpl = ChannelComponent::KarstChannel<ContractState>;

// *************************************************************************
// STORAGE
// *************************************************************************
Expand All @@ -64,6 +80,14 @@ pub mod KarstHub {
profile: ProfileComponent::Storage,
#[substorage(v0)]
publication: PublicationComponent::Storage,
#[substorage(v0)]
jolt: JoltComponent::Storage,
#[substorage(v0)]
ownable: OwnableComponent::Storage,
#[substorage(v0)]
community: CommunityComponent::Storage,
#[substorage(v0)]
channel: ChannelComponent::Storage,
handle_contract_address: ContractAddress,
handle_registry_contract_address: ContractAddress
}
Expand All @@ -75,7 +99,15 @@ pub mod KarstHub {
#[derive(Drop, starknet::Event)]
enum Event {
ProfileEvent: ProfileComponent::Event,
PublicationEvent: PublicationComponent::Event
PublicationEvent: PublicationComponent::Event,
#[flat]
JoltEvent: JoltComponent::Event,
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
CommunityEvent: CommunityComponent::Event,
#[flat]
ChannelEvent: ChannelComponent::Event,
}

// *************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod IHandleRegistry;
pub mod IHub;
pub mod ICommunity;
pub mod ICollectNFT;
pub mod ICommunityNft;
pub mod ICustomNFT;
pub mod IJolt;
pub mod IUpgradeable;
pub mod IChannel;
2 changes: 1 addition & 1 deletion src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait ICommunity<TState> {
fn is_community_member(
self: @TState, profile: ContractAddress, community_id: u256
) -> (bool, CommunityMember);
fn get_total_members(self: @TState, community_id: u256) -> u256;
fn get_total_community_members(self: @TState, community_id: u256) -> u256;
fn is_community_mod(self: @TState, profile: ContractAddress, community_id: u256) -> bool;
fn get_community_censorship_status(self: @TState, community_id: u256) -> bool;
fn get_ban_status(self: @TState, profile: ContractAddress, community_id: u256) -> bool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet::ContractAddress;
// INTERFACE of ICommunity NFT
// *************************************************************************
#[starknet::interface]
pub trait ICommunityNft<TContractState> {
pub trait ICustomNFT<TContractState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
Expand Down
18 changes: 6 additions & 12 deletions src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// *************************************************************************
use starknet::ContractAddress;
use karst::base::constants::types::{
PostParams, RepostParams, CommentParams, PublicationType, Publication
PostParams, RepostParams, CommentParams, PublicationType, Publication, UpVoteParams,
DownVoteParams, TipParams, CollectParams
};

#[starknet::interface]
Expand All @@ -14,17 +15,10 @@ pub trait IKarstPublications<TState> {
fn post(ref self: TState, post_params: PostParams) -> u256;
fn comment(ref self: TState, comment_params: CommentParams) -> u256;
fn repost(ref self: TState, repost_params: RepostParams) -> u256;
fn upvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn downvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn tip(ref self: TState, profile_address: ContractAddress, pub_id: u256, amount: u256);
fn collect(
ref self: TState,
karst_hub: ContractAddress,
profile_address: ContractAddress,
pub_id: u256,
collect_nft_impl_class_hash: felt252,
salt: felt252
) -> u256;
fn upvote(ref self: TState, upvote_params: UpVoteParams);
fn downvote(ref self: TState, downvote_params: DownVoteParams);
fn tip(ref self: TState, tip_params: TipParams);
fn collect(ref self: TState, collect_params: CollectParams) -> u256;
// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
1 change: 0 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ pub mod namespaces;
pub mod presets;
pub mod hub;
pub mod jolt;
pub mod collectnft;
pub mod community;
pub mod channel;
18 changes: 6 additions & 12 deletions src/mocks/interfaces/IComposable.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use starknet::ContractAddress;
use karst::base::constants::types::{
Profile, PublicationType, Publication, RepostParams, PostParams, CommentParams
Profile, PublicationType, Publication, RepostParams, PostParams, CommentParams, UpVoteParams,
DownVoteParams, TipParams, CollectParams
};
// *************************************************************************
// INTERFACE of KARST PROFILE
Expand Down Expand Up @@ -38,17 +39,10 @@ pub trait IComposable<TState> {
fn post(ref self: TState, post_params: PostParams) -> u256;
fn comment(ref self: TState, comment_params: CommentParams) -> u256;
fn repost(ref self: TState, mirror_params: RepostParams) -> u256;
fn upvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn downvote(ref self: TState, profile_address: ContractAddress, pub_id: u256);
fn tip(ref self: TState, profile_address: ContractAddress, pub_id: u256, amount: u256);
fn collect(
ref self: TState,
karst_hub: ContractAddress,
profile_address: ContractAddress,
pub_id: u256,
collect_nft_impl_class_hash: felt252,
salt: felt252
) -> u256;
fn upvote(ref self: TState, upvote_params: UpVoteParams);
fn downvote(ref self: TState, downvote_params: DownVoteParams);
fn tip(ref self: TState, tip_params: TipParams);
fn collect(ref self: TState, collect_params: CollectParams) -> u256;

// *************************************************************************
// GETTERS
Expand Down
Loading

0 comments on commit b1e00cf

Please sign in to comment.