bucks-api 0.2.0

White label stablecoin launchpad
Documentation
mod position;
mod protocol;
mod stable;
mod vault;

pub use position::*;
pub use protocol::*;
pub use stable::*;
pub use vault::*;

use crate::consts::*;

use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum BucksAccount {
    Stable = 100,
    Vault = 101,
    ProtocolRegistry = 102,
    StableProtocolPosition = 103,
}

/// Derives the Stable account PDA from a stablecoin mint.
pub fn stable_pda(mint: Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[STABLE, mint.as_ref()], &crate::ID)
}

/// Derives the global Vault account PDA.
pub fn vault_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[VAULT], &crate::ID)
}

/// Derives the ProtocolRegistry account PDA for a given protocol ID.
pub fn protocol_pda(protocol_id: u8) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[PROTOCOL, &[protocol_id]], &crate::ID)
}

/// Derives the StableProtocolPosition account PDA for a stable's position in a protocol.
pub fn position_pda(stable: Pubkey, protocol_id: u8) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[POSITION, stable.as_ref(), &[protocol_id]], &crate::ID)
}