Skip to content

Commit 25abdad

Browse files
authored
PPv2 / MintGov fixes (#432)
* Fix TWAP accumulator weighting and add virtual crank to get_twap * prevent same mint on dao init, adjust error * reject performance package init/change that would result in same authority and recipient * ppv2 - check Futarchy oracle start delay * validate max min_duration size * use emit_cpi instead of emit * can't end before record_start has been called at least once * add 50k CUs to v6 finalize launch * allow only recipient to start unlocks
1 parent a086658 commit 25abdad

28 files changed

Lines changed: 612 additions & 142 deletions

programs/mint_governor/src/instructions/add_mint_authority.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct AddMintAuthorityArgs {
1010
pub max_total: Option<u64>,
1111
}
1212

13+
#[event_cpi]
1314
#[derive(Accounts)]
1415
pub struct AddMintAuthority<'info> {
1516
#[account(mut)]
@@ -57,7 +58,7 @@ impl AddMintAuthority<'_> {
5758

5859
let clock = Clock::get()?;
5960

60-
emit!(MintAuthorityAddedEvent {
61+
emit_cpi!(MintAuthorityAddedEvent {
6162
common: CommonFields {
6263
slot: clock.slot,
6364
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/initialize_mint_governor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use anchor_spl::token::Mint;
33

44
use crate::{CommonFields, MintGovernor, MintGovernorInitializedEvent, MINT_GOVERNOR_SEED};
55

6+
#[event_cpi]
67
#[derive(Accounts)]
78
pub struct InitializeMintGovernor<'info> {
89
pub mint: Account<'info, Mint>,
@@ -44,7 +45,7 @@ impl InitializeMintGovernor<'_> {
4445
let clock = Clock::get()?;
4546
let mint_governor = &ctx.accounts.mint_governor;
4647

47-
emit!(MintGovernorInitializedEvent {
48+
emit_cpi!(MintGovernorInitializedEvent {
4849
common: CommonFields {
4950
slot: clock.slot,
5051
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/mint_tokens.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct MintTokensArgs {
1111
pub amount: u64,
1212
}
1313

14+
#[event_cpi]
1415
#[derive(Accounts)]
1516
pub struct MintTokens<'info> {
1617
#[account(mut)]
@@ -93,7 +94,7 @@ impl MintTokens<'_> {
9394
// Reload mint to get post-mint supply
9495
ctx.accounts.mint.reload()?;
9596

96-
emit!(TokensMintedEvent {
97+
emit_cpi!(TokensMintedEvent {
9798
common: CommonFields {
9899
slot: clock.slot,
99100
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/reclaim_authority.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
CommonFields, MintAuthorityReclaimedEvent, MintGovernor, MintGovernorError, MINT_GOVERNOR_SEED,
77
};
88

9+
#[event_cpi]
910
#[derive(Accounts)]
1011
pub struct ReclaimAuthority<'info> {
1112
#[account(mut)]
@@ -68,7 +69,7 @@ impl ReclaimAuthority<'_> {
6869
// Emit event
6970
let clock = Clock::get()?;
7071

71-
emit!(MintAuthorityReclaimedEvent {
72+
emit_cpi!(MintAuthorityReclaimedEvent {
7273
common: CommonFields {
7374
slot: clock.slot,
7475
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/remove_mint_authority.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
CommonFields, MintAuthority, MintAuthorityRemovedEvent, MintGovernor, MintGovernorError,
55
};
66

7+
#[event_cpi]
78
#[derive(Accounts)]
89
pub struct RemoveMintAuthority<'info> {
910
#[account(mut)]
@@ -39,7 +40,7 @@ impl RemoveMintAuthority<'_> {
3940
// Emit event
4041
let clock = Clock::get()?;
4142

42-
emit!(MintAuthorityRemovedEvent {
43+
emit_cpi!(MintAuthorityRemovedEvent {
4344
common: CommonFields {
4445
slot: clock.slot,
4546
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/transfer_authority_to_governor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anchor_spl::token::{self, Mint, SetAuthority, Token};
44

55
use crate::{CommonFields, MintAuthorityTransferredEvent, MintGovernor, MintGovernorError};
66

7+
#[event_cpi]
78
#[derive(Accounts)]
89
pub struct TransferAuthorityToGovernor<'info> {
910
#[account(mut)]
@@ -47,7 +48,7 @@ impl TransferAuthorityToGovernor<'_> {
4748
// Emit event
4849
let clock = Clock::get()?;
4950

50-
emit!(MintAuthorityTransferredEvent {
51+
emit_cpi!(MintAuthorityTransferredEvent {
5152
common: CommonFields {
5253
slot: clock.slot,
5354
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/update_mint_authority.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct UpdateMintAuthorityArgs {
99
pub max_total: Option<u64>,
1010
}
1111

12+
#[event_cpi]
1213
#[derive(Accounts)]
1314
pub struct UpdateMintAuthority<'info> {
1415
#[account(mut)]
@@ -42,7 +43,7 @@ impl UpdateMintAuthority<'_> {
4243
// Emit event
4344
let clock = Clock::get()?;
4445

45-
emit!(MintAuthorityUpdatedEvent {
46+
emit_cpi!(MintAuthorityUpdatedEvent {
4647
common: CommonFields {
4748
slot: clock.slot,
4849
unix_timestamp: clock.unix_timestamp,

programs/mint_governor/src/instructions/update_mint_governor_admin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anchor_lang::prelude::*;
22

33
use crate::{CommonFields, MintGovernor, MintGovernorAdminUpdatedEvent, MintGovernorError};
44

5+
#[event_cpi]
56
#[derive(Accounts)]
67
pub struct UpdateMintGovernorAdmin<'info> {
78
#[account(mut)]
@@ -27,7 +28,7 @@ impl UpdateMintGovernorAdmin<'_> {
2728

2829
let clock = Clock::get()?;
2930

30-
emit!(MintGovernorAdminUpdatedEvent {
31+
emit_cpi!(MintGovernorAdminUpdatedEvent {
3132
common: CommonFields {
3233
slot: clock.slot,
3334
unix_timestamp: clock.unix_timestamp,

programs/performance_package_v2/src/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ pub const CHANGE_REQUEST_SEED: &[u8] = b"change_request";
55

66
#[constant]
77
pub const MAX_TRANCHES: usize = 10;
8+
9+
#[constant]
10+
pub const MAX_MIN_DURATION: u32 = 60 * 60 * 24 * 365; // 365 days in seconds

programs/performance_package_v2/src/error.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use anchor_lang::prelude::*;
22

33
#[error_code]
44
pub enum PerformancePackageError {
5-
// Authorization
65
#[msg("Signer is neither authority nor recipient")]
76
Unauthorized,
87
#[msg("Executor is not the opposite party from proposer")]
@@ -11,20 +10,14 @@ pub enum PerformancePackageError {
1110
InvalidAuthority,
1211
#[msg("Signer is not the admin")]
1312
InvalidAdmin,
14-
15-
// Account validation
1613
#[msg("Mint governor does not match the provided mint")]
1714
InvalidMintGovernor,
1815
#[msg("Mint authority does not match expected configuration")]
1916
InvalidMintAuthority,
20-
21-
// State
2217
#[msg("Expected Locked status")]
2318
NotLocked,
2419
#[msg("Expected Unlocking status")]
2520
NotUnlocking,
26-
27-
// Oracle
2821
#[msg("Expected remaining_accounts not provided")]
2922
OracleMissingAccount,
3023
#[msg("Account pubkey doesn't match expected")]
@@ -35,24 +28,18 @@ pub enum PerformancePackageError {
3528
OracleInvalidState,
3629
#[msg("Minimum duration hasn't passed yet")]
3730
OracleMinDurationNotReached,
38-
39-
// Time
4031
#[msg("Minimum unlock timestamp not yet reached")]
4132
UnlockTimestampNotReached,
42-
43-
// Rewards
4433
#[msg("Math overflow in reward function")]
4534
RewardCalculationOverflow,
46-
47-
// Configuration
4835
#[msg("Tranches should be sorted and non-empty")]
4936
InvalidTranches,
5037
#[msg("Invalid vesting schedule configuration")]
5138
InvalidVestingSchedule,
52-
53-
// Change Requests
5439
#[msg("Missing proposal for execute")]
5540
ChangeRequestNotFound,
5641
#[msg("All optional change fields are None")]
5742
NoChangesProposed,
43+
#[msg("min_duration exceeds maximum allowed (365 days)")]
44+
MinDurationTooLarge,
5845
}

0 commit comments

Comments
 (0)