use solana_program::pubkey::Pubkey;
use crate::constants::*;
pub fn get_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[AUTH_SEED], &PROGRAM_ID)
}
pub fn get_pool_state_pda(base_mint: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[POOL_SEED, base_mint.as_ref(), quote_mint.as_ref()],
&PROGRAM_ID,
)
}
pub fn get_pool_vault_pda(pool_state: &Pubkey, token_mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[POOL_VAULT_SEED, pool_state.as_ref(), token_mint.as_ref()],
&PROGRAM_ID,
)
}
pub fn get_global_config_pda(
quote_token_mint: &Pubkey,
curve_type: u8,
index: u16,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
GLOBAL_CONFIG_SEED,
quote_token_mint.as_ref(),
&[curve_type],
&index.to_le_bytes(),
],
&PROGRAM_ID,
)
}
pub fn get_platform_config_pda(platform_admin: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[PLATFORM_CONFIG_SEED, platform_admin.as_ref()],
&PROGRAM_ID,
)
}
pub fn get_vesting_record_pda(pool_state: &Pubkey, beneficiary: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
POOL_VESTING_SEED,
pool_state.as_ref(),
beneficiary.as_ref(),
],
&PROGRAM_ID,
)
}
pub fn get_event_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &PROGRAM_ID)
}
pub fn get_creator_fee_vault_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[CREATOR_FEE_VAULT_AUTH_SEED], &PROGRAM_ID)
}
pub fn get_creator_fee_vault_pda(creator: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[creator.as_ref(), quote_mint.as_ref()],
&PROGRAM_ID,
)
}
pub fn get_platform_fee_vault_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[PLATFORM_FEE_VAULT_AUTH_SEED], &PROGRAM_ID)
}
pub fn get_platform_fee_vault_pda(platform_config: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[platform_config.as_ref(), quote_mint.as_ref()],
&PROGRAM_ID,
)
}
pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
spl_associated_token_account::get_associated_token_address(owner, mint)
}
pub fn get_associated_token_address_2022(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
spl_associated_token_account::get_associated_token_address_with_program_id(
owner,
mint,
&TOKEN_2022_PROGRAM_ID,
)
}
pub fn get_metadata_address(mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
b"metadata",
METADATA_PROGRAM_ID.as_ref(),
mint.as_ref(),
],
&METADATA_PROGRAM_ID,
)
}
pub fn get_cpswap_vault_pda(cpswap_pool: &Pubkey, token_mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[b"pool_vault", cpswap_pool.as_ref(), token_mint.as_ref()],
&CPSWAP_PROGRAM_ID,
)
}
pub fn get_cpswap_lp_mint_pda(cpswap_pool: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[b"pool_lp_mint", cpswap_pool.as_ref()],
&CPSWAP_PROGRAM_ID,
)
}
pub fn get_cpswap_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(
&[b"vault_and_lp_mint_auth_seed"],
&CPSWAP_PROGRAM_ID,
)
}
pub fn get_cpswap_observation_pda(cpswap_pool: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[b"observation", cpswap_pool.as_ref()],
&CPSWAP_PROGRAM_ID,
)
}
pub fn get_lock_authority_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(
&[b"lock_cp_authority_seed"],
&LOCK_PROGRAM_ID,
)
}