ore_api/
sdk.rs

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