Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
amityadav0 committed Sep 22, 2023
1 parent 2fbe344 commit eb9e5c5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,28 @@ Change log entries are to be added to the Unreleased section. Example entry:

## Unreleased

+ Update repo to the latest near-sdk and related deps
+ Integrate hooks
+ Add option to act_proposal to not execute the proposal
+ Add events to veto and dissolve hooks
+ Integrate cooldown

### Features

New methods:

- A..
- `veto_hook`: Vetos any proposal.(must be called by authority with permission)
- `dissolve_hook`: Dissolves the DAO by removing all members, closing all active proposals and returning bonds.

Extended types:

- ProposalStatus: `Executed`
- Action: `Veto` and `Dissolve`

New types:

- `ContractStatus`: Active or Dissolved

### Breaking Changes

- B...
Expand Down
1 change: 1 addition & 0 deletions astra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ mod tests {
proposal_period: None, bounty_bond: None,
bounty_forgiveness_period: None
});
contract.policy.set(&VersionedPolicy::Current(policy));

contract.act_proposal(id, Action::VoteApprove, None, None);
// verify proposal wasn't executed during final vote
Expand Down
10 changes: 5 additions & 5 deletions astra/src/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl Contract {
let mut proposal: Proposal = self.proposals.get(&id).expect("ERR_NO_PROPOSAL").into();
let policy = self.policy.get().unwrap().to_policy();

let execute = !skip_execution.unwrap_or(false) && self.assert_cooldown(proposal.submission_time, policy.cooldown);
let execute = !skip_execution.unwrap_or(false) && self.is_past_cooldown(proposal.submission_time, policy.cooldown);
// Check permissions for the given action.
let (roles, allowed) =
policy.can_execute_action(self.internal_user_info(), &proposal.kind, &action);
Expand Down Expand Up @@ -602,7 +602,7 @@ impl Contract {
// - if the number of votes in the group has changed (new members has been added) -
// the proposal can loose it's approved state. In this case new proposal needs to be made, this one can only expire.
Action::Finalize => {
require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT");
require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT");
proposal.status = policy.proposal_status(
&proposal,
policy.roles.iter().map(|r| r.name.clone()).collect(),
Expand All @@ -625,7 +625,7 @@ impl Contract {
Action::MoveToHub => false,
Action::Execute => {
require!(proposal.status != ProposalStatus::Executed, "ERR_PROPOSAL_ALREADY_EXECUTED");
require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT");
require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT");
// recompute status to check if the proposal is not expired.
proposal.status = policy.proposal_status(&proposal, roles, self.total_delegation_amount);
require!(proposal.status == ProposalStatus::Approved, "ERR_PROPOSAL_NOT_APPROVED");
Expand Down Expand Up @@ -675,8 +675,8 @@ impl Contract {

/// Returns true if cooldown is over else false
#[private]
pub fn assert_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool {
if env::block_timestamp_ms() > cooldown.0 + submission_time.0 {
fn is_past_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool {
if env::block_timestamp_ms() >= cooldown.0 + submission_time.0 {
return true;
}
false
Expand Down
2 changes: 1 addition & 1 deletion astra/tests/test_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn test_multi_council() -> anyhow::Result<()> {
RolePermission {
name: "all".to_string(),
kind: RoleKind::Everyone,
permissions: vec!["*:AddProposal".to_string()].into_iter().collect(),
permissions: vec!["*:Execute".to_string(), "*:AddProposal".to_string()].into_iter().collect(),
vote_policy: HashMap::default(),
},
RolePermission {
Expand Down

0 comments on commit eb9e5c5

Please sign in to comment.