Skip to main content

spl_single_pool/
lib.rs

1#![deny(missing_docs)]
2
3//! A program for liquid staking with a single validator
4
5pub mod error;
6pub mod inline_mpl_token_metadata;
7pub mod instruction;
8pub mod processor;
9pub mod state;
10
11#[cfg(not(feature = "no-entrypoint"))]
12pub mod entrypoint;
13
14use {solana_native_token::LAMPORTS_PER_SOL, solana_pubkey::Pubkey};
15
16solana_pubkey::declare_id!("SVSPxpvHdN29nkVg9rPapPNDddN5DipNLRUFhyjFThE");
17
18const POOL_PREFIX: &[u8] = b"pool";
19const POOL_STAKE_PREFIX: &[u8] = b"stake";
20const POOL_ONRAMP_PREFIX: &[u8] = b"onramp";
21const POOL_MINT_PREFIX: &[u8] = b"mint";
22const POOL_MINT_AUTHORITY_PREFIX: &[u8] = b"mint_authority";
23const POOL_STAKE_AUTHORITY_PREFIX: &[u8] = b"stake_authority";
24const POOL_MPL_AUTHORITY_PREFIX: &[u8] = b"mpl_authority";
25
26const PHANTOM_TOKEN_AMOUNT: u64 = LAMPORTS_PER_SOL;
27const MINT_DECIMALS: u8 = 9;
28const PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH: Option<u64> = Some(0);
29
30const VOTE_STATE_DISCRIMINATOR_END: usize = 4;
31const VOTE_STATE_AUTHORIZED_WITHDRAWER_START: usize = 36;
32const VOTE_STATE_AUTHORIZED_WITHDRAWER_END: usize = 68;
33
34fn find_pool_address_and_bump(program_id: &Pubkey, vote_account_address: &Pubkey) -> (Pubkey, u8) {
35    Pubkey::find_program_address(&[POOL_PREFIX, vote_account_address.as_ref()], program_id)
36}
37
38fn find_pool_stake_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
39    Pubkey::find_program_address(&[POOL_STAKE_PREFIX, pool_address.as_ref()], program_id)
40}
41
42fn find_pool_onramp_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
43    Pubkey::find_program_address(&[POOL_ONRAMP_PREFIX, pool_address.as_ref()], program_id)
44}
45
46fn find_pool_mint_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
47    Pubkey::find_program_address(&[POOL_MINT_PREFIX, pool_address.as_ref()], program_id)
48}
49
50fn find_pool_stake_authority_address_and_bump(
51    program_id: &Pubkey,
52    pool_address: &Pubkey,
53) -> (Pubkey, u8) {
54    Pubkey::find_program_address(
55        &[POOL_STAKE_AUTHORITY_PREFIX, pool_address.as_ref()],
56        program_id,
57    )
58}
59
60fn find_pool_mint_authority_address_and_bump(
61    program_id: &Pubkey,
62    pool_address: &Pubkey,
63) -> (Pubkey, u8) {
64    Pubkey::find_program_address(
65        &[POOL_MINT_AUTHORITY_PREFIX, pool_address.as_ref()],
66        program_id,
67    )
68}
69
70fn find_pool_mpl_authority_address_and_bump(
71    program_id: &Pubkey,
72    pool_address: &Pubkey,
73) -> (Pubkey, u8) {
74    Pubkey::find_program_address(
75        &[POOL_MPL_AUTHORITY_PREFIX, pool_address.as_ref()],
76        program_id,
77    )
78}
79
80/// Find the canonical pool address for a given vote account.
81pub fn find_pool_address(program_id: &Pubkey, vote_account_address: &Pubkey) -> Pubkey {
82    find_pool_address_and_bump(program_id, vote_account_address).0
83}
84
85/// Find the canonical main stake account address for a given pool account.
86pub fn find_pool_stake_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
87    find_pool_stake_address_and_bump(program_id, pool_address).0
88}
89
90/// Find the canonical stake on-ramp account address for a given pool account.
91pub fn find_pool_onramp_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
92    find_pool_onramp_address_and_bump(program_id, pool_address).0
93}
94
95/// Find the canonical token mint address for a given pool account.
96pub fn find_pool_mint_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
97    find_pool_mint_address_and_bump(program_id, pool_address).0
98}
99
100/// Find the canonical stake authority address for a given pool account.
101pub fn find_pool_stake_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
102    find_pool_stake_authority_address_and_bump(program_id, pool_address).0
103}
104
105/// Find the canonical mint authority address for a given pool account.
106pub fn find_pool_mint_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
107    find_pool_mint_authority_address_and_bump(program_id, pool_address).0
108}
109
110/// Find the canonical MPL authority address for a given pool account.
111pub fn find_pool_mpl_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
112    find_pool_mpl_authority_address_and_bump(program_id, pool_address).0
113}