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!("Moook87DzJ25dELx3LXJ3dnu5a4ERVFwKo1PWWF4p7Y");
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 core::num::NonZeroU64;
26
27    use crate::Pubkey;
28
29    /// Deterministically generate a [`Pubkey`] by hashing a seed string, for
30    /// building fixtures with stable, readable addresses.
31    pub fn pubkey_from_seed(seed: &str) -> Pubkey {
32        Pubkey::new_from_array(solana_sha256_hasher::hash(seed.as_bytes()).to_bytes())
33    }
34
35    /// Wrap a known-non-zero `u64` in a [`NonZeroU64`], as `amount.nz()`.
36    /// Used to make test code shorter.
37    pub trait IntoNonZero {
38        fn nz(self) -> NonZeroU64;
39    }
40
41    impl IntoNonZero for u64 {
42        #[track_caller]
43        fn nz(self) -> NonZeroU64 {
44            NonZeroU64::new(self).expect("value must be non-zero")
45        }
46    }
47}