diff --git a/scripts/src/contracts/community.ts b/scripts/src/contracts/community.ts index 7cf608c..b8841b1 100644 --- a/scripts/src/contracts/community.ts +++ b/scripts/src/contracts/community.ts @@ -19,10 +19,12 @@ export const GateKeepType = { } as const; const execute_create_community = async() =>{ + let community_id = cairo.uint256(16); + let call:Call = { to: coloniz_HUB_CONTRACT_ADDRESS, selector:"0x8945c258076d05a649eb76dca07fe609b43b360775b41226e3a345e9593ab4", - calldata:[] + calldata: CallData.compile([community_id]) } try { const Resp = await tokenbound?.execute("0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f", [call]) @@ -33,8 +35,8 @@ const execute_create_community = async() =>{ } const execute_create_channel = async() =>{ - let channel_id = cairo.uint256(15); - let community_id = cairo.uint256(9); + let channel_id = cairo.uint256(29); + let community_id = cairo.uint256(819); let call: Call = { to: coloniz_HUB_CONTRACT_ADDRESS, //coloniz_HUB_CONTRACT_ADDRESS, @@ -51,14 +53,52 @@ const execute_create_channel = async() =>{ } const execute_join_community = async() =>{ + let community_id = cairo.uint256(819); + let call:Call = { to:coloniz_HUB_CONTRACT_ADDRESS, selector:"0x4520555a219f5c8f5c5dba38600b2ef90052dda2c3bd82d24968e43fb54207", - calldata:["0x1"] + calldata: CallData.compile([community_id]) } try { - const Resp = await tokenbound?.execute(PROFILE_ADDRESS_TWO, [call]) + const Resp = await tokenbound?.execute("0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f", [call]) + console.log('execution-response=:', Resp) + } catch (error) { + console.log(error) + } +} + +const execute_add_mod = async() =>{ + let community_id = cairo.uint256(962) + let address = ["0x047e64015c4b5a9fa7a67c0d010c560eb41fbad49573fe78fc3138f0b4ab3e83", "0x014237c152d3e5138bfe1bcae658c72d84c52fe9cc137bf9635f8561bd461bfd"]; + + let call: Call = { + to: coloniz_HUB_CONTRACT_ADDRESS, + selector: "0x020855da45f2c45300363a4ad7339e4c49de86fa97280baafa3137c2531a22e3", + calldata: CallData.compile([community_id, address]) + } + + try { + const Resp = await tokenbound?.execute("0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f", [call]) + console.log('execution-response=:', Resp) + } catch (error) { + console.log(error) + } +} + +const execute_add_channel_mod = async() =>{ + let channel_id = cairo.uint256(7) + let address = ["0x0688008cb60a5d23689df1ebcbb5e15704e83642d453957441cdbeeda81bdb2c", "0x014237c152d3e5138bfe1bcae658c72d84c52fe9cc137bf9635f8561bd461bfd"]; + + let call: Call = { + to: coloniz_HUB_CONTRACT_ADDRESS, + selector: "0x01056471e50214407d31a6ca2fa3b9250e350d89827032cd741552145ea28090", + calldata: CallData.compile([channel_id, address]) + } + + try { + const Resp = await tokenbound?.execute("0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f", [call]) console.log('execution-response=:', Resp) } catch (error) { console.log(error) @@ -181,9 +221,9 @@ const execute_downvote = async () => { // create subscription const create_subscription = async() => { - let erc20_address:string = "0x006e1698dcd0665757dd213a59aff489624bab8c970ce0482c23937a78879b04"; - let admin: string = "0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f"; - let amount = cairo.uint256(50); + let erc20_address:string = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"; + let admin: string = "0x02d904Aedff382C0D68F22444B525146ec5eA2926e271fC411845e8D9E751DE1"; + let amount = cairo.uint256(10000000000000000000); let call: Call = { to: coloniz_HUB_CONTRACT_ADDRESS, @@ -307,13 +347,15 @@ const execute_gatekeep = async() =>{ } // execute_get_community(); -// execute_create_community(123); +// execute_create_community(); // execute_upgrade() // execute_gatekeep() // set_fee_address() // set_permissioned_address() // create_subscription() -execute_create_channel(); +// execute_create_channel(); +execute_add_mod(); +// execute_add_channel_mod(); // execute_join_community(); // execute_make_post(); // execute_add_comment() diff --git a/src/base/constants/types.cairo b/src/base/constants/types.cairo index 66a6c67..f9fe1b7 100644 --- a/src/base/constants/types.cairo +++ b/src/base/constants/types.cairo @@ -20,7 +20,7 @@ pub struct Profile { } // ************************************************************************* -// TOKEN URIs +// PROFILE TOKEN URIs // ************************************************************************* #[derive(Copy, Drop, Serde, starknet::Store, Clone)] pub enum ToolVariants { diff --git a/src/channel/channel.cairo b/src/channel/channel.cairo index 73216a5..a594163 100644 --- a/src/channel/channel.cairo +++ b/src/channel/channel.cairo @@ -171,7 +171,6 @@ pub mod ChannelComponent { // check user is not already a channel member and wasn't previously banned let (is_channel_member, _) = self.is_channel_member(profile, channel_id); let is_banned = self.get_channel_ban_status(profile, channel_id); - assert(!is_banned, BANNED_FROM_CHANNEL); assert(!is_channel_member, ALREADY_MEMBER); @@ -201,13 +200,13 @@ pub mod ChannelComponent { ChannelMember { profile: contract_address_const::<0>(), channel_id: 0, - total_publications: 0, - // channel_token_id: 0, + total_publications: 0 } ); channel.channel_total_members -= 1; self.channels.write(channel_id, channel); + // emit event self .emit( @@ -433,7 +432,6 @@ pub mod ChannelComponent { channel_id: channel_id, transaction_executor: get_caller_address(), profile: profile, - // token_id: minted_token_id, block_timestamp: get_block_timestamp(), } ) @@ -527,6 +525,7 @@ pub mod ChannelComponent { let (is_channel_member, _) = self.is_channel_member(profile, channel_id); assert(is_channel_member == true, NOT_CHANNEL_MEMBER); self.channel_ban_status.write((channel_id, profile), ban_status); + self .emit( ChannelBanStatusUpdated { diff --git a/src/community/community.cairo b/src/community/community.cairo index b6025cc..d416cf3 100644 --- a/src/community/community.cairo +++ b/src/community/community.cairo @@ -191,8 +191,9 @@ pub mod CommunityComponent { // check user is not already a member and wasn't previously banned let (is_community_member, _) = self.is_community_member(profile, community_id); - let is_banned = self.get_ban_status(profile, community_id); assert(is_community_member != true, ALREADY_MEMBER); + + let is_banned = self.get_ban_status(profile, community_id); assert(is_banned != true, BANNED_MEMBER); // enforce gatekeeping rules diff --git a/src/community/communitynft.cairo b/src/community/communitynft.cairo index 13de5c6..a369d90 100644 --- a/src/community/communitynft.cairo +++ b/src/community/communitynft.cairo @@ -103,7 +103,7 @@ pub mod CommunityNFT { self.last_minted_id.write(token_id); self.mint_timestamp.write(token_id, timestamp); - self.last_minted_id.read() + token_id } /// @notice burns a community NFT @@ -111,6 +111,7 @@ pub mod CommunityNFT { fn burn_nft(ref self: ContractState, user_address: ContractAddress, token_id: u256) { let user_token_id = self.user_token_id.read(user_address); assert(user_token_id == token_id, NOT_TOKEN_OWNER); + // check the token exists assert(self.erc721.exists(token_id), TOKEN_DOES_NOT_EXIST); self.erc721.burn(token_id); diff --git a/src/follownft/follownft.cairo b/src/follownft/follownft.cairo index 22ae23f..219102d 100644 --- a/src/follownft/follownft.cairo +++ b/src/follownft/follownft.cairo @@ -140,6 +140,7 @@ pub mod Follow { let prefix: ByteArray = "Coloniz Followers | #"; let profile_id: felt252 = self.token_id.read().low.into(); let name = format!("{}{}", prefix, profile_id); + self.erc721.initializer(name, "CLZ:FOLLOWERS", ""); } @@ -156,6 +157,7 @@ pub mod Follow { .follow_id_by_follower_profile_address .read(follower_profile_address); assert(follow_id.is_zero(), Errors::FOLLOWING); + self._follow(follower_profile_address) } @@ -168,6 +170,7 @@ pub mod Follow { .follow_id_by_follower_profile_address .read(unfollower_profile_address); assert(follow_id.is_non_zero(), Errors::NOT_FOLLOWING); + self._unfollow(unfollower_profile_address, follow_id); } @@ -177,10 +180,12 @@ pub mod Follow { ref self: ContractState, follower_profile_address: ContractAddress ) -> bool { hub_only(self.coloniz_hub.read()); + let follow_id = self .follow_id_by_follower_profile_address .read(follower_profile_address); assert(follow_id.is_non_zero(), Errors::NOT_FOLLOWING); + let follow_data = self.follow_data_by_follow_id.read(follow_id); self @@ -204,6 +209,7 @@ pub mod Follow { timestamp: get_block_timestamp() } ); + return true; } @@ -213,9 +219,11 @@ pub mod Follow { ref self: ContractState, follower_profile_address: ContractAddress ) -> bool { hub_only(self.coloniz_hub.read()); + let follow_id = self .follow_id_by_follower_profile_address .read(follower_profile_address); + let follow_data = self.follow_data_by_follow_id.read(follow_id); assert(follow_data.block_status == true, Errors::USER_NOT_BLOCKED); @@ -347,6 +355,7 @@ pub mod Follow { .write(follower_profile_address, new_follower_id); self.follow_data_by_follow_id.write(new_follower_id, follow_data); self.follower_count.write(self.follower_count.read() + 1); + self .emit( Followed { @@ -377,6 +386,7 @@ pub mod Follow { } ); self.follower_count.write(self.follower_count.read() - 1); + self .emit( Unfollowed { diff --git a/src/namespaces/handle_registry.cairo b/src/namespaces/handle_registry.cairo index a25c027..2a9c48d 100644 --- a/src/namespaces/handle_registry.cairo +++ b/src/namespaces/handle_registry.cairo @@ -89,14 +89,14 @@ pub mod HandleRegistry { #[abi(embed_v0)] impl HandleRegistryImpl of IHandleRegistry { /// @notice links a profile address to a handle - /// @param handle_id ID of handle to be linked + /// @param handle_id token ID of handle to be linked /// @param profile_address address of profile to be linked fn link(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) { self._link(handle_id, profile_address); } /// @notice unlinks a profile address from a handle - /// @param handle_id ID of handle to be unlinked + /// @param handle_id token ID of handle to be unlinked /// @param profile_address address of profile to be unlinked fn unlink(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) { let caller = get_caller_address(); @@ -117,11 +117,12 @@ pub mod HandleRegistry { // ************************************************************************* /// @notice resolves a handle to a profile address - /// @param handle_id ID of handle to be resolved + /// @param handle_id token ID of handle to be resolved fn resolve(self: @ContractState, handle_id: u256) -> ContractAddress { let it_exists = IHandleDispatcher { contract_address: self.handle_address.read() } .exists(handle_id); assert(it_exists, Errors::HANDLE_DOES_NOT_EXIST); + self.handle_to_profile_address.read(handle_id) } @@ -138,7 +139,7 @@ pub mod HandleRegistry { #[generate_trait] impl Private of PrivateTrait { /// @notice internal function to link a profile address to a handle - /// @param handle_id ID of handle to be linked + /// @param handle_id token ID of handle to be linked /// @param profile_address address of profile to be linked fn _link(ref self: ContractState, handle_id: u256, profile_address: ContractAddress) { let owner = IERC721Dispatcher { contract_address: self.handle_address.read() } @@ -163,7 +164,7 @@ pub mod HandleRegistry { } /// @notice internal function to unlink a profile address from a handle - /// @param handle_id ID of handle to be unlinked + /// @param handle_id token ID of handle to be unlinked /// @param profile_address address of profile to be unlinked /// @param caller address of user calling this function fn _unlink( diff --git a/src/namespaces/handles.cairo b/src/namespaces/handles.cairo index 3f24d1d..03258b9 100644 --- a/src/namespaces/handles.cairo +++ b/src/namespaces/handles.cairo @@ -70,7 +70,7 @@ pub mod Handles { // CONSTANTS // ************************************************************************* const MAX_LOCAL_NAME_LENGTH: u256 = 26; - const NAMESPACE: felt252 = 'kst'; + const NAMESPACE: felt252 = 'clz'; const ASCII_A: u8 = 97; const ASCII_Z: u8 = 122; const ASCII_0: u8 = 48; @@ -141,11 +141,14 @@ pub mod Handles { /// @param token_id ID of handle to be burnt fn burn_handle(ref self: ContractState, token_id: u256) { assert(get_caller_address() == self.erc721.owner_of(token_id), Errors::INVALID_OWNER); + let current_supply = self.total_supply.read(); let local_name = self.local_names.read(token_id); + self.erc721.burn(token_id); self.total_supply.write(current_supply - 1); self.local_names.write(token_id, 0); + self .emit( HandleBurnt { @@ -185,9 +188,11 @@ pub mod Handles { fn get_handle(self: @ContractState, token_id: u256) -> ByteArray { let local_name = self.get_local_name(token_id); assert(local_name.is_non_zero(), Errors::HANDLE_DOES_NOT_EXIST); + let local_name_in_byte_array: ByteArray = local_name.try_into().unwrap(); let namespace_in_byte_array: ByteArray = NAMESPACE.try_into().unwrap(); let handle = local_name_in_byte_array + "." + namespace_in_byte_array; + handle } @@ -246,12 +251,11 @@ pub mod Handles { ref self: ContractState, address: ContractAddress, local_name: felt252, ) -> u256 { let token_id = self.get_token_id(local_name); - let mut current_total_supply = self.total_supply.read(); - current_total_supply += 1; - self.total_supply.write(current_total_supply); - + let current_total_supply = self.total_supply.read(); self.erc721.mint(address, token_id); + self.local_names.write(token_id, local_name); + self.total_supply.write(current_total_supply + 1); self .emit( diff --git a/src/profile/profile.cairo b/src/profile/profile.cairo index 048b719..39e366a 100644 --- a/src/profile/profile.cairo +++ b/src/profile/profile.cairo @@ -71,6 +71,7 @@ pub mod ProfileComponent { profile_variants: ProfileVariants ) -> ContractAddress { let coloniz_nft_address = self.coloniz_nft_address.read(); + // mint coloniz nft let recipient = get_caller_address(); let owns_coloniznft = IERC721Dispatcher { contract_address: coloniz_nft_address } @@ -83,6 +84,7 @@ pub mod ProfileComponent { .get_user_token_id(recipient); let tx_info = get_tx_info().unbox(); let chain_id = tx_info.chain_id; + // create tokenbound account let profile_address = IRegistryDispatcher { contract_address: registry_contract_address diff --git a/tests/test_handle.cairo b/tests/test_handle.cairo index d66e552..757a759 100644 --- a/tests/test_handle.cairo +++ b/tests/test_handle.cairo @@ -171,7 +171,7 @@ fn test_get_handle() { let handle: ByteArray = handles_dispatcher.get_handle(token_id); - assert(handle == "coloniz.kst", 'Invalid handle'); + assert(handle == "coloniz.clz", 'Invalid handle'); } #[test] diff --git a/tests/test_hub.cairo b/tests/test_hub.cairo index 69fe58a..8a75d35 100644 --- a/tests/test_hub.cairo +++ b/tests/test_hub.cairo @@ -292,5 +292,5 @@ fn test_get_handle() { let dispatcher = IHubDispatcher { contract_address: hub_contract_address }; let handle = dispatcher.get_handle(minted_handle_id); - assert(handle == "user.kst", 'invalid handle id'); + assert(handle == "user.clz", 'invalid handle id'); }