Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: closing account after unlocking #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,28 @@ impl Processor {
&mut packed_state.borrow_mut()[VestingScheduleHeader::LEN..],
);

// Create the close account instruction (refunding rent to destination account)
let close_account_instruction = spl_token::instruction::close_account(
&spl_token_account.key,
&vesting_token_account.key,
&destination_token_account.key, // Send rent back to this account
&vesting_account_key,
&[],
)?;

// Invoke the close account instruction
invoke_signed(
&close_account_instruction,
&[
spl_token_account.clone(),
vesting_token_account.clone(),
destination_token_account.clone(),
vesting_account.clone(),
],
&[&[&seeds]],
)?;
msg!("Vesting account successfully closed and rent refunded.");

Ok(())
}

Expand Down Expand Up @@ -343,7 +365,7 @@ impl Processor {
msg!("Shouldn't initialize withdrawal for already initialized schedule");
return Err(ProgramError::InvalidArgument);
}

// Withdrawal period is 7 days = 7 * 86400 = 604_800
schedule.release_time = clock.unix_timestamp as u64 + 604_800;

Expand Down
Loading