-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinalize.rs
41 lines (38 loc) · 1.32 KB
/
finalize.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::context::VESTING_CONFIG_SEED;
use crate::error::VestingError;
use crate::state::VestingConfig;
use anchor_lang::prelude::*;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
#[derive(Accounts)]
pub struct Finalize<'info> {
#[account(mut)]
pub admin: Signer<'info>,
pub mint: InterfaceAccount<'info, Mint>,
// Initialize a vault for us to store our money in escrow for vesting
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = config,
associated_token::token_program = token_program
)]
vault: InterfaceAccount<'info, TokenAccount>,
// Initialize a vesting config for a specific admin, mint and seed
#[account(
mut,
constraint = !config.finalized @ VestingError::VestingFinalized,
seeds = [VESTING_CONFIG_SEED.as_bytes(), admin.key().as_ref(), mint.key().as_ref(), config.seed.to_le_bytes().as_ref()],
bump = config.bump
)]
config: Account<'info, VestingConfig>,
token_program: Interface<'info, TokenInterface>,
}
impl<'info> Finalize<'info> {
pub fn finalize(&mut self) -> Result<()> {
require!(
self.vault.amount >= self.config.vested,
VestingError::VestedBalanceMismatch
);
self.config.finalized = true;
Ok(())
}
}