1use drillx::Solution;
2use steel::*;
3
4use crate::{
5 consts::*,
6 instruction::*,
7 state::{bus_pda, config_pda, proof_pda, treasury_pda},
8};
9
10pub fn auth(proof: Pubkey) -> Instruction {
12 Instruction {
13 program_id: NOOP_PROGRAM_ID,
14 accounts: vec![],
15 data: proof.to_bytes().to_vec(),
16 }
17}
18
19pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction {
21 let proof = proof_pda(signer).0;
22 Instruction {
23 program_id: crate::ID,
24 accounts: vec![
25 AccountMeta::new(signer, true),
26 AccountMeta::new(beneficiary, false),
27 AccountMeta::new(proof, false),
28 AccountMeta::new_readonly(TREASURY_ADDRESS, false),
29 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
30 AccountMeta::new_readonly(spl_token::ID, false),
31 ],
32 data: Claim {
33 amount: amount.to_le_bytes(),
34 }
35 .to_bytes(),
36 }
37}
38
39pub fn close(signer: Pubkey) -> Instruction {
41 let proof = proof_pda(signer).0;
42 Instruction {
43 program_id: crate::ID,
44 accounts: vec![
45 AccountMeta::new(signer, true),
46 AccountMeta::new(proof, false),
47 AccountMeta::new_readonly(solana_program::system_program::ID, false),
48 ],
49 data: Close {}.to_bytes(),
50 }
51}
52
53pub fn mine(
55 signer: Pubkey,
56 authority: Pubkey,
57 bus: Pubkey,
58 solution: Solution,
59 boost_keys: Option<[Pubkey; 2]>,
60) -> Instruction {
61 let proof = proof_pda(authority).0;
62 let mut accounts = vec![
63 AccountMeta::new(signer, true),
64 AccountMeta::new(bus, false),
65 AccountMeta::new_readonly(CONFIG_ADDRESS, false),
66 AccountMeta::new(proof, false),
67 AccountMeta::new_readonly(sysvar::instructions::ID, false),
68 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
69 ];
70 if let Some([boost_address, boost_config_address]) = boost_keys {
71 accounts.push(AccountMeta::new_readonly(boost_address, false));
72 accounts.push(AccountMeta::new(proof_pda(boost_address).0, false));
73 accounts.push(AccountMeta::new_readonly(boost_config_address, false));
74 }
75 Instruction {
76 program_id: crate::ID,
77 accounts,
78 data: Mine {
79 digest: solution.d,
80 nonce: solution.n,
81 }
82 .to_bytes(),
83 }
84}
85
86pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
88 let proof_pda = proof_pda(signer);
89 Instruction {
90 program_id: crate::ID,
91 accounts: vec![
92 AccountMeta::new(signer, true),
93 AccountMeta::new_readonly(miner, false),
94 AccountMeta::new(payer, true),
95 AccountMeta::new(proof_pda.0, false),
96 AccountMeta::new_readonly(solana_program::system_program::ID, false),
97 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
98 ],
99 data: Open {}.to_bytes(),
100 }
101}
102
103pub fn reset(signer: Pubkey) -> Instruction {
105 Instruction {
106 program_id: crate::ID,
107 accounts: vec![
108 AccountMeta::new(signer, true),
109 AccountMeta::new(BUS_ADDRESSES[0], false),
110 AccountMeta::new(BUS_ADDRESSES[1], false),
111 AccountMeta::new(BUS_ADDRESSES[2], false),
112 AccountMeta::new(BUS_ADDRESSES[3], false),
113 AccountMeta::new(BUS_ADDRESSES[4], false),
114 AccountMeta::new(BUS_ADDRESSES[5], false),
115 AccountMeta::new(BUS_ADDRESSES[6], false),
116 AccountMeta::new(BUS_ADDRESSES[7], false),
117 AccountMeta::new(CONFIG_ADDRESS, false),
118 AccountMeta::new(MINT_ADDRESS, false),
119 AccountMeta::new(TREASURY_ADDRESS, false),
120 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
121 AccountMeta::new_readonly(spl_token::ID, false),
122 ],
123 data: Reset {}.to_bytes(),
124 }
125}
126
127pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
129 let proof = proof_pda(signer).0;
130 Instruction {
131 program_id: crate::ID,
132 accounts: vec![
133 AccountMeta::new(signer, true),
134 AccountMeta::new_readonly(miner, false),
135 AccountMeta::new(proof, false),
136 ],
137 data: Update {}.to_bytes(),
138 }
139}
140
141pub fn initialize(signer: Pubkey) -> Instruction {
143 let bus_pdas = [
144 bus_pda(0),
145 bus_pda(1),
146 bus_pda(2),
147 bus_pda(3),
148 bus_pda(4),
149 bus_pda(5),
150 bus_pda(6),
151 bus_pda(7),
152 ];
153 let config_pda = config_pda();
154 let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
155 let treasury_pda = treasury_pda();
156 let metadata_pda = Pubkey::find_program_address(
157 &[
158 METADATA,
159 mpl_token_metadata::ID.as_ref(),
160 mint_pda.0.as_ref(),
161 ],
162 &mpl_token_metadata::ID,
163 );
164 Instruction {
165 program_id: crate::ID,
166 accounts: vec![
167 AccountMeta::new(signer, true),
168 AccountMeta::new(bus_pdas[0].0, false),
169 AccountMeta::new(bus_pdas[1].0, false),
170 AccountMeta::new(bus_pdas[2].0, false),
171 AccountMeta::new(bus_pdas[3].0, false),
172 AccountMeta::new(bus_pdas[4].0, false),
173 AccountMeta::new(bus_pdas[5].0, false),
174 AccountMeta::new(bus_pdas[6].0, false),
175 AccountMeta::new(bus_pdas[7].0, false),
176 AccountMeta::new(config_pda.0, false),
177 AccountMeta::new(metadata_pda.0, false),
178 AccountMeta::new(mint_pda.0, false),
179 AccountMeta::new(treasury_pda.0, false),
180 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
181 AccountMeta::new_readonly(system_program::ID, false),
182 AccountMeta::new_readonly(spl_token::ID, false),
183 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
184 AccountMeta::new_readonly(mpl_token_metadata::ID, false),
185 AccountMeta::new_readonly(sysvar::rent::ID, false),
186 ],
187 data: Initialize {}.to_bytes(),
188 }
189}