use tycho_common::{
models::{token::Token, Chain},
Bytes,
};
use crate::protocol::models::ProtocolComponent;
pub fn pair_component_id(protocol_system: &str, base: &Bytes, quote: &Bytes) -> Bytes {
Bytes::from([protocol_system.as_bytes(), base, quote].concat())
}
#[expect(
dead_code,
reason = "nothing in this crate implements a book feed yet; the layer is exercised by its own tests"
)]
pub fn pair_component(
id: Bytes,
protocol_system: impl Into<String>,
protocol_type: impl Into<String>,
chain: Chain,
base: Token,
quote: Token,
) -> ProtocolComponent {
ProtocolComponent::new(
id,
protocol_system.into(),
protocol_type.into(),
chain,
vec![base, quote],
vec![],
Default::default(),
Default::default(),
Default::default(),
)
}
#[cfg(test)]
mod tests {
use super::*;
fn addr(byte: u8) -> Bytes {
Bytes::from(vec![byte; 20])
}
#[test]
fn the_id_is_the_protocol_system_followed_by_the_two_addresses() {
let id = pair_component_id("book:venue", &addr(0x11), &addr(0x22));
assert_eq!(
id.to_string(),
"0x626f6f6b3a76656e7565\
1111111111111111111111111111111111111111\
2222222222222222222222222222222222222222"
);
}
#[test]
fn the_id_distinguishes_orientation_and_venue() {
let (a, b) = (addr(1), addr(2));
assert_ne!(pair_component_id("book:v", &a, &b), pair_component_id("book:v", &b, &a));
assert_ne!(pair_component_id("book:v", &a, &b), pair_component_id("v", &a, &b));
}
}