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