hypercall_db/traits/
directive_outbox.rs1use alloy::primitives::Address;
4use anyhow::Result;
5use async_trait::async_trait;
6use hypercall_types::WalletAddress;
7use rust_decimal::Decimal;
8
9use crate::{
10 DepositMonitoringRow, DirectiveOutboxDeliveryMetricsRow, DirectiveOutboxRecentRow,
11 DirectiveOutboxRow, DirectiveStatusRow, HypercoreCashLedgerApply,
12 HypercoreCashLedgerApplyResult, OptionInstrumentForCredit, RsmDepositCreditClaimInput,
13 RsmDepositCreditClaimRecord, RsmUsdcDepositMatch,
14};
15
16pub trait DirectiveOutboxReader: Send + Sync {
17 fn claim_next_directive_outbox_item_sync(&self) -> Result<Option<DirectiveOutboxRow>>;
18
19 fn get_directive_status_sync(&self, directive_id: &str) -> Result<Option<DirectiveStatusRow>>;
21
22 fn get_withdrawal_history_sync(
24 &self,
25 wallet: &WalletAddress,
26 limit: i64,
27 ) -> Result<Vec<DirectiveStatusRow>>;
28
29 fn list_directive_outbox_delivery_metrics_sync(
31 &self,
32 ) -> Result<Vec<DirectiveOutboxDeliveryMetricsRow>>;
33
34 fn list_recent_directive_outbox_rows_sync(
36 &self,
37 limit: i64,
38 offset: i64,
39 ) -> Result<Vec<DirectiveOutboxRecentRow>>;
40}
41
42#[async_trait]
43pub trait AsyncDirectiveOutboxReader: Send + Sync {
44 async fn directive_outbox_exists(&self, directive_id: &str) -> Result<bool>;
46
47 async fn get_directive_status(&self, directive_id: &str) -> Result<Option<DirectiveStatusRow>>;
49
50 async fn get_withdrawal_history(
52 &self,
53 wallet: &WalletAddress,
54 limit: i64,
55 ) -> Result<Vec<DirectiveStatusRow>>;
56
57 async fn list_directive_outbox_delivery_metrics(
59 &self,
60 ) -> Result<Vec<DirectiveOutboxDeliveryMetricsRow>>;
61
62 async fn list_recent_directive_outbox_rows(
64 &self,
65 limit: i64,
66 offset: i64,
67 ) -> Result<Vec<DirectiveOutboxRecentRow>>;
68}
69
70pub trait DirectiveOutboxWriter: DirectiveOutboxReader {
71 fn mark_directive_outbox_delivery_failed_sync(
72 &self,
73 outbox_seq: i64,
74 error: &str,
75 ) -> Result<()>;
76
77 fn mark_directive_outbox_dead_lettered_sync(&self, outbox_seq: i64, error: &str) -> Result<()>;
78
79 fn mark_directive_outbox_manual_reconciliation_sync(
84 &self,
85 outbox_seq: i64,
86 error: &str,
87 ) -> Result<()>;
88
89 fn record_directive_submitter_submission_sync(
95 &self,
96 request_id: &str,
97 submitter_address: &Address,
98 submitter_nonce: u64,
99 ) -> Result<()>;
100
101 fn persist_directive_transaction_update_sync(
107 &self,
108 request_id: &str,
109 status: hypercall_types::TransactionStatus,
110 tx_hash: Option<&str>,
111 error: Option<&str>,
112 ) -> Result<()>;
113}
114
115#[async_trait]
116pub trait AsyncDirectiveOutboxWriter: AsyncDirectiveOutboxReader {
117 async fn record_directive_submitter_submission(
123 &self,
124 request_id: &str,
125 submitter_address: &Address,
126 submitter_nonce: u64,
127 ) -> Result<()>;
128
129 async fn persist_directive_transaction_update(
135 &self,
136 request_id: &str,
137 status: hypercall_types::TransactionStatus,
138 tx_hash: Option<&str>,
139 error: Option<&str>,
140 ) -> Result<()>;
141}
142
143#[async_trait]
144pub trait RsmCreditReader: Send + Sync {
145 fn directive_outbox_exists_sync(&self, directive_id: &str) -> Result<bool>;
147
148 async fn get_max_rsm_deposit_credit_observed_block(&self) -> Result<Option<u64>>;
150
151 fn get_exchange_cash_ledger_watermark_sync(&self) -> Result<Option<i64>>;
153
154 async fn get_option_instrument_for_credit(
156 &self,
157 token: &WalletAddress,
158 ) -> Result<Option<OptionInstrumentForCredit>>;
159
160 async fn list_recent_cash_deposit_monitoring_rows(
162 &self,
163 limit: i64,
164 offset: i64,
165 ) -> Result<Vec<DepositMonitoringRow>>;
166}
167
168#[async_trait]
169pub trait RsmCreditWriter: RsmCreditReader {
170 async fn ensure_observed_deposit_account(&self, account: &WalletAddress) -> Result<()>;
172
173 async fn claim_rsm_deposit_credit(
175 &self,
176 input: &RsmDepositCreditClaimInput,
177 ) -> Result<RsmDepositCreditClaimRecord>;
178
179 async fn mark_rsm_deposit_credit_submitted(&self, request_id: &str) -> Result<()>;
181
182 async fn mark_rsm_deposit_credit_failed(&self, request_id: &str, error: &str) -> Result<()>;
184
185 async fn pending_rsm_usdc_deposit_for_amount(
187 &self,
188 amount_wei: &str,
189 ) -> Result<Option<RsmUsdcDepositMatch>>;
190
191 async fn pending_rsm_usdc_deposit_for_evm_tx_hash(
193 &self,
194 evm_tx_hash: &str,
195 amount_wei: &str,
196 ) -> Result<Option<RsmUsdcDepositMatch>>;
197
198 async fn pending_rsm_usdc_deposit_for_credited_hypercore_event(
200 &self,
201 event_hash: &str,
202 amount_wei: &str,
203 ) -> Result<Option<RsmUsdcDepositMatch>>;
204
205 async fn credited_wallet_for_hypercore_cash_event(
207 &self,
208 event_hash: &str,
209 ) -> Result<Option<WalletAddress>>;
210
211 async fn non_crediting_hypercore_cash_event(
213 &self,
214 event_hash: &str,
215 amount_usdc: Decimal,
216 ) -> Result<bool>;
217
218 async fn apply_hypercore_cash_deposit(
220 &self,
221 input: &HypercoreCashLedgerApply,
222 ) -> Result<HypercoreCashLedgerApplyResult>;
223
224 async fn record_hypercore_cash_deposit_pending_margin_mode(
226 &self,
227 input: &HypercoreCashLedgerApply,
228 ) -> Result<()>;
229}