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
8/// Program address of the production settlement deployment.
9pub const PROD_ID: Pubkey = ID;
10
11/// Program address of the staging ("barn") settlement deployment.
12pub const BARN_ID: Pubkey = Pubkey::from_str_const("EzHqcdJssenE2R8xogJ8wpL66PRQet9M6ubpsX4QxpPb");
13
14pub mod data;
15pub mod error;
16pub mod instruction;
17pub mod pda;
18pub mod role;
19pub mod token_program;
20
21pub use error::{parse_settlement_error, SettlementError};
22pub use instruction::{recover_discriminator, SettlementInstruction};
23pub use pda::SettlementAccount;
24pub use role::Role;
25
26/// Test fixtures for building settlement values with stable, readable
27/// addresses. Exposed under the `test-fixtures` feature (and unconditionally
28/// for this crate's own `cargo test`) so other crates can reuse them.
29#[cfg(any(test, feature = "test-fixtures"))]
30pub mod fixtures {
31    use core::num::NonZeroU64;
32
33    use crate::Pubkey;
34
35    /// Deterministically generate a [`Pubkey`] by hashing a seed string, for
36    /// building fixtures with stable, readable addresses.
37    pub fn pubkey_from_seed(seed: &str) -> Pubkey {
38        Pubkey::new_from_array(solana_sha256_hasher::hash(seed.as_bytes()).to_bytes())
39    }
40
41    /// Wrap a known-non-zero `u64` in a [`NonZeroU64`], as `amount.nz()`.
42    /// Used to make test code shorter.
43    pub trait IntoNonZero {
44        fn nz(self) -> NonZeroU64;
45    }
46
47    impl IntoNonZero for u64 {
48        #[track_caller]
49        fn nz(self) -> NonZeroU64 {
50            NonZeroU64::new(self).expect("value must be non-zero")
51        }
52    }
53}