Skip to main content

CommunityRules

CommunityRules​

This contract serves as the central registry for user management within the community. It manages user types, registration processes, invitation mechanisms, and a delation system for reporting unwanted behavior.

Inherits from Ownable for deploy setup and Callable for restricting access to sensitive functions to whitelisted addresses. It defines critical parameters and logic for user onboarding and community governance.

SUPPORTER_INVITATION_DELAY_BLOCKS​

uint32 SUPPORTER_INVITATION_DELAY_BLOCKS

The number of blocks an invitation is delayed for Supporters.

VOTER_INVITATION_DELAY_BLOCKS​

uint32 VOTER_INVITATION_DELAY_BLOCKS

The number of blocks an invitation is delayed for voter-type users.

delationsCount​

uint64 delationsCount

Total count of delations received across all users.

usersCount​

uint64 usersCount

The global total count of all active (non-UNDEFINED) users in the system..

delationsById​

mapping(uint256 => struct CommunityTypes.Delation) delationsById

A mapping from a delation id to the Delation struct.

invitations​

mapping(address => struct CommunityTypes.Invitation) invitations

A mapping from an invited user's address to their Invitation details.

userTypesCount​

mapping(enum CommunityTypes.UserType => uint64) userTypesCount

A mapping to track the count of active users for each UserType.

userTypesTotalCount​

mapping(enum CommunityTypes.UserType => uint64) userTypesTotalCount

A mapping to track the total count of registered users for each UserType, including both active and DENIED users. This count serves as a global counter for new user IDs.

userTypeSettings​

mapping(enum CommunityTypes.UserType => struct CommunityTypes.UserTypeSetting) userTypeSettings

A mapping storing specific settings for each UserType, including proportionality rules, invitation requirements, and voter status.

inviterPenalties​

mapping(address => uint16) inviterPenalties

Tracks the number of times an inviter has had their invitees denied.

lastDelationBlock​

mapping(address => uint256) lastDelationBlock

Tracks the block number of each user's last submitted delation.

invitationRulesAddress​

address invitationRulesAddress

The address of the InvitationRules contract.

validationRulesAddress​

address validationRulesAddress

The address of the InvitationRules contract.

constructor​

constructor(uint8 inspectorProportionality, uint8 activistProportionality, uint8 researcherProportionality, uint8 developerProportionality, uint8 contributorProportionality) public

Initializes the CommunityRules contract by setting up initial proportionality and invitation rules for various user types.

Sets predefined UserTypeSetting for Regenerators, Inspectors, Activists, Researchers, Developers, and Contributors.

Parameters​

NameTypeDescription
inspectorProportionalityuint8Defines the proportionality ratio for Inspector registration.
activistProportionalityuint8Defines the proportionality ratio for Activist registration.
researcherProportionalityuint8Defines the proportionality ratio for Researcher registration.
developerProportionalityuint8Defines the proportionality ratio for Developer registration.
contributorProportionalityuint8Defines the proportionality ratio for Contributor registration.

setContractCall​

function setContractCall(address _invitationRulesAddress, address _validationRulesAddress) external

onlyOwner function to set contract call addresses. This function must be called only once after the contract deploy and ownership must be renounced.

Parameters​

NameTypeDescription
_invitationRulesAddressaddressAddress of InvitationRules.
_validationRulesAddressaddressAddress of ValidationRules.

addDelation​

function addDelation(address addr, string title, string testimony) external

Allows registered users (excluding Supporters) to report other users or resources that may require invalidation. Limited to one delation per target.

Examples of unwanted behavior:

  • A user voting to invalidate a valid resource
  • User without valid proofPhoto
  • Inspections without valid proofPhoto
  • Inspections without valid justification report
  • Resources without valid justifications report
  • Inactive users

Adds a new delation to the system. Enforces character limits for title and testimony, and requires both reporter and reported user to be registered.

Parameters​

NameTypeDescription
addraddressThe address of the user being reported.
titlestringTitle of the delation (Max 100 characters).
testimonystringJustification/details of the delation (Max 300 characters).

voteOnDelation​

function voteOnDelation(uint64 _delationId, bool _supportsDelation) external

Allows users to vote (true/false) on an existing delation.

This creates a social validation layer. Voters cannot be the informer or the reported user.

Parameters​

NameTypeDescription
_delationIduint64The ID of the delation to vote on.
_supportsDelationboolTrue for a "thumbs up" (agrees), false for "thumbs down" (disagrees).

addUser​

function addUser(address addr, enum CommunityTypes.UserType userType) external

Adds a new user to the system with a specified user type.

This function can only be called by an allowed caller (e.g., specific *Rules contracts for each user type). It enforces rules for single registration per address, valid user types, proportionality limits, and valid invitations if required.

Parameters​

NameTypeDescription
addraddressThe address of the user to be registered.
userTypeenum CommunityTypes.UserTypeThe desired UserType for the user.

addInvitation​

function addInvitation(address inviter, address invited, enum CommunityTypes.UserType userType) external

Attempts to add an invitation for a new user.

This function is intended to be called by an allowed caller, the Invitation Rules. It records an invitation for a specific user to register as a certain user type. Prevents re-inviting an already invited or registered address.

Parameters​

NameTypeDescription
inviteraddressThe address of the user who issued the invitation.
invitedaddressThe address of the user who received the invitation.
userTypeenum CommunityTypes.UserTypeThe UserType the invited user is intended to register as.

setToDenied​

function setToDenied(address userAddress) external

Sets a user's to DENIED.

This function is intended to be called by an allowed caller (ValidationRules). It decrements the count of the user's previous type and sets their UserType to DENIED. Prevents re-denying an already denied user.

Parameters​

NameTypeDescription
userAddressaddressThe address of the user to be denied.

addInviterPenalty​

function addInviterPenalty(address inviter) external

This functions adds a penalty to users when a invited user gets denied.

This function is intended to be called by an allowed caller (ValidationRules). It decrements the count of penalties for the inviter.

Parameters​

NameTypeDescription
inviteraddressThe address of the inviter receiving the penalty.

votersCount​

function votersCount() public view returns (uint256)

Returns the total count of users currently classified as voters.

Sums the active counts of Activist, Contributor, Developer, and Researcher user types.

Return Values​

NameTypeDescription
[0]uint256uint256 The total number of voters.

isVoter​

function isVoter(address addr) public view returns (bool)

Checks if a given address belongs to a user type that is considered a voter.

Parameters​

NameTypeDescription
addraddressThe address of the user to check.

Return Values​

NameTypeDescription
[0]boolbool True if the user is a voter, false otherwise.

getUser​

function getUser(address addr) public view returns (enum CommunityTypes.UserType)

Returns the UserType of a given address.

Parameters​

NameTypeDescription
addraddressThe address to query.

Return Values​

NameTypeDescription
[0]enum CommunityTypes.UserTypeUserType The UserType enum value associated with the address.

getUserTypeSettings​

function getUserTypeSettings(enum CommunityTypes.UserType userType) public view returns (struct CommunityTypes.UserTypeSetting)

Returns the UserTypeSetting configuration for a specific UserType.

Parameters​

NameTypeDescription
userTypeenum CommunityTypes.UserTypeThe UserType to query settings for.

Return Values​

NameTypeDescription
[0]struct CommunityTypes.UserTypeSettingUserTypeSetting The UserTypeSetting struct containing configuration data.

userTypeIs​

function userTypeIs(enum CommunityTypes.UserType userType, address userAddress) public view returns (bool)

Function to check if an userAddress type is equal passed userType.

This function also checks if a user is denied, returning false if denied.

Parameters​

NameTypeDescription
userTypeenum CommunityTypes.UserTypeThe UserType to check for.
userAddressaddressDenied user address.

Return Values​

NameTypeDescription
[0]boolbool True if userAddress is equal userType.

isDenied​

function isDenied(address userAddress) public view returns (bool)

Function to check if an userAddress is denied.

Parameters​

NameTypeDescription
userAddressaddressThe user address to check.

Return Values​

NameTypeDescription
[0]boolbool True if userAddress is denied.

getUserDelations​

function getUserDelations(address _user) external view returns (uint64[])

Gets the unique IDs of all delations filed against a user.

This function returns an array of IDs. The full data for each delation can then be fetched individually from the public delationsById mapping.

Parameters​

NameTypeDescription
_useraddressThe address of the user whose delation IDs are to be retrieved.

Return Values​

NameTypeDescription
[0]uint64[]An array of uint64 delation IDs.

getInvitation​

function getInvitation(address addr) external view returns (struct CommunityTypes.Invitation)

Get the invitation of a user.

Returns the invitation.

Parameters​

NameTypeDescription
addraddressUser address.

Return Values​

NameTypeDescription
[0]struct CommunityTypes.Invitationthe Invitation data struct.

hasWaitedRequiredTime​

function hasWaitedRequiredTime(address addr) public view returns (bool)

Calculates if a user is eligible to publish a delation. Eligibility based on the lastDelationBlock and BLOCKS_BETWEEN_DELATIONS.

Parameters​

NameTypeDescription
addraddressThe address to check.

Return Values​

NameTypeDescription
[0]booltrue if the user can publish, false otherwise.

UserRegistered​

event UserRegistered(address addr, enum CommunityTypes.UserType userType)

Emitted when a new user is successfully added to the system.

Parameters​

NameTypeDescription
addraddressThe address of the newly registered user.
userTypeenum CommunityTypes.UserTypeThe UserType assigned to the new user.

DeniedUserEvent​

event DeniedUserEvent(address addr)

Emitted when a user's type is changed to DENIED.

Parameters​

NameTypeDescription
addraddressThe address of the user who has been denied.

DelationAdded​

event DelationAdded(address informer, address reported, uint64 newDelationId)

Emitted when a delation is successfully added.

Parameters​

NameTypeDescription
informeraddressThe address of the user who submitted the delation.
reportedaddressThe address of the user being reported.
newDelationIduint64

InvitationAdded​

event InvitationAdded(address inviter, address invited, enum CommunityTypes.UserType userTypeTo)

Emitted when an invitation is successfully added to the system.

Parameters​

NameTypeDescription
inviteraddressThe address of the user who issued the invitation.
invitedaddressThe address of the user who received the invitation.
userTypeToenum CommunityTypes.UserTypeThe UserType the invited user is intended to register as.

DelationVoted​

event DelationVoted(uint64 delationId, address voter, bool supportsDelation, uint256 newThumbsUpCount, uint256 newThumbsDownCount)

Emitted when a user votes on a delation.

Parameters​

NameTypeDescription
delationIduint64The ID of the delation that was voted on.
voteraddressThe address of the user who voted.
supportsDelationboolTrue if the vote was a "thumbs up", false for "thumbs down".
newThumbsUpCountuint256The new total of "thumbs up" votes for this delation.
newThumbsDownCountuint256The new total of "thumbs down" votes for this delation.