Skip to main content

hypercall_db/traits/
rfq.rs

1//! RFQ (Request for Quote) persistence traits.
2//!
3//! Sync because RFQ writes happen in the engine event loop.
4
5use anyhow::Result;
6use hypercall_types::WalletAddress;
7use rust_decimal::Decimal;
8use uuid::Uuid;
9
10use crate::QuoteProviderRecord;
11
12/// Read-only quote provider queries.
13pub trait RfqReader: Send + Sync {
14    /// Load all registered quote providers.
15    fn get_all_quote_providers_sync(&self) -> Result<Vec<QuoteProviderRecord>>;
16}
17
18/// Quote provider and RFQ mutations.
19pub trait RfqWriter: RfqReader {
20    /// Upsert a quote provider registration.
21    fn upsert_quote_provider_sync(&self, qp: &QuoteProviderRecord) -> Result<()>;
22
23    /// Update a quote provider's status ("active" / "suspended").
24    fn update_quote_provider_status_sync(&self, wallet: &WalletAddress, status: &str)
25        -> Result<()>;
26
27    /// Persist an RFQ record and its legs atomically.
28    fn persist_rfq_record_sync(
29        &self,
30        rfq_id: &Uuid,
31        taker_wallet: &WalletAddress,
32        underlying: &str,
33        status: &str,
34        taker_signature: &str,
35        taker_nonce: u64,
36        legs_hash: &[u8; 32],
37        legs: &[(String, String, Decimal)],
38        expires_at_ms: u64,
39    ) -> Result<()>;
40
41    /// Persist a quote provider's firm quote and its legs atomically.
42    fn persist_rfq_quote_sync(
43        &self,
44        quote_id: &Uuid,
45        rfq_id: &Uuid,
46        qp_wallet: &WalletAddress,
47        net_premium: Decimal,
48        valid_for_ms: u64,
49        qp_signature: &str,
50        qp_nonce: u64,
51        legs: &[(String, String, Decimal, Decimal)],
52        expires_at_ms: u64,
53    ) -> Result<()>;
54
55    /// Update RFQ record status.
56    fn update_rfq_status_sync(&self, rfq_id: &Uuid, status: &str) -> Result<()>;
57}