Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct AddMintAuthorityArgs {
pub max_total: Option<u64>,
}

#[event_cpi]
#[derive(Accounts)]
pub struct AddMintAuthority<'info> {
#[account(mut)]
Expand Down Expand Up @@ -57,7 +58,7 @@ impl AddMintAuthority<'_> {

let clock = Clock::get()?;

emit!(MintAuthorityAddedEvent {
emit_cpi!(MintAuthorityAddedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anchor_spl::token::Mint;

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

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

emit!(MintGovernorInitializedEvent {
emit_cpi!(MintGovernorInitializedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
3 changes: 2 additions & 1 deletion programs/mint_governor/src/instructions/mint_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct MintTokensArgs {
pub amount: u64,
}

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

emit!(TokensMintedEvent {
emit_cpi!(TokensMintedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
3 changes: 2 additions & 1 deletion programs/mint_governor/src/instructions/reclaim_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
CommonFields, MintAuthorityReclaimedEvent, MintGovernor, MintGovernorError, MINT_GOVERNOR_SEED,
};

#[event_cpi]
#[derive(Accounts)]
pub struct ReclaimAuthority<'info> {
#[account(mut)]
Expand Down Expand Up @@ -68,7 +69,7 @@ impl ReclaimAuthority<'_> {
// Emit event
let clock = Clock::get()?;

emit!(MintAuthorityReclaimedEvent {
emit_cpi!(MintAuthorityReclaimedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
CommonFields, MintAuthority, MintAuthorityRemovedEvent, MintGovernor, MintGovernorError,
};

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

emit!(MintAuthorityRemovedEvent {
emit_cpi!(MintAuthorityRemovedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anchor_spl::token::{self, Mint, SetAuthority, Token};

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

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

emit!(MintAuthorityTransferredEvent {
emit_cpi!(MintAuthorityTransferredEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct UpdateMintAuthorityArgs {
pub max_total: Option<u64>,
}

#[event_cpi]
#[derive(Accounts)]
pub struct UpdateMintAuthority<'info> {
#[account(mut)]
Expand Down Expand Up @@ -42,7 +43,7 @@ impl UpdateMintAuthority<'_> {
// Emit event
let clock = Clock::get()?;

emit!(MintAuthorityUpdatedEvent {
emit_cpi!(MintAuthorityUpdatedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anchor_lang::prelude::*;

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

#[event_cpi]
#[derive(Accounts)]
pub struct UpdateMintGovernorAdmin<'info> {
#[account(mut)]
Expand All @@ -27,7 +28,7 @@ impl UpdateMintGovernorAdmin<'_> {

let clock = Clock::get()?;

emit!(MintGovernorAdminUpdatedEvent {
emit_cpi!(MintGovernorAdminUpdatedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
3 changes: 3 additions & 0 deletions programs/performance_package_v2/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ pub const CHANGE_REQUEST_SEED: &[u8] = b"change_request";

#[constant]
pub const MAX_TRANCHES: usize = 10;

#[constant]
pub const MAX_MIN_DURATION: u32 = 60 * 60 * 24 * 365; // 365 days in seconds
17 changes: 2 additions & 15 deletions programs/performance_package_v2/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anchor_lang::prelude::*;

#[error_code]
pub enum PerformancePackageError {
// Authorization
#[msg("Signer is neither authority nor recipient")]
Unauthorized,
#[msg("Executor is not the opposite party from proposer")]
Expand All @@ -11,20 +10,14 @@ pub enum PerformancePackageError {
InvalidAuthority,
#[msg("Signer is not the admin")]
InvalidAdmin,

// Account validation
#[msg("Mint governor does not match the provided mint")]
InvalidMintGovernor,
#[msg("Mint authority does not match expected configuration")]
InvalidMintAuthority,

// State
#[msg("Expected Locked status")]
NotLocked,
#[msg("Expected Unlocking status")]
NotUnlocking,

// Oracle
#[msg("Expected remaining_accounts not provided")]
OracleMissingAccount,
#[msg("Account pubkey doesn't match expected")]
Expand All @@ -35,24 +28,18 @@ pub enum PerformancePackageError {
OracleInvalidState,
#[msg("Minimum duration hasn't passed yet")]
OracleMinDurationNotReached,

// Time
#[msg("Minimum unlock timestamp not yet reached")]
UnlockTimestampNotReached,

// Rewards
#[msg("Math overflow in reward function")]
RewardCalculationOverflow,

// Configuration
#[msg("Tranches should be sorted and non-empty")]
InvalidTranches,
#[msg("Invalid vesting schedule configuration")]
InvalidVestingSchedule,

// Change Requests
#[msg("Missing proposal for execute")]
ChangeRequestNotFound,
#[msg("All optional change fields are None")]
NoChangesProposed,
#[msg("min_duration exceeds maximum allowed (365 days)")]
MinDurationTooLarge,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
PERFORMANCE_PACKAGE_SEED,
};

#[event_cpi]
#[derive(Accounts)]
pub struct ChangeAuthority<'info> {
#[account(
Expand Down Expand Up @@ -37,7 +38,7 @@ impl ChangeAuthority<'_> {

let clock = Clock::get()?;

emit!(AuthorityChangedEvent {
emit_cpi!(AuthorityChangedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod admin {
declare_id!("6awyHMshBGVjJ3ozdSJdyyDE1CTAXUwrpNMaRGMsb4sf");
}

#[event_cpi]
#[derive(Accounts)]
pub struct ClosePerformancePackage<'info> {
#[account(
Expand Down Expand Up @@ -51,7 +52,7 @@ impl ClosePerformancePackage<'_> {
let pp = &ctx.accounts.performance_package;
let clock = Clock::get()?;

emit!(PerformancePackageClosedEvent {
emit_cpi!(PerformancePackageClosedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
PERFORMANCE_PACKAGE_SEED,
};

#[event_cpi]
#[derive(Accounts)]
pub struct CompleteUnlock<'info> {
#[account(
Expand Down Expand Up @@ -56,6 +57,9 @@ pub struct CompleteUnlock<'info> {
pub associated_token_program: Program<'info, AssociatedToken>,

pub mint_governor_program: Program<'info, MintGovernorProgram>,

/// CHECK: checked by mint_governor program
pub mint_governor_event_authority: UncheckedAccount<'info>,
}

impl CompleteUnlock<'_> {
Expand Down Expand Up @@ -120,6 +124,8 @@ impl CompleteUnlock<'_> {
destination_ata: ctx.accounts.recipient_ata.to_account_info(),
authorized_minter: ctx.accounts.performance_package.to_account_info(),
token_program: ctx.accounts.token_program.to_account_info(),
event_authority: ctx.accounts.mint_governor_event_authority.to_account_info(),
program: ctx.accounts.mint_governor_program.to_account_info(),
},
signer_seeds,
);
Expand Down Expand Up @@ -151,7 +157,7 @@ impl CompleteUnlock<'_> {

let clock = Clock::get()?;

emit!(UnlockCompletedEvent {
emit_cpi!(UnlockCompletedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
PerformancePackageError, ProposerType,
};

#[event_cpi]
#[derive(Accounts)]
pub struct ExecuteChange<'info> {
#[account(mut)]
Expand Down Expand Up @@ -92,7 +93,7 @@ impl ExecuteChange<'_> {

let clock = Clock::get()?;

emit!(ChangeExecutedEvent {
emit_cpi!(ChangeExecutedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct InitializePerformancePackageArgs {
pub min_unlock_timestamp: i64,
}

#[event_cpi]
#[derive(Accounts)]
pub struct InitializePerformancePackage<'info> {
#[account(
Expand Down Expand Up @@ -81,7 +82,7 @@ impl InitializePerformancePackage<'_> {
let clock = Clock::get()?;
let pp = &ctx.accounts.performance_package;

emit!(PerformancePackageCreatedEvent {
emit_cpi!(PerformancePackageCreatedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct ProposeChangeArgs {
pub new_reward_function: Option<RewardFunction>,
}

#[event_cpi]
#[derive(Accounts)]
#[instruction(args: ProposeChangeArgs)]
pub struct ProposeChange<'info> {
Expand Down Expand Up @@ -102,7 +103,7 @@ impl ProposeChange<'_> {
// Increment seq_num for event tracking
pp.seq_num += 1;

emit!(ChangeProposedEvent {
emit_cpi!(ChangeProposedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
10 changes: 6 additions & 4 deletions programs/performance_package_v2/src/instructions/start_unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
PERFORMANCE_PACKAGE_SEED,
};

#[event_cpi]
#[derive(Accounts)]
pub struct StartUnlock<'info> {
#[account(
Expand All @@ -21,9 +22,10 @@ impl StartUnlock<'_> {
pub fn validate(&self) -> Result<()> {
let pp = &self.performance_package;

// Signer must be authority or recipient
require!(
self.signer.key() == pp.authority || self.signer.key() == pp.recipient,
// Only the recipient can start an unlock
require_keys_eq!(
self.signer.key(),
pp.recipient,
PerformancePackageError::Unauthorized
);

Expand Down Expand Up @@ -58,7 +60,7 @@ impl StartUnlock<'_> {

let clock = Clock::get()?;

emit!(UnlockStartedEvent {
emit_cpi!(UnlockStartedEvent {
common: CommonFields {
slot: clock.slot,
unix_timestamp: clock.unix_timestamp,
Expand Down
Loading
Loading