From 2386c0e9294e5ae69cbbaf8fd6e7922b15ad3936 Mon Sep 17 00:00:00 2001 From: Luke Miller <millerluke1364@gmail.com> Date: Mon, 11 Oct 2021 09:58:56 -0400 Subject: [PATCH] first draft of consent system --- modpol/orgs/process.lua | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/modpol/orgs/process.lua b/modpol/orgs/process.lua index ddd478a..52a7029 100644 --- a/modpol/orgs/process.lua +++ b/modpol/orgs/process.lua @@ -42,6 +42,90 @@ new_process_format = { } +-- initialize values +function init_consent(policy) { + self.start_time = os.time() + self.member_count = modpol.orgs.get_org(self.org_id):get_member_count() + + if policy.duration then + register_callback(self.start_time + policy.duration) + end + + if (duration and (consent_ratio or yes_threshold or no_threshold)) or (yes_threshold) or (consent_ratio) then + -- well formed policy + else + -- invalid + end + +} + +-- update vote count +function update_consent(user, approve) { + if approve then + table.insert(yes_votes, user) + else + table.insert(no_votes, user) + + if not duration then + eval_consent() + end + +} + +-- evaluate state of vote +function eval_consent() { + consent_ratio = #yes_votes / (#yes_votes + #no_votes) + quorum = (#yes_votes + #no_votes) / member_count + + if policy.duration then + + if policy.consent_ratio then + if policy.quorum then + if quorum < policy.quorum then + fail() + end + end + if consent_ratio >= policy.consent_ratio then + pass() + else + fail() + end + + elseif policy.yes_threshold then + if #yes_votes >= policy.yes_threshold then + pass() + else + fail() + end + + elseif policy.no_threshold then + if #no_votes <= policy.no_threshold then + fail() + else + pass() + end + end + + elseif policy.yes_threshold then + if policy.no_threshold then + if #no_votes >= policy.no_threshold then + fail() + end + if #yes_votes >= policy.yes_threshold then + pass() + end + + elseif policy.consent_ratio and policy.quorum then + if quorum >= policy.quorum then + if consent_ratio >= policy.consent_ratio then + pass() + else + fail() + end + end + end + +} policy_table_format = {