-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinalize.rs
51 lines (48 loc) · 1.64 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
42
43
44
45
46
47
48
49
50
51
use crate::context::{VESTING_CONFIG_SEED, CONFIG_SEED};
use crate::error::VestingError;
use crate::state::VestingConfig;
use anchor_lang::prelude::*;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use crate::state::global_config::GlobalConfig;
#[derive(Accounts)]
pub struct Finalize<'info> {
#[account(
mut,
constraint = global_config.vesting_admin == admin.key()
@ VestingError::InvalidVestingAdmin
)]
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(), mint.key().as_ref(), config.seed.to_le_bytes().as_ref()],
bump = config.bump
)]
config: Account<'info, VestingConfig>,
#[account(
seeds = [CONFIG_SEED.as_bytes()],
bump = global_config.bump,
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
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(())
}
}