1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

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
}