From bd347cd2412a1dfc7c1006dd04e6fd7b9c8c2479 Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Sat, 31 Aug 2024 09:59:19 +0530 Subject: [PATCH 1/6] Update registry.cairo --- src/core/registry.cairo | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index c96217d..2463915 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -30,6 +30,8 @@ struct Metadata { #[starknet::interface] pub trait IRegistry { fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool; + fn is_member_of_profile(self: @TContractState, profile_id: u256, member: ContractAddress) -> bool; + fn is_owner_or_member_of_profile(self: @TContractState, profile_id: u256, account: ContractAddress) -> bool; fn update_profile_pending_owner( ref self: TContractState, profile_id: u256, pending_owner: ContractAddress ); @@ -39,7 +41,7 @@ pub trait IRegistry { } #[starknet::contract] pub mod Registry { - use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; +use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; use alexandria_bytes::{Bytes, BytesTrait}; use starknet::ContractAddress; use core::poseidon::PoseidonTrait; @@ -195,6 +197,13 @@ pub mod Registry { // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L229 + fn is_owner_or_member_of_profile( + self: @ContractState, profile_id: u256, account: ContractAddress + ) -> bool { + return self._is_owner_of_profile(profile_id, account) || self.is_member_of_profile(profile_id, account); + } + + // Issue no. #3 Implement the functionality of isOwnerOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 @@ -208,6 +217,12 @@ pub mod Registry { // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 + fn is_member_of_profile( + self: @ContractState, profile_id:u256, member: ContractAddress + ) -> bool { + return self.is_member_of_profile(profile_id, member); + } + // Issue no. #9 Implement the functionality of UpdateProfilePendingOwner // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L253 From 3334b9f317cc573921ff72ec35cf483c9ff8d71c Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Tue, 3 Sep 2024 18:08:29 +0530 Subject: [PATCH 2/6] Executed command Scarb fmt --- src/core/registry.cairo | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index 2463915..23de9c3 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -23,15 +23,20 @@ struct Metadata { // allo.gitcoin.co /// Registry contract -/// Solidity equivalent: https://github.com/allo-protocol/allo-v2/blob/main/contracts/core/Registry.sol +/// Solidity equivalent: +/// https://github.com/allo-protocol/allo-v2/blob/main/contracts/core/Registry.sol /// Registry contract interface /// Interface for the Registry contract. #[starknet::interface] pub trait IRegistry { fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool; - fn is_member_of_profile(self: @TContractState, profile_id: u256, member: ContractAddress) -> bool; - fn is_owner_or_member_of_profile(self: @TContractState, profile_id: u256, account: ContractAddress) -> bool; + fn is_member_of_profile( + self: @TContractState, profile_id: u256, member: ContractAddress + ) -> bool; + fn is_owner_or_member_of_profile( + self: @TContractState, profile_id: u256, account: ContractAddress + ) -> bool; fn update_profile_pending_owner( ref self: TContractState, profile_id: u256, pending_owner: ContractAddress ); @@ -41,7 +46,7 @@ pub trait IRegistry { } #[starknet::contract] pub mod Registry { -use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; + use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; use alexandria_bytes::{Bytes, BytesTrait}; use starknet::ContractAddress; use core::poseidon::PoseidonTrait; @@ -144,7 +149,7 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; > { // Issue no. #15 Implement the functionality to retrieve profile by profileId // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L94 - // Use _profileID as u256 + // Use _profileID as u256 fn get_profile_by_id(self: @ContractState, profile_id: u256) -> Profile { return self.profiles_by_id.read(profile_id); @@ -200,7 +205,8 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; fn is_owner_or_member_of_profile( self: @ContractState, profile_id: u256, account: ContractAddress ) -> bool { - return self._is_owner_of_profile(profile_id, account) || self.is_member_of_profile(profile_id, account); + return self._is_owner_of_profile(profile_id, account) + || self.is_member_of_profile(profile_id, account); } @@ -218,7 +224,7 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 fn is_member_of_profile( - self: @ContractState, profile_id:u256, member: ContractAddress + self: @ContractState, profile_id: u256, member: ContractAddress ) -> bool { return self.is_member_of_profile(profile_id, member); } @@ -258,12 +264,12 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; i += 1; } } - // Issue no. #6 Implement the functionality of removeMembers + // Issue no. #6 Implement the functionality of removeMembers // Use u256 instead of bytes32 // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L311 - // Issue no. #16 Implement the functionality of recoverFunds + // Issue no. #16 Implement the functionality of recoverFunds // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L392C14-L392C26 @@ -276,10 +282,13 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; impl RegistryInternalImpl of RegistryInternalTrait { // Issue no. #19 Implement the functionality of _generateProfileId // Internal function to create a profile // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L366 - // Reference on how to implement keccak256(abi.encodePacked) - // Solidity - https://github.com/celestiaorg/blobstream-contracts/blob/0b4bcf69d1ce96df000da7f95fba8c03aa15a45e/src/lib/tree/namespace/TreeHasher.sol#L33 - // Cairo - https://github.com/keep-starknet-strange/blobstream-starknet/blob/b74777e5fb479e5b4aa5a1419135e0826343fc37/src/tree/namespace/hasher.cairo#L10 - // More about it - https://github.com/keep-starknet-strange/alexandria/tree/main/src/encoding + // Reference on how to implement keccak256(abi.encodePacked) + // Solidity - + // https://github.com/celestiaorg/blobstream-contracts/blob/0b4bcf69d1ce96df000da7f95fba8c03aa15a45e/src/lib/tree/namespace/TreeHasher.sol#L33 + // Cairo - + // https://github.com/keep-starknet-strange/blobstream-starknet/blob/b74777e5fb479e5b4aa5a1419135e0826343fc37/src/tree/namespace/hasher.cairo#L10 + // More about it - + // https://github.com/keep-starknet-strange/alexandria/tree/main/src/encoding // Issue no. #18 Implement the functionality of _generateAnchor // Internal function to create a _generateAnchor @@ -308,7 +317,7 @@ use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; ) -> bool { return self.profiles_by_id.read(_profile_id).owner == _owner; } - // Issue n. #5 Implement the functionality of _isMemberOfProfile + // Issue n. #5 Implement the functionality of _isMemberOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 From f100e38c02ca177d157fd0f2e1b97fb86e22d32b Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Sun, 8 Sep 2024 13:34:50 +0530 Subject: [PATCH 3/6] Pending changes --- src/core/registry.cairo | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index 23de9c3..f0fcc0f 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -6,7 +6,6 @@ struct Metadata { pointer: ByteArray, } - // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ @@ -82,6 +81,7 @@ pub mod Registry { metadata: Metadata, } + #[derive(Drop, Serde, starknet::Store)] pub struct Profile { id: u256, @@ -92,6 +92,7 @@ pub mod Registry { anchor: ContractAddress, } + #[derive(Drop, starknet::Event)] struct ProfilePendingOwnerUpdated { #[key] @@ -206,7 +207,7 @@ pub mod Registry { self: @ContractState, profile_id: u256, account: ContractAddress ) -> bool { return self._is_owner_of_profile(profile_id, account) - || self.is_member_of_profile(profile_id, account); + || self._is_member_of_profile(profile_id, account); } @@ -226,7 +227,7 @@ pub mod Registry { fn is_member_of_profile( self: @ContractState, profile_id: u256, member: ContractAddress ) -> bool { - return self.is_member_of_profile(profile_id, member); + return self._is_member_of_profile(profile_id, member); } // Issue no. #9 Implement the functionality of UpdateProfilePendingOwner @@ -318,8 +319,14 @@ pub mod Registry { return self.profiles_by_id.read(_profile_id).owner == _owner; } // Issue n. #5 Implement the functionality of _isMemberOfProfile - // Down below is the function that is to be implemented in the contract but in cairo. - // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 - + // Down below is the function that is to be implemented in the contract but in cairo. + // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 + fn _is_member_of_profile( + self: @ContractState, _profile_id: u256, _owner: ContractAddress + ) -> bool { + let _profile_id: felt252 = _profile_id.try_into().unwrap(); + return self.accessControl.has_role(_profile_id, _owner); + } } } + From 6685e8a45e05b78ac649916e505136672ccf1173 Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Sun, 15 Sep 2024 10:59:04 +0530 Subject: [PATCH 4/6] Implmented the Remove member --- src/core/registry.cairo | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index f0fcc0f..7b15310 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -40,6 +40,7 @@ pub trait IRegistry { ref self: TContractState, profile_id: u256, pending_owner: ContractAddress ); fn add_members(ref self: TContractState, profile_Id: u256, members: Array); + fn remove_members(ref self: TContractState, profile_Id: u256, members: Array); fn update_profile_metadata(ref self: TContractState, profile_id: u256, metadata: Metadata); fn get_profile_by_id(self: @TContractState, profile_id: u256) -> Registry::Profile; } @@ -266,10 +267,25 @@ pub mod Registry { } } // Issue no. #6 Implement the functionality of removeMembers - // Use u256 instead of bytes32 - // Down below is the function that is to be implemented in the contract but in cairo. - // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L311 + // Use u256 instead of bytes32 + // Down below is the function that is to be implemented in the contract but in cairo. + // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L311 + fn remove_members( + ref self: ContractState, profile_Id: u256, members: Array + ) { + let profile_id: felt252 = profile_Id.try_into().unwrap(); + self.member_length.write(members.len().into()); + let mut i = 0; + loop { + if (i >= members.len().into()) { + break; + } + let member: ContractAddress = *members.at(i); + self.accessControl._revoke_role(profile_id, member); + i += 1; + } + } // Issue no. #16 Implement the functionality of recoverFunds // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L392C14-L392C26 From 32a8bfc532f052ed29a5404e9cc3b5d808e4be78 Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Sun, 15 Sep 2024 11:03:07 +0530 Subject: [PATCH 5/6] Pending changes --- src/core/registry.cairo | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index 7b15310..ff73c83 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -30,12 +30,8 @@ struct Metadata { #[starknet::interface] pub trait IRegistry { fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool; - fn is_member_of_profile( - self: @TContractState, profile_id: u256, member: ContractAddress - ) -> bool; - fn is_owner_or_member_of_profile( - self: @TContractState, profile_id: u256, account: ContractAddress - ) -> bool; + + fn update_profile_pending_owner( ref self: TContractState, profile_id: u256, pending_owner: ContractAddress ); @@ -204,12 +200,7 @@ pub mod Registry { // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L229 - fn is_owner_or_member_of_profile( - self: @ContractState, profile_id: u256, account: ContractAddress - ) -> bool { - return self._is_owner_of_profile(profile_id, account) - || self._is_member_of_profile(profile_id, account); - } + // Issue no. #3 Implement the functionality of isOwnerOfProfile @@ -224,13 +215,7 @@ pub mod Registry { // Issue no. #5 Implement the functionality of isMemberOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 - - fn is_member_of_profile( - self: @ContractState, profile_id: u256, member: ContractAddress - ) -> bool { - return self._is_member_of_profile(profile_id, member); - } - ++ // Issue no. #9 Implement the functionality of UpdateProfilePendingOwner // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L253 @@ -337,12 +322,7 @@ pub mod Registry { // Issue n. #5 Implement the functionality of _isMemberOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 - fn _is_member_of_profile( - self: @ContractState, _profile_id: u256, _owner: ContractAddress - ) -> bool { - let _profile_id: felt252 = _profile_id.try_into().unwrap(); - return self.accessControl.has_role(_profile_id, _owner); - } + } } From fc0fb8ee0dce9e32ca42396f2c82f8c3c3acb515 Mon Sep 17 00:00:00 2001 From: Manush Sanchela Date: Sun, 15 Sep 2024 11:08:24 +0530 Subject: [PATCH 6/6] Final changes and checks --- src/core/registry.cairo | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/core/registry.cairo b/src/core/registry.cairo index ff73c83..55db33c 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -30,7 +30,7 @@ struct Metadata { #[starknet::interface] pub trait IRegistry { fn is_owner_of_profile(self: @TContractState, profile_id: u256, owner: ContractAddress) -> bool; - + fn update_profile_pending_owner( ref self: TContractState, profile_id: u256, pending_owner: ContractAddress @@ -200,9 +200,6 @@ pub mod Registry { // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L229 - - - // Issue no. #3 Implement the functionality of isOwnerOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 @@ -215,7 +212,7 @@ pub mod Registry { // Issue no. #5 Implement the functionality of isMemberOfProfile // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L245 -+ + // Issue no. #9 Implement the functionality of UpdateProfilePendingOwner // Down below is the function that is to be implemented in the contract but in cairo. // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L253 @@ -320,8 +317,8 @@ pub mod Registry { return self.profiles_by_id.read(_profile_id).owner == _owner; } // Issue n. #5 Implement the functionality of _isMemberOfProfile - // Down below is the function that is to be implemented in the contract but in cairo. - // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 + // Down below is the function that is to be implemented in the contract but in cairo. + // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L384C14-L384C32 } }