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
18/// Fee charged for the `DepositSol` instruction. This fee may be adjusted down in
19/// the future depending on how `DepositSol` is used in practice. Care should be
20/// taken if using this number for calculations in third-party libraries or programs,
21/// as it is not guaranteed to remain at this value.
22pub const DEPOSIT_SOL_FEE_BPS: u64 = 100;
23const MAX_BPS: u64 = 10_000;
24
25const POOL_PREFIX: &[u8] = b"pool";
26const POOL_STAKE_PREFIX: &[u8] = b"stake";
27const POOL_ONRAMP_PREFIX: &[u8] = b"onramp";
28const POOL_MINT_PREFIX: &[u8] = b"mint";
29const POOL_MINT_AUTHORITY_PREFIX: &[u8] = b"mint_authority";
30const POOL_STAKE_AUTHORITY_PREFIX: &[u8] = b"stake_authority";
31const POOL_MPL_AUTHORITY_PREFIX: &[u8] = b"mpl_authority";
32
33const PHANTOM_TOKEN_AMOUNT: u64 = LAMPORTS_PER_SOL;
34const MINT_DECIMALS: u8 = 9;
35const PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH: Option<u64> = Some(0);
36
37const VOTE_STATE_DISCRIMINATOR_END: usize = 4;
38const VOTE_STATE_AUTHORIZED_WITHDRAWER_START: usize = 36;
39const VOTE_STATE_AUTHORIZED_WITHDRAWER_END: usize = 68;
40
41fn find_pool_address_and_bump(program_id: &Pubkey, vote_account_address: &Pubkey) -> (Pubkey, u8) {
42    Pubkey::find_program_address(&[POOL_PREFIX, vote_account_address.as_ref()], program_id)
43}
44
45fn find_pool_stake_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
46    Pubkey::find_program_address(&[POOL_STAKE_PREFIX, pool_address.as_ref()], program_id)
47}
48
49fn find_pool_onramp_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
50    Pubkey::find_program_address(&[POOL_ONRAMP_PREFIX, pool_address.as_ref()], program_id)
51}
52
53fn find_pool_mint_address_and_bump(program_id: &Pubkey, pool_address: &Pubkey) -> (Pubkey, u8) {
54    Pubkey::find_program_address(&[POOL_MINT_PREFIX, pool_address.as_ref()], program_id)
55}
56
57fn find_pool_stake_authority_address_and_bump(
58    program_id: &Pubkey,
59    pool_address: &Pubkey,
60) -> (Pubkey, u8) {
61    Pubkey::find_program_address(
62        &[POOL_STAKE_AUTHORITY_PREFIX, pool_address.as_ref()],
63        program_id,
64    )
65}
66
67fn find_pool_mint_authority_address_and_bump(
68    program_id: &Pubkey,
69    pool_address: &Pubkey,
70) -> (Pubkey, u8) {
71    Pubkey::find_program_address(
72        &[POOL_MINT_AUTHORITY_PREFIX, pool_address.as_ref()],
73        program_id,
74    )
75}
76
77fn find_pool_mpl_authority_address_and_bump(
78    program_id: &Pubkey,
79    pool_address: &Pubkey,
80) -> (Pubkey, u8) {
81    Pubkey::find_program_address(
82        &[POOL_MPL_AUTHORITY_PREFIX, pool_address.as_ref()],
83        program_id,
84    )
85}
86
87/// Find the canonical pool address for a given vote account.
88pub fn find_pool_address(program_id: &Pubkey, vote_account_address: &Pubkey) -> Pubkey {
89    find_pool_address_and_bump(program_id, vote_account_address).0
90}
91
92/// Find the canonical main stake account address for a given pool account.
93pub fn find_pool_stake_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
94    find_pool_stake_address_and_bump(program_id, pool_address).0
95}
96
97/// Find the canonical stake on-ramp account address for a given pool account.
98pub fn find_pool_onramp_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
99    find_pool_onramp_address_and_bump(program_id, pool_address).0
100}
101
102/// Find the canonical token mint address for a given pool account.
103pub fn find_pool_mint_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
104    find_pool_mint_address_and_bump(program_id, pool_address).0
105}
106
107/// Find the canonical stake authority address for a given pool account.
108pub fn find_pool_stake_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
109    find_pool_stake_authority_address_and_bump(program_id, pool_address).0
110}
111
112/// Find the canonical mint authority address for a given pool account.
113pub fn find_pool_mint_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
114    find_pool_mint_authority_address_and_bump(program_id, pool_address).0
115}
116
117/// Find the canonical MPL authority address for a given pool account.
118pub fn find_pool_mpl_authority_address(program_id: &Pubkey, pool_address: &Pubkey) -> Pubkey {
119    find_pool_mpl_authority_address_and_bump(program_id, pool_address).0
120}