|
1 | | -use borsh::to_vec; |
2 | 1 | use solana_program::instruction::Instruction; |
3 | 2 | use solana_program::system_program; |
4 | 3 | use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; |
5 | 4 |
|
6 | 5 | use crate::args::CommitFinalizeArgs; |
7 | 6 | use crate::discriminator::DlpDiscriminator; |
8 | | -use crate::pda::{ |
9 | | - delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account, |
10 | | - program_config_from_program_id, validator_fees_vault_pda_from_validator, |
| 7 | +use crate::pod_view::PodView; |
| 8 | +use crate::{ |
| 9 | + delegation_metadata_seeds_from_delegated_account, |
| 10 | + delegation_record_seeds_from_delegated_account, program_config_seeds_from_program_id, |
| 11 | + total_size_budget, validator_fees_vault_seeds_from_validator, AccountSizeClass, |
| 12 | + DLP_PROGRAM_DATA_SIZE_CLASS, |
11 | 13 | }; |
12 | | -use crate::{total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS}; |
13 | 14 |
|
14 | 15 | /// Builds a commit finalize instruction. |
15 | 16 | /// See [crate::processor::process_commit_finalize] for docs. |
16 | 17 | pub fn commit_finalize( |
17 | 18 | validator: Pubkey, |
18 | 19 | delegated_account: Pubkey, |
19 | 20 | delegated_account_owner: Pubkey, |
20 | | - commit_args: CommitFinalizeArgs, |
| 21 | + commit_args: &mut CommitFinalizeArgs, |
| 22 | + data: &[u8], |
21 | 23 | ) -> Instruction { |
22 | | - let commit_args = to_vec(&commit_args).unwrap(); |
23 | | - let delegation_record_pda = delegation_record_pda_from_delegated_account(&delegated_account); |
24 | | - let validator_fees_vault_pda = validator_fees_vault_pda_from_validator(&validator); |
25 | | - let delegation_metadata_pda = |
26 | | - delegation_metadata_pda_from_delegated_account(&delegated_account); |
27 | | - let program_config_pda = program_config_from_program_id(&delegated_account_owner); |
| 24 | + let delegation_record = Pubkey::find_program_address( |
| 25 | + delegation_record_seeds_from_delegated_account!(delegated_account), |
| 26 | + &crate::id(), |
| 27 | + ); |
| 28 | + |
| 29 | + let validator_fees_vault = Pubkey::find_program_address( |
| 30 | + validator_fees_vault_seeds_from_validator!(validator), |
| 31 | + &crate::id(), |
| 32 | + ); |
| 33 | + |
| 34 | + let delegation_metadata = Pubkey::find_program_address( |
| 35 | + delegation_metadata_seeds_from_delegated_account!(delegated_account), |
| 36 | + &crate::id(), |
| 37 | + ); |
| 38 | + |
| 39 | + let program_config = Pubkey::find_program_address( |
| 40 | + program_config_seeds_from_program_id!(delegated_account_owner), |
| 41 | + &crate::id(), |
| 42 | + ); |
| 43 | + |
| 44 | + // save the bumps in the args |
| 45 | + commit_args.delegation_record_bump = delegation_record.1; |
| 46 | + commit_args.delegation_metadata_bump = delegation_metadata.1; |
| 47 | + commit_args.validator_fees_vault_bump = validator_fees_vault.1; |
| 48 | + commit_args.program_config_bump = program_config.1; |
| 49 | + |
28 | 50 | Instruction { |
29 | 51 | program_id: crate::id(), |
30 | 52 | accounts: vec![ |
31 | 53 | AccountMeta::new_readonly(validator, true), |
32 | 54 | AccountMeta::new(delegated_account, false), |
33 | | - AccountMeta::new_readonly(delegation_record_pda, false), |
34 | | - AccountMeta::new(delegation_metadata_pda, false), |
35 | | - AccountMeta::new_readonly(validator_fees_vault_pda, false), |
36 | | - AccountMeta::new_readonly(program_config_pda, false), |
| 55 | + AccountMeta::new_readonly(delegation_record.0, false), |
| 56 | + AccountMeta::new(delegation_metadata.0, false), |
| 57 | + AccountMeta::new_readonly(validator_fees_vault.0, false), |
| 58 | + AccountMeta::new_readonly(program_config.0, false), |
37 | 59 | AccountMeta::new_readonly(system_program::id(), false), |
38 | 60 | ], |
39 | | - data: [DlpDiscriminator::CommitFinalize.to_vec(), commit_args].concat(), |
| 61 | + data: [ |
| 62 | + DlpDiscriminator::CommitFinalize.to_vec(), |
| 63 | + commit_args.to_bytes(), |
| 64 | + data.to_vec(), |
| 65 | + ] |
| 66 | + .concat(), |
40 | 67 | } |
41 | 68 | } |
42 | 69 |
|
|
0 commit comments