Skip to content

Commit

Permalink
feature: integrate publication feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed Oct 21, 2024
1 parent 6089e8b commit 3bab09d
Show file tree
Hide file tree
Showing 18 changed files with 1,216 additions and 654 deletions.
53 changes: 50 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,9 +105,11 @@ 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,
}


///**
// * @notice A struct containing the parameters supplied to the comment method
// *
Expand All @@ -121,6 +125,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 +159,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 All @@ -172,6 +180,45 @@ pub struct QuoteParams {
pub reference_pub_type: PublicationType
}


#[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,
}


// *************************************************************************
// COMMUNITY
// *************************************************************************
Expand Down
6 changes: 3 additions & 3 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod ChannelComponent {
use karst::community::community::CommunityComponent;
use karst::interfaces::{
IChannel::IChannel, ICommunity::ICommunity,
ICommunityNft::{ICommunityNftDispatcher, ICommunityNftDispatcherTrait}
ICustomNFT::{ICustomNFTDispatcher, ICustomNFTDispatcherTrait}
};
use karst::base::{
constants::errors::Errors::{
Expand Down Expand Up @@ -609,7 +609,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 @@ -622,7 +622,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.

6 changes: 3 additions & 3 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod CommunityComponent {
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 @@ -913,7 +913,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 @@ -927,7 +927,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
46 changes: 44 additions & 2 deletions 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,18 @@ 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>;
impl channelPrivateImpl = ChannelComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl joltImpl = JoltComponent::Jolt<ContractState>;
impl joltPrivateImpl = JoltComponent::Private<ContractState>;
// *************************************************************************
// STORAGE
// *************************************************************************
Expand All @@ -64,6 +84,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 +103,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 All @@ -87,13 +123,19 @@ pub mod KarstHub {
karstnft_contract_address: ContractAddress,
handle_contract_address: ContractAddress,
handle_registry_contract_address: ContractAddress,
follow_nft_classhash: felt252
follow_nft_classhash: felt252,
channel_nft_classhash: felt252,
community_nft_classhash: felt252,
owner: ContractAddress
) {
self
.profile
._initializer(karstnft_contract_address, get_contract_address(), follow_nft_classhash);
self.handle_contract_address.write(handle_contract_address);
self.handle_registry_contract_address.write(handle_registry_contract_address);
self.channel._initializer(channel_nft_classhash);
self.community._initializer(community_nft_classhash);
self.jolt._initializer(owner);
}

#[abi(embed_v0)]
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;
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 3bab09d

Please sign in to comment.