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
use crate::utils::try_from_slice_checked;
use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankAccount;
use safecoin_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
pub const PREFIX: &str = "vault";
#[repr(C)]
#[derive(Clone, BorshSerialize, BorshDeserialize, PartialEq)]
pub enum Key {
Uninitialized,
SafetyDepositBoxV1,
ExternalAccountKeyV1,
VaultV1,
}
pub const MAX_SAFETY_DEPOSIT_SIZE: usize = 1 + 32 + 32 + 32 + 1;
pub const MAX_VAULT_SIZE: usize = 1 + 32 + 32 + 32 + 32 + 1 + 32 + 1 + 32 + 1 + 1 + 8;
pub const MAX_EXTERNAL_ACCOUNT_SIZE: usize = 1 + 8 + 32 + 1;
#[repr(C)]
#[derive(Clone, BorshSerialize, BorshDeserialize, PartialEq)]
pub enum VaultState {
Inactive,
Active,
Combined,
Deactivated,
}
#[repr(C)]
#[derive(Clone, BorshSerialize, BorshDeserialize, ShankAccount)]
pub struct Vault {
pub key: Key,
pub token_program: Pubkey,
pub fraction_mint: Pubkey,
pub authority: Pubkey,
pub fraction_treasury: Pubkey,
pub redeem_treasury: Pubkey,
pub allow_further_share_creation: bool,
pub pricing_lookup_address: Pubkey,
pub token_type_count: u8,
pub state: VaultState,
pub locked_price_per_share: u64,
_extra_byte: u8,
}
impl Vault {
pub fn from_account_info(a: &AccountInfo) -> Result<Vault, ProgramError> {
let vt: Vault = try_from_slice_checked(&a.data.borrow_mut(), Key::VaultV1, MAX_VAULT_SIZE)?;
Ok(vt)
}
pub fn get_token_type_count(a: &AccountInfo) -> u8 {
return a.data.borrow()[194];
}
}
#[repr(C)]
#[derive(Clone, BorshSerialize, BorshDeserialize, ShankAccount)]
pub struct SafetyDepositBox {
pub key: Key,
pub vault: Pubkey,
pub token_mint: Pubkey,
pub store: Pubkey,
pub order: u8,
}
impl SafetyDepositBox {
pub fn from_account_info(a: &AccountInfo) -> Result<SafetyDepositBox, ProgramError> {
let sd: SafetyDepositBox = try_from_slice_checked(
&a.data.borrow_mut(),
Key::SafetyDepositBoxV1,
MAX_SAFETY_DEPOSIT_SIZE,
)?;
Ok(sd)
}
pub fn get_order(a: &AccountInfo) -> u8 {
a.data.borrow()[97]
}
}
#[repr(C)]
#[derive(Clone, BorshSerialize, BorshDeserialize, ShankAccount)]
pub struct ExternalPriceAccount {
pub key: Key,
pub price_per_share: u64,
pub price_mint: Pubkey,
pub allowed_to_combine: bool,
}
impl ExternalPriceAccount {
pub fn from_account_info(a: &AccountInfo) -> Result<ExternalPriceAccount, ProgramError> {
let sd: ExternalPriceAccount = try_from_slice_checked(
&a.data.borrow_mut(),
Key::ExternalAccountKeyV1,
MAX_EXTERNAL_ACCOUNT_SIZE,
)?;
Ok(sd)
}
}