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
86#[allow(deprecated)]
88pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
89 let proof_pda = proof_pda(signer);
90 Instruction {
91 program_id: crate::ID,
92 accounts: vec![
93 AccountMeta::new(signer, true),
94 AccountMeta::new_readonly(miner, false),
95 AccountMeta::new(payer, true),
96 AccountMeta::new(proof_pda.0, false),
97 AccountMeta::new_readonly(solana_program::system_program::ID, false),
98 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
99 ],
100 data: Open { bump: proof_pda.1 }.to_bytes(),
101 }
102}
103
104pub fn reset(signer: Pubkey) -> Instruction {
106 Instruction {
107 program_id: crate::ID,
108 accounts: vec![
109 AccountMeta::new(signer, true),
110 AccountMeta::new(BUS_ADDRESSES[0], false),
111 AccountMeta::new(BUS_ADDRESSES[1], false),
112 AccountMeta::new(BUS_ADDRESSES[2], false),
113 AccountMeta::new(BUS_ADDRESSES[3], false),
114 AccountMeta::new(BUS_ADDRESSES[4], false),
115 AccountMeta::new(BUS_ADDRESSES[5], false),
116 AccountMeta::new(BUS_ADDRESSES[6], false),
117 AccountMeta::new(BUS_ADDRESSES[7], false),
118 AccountMeta::new(CONFIG_ADDRESS, false),
119 AccountMeta::new(MINT_ADDRESS, false),
120 AccountMeta::new(TREASURY_ADDRESS, false),
121 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
122 AccountMeta::new_readonly(spl_token::ID, false),
123 ],
124 data: Reset {}.to_bytes(),
125 }
126}
127
128#[allow(deprecated)]
130#[deprecated(since = "2.4.0", note = "Please stake with the boost program")]
131pub fn stake(signer: Pubkey, sender: Pubkey, amount: u64) -> Instruction {
132 let proof = proof_pda(signer).0;
133 Instruction {
134 program_id: crate::ID,
135 accounts: vec![
136 AccountMeta::new(signer, true),
137 AccountMeta::new(proof, false),
138 AccountMeta::new(sender, false),
139 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
140 AccountMeta::new_readonly(spl_token::ID, false),
141 ],
142 data: Stake {
143 amount: amount.to_le_bytes(),
144 }
145 .to_bytes(),
146 }
147}
148
149pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
151 let proof = proof_pda(signer).0;
152 Instruction {
153 program_id: crate::ID,
154 accounts: vec![
155 AccountMeta::new(signer, true),
156 AccountMeta::new_readonly(miner, false),
157 AccountMeta::new(proof, false),
158 ],
159 data: Update {}.to_bytes(),
160 }
161}
162
163#[allow(deprecated)]
165#[deprecated(since = "2.6.0", note = "v1 tokens are no longer eligable to upgrade")]
166pub fn upgrade(signer: Pubkey, beneficiary: Pubkey, sender: Pubkey, amount: u64) -> Instruction {
167 Instruction {
168 program_id: crate::ID,
169 accounts: vec![
170 AccountMeta::new(signer, true),
171 AccountMeta::new(beneficiary, false),
172 AccountMeta::new(MINT_ADDRESS, false),
173 AccountMeta::new(MINT_V1_ADDRESS, false),
174 AccountMeta::new(sender, false),
175 AccountMeta::new(TREASURY_ADDRESS, false),
176 AccountMeta::new_readonly(spl_token::ID, false),
177 ],
178 data: Upgrade {
179 amount: amount.to_le_bytes(),
180 }
181 .to_bytes(),
182 }
183}
184
185#[allow(deprecated)]
187pub fn initialize(signer: Pubkey) -> Instruction {
188 let bus_pdas = [
189 bus_pda(0),
190 bus_pda(1),
191 bus_pda(2),
192 bus_pda(3),
193 bus_pda(4),
194 bus_pda(5),
195 bus_pda(6),
196 bus_pda(7),
197 ];
198 let config_pda = config_pda();
199 let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
200 let treasury_pda = treasury_pda();
201 let metadata_pda = Pubkey::find_program_address(
202 &[
203 METADATA,
204 mpl_token_metadata::ID.as_ref(),
205 mint_pda.0.as_ref(),
206 ],
207 &mpl_token_metadata::ID,
208 );
209 Instruction {
210 program_id: crate::ID,
211 accounts: vec![
212 AccountMeta::new(signer, true),
213 AccountMeta::new(bus_pdas[0].0, false),
214 AccountMeta::new(bus_pdas[1].0, false),
215 AccountMeta::new(bus_pdas[2].0, false),
216 AccountMeta::new(bus_pdas[3].0, false),
217 AccountMeta::new(bus_pdas[4].0, false),
218 AccountMeta::new(bus_pdas[5].0, false),
219 AccountMeta::new(bus_pdas[6].0, false),
220 AccountMeta::new(bus_pdas[7].0, false),
221 AccountMeta::new(config_pda.0, false),
222 AccountMeta::new(metadata_pda.0, false),
223 AccountMeta::new(mint_pda.0, false),
224 AccountMeta::new(treasury_pda.0, false),
225 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
226 AccountMeta::new_readonly(system_program::ID, false),
227 AccountMeta::new_readonly(spl_token::ID, false),
228 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
229 AccountMeta::new_readonly(mpl_token_metadata::ID, false),
230 AccountMeta::new_readonly(sysvar::rent::ID, false),
231 ],
232 data: Initialize {
233 bus_0_bump: bus_pdas[0].1,
234 bus_1_bump: bus_pdas[1].1,
235 bus_2_bump: bus_pdas[2].1,
236 bus_3_bump: bus_pdas[3].1,
237 bus_4_bump: bus_pdas[4].1,
238 bus_5_bump: bus_pdas[5].1,
239 bus_6_bump: bus_pdas[6].1,
240 bus_7_bump: bus_pdas[7].1,
241 config_bump: config_pda.1,
242 metadata_bump: metadata_pda.1,
243 mint_bump: mint_pda.1,
244 treasury_bump: treasury_pda.1,
245 }
246 .to_bytes(),
247 }
248}