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