ore_boost_api/
sdk.rs

1use ore_api::{
2    consts::{TREASURY_ADDRESS, TREASURY_TOKENS_ADDRESS},
3    state::proof_pda,
4};
5use steel::*;
6
7use crate::{
8    instruction::*,
9    state::{boost_pda, checkpoint_pda, config_pda, directory_pda, reservation_pda, stake_pda},
10};
11
12// Build activate instruction.
13pub fn activate(signer: Pubkey, mint: Pubkey) -> Instruction {
14    let boost_pda = boost_pda(mint);
15    let directory_pda = directory_pda();
16    Instruction {
17        program_id: crate::ID,
18        accounts: vec![
19            AccountMeta::new(signer, true),
20            AccountMeta::new(boost_pda.0, false),
21            AccountMeta::new(directory_pda.0, false),
22            AccountMeta::new_readonly(config_pda().0, false),
23        ],
24        data: Activate {}.to_bytes(),
25    }
26}
27
28// Build claim instruction.
29pub fn claim(signer: Pubkey, beneficiary: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
30    let boost_pda = boost_pda(mint);
31    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
32        &boost_pda.0,
33        &ore_api::consts::MINT_ADDRESS,
34    );
35    let stake_pda = stake_pda(signer, boost_pda.0);
36    Instruction {
37        program_id: crate::ID,
38        accounts: vec![
39            AccountMeta::new(signer, true),
40            AccountMeta::new(beneficiary, false),
41            AccountMeta::new_readonly(boost_pda.0, false),
42            AccountMeta::new(boost_rewards_address, false),
43            AccountMeta::new(stake_pda.0, false),
44            AccountMeta::new_readonly(spl_token::ID, false),
45        ],
46        data: Claim {
47            amount: amount.to_le_bytes(),
48        }
49        .to_bytes(),
50    }
51}
52
53// Build deactivate instruction.
54pub fn deactivate(signer: Pubkey, mint: Pubkey) -> Instruction {
55    let boost_pda = boost_pda(mint);
56    let directory_pda = directory_pda();
57    Instruction {
58        program_id: crate::ID,
59        accounts: vec![
60            AccountMeta::new(signer, true),
61            AccountMeta::new(boost_pda.0, false),
62            AccountMeta::new(directory_pda.0, false),
63            AccountMeta::new_readonly(config_pda().0, false),
64        ],
65        data: Deactivate {}.to_bytes(),
66    }
67}
68
69// Build deposit instruction.
70pub fn deposit(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
71    let boost_pda = boost_pda(mint);
72    let boost_deposits_address =
73        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
74    let sender_address = spl_associated_token_account::get_associated_token_address(&signer, &mint);
75    let stake_pda = stake_pda(signer, boost_pda.0);
76    Instruction {
77        program_id: crate::ID,
78        accounts: vec![
79            AccountMeta::new(signer, true),
80            AccountMeta::new(boost_pda.0, false),
81            AccountMeta::new(boost_deposits_address, false),
82            AccountMeta::new_readonly(mint, false),
83            AccountMeta::new(sender_address, false),
84            AccountMeta::new(stake_pda.0, false),
85            AccountMeta::new_readonly(spl_token::ID, false),
86        ],
87        data: Deposit {
88            amount: amount.to_le_bytes(),
89        }
90        .to_bytes(),
91    }
92}
93
94// Build initialize instruction.
95pub fn initialize(signer: Pubkey) -> Instruction {
96    let config_pda = config_pda();
97    let directory_pda = directory_pda();
98    Instruction {
99        program_id: crate::ID,
100        accounts: vec![
101            AccountMeta::new(signer, true),
102            AccountMeta::new(config_pda.0, false),
103            AccountMeta::new(directory_pda.0, false),
104            AccountMeta::new_readonly(system_program::ID, false),
105        ],
106        data: Initialize {}.to_bytes(),
107    }
108}
109
110// Build new instruction.
111pub fn new(signer: Pubkey, mint: Pubkey, expires_at: i64, multiplier: u64) -> Instruction {
112    let boost_pda = boost_pda(mint);
113    let boost_deposits_address =
114        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
115    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
116        &boost_pda.0,
117        &ore_api::consts::MINT_ADDRESS,
118    );
119    let checkpoint_pda = checkpoint_pda(boost_pda.0);
120    let config_pda = config_pda();
121    let proof_pda = proof_pda(boost_pda.0);
122    Instruction {
123        program_id: crate::ID,
124        accounts: vec![
125            AccountMeta::new(signer, true),
126            AccountMeta::new(boost_pda.0, false),
127            AccountMeta::new(boost_deposits_address, false),
128            AccountMeta::new(boost_rewards_address, false),
129            AccountMeta::new(checkpoint_pda.0, false),
130            AccountMeta::new_readonly(config_pda.0, false),
131            AccountMeta::new(directory_pda().0, false),
132            AccountMeta::new_readonly(mint, false),
133            AccountMeta::new_readonly(ore_api::consts::MINT_ADDRESS, false),
134            AccountMeta::new(proof_pda.0, false),
135            AccountMeta::new_readonly(ore_api::ID, false),
136            AccountMeta::new_readonly(system_program::ID, false),
137            AccountMeta::new_readonly(spl_token::ID, false),
138            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
139            AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
140        ],
141        data: New {
142            expires_at: expires_at.to_le_bytes(),
143            multiplier: multiplier.to_le_bytes(),
144        }
145        .to_bytes(),
146    }
147}
148
149// Build open instruction.
150pub fn open(signer: Pubkey, payer: Pubkey, mint: Pubkey) -> Instruction {
151    let boost_pda = boost_pda(mint);
152    let stake_pda = stake_pda(signer, boost_pda.0);
153    Instruction {
154        program_id: crate::ID,
155        accounts: vec![
156            AccountMeta::new(signer, true),
157            AccountMeta::new(payer, true),
158            AccountMeta::new(boost_pda.0, false),
159            AccountMeta::new_readonly(mint, false),
160            AccountMeta::new(stake_pda.0, false),
161            AccountMeta::new_readonly(system_program::ID, false),
162        ],
163        data: Open {}.to_bytes(),
164    }
165}
166
167// Build rebase instruction.
168pub fn rebase(signer: Pubkey, mint: Pubkey, stake: Pubkey) -> Instruction {
169    let boost_pda = boost_pda(mint);
170    let boost_rewards = spl_associated_token_account::get_associated_token_address(
171        &boost_pda.0,
172        &ore_api::consts::MINT_ADDRESS,
173    );
174    let checkpoint_pda = checkpoint_pda(boost_pda.0);
175    Instruction {
176        program_id: crate::ID,
177        accounts: vec![
178            AccountMeta::new(signer, true),
179            AccountMeta::new(boost_pda.0, false),
180            AccountMeta::new(ore_api::state::proof_pda(boost_pda.0).0, false),
181            AccountMeta::new(boost_rewards, false),
182            AccountMeta::new(checkpoint_pda.0, false),
183            AccountMeta::new(stake, false),
184            AccountMeta::new_readonly(TREASURY_ADDRESS, false),
185            AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
186            AccountMeta::new_readonly(ore_api::ID, false),
187            AccountMeta::new_readonly(spl_token::ID, false),
188        ],
189        data: Rebase {}.to_bytes(),
190    }
191}
192
193// Build register instruction.
194pub fn register(signer: Pubkey, payer: Pubkey, proof: Pubkey) -> Instruction {
195    let reservation_pda = reservation_pda(proof);
196    Instruction {
197        program_id: crate::ID,
198        accounts: vec![
199            AccountMeta::new(signer, true),
200            AccountMeta::new(payer, true),
201            AccountMeta::new_readonly(proof, false),
202            AccountMeta::new(reservation_pda.0, false),
203            AccountMeta::new_readonly(system_program::ID, false),
204            AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
205        ],
206        data: Register {}.to_bytes(),
207    }
208}
209
210// Build rotate instruction.
211pub fn rotate(signer: Pubkey, proof: Pubkey) -> Instruction {
212    let directory_pda = directory_pda();
213    let reservation_pda = reservation_pda(proof);
214    Instruction {
215        program_id: crate::ID,
216        accounts: vec![
217            AccountMeta::new(signer, true),
218            AccountMeta::new_readonly(directory_pda.0, false),
219            AccountMeta::new_readonly(proof, false),
220            AccountMeta::new(reservation_pda.0, false),
221            AccountMeta::new_readonly(TREASURY_TOKENS_ADDRESS, false),
222        ],
223        data: Rotate {}.to_bytes(),
224    }
225}
226
227// Build update_boost instruction.
228pub fn update_boost(
229    signer: Pubkey,
230    boost: Pubkey,
231    expires_at: i64,
232    multiplier: u64,
233) -> Instruction {
234    Instruction {
235        program_id: crate::ID,
236        accounts: vec![
237            AccountMeta::new(signer, true),
238            AccountMeta::new(boost, false),
239            AccountMeta::new_readonly(config_pda().0, false),
240        ],
241        data: UpdateBoost {
242            expires_at: expires_at.to_le_bytes(),
243            multiplier: multiplier.to_le_bytes(),
244        }
245        .to_bytes(),
246    }
247}
248
249// Build withdraw instruction.
250pub fn withdraw(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
251    let boost_pda = boost_pda(mint);
252    let boost_deposits_address =
253        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
254    let beneficiary_address =
255        spl_associated_token_account::get_associated_token_address(&signer, &mint);
256    let stake_pda = stake_pda(signer, boost_pda.0);
257    Instruction {
258        program_id: crate::ID,
259        accounts: vec![
260            AccountMeta::new(signer, true),
261            AccountMeta::new(beneficiary_address, false),
262            AccountMeta::new(boost_pda.0, false),
263            AccountMeta::new(boost_deposits_address, false),
264            AccountMeta::new_readonly(mint, false),
265            AccountMeta::new(stake_pda.0, false),
266            AccountMeta::new_readonly(spl_token::ID, false),
267        ],
268        data: Withdraw {
269            amount: amount.to_le_bytes(),
270        }
271        .to_bytes(),
272    }
273}
274
275// Build migrate instruction.
276pub fn migrate(
277    signer: Pubkey,
278    authority: Pubkey,
279    mint: Pubkey,
280    boost_v3_address: Pubkey,
281    stake_v3_address: Pubkey,
282) -> Instruction {
283    let boost_pda = boost_pda(mint);
284    let boost_deposits_address =
285        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
286    let boost_deposits_v3_address =
287        spl_associated_token_account::get_associated_token_address(&boost_v3_address, &mint);
288    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
289        &boost_pda.0,
290        &ore_api::consts::MINT_ADDRESS,
291    );
292    let boost_rewards_v3_address = spl_associated_token_account::get_associated_token_address(
293        &boost_v3_address,
294        &ore_api::consts::MINT_ADDRESS,
295    );
296    let stake_pda = stake_pda(authority, boost_pda.0);
297    Instruction {
298        program_id: crate::ID,
299        accounts: vec![
300            AccountMeta::new(signer, true),
301            AccountMeta::new(authority, false),
302            AccountMeta::new(boost_pda.0, false),
303            AccountMeta::new_readonly(boost_v3_address, false),
304            AccountMeta::new(boost_deposits_address, false),
305            AccountMeta::new(boost_deposits_v3_address, false),
306            AccountMeta::new(boost_rewards_address, false),
307            AccountMeta::new(boost_rewards_v3_address, false),
308            AccountMeta::new_readonly(mint, false),
309            AccountMeta::new(stake_pda.0, false),
310            AccountMeta::new_readonly(stake_v3_address, false),
311            AccountMeta::new_readonly(solana_program::system_program::ID, false),
312            AccountMeta::new_readonly(spl_token::ID, false),
313        ],
314        data: Migrate {}.to_bytes(),
315    }
316}