-
Notifications
You must be signed in to change notification settings - Fork 3
/
new.rs
62 lines (57 loc) · 1.86 KB
/
new.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
52
53
54
55
56
57
58
59
60
61
62
use ore_boost_api::{
consts::BOOST,
instruction::New,
state::{Boost, Config},
};
use solana_program::system_program;
use steel::*;
/// New creates a new boost.
pub fn process_new(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
// Parse args.
let args = New::try_from_bytes(data)?;
let multiplier = u64::from_le_bytes(args.multiplier);
let expires_at = i64::from_le_bytes(args.expires_at);
// Load accounts.
let [signer_info, boost_info, boost_tokens_info, config_info, mint_info, system_program, token_program, associated_token_program] =
accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
boost_info
.is_writable()?
.is_empty()?
.has_seeds(&[BOOST, mint_info.key.as_ref()], &ore_boost_api::id())?;
boost_tokens_info.is_writable()?.is_empty()?;
config_info
.as_account::<Config>(&ore_boost_api::ID)?
.assert(|c| c.authority == *signer_info.key)?;
mint_info.as_mint()?;
system_program.is_program(&system_program::ID)?;
token_program.is_program(&spl_token::ID)?;
associated_token_program.is_program(&spl_associated_token_account::ID)?;
// Initialize the boost account.
create_account::<Boost>(
boost_info,
system_program,
signer_info,
&ore_boost_api::id(),
&[BOOST, mint_info.key.as_ref()],
)?;
let boost = boost_info.as_account_mut::<Boost>(&ore_boost_api::ID)?;
boost.mint = *mint_info.key;
boost.expires_at = expires_at;
boost.multiplier = multiplier;
boost.total_stake = 0;
// Create boost token account.
create_associated_token_account(
signer_info,
boost_info,
boost_tokens_info,
mint_info,
system_program,
token_program,
associated_token_program,
)?;
Ok(())
}