Skip to content

Commit

Permalink
add new proposal type to alllow updating the parameters of a policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ctindogarus4f committed Jan 13, 2022
1 parent 009bdac commit 2161112
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sputnikdao2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ ProposalKind::ChangePolicy { .. },
ProposalKind::ChangePolicyAddOrUpdateRole { .. },
ProposalKind::ChangePolicyRemoveRole { .. },
ProposalKind::ChangePolicyUpdateDefaultVotePolicy { .. },
ProposalKind::ChangePolicyUpdateParameters { .. },
ProposalKind::AddMemberToRole { .. },
ProposalKind::RemoveMemberFromRole { .. },
ProposalKind::FunctionCall { .. },
Expand All @@ -280,6 +281,7 @@ ProposalKind::FactoryInfoUpdate { .. },
- **ChangePolicyAddOrUpdateRole** - used to add a new role to the policy of the DAO. If the role already exists, update it.
- **ChangePolicyRemoveRole** - used to remove a role from the policy of the DAO.
- **ChangePolicyUpdateDefaultVotePolicy** - used to update the default vote policy from the policy of the DAO.
- **ChangePolicyUpdateParameters** - used to update the parameters from the policy of the DAO. Parameters include: proposal bond, proposal period, bounty bond, bounty forgiveness period.
- **AddMemberToRole** - used to add a member to a role in the DAO
- **RemoveMemberFromRole** - used to remove a member from a role in the DAO
- **FunctionCall** - used to a call a function on any valid account on the network including the DAO itself, any other DAO, or any other contract. This is a useful mechanism for extending the capabilities of the DAO without modifying or complicating the DAO contract code. One can imagine a family of contracts built specifically to serve the DAO as agents, proxies, oracles and banks, for example.
Expand Down
18 changes: 17 additions & 1 deletion sputnikdao2/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use near_sdk::json_types::{U128, U64};
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{env, AccountId, Balance};

use crate::proposals::{Proposal, ProposalKind, ProposalStatus, Vote};
use crate::proposals::{PolicyParameters, Proposal, ProposalKind, ProposalStatus, Vote};
use crate::types::Action;

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -267,6 +267,22 @@ impl Policy {
env::log_str("Successfully updated the default vote policy.");
}

pub fn update_parameters(&mut self, parameters: &PolicyParameters) {
if parameters.proposal_bond.is_some() {
self.proposal_bond = parameters.proposal_bond.unwrap();
}
if parameters.proposal_period.is_some() {
self.proposal_period = parameters.proposal_period.unwrap();
}
if parameters.bounty_bond.is_some() {
self.bounty_bond = parameters.bounty_bond.unwrap();
}
if parameters.bounty_forgiveness_period.is_some() {
self.bounty_forgiveness_period = parameters.bounty_forgiveness_period.unwrap();
}
env::log_str("Successfully updated the policy parameters.");
}

pub fn add_member_to_role(&mut self, role: &String, member_id: &AccountId) {
for i in 0..self.roles.len() {
if &self.roles[i].name == role {
Expand Down
20 changes: 20 additions & 0 deletions sputnikdao2/src/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ pub struct ActionCall {
gas: U64,
}

/// Function call arguments.
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
#[cfg_attr(not(target_arch = "wasm32"), derive(Clone, Debug))]
#[serde(crate = "near_sdk::serde")]
pub struct PolicyParameters {
pub proposal_bond: Option<U128>,
pub proposal_period: Option<U64>,
pub bounty_bond: Option<U128>,
pub bounty_forgiveness_period: Option<U64>,
}

/// Kinds of proposals, doing different action.
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
#[cfg_attr(not(target_arch = "wasm32"), derive(Clone, Debug))]
Expand All @@ -56,6 +67,8 @@ pub enum ProposalKind {
ChangePolicyRemoveRole { role: String },
/// Update the default vote policy from the policy. This is short cut to updating the whole policy.
ChangePolicyUpdateDefaultVotePolicy { vote_policy: VotePolicy },
/// Update the parameters from the policy. This is short cut to updating the whole policy.
ChangePolicyUpdateParameters { parameters: PolicyParameters },
/// Add member to given role in the policy. This is short cut to updating the whole policy.
AddMemberToRole { member_id: AccountId, role: String },
/// Remove member to given role in the policy. This is short cut to updating the whole policy.
Expand Down Expand Up @@ -111,6 +124,7 @@ impl ProposalKind {
ProposalKind::ChangePolicyUpdateDefaultVotePolicy { .. } => {
"policy_update_default_vote_policy"
}
ProposalKind::ChangePolicyUpdateParameters { .. } => "policy_update_parameters",
ProposalKind::AddMemberToRole { .. } => "add_member_to_role",
ProposalKind::RemoveMemberFromRole { .. } => "remove_member_from_role",
ProposalKind::FunctionCall { .. } => "call",
Expand Down Expand Up @@ -316,6 +330,12 @@ impl Contract {
self.policy.set(&VersionedPolicy::Current(new_policy));
PromiseOrValue::Value(())
}
ProposalKind::ChangePolicyUpdateParameters { parameters } => {
let mut new_policy = policy.clone();
new_policy.update_parameters(parameters);
self.policy.set(&VersionedPolicy::Current(new_policy));
PromiseOrValue::Value(())
}
ProposalKind::AddMemberToRole { member_id, role } => {
let mut new_policy = policy.clone();
new_policy.add_member_to_role(role, &member_id.clone().into());
Expand Down

0 comments on commit 2161112

Please sign in to comment.