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

feature: integrate publication contract with community & channel cont… #130

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 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
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
50 changes: 45 additions & 5 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 Expand Up @@ -190,9 +232,7 @@ pub mod KarstHub {
let dispatcher = IHandleRegistryDispatcher {
contract_address: self.handle_registry_contract_address.read()
};

let handle_id = dispatcher.get_handle(profile_address);
handle_id
dispatcher.get_handle(profile_address)
}

/// @notice returns the full handle of a user
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
30 changes: 25 additions & 5 deletions src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,36 @@ 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 upvote(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256
);
fn downvote(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256
);
fn tip(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
amount: u256,
channel_id: u256,
community_id: u256,
erc20_contract_address: ContractAddress,
);
fn collect(
ref self: TState,
karst_hub: ContractAddress,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256,
collect_nft_impl_class_hash: felt252,
salt: felt252
) -> 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;
32 changes: 26 additions & 6 deletions src/mocks/interfaces/IComposable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,37 @@ pub trait IComposable<TState> {
fn initialize(ref self: TState, hub_address: ContractAddress);
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 repost(ref self: TState, repost_params: RepostParams) -> u256;
fn upvote(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256
);
fn downvote(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256
);
fn tip(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256,
amount: u256,
channel_id: u256,
community_id: u256,
erc20_contract_address: ContractAddress,
);
fn collect(
ref self: TState,
karst_hub: ContractAddress,
profile_address: ContractAddress,
pub_id: u256,
channel_id: u256,
community_id: u256,
collect_nft_impl_class_hash: felt252,
salt: felt252
) -> u256;

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