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: Pubkey,
60 boost_config: Pubkey,
61) -> Instruction {
62 let proof = proof_pda(authority).0;
63 let accounts = vec![
64 AccountMeta::new(signer, true),
65 AccountMeta::new(bus, false),
66 AccountMeta::new_readonly(CONFIG_ADDRESS, false),
67 AccountMeta::new(proof, false),
68 AccountMeta::new_readonly(sysvar::instructions::ID, false),
69 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
70 AccountMeta::new_readonly(boost, false),
71 AccountMeta::new(proof_pda(boost).0, false),
72 AccountMeta::new_readonly(boost_config, false),
73 ];
74 Instruction {
75 program_id: crate::ID,
76 accounts,
77 data: Mine {
78 digest: solution.d,
79 nonce: solution.n,
80 }
81 .to_bytes(),
82 }
83}
84
85pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
87 let proof_pda = proof_pda(signer);
88 Instruction {
89 program_id: crate::ID,
90 accounts: vec![
91 AccountMeta::new(signer, true),
92 AccountMeta::new_readonly(miner, false),
93 AccountMeta::new(payer, true),
94 AccountMeta::new(proof_pda.0, false),
95 AccountMeta::new_readonly(solana_program::system_program::ID, false),
96 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
97 ],
98 data: Open {}.to_bytes(),
99 }
100}
101
102pub fn reset(signer: Pubkey) -> Instruction {
104 Instruction {
105 program_id: crate::ID,
106 accounts: vec![
107 AccountMeta::new(signer, true),
108 AccountMeta::new(BUS_ADDRESSES[0], false),
109 AccountMeta::new(BUS_ADDRESSES[1], false),
110 AccountMeta::new(BUS_ADDRESSES[2], false),
111 AccountMeta::new(BUS_ADDRESSES[3], false),
112 AccountMeta::new(BUS_ADDRESSES[4], false),
113 AccountMeta::new(BUS_ADDRESSES[5], false),
114 AccountMeta::new(BUS_ADDRESSES[6], false),
115 AccountMeta::new(BUS_ADDRESSES[7], false),
116 AccountMeta::new(CONFIG_ADDRESS, false),
117 AccountMeta::new(MINT_ADDRESS, false),
118 AccountMeta::new(TREASURY_ADDRESS, false),
119 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
120 AccountMeta::new_readonly(spl_token::ID, false),
121 ],
122 data: Reset {}.to_bytes(),
123 }
124}
125
126pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
128 let proof = proof_pda(signer).0;
129 Instruction {
130 program_id: crate::ID,
131 accounts: vec![
132 AccountMeta::new(signer, true),
133 AccountMeta::new_readonly(miner, false),
134 AccountMeta::new(proof, false),
135 ],
136 data: Update {}.to_bytes(),
137 }
138}
139
140pub fn initialize(signer: Pubkey) -> Instruction {
142 let bus_pdas = [
143 bus_pda(0),
144 bus_pda(1),
145 bus_pda(2),
146 bus_pda(3),
147 bus_pda(4),
148 bus_pda(5),
149 bus_pda(6),
150 bus_pda(7),
151 ];
152 let config_pda = config_pda();
153 let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
154 let treasury_pda = treasury_pda();
155 let metadata_pda = Pubkey::find_program_address(
156 &[
157 METADATA,
158 mpl_token_metadata::ID.as_ref(),
159 mint_pda.0.as_ref(),
160 ],
161 &mpl_token_metadata::ID,
162 );
163 Instruction {
164 program_id: crate::ID,
165 accounts: vec![
166 AccountMeta::new(signer, true),
167 AccountMeta::new(bus_pdas[0].0, false),
168 AccountMeta::new(bus_pdas[1].0, false),
169 AccountMeta::new(bus_pdas[2].0, false),
170 AccountMeta::new(bus_pdas[3].0, false),
171 AccountMeta::new(bus_pdas[4].0, false),
172 AccountMeta::new(bus_pdas[5].0, false),
173 AccountMeta::new(bus_pdas[6].0, false),
174 AccountMeta::new(bus_pdas[7].0, false),
175 AccountMeta::new(config_pda.0, false),
176 AccountMeta::new(metadata_pda.0, false),
177 AccountMeta::new(mint_pda.0, false),
178 AccountMeta::new(treasury_pda.0, false),
179 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
180 AccountMeta::new_readonly(system_program::ID, false),
181 AccountMeta::new_readonly(spl_token::ID, false),
182 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
183 AccountMeta::new_readonly(mpl_token_metadata::ID, false),
184 AccountMeta::new_readonly(sysvar::rent::ID, false),
185 ],
186 data: Initialize {}.to_bytes(),
187 }
188}