-
Notifications
You must be signed in to change notification settings - Fork 64
WIP: Permission Claims - Voting Mechanics [skip-ci] #1390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rackstar
wants to merge
14
commits into
release-candidate
Choose a base branch
from
feat/permissioned-assessment-voting-mechanics
base: release-candidate
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9fbba73
feat: add PermissionedAssessment voting mechanics --WIP-- [skip-ci]
rackstar 4d86c71
feat: add validation when reading mapping values
rackstar 87bd2ed
refactor: modify _getTally to have assessment instead of claimId as p…
rackstar 1c692e9
perf: reduce SLOAD for gas optimisation
rackstar 42fc4d7
refactor: simplify _isAssessmentDecided params
rackstar 255c2a5
refactor: optimise Ballot struct slot packing
rackstar 4c68543
refactor: remove revert on some of the validations
rackstar eacfa1d
feat: add assessor address to VoteCast event
rackstar 9b7e236
fix: change claimId to uint256
rackstar 8598739
feat: add finalizedAt and result fields to Assessment struct
rackstar 8bfcaba
feat: add closeAssessment and simplify castVote function
rackstar 8192cb9
feat: add snapshot acceptVotes and denyVotes on Assessment struct
rackstar a02db5a
feat: prevent vote cast if voting period ends and not a draw
rackstar c2901d4
feat: add isReadyToCloseAfterVote helper function
rackstar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
pragma solidity ^0.8.28; | ||
|
||
import {EnumerableSet} from "@openzeppelin/contracts-v4/utils/structs/EnumerableSet.sol"; | ||
|
||
interface IPermissionedAssessment { | ||
|
||
/* ========== DATA STRUCTURES ========== */ | ||
|
||
struct AssessmentData { | ||
uint32 assessingGroupId; | ||
uint32 cooldownPeriod; | ||
} | ||
|
||
struct AssessmentGroupView { | ||
uint id; | ||
string ipfsMetadata; | ||
address[] assessors; | ||
} | ||
|
||
struct Ballot { | ||
bytes32 ipfsHash; | ||
Vote vote; | ||
uint32 timestamp; | ||
} | ||
|
||
struct Assessment { | ||
uint32 start; | ||
uint32 assessorGroupId; | ||
uint32 finalizedAt; // 0, not closed yet else timestamp of closure | ||
uint8 acceptVotes; // 0, if not finalized yet, should only be set onced finalized | ||
uint8 denyVotes; // 0, if not finalized yet, should only be set onced finalized | ||
mapping(uint256 assessorMemberId => Ballot) ballot; // only stores latest choice | ||
} | ||
|
||
enum AssessmentResult { | ||
NONE, | ||
ACCEPTED, | ||
DENIED | ||
} | ||
|
||
enum Vote { | ||
NONE, // 0 - default | ||
ACCEPT, // 1 | ||
DENY // 2 | ||
} | ||
|
||
/* ========== VIEWS ========== */ | ||
|
||
// Groups management | ||
|
||
// function getGroupsCount() external view returns (uint groupCount); | ||
|
||
// function getGroupAssessorCount(uint groupId) external view returns (uint assessorCount); | ||
|
||
// function getGroupAssessors(uint groupId) external view returns (address[] memory assessors); | ||
|
||
// function isAssessorInGroup(address assessor, uint groupId) external view returns (bool); | ||
|
||
// function getGroupsForAssessor(address assessor) external view returns (uint[] memory groupIds); | ||
|
||
// function getGroupsData(uint[] calldata groupIds) external view returns (AssessmentGroupView[] memory groups); | ||
|
||
// Voting | ||
|
||
function minVotingPeriod() external pure returns (uint256); | ||
|
||
function payoutCooldown(uint256 productTypeId) external view returns (uint256); | ||
|
||
function assessorGroupOf(uint256 claimId) external view returns (uint32); | ||
|
||
function getAssessmentInfo(uint256 claimId) external view returns (uint256 acceptVotes, uint256 denyVotes, uint256 groupSize, uint32 end, uint32 finalizedAt); | ||
|
||
function isReadyToCloseAfterVote(uint256 claimId, Vote vote) external view returns (bool); | ||
|
||
function ballotOf(uint256 claimId, address assessor) external view returns (Ballot memory); | ||
|
||
function claimsOpenForVoting(address assessor) external view returns (bytes32[] memory); | ||
|
||
/* === MUTATIVE FUNCTIONS ==== */ | ||
|
||
// Groups management | ||
|
||
// function makeNewGroup(address[] calldata assessors, string calldata ipfsMetadata) external returns (uint groupId); | ||
|
||
// function addAssessorsToGroup(address[] calldata assessors, uint groupId) external; | ||
|
||
// function setGroupMetadata(uint groupId, string calldata ipfsMetadata) external; | ||
|
||
// function removeAssessorsFromGroup(address[] calldata assessors, uint groupId) external; | ||
|
||
// function removeAssessorsFromAllGroups(address[] calldata assessors) external; | ||
|
||
// Voting | ||
|
||
function castVote(uint256 claimId, Vote vote, bytes32 ipfsHash) external; | ||
|
||
function startAssessment(uint256 claimId, uint16 productTypeId) external; | ||
|
||
/* ========= EVENTS ========== */ | ||
|
||
event SetAssessmentDataForProductTypes(uint[] productTypeIds, uint cooldownPeriod, uint groupId); | ||
event AddAssessorsToGroup(uint indexed groupId, address[] assessors); | ||
event RemoveAssessorsFromGroup(uint indexed groupId, address[] assessors); | ||
event RemoveAssessorsFromAllGroups(address[] assessors); | ||
|
||
event AssessmentStarted( | ||
uint256 indexed claimId, | ||
uint32 assessorGroupId, | ||
uint32 start, | ||
uint32 end | ||
); | ||
|
||
event VoteCast( | ||
uint256 indexed claimId, | ||
address indexed assessor, | ||
uint256 indexed assessorMemberId, | ||
Vote vote, | ||
bytes32 ipfsHash | ||
); | ||
|
||
event AssessmentClosed(uint256 claimId); | ||
event AssessmentExtended(uint256 claimId, uint32 newEnd); | ||
|
||
|
||
/* ========== ERRORS ========== */ | ||
|
||
error AssessmentAlreadyExists(); | ||
error ClaimIdsEmpty(); | ||
error ClaimAssessmentAlreadyClosed(); | ||
error ClaimIdsVotesLengthMismatch(); | ||
error ClaimIdsCidsLengthMismatch(); | ||
error ClaimAssessmentNotFinished(); | ||
error EmptyAssessorGroup(); | ||
error InvalidAssessor(); | ||
error InvalidClaimId(); | ||
error InvalidVote(); | ||
error InvalidProductType(); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this timestamp onchain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we could probably get the timestamp from the event but since it also packs into slot 1, I've added it in for convenience.