Skip to content

Commit

Permalink
chore: review contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Feb 20, 2025
1 parent fb51bb9 commit 7e52ac7
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 29 deletions.
62 changes: 52 additions & 10 deletions scripts/src/contracts/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Profile {
}

// *************************************************************************
// TOKEN URIs
// PROFILE TOKEN URIs
// *************************************************************************
#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum ToolVariants {
Expand Down
7 changes: 3 additions & 4 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
}
)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/community/communitynft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ 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
/// @param address address of user trying to burn the community NFT token
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);
Expand Down
10 changes: 10 additions & 0 deletions src/follownft/follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
}

Expand All @@ -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)
}

Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -204,6 +209,7 @@ pub mod Follow {
timestamp: get_block_timestamp()
}
);

return true;
}

Expand All @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -377,6 +386,7 @@ pub mod Follow {
}
);
self.follower_count.write(self.follower_count.read() - 1);

self
.emit(
Unfollowed {
Expand Down
11 changes: 6 additions & 5 deletions src/namespaces/handle_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ pub mod HandleRegistry {
#[abi(embed_v0)]
impl HandleRegistryImpl of IHandleRegistry<ContractState> {
/// @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();
Expand All @@ -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)
}

Expand All @@ -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() }
Expand All @@ -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(
Expand Down
14 changes: 9 additions & 5 deletions src/namespaces/handles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/profile/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_handle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

0 comments on commit 7e52ac7

Please sign in to comment.