ore_boost_api/
sdk.rs

1use ore_api::state::proof_pda;
2use steel::*;
3
4use crate::{
5    instruction::*,
6    state::{boost_pda, config_pda, stake_pda},
7};
8
9// Build activate instruction.
10pub 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
24// Build claim instruction.
25pub 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
56// Build deactivate instruction.
57pub 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
71// Build deposit instruction.
72pub 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
109// Build initialize instruction.
110pub 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
123// Build new instruction.
124pub 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
159// Build open instruction.
160pub 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
177// Build update_boost instruction.
178pub fn update_boost(signer: Pubkey, boost: Pubkey, expires_at: i64, weight: u64) -> Instruction {
179    Instruction {
180        program_id: crate::ID,
181        accounts: vec![
182            AccountMeta::new(signer, true),
183            AccountMeta::new(boost, false),
184            AccountMeta::new(config_pda().0, false),
185        ],
186        data: UpdateBoost {
187            expires_at: expires_at.to_le_bytes(),
188            weight: weight.to_le_bytes(),
189        }
190        .to_bytes(),
191    }
192}
193
194// Build withdraw instruction.
195pub fn withdraw(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
196    let boost_address = boost_pda(mint).0;
197    let boost_proof_address = proof_pda(boost_address).0;
198    let boost_deposits_address =
199        spl_associated_token_account::get_associated_token_address(&boost_address, &mint);
200    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
201        &boost_address,
202        &ore_api::consts::MINT_ADDRESS,
203    );
204    let beneficiary_address =
205        spl_associated_token_account::get_associated_token_address(&signer, &mint);
206    let stake_address = stake_pda(signer, boost_address).0;
207    Instruction {
208        program_id: crate::ID,
209        accounts: vec![
210            AccountMeta::new(signer, true),
211            AccountMeta::new(beneficiary_address, false),
212            AccountMeta::new(boost_address, false),
213            AccountMeta::new(boost_deposits_address, false),
214            AccountMeta::new(boost_proof_address, false),
215            AccountMeta::new(boost_rewards_address, false),
216            AccountMeta::new_readonly(mint, false),
217            AccountMeta::new(stake_address, false),
218            AccountMeta::new_readonly(ore_api::consts::TREASURY_ADDRESS, false),
219            AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
220            AccountMeta::new_readonly(ore_api::ID, false),
221            AccountMeta::new_readonly(spl_token::ID, false),
222        ],
223        data: Withdraw {
224            amount: amount.to_le_bytes(),
225        }
226        .to_bytes(),
227    }
228}
229
230// Build migrate_config instruction.
231pub fn migrate_config(signer: Pubkey) -> Instruction {
232    let config_address = config_pda().0;
233    Instruction {
234        program_id: crate::ID,
235        accounts: vec![
236            AccountMeta::new(signer, true),
237            AccountMeta::new(config_address, false),
238            AccountMeta::new_readonly(ore_api::consts::MINT_ADDRESS, false),
239            AccountMeta::new(proof_pda(config_address).0, false),
240            AccountMeta::new(
241                spl_associated_token_account::get_associated_token_address(
242                    &config_address,
243                    &ore_api::consts::MINT_ADDRESS,
244                ),
245                false,
246            ),
247            AccountMeta::new_readonly(system_program::ID, false),
248            AccountMeta::new_readonly(ore_api::ID, false),
249            AccountMeta::new_readonly(spl_token::ID, false),
250            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
251            AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
252        ],
253        data: MigrateConfig {}.to_bytes(),
254    }
255}
256
257pub fn migrate_boost(signer: Pubkey, mint: Pubkey) -> Instruction {
258    let boost_address = boost_pda(mint).0;
259    let boost_proof_address = proof_pda(boost_address).0;
260    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
261        &boost_address,
262        &ore_api::consts::MINT_ADDRESS,
263    );
264    let config_address = config_pda().0;
265    let rewards_address = spl_associated_token_account::get_associated_token_address(
266        &config_address,
267        &ore_api::consts::MINT_ADDRESS,
268    );
269    Instruction {
270        program_id: crate::ID,
271        accounts: vec![
272            AccountMeta::new(signer, true),
273            AccountMeta::new(boost_address, false),
274            AccountMeta::new(boost_proof_address, false),
275            AccountMeta::new(boost_rewards_address, false),
276            AccountMeta::new_readonly(config_address, false),
277            AccountMeta::new_readonly(ore_api::consts::MINT_ADDRESS, false),
278            AccountMeta::new(rewards_address, false),
279            AccountMeta::new(ore_api::consts::TREASURY_ADDRESS, false),
280            AccountMeta::new(ore_api::consts::TREASURY_TOKENS_ADDRESS, false),
281            AccountMeta::new_readonly(system_program::ID, false),
282            AccountMeta::new_readonly(spl_token::ID, false),
283            AccountMeta::new_readonly(ore_api::ID, false),
284        ],
285        data: MigrateBoost {}.to_bytes(),
286    }
287}