phase-protocol-sdk 0.3.0

Integration SDK for phase-protocol and fundraising programs
Documentation

use crate::id;
use anchor_lang::{account, prelude::Pubkey, prelude::*, AnchorDeserialize, AnchorSerialize};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Debug)]
pub enum RoadmapGovType {
    NFT,

    //Not implemented
    SPL,
}


#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Debug)]

pub enum RoadmapState {
    //In draft a roadmap config can be freely edited and updated
    Draft,

    LockedForMint,

    Resolution,

    StagedForResolution,

    // State to show that some staged phases have been moved into approved state
    // while some are still to be processed into that state
    Actioning,

    // The Roadmap has been approved and team is now able to action phases
    // to show what they are currently implementing from the roadmap
    Actioned,

    Refunding,

    // Not currently implemented
    Complete,

    Canceled,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Debug)]
pub struct RoadmapConfig {
    pub usdc_team_withdrawl_account: Pubkey,
    pub sol_team_withdrawal_account: Pubkey,
    pub minting_account_plugin_program_address: Option<Pubkey>,
    // Authority can be set for plugin to allow creation of minting account seperate from team authority
    pub dev_authority: Pubkey,
}


#[account]
#[derive(Debug)]
pub struct Roadmap {
    pub realm: Pubkey,
    pub collection: Option<Pubkey>,
    pub team_authority: Pubkey,
    pub dao_authority: Pubkey,
    pub metadata_shadow_drive: Pubkey,
    pub governance_program_id: Pubkey,
    pub governance_type: RoadmapGovType,
    pub state: RoadmapState,
    pub config: RoadmapConfig,
    pub staged_phase_count: u8,
    pub locked_phase_count: u8,
    pub resolution_proposal: Option<Pubkey>,

    // Amount of value in phases that are in lockedForMint state
    // Only can be actioned if mint completes or is withdrawn and there is enough in the pools
    // to transfer into phase vaults
    pub locked_total_usdc: u64,
    pub locked_total_sol: u64,

    // Amount for phases staged for approval once the roadmap has been unlocked and is in actioning state
    pub staged_total_usdc: u64,
    pub staged_total_sol: u64,

    pub approved_phase_count: u8,
    pub phase_count: u8,
    pub phases_complete: u8,
    pub usdc_roadmap_pool: Pubkey,
    pub sol_roadmap_pool: Pubkey,
    pub mint_contract_record: Option<Pubkey>,
    pub bump: u8,
    pub initial_payout_percentage : u16,
    pub has_initial_payout_completed : bool,
    pub reserved: [u8; 15],
    pub name: String,
}

impl Roadmap {
    pub fn space(name: &str) -> usize {
        8 +
        std::mem::size_of::<Pubkey>() + // realm_pubkey
        4 + std::mem::size_of::<Pubkey>() + // collection
        std::mem::size_of::<Pubkey>() + // team_authority
        std::mem::size_of::<Pubkey>() + // dao_authority
        std::mem::size_of::<Pubkey>() + // metadata_shadow_drive
        std::mem::size_of::<Pubkey>() + // governance_program_id
        1+ //governance type
        1 + // state
        std::mem::size_of::<RoadmapConfig>() +
        1 + // Staged count
        1 + // Locked count
        4 + std::mem::size_of::<Pubkey>()+ // roadmap_resolution_proposal
        16 + // locked_total_usdc
        16 + // locked_total_sol
        16 + // staged total usd
        16 + // staged total sol
        1 + // Approved phase count
        1 + // Phase count
        1 + //Phases completed
        std::mem::size_of::<Pubkey>()+ // usdc roadmap_pool
        std::mem::size_of::<Pubkey>()+ // sol roadmap_pool
        4 + std::mem::size_of::<Pubkey>()+ // mint_contract_record
        1 + // bump,
        16 + //payout percentage
        1 + // has initial payout completed
        15 + //reserved
        name.len()
    }
}


pub fn get_roadmap_address(realm: &Pubkey, governance_program: &Pubkey) -> Pubkey {
    Pubkey::find_program_address(
        &[b"roadmap", governance_program.as_ref(), realm.as_ref()],
        &id(),
    )
    .0
}

pub fn get_roadmap_pool_address(roadmap: &Pubkey, mint: &Pubkey) -> Pubkey {
    Pubkey::find_program_address(&[b"roadmap_pool", roadmap.as_ref(), mint.as_ref()], &id()).0
}