Skip to main content

kvault_interface/
pda.rs

1//! PDA derivation helpers for Kvault accounts.
2//!
3//! Each function calls [`Pubkey::find_program_address`] with the documented
4//! seeds and returns `(address, bump)`.
5
6use solana_pubkey::Pubkey;
7
8/// Seed for the vault authority PDA.
9pub const BASE_VAULT_AUTHORITY_SEED: &[u8] = b"authority";
10/// Seed for the token vault PDA.
11pub const TOKEN_VAULT_SEED: &[u8] = b"token_vault";
12/// Seed for the shares mint PDA.
13pub const SHARES_SEED: &[u8] = b"shares";
14/// Seed for per-reserve cToken vault PDAs.
15pub const CTOKEN_VAULT_SEED: &[u8] = b"ctoken_vault";
16/// Seed for the global config PDA.
17pub const GLOBAL_CONFIG_SEED: &[u8] = b"global_config";
18/// Seed for reserve whitelist entry PDAs.
19pub const WHITELISTED_RESERVES_SEED: &[u8] = b"whitelisted_reserves";
20/// Seed for the Anchor event authority PDA.
21pub const EVENT_AUTHORITY: &[u8] = b"__event_authority";
22
23/// Vault authority PDA that signs CPI calls on behalf of the vault.
24///
25/// Seeds: `[b"authority", vault_state]`.
26pub fn base_vault_authority(program_id: &Pubkey, vault_state: &Pubkey) -> (Pubkey, u8) {
27    Pubkey::find_program_address(
28        &[BASE_VAULT_AUTHORITY_SEED, vault_state.as_ref()],
29        program_id,
30    )
31}
32
33/// Token account holding the vault's uninvested liquidity.
34///
35/// Seeds: `[b"token_vault", vault_state]`.
36pub fn token_vault(program_id: &Pubkey, vault_state: &Pubkey) -> (Pubkey, u8) {
37    Pubkey::find_program_address(&[TOKEN_VAULT_SEED, vault_state.as_ref()], program_id)
38}
39
40/// SPL mint for vault share tokens issued to depositors.
41///
42/// Seeds: `[b"shares", vault_state]`.
43pub fn shares_mint(program_id: &Pubkey, vault_state: &Pubkey) -> (Pubkey, u8) {
44    Pubkey::find_program_address(&[SHARES_SEED, vault_state.as_ref()], program_id)
45}
46
47/// Token account holding cTokens received from a specific Klend reserve.
48///
49/// Seeds: `[b"ctoken_vault", vault_state, reserve]`.
50pub fn ctoken_vault(program_id: &Pubkey, vault_state: &Pubkey, reserve: &Pubkey) -> (Pubkey, u8) {
51    Pubkey::find_program_address(
52        &[CTOKEN_VAULT_SEED, vault_state.as_ref(), reserve.as_ref()],
53        program_id,
54    )
55}
56
57/// System-wide vault configuration account.
58///
59/// Seeds: `[b"global_config"]`.
60pub fn global_config(program_id: &Pubkey) -> (Pubkey, u8) {
61    Pubkey::find_program_address(&[GLOBAL_CONFIG_SEED], program_id)
62}
63
64/// Whitelist entry PDA for a specific Klend reserve.
65///
66/// Seeds: `[b"whitelisted_reserves", reserve]`.
67pub fn whitelisted_reserve(program_id: &Pubkey, reserve: &Pubkey) -> (Pubkey, u8) {
68    Pubkey::find_program_address(&[WHITELISTED_RESERVES_SEED, reserve.as_ref()], program_id)
69}
70
71/// Anchor event authority PDA (used for `event_cpi` accounts).
72///
73/// Seeds: `[b"__event_authority"]`.
74pub fn event_authority(program_id: &Pubkey) -> (Pubkey, u8) {
75    Pubkey::find_program_address(&[EVENT_AUTHORITY], program_id)
76}