Skip to main content

bucks_api/state/
mod.rs

1mod position;
2mod protocol;
3mod stable;
4mod vault;
5
6pub use position::*;
7pub use protocol::*;
8pub use stable::*;
9pub use vault::*;
10
11use crate::consts::*;
12
13use steel::*;
14
15#[repr(u8)]
16#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
17pub enum BucksAccount {
18    Stable = 100,
19    Vault = 101,
20    ProtocolRegistry = 102,
21    StableProtocolPosition = 103,
22}
23
24/// Derives the Stable account PDA from a stablecoin mint.
25pub fn stable_pda(mint: Pubkey) -> (Pubkey, u8) {
26    Pubkey::find_program_address(&[STABLE, mint.as_ref()], &crate::ID)
27}
28
29/// Derives the global Vault account PDA.
30pub fn vault_pda() -> (Pubkey, u8) {
31    Pubkey::find_program_address(&[VAULT], &crate::ID)
32}
33
34/// Derives the ProtocolRegistry account PDA for a given protocol ID.
35pub fn protocol_pda(protocol_id: u8) -> (Pubkey, u8) {
36    Pubkey::find_program_address(&[PROTOCOL, &[protocol_id]], &crate::ID)
37}
38
39/// Derives the StableProtocolPosition account PDA for a stable's position in a protocol.
40pub fn position_pda(stable: Pubkey, protocol_id: u8) -> (Pubkey, u8) {
41    Pubkey::find_program_address(&[POSITION, stable.as_ref(), &[protocol_id]], &crate::ID)
42}