df_papertrade_core/client/
mod.rs1pub mod chain;
14pub mod config;
15pub mod deployment;
16pub mod error;
17mod reads;
18pub mod relayer;
19
20pub use config::Config;
21pub use error::Error;
22pub use reads::Quote;
23pub use relayer::{Accepted, Call, Relayer, RelayerError};
24
25use df_hyperliquid_core::client::Http;
26use df_hyperliquid_core::client::evm::Rpc;
27
28#[derive(Clone, Debug)]
30pub struct Client<H> {
31 http: H,
32 config: Config,
33}
34
35impl<H: Http + Clone> Client<H> {
36 pub fn new(http: H, config: Config) -> Self {
37 Client { http, config }
38 }
39
40 #[must_use]
41 pub const fn config(&self) -> &Config {
42 &self.config
43 }
44
45 #[must_use]
46 pub const fn http(&self) -> &H {
47 &self.http
48 }
49
50 pub(crate) fn now_ms(&self) -> u64 {
51 (self.config.now_ms)()
52 }
53
54 pub(crate) fn random<const N: usize>(&self) -> Result<[u8; N], Error> {
55 let mut bytes = [0u8; N];
56 (self.config.random)(&mut bytes).map_err(Error::Random)?;
57 Ok(bytes)
58 }
59
60 #[must_use]
61 pub fn relayer(&self) -> Relayer<H> {
62 Relayer::at(self.http.clone(), self.config.relayer.clone())
63 }
64
65 pub(crate) fn rpc(&self) -> Rpc<H> {
66 Rpc::new(self.http.clone(), self.config.rpc.clone())
67 }
68}