Skip to main content

cow_settlement_interface/
lib.rs

1//! Shared types and instruction builders for the CoW Protocol settlement program.
2
3pub use solana_instruction::{AccountMeta, Instruction};
4pub use solana_pubkey::Pubkey;
5
6solana_pubkey::declare_id!("C7PXyLpLQBh3Ce7e9DNj3rDVUvwqa5orDwQG5hs1rfNi");
7
8pub mod data;
9pub mod error;
10pub mod instruction;
11pub mod pda;
12pub mod role;
13pub mod token_program;
14
15pub use error::SettlementError;
16pub use instruction::{recover_discriminator, SettlementInstruction};
17pub use pda::SettlementAccount;
18pub use role::Role;
19
20/// Test fixtures for building settlement values with stable, readable
21/// addresses. Exposed under the `test-fixtures` feature (and unconditionally
22/// for this crate's own `cargo test`) so other crates can reuse them.
23#[cfg(any(test, feature = "test-fixtures"))]
24pub mod fixtures {
25    use std::sync::LazyLock;
26
27    use crate::pda::state::state_pda_seeds;
28    use crate::Pubkey;
29
30    /// Deterministically generate a [`Pubkey`] by hashing a seed string, for
31    /// building fixtures with stable, readable addresses.
32    pub fn pubkey_from_seed(seed: &str) -> Pubkey {
33        Pubkey::new_from_array(solana_sha256_hasher::hash(seed.as_bytes()).to_bytes())
34    }
35
36    /// A deterministic stand-in program id shared by handler tests, so each
37    /// doesn't define its own. This is an arbitrary placeholder, not the
38    /// declared on-chain id.
39    pub static PROGRAM_ID: LazyLock<Pubkey> = LazyLock::new(|| pubkey_from_seed("program id"));
40
41    /// The canonical settlement state PDA for [`PROGRAM_ID`], shared so handler
42    /// tests don't each re-derive it.
43    pub static STATE_PDA: LazyLock<Pubkey> =
44        LazyLock::new(|| Pubkey::find_program_address(&state_pda_seeds(), &PROGRAM_ID).0);
45}