use crate::{constants::FREEZE_FEE, CandyError};
use anchor_lang::prelude::*;
#[account]
#[derive(Default, Debug)]
pub struct CandyMachine {
pub authority: Pubkey,
pub wallet: Pubkey,
pub token_mint: Option<Pubkey>,
pub items_redeemed: u64,
pub data: CandyMachineData,
}
#[account]
#[derive(Default, Debug)]
pub struct CollectionPDA {
pub mint: Pubkey,
pub candy_machine: Pubkey,
}
impl CollectionPDA {
pub const PREFIX: &'static str = "collection";
}
#[account]
#[derive(Default, Debug, PartialEq, Eq)]
pub struct FreezePDA {
pub candy_machine: Pubkey, pub allow_thaw: bool, pub frozen_count: u64, pub mint_start: Option<i64>, pub freeze_time: i64, pub freeze_fee: u64, }
impl FreezePDA {
pub const SIZE: usize = 8 + 32 + 32 + 1 + 8 + 1 + 8 + 8 + 8;
pub const PREFIX: &'static str = "freeze";
pub fn init(&mut self, candy_machine: Pubkey, mint_start: Option<i64>, freeze_time: i64) {
self.candy_machine = candy_machine;
self.allow_thaw = false;
self.frozen_count = 0;
self.mint_start = mint_start;
self.freeze_time = freeze_time;
self.freeze_fee = FREEZE_FEE;
}
pub fn thaw_eligible(&self, current_timestamp: i64, candy_machine: &CandyMachine) -> bool {
if self.allow_thaw || candy_machine.items_redeemed >= candy_machine.data.items_available {
return true;
} else if let Some(start_timestamp) = self.mint_start {
if current_timestamp >= start_timestamp + self.freeze_time {
return true;
}
}
false
}
pub fn assert_from_candy(&self, candy_machine: &Pubkey) -> Result<()> {
if &self.candy_machine != candy_machine {
return err!(CandyError::FreezePDAMismatch);
}
Ok(())
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default, Debug)]
pub struct CandyMachineData {
pub uuid: String,
pub price: u64,
pub symbol: String,
pub seller_fee_basis_points: u16,
pub max_supply: u64,
pub is_mutable: bool,
pub retain_authority: bool,
pub go_live_date: Option<i64>,
pub end_settings: Option<EndSettings>,
pub creators: Vec<Creator>,
pub hidden_settings: Option<HiddenSettings>,
pub whitelist_mint_settings: Option<WhitelistMintSettings>,
pub items_available: u64,
pub gatekeeper: Option<GatekeeperConfig>,
}
impl CandyMachine {
pub fn assert_not_minted(&self, candy_error: Error) -> Result<()> {
if self.items_redeemed > 0 {
Err(candy_error)
} else {
Ok(())
}
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Debug)]
pub struct ConfigLine {
pub name: String,
pub uri: String,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct EndSettings {
pub end_setting_type: EndSettingType,
pub number: u64,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub enum EndSettingType {
Date,
Amount,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct Creator {
pub address: Pubkey,
pub verified: bool,
pub share: u8,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default, Debug)]
pub struct HiddenSettings {
pub name: String,
pub uri: String,
pub hash: [u8; 32],
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct WhitelistMintSettings {
pub mode: WhitelistMintMode,
pub mint: Pubkey,
pub presale: bool,
pub discount_price: Option<u64>,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Eq, PartialEq, Debug)]
pub enum WhitelistMintMode {
BurnEveryTime,
NeverBurn,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct GatekeeperConfig {
pub gatekeeper_network: Pubkey,
pub expire_on_use: bool,
}