@@ -24,7 +24,7 @@ use crate::{
24
24
error:: GovernanceError ,
25
25
state:: {
26
26
enums:: {
27
- GovernanceAccountType , InstructionExecutionFlags , MintMaxVoteWeightSource ,
27
+ GovernanceAccountType , InstructionExecutionFlags , MintMaxVoterWeightSource ,
28
28
ProposalState , TransactionExecutionStatus , VoteThreshold , VoteTipping ,
29
29
} ,
30
30
governance:: GovernanceConfig ,
@@ -432,26 +432,24 @@ impl ProposalV2 {
432
432
return Ok ( governing_token_mint_supply) ;
433
433
}
434
434
435
- match realm_data. config . community_mint_max_vote_weight_source {
436
- MintMaxVoteWeightSource :: SupplyFraction ( fraction) => {
437
- if fraction == MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE {
435
+ let max_voter_weight = match realm_data. config . community_mint_max_voter_weight_source {
436
+ MintMaxVoterWeightSource :: SupplyFraction ( fraction) => {
437
+ if fraction == MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE {
438
438
return Ok ( governing_token_mint_supply) ;
439
439
}
440
440
441
- let max_voter_weight = ( governing_token_mint_supply as u128 )
441
+ ( governing_token_mint_supply as u128 )
442
442
. checked_mul ( fraction as u128 )
443
443
. unwrap ( )
444
- . checked_div ( MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE as u128 )
445
- . unwrap ( ) as u64 ;
446
-
447
- // When the fraction is used it's possible we can go over the calculated max_vote_weight
448
- // and we have to adjust it in case more votes have been cast
449
- Ok ( self . coerce_max_voter_weight ( max_voter_weight, vote_kind) )
450
- }
451
- MintMaxVoteWeightSource :: Absolute ( _) => {
452
- Err ( GovernanceError :: VoteWeightSourceNotSupported . into ( ) )
444
+ . checked_div ( MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE as u128 )
445
+ . unwrap ( ) as u64
453
446
}
454
- }
447
+ MintMaxVoterWeightSource :: Absolute ( value) => value,
448
+ } ;
449
+
450
+ // When the fraction or absolute value is used it's possible we can go over the calculated max_vote_weight
451
+ // and we have to adjust it in case more votes have been cast
452
+ Ok ( self . coerce_max_voter_weight ( max_voter_weight, vote_kind) )
455
453
}
456
454
457
455
/// Adjusts max voter weight to ensure it's not lower than total cast votes
@@ -1057,7 +1055,7 @@ mod test {
1057
1055
use solana_program:: clock:: Epoch ;
1058
1056
1059
1057
use crate :: state:: {
1060
- enums:: { MintMaxVoteWeightSource , VoteThreshold } ,
1058
+ enums:: { MintMaxVoterWeightSource , VoteThreshold } ,
1061
1059
legacy:: ProposalV1 ,
1062
1060
realm:: RealmConfig ,
1063
1061
vote_record:: VoteChoice ,
@@ -1158,8 +1156,8 @@ mod test {
1158
1156
legacy1 : 0 ,
1159
1157
legacy2 : 0 ,
1160
1158
1161
- community_mint_max_vote_weight_source :
1162
- MintMaxVoteWeightSource :: FULL_SUPPLY_FRACTION ,
1159
+ community_mint_max_voter_weight_source :
1160
+ MintMaxVoterWeightSource :: FULL_SUPPLY_FRACTION ,
1163
1161
min_community_weight_to_create_governance : 10 ,
1164
1162
} ,
1165
1163
voting_proposal_count : 0 ,
@@ -1801,9 +1799,9 @@ mod test {
1801
1799
let vote_tipping = VoteTipping :: Strict ;
1802
1800
1803
1801
// reduce max vote weight to 100
1804
- realm. config . community_mint_max_vote_weight_source =
1805
- MintMaxVoteWeightSource :: SupplyFraction (
1806
- MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1802
+ realm. config . community_mint_max_voter_weight_source =
1803
+ MintMaxVoterWeightSource :: SupplyFraction (
1804
+ MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1807
1805
) ;
1808
1806
1809
1807
let max_voter_weight = proposal
@@ -1834,6 +1832,57 @@ mod test {
1834
1832
assert_eq ! ( proposal. max_vote_weight, Some ( 100 ) ) ;
1835
1833
}
1836
1834
1835
+ #[ test]
1836
+ fn test_try_tip_vote_with_reduced_absolute_community_mint_max_vote_weight ( ) {
1837
+ // Arrange
1838
+ let mut proposal = create_test_proposal ( ) ;
1839
+
1840
+ proposal. options [ 0 ] . vote_weight = 60 ;
1841
+ proposal. deny_vote_weight = Some ( 10 ) ;
1842
+
1843
+ proposal. state = ProposalState :: Voting ;
1844
+
1845
+ let current_timestamp = 15_i64 ;
1846
+
1847
+ let community_token_supply = 200 ;
1848
+
1849
+ let mut realm = create_test_realm ( ) ;
1850
+ let governing_token_mint = proposal. governing_token_mint ;
1851
+ let vote_kind = VoteKind :: Electorate ;
1852
+ let vote_tipping = VoteTipping :: Strict ;
1853
+
1854
+ // set max vote weight to 100
1855
+ realm. config . community_mint_max_voter_weight_source =
1856
+ MintMaxVoterWeightSource :: Absolute ( community_token_supply / 2 ) ;
1857
+
1858
+ let max_voter_weight = proposal
1859
+ . get_max_voter_weight_from_mint_supply (
1860
+ & realm,
1861
+ & governing_token_mint,
1862
+ community_token_supply,
1863
+ & vote_kind,
1864
+ )
1865
+ . unwrap ( ) ;
1866
+
1867
+ let vote_threshold = & VoteThreshold :: YesVotePercentage ( 60 ) ;
1868
+ let vote_kind = VoteKind :: Electorate ;
1869
+
1870
+ // Act
1871
+ proposal
1872
+ . try_tip_vote (
1873
+ max_voter_weight,
1874
+ & vote_tipping,
1875
+ current_timestamp,
1876
+ vote_threshold,
1877
+ & vote_kind,
1878
+ )
1879
+ . unwrap ( ) ;
1880
+
1881
+ // Assert
1882
+ assert_eq ! ( proposal. state, ProposalState :: Succeeded ) ;
1883
+ assert_eq ! ( proposal. max_vote_weight, Some ( 100 ) ) ;
1884
+ }
1885
+
1837
1886
#[ test]
1838
1887
fn test_try_tip_vote_with_reduced_community_mint_max_vote_weight_and_vote_overflow ( ) {
1839
1888
// Arrange
@@ -1854,9 +1903,9 @@ mod test {
1854
1903
let vote_tipping = VoteTipping :: Strict ;
1855
1904
1856
1905
// reduce max vote weight to 100
1857
- realm. config . community_mint_max_vote_weight_source =
1858
- MintMaxVoteWeightSource :: SupplyFraction (
1859
- MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1906
+ realm. config . community_mint_max_voter_weight_source =
1907
+ MintMaxVoterWeightSource :: SupplyFraction (
1908
+ MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1860
1909
) ;
1861
1910
1862
1911
// vote above reduced supply
@@ -1890,6 +1939,60 @@ mod test {
1890
1939
assert_eq ! ( proposal. max_vote_weight, Some ( 130 ) ) ;
1891
1940
}
1892
1941
1942
+ #[ test]
1943
+ fn test_try_tip_vote_with_reduced_absolute_mint_max_vote_weight_and_vote_overflow ( ) {
1944
+ // Arrange
1945
+ let mut proposal = create_test_proposal ( ) ;
1946
+
1947
+ // no vote weight
1948
+ proposal. deny_vote_weight = Some ( 10 ) ;
1949
+
1950
+ proposal. state = ProposalState :: Voting ;
1951
+
1952
+ let current_timestamp = 15_i64 ;
1953
+
1954
+ let community_token_supply = 200 ;
1955
+
1956
+ let mut realm = create_test_realm ( ) ;
1957
+ let governing_token_mint = proposal. governing_token_mint ;
1958
+ let vote_kind = VoteKind :: Electorate ;
1959
+ let vote_tipping = VoteTipping :: Strict ;
1960
+
1961
+ // reduce max vote weight to 100
1962
+ realm. config . community_mint_max_voter_weight_source =
1963
+ MintMaxVoterWeightSource :: Absolute ( community_token_supply / 2 ) ;
1964
+
1965
+ // vote above reduced supply
1966
+ // Yes vote weight
1967
+ proposal. options [ 0 ] . vote_weight = 120 ;
1968
+
1969
+ let max_voter_weight = proposal
1970
+ . get_max_voter_weight_from_mint_supply (
1971
+ & realm,
1972
+ & governing_token_mint,
1973
+ community_token_supply,
1974
+ & vote_kind,
1975
+ )
1976
+ . unwrap ( ) ;
1977
+
1978
+ let vote_threshold = VoteThreshold :: YesVotePercentage ( 60 ) ;
1979
+
1980
+ // Act
1981
+ proposal
1982
+ . try_tip_vote (
1983
+ max_voter_weight,
1984
+ & vote_tipping,
1985
+ current_timestamp,
1986
+ & vote_threshold,
1987
+ & vote_kind,
1988
+ )
1989
+ . unwrap ( ) ;
1990
+
1991
+ // Assert
1992
+ assert_eq ! ( proposal. state, ProposalState :: Succeeded ) ;
1993
+ assert_eq ! ( proposal. max_vote_weight, Some ( 130 ) ) ; // Deny Vote 10 + Approve Vote 120
1994
+ }
1995
+
1893
1996
#[ test]
1894
1997
fn test_try_tip_vote_for_council_vote_with_reduced_community_mint_max_vote_weight ( ) {
1895
1998
// Arrange
@@ -1909,9 +2012,9 @@ mod test {
1909
2012
let vote_kind = VoteKind :: Electorate ;
1910
2013
let vote_tipping = VoteTipping :: Strict ;
1911
2014
1912
- realm. config . community_mint_max_vote_weight_source =
1913
- MintMaxVoteWeightSource :: SupplyFraction (
1914
- MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
2015
+ realm. config . community_mint_max_voter_weight_source =
2016
+ MintMaxVoterWeightSource :: SupplyFraction (
2017
+ MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1915
2018
) ;
1916
2019
realm. config . council_mint = Some ( proposal. governing_token_mint ) ;
1917
2020
@@ -1961,9 +2064,9 @@ mod test {
1961
2064
let vote_kind = VoteKind :: Electorate ;
1962
2065
1963
2066
// reduce max vote weight to 100
1964
- realm. config . community_mint_max_vote_weight_source =
1965
- MintMaxVoteWeightSource :: SupplyFraction (
1966
- MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
2067
+ realm. config . community_mint_max_voter_weight_source =
2068
+ MintMaxVoterWeightSource :: SupplyFraction (
2069
+ MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
1967
2070
) ;
1968
2071
1969
2072
let max_voter_weight = proposal
@@ -2012,9 +2115,9 @@ mod test {
2012
2115
let vote_kind = VoteKind :: Electorate ;
2013
2116
2014
2117
// reduce max vote weight to 100
2015
- realm. config . community_mint_max_vote_weight_source =
2016
- MintMaxVoteWeightSource :: SupplyFraction (
2017
- MintMaxVoteWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
2118
+ realm. config . community_mint_max_voter_weight_source =
2119
+ MintMaxVoterWeightSource :: SupplyFraction (
2120
+ MintMaxVoterWeightSource :: SUPPLY_FRACTION_BASE / 2 ,
2018
2121
) ;
2019
2122
2020
2123
// vote above reduced supply
0 commit comments