use anchor_lang::{Key, prelude::Pubkey};

use super::LIQUIDITY_PROGRAM_ID;

pub fn get_liquidity() -> Pubkey {
    Pubkey::find_program_address(&[b"liquidity"], &LIQUIDITY_PROGRAM_ID).0
}

pub fn get_token_reserve(asset: Pubkey) -> Pubkey {
    Pubkey::find_program_address(&[b"reserve", asset.key().as_ref()], &LIQUIDITY_PROGRAM_ID).0
}

pub fn get_user_supply_position(asset: Pubkey, protocol: Pubkey) -> Pubkey {
    Pubkey::find_program_address(
        &[
            b"user_supply_position",
            asset.key().as_ref(),
            protocol.key().as_ref(),
        ],
        &LIQUIDITY_PROGRAM_ID,
    )
    .0
}

pub fn get_user_borrow_position(asset: Pubkey, protocol: Pubkey) -> Pubkey {
    Pubkey::find_program_address(
        &[
            b"user_borrow_position",
            asset.key().as_ref(),
            protocol.key().as_ref(),
        ],
        &LIQUIDITY_PROGRAM_ID,
    )
    .0
}

pub fn get_user_claim_account(asset: Pubkey, user: Pubkey) -> Pubkey {
    Pubkey::find_program_address(
        &[b"user_claim", asset.key().as_ref(), user.key().as_ref()],
        &LIQUIDITY_PROGRAM_ID,
    )
    .0
}

pub fn get_rate_model(asset: Pubkey) -> Pubkey {
    Pubkey::find_program_address(
        &[b"rate_model", asset.key().as_ref()],
        &LIQUIDITY_PROGRAM_ID,
    )
    .0
}
