ore_api/
sdk.rs

1use solana_program::pubkey::Pubkey;
2use spl_associated_token_account::get_associated_token_address;
3use steel::*;
4
5use crate::{
6    consts::{BOARD, MINT_ADDRESS, SOL_MINT, TREASURY_ADDRESS},
7    instruction::*,
8    state::*,
9};
10
11pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
12    let mut data = Log {}.to_bytes();
13    data.extend_from_slice(msg);
14    Instruction {
15        program_id: crate::ID,
16        accounts: vec![AccountMeta::new(signer, true)],
17        data: data,
18    }
19}
20
21pub fn program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
22    invoke_signed(&log(*accounts[0].key, msg), accounts, &crate::ID, &[BOARD])
23}
24
25// let [signer_info, automation_info, executor_info, miner_info, system_program] = accounts else {
26
27pub fn automate(
28    signer: Pubkey,
29    amount: u64,
30    deposit: u64,
31    executor: Pubkey,
32    fee: u64,
33    mask: u64,
34    strategy: u8,
35) -> Instruction {
36    let automation_address = automation_pda(signer).0;
37    let miner_address = miner_pda(signer).0;
38    Instruction {
39        program_id: crate::ID,
40        accounts: vec![
41            AccountMeta::new(signer, true),
42            AccountMeta::new(automation_address, false),
43            AccountMeta::new(executor, false),
44            AccountMeta::new(miner_address, false),
45            AccountMeta::new_readonly(system_program::ID, false),
46        ],
47        data: Automate {
48            amount: amount.to_le_bytes(),
49            deposit: deposit.to_le_bytes(),
50            fee: fee.to_le_bytes(),
51            mask: mask.to_le_bytes(),
52            strategy: strategy as u8,
53        }
54        .to_bytes(),
55    }
56}
57
58// let [signer_info, board_info, config_info, mint_info, treasury_info, vault_info, system_program, token_program, associated_token_program] =
59
60pub fn initialize(signer: Pubkey) -> Instruction {
61    let config_address = config_pda().0;
62    let board_address = board_pda().0;
63    let mint_address = MINT_ADDRESS;
64    let treasury_address = TREASURY_ADDRESS;
65    let treasury_tokens_address = treasury_tokens_address();
66    Instruction {
67        program_id: crate::ID,
68        accounts: vec![
69            AccountMeta::new(signer, true),
70            AccountMeta::new(board_address, false),
71            AccountMeta::new(config_address, false),
72            AccountMeta::new(mint_address, false),
73            AccountMeta::new(treasury_address, false),
74            AccountMeta::new(treasury_tokens_address, false),
75            AccountMeta::new_readonly(system_program::ID, false),
76            AccountMeta::new_readonly(spl_token::ID, false),
77            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
78        ],
79        data: Initialize {}.to_bytes(),
80    }
81}
82
83pub fn claim_sol(signer: Pubkey) -> Instruction {
84    let miner_address = miner_pda(signer).0;
85    Instruction {
86        program_id: crate::ID,
87        accounts: vec![
88            AccountMeta::new(signer, true),
89            AccountMeta::new(miner_address, false),
90            AccountMeta::new_readonly(system_program::ID, false),
91        ],
92        data: ClaimSOL {}.to_bytes(),
93    }
94}
95
96// let [signer_info, miner_info, mint_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
97
98pub fn claim_ore(signer: Pubkey) -> Instruction {
99    let miner_address = miner_pda(signer).0;
100    let treasury_address = treasury_pda().0;
101    let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
102    let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
103    Instruction {
104        program_id: crate::ID,
105        accounts: vec![
106            AccountMeta::new(signer, true),
107            AccountMeta::new(miner_address, false),
108            AccountMeta::new(MINT_ADDRESS, false),
109            AccountMeta::new(recipient_address, false),
110            AccountMeta::new(treasury_address, false),
111            AccountMeta::new(treasury_tokens_address, false),
112            AccountMeta::new_readonly(system_program::ID, false),
113            AccountMeta::new_readonly(spl_token::ID, false),
114            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
115        ],
116        data: ClaimORE {}.to_bytes(),
117    }
118}
119
120// let [signer_info, authority_info, automation_info, board_info, miner_info, round_info, system_program] =
121
122pub fn deploy(
123    signer: Pubkey,
124    authority: Pubkey,
125    amount: u64,
126    round_id: u64,
127    squares: [bool; 25],
128) -> Instruction {
129    let automation_address = automation_pda(authority).0;
130    let board_address = board_pda().0;
131    let miner_address = miner_pda(authority).0;
132    let round_address = round_pda(round_id).0;
133
134    // Convert array of 25 booleans into a 32-bit mask where each bit represents whether
135    // that square index is selected (1) or not (0)
136    let mut mask: u32 = 0;
137    for (i, &square) in squares.iter().enumerate() {
138        if square {
139            mask |= 1 << i;
140        }
141    }
142
143    Instruction {
144        program_id: crate::ID,
145        accounts: vec![
146            AccountMeta::new(signer, true),
147            AccountMeta::new(authority, false),
148            AccountMeta::new(automation_address, false),
149            AccountMeta::new(board_address, false),
150            AccountMeta::new(miner_address, false),
151            AccountMeta::new(round_address, false),
152            AccountMeta::new_readonly(system_program::ID, false),
153        ],
154        data: Deploy {
155            amount: amount.to_le_bytes(),
156            squares: mask.to_le_bytes(),
157        }
158        .to_bytes(),
159    }
160}
161
162// let [pool, user_source_token, user_destination_token, a_vault, b_vault, a_token_vault, b_token_vault, a_vault_lp_mint, b_vault_lp_mint, a_vault_lp, b_vault_lp, protocol_token_fee, user_key, vault_program, token_program] =
163
164pub fn bury(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
165    let board_address = board_pda().0;
166    let config_address = config_pda().0;
167    let mint_address = MINT_ADDRESS;
168    let treasury_address = TREASURY_ADDRESS;
169    let treasury_ore_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
170    let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
171    let mut accounts = vec![
172        AccountMeta::new(signer, true),
173        AccountMeta::new(board_address, false),
174        AccountMeta::new_readonly(config_address, false),
175        AccountMeta::new(mint_address, false),
176        AccountMeta::new(treasury_address, false),
177        AccountMeta::new(treasury_ore_address, false),
178        AccountMeta::new(treasury_sol_address, false),
179        AccountMeta::new_readonly(spl_token::ID, false),
180        AccountMeta::new_readonly(crate::ID, false),
181    ];
182    for account in swap_accounts.iter() {
183        let mut acc_clone = account.clone();
184        acc_clone.is_signer = false;
185        accounts.push(acc_clone);
186    }
187    let mut data = Bury {}.to_bytes();
188    data.extend_from_slice(swap_data);
189    Instruction {
190        program_id: crate::ID,
191        accounts,
192        data,
193    }
194}
195
196pub fn wrap(signer: Pubkey) -> Instruction {
197    let config_address = config_pda().0;
198    let treasury_address = TREASURY_ADDRESS;
199    let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
200    Instruction {
201        accounts: vec![
202            AccountMeta::new(signer, true),
203            AccountMeta::new_readonly(config_address, false),
204            AccountMeta::new(treasury_address, false),
205            AccountMeta::new(treasury_sol_address, false),
206            AccountMeta::new_readonly(system_program::ID, false),
207        ],
208        program_id: crate::ID,
209        data: Wrap {}.to_bytes(),
210    }
211}
212
213// let [signer_info, board_info, config_info, fee_collector_info, mint_info, round_info, round_next_info, top_miner_info, treasury_info, treasury_tokens_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
214
215pub fn reset(
216    signer: Pubkey,
217    fee_collector: Pubkey,
218    round_id: u64,
219    top_miner: Pubkey,
220) -> Instruction {
221    let board_address = board_pda().0;
222    let config_address = config_pda().0;
223    let mint_address = MINT_ADDRESS;
224    let round_address = round_pda(round_id).0;
225    let round_next_address = round_pda(round_id + 1).0;
226    let top_miner_address = miner_pda(top_miner).0;
227    let treasury_address = TREASURY_ADDRESS;
228    let treasury_tokens_address = treasury_tokens_address();
229    Instruction {
230        program_id: crate::ID,
231        accounts: vec![
232            AccountMeta::new(signer, true),
233            AccountMeta::new(board_address, false),
234            AccountMeta::new(config_address, false),
235            AccountMeta::new(fee_collector, false),
236            AccountMeta::new(mint_address, false),
237            AccountMeta::new(round_address, false),
238            AccountMeta::new(round_next_address, false),
239            AccountMeta::new(top_miner_address, false),
240            AccountMeta::new(treasury_address, false),
241            AccountMeta::new(treasury_tokens_address, false),
242            AccountMeta::new_readonly(system_program::ID, false),
243            AccountMeta::new_readonly(spl_token::ID, false),
244            AccountMeta::new_readonly(crate::ID, false),
245            AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
246        ],
247        data: Reset {}.to_bytes(),
248    }
249}
250
251// let [signer_info, board_info, rent_payer_info, round_info, treasury_info, system_program] =
252
253pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
254    let board_address = board_pda().0;
255    let treasury_address = TREASURY_ADDRESS;
256    let round_address = round_pda(round_id).0;
257    Instruction {
258        program_id: crate::ID,
259        accounts: vec![
260            AccountMeta::new(signer, true),
261            AccountMeta::new(board_address, false),
262            AccountMeta::new(rent_payer, false),
263            AccountMeta::new(round_address, false),
264            AccountMeta::new(treasury_address, false),
265            AccountMeta::new_readonly(system_program::ID, false),
266        ],
267        data: Close {}.to_bytes(),
268    }
269}
270
271// let [signer_info, automation_info, board_info, miner_info, round_info, treasury_info, system_program] =
272
273pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
274    let miner_address = miner_pda(authority).0;
275    let board_address = board_pda().0;
276    let round_address = round_pda(round_id).0;
277    let treasury_address = TREASURY_ADDRESS;
278    Instruction {
279        program_id: crate::ID,
280        accounts: vec![
281            AccountMeta::new(signer, true),
282            AccountMeta::new(board_address, false),
283            AccountMeta::new(miner_address, false),
284            AccountMeta::new(round_address, false),
285            AccountMeta::new(treasury_address, false),
286            AccountMeta::new_readonly(system_program::ID, false),
287        ],
288        data: Checkpoint {}.to_bytes(),
289    }
290}
291
292pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
293    let config_address = config_pda().0;
294    Instruction {
295        program_id: crate::ID,
296        accounts: vec![
297            AccountMeta::new(signer, true),
298            AccountMeta::new(config_address, false),
299            AccountMeta::new_readonly(system_program::ID, false),
300        ],
301        data: SetAdmin {
302            admin: admin.to_bytes(),
303        }
304        .to_bytes(),
305    }
306}
307
308pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
309    let config_address = config_pda().0;
310    Instruction {
311        program_id: crate::ID,
312        accounts: vec![
313            AccountMeta::new(signer, true),
314            AccountMeta::new(config_address, false),
315            AccountMeta::new_readonly(system_program::ID, false),
316        ],
317        data: SetFeeCollector {
318            fee_collector: fee_collector.to_bytes(),
319        }
320        .to_bytes(),
321    }
322}
323
324// let [signer_info, mint_info, sender_info, stake_info, stake_tokens_info, treasury_info, system_program, token_program, associated_token_program] =
325
326pub fn deposit(signer: Pubkey, amount: u64) -> Instruction {
327    let mint_address = MINT_ADDRESS;
328    let stake_address = stake_pda(signer).0;
329    let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
330    let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
331    let treasury_address = TREASURY_ADDRESS;
332    Instruction {
333        program_id: crate::ID,
334        accounts: vec![
335            AccountMeta::new(signer, true),
336            AccountMeta::new(mint_address, false),
337            AccountMeta::new(sender_address, false),
338            AccountMeta::new(stake_address, false),
339            AccountMeta::new(stake_tokens_address, false),
340            AccountMeta::new(treasury_address, false),
341            AccountMeta::new_readonly(system_program::ID, false),
342            AccountMeta::new_readonly(spl_token::ID, false),
343            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
344        ],
345        data: Deposit {
346            amount: amount.to_le_bytes(),
347        }
348        .to_bytes(),
349    }
350}
351
352// let [signer_info, mint_info, recipient_info, stake_info, stake_tokens_info, treasury_info, system_program, token_program, associated_token_program] =
353
354pub fn withdraw(signer: Pubkey, amount: u64) -> Instruction {
355    let stake_address = stake_pda(signer).0;
356    let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
357    let mint_address = MINT_ADDRESS;
358    let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
359    let treasury_address = TREASURY_ADDRESS;
360    Instruction {
361        program_id: crate::ID,
362        accounts: vec![
363            AccountMeta::new(signer, true),
364            AccountMeta::new(mint_address, false),
365            AccountMeta::new(recipient_address, false),
366            AccountMeta::new(stake_address, false),
367            AccountMeta::new(stake_tokens_address, false),
368            AccountMeta::new(treasury_address, false),
369            AccountMeta::new_readonly(system_program::ID, false),
370            AccountMeta::new_readonly(spl_token::ID, false),
371            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
372        ],
373        data: Withdraw {
374            amount: amount.to_le_bytes(),
375        }
376        .to_bytes(),
377    }
378}
379
380// let [signer_info, mint_info, recipient_info, stake_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
381
382pub fn claim_yield(signer: Pubkey, amount: u64) -> Instruction {
383    let stake_address = stake_pda(signer).0;
384    let mint_address = MINT_ADDRESS;
385    let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
386    let treasury_address = TREASURY_ADDRESS;
387    let treasury_tokens_address = treasury_tokens_address();
388    Instruction {
389        program_id: crate::ID,
390        accounts: vec![
391            AccountMeta::new(signer, true),
392            AccountMeta::new(mint_address, false),
393            AccountMeta::new(recipient_address, false),
394            AccountMeta::new(stake_address, false),
395            AccountMeta::new(treasury_address, false),
396            AccountMeta::new(treasury_tokens_address, false),
397            AccountMeta::new_readonly(system_program::ID, false),
398            AccountMeta::new_readonly(spl_token::ID, false),
399            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
400        ],
401        data: ClaimYield {
402            amount: amount.to_le_bytes(),
403        }
404        .to_bytes(),
405    }
406}