ore_boost_api/
sdk.rs

1use ore_api::state::proof_pda;
2use steel::*;
3
4use crate::{
5    instruction::*,
6    state::{boost_pda, config_pda, stake_pda},
7};
8
9// Build activate instruction.
10pub fn activate(signer: Pubkey, mint: Pubkey) -> Instruction {
11    let boost_pda = boost_pda(mint);
12    let config_pda = config_pda();
13    Instruction {
14        program_id: crate::ID,
15        accounts: vec![
16            AccountMeta::new(signer, true),
17            AccountMeta::new_readonly(boost_pda.0, false),
18            AccountMeta::new(config_pda.0, false),
19        ],
20        data: Activate {}.to_bytes(),
21    }
22}
23
24// Build claim instruction.
25pub fn claim(signer: Pubkey, beneficiary: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
26    let boost_pda = boost_pda(mint);
27    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
28        &boost_pda.0,
29        &ore_api::consts::MINT_ADDRESS,
30    );
31    let stake_pda = stake_pda(signer, boost_pda.0);
32    Instruction {
33        program_id: crate::ID,
34        accounts: vec![
35            AccountMeta::new(signer, true),
36            AccountMeta::new(beneficiary, false),
37            AccountMeta::new_readonly(boost_pda.0, false),
38            AccountMeta::new(boost_rewards_address, false),
39            AccountMeta::new(stake_pda.0, false),
40            AccountMeta::new_readonly(spl_token::ID, false),
41        ],
42        data: Claim {
43            amount: amount.to_le_bytes(),
44        }
45        .to_bytes(),
46    }
47}
48
49// Build deactivate instruction.
50pub fn deactivate(signer: Pubkey, mint: Pubkey) -> Instruction {
51    let boost_pda = boost_pda(mint);
52    let config_pda = config_pda();
53    Instruction {
54        program_id: crate::ID,
55        accounts: vec![
56            AccountMeta::new(signer, true),
57            AccountMeta::new_readonly(boost_pda.0, false),
58            AccountMeta::new(config_pda.0, false),
59        ],
60        data: Deactivate {}.to_bytes(),
61    }
62}
63
64// Build deposit instruction.
65pub fn deposit(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
66    let boost_pda = boost_pda(mint);
67    let boost_deposits_address =
68        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
69    let sender_address = spl_associated_token_account::get_associated_token_address(&signer, &mint);
70    let stake_pda = stake_pda(signer, boost_pda.0);
71    Instruction {
72        program_id: crate::ID,
73        accounts: vec![
74            AccountMeta::new(signer, true),
75            AccountMeta::new(boost_pda.0, false),
76            AccountMeta::new(boost_deposits_address, false),
77            AccountMeta::new_readonly(mint, false),
78            AccountMeta::new(sender_address, false),
79            AccountMeta::new(stake_pda.0, false),
80            AccountMeta::new_readonly(spl_token::ID, false),
81        ],
82        data: Deposit {
83            amount: amount.to_le_bytes(),
84        }
85        .to_bytes(),
86    }
87}
88
89// Build initialize instruction.
90pub fn initialize(signer: Pubkey) -> Instruction {
91    let config_pda = config_pda();
92    Instruction {
93        program_id: crate::ID,
94        accounts: vec![
95            AccountMeta::new(signer, true),
96            AccountMeta::new(config_pda.0, false),
97            AccountMeta::new_readonly(system_program::ID, false),
98        ],
99        data: Initialize {}.to_bytes(),
100    }
101}
102
103// Build new instruction.
104pub fn new(signer: Pubkey, mint: Pubkey, expires_at: i64, multiplier: u64) -> Instruction {
105    let boost_pda = boost_pda(mint);
106    let boost_deposits_address =
107        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
108    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
109        &boost_pda.0,
110        &ore_api::consts::MINT_ADDRESS,
111    );
112    let config_pda = config_pda();
113    let proof_pda = proof_pda(boost_pda.0);
114    Instruction {
115        program_id: crate::ID,
116        accounts: vec![
117            AccountMeta::new(signer, true),
118            AccountMeta::new(boost_pda.0, false),
119            AccountMeta::new(boost_deposits_address, false),
120            AccountMeta::new(boost_rewards_address, false),
121            AccountMeta::new(config_pda.0, false),
122            AccountMeta::new_readonly(mint, false),
123            AccountMeta::new_readonly(ore_api::consts::MINT_ADDRESS, false),
124            AccountMeta::new(proof_pda.0, false),
125            AccountMeta::new_readonly(ore_api::ID, false),
126            AccountMeta::new_readonly(system_program::ID, false),
127            AccountMeta::new_readonly(spl_token::ID, false),
128            AccountMeta::new_readonly(spl_associated_token_account::ID, false),
129            AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
130        ],
131        data: New {
132            expires_at: expires_at.to_le_bytes(),
133            multiplier: multiplier.to_le_bytes(),
134        }
135        .to_bytes(),
136    }
137}
138
139// Build open instruction.
140pub fn open(signer: Pubkey, payer: Pubkey, mint: Pubkey) -> Instruction {
141    let boost_pda = boost_pda(mint);
142    let stake_pda = stake_pda(signer, boost_pda.0);
143    Instruction {
144        program_id: crate::ID,
145        accounts: vec![
146            AccountMeta::new(signer, true),
147            AccountMeta::new(payer, true),
148            AccountMeta::new(boost_pda.0, false),
149            AccountMeta::new_readonly(mint, false),
150            AccountMeta::new(stake_pda.0, false),
151            AccountMeta::new_readonly(system_program::ID, false),
152        ],
153        data: Open {}.to_bytes(),
154    }
155}
156
157// Build rotate instruction.
158pub fn rotate(signer: Pubkey) -> Instruction {
159    let config_pda = config_pda();
160    Instruction {
161        program_id: crate::ID,
162        accounts: vec![
163            AccountMeta::new(signer, true),
164            AccountMeta::new(config_pda.0, false),
165        ],
166        data: Rotate {}.to_bytes(),
167    }
168}
169
170// Build update_boost instruction.
171pub fn update_boost(
172    signer: Pubkey,
173    boost: Pubkey,
174    expires_at: i64,
175    multiplier: u64,
176) -> Instruction {
177    Instruction {
178        program_id: crate::ID,
179        accounts: vec![
180            AccountMeta::new(signer, true),
181            AccountMeta::new(boost, false),
182            AccountMeta::new_readonly(config_pda().0, false),
183        ],
184        data: UpdateBoost {
185            expires_at: expires_at.to_le_bytes(),
186            multiplier: multiplier.to_le_bytes(),
187        }
188        .to_bytes(),
189    }
190}
191
192// Build withdraw instruction.
193pub fn withdraw(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
194    let boost_pda = boost_pda(mint);
195    let boost_deposits_address =
196        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
197    let beneficiary_address =
198        spl_associated_token_account::get_associated_token_address(&signer, &mint);
199    let stake_pda = stake_pda(signer, boost_pda.0);
200    Instruction {
201        program_id: crate::ID,
202        accounts: vec![
203            AccountMeta::new(signer, true),
204            AccountMeta::new(beneficiary_address, false),
205            AccountMeta::new(boost_pda.0, false),
206            AccountMeta::new(boost_deposits_address, false),
207            AccountMeta::new_readonly(mint, false),
208            AccountMeta::new(stake_pda.0, false),
209            AccountMeta::new_readonly(spl_token::ID, false),
210        ],
211        data: Withdraw {
212            amount: amount.to_le_bytes(),
213        }
214        .to_bytes(),
215    }
216}
217
218// Build migrate instruction.
219pub fn migrate(signer: Pubkey, authority: Pubkey, mint: Pubkey) -> Instruction {
220    let boost_pda = boost_pda(mint);
221    let boost_v1_pda = ore_boost_api_v1::state::boost_pda(mint);
222    let boost_deposits_address =
223        spl_associated_token_account::get_associated_token_address(&boost_pda.0, &mint);
224    let boost_deposits_v1_address =
225        spl_associated_token_account::get_associated_token_address(&boost_v1_pda.0, &mint);
226    let boost_rewards_address = spl_associated_token_account::get_associated_token_address(
227        &boost_pda.0,
228        &ore_api::consts::MINT_ADDRESS,
229    );
230    let boost_rewards_v1_address = spl_associated_token_account::get_associated_token_address(
231        &boost_v1_pda.0,
232        &ore_api::consts::MINT_ADDRESS,
233    );
234    let stake_pda = stake_pda(authority, boost_pda.0);
235    let stake_v1_pda = ore_boost_api_v1::state::stake_pda(authority, boost_v1_pda.0);
236    Instruction {
237        program_id: crate::ID,
238        accounts: vec![
239            AccountMeta::new(signer, true),
240            AccountMeta::new(authority, false),
241            AccountMeta::new(config_pda().0, false),
242            AccountMeta::new(signer, true),
243            AccountMeta::new(boost_pda.0, false),
244            AccountMeta::new(boost_v1_pda.0, false),
245            AccountMeta::new(boost_deposits_address, false),
246            AccountMeta::new(boost_deposits_v1_address, false),
247            AccountMeta::new(boost_rewards_address, false),
248            AccountMeta::new(boost_rewards_v1_address, false),
249            AccountMeta::new_readonly(mint, false),
250            AccountMeta::new(stake_pda.0, false),
251            AccountMeta::new(stake_v1_pda.0, false),
252            AccountMeta::new_readonly(ore_boost_api_v1::ID, false),
253            AccountMeta::new_readonly(system_program::ID, false),
254            AccountMeta::new_readonly(spl_token::ID, false),
255        ],
256        data: Migrate {}.to_bytes(),
257    }
258}