MCPcopy Create free account
hub / github.com/Bonfida/dex-v4 / process

Function process

program/src/processor/close_account.rs:59–86  ·  view source on GitHub ↗
(program_id: &Pubkey, accounts: &[AccountInfo])

Source from the content-addressed store, hash-verified

57}
58
59pub(crate) fn process(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
60 let accounts = Accounts::parse(program_id, accounts)?;
61
62 let mut user_account_data = accounts.user.data.borrow_mut();
63 let user_account = UserAccount::from_buffer(&mut user_account_data)?;
64 if &user_account.header.owner != accounts.user_owner.key {
65 msg!("Invalid user account owner provided!");
66 return Err(ProgramError::InvalidArgument);
67 };
68
69 if user_account.header.number_of_orders != 0
70 || user_account.header.quote_token_free != 0
71 || user_account.header.base_token_free != 0
72 {
73 msg!("The user account cannot be closed as it has pending orders or unsettled funds");
74 return Err(DexError::UserAccountStillActive.into());
75 }
76
77 user_account.header.tag = AccountTag::Closed as u64;
78
79 let mut lamports = accounts.user.lamports.borrow_mut();
80 let mut target_lamports = accounts.target_lamports_account.lamports.borrow_mut();
81
82 **target_lamports += **lamports;
83 **lamports = 0;
84
85 Ok(())
86}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected