use std::collections::HashSet;
use tokio::time::Duration;
use tycho_common::{models::Chain, Bytes};
use super::client::BebopClient;
use crate::rfq::{errors::RFQError, protocols::utils::default_quote_tokens_for_chain};
pub struct BebopClientBuilder {
chain: Chain,
ws_user: String,
ws_key: String,
tokens: HashSet<Bytes>,
tvl: f64,
quote_tokens: Option<HashSet<Bytes>>,
quote_timeout: Duration,
}
impl BebopClientBuilder {
pub fn new(chain: Chain, ws_user: String, ws_key: String) -> Self {
Self {
chain,
ws_user,
ws_key,
tokens: HashSet::new(),
tvl: 100.0, quote_tokens: None,
quote_timeout: Duration::from_secs(5), }
}
pub fn tokens(mut self, tokens: HashSet<Bytes>) -> Self {
self.tokens = tokens;
self
}
pub fn tvl_threshold(mut self, tvl: f64) -> Self {
self.tvl = tvl;
self
}
pub fn quote_tokens(mut self, quote_tokens: HashSet<Bytes>) -> Self {
self.quote_tokens = Some(quote_tokens);
self
}
pub fn quote_timeout(mut self, timeout: Duration) -> Self {
self.quote_timeout = timeout;
self
}
pub fn build(self) -> Result<BebopClient, RFQError> {
let quote_tokens;
if let Some(tokens) = self.quote_tokens {
quote_tokens = tokens;
} else {
quote_tokens = default_quote_tokens_for_chain(&self.chain)?
}
BebopClient::new(
self.chain,
self.tokens,
self.tvl,
self.ws_user,
self.ws_key,
quote_tokens,
self.quote_timeout,
)
}
}