1use solana_program::pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12#[derive(Debug)]
14pub struct UpdateVault {
15
16
17 pub authority: solana_program::pubkey::Pubkey,
18
19
20 pub tuna_config: solana_program::pubkey::Pubkey,
21
22
23 pub vault: solana_program::pubkey::Pubkey,
24 }
25
26impl UpdateVault {
27 pub fn instruction(&self, args: UpdateVaultInstructionArgs) -> solana_program::instruction::Instruction {
28 self.instruction_with_remaining_accounts(args, &[])
29 }
30 #[allow(clippy::arithmetic_side_effects)]
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(&self, args: UpdateVaultInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
33 let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
34 accounts.push(solana_program::instruction::AccountMeta::new(
35 self.authority,
36 true
37 ));
38 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
39 self.tuna_config,
40 false
41 ));
42 accounts.push(solana_program::instruction::AccountMeta::new(
43 self.vault,
44 false
45 ));
46 accounts.extend_from_slice(remaining_accounts);
47 let mut data = borsh::to_vec(&UpdateVaultInstructionData::new()).unwrap();
48 let mut args = borsh::to_vec(&args).unwrap();
49 data.append(&mut args);
50
51 solana_program::instruction::Instruction {
52 program_id: crate::TUNA_ID,
53 accounts,
54 data,
55 }
56 }
57}
58
59#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
60#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61 pub struct UpdateVaultInstructionData {
62 discriminator: [u8; 8],
63 }
64
65impl UpdateVaultInstructionData {
66 pub fn new() -> Self {
67 Self {
68 discriminator: [67, 229, 185, 188, 226, 11, 210, 60],
69 }
70 }
71}
72
73impl Default for UpdateVaultInstructionData {
74 fn default() -> Self {
75 Self::new()
76 }
77}
78
79#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
81 pub struct UpdateVaultInstructionArgs {
82 pub interest_rate: u64,
83 pub supply_limit: u64,
84 pub pyth_oracle_price_update: Pubkey,
85 pub pyth_oracle_feed_id: Pubkey,
86 }
87
88
89#[derive(Clone, Debug, Default)]
97pub struct UpdateVaultBuilder {
98 authority: Option<solana_program::pubkey::Pubkey>,
99 tuna_config: Option<solana_program::pubkey::Pubkey>,
100 vault: Option<solana_program::pubkey::Pubkey>,
101 interest_rate: Option<u64>,
102 supply_limit: Option<u64>,
103 pyth_oracle_price_update: Option<Pubkey>,
104 pyth_oracle_feed_id: Option<Pubkey>,
105 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
106}
107
108impl UpdateVaultBuilder {
109 pub fn new() -> Self {
110 Self::default()
111 }
112 #[inline(always)]
113 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
114 self.authority = Some(authority);
115 self
116 }
117 #[inline(always)]
118 pub fn tuna_config(&mut self, tuna_config: solana_program::pubkey::Pubkey) -> &mut Self {
119 self.tuna_config = Some(tuna_config);
120 self
121 }
122 #[inline(always)]
123 pub fn vault(&mut self, vault: solana_program::pubkey::Pubkey) -> &mut Self {
124 self.vault = Some(vault);
125 self
126 }
127 #[inline(always)]
128 pub fn interest_rate(&mut self, interest_rate: u64) -> &mut Self {
129 self.interest_rate = Some(interest_rate);
130 self
131 }
132 #[inline(always)]
133 pub fn supply_limit(&mut self, supply_limit: u64) -> &mut Self {
134 self.supply_limit = Some(supply_limit);
135 self
136 }
137 #[inline(always)]
138 pub fn pyth_oracle_price_update(&mut self, pyth_oracle_price_update: Pubkey) -> &mut Self {
139 self.pyth_oracle_price_update = Some(pyth_oracle_price_update);
140 self
141 }
142 #[inline(always)]
143 pub fn pyth_oracle_feed_id(&mut self, pyth_oracle_feed_id: Pubkey) -> &mut Self {
144 self.pyth_oracle_feed_id = Some(pyth_oracle_feed_id);
145 self
146 }
147 #[inline(always)]
149 pub fn add_remaining_account(&mut self, account: solana_program::instruction::AccountMeta) -> &mut Self {
150 self.__remaining_accounts.push(account);
151 self
152 }
153 #[inline(always)]
155 pub fn add_remaining_accounts(&mut self, accounts: &[solana_program::instruction::AccountMeta]) -> &mut Self {
156 self.__remaining_accounts.extend_from_slice(accounts);
157 self
158 }
159 #[allow(clippy::clone_on_copy)]
160 pub fn instruction(&self) -> solana_program::instruction::Instruction {
161 let accounts = UpdateVault {
162 authority: self.authority.expect("authority is not set"),
163 tuna_config: self.tuna_config.expect("tuna_config is not set"),
164 vault: self.vault.expect("vault is not set"),
165 };
166 let args = UpdateVaultInstructionArgs {
167 interest_rate: self.interest_rate.clone().expect("interest_rate is not set"),
168 supply_limit: self.supply_limit.clone().expect("supply_limit is not set"),
169 pyth_oracle_price_update: self.pyth_oracle_price_update.clone().expect("pyth_oracle_price_update is not set"),
170 pyth_oracle_feed_id: self.pyth_oracle_feed_id.clone().expect("pyth_oracle_feed_id is not set"),
171 };
172
173 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
174 }
175}
176
177 pub struct UpdateVaultCpiAccounts<'a, 'b> {
179
180
181 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
182
183
184 pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
185
186
187 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
188 }
189
190pub struct UpdateVaultCpi<'a, 'b> {
192 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
194
195
196 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
197
198
199 pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
200
201
202 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
203 pub __args: UpdateVaultInstructionArgs,
205 }
206
207impl<'a, 'b> UpdateVaultCpi<'a, 'b> {
208 pub fn new(
209 program: &'b solana_program::account_info::AccountInfo<'a>,
210 accounts: UpdateVaultCpiAccounts<'a, 'b>,
211 args: UpdateVaultInstructionArgs,
212 ) -> Self {
213 Self {
214 __program: program,
215 authority: accounts.authority,
216 tuna_config: accounts.tuna_config,
217 vault: accounts.vault,
218 __args: args,
219 }
220 }
221 #[inline(always)]
222 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
223 self.invoke_signed_with_remaining_accounts(&[], &[])
224 }
225 #[inline(always)]
226 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> solana_program::entrypoint::ProgramResult {
227 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
228 }
229 #[inline(always)]
230 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
231 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
232 }
233 #[allow(clippy::arithmetic_side_effects)]
234 #[allow(clippy::clone_on_copy)]
235 #[allow(clippy::vec_init_then_push)]
236 pub fn invoke_signed_with_remaining_accounts(
237 &self,
238 signers_seeds: &[&[&[u8]]],
239 remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]
240 ) -> solana_program::entrypoint::ProgramResult {
241 let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
242 accounts.push(solana_program::instruction::AccountMeta::new(
243 *self.authority.key,
244 true
245 ));
246 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
247 *self.tuna_config.key,
248 false
249 ));
250 accounts.push(solana_program::instruction::AccountMeta::new(
251 *self.vault.key,
252 false
253 ));
254 remaining_accounts.iter().for_each(|remaining_account| {
255 accounts.push(solana_program::instruction::AccountMeta {
256 pubkey: *remaining_account.0.key,
257 is_signer: remaining_account.1,
258 is_writable: remaining_account.2,
259 })
260 });
261 let mut data = borsh::to_vec(&UpdateVaultInstructionData::new()).unwrap();
262 let mut args = borsh::to_vec(&self.__args).unwrap();
263 data.append(&mut args);
264
265 let instruction = solana_program::instruction::Instruction {
266 program_id: crate::TUNA_ID,
267 accounts,
268 data,
269 };
270 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
271 account_infos.push(self.__program.clone());
272 account_infos.push(self.authority.clone());
273 account_infos.push(self.tuna_config.clone());
274 account_infos.push(self.vault.clone());
275 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
276
277 if signers_seeds.is_empty() {
278 solana_program::program::invoke(&instruction, &account_infos)
279 } else {
280 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
281 }
282 }
283}
284
285#[derive(Clone, Debug)]
293pub struct UpdateVaultCpiBuilder<'a, 'b> {
294 instruction: Box<UpdateVaultCpiBuilderInstruction<'a, 'b>>,
295}
296
297impl<'a, 'b> UpdateVaultCpiBuilder<'a, 'b> {
298 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
299 let instruction = Box::new(UpdateVaultCpiBuilderInstruction {
300 __program: program,
301 authority: None,
302 tuna_config: None,
303 vault: None,
304 interest_rate: None,
305 supply_limit: None,
306 pyth_oracle_price_update: None,
307 pyth_oracle_feed_id: None,
308 __remaining_accounts: Vec::new(),
309 });
310 Self { instruction }
311 }
312 #[inline(always)]
313 pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
314 self.instruction.authority = Some(authority);
315 self
316 }
317 #[inline(always)]
318 pub fn tuna_config(&mut self, tuna_config: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
319 self.instruction.tuna_config = Some(tuna_config);
320 self
321 }
322 #[inline(always)]
323 pub fn vault(&mut self, vault: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
324 self.instruction.vault = Some(vault);
325 self
326 }
327 #[inline(always)]
328 pub fn interest_rate(&mut self, interest_rate: u64) -> &mut Self {
329 self.instruction.interest_rate = Some(interest_rate);
330 self
331 }
332 #[inline(always)]
333 pub fn supply_limit(&mut self, supply_limit: u64) -> &mut Self {
334 self.instruction.supply_limit = Some(supply_limit);
335 self
336 }
337 #[inline(always)]
338 pub fn pyth_oracle_price_update(&mut self, pyth_oracle_price_update: Pubkey) -> &mut Self {
339 self.instruction.pyth_oracle_price_update = Some(pyth_oracle_price_update);
340 self
341 }
342 #[inline(always)]
343 pub fn pyth_oracle_feed_id(&mut self, pyth_oracle_feed_id: Pubkey) -> &mut Self {
344 self.instruction.pyth_oracle_feed_id = Some(pyth_oracle_feed_id);
345 self
346 }
347 #[inline(always)]
349 pub fn add_remaining_account(&mut self, account: &'b solana_program::account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
350 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
351 self
352 }
353 #[inline(always)]
358 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
359 self.instruction.__remaining_accounts.extend_from_slice(accounts);
360 self
361 }
362 #[inline(always)]
363 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
364 self.invoke_signed(&[])
365 }
366 #[allow(clippy::clone_on_copy)]
367 #[allow(clippy::vec_init_then_push)]
368 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
369 let args = UpdateVaultInstructionArgs {
370 interest_rate: self.instruction.interest_rate.clone().expect("interest_rate is not set"),
371 supply_limit: self.instruction.supply_limit.clone().expect("supply_limit is not set"),
372 pyth_oracle_price_update: self.instruction.pyth_oracle_price_update.clone().expect("pyth_oracle_price_update is not set"),
373 pyth_oracle_feed_id: self.instruction.pyth_oracle_feed_id.clone().expect("pyth_oracle_feed_id is not set"),
374 };
375 let instruction = UpdateVaultCpi {
376 __program: self.instruction.__program,
377
378 authority: self.instruction.authority.expect("authority is not set"),
379
380 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
381
382 vault: self.instruction.vault.expect("vault is not set"),
383 __args: args,
384 };
385 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
386 }
387}
388
389#[derive(Clone, Debug)]
390struct UpdateVaultCpiBuilderInstruction<'a, 'b> {
391 __program: &'b solana_program::account_info::AccountInfo<'a>,
392 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
393 tuna_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
394 vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
395 interest_rate: Option<u64>,
396 supply_limit: Option<u64>,
397 pyth_oracle_price_update: Option<Pubkey>,
398 pyth_oracle_feed_id: Option<Pubkey>,
399 __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
401}
402