solders_system_program/
lib.rs

1use dict_derive::{FromPyObject, IntoPyObject};
2use pyo3::{exceptions::PyValueError, prelude::*};
3use solana_program::address_lookup_table::instruction::{
4    close_lookup_table as close_lookup_table_original,
5    create_lookup_table as create_lookup_table_original,
6    create_lookup_table_signed as create_lookup_table_signed_original,
7    deactivate_lookup_table as deactivate_lookup_table_original,
8    extend_lookup_table as extend_lookup_table_original,
9    freeze_lookup_table as freeze_lookup_table_original,
10};
11use solana_sdk::{
12    instruction::Instruction as InstructionOriginal,
13    pubkey::Pubkey as PubkeyOriginal,
14    system_instruction::{
15        advance_nonce_account as advance_nonce_account_original, allocate as allocate_original,
16        allocate_with_seed as allocate_with_seed_original, assign as assign_original,
17        assign_with_seed as assign_with_seed_original,
18        authorize_nonce_account as authorize_nonce_account_original,
19        create_account as create_account_original,
20        create_account_with_seed as create_account_with_seed_original,
21        create_nonce_account as create_nonce_account_original,
22        create_nonce_account_with_seed as create_nonce_account_with_seed_original,
23        transfer as transfer_original, transfer_many as transfer_many_original,
24        transfer_with_seed as transfer_with_seed_original,
25        withdraw_nonce_account as withdraw_nonce_account_original,
26        SystemInstruction as SystemInstructionOriginal,
27    },
28    system_program,
29};
30
31use solders_instruction::Instruction;
32use solders_pubkey::Pubkey;
33use solders_traits::handle_py_err;
34
35fn convert_instructions_from_original(ixs: Vec<InstructionOriginal>) -> Vec<Instruction> {
36    ixs.into_iter().map(Instruction::from).collect()
37}
38
39pub fn create_system_program_mod(py: Python<'_>) -> PyResult<&PyModule> {
40    let system_program_mod = PyModule::new(py, "_system_program")?;
41    system_program_mod.add("ID", Pubkey(system_program::ID))?;
42    let funcs = [
43        wrap_pyfunction!(create_account, system_program_mod)?,
44        wrap_pyfunction!(decode_create_account, system_program_mod)?,
45        wrap_pyfunction!(create_account_with_seed, system_program_mod)?,
46        wrap_pyfunction!(decode_create_account_with_seed, system_program_mod)?,
47        wrap_pyfunction!(assign, system_program_mod)?,
48        wrap_pyfunction!(decode_assign, system_program_mod)?,
49        wrap_pyfunction!(assign_with_seed, system_program_mod)?,
50        wrap_pyfunction!(decode_assign_with_seed, system_program_mod)?,
51        wrap_pyfunction!(transfer, system_program_mod)?,
52        wrap_pyfunction!(decode_transfer, system_program_mod)?,
53        wrap_pyfunction!(transfer_with_seed, system_program_mod)?,
54        wrap_pyfunction!(decode_transfer_with_seed, system_program_mod)?,
55        wrap_pyfunction!(allocate, system_program_mod)?,
56        wrap_pyfunction!(decode_allocate, system_program_mod)?,
57        wrap_pyfunction!(allocate_with_seed, system_program_mod)?,
58        wrap_pyfunction!(decode_allocate_with_seed, system_program_mod)?,
59        wrap_pyfunction!(transfer_many, system_program_mod)?,
60        wrap_pyfunction!(create_nonce_account, system_program_mod)?,
61        wrap_pyfunction!(initialize_nonce_account, system_program_mod)?,
62        wrap_pyfunction!(decode_initialize_nonce_account, system_program_mod)?,
63        wrap_pyfunction!(create_nonce_account_with_seed, system_program_mod)?,
64        wrap_pyfunction!(advance_nonce_account, system_program_mod)?,
65        wrap_pyfunction!(decode_advance_nonce_account, system_program_mod)?,
66        wrap_pyfunction!(withdraw_nonce_account, system_program_mod)?,
67        wrap_pyfunction!(decode_withdraw_nonce_account, system_program_mod)?,
68        wrap_pyfunction!(authorize_nonce_account, system_program_mod)?,
69        wrap_pyfunction!(decode_authorize_nonce_account, system_program_mod)?,
70        // address_lookup_table_program
71        wrap_pyfunction!(close_lookup_table, system_program_mod)?,
72        wrap_pyfunction!(create_lookup_table, system_program_mod)?,
73        wrap_pyfunction!(create_lookup_table_signed, system_program_mod)?,
74        wrap_pyfunction!(deactivate_lookup_table, system_program_mod)?,
75        wrap_pyfunction!(extend_lookup_table, system_program_mod)?,
76        wrap_pyfunction!(freeze_lookup_table, system_program_mod)?,
77    ];
78    for func in funcs {
79        system_program_mod.add_function(func)?;
80    }
81    Ok(system_program_mod)
82}
83
84#[derive(FromPyObject, IntoPyObject)]
85pub struct CreateAccountParams {
86    from_pubkey: Pubkey,
87    to_pubkey: Pubkey,
88    lamports: u64,
89    space: u64,
90    owner: Pubkey,
91}
92
93#[pyfunction]
94pub fn decode_create_account(instruction: Instruction) -> PyResult<CreateAccountParams> {
95    let keys = instruction.0.accounts;
96    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
97        instruction.0.data.as_slice(),
98    ))?;
99    match parsed_data {
100        SystemInstructionOriginal::CreateAccount {
101            lamports,
102            space,
103            owner,
104        } => Ok(CreateAccountParams {
105            from_pubkey: keys[0].pubkey.into(),
106            to_pubkey: keys[1].pubkey.into(),
107            lamports,
108            space,
109            owner: owner.into(),
110        }),
111        _ => Err(PyValueError::new_err("Not a CreateAccount instruction")),
112    }
113}
114
115#[pyfunction]
116pub fn create_account(params: CreateAccountParams) -> Instruction {
117    create_account_original(
118        params.from_pubkey.as_ref(),
119        params.to_pubkey.as_ref(),
120        params.lamports,
121        params.space,
122        params.owner.as_ref(),
123    )
124    .into()
125}
126
127#[derive(FromPyObject, IntoPyObject)]
128pub struct CreateAccountWithSeedParams {
129    from_pubkey: Pubkey,
130    to_pubkey: Pubkey,
131    base: Pubkey,
132    seed: String,
133    lamports: u64,
134    space: u64,
135    owner: Pubkey,
136}
137
138#[pyfunction]
139pub fn create_account_with_seed(params: CreateAccountWithSeedParams) -> Instruction {
140    create_account_with_seed_original(
141        params.from_pubkey.as_ref(),
142        params.to_pubkey.as_ref(),
143        params.base.as_ref(),
144        &params.seed,
145        params.lamports,
146        params.space,
147        params.owner.as_ref(),
148    )
149    .into()
150}
151
152#[pyfunction]
153pub fn decode_create_account_with_seed(
154    instruction: Instruction,
155) -> PyResult<CreateAccountWithSeedParams> {
156    let keys = instruction.0.accounts;
157    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
158        instruction.0.data.as_slice(),
159    ))?;
160    match parsed_data {
161        SystemInstructionOriginal::CreateAccountWithSeed {
162            base,
163            seed,
164            lamports,
165            space,
166            owner,
167        } => Ok(CreateAccountWithSeedParams {
168            from_pubkey: keys[0].pubkey.into(),
169            to_pubkey: keys[1].pubkey.into(),
170            base: base.into(),
171            seed,
172            lamports,
173            space,
174            owner: owner.into(),
175        }),
176        _ => Err(PyValueError::new_err(
177            "Not a CreateAccountWithSeed instruction",
178        )),
179    }
180}
181
182#[derive(FromPyObject, IntoPyObject)]
183pub struct AssignParams {
184    pubkey: Pubkey,
185    owner: Pubkey,
186}
187
188#[pyfunction]
189pub fn assign(params: AssignParams) -> Instruction {
190    assign_original(params.pubkey.as_ref(), params.owner.as_ref()).into()
191}
192
193#[pyfunction]
194pub fn decode_assign(instruction: Instruction) -> PyResult<AssignParams> {
195    let pubkey = instruction.0.accounts[0].pubkey;
196    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
197        instruction.0.data.as_slice(),
198    ))?;
199    match parsed_data {
200        SystemInstructionOriginal::Assign { owner } => Ok(AssignParams {
201            pubkey: pubkey.into(),
202            owner: owner.into(),
203        }),
204        _ => Err(PyValueError::new_err("Not an Assign instruction")),
205    }
206}
207
208#[derive(FromPyObject, IntoPyObject)]
209pub struct AssignWithSeedParams {
210    address: Pubkey,
211    base: Pubkey,
212    seed: String,
213    owner: Pubkey,
214}
215
216#[pyfunction]
217pub fn assign_with_seed(params: AssignWithSeedParams) -> Instruction {
218    assign_with_seed_original(
219        params.address.as_ref(),
220        params.base.as_ref(),
221        &params.seed,
222        params.owner.as_ref(),
223    )
224    .into()
225}
226
227#[pyfunction]
228pub fn decode_assign_with_seed(instruction: Instruction) -> PyResult<AssignWithSeedParams> {
229    let address = instruction.0.accounts[0].pubkey;
230    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
231        instruction.0.data.as_slice(),
232    ))?;
233    match parsed_data {
234        SystemInstructionOriginal::AssignWithSeed { base, seed, owner } => {
235            Ok(AssignWithSeedParams {
236                address: address.into(),
237                base: base.into(),
238                seed,
239                owner: owner.into(),
240            })
241        }
242        _ => Err(PyValueError::new_err("Not an AssignWithSeed instruction")),
243    }
244}
245
246#[derive(FromPyObject, IntoPyObject)]
247pub struct TransferParams {
248    from_pubkey: Pubkey,
249    to_pubkey: Pubkey,
250    lamports: u64,
251}
252
253#[pyfunction]
254pub fn transfer(params: TransferParams) -> Instruction {
255    transfer_original(
256        params.from_pubkey.as_ref(),
257        params.to_pubkey.as_ref(),
258        params.lamports,
259    )
260    .into()
261}
262
263#[pyfunction]
264pub fn decode_transfer(instruction: Instruction) -> PyResult<TransferParams> {
265    let keys = instruction.0.accounts;
266    let from_pubkey = keys[0].pubkey;
267    let to_pubkey = keys[1].pubkey;
268    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
269        instruction.0.data.as_slice(),
270    ))?;
271    match parsed_data {
272        SystemInstructionOriginal::Transfer { lamports } => Ok(TransferParams {
273            from_pubkey: from_pubkey.into(),
274            to_pubkey: to_pubkey.into(),
275            lamports,
276        }),
277        _ => Err(PyValueError::new_err("Not a Transfer instruction")),
278    }
279}
280
281#[derive(FromPyObject, IntoPyObject)]
282pub struct TransferWithSeedParams {
283    from_pubkey: Pubkey,
284    from_base: Pubkey,
285    from_seed: String,
286    from_owner: Pubkey,
287    to_pubkey: Pubkey,
288    lamports: u64,
289}
290
291#[pyfunction]
292pub fn transfer_with_seed(params: TransferWithSeedParams) -> Instruction {
293    transfer_with_seed_original(
294        params.from_pubkey.as_ref(),
295        params.from_base.as_ref(),
296        params.from_seed,
297        params.from_owner.as_ref(),
298        params.to_pubkey.as_ref(),
299        params.lamports,
300    )
301    .into()
302}
303
304#[pyfunction]
305pub fn decode_transfer_with_seed(instruction: Instruction) -> PyResult<TransferWithSeedParams> {
306    let keys = instruction.0.accounts;
307    let from_pubkey = keys[0].pubkey;
308    let from_base = keys[1].pubkey;
309    let to_pubkey = keys[2].pubkey;
310    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
311        instruction.0.data.as_slice(),
312    ))?;
313    match parsed_data {
314        SystemInstructionOriginal::TransferWithSeed {
315            lamports,
316            from_seed,
317            from_owner,
318        } => Ok(TransferWithSeedParams {
319            from_pubkey: from_pubkey.into(),
320            from_base: from_base.into(),
321            to_pubkey: to_pubkey.into(),
322            from_seed,
323            from_owner: from_owner.into(),
324            lamports,
325        }),
326        _ => Err(PyValueError::new_err("Not a TransferWithSeed instruction")),
327    }
328}
329
330#[derive(FromPyObject, IntoPyObject)]
331pub struct AllocateParams {
332    pubkey: Pubkey,
333    space: u64,
334}
335
336#[pyfunction]
337pub fn allocate(params: AllocateParams) -> Instruction {
338    allocate_original(params.pubkey.as_ref(), params.space).into()
339}
340
341#[pyfunction]
342pub fn decode_allocate(instruction: Instruction) -> PyResult<AllocateParams> {
343    let pubkey = instruction.0.accounts[0].pubkey;
344    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
345        instruction.0.data.as_slice(),
346    ))?;
347    match parsed_data {
348        SystemInstructionOriginal::Allocate { space } => Ok(AllocateParams {
349            pubkey: pubkey.into(),
350            space,
351        }),
352        _ => Err(PyValueError::new_err("Not an Allocate instruction")),
353    }
354}
355
356#[derive(FromPyObject, IntoPyObject)]
357pub struct AllocateWithSeedParams {
358    address: Pubkey,
359    base: Pubkey,
360    seed: String,
361    space: u64,
362    owner: Pubkey,
363}
364
365#[pyfunction]
366pub fn allocate_with_seed(params: AllocateWithSeedParams) -> Instruction {
367    allocate_with_seed_original(
368        params.address.as_ref(),
369        params.base.as_ref(),
370        &params.seed,
371        params.space,
372        params.owner.as_ref(),
373    )
374    .into()
375}
376
377#[pyfunction]
378pub fn decode_allocate_with_seed(instruction: Instruction) -> PyResult<AllocateWithSeedParams> {
379    let address = instruction.0.accounts[0].pubkey;
380    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
381        instruction.0.data.as_slice(),
382    ))?;
383    match parsed_data {
384        SystemInstructionOriginal::AllocateWithSeed {
385            base,
386            seed,
387            space,
388            owner,
389        } => Ok(AllocateWithSeedParams {
390            address: address.into(),
391            base: base.into(),
392            seed,
393            space,
394            owner: owner.into(),
395        }),
396        _ => Err(PyValueError::new_err("Not an AllocateWithSeed instruction")),
397    }
398}
399
400#[pyfunction]
401/// Create new Transfer instructions to many destinations.
402///
403/// Args:
404///     from_pubkey (Pubkey): The sender pubkey.
405///     to_lamports (Sequence[tuple[int, Pubkey]]): The lamports to transfer to each pubkey.
406///
407/// Returns:
408///     list[Instruction]: The Transfer instructions.
409///
410pub fn transfer_many(from_pubkey: &Pubkey, to_lamports: Vec<(Pubkey, u64)>) -> Vec<Instruction> {
411    let to_lamports_converted: Vec<(PubkeyOriginal, u64)> = to_lamports
412        .into_iter()
413        .map(|x| (PubkeyOriginal::from(x.0), x.1))
414        .collect();
415    convert_instructions_from_original(transfer_many_original(
416        from_pubkey.as_ref(),
417        &to_lamports_converted,
418    ))
419}
420
421#[pyfunction]
422/// Generate instructions to create and initialize a nonce account.
423///
424/// Args:
425///     from_pubkey (Pubkey): The account that will transfer
426///         lamports to the created nonce account.
427///     nonce_pubkey (Pubkey): Nonce account which will be
428///         created and initialized.
429///     authority (Pubkey): Pubkey to set as authority of the
430///         initialized nonce account.
431///     lamports (int): Amount of lamports to transfer to
432///         the created account.
433///
434/// Returns:
435///     tuple[Instruction, Instruction]: The CreateAccount instruction and the InitializeNonceAccount instruction.
436///
437pub fn create_nonce_account(
438    from_pubkey: &Pubkey,
439    nonce_pubkey: &Pubkey,
440    authority: &Pubkey,
441    lamports: u64,
442) -> (Instruction, Instruction) {
443    let ixs = create_nonce_account_original(
444        from_pubkey.as_ref(),
445        nonce_pubkey.as_ref(),
446        authority.as_ref(),
447        lamports,
448    );
449    (ixs[0].clone().into(), ixs[1].clone().into())
450}
451
452#[derive(FromPyObject, IntoPyObject)]
453pub struct InitializeNonceAccountParams {
454    nonce_pubkey: Pubkey,
455    authority: Pubkey,
456}
457
458#[pyfunction]
459pub fn initialize_nonce_account(params: InitializeNonceAccountParams) -> Instruction {
460    create_nonce_account(
461        &Pubkey::default(),
462        &params.nonce_pubkey,
463        &params.authority,
464        0,
465    )
466    .1
467}
468
469#[pyfunction]
470pub fn decode_initialize_nonce_account(
471    instruction: Instruction,
472) -> PyResult<InitializeNonceAccountParams> {
473    let nonce_pubkey = instruction.0.accounts[0].pubkey;
474    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
475        instruction.0.data.as_slice(),
476    ))?;
477    match parsed_data {
478        SystemInstructionOriginal::InitializeNonceAccount(authority) => {
479            Ok(InitializeNonceAccountParams {
480                authority: authority.into(),
481                nonce_pubkey: nonce_pubkey.into(),
482            })
483        }
484        _ => Err(PyValueError::new_err(
485            "Not an InitializeNonceAccount instruction",
486        )),
487    }
488}
489
490#[pyfunction]
491/// Generate instructions to create a nonce account with seed.
492///
493/// Args:
494///     from_pubkey (Pubkey): The account that will transfer
495///         lamports to the created nonce account.
496///     nonce_pubkey (Pubkey): Nonce account which will be
497///         created and initialized. Must be pre-calculated
498///         with :meth:`~solders.pubkey.Pubkey.create_with_seed`
499///     base (Pubkey): Base public key to use to derive the
500///         address of the created account. Must be the same
501///         as the base key used to create ``nonce_pubkey``.
502///     seed (str): Seed to use to derive the address of the created account.
503///         Must be the same as the seed used to create ``nonce_pubkey``.
504///     authority (Pubkey): Pubkey to set as authority of the
505///         initialized nonce account.
506///     lamports (int): Amount of lamports to transfer to
507///         the created account.
508///
509/// Returns:
510///     tuple[Instruction, Instruction]: The CreateAccountWithSeed instruction and the InitializeNonceAccount instruction.
511///
512pub fn create_nonce_account_with_seed(
513    from_pubkey: &Pubkey,
514    nonce_pubkey: &Pubkey,
515    base: &Pubkey,
516    seed: &str,
517    authority: &Pubkey,
518    lamports: u64,
519) -> (Instruction, Instruction) {
520    let ixs = create_nonce_account_with_seed_original(
521        from_pubkey.as_ref(),
522        nonce_pubkey.as_ref(),
523        base.as_ref(),
524        seed,
525        authority.as_ref(),
526        lamports,
527    );
528    (ixs[0].clone().into(), ixs[1].clone().into())
529}
530
531#[derive(FromPyObject, IntoPyObject)]
532pub struct AdvanceNonceAccountParams {
533    nonce_pubkey: Pubkey,
534    authorized_pubkey: Pubkey,
535}
536
537#[pyfunction]
538pub fn advance_nonce_account(params: AdvanceNonceAccountParams) -> Instruction {
539    advance_nonce_account_original(
540        params.nonce_pubkey.as_ref(),
541        params.authorized_pubkey.as_ref(),
542    )
543    .into()
544}
545
546#[pyfunction]
547pub fn decode_advance_nonce_account(
548    instruction: Instruction,
549) -> PyResult<AdvanceNonceAccountParams> {
550    let keys = instruction.0.accounts;
551    let nonce_pubkey = keys[0].pubkey;
552    let authorized_pubkey = keys[2].pubkey;
553    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
554        instruction.0.data.as_slice(),
555    ))?;
556    match parsed_data {
557        SystemInstructionOriginal::AdvanceNonceAccount => Ok(AdvanceNonceAccountParams {
558            authorized_pubkey: authorized_pubkey.into(),
559            nonce_pubkey: nonce_pubkey.into(),
560        }),
561        _ => Err(PyValueError::new_err(
562            "Not an AdvanceNonceAccount instruction",
563        )),
564    }
565}
566
567#[derive(FromPyObject, IntoPyObject)]
568pub struct WithdrawNonceAccountParams {
569    nonce_pubkey: Pubkey,
570    authorized_pubkey: Pubkey,
571    to_pubkey: Pubkey,
572    lamports: u64,
573}
574
575#[pyfunction]
576pub fn withdraw_nonce_account(params: WithdrawNonceAccountParams) -> Instruction {
577    withdraw_nonce_account_original(
578        params.nonce_pubkey.as_ref(),
579        params.authorized_pubkey.as_ref(),
580        params.to_pubkey.as_ref(),
581        params.lamports,
582    )
583    .into()
584}
585
586#[pyfunction]
587pub fn decode_withdraw_nonce_account(
588    instruction: Instruction,
589) -> PyResult<WithdrawNonceAccountParams> {
590    let keys = instruction.0.accounts;
591    let nonce_pubkey = keys[0].pubkey;
592    let to_pubkey = keys[1].pubkey;
593    let authorized_pubkey = keys[4].pubkey;
594    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
595        instruction.0.data.as_slice(),
596    ))?;
597    match parsed_data {
598        SystemInstructionOriginal::WithdrawNonceAccount(lamports) => {
599            Ok(WithdrawNonceAccountParams {
600                authorized_pubkey: authorized_pubkey.into(),
601                nonce_pubkey: nonce_pubkey.into(),
602                to_pubkey: to_pubkey.into(),
603                lamports,
604            })
605        }
606        _ => Err(PyValueError::new_err(
607            "Not a WithdrawNonceAccount instruction",
608        )),
609    }
610}
611
612#[derive(FromPyObject, IntoPyObject)]
613pub struct AuthorizeNonceAccountParams {
614    nonce_pubkey: Pubkey,
615    authorized_pubkey: Pubkey,
616    new_authority: Pubkey,
617}
618
619#[pyfunction]
620pub fn authorize_nonce_account(params: AuthorizeNonceAccountParams) -> Instruction {
621    authorize_nonce_account_original(
622        params.nonce_pubkey.as_ref(),
623        params.authorized_pubkey.as_ref(),
624        params.new_authority.as_ref(),
625    )
626    .into()
627}
628
629#[pyfunction]
630pub fn decode_authorize_nonce_account(
631    instruction: Instruction,
632) -> PyResult<AuthorizeNonceAccountParams> {
633    let keys = instruction.0.accounts;
634    let nonce_pubkey = keys[0].pubkey;
635    let authorized_pubkey = keys[1].pubkey;
636    let parsed_data = handle_py_err(bincode::deserialize::<SystemInstructionOriginal>(
637        instruction.0.data.as_slice(),
638    ))?;
639    match parsed_data {
640        SystemInstructionOriginal::AuthorizeNonceAccount(new_authority) => {
641            Ok(AuthorizeNonceAccountParams {
642                nonce_pubkey: nonce_pubkey.into(),
643                authorized_pubkey: authorized_pubkey.into(),
644                new_authority: new_authority.into(),
645            })
646        }
647        _ => Err(PyValueError::new_err(
648            "Not an AuthorizeNonceAccount instruction",
649        )),
650    }
651}
652
653#[derive(FromPyObject, IntoPyObject)]
654pub struct CloseLookupTableParams {
655    lookup_table_address: Pubkey,
656    authority_address: Pubkey,
657    recipient_address: Pubkey,
658}
659
660#[pyfunction]
661pub fn close_lookup_table(params: CloseLookupTableParams) -> Instruction {
662    close_lookup_table_original(
663        params.lookup_table_address.into(),
664        params.authority_address.into(),
665        params.recipient_address.into(),
666    )
667    .into()
668}
669
670#[derive(FromPyObject, IntoPyObject)]
671pub struct CreateLookupTableParams {
672    authority_address: Pubkey,
673    payer_address: Pubkey,
674    recent_slot: u64,
675}
676
677#[pyfunction]
678pub fn create_lookup_table(params: CreateLookupTableParams) -> (Instruction, Pubkey) {
679    let (instruction, lookup_table_address) = create_lookup_table_original(
680        params.authority_address.into(),
681        params.payer_address.into(),
682        params.recent_slot,
683    );
684    (instruction.into(), lookup_table_address.into())
685}
686
687#[derive(FromPyObject, IntoPyObject)]
688pub struct CreateLookupTableSignedParams {
689    authority_address: Pubkey,
690    payer_address: Pubkey,
691    recent_slot: u64,
692}
693
694#[pyfunction]
695pub fn create_lookup_table_signed(params: CreateLookupTableSignedParams) -> (Instruction, Pubkey) {
696    let (instruction, lookup_table_address) = create_lookup_table_signed_original(
697        params.authority_address.into(),
698        params.payer_address.into(),
699        params.recent_slot,
700    );
701    (instruction.into(), lookup_table_address.into())
702}
703
704#[derive(FromPyObject, IntoPyObject)]
705pub struct DeactivateLookupTableParams {
706    lookup_table_address: Pubkey,
707    authority_address: Pubkey,
708}
709
710#[pyfunction]
711pub fn deactivate_lookup_table(params: DeactivateLookupTableParams) -> Instruction {
712    deactivate_lookup_table_original(
713        params.lookup_table_address.into(),
714        params.authority_address.into(),
715    )
716    .into()
717}
718
719#[derive(FromPyObject, IntoPyObject)]
720pub struct ExtendLookupTableParams {
721    lookup_table_address: Pubkey,
722    authority_address: Pubkey,
723    payer_address: Option<Pubkey>,
724    new_addresses: Vec<Pubkey>,
725}
726
727#[pyfunction]
728pub fn extend_lookup_table(params: ExtendLookupTableParams) -> Instruction {
729    extend_lookup_table_original(
730        params.lookup_table_address.into(),
731        params.authority_address.into(),
732        params.payer_address.map(Into::into),
733        params
734            .new_addresses
735            .into_iter()
736            .map(Into::into)
737            .collect::<Vec<_>>(),
738    )
739    .into()
740}
741
742#[derive(FromPyObject, IntoPyObject)]
743pub struct FreezeLookupTableParams {
744    lookup_table_address: Pubkey,
745    authority_address: Pubkey,
746}
747
748#[pyfunction]
749pub fn freeze_lookup_table(params: FreezeLookupTableParams) -> Instruction {
750    freeze_lookup_table_original(
751        params.lookup_table_address.into(),
752        params.authority_address.into(),
753    )
754    .into()
755}