diff --git a/scripts/src/contracts/community.ts b/scripts/src/contracts/community.ts index 9297db4..54306af 100644 --- a/scripts/src/contracts/community.ts +++ b/scripts/src/contracts/community.ts @@ -233,7 +233,7 @@ const create_subscription = async() => { // execute upgrade const execute_upgrade = async() => { - let community_id = cairo.uint256(1); + let community_id = cairo.uint256(5); let community_type = new CairoCustomEnum({ Business: {} }); let erc20_address:string = "0x006e1698dcd0665757dd213a59aff489624bab8c970ce0482c23937a78879b04"; let sub_id: Uint256 = cairo.uint256( @@ -265,12 +265,12 @@ const execute_upgrade = async() => { // execute gatekeep const execute_gatekeep = async() =>{ - let community_id = cairo.uint256(3); - let gatekeep_type = new CairoCustomEnum({ [GateKeepType.PaidGating]: {} }); + let community_id = cairo.uint256(4); + let gatekeep_type = new CairoCustomEnum({ [GateKeepType.PermissionedGating]: {} }); let permissioned_address = [1, "0x075a4558a2e9d8b10fdb3d94d51b35312703cc7aae43a1ff95e234512e83783f"]; let erc20_address:string = "0x006e1698dcd0665757dd213a59aff489624bab8c970ce0482c23937a78879b04"; let amount = cairo.uint256(50); - let erc721_address = "0x036053a7520d7ff5cb1ce8ebec7acaf8b6364130865662937ab1e2a36d4e00c1"; + let erc721_address = "0x0000003697660a0981d734780731949ecb2b4a38d6a58fc41629ed611e8defda"; let paid_gating_details = { "0": erc20_address, "1": amount @@ -299,9 +299,9 @@ const execute_gatekeep = async() =>{ // execute_get_community(); // execute_create_community(); +// execute_upgrade() execute_gatekeep() // create_subscription() -// execute_upgrade() // execute_create_channel(); // execute_join_community(); // execute_make_post(); diff --git a/src/base/constants/errors.cairo b/src/base/constants/errors.cairo index d44888b..1d74e04 100644 --- a/src/base/constants/errors.cairo +++ b/src/base/constants/errors.cairo @@ -24,6 +24,7 @@ pub mod Errors { pub const COMMUNITY_DOES_NOT_EXIST: felt252 = 'coloniz: Comm does not exist'; pub const NOT_COMMUNITY_OWNER: felt252 = 'coloniz: Not Community owner'; pub const ONLY_PREMIUM_COMMUNITIES: felt252 = 'coloniz: not premium community'; + pub const INVALID_UPGRADE: felt252 = 'coloniz: invalid upgrade type'; pub const NOT_COMMUNITY_MEMBER: felt252 = 'coloniz: Not Community Member'; pub const NOT_COMMUNITY_MOD: felt252 = 'coloniz: Not a community mod'; pub const BANNED_MEMBER: felt252 = 'coloniz: Profile is banned!'; diff --git a/src/community/community.cairo b/src/community/community.cairo index b2dffed..add793e 100644 --- a/src/community/community.cairo +++ b/src/community/community.cairo @@ -26,7 +26,7 @@ pub mod CommunityComponent { }; use coloniz::base::constants::errors::Errors::{ ALREADY_MEMBER, NOT_COMMUNITY_OWNER, NOT_COMMUNITY_MEMBER, NOT_COMMUNITY_MOD, BANNED_MEMBER, - UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH + UNAUTHORIZED, ONLY_PREMIUM_COMMUNITIES, INVALID_LENGTH, INVALID_UPGRADE }; // ************************************************************************* @@ -313,6 +313,7 @@ pub mod CommunityComponent { // check community owner is caller let community_owner = self.communities.read(community_id).community_owner; assert(community_owner == get_caller_address(), NOT_COMMUNITY_OWNER); + assert(upgrade_type != CommunityType::Free, INVALID_UPGRADE); self ._upgrade_community( @@ -386,14 +387,28 @@ pub mod CommunityComponent { ); } + /// @notice sets permissioned addresses for a community + /// @param community_id The id of the community + /// /// @param permissioned_addresses array of addresses to set for permissioned gatekeeping + fn set_permissioned_addresses( + ref self: ComponentState, community_id: u256, + permissioned_addresses: Array + ) { + // check caller is owner + let mut community = self.communities.read(community_id); + assert(community.community_owner == get_caller_address(), UNAUTHORIZED); + + // set permissioned addresses + self._permissioned_gatekeeping(community_id, permissioned_addresses); + } + /// @notice set the censorship status of a community /// @param community_id The id of the community fn set_community_censorship_status( ref self: ComponentState, community_id: u256, censorship_status: bool ) { - let mut community = self.communities.read(community_id); - // check caller is owner + let mut community = self.communities.read(community_id); assert(community.community_owner == get_caller_address(), UNAUTHORIZED); // update storage @@ -513,6 +528,15 @@ pub mod CommunityComponent { (true, gatekeep_details) } + + /// @notice checks if an address has permissions to join a community + /// @param community_id id of community to check + /// @return bool permissioned status of the address + fn is_permissioned_address( + self: @ComponentState, community_id: u256, address: ContractAddress + ) -> bool { + self.gate_keep_permissioned_addresses.read((community_id, address)) + } } // ************************************************************************* diff --git a/src/interfaces/ICommunity.cairo b/src/interfaces/ICommunity.cairo index ef12058..b773865 100644 --- a/src/interfaces/ICommunity.cairo +++ b/src/interfaces/ICommunity.cairo @@ -48,6 +48,11 @@ pub trait ICommunity { permissioned_addresses: Array, paid_gating_details: (ContractAddress, u256), ); + fn set_permissioned_addresses( + ref self: TState, + community_id: u256, + permissioned_addresses: Array + ); // ************************************************************************* // GETTERS @@ -64,4 +69,5 @@ pub trait ICommunity { fn get_community_fee_address(self: @TState, community_id: u256) -> ContractAddress; fn is_premium_community(self: @TState, community_id: u256) -> (bool, CommunityType); fn is_gatekeeped(self: @TState, community_id: u256) -> (bool, CommunityGateKeepDetails); + fn is_permissioned_address(self: @TState, community_id: u256, address: ContractAddress) -> bool; }