1use ore_api::state::proof_pda;
2use steel::*;
3
4use crate::{
5 instruction::*,
6 state::{boost_pda, config_pda, stake_pda},
7};
8
9pub fn activate(signer: Pubkey, mint: Pubkey) -> Instruction {
11 let boost_pda = boost_pda(mint);
12 let config_pda = config_pda();
13 Instruction {
14 program_id: crate::ID,
15 accounts: vec![
16 AccountMeta::new(signer, true),
17 AccountMeta::new_readonly(boost_pda.0, false),
18 AccountMeta::new(config_pda.0, false),
19 ],
20 data: Activate {}.to_bytes(),
21 }
22}
23
24pub fn claim(signer: Pubkey, beneficiary: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
26 let boost_address = boost_pda(mint).0;
27 let config_address = config_pda().0;
28 let proof_address = proof_pda(config_address).0;
29 let rewards_address = spl_associated_token_account::get_associated_token_address(
30 &config_address,
31 &ore_api::consts::MINT_ADDRESS,
32 );
33 let stake_address = stake_pda(signer, boost_address).0;
34 Instruction {
35 program_id: crate::ID,
36 accounts: vec![
37 AccountMeta::new(signer, true),
38 AccountMeta::new(beneficiary, false),
39 AccountMeta::new(boost_address, false),
40 AccountMeta::new(config_address, false),
41 AccountMeta::new(proof_address, false),
42 AccountMeta::new(rewards_address, false),
43 AccountMeta::new(stake_address, false),
44 AccountMeta::new_readonly(ore_api::consts::TREASURY_ADDRESS, false),
45 AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
46 AccountMeta::new_readonly(ore_api::ID, false),
47 AccountMeta::new_readonly(spl_token::ID, false),
48 ],
49 data: Claim {
50 amount: amount.to_le_bytes(),
51 }
52 .to_bytes(),
53 }
54}
55
56pub fn deactivate(signer: Pubkey, mint: Pubkey) -> Instruction {
58 let boost_pda = boost_pda(mint);
59 let config_pda = config_pda();
60 Instruction {
61 program_id: crate::ID,
62 accounts: vec![
63 AccountMeta::new(signer, true),
64 AccountMeta::new_readonly(boost_pda.0, false),
65 AccountMeta::new(config_pda.0, false),
66 ],
67 data: Deactivate {}.to_bytes(),
68 }
69}
70
71pub fn deposit(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
73 let boost_address = boost_pda(mint).0;
74 let config_address = config_pda().0;
75 let deposits_address =
76 spl_associated_token_account::get_associated_token_address(&boost_address, &mint);
77
78 let proof_address = proof_pda(config_address).0;
79 let rewards_address = spl_associated_token_account::get_associated_token_address(
80 &config_address,
81 &ore_api::consts::MINT_ADDRESS,
82 );
83 let sender_address = spl_associated_token_account::get_associated_token_address(&signer, &mint);
84 let stake_address = stake_pda(signer, boost_address).0;
85 Instruction {
86 program_id: crate::ID,
87 accounts: vec![
88 AccountMeta::new(signer, true),
89 AccountMeta::new(boost_address, false),
90 AccountMeta::new(config_address, false),
91 AccountMeta::new(deposits_address, false),
92 AccountMeta::new_readonly(mint, false),
93 AccountMeta::new(proof_address, false),
94 AccountMeta::new(rewards_address, false),
95 AccountMeta::new(sender_address, false),
96 AccountMeta::new(stake_address, false),
97 AccountMeta::new_readonly(ore_api::consts::TREASURY_ADDRESS, false),
98 AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
99 AccountMeta::new_readonly(ore_api::ID, false),
100 AccountMeta::new_readonly(spl_token::ID, false),
101 ],
102 data: Deposit {
103 amount: amount.to_le_bytes(),
104 }
105 .to_bytes(),
106 }
107}
108
109pub fn initialize(signer: Pubkey) -> Instruction {
111 let config_pda = config_pda();
112 Instruction {
113 program_id: crate::ID,
114 accounts: vec![
115 AccountMeta::new(signer, true),
116 AccountMeta::new(config_pda.0, false),
117 AccountMeta::new_readonly(system_program::ID, false),
118 ],
119 data: Initialize {}.to_bytes(),
120 }
121}
122
123pub fn new(signer: Pubkey, mint: Pubkey, expires_at: i64, weight: u64) -> Instruction {
125 let boost_pda = boost_pda(mint);
126 let boost_deposits_address =
127 spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
128 let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
129 &boost_pda.0,
130 &ore_api::consts::MINT_ADDRESS,
131 );
132 let config_pda = config_pda();
133 let proof_pda = proof_pda(boost_pda.0);
134 Instruction {
135 program_id: crate::ID,
136 accounts: vec![
137 AccountMeta::new(signer, true),
138 AccountMeta::new(boost_pda.0, false),
139 AccountMeta::new(boost_deposits_address, false),
140 AccountMeta::new(boost_rewards_address, false),
141 AccountMeta::new(config_pda.0, false),
142 AccountMeta::new_readonly(mint, false),
143 AccountMeta::new_readonly(ore_api::consts::MINT_ADDRESS, false),
144 AccountMeta::new(proof_pda.0, false),
145 AccountMeta::new_readonly(ore_api::ID, false),
146 AccountMeta::new_readonly(system_program::ID, false),
147 AccountMeta::new_readonly(spl_token::ID, false),
148 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
149 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
150 ],
151 data: New {
152 expires_at: expires_at.to_le_bytes(),
153 weight: weight.to_le_bytes(),
154 }
155 .to_bytes(),
156 }
157}
158
159pub fn open(signer: Pubkey, payer: Pubkey, mint: Pubkey) -> Instruction {
161 let boost_pda = boost_pda(mint);
162 let stake_pda = stake_pda(signer, boost_pda.0);
163 Instruction {
164 program_id: crate::ID,
165 accounts: vec![
166 AccountMeta::new(signer, true),
167 AccountMeta::new(payer, true),
168 AccountMeta::new(boost_pda.0, false),
169 AccountMeta::new_readonly(mint, false),
170 AccountMeta::new(stake_pda.0, false),
171 AccountMeta::new_readonly(system_program::ID, false),
172 ],
173 data: Open {}.to_bytes(),
174 }
175}
176
177pub fn update_boost(signer: Pubkey, boost: Pubkey, expires_at: i64, weight: u64) -> Instruction {
181 let config_address = config_pda().0;
182 let proof_address = proof_pda(boost).0;
183 let rewards_address = spl_associated_token_account::get_associated_token_address(
184 &config_address,
185 &ore_api::consts::MINT_ADDRESS,
186 );
187 Instruction {
188 program_id: crate::ID,
189 accounts: vec![
190 AccountMeta::new(signer, true),
191 AccountMeta::new(boost, false),
192 AccountMeta::new(config_address, false),
193 AccountMeta::new(proof_address, false),
194 AccountMeta::new(rewards_address, false),
195 AccountMeta::new(ore_api::consts::TREASURY_ADDRESS, false),
196 AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
197 AccountMeta::new_readonly(ore_api::ID, false),
198 AccountMeta::new_readonly(spl_token::ID, false),
199 ],
200 data: UpdateBoost {
201 expires_at: expires_at.to_le_bytes(),
202 weight: weight.to_le_bytes(),
203 }
204 .to_bytes(),
205 }
206}
207
208pub fn withdraw(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
210 let boost_address = boost_pda(mint).0;
211 let config_address = config_pda().0;
212 let deposits_address =
213 spl_associated_token_account::get_associated_token_address(&boost_address, &mint);
214 let proof_address = proof_pda(config_address).0;
215 let rewards_address = spl_associated_token_account::get_associated_token_address(
216 &config_address,
217 &ore_api::consts::MINT_ADDRESS,
218 );
219 let beneficiary_address =
220 spl_associated_token_account::get_associated_token_address(&signer, &mint);
221 let stake_address = stake_pda(signer, boost_address).0;
222 Instruction {
223 program_id: crate::ID,
224 accounts: vec![
225 AccountMeta::new(signer, true),
226 AccountMeta::new(beneficiary_address, false),
227 AccountMeta::new(boost_address, false),
228 AccountMeta::new(config_address, false),
229 AccountMeta::new(deposits_address, false),
230 AccountMeta::new_readonly(mint, false),
231 AccountMeta::new(proof_address, false),
232 AccountMeta::new(rewards_address, false),
233 AccountMeta::new(stake_address, false),
234 AccountMeta::new_readonly(ore_api::consts::TREASURY_ADDRESS, false),
235 AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
236 AccountMeta::new_readonly(ore_api::ID, false),
237 AccountMeta::new_readonly(spl_token::ID, false),
238 ],
239 data: Withdraw {
240 amount: amount.to_le_bytes(),
241 }
242 .to_bytes(),
243 }
244}