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