|
| 1 | +use 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, |
| 8 | + undelegate_buffer_pda_from_delegated_account, |
| 9 | + undelegation_request_pda_from_delegated_account, |
| 10 | + }, |
| 11 | + total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS, |
| 12 | +}; |
| 13 | +use solana_program::{ |
| 14 | + instruction::{AccountMeta, Instruction}, |
| 15 | + pubkey::Pubkey, |
| 16 | +}; |
| 17 | +use solana_sdk_ids::system_program; |
| 18 | + |
| 19 | +use crate::compat::{Compatize, Modernize}; |
| 20 | + |
| 21 | +/// Builds a timeout carry-over instruction for a requested undelegation. |
| 22 | +/// See [dlp::processor::process_carry_over_requested_undelegation] for docs. |
| 23 | +#[allow(clippy::too_many_arguments)] |
| 24 | +pub fn carry_over_requested_undelegation( |
| 25 | + caller: Pubkey, |
| 26 | + delegated_account: Pubkey, |
| 27 | + owner_program: Pubkey, |
| 28 | + request_rent_payer: Pubkey, |
| 29 | + delegation_rent_payer: Pubkey, |
| 30 | + commit_reimbursement: Pubkey, |
| 31 | +) -> Instruction { |
| 32 | + let delegated_account_compat = delegated_account.compatize(); |
| 33 | + let undelegate_buffer_pda = |
| 34 | + undelegate_buffer_pda_from_delegated_account(&delegated_account_compat) |
| 35 | + .modernize(); |
| 36 | + let request_pda = undelegation_request_pda_from_delegated_account( |
| 37 | + &delegated_account_compat, |
| 38 | + ) |
| 39 | + .modernize(); |
| 40 | + let delegation_record_pda = |
| 41 | + delegation_record_pda_from_delegated_account(&delegated_account_compat) |
| 42 | + .modernize(); |
| 43 | + let delegation_metadata_pda = |
| 44 | + delegation_metadata_pda_from_delegated_account( |
| 45 | + &delegated_account_compat, |
| 46 | + ) |
| 47 | + .modernize(); |
| 48 | + let commit_state_pda = |
| 49 | + commit_state_pda_from_delegated_account(&delegated_account_compat) |
| 50 | + .modernize(); |
| 51 | + let commit_record_pda = |
| 52 | + commit_record_pda_from_delegated_account(&delegated_account_compat) |
| 53 | + .modernize(); |
| 54 | + |
| 55 | + Instruction { |
| 56 | + program_id: dlp::id().modernize(), |
| 57 | + accounts: vec![ |
| 58 | + AccountMeta::new(caller, true), |
| 59 | + AccountMeta::new(delegated_account, false), |
| 60 | + AccountMeta::new_readonly(owner_program, false), |
| 61 | + AccountMeta::new(undelegate_buffer_pda, false), |
| 62 | + AccountMeta::new(request_pda, false), |
| 63 | + AccountMeta::new(delegation_record_pda, false), |
| 64 | + AccountMeta::new(delegation_metadata_pda, false), |
| 65 | + AccountMeta::new(request_rent_payer, false), |
| 66 | + AccountMeta::new(delegation_rent_payer, false), |
| 67 | + AccountMeta::new(commit_state_pda, false), |
| 68 | + AccountMeta::new(commit_record_pda, false), |
| 69 | + AccountMeta::new(commit_reimbursement, false), |
| 70 | + AccountMeta::new_readonly(system_program::id(), false), |
| 71 | + ], |
| 72 | + data: DlpDiscriminator::CarryOverRequestedUndelegation.to_vec(), |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/// |
| 77 | +/// Returns accounts-data-size budget for requested undelegation carry-over. |
| 78 | +/// |
| 79 | +/// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit |
| 80 | +/// |
| 81 | +pub fn carry_over_requested_undelegation_size_budget( |
| 82 | + delegated_account: AccountSizeClass, |
| 83 | +) -> u32 { |
| 84 | + total_size_budget(&[ |
| 85 | + DLP_PROGRAM_DATA_SIZE_CLASS, |
| 86 | + AccountSizeClass::Tiny, // caller |
| 87 | + delegated_account, // delegated_account |
| 88 | + AccountSizeClass::Tiny, // owner_program |
| 89 | + delegated_account, // undelegate_buffer_pda |
| 90 | + AccountSizeClass::Tiny, // undelegation_request_pda |
| 91 | + AccountSizeClass::Tiny, // delegation_record_pda |
| 92 | + AccountSizeClass::Tiny, // delegation_metadata_pda |
| 93 | + AccountSizeClass::Tiny, // request_rent_payer |
| 94 | + AccountSizeClass::Tiny, // delegation_rent_payer |
| 95 | + delegated_account, // commit_state_pda |
| 96 | + AccountSizeClass::Tiny, // commit_record_pda |
| 97 | + AccountSizeClass::Tiny, // commit_reimbursement |
| 98 | + AccountSizeClass::Tiny, // system_program |
| 99 | + ]) |
| 100 | +} |
0 commit comments