Skip to main content

cow_primitives/
lib.rs

1//! `cow-primitives` — Layer 0 foundational constants for the `CoW` Protocol SDK.
2//!
3//! This crate sits at the bottom of the workspace DAG and has **no internal
4//! dependencies**. It exposes:
5//!
6//! - Numeric constants (`ZERO`, `ONE`, `MAX_UINT256`, `ONE_HUNDRED_BPS`, ...)
7//! - The zero address and zero hash helpers
8//! - Near Intents attestation constants
9//!
10//! Protocol enums (`OrderKind`, `SigningScheme`, `TokenBalance`, ...) live in
11//! [`cow-types`](https://docs.rs/cow-types) (Layer 1) because their
12//! `TryFrom<&str>` impls depend on [`cow-errors`](https://docs.rs/cow-errors).
13
14#![deny(unsafe_code)]
15#![warn(missing_docs)]
16
17use alloy_primitives::{Address, U256};
18
19// ── Common constants ────────────────────────────────────────────────────────
20
21/// The zero address (`0x0000…0000`).
22pub const ZERO_ADDRESS: Address = Address::ZERO;
23
24/// The 32-byte zero hash.
25pub const ZERO_HASH: &str = "0x0000000000000000000000000000000000000000000000000000000000000000";
26
27/// `U256` zero.
28pub const ZERO: U256 = U256::ZERO;
29
30/// `U256` one.
31pub const ONE: U256 = U256::from_limbs([1, 0, 0, 0]);
32
33/// Maximum `u32` value as a `U256` (2^32 - 1 = 4 294 967 295).
34pub const MAX_UINT32: U256 = U256::from_limbs([u32::MAX as u64, 0, 0, 0]);
35
36/// Maximum `U256` value (2^256 - 1).
37pub const MAX_UINT256: U256 = U256::MAX;
38
39/// Scale factor: 100 000.
40pub const HUNDRED_THOUSANDS: u64 = 100_000;
41
42/// One hundred basis points expressed as a `U256` (100 * 100 = 10 000).
43pub const ONE_HUNDRED_BPS: u64 = 10_000;
44
45/// Maximum concurrent requests to the `CoW` Protocol API.
46pub const LIMIT_CONCURRENT_REQUESTS: u32 = 5;
47
48/// Near Intents attestation prefix constant.
49pub const ATTESTATION_PREFIX_CONST: &str = "0x0a773570";
50
51/// Near Intents attestation version byte.
52pub const ATTESTION_VERSION_BYTE: &str = "0x00";
53
54/// Near Intents attestator address.
55///
56/// `0x0073DD100b51C555E41B2a452E5933ef76F42790`
57pub const ATTESTATOR_ADDRESS: Address = Address::new([
58    0x00, 0x73, 0xdd, 0x10, 0x0b, 0x51, 0xc5, 0x55, 0xe4, 0x1b, 0x2a, 0x45, 0x2e, 0x59, 0x33, 0xef,
59    0x76, 0xf4, 0x27, 0x90,
60]);
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn constants_are_correct() {
68        assert!(ZERO_ADDRESS.is_zero());
69        assert_eq!(ZERO, U256::ZERO);
70        assert_eq!(ONE, U256::from(1));
71        assert_eq!(MAX_UINT32, U256::from(u32::MAX));
72        assert_eq!(MAX_UINT256, U256::MAX);
73        assert_eq!(ONE_HUNDRED_BPS, 10_000);
74        assert_eq!(HUNDRED_THOUSANDS, 100_000);
75        assert_eq!(LIMIT_CONCURRENT_REQUESTS, 5);
76    }
77
78    #[test]
79    fn zero_hash_is_correct_length() {
80        assert_eq!(ZERO_HASH.len(), 66); // "0x" + 64 hex chars
81        assert!(ZERO_HASH.starts_with("0x"));
82    }
83
84    #[test]
85    fn attestator_address_is_nonzero() {
86        assert!(!ATTESTATOR_ADDRESS.is_zero());
87    }
88}