1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//! API information and limits (`GET /v1/info`) and health (`GET /health`).
use alloy_primitives::Address;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{Amount, BlockNumber, VenueId, open_enum};
open_enum! {
/// Who may make new commitments.
pub enum AccessMode {
/// Everyone.
Open = "open",
/// Users granted access (see [`AccessState`](super::AccessState)).
Invite = "invite",
}
}
open_enum! {
/// The server's overall health.
pub enum HealthStatus {
/// Every chain is ready.
Ok = "ok",
/// Something is not ready.
Degraded = "degraded",
}
}
/// This deployment's version, operator, limits, timing and chains (`GET /v1/info`).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Info {
/// The API version (`v1`).
pub api_version: String,
/// The server's time.
pub server_time: DateTime<Utc>,
/// The escrow operator of this deployment.
pub operator: Address,
/// Request and trading limits.
pub limits: ApiLimits,
/// Settlement timing.
pub settlement: SettlementTiming,
/// The escrow deployments.
pub chains: Vec<DeploymentChain>,
/// Who may make new commitments.
pub access: AccessPolicy,
}
/// Who may make new commitments.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AccessPolicy {
/// Open, or by invitation.
pub mode: AccessMode,
/// The captcha site key of the access page; `None` without captcha.
#[serde(deserialize_with = "super::required")]
pub captcha_site_key: Option<String>,
}
/// Request and trading limits.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ApiLimits {
/// Requests per second per user's sessions or per credential, on authenticated routes.
pub requests_per_second: u32,
/// The request burst.
pub request_burst: u32,
/// The largest request body, in bytes.
pub body_bytes: u64,
/// The shortest quote lease, in seconds.
pub lease_seconds_min: u64,
/// The longest quote lease, in seconds.
pub lease_seconds_max: u64,
/// The longest quote validity, in seconds.
pub quote_validity_seconds_max: u64,
/// The most parts a take splits into.
pub take_parts_max: u8,
/// How long a take may wait for its payment, in seconds.
pub pay_window_seconds: u64,
/// The payment window of a take signed with its withdrawal, in seconds.
pub route_pay_window_seconds: u64,
/// Takes one taker may hold awaiting payment at once.
pub max_unpaid_takes: u32,
/// The most one fill takes from one level, in base units.
pub fill_max: Amount,
}
/// Settlement timing.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SettlementTiming {
/// The maker's claim timeout, in seconds.
pub maker_timeout_seconds: u64,
/// The taker's refund timeout, in seconds.
pub taker_timeout_seconds: u64,
/// Deliveries on Lighter and Aster; `None` when neither is enabled.
#[serde(deserialize_with = "super::required")]
pub delivery: Option<DeliveryTiming>,
}
/// Timing of deliveries on Lighter and Aster.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DeliveryTiming {
/// `deliver_by` is `pay_by` plus this many seconds.
pub window_seconds: u64,
/// Seconds after `deliver_by` when an unreported paid fill's delivery is abandoned.
pub abandon_after_seconds: u64,
/// `report_by` is `t2` less this many seconds.
pub report_margin_seconds: u64,
/// The Lighter status a delivery needs; `None` without Lighter.
#[serde(deserialize_with = "super::required")]
pub min_status: Option<u8>,
}
/// An escrow deployment.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DeploymentChain {
/// The venue it serves.
pub venue: VenueId,
/// Its chain.
pub chain_id: u64,
/// The escrow token.
pub token: Address,
/// Its symbol.
pub symbol: String,
/// Its decimals.
pub decimals: u8,
/// The escrow.
pub escrow: Address,
/// The block the escrow was deployed at.
pub deployment_block: BlockNumber,
}
/// The server's health (`GET /health`); a 503 answer carries it too.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Health {
/// Overall health.
pub status: HealthStatus,
/// Whether every chain is ready.
pub ready: bool,
/// The server's time.
pub server_time: DateTime<Utc>,
/// Relay transactions pending on all chains.
pub pending_transactions: u64,
/// Events committed but not yet given a cursor.
pub journal_unpublished: u64,
/// The age of the oldest of those, in seconds.
#[serde(deserialize_with = "super::required")]
pub journal_oldest_unpublished_seconds: Option<f64>,
/// Per chain.
pub chains: Vec<ChainHealth>,
}
/// One chain's health.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChainHealth {
/// The venue on the chain.
pub venue: VenueId,
/// The chain.
pub chain_id: u64,
/// Observations ready, no integrity mismatch, few and young pending transactions.
pub ready: bool,
/// The watcher follows the finalized head with enough operator gas.
pub observations_ready: bool,
/// The oldest pending relay transaction's age, in seconds.
#[serde(deserialize_with = "super::required")]
pub oldest_pending_seconds: Option<u64>,
/// Relay transactions pending.
pub pending_transactions: u64,
/// When the last integrity check started.
#[serde(deserialize_with = "super::required")]
pub integrity_checked_at: Option<DateTime<Utc>>,
/// When the last integrity check completed.
#[serde(deserialize_with = "super::required")]
pub integrity_completed_at: Option<DateTime<Utc>>,
/// Why the last integrity check failed.
#[serde(deserialize_with = "super::required")]
pub integrity_error: Option<String>,
/// A latched discrepancy; blocks admission until supervised verification.
pub integrity_mismatch: bool,
/// The watched block.
#[serde(deserialize_with = "super::required")]
pub block: Option<BlockNumber>,
/// The finalized block.
#[serde(deserialize_with = "super::required")]
pub finalized_block: Option<BlockNumber>,
/// When the watched block was read.
#[serde(deserialize_with = "super::required")]
pub checked_at: Option<DateTime<Utc>>,
/// When the finalized block was read.
#[serde(deserialize_with = "super::required")]
pub finalized_at: Option<DateTime<Utc>>,
/// The watcher's error.
#[serde(deserialize_with = "super::required")]
pub error: Option<String>,
/// The operator's gas balance, in the chain's native base units.
#[serde(deserialize_with = "super::required")]
pub operator_gas: Option<Amount>,
}
#[cfg(test)]
mod tests;