1use drillx::Solution;
2use ore_api::{
3 consts::{CONFIG_ADDRESS, MINT_ADDRESS, TREASURY_ADDRESS, TREASURY_TOKENS_ADDRESS},
4 state::proof_pda,
5};
6use steel::*;
7
8use crate::{
9 consts::LEGACY_BOOST_PROGRAM_ID,
10 error::ApiError,
11 instruction::*,
12 state::{legacy_boost_pda, legacy_stake_pda, member_pda, pool_pda, pool_proof_pda, share_pda},
13};
14
15#[allow(deprecated)]
17pub fn launch(signer: Pubkey, miner: Pubkey, url: String) -> Result<Instruction, ApiError> {
18 let url = url_to_bytes(url.as_str())?;
19 let (pool_pda, pool_bump) = pool_pda(signer);
20 let (proof_pda, proof_bump) = pool_proof_pda(pool_pda);
21 let ix = Instruction {
22 program_id: crate::ID,
23 accounts: vec![
24 AccountMeta::new(signer, true),
25 AccountMeta::new_readonly(miner, false),
26 AccountMeta::new(pool_pda, false),
27 AccountMeta::new(proof_pda, false),
28 AccountMeta::new_readonly(ore_api::ID, false),
29 AccountMeta::new_readonly(ore_boost_api::ID, false),
30 AccountMeta::new_readonly(spl_token::ID, false),
31 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
32 AccountMeta::new_readonly(system_program::ID, false),
33 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
34 ],
35 data: Launch {
36 pool_bump,
37 proof_bump,
38 url,
39 }
40 .to_bytes(),
41 };
42 Ok(ix)
43}
44
45#[allow(deprecated)]
47pub fn join(member_authority: Pubkey, pool: Pubkey, payer: Pubkey) -> Instruction {
48 let (member_pda, member_bump) = member_pda(member_authority, pool);
49 Instruction {
50 program_id: crate::ID,
51 accounts: vec![
52 AccountMeta::new(payer, true),
53 AccountMeta::new_readonly(member_authority, false),
54 AccountMeta::new(member_pda, false),
55 AccountMeta::new(pool, false),
56 AccountMeta::new_readonly(system_program::ID, false),
57 ],
58 data: Join { member_bump }.to_bytes(),
59 }
60}
61
62#[allow(deprecated)]
64pub fn claim(
65 signer: Pubkey,
66 beneficiary: Pubkey,
67 pool_address: Pubkey,
68 amount: u64,
69) -> Instruction {
70 let (member_pda, _) = member_pda(signer, pool_address);
71 let (pool_proof_pda, _) = proof_pda(pool_address);
72 let pool_tokens_address =
73 spl_associated_token_account::get_associated_token_address(&pool_address, &MINT_ADDRESS);
74 Instruction {
75 program_id: crate::ID,
76 accounts: vec![
77 AccountMeta::new(signer, true),
78 AccountMeta::new(beneficiary, false),
79 AccountMeta::new(member_pda, false),
80 AccountMeta::new(pool_address, false),
81 AccountMeta::new(pool_tokens_address, false),
82 AccountMeta::new(pool_proof_pda, false),
83 AccountMeta::new_readonly(TREASURY_ADDRESS, false),
84 AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
85 AccountMeta::new_readonly(ore_api::ID, false),
86 AccountMeta::new_readonly(spl_token::ID, false),
87 ],
88 data: Claim {
89 amount: amount.to_le_bytes(),
90 pool_bump: 0,
91 }
92 .to_bytes(),
93 }
94}
95
96pub fn attribute(signer: Pubkey, member_authority: Pubkey, total_balance: u64) -> Instruction {
98 let (pool_address, _) = pool_pda(signer);
99 let (proof_address, _) = pool_proof_pda(pool_address);
100 let (member_address, _) = member_pda(member_authority, pool_address);
101 let pool_tokens_address =
102 spl_associated_token_account::get_associated_token_address(&pool_address, &MINT_ADDRESS);
103 Instruction {
104 program_id: crate::ID,
105 accounts: vec![
106 AccountMeta::new(signer, true),
107 AccountMeta::new(pool_address, false),
108 AccountMeta::new(pool_tokens_address, false),
109 AccountMeta::new(proof_address, false),
110 AccountMeta::new(member_address, false),
111 ],
112 data: Attribute {
113 total_balance: total_balance.to_le_bytes(),
114 }
115 .to_bytes(),
116 }
117}
118
119#[deprecated(
121 since = "0.3.0",
122 note = "Staking has moved to the global boost program"
123)]
124#[allow(deprecated)]
125pub fn commit(_signer: Pubkey, _mint: Pubkey) -> Instruction {
126 panic!("Staking has moved to the global boost program");
127}
128
129pub fn submit(
131 signer: Pubkey,
132 solution: Solution,
133 attestation: [u8; 32],
134 bus: Pubkey,
135 boost_accounts: Option<[Pubkey; 3]>,
136) -> Instruction {
137 let (pool_pda, _) = pool_pda(signer);
138 let (proof_pda, _) = pool_proof_pda(pool_pda);
139 let mut accounts = vec![
140 AccountMeta::new(signer, true),
141 AccountMeta::new(bus, false),
142 AccountMeta::new_readonly(CONFIG_ADDRESS, false),
143 AccountMeta::new(pool_pda, false),
144 AccountMeta::new(proof_pda, false),
145 AccountMeta::new_readonly(ore_api::ID, false),
146 AccountMeta::new_readonly(system_program::ID, false),
147 AccountMeta::new_readonly(sysvar::instructions::ID, false),
148 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
149 ];
150 if let Some(boost_accounts) = boost_accounts {
151 accounts.push(AccountMeta::new_readonly(boost_accounts[0], false));
152 accounts.push(AccountMeta::new(boost_accounts[1], false));
153 accounts.push(AccountMeta::new_readonly(boost_accounts[2], false));
154 }
155 Instruction {
156 program_id: crate::ID,
157 accounts,
158 data: Submit {
159 attestation,
160 digest: solution.d,
161 nonce: solution.n,
162 }
163 .to_bytes(),
164 }
165}
166
167pub fn unstake(
169 signer: Pubkey,
170 mint: Pubkey,
171 pool: Pubkey,
172 recipient: Pubkey,
173 amount: u64,
174) -> Instruction {
175 let (boost_pda, _) = legacy_boost_pda(mint);
176 let boost_tokens =
177 spl_associated_token_account::get_associated_token_address(&boost_pda, &mint);
178 let (member_pda, _) = member_pda(signer, pool);
179 let pool_tokens = spl_associated_token_account::get_associated_token_address(&pool, &mint);
180 let (share_pda, _) = share_pda(signer, pool, mint);
181 let (stake_pda, _) = legacy_stake_pda(pool, boost_pda);
182 Instruction {
183 program_id: crate::ID,
184 accounts: vec![
185 AccountMeta::new(signer, true),
186 AccountMeta::new(boost_pda, false),
187 AccountMeta::new(boost_tokens, false),
188 AccountMeta::new_readonly(mint, false),
189 AccountMeta::new_readonly(member_pda, false),
190 AccountMeta::new(pool, false),
191 AccountMeta::new(pool_tokens, false),
192 AccountMeta::new(recipient, false),
193 AccountMeta::new(share_pda, false),
194 AccountMeta::new(stake_pda, false),
195 AccountMeta::new_readonly(spl_token::ID, false),
196 AccountMeta::new_readonly(LEGACY_BOOST_PROGRAM_ID, false),
197 ],
198 data: Unstake {
199 amount: amount.to_le_bytes(),
200 }
201 .to_bytes(),
202 }
203}
204
205#[deprecated(
207 since = "0.3.0",
208 note = "Staking has moved to the global boost program"
209)]
210#[allow(deprecated)]
211pub fn stake(
212 signer: Pubkey,
213 mint: Pubkey,
214 pool: Pubkey,
215 sender: Pubkey,
216 amount: u64,
217) -> Instruction {
218 let (member_pda, _) = member_pda(signer, pool);
219 let pool_tokens = spl_associated_token_account::get_associated_token_address(&pool, &mint);
220 let (share_pda, _) = share_pda(signer, pool, mint);
221 Instruction {
222 program_id: crate::ID,
223 accounts: vec![
224 AccountMeta::new(signer, true),
225 AccountMeta::new_readonly(mint, false),
226 AccountMeta::new_readonly(member_pda, false),
227 AccountMeta::new_readonly(pool, false),
228 AccountMeta::new(pool_tokens, false),
229 AccountMeta::new(sender, false),
230 AccountMeta::new(share_pda, false),
231 AccountMeta::new_readonly(spl_token::ID, false),
232 ],
233 data: Stake {
234 amount: amount.to_le_bytes(),
235 }
236 .to_bytes(),
237 }
238}
239
240#[deprecated(
242 since = "0.3.0",
243 note = "Staking has moved to the global boost program"
244)]
245#[allow(deprecated)]
246pub fn open_share(_signer: Pubkey, _mint: Pubkey, _pool: Pubkey) -> Instruction {
247 panic!("Staking has moved to the global boost program");
248}
249
250#[deprecated(
252 since = "0.3.0",
253 note = "Staking has moved to the global boost program"
254)]
255#[allow(deprecated)]
256pub fn open_stake(_signer: Pubkey, _mint: Pubkey) -> Instruction {
257 panic!("Staking has moved to the global boost program");
258}
259
260fn url_to_bytes(input: &str) -> Result<[u8; 128], ApiError> {
261 let bytes = input.as_bytes();
262 let len = bytes.len();
263 if len > 128 {
264 Err(ApiError::UrlTooLarge)
265 } else {
266 let mut array = [0u8; 128];
267 array[..len].copy_from_slice(&bytes[..len]);
268 Ok(array)
269 }
270}