valiant_vortex_client 0.2.1

Rust client to interact with Valiant's on-chain Vortex program.
Documentation
use crate::generated::programs::VORTEX_ID;
use solana_program::program_error::ProgramError;
use solana_program::pubkey::Pubkey;

pub fn get_token_badge_address(
    vortex_config: &Pubkey,
    token_mint: &Pubkey,
) -> Result<(Pubkey, u8), ProgramError> {
    let seeds = &[b"token_badge", vortex_config.as_ref(), token_mint.as_ref()];

    Pubkey::try_find_program_address(seeds, &VORTEX_ID).ok_or(ProgramError::InvalidSeeds)
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::str::FromStr;

    #[test]
    fn test_get_token_badge_address() {
        let vortex_config =
            Pubkey::from_str("7BRUr84e48Zh6PoFLQxfd8bvMdYQ2CgHXWczDsTqLhy6").unwrap();
        let token_mint = Pubkey::from_str("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo").unwrap();
        let token_badge = Pubkey::from_str("HWErrqQNvkLCKPhGPuuWiiGiGzpjJngnk3k7gQw45dWg").unwrap();
        let (address, _) = get_token_badge_address(&vortex_config, &token_mint).unwrap();
        assert_eq!(address, token_badge);
    }
}