satrush-client 0.1.14

Rust client to interact with SatRush's on-chain program.
Documentation
//! satrush-rng addresses the satrush instructions need: the program id, the
//! rotor tags/PDAs, and the remaining-accounts sets for the arming CPIs.
//!
//! Keeper-side instruction builders and the rotor account parser live with
//! the rng program's own SDK (and, for the LiteSVM suite, in this repo's
//! test harness) — a satrush client only ever passes rng accounts through.

use solana_instruction::AccountMeta;
use solana_pubkey::Pubkey;

use crate::builders::SLOT_HASHES_ID;

/// The satrush-rng entropy program (must match its `declare_id!` and the
/// satrush program's `RNG_PROGRAM` constant).
pub const RNG_PROGRAM_ID: Pubkey = Pubkey::from_str_const("SatRngpc6hC9uMXqS4dRk4trqhySktoxMXYSSRbjemd");

/// The rounds rotor tag — PDA `[b"rotor", b"round"]`.
pub const ROUND_ROTOR_TAG: &[u8] = b"round";

/// The epoch draw rotor tag — PDA `[b"rotor", b"epoch"]`.
pub const EPOCH_ROTOR_TAG: &[u8] = b"epoch";

/// The 1 BTC draw rotor tag — PDA `[b"rotor", b"btc"]`.
pub const BTC_ROTOR_TAG: &[u8] = b"btc";

/// The rng program's config singleton, PDA `[b"config"]`.
pub fn get_rng_config_address() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[b"config"], &RNG_PROGRAM_ID)
}

/// A rotor PDA, `[b"rotor", tag]` (the trimmed tag, not the padded array).
pub fn get_rotor_address(tag: &[u8]) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[b"rotor", tag], &RNG_PROGRAM_ID)
}

/// The `[rotor, rng config, rng program, slot hashes sysvar]` accounts the
/// satrush arming instructions expect as remaining accounts, so they can arm
/// the tagged rotor via CPI. The deploy instructions arm the `round` rotor;
/// the epoch trigger/selection arm `epoch`; the one-BTC trigger arms `btc`.
pub fn get_rng_remaining_accounts_for(tag: &[u8]) -> Vec<AccountMeta> {
    vec![
        AccountMeta::new(get_rotor_address(tag).0, false),
        AccountMeta::new_readonly(get_rng_config_address().0, false),
        AccountMeta::new_readonly(RNG_PROGRAM_ID, false),
        AccountMeta::new_readonly(SLOT_HASHES_ID, false),
    ]
}

/// The round-rotor arming accounts the deploy instructions expect.
pub fn get_rng_remaining_accounts() -> Vec<AccountMeta> {
    get_rng_remaining_accounts_for(ROUND_ROTOR_TAG)
}