Skip to content

Commit

Permalink
function to deploy community nft
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Oct 3, 2024
1 parent c364b22 commit 9cbc6ea
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ mod CommunityComponent {
CommunityBanStatusUpdated: CommunityBanStatusUpdated,
CommunityModRemoved: CommunityModRemoved,
CommunityUpgraded: CommunityUpgraded,
CommunityGatekeeped: CommunityGatekeeped
CommunityGatekeeped: CommunityGatekeeped,
DeployedCommunityNFT: DeployedCommunityNFT
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -109,6 +110,14 @@ mod CommunityComponent {
block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct DeployedCommunityNFT {
community_id: u256,
profile_address: ContractAddress,
community_nft: ContractAddress,
block_timestamp: u64,
}

// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
Expand Down Expand Up @@ -505,7 +514,64 @@ mod CommunityComponent {
}
}
// *************************************************************************
// PRIVATE FUNCTIONS
// *************************************************************************
// PRIVATE FUNCTIONS
// *************************************************************************

fn _get_or_deploy_collect_nft(
ref self: ComponentState<TContractState>,
karst_hub: ContractAddress,
profile_address: ContractAddress,
community_id: u256,
community_nft_impl_class_hash: felt252,
salt: felt252
) -> ContractAddress {
let mut commuity = self.communities(community_id);
let community_nft = commuity.community_nft_address;
if community_nft.is_zero() {
// Deploy a new Collect NFT contract
let deployed_collect_nft_address = self
._deploy_community_nft(
karst_hub, profile_address, community_id, community_nft_impl_class_hash, salt
);

// Update the community with the deployed Collect NFT address
let updated_community = CommunityDetails {
community_nft_address: deployed_collect_nft_address, ..commuity
};

// Write the updated community with the new Community NFT address
self.communities.write(community_id, updated_community);
}
commuity.community_nft_address
}

fn _deploy_community_nft(
ref self: ComponentState<TContractState>,
karst_hub: ContractAddress,
profile_address: ContractAddress,
community_id: u256,
community_nft_impl_class_hash: felt252,
salt: felt252
) -> ContractAddress {
let mut constructor_calldata: Array<felt252> = array![
karst_hub.into(),
profile_address.into(),
community_id.low.into(),
community_id.high.into()
];
let class_hash: ClassHash = community_nft_impl_class_hash.try_into().unwrap();
let result = deploy_syscall(class_hash, salt, constructor_calldata.span(), true);
let (account_address, _) = result.unwrap_syscall();

self
.emit(
DeployedCommunityNFT {
community_id: community_id,
profile_address: profile_address,
community_nft: account_address,
block_timestamp: get_block_timestamp()
}
);
account_address
}
}

0 comments on commit 9cbc6ea

Please sign in to comment.