@@ -15,6 +15,7 @@ use crate::loaders::{load_owned_pda, load_program, load_signer, load_uninitializ
1515use crate :: state:: { CommitRecord , DelegationMetadata , DelegationRecord } ;
1616use crate :: utils:: { close_pda, create_pda, ValidateEdwards } ;
1717use crate :: utils_account:: AccountDeserialize ;
18+ use crate :: verify_state:: verify_state;
1819use solana_program:: sysvar:: Sysvar ;
1920
2021/// Undelegate a delegated Pda
@@ -38,13 +39,13 @@ pub fn process_undelegate(
3839 accounts : & [ AccountInfo ] ,
3940 _data : & [ u8 ] ,
4041) -> ProgramResult {
41- let [ payer , delegated_account, owner_program, buffer, committed_state_account, committed_state_record, delegation_record, delegation_metadata, reimbursement, system_program] =
42+ let [ authority , delegated_account, owner_program, buffer, committed_state_account, committed_state_record, delegation_record, delegation_metadata, reimbursement, system_program] =
4243 accounts
4344 else {
4445 return Err ( ProgramError :: NotEnoughAccountKeys ) ;
4546 } ;
4647
47- load_signer ( payer ) ?;
48+ load_signer ( authority ) ?;
4849 load_owned_pda ( delegated_account, & crate :: id ( ) ) ?;
4950 load_owned_pda ( delegation_record, & crate :: id ( ) ) ?;
5051 load_owned_pda ( delegation_metadata, & crate :: id ( ) ) ?;
@@ -83,6 +84,16 @@ pub fn process_undelegate(
8384 None
8485 } ;
8586
87+ // If there is a committed state, verify the state
88+ if commit_record. is_some ( ) {
89+ verify_state (
90+ authority,
91+ delegation,
92+ commit_record. unwrap ( ) ,
93+ committed_state_account,
94+ ) ?;
95+ }
96+
8697 // Load delegated account metadata
8798 let metadata = DelegationMetadata :: deserialize ( & mut & * * delegation_metadata. data . borrow ( ) ) ?;
8899
@@ -108,7 +119,7 @@ pub fn process_undelegate(
108119 } ,
109120 & [ BUFFER , & delegated_account. key . to_bytes ( ) , & [ buffer_bump] ] ,
110121 system_program,
111- payer ,
122+ authority ,
112123 ) ?;
113124
114125 if !delegation. owner . eq ( owner_program. key ) {
@@ -146,7 +157,7 @@ pub fn process_undelegate(
146157 let signer_seeds: & [ & [ & [ u8 ] ] ] =
147158 & [ & [ BUFFER , & delegated_account. key . to_bytes ( ) , & [ buffer_bump] ] ] ;
148159 cpi_external_undelegate (
149- payer ,
160+ authority ,
150161 delegated_account,
151162 buffer,
152163 system_program,
@@ -171,7 +182,7 @@ pub fn process_undelegate(
171182 close_pda ( committed_state_record, reimbursement) ?;
172183 close_pda ( delegation_record, reimbursement) ?;
173184 close_pda ( committed_state_account, reimbursement) ?;
174- close_pda ( buffer, payer ) ?;
185+ close_pda ( buffer, authority ) ?;
175186 Ok ( ( ) )
176187}
177188
0 commit comments