Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Governance: vote options #2544

Merged
merged 57 commits into from
Nov 11, 2021
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5bff3e9
feat: use VoteChoice instead of VoteWeight
SebastianBor Oct 25, 2021
13b53cf
chore: make clippy happy
SebastianBor Oct 25, 2021
508f925
feat: use options for ye/no vote
SebastianBor Oct 25, 2021
867c760
feat: use choices for CastVote instruction
SebastianBor Oct 25, 2021
a618faa
chore: move Vote enum to tests
SebastianBor Oct 25, 2021
417670c
fix: iterate overall choices for withdrawal
SebastianBor Oct 25, 2021
0a887c6
chore: split ProposalOption and ProposalOptionVote
SebastianBor Oct 25, 2021
aabe4e3
fix: calculate multi option proposal size
SebastianBor Oct 25, 2021
4ce9cc0
chore: split weighted and fractional vote choices
SebastianBor Oct 25, 2021
fc4c0dc
feat: add proposal type
SebastianBor Oct 25, 2021
8207e16
feat: add reject option flag
SebastianBor Oct 26, 2021
40c18cf
feat: calculate final state for proposal using options results
SebastianBor Oct 26, 2021
ae9e1d2
chore: make clippy happy
SebastianBor Oct 26, 2021
9966dee
fix: generalise max vote weight calculation for multiple options
SebastianBor Oct 26, 2021
0316db8
feat: gate vote tipping for yes/no proposals only
SebastianBor Oct 26, 2021
ef3c6b7
chore: make clippy happy
SebastianBor Oct 26, 2021
170ba0e
feat: add option_index to instruction
SebastianBor Oct 27, 2021
b5bd430
feat: move instructions to options
SebastianBor Oct 27, 2021
38f34cd
chore: advance clock
SebastianBor Oct 27, 2021
9ed8f14
chore: add await
SebastianBor Oct 27, 2021
53153ab
chore: add multi option proposal tests
SebastianBor Oct 27, 2021
772c005
chore: move governing_mint to account list
SebastianBor Oct 27, 2021
529d152
feat: assert valid proposal options
SebastianBor Oct 27, 2021
b258554
feat: assert proposal is executable when instruction is added
SebastianBor Oct 27, 2021
484a8c8
chore: make clippy happy
SebastianBor Oct 27, 2021
537ab3f
chore: add tests to insert instructions into multi option proposal
SebastianBor Oct 27, 2021
c507cc7
chore: make clippy happy
SebastianBor Oct 27, 2021
6421761
feat: use explicit reject_option_vote_weight
SebastianBor Oct 27, 2021
e64d156
feat: use Vote struct for vote results
SebastianBor Oct 27, 2021
1d19e0d
feat: validate vote
SebastianBor Oct 27, 2021
c23cd24
feat: reject empty proposal options
SebastianBor Oct 27, 2021
512a97d
chore: update comments
SebastianBor Oct 27, 2021
6e20486
fix: allow execute only successful options
SebastianBor Oct 27, 2021
5f45f7f
chore: add assertions for option statuses
SebastianBor Oct 28, 2021
e77bc18
chore: add partial success test
SebastianBor Oct 28, 2021
6a16453
chore: add full success execution test
SebastianBor Oct 28, 2021
530e0af
chore: add test for instructions execution for fully denied proposal
SebastianBor Oct 28, 2021
f407e16
feat: finalise none executable proposals into completed state
SebastianBor Oct 28, 2021
81d9115
chore: fix chat
SebastianBor Oct 28, 2021
03df0d9
feat: add vote_record v1 v2 roundtrip serialization
SebastianBor Oct 28, 2021
c864a16
eat: add proposal_instruction v1 v2 roundtrip serialisation
SebastianBor Oct 28, 2021
aac5806
chore: use VoteRecordV1
SebastianBor Oct 28, 2021
6285f0a
chore: use legacy structs instead of legacy crate version
SebastianBor Oct 28, 2021
c7b1170
chore: rename proposal to V2
SebastianBor Oct 28, 2021
e1f1420
feat: translate Proposal v1 v2 versions
SebastianBor Oct 28, 2021
1b5d74e
chore: make clippy happy
SebastianBor Oct 28, 2021
0a71dd9
chore: make clippy happy
SebastianBor Oct 28, 2021
2967adf
chore: remove unnecessary clone for match
SebastianBor Oct 30, 2021
677794a
chore: rename get_final_vote_state to resolve_final_vote_state
SebastianBor Oct 30, 2021
126464b
fix proposal account name
SebastianBor Oct 30, 2021
e6c4f77
chore: fix compilation
SebastianBor Oct 30, 2021
8fa1ba3
chore: use borsh::maybestd::io::Write
SebastianBor Oct 30, 2021
c6efecd
chore: consume self in serialise instructions to avoid cloning
SebastianBor Oct 30, 2021
00a446b
chore: update comments
SebastianBor Oct 30, 2021
ce61b13
feat: add N limit placeholder to multi choice vote type
SebastianBor Oct 30, 2021
a534d61
feat: increase options size to u16
SebastianBor Oct 30, 2021
172ead5
fix: use checked math
SebastianBor Oct 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: generalise max vote weight calculation for multiple options
  • Loading branch information
SebastianBor committed Oct 26, 2021
commit 9966dee49303a503475a4b0e9d66d790fd7b45a4
27 changes: 22 additions & 5 deletions governance/program/src/state/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,32 @@ impl Proposal {
.checked_div(MintMaxVoteWeightSource::SUPPLY_FRACTION_BASE as u128)
.unwrap() as u64;

// TODO: generalize for multi option case
let yes_vote_weight = self.options[0].vote_weight;
let no_vote_weight = self.options[1].vote_weight;
// TODO: Consider removing the reject option from options collection
let (reject_vote_weight, option_count) = if self.has_reject_option {
(
// The reject option is always the last option
self.options.last().unwrap().vote_weight,
self.options.len() - 1,
)
} else {
(0, self.options.len())
};

let max_option_vote_weight = self
.options
.iter()
.take(option_count)
.map(|o| o.vote_weight)
.max()
.unwrap();

// When the fraction is used it's possible we can go over the calculated max_vote_weight
// and we have to adjust it in case more votes have been cast
let total_vote_count = yes_vote_weight.checked_add(no_vote_weight).unwrap();
let total_vote_weight = max_option_vote_weight
.checked_add(reject_vote_weight)
.unwrap();

Ok(max_vote_weight.max(total_vote_count))
Ok(max_vote_weight.max(total_vote_weight))
}
MintMaxVoteWeightSource::Absolute(_) => {
Err(GovernanceError::VoteWeightSourceNotSupported.into())
Expand Down