tycho_simulation/rfq/protocols/hashflow/
client_builder.rs1use std::collections::HashSet;
2
3use tokio::time::Duration;
4use tycho_common::{models::Chain, Bytes};
5
6use super::client::HashflowClient;
7use crate::rfq::{errors::RFQError, protocols::utils::default_quote_tokens_for_chain};
8
9pub struct HashflowClientBuilder {
34 chain: Chain,
35 auth_user: String,
36 auth_key: String,
37 tokens: HashSet<Bytes>,
38 tvl: f64,
39 quote_tokens: Option<HashSet<Bytes>>,
40 poll_time: Duration,
41 quote_timeout: Duration,
42}
43
44impl HashflowClientBuilder {
45 pub fn new(chain: Chain, auth_user: String, auth_key: String) -> Self {
46 Self {
47 chain,
48 auth_user,
49 auth_key,
50 tokens: HashSet::new(),
51 tvl: 100.0, quote_tokens: None,
53 poll_time: Duration::from_secs(5), quote_timeout: Duration::from_secs(5), }
56 }
57
58 pub fn tokens(mut self, tokens: HashSet<Bytes>) -> Self {
60 self.tokens = tokens;
61 self
62 }
63
64 pub fn tvl_threshold(mut self, tvl: f64) -> Self {
66 self.tvl = tvl;
67 self
68 }
69
70 pub fn quote_tokens(mut self, quote_tokens: HashSet<Bytes>) -> Self {
73 self.quote_tokens = Some(quote_tokens);
74 self
75 }
76
77 pub fn poll_time(mut self, poll_time: Duration) -> Self {
79 self.poll_time = poll_time;
80 self
81 }
82
83 pub fn quote_timeout(mut self, timeout: Duration) -> Self {
85 self.quote_timeout = timeout;
86 self
87 }
88
89 pub fn build(self) -> Result<HashflowClient, RFQError> {
90 let quote_tokens;
91 if let Some(tokens) = self.quote_tokens {
92 quote_tokens = tokens;
93 } else {
94 quote_tokens = default_quote_tokens_for_chain(&self.chain)?
95 }
96
97 HashflowClient::new(
98 self.chain,
99 self.tokens,
100 self.tvl,
101 quote_tokens,
102 self.auth_user,
103 self.auth_key,
104 self.poll_time,
105 self.quote_timeout,
106 )
107 }
108}