near-daos / sputnik-dao-contract

Smart contracts for https://app.astrodao.com
https://astrodao.com/
MIT License
108 stars 81 forks source link

How to update role : "vote_policy" #180

Closed GaloisField2718 closed 2 years ago

GaloisField2718 commented 2 years ago

Hello, I'm currently working on different vote policy per each role. I think that I might use

pub struct RolePermission {
    /// Name of the role to display to the user.
    pub name: String,
    /// Kind of the role: defines which users this permissions apply.
    pub kind: RoleKind,
    /// Set of actions on which proposals that this role is allowed to execute.
    /// <proposal_kind>:<action>
    pub permissions: HashSet<String>,
    /// For each proposal kind, defines voting policy.
    pub vote_policy: HashMap<String, VotePolicy>,
}

For now my code it seems like that :

export VOTE_POLICY_STAGIAIRES='{"weight_kind": "RoleWeight", "quorum": "1", "threshold": [1,4]}'
export VOTE_ADD_MEMBER_STAGIAIRES='{"kind": "AddMemberToRole", "vote_policy": '$VOTE_POLICY_STAGIAIRES'}'
export role_stagiaires='{
    "name": "stagiaires", 
    "kind": {
        "Group": []
    },
    "permissions": ["*:AddProposal", "*:VoteApprove", "*:VoteReject"],
    "vote_policy": '$VOTE_ADD_MEMBER_STAGIAIRES'
    }'
near call $DAO add_proposal ' {
    "proposal": {
        "description": "Add the new role member Stagiaire",
        "kind": {
            "ChangePolicyAddOrUpdateRole": {
                "role": '$role_stagiaires'
            }
        }
    }
} ' --accountId $NEAR_ACCT --amount $BOND_AMOUNT

The error is follow :

ExecutionError: `Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error("invalid type: string \\"AddMemberToRole\\", expected struct VotePolicy", line: 1, column: 252)', sputnikdao2/src/proposals.rs:482:1`

The problem is : in struct VotePolicy we have :

pub struct VotePolicy {
    /// Kind of weight to use for votes.
    pub weight_kind: WeightKind,
    /// Minimum number required for vote to finalize.
    /// If weight kind is TokenWeight - this is minimum number of tokens required.
    ///     This allows to avoid situation where the number of staked tokens from total supply is too small.
    /// If RoleWeight - this is minimum number of votes.
    ///     This allows to avoid situation where the role is got too small but policy kept at 1/2, for example.
    pub quorum: U128,
    /// How many votes to pass this vote.
    pub threshold: WeightOrRatio,
}

But as we see in first lines vote_policy takes this argument pub vote_policy: HashMap<String, VotePolicy>, in other words we have a "kind" which is a string and "vote_policy" which is a VotePolicy type. Nevertheless, when I only try with VOTE_POLICY_STAGIAIRES, it's the same error :

    ExecutionError: `Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error("invalid type: string \\"RoleWeight\\", expected struct VotePolicy", line: 1, column: 254)', sputnikdao2/src/proposals.rs:482:1`

Anyone has an idea about how to solve this issue ?

GaloisField2718 commented 2 years ago

I find this solution

near call $DAO add_proposal '{
    "proposal": {
        "description": "Update voting policy to simplify test vote",
        "kind":{
            "ChangePolicyUpdateDefaultVotePolicy": {
                "vote_policy":{
                    "weight_kind": "RoleWeight",
                   "quorum": "0",
                    "threshold": [1,4]
                }
            }
        }
    }
}' --accountId $NEAR_ACCT --amount $BOND_AMOUNT --gas $MAX_GAS