dlp_api/instruction_builder/
undelegate.rs1use dlp::{
2 discriminator::DlpDiscriminator,
3 pda::{
4 commit_record_pda_from_delegated_account,
5 commit_state_pda_from_delegated_account,
6 delegation_metadata_pda_from_delegated_account,
7 delegation_record_pda_from_delegated_account, fees_vault_pda,
8 undelegate_buffer_pda_from_delegated_account,
9 validator_fees_vault_pda_from_validator,
10 },
11 total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS,
12};
13use solana_program::{
14 instruction::{AccountMeta, Instruction},
15 pubkey::Pubkey,
16 system_program,
17};
18
19#[allow(clippy::too_many_arguments)]
22pub fn undelegate(
23 validator: Pubkey,
24 delegated_account: Pubkey,
25 owner_program: Pubkey,
26 rent_reimbursement: Pubkey,
27) -> Instruction {
28 let undelegate_buffer_pda =
29 undelegate_buffer_pda_from_delegated_account(&delegated_account);
30 let commit_state_pda =
31 commit_state_pda_from_delegated_account(&delegated_account);
32 let commit_record_pda =
33 commit_record_pda_from_delegated_account(&delegated_account);
34 let delegation_record_pda =
35 delegation_record_pda_from_delegated_account(&delegated_account);
36 let delegation_metadata_pda =
37 delegation_metadata_pda_from_delegated_account(&delegated_account);
38 let fees_vault_pda = fees_vault_pda();
39 let validator_fees_vault_pda =
40 validator_fees_vault_pda_from_validator(&validator);
41 Instruction {
42 program_id: dlp::id(),
43 accounts: vec![
44 AccountMeta::new(validator, true),
45 AccountMeta::new(delegated_account, false),
46 AccountMeta::new_readonly(owner_program, false),
47 AccountMeta::new(undelegate_buffer_pda, false),
48 AccountMeta::new_readonly(commit_state_pda, false),
49 AccountMeta::new_readonly(commit_record_pda, false),
50 AccountMeta::new(delegation_record_pda, false),
51 AccountMeta::new(delegation_metadata_pda, false),
52 AccountMeta::new(rent_reimbursement, false),
53 AccountMeta::new(fees_vault_pda, false),
54 AccountMeta::new(validator_fees_vault_pda, false),
55 AccountMeta::new_readonly(system_program::id(), false),
56 ],
57 data: DlpDiscriminator::Undelegate.to_vec(),
58 }
59}
60
61pub fn undelegate_size_budget(delegated_account: AccountSizeClass) -> u32 {
67 total_size_budget(&[
68 DLP_PROGRAM_DATA_SIZE_CLASS,
69 AccountSizeClass::Tiny, delegated_account, AccountSizeClass::Tiny, delegated_account, delegated_account, AccountSizeClass::Tiny, AccountSizeClass::Tiny, AccountSizeClass::Tiny, AccountSizeClass::Tiny, AccountSizeClass::Tiny, AccountSizeClass::Tiny, AccountSizeClass::Tiny, ])
82}