use crate::clob::constants::{AMOY, POLYGON};
pub const CLOB_API_URL: &str = "https://clob.polymarket.com";
pub const CLOB_TESTNET_API_URL: &str = "https://clob-testnet.polymarket.com";
#[derive(Debug, Clone)]
pub struct ClobConfig {
pub host: String,
pub chain_id: u64,
pub funder: Option<String>,
pub signature_type: u8,
}
impl ClobConfig {
pub fn new_mainnet() -> Self {
Self {
host: CLOB_API_URL.to_string(),
chain_id: POLYGON,
funder: None,
signature_type: 0,
}
}
pub fn new_testnet() -> Self {
Self {
host: CLOB_TESTNET_API_URL.to_string(),
chain_id: AMOY,
funder: None,
signature_type: 0,
}
}
pub fn new(host: impl Into<String>, chain_id: u64) -> Self {
Self {
host: host.into(),
chain_id,
funder: None,
signature_type: 0,
}
}
pub fn with_funder(mut self, funder: impl Into<String>) -> Self {
self.funder = Some(funder.into());
self
}
pub fn with_signature_type(mut self, signature_type: u8) -> Self {
self.signature_type = signature_type;
self
}
}
impl Default for ClobConfig {
fn default() -> Self {
Self::new_mainnet()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mainnet_config() {
let config = ClobConfig::new_mainnet();
assert_eq!(config.host, CLOB_API_URL);
assert_eq!(config.chain_id, POLYGON);
assert_eq!(config.signature_type, 0);
assert!(config.funder.is_none());
}
#[test]
fn test_testnet_config() {
let config = ClobConfig::new_testnet();
assert_eq!(config.host, CLOB_TESTNET_API_URL);
assert_eq!(config.chain_id, AMOY);
assert_eq!(config.signature_type, 0);
assert!(config.funder.is_none());
}
#[test]
fn test_custom_config() {
let config = ClobConfig::new("https://custom.api", 1337);
assert_eq!(config.host, "https://custom.api");
assert_eq!(config.chain_id, 1337);
}
#[test]
fn test_with_funder() {
let config = ClobConfig::new_mainnet()
.with_funder("0x1234567890123456789012345678901234567890");
assert_eq!(config.funder.as_ref().unwrap(), "0x1234567890123456789012345678901234567890");
}
#[test]
fn test_with_signature_type() {
let config = ClobConfig::new_mainnet().with_signature_type(1);
assert_eq!(config.signature_type, 1);
}
#[test]
fn test_default_config() {
let config = ClobConfig::default();
assert_eq!(config.host, CLOB_API_URL);
assert_eq!(config.chain_id, POLYGON);
}
}