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
//! Quote models: quote sets, quote lines, drafts, leases and identity cancellations.
use alloy_primitives::{Address, Bytes};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::ToSign;
use crate::types::{Amount, OrderId, Price, QuoteIdentityId, Revision, VenueId};
/// One quote as signed: the taker pays `receive` on `venue` per `supply` of the order's venue.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Quote {
/// The venue the taker pays on.
pub venue: VenueId,
/// That venue's chain.
pub chain_id: u64,
/// The token paid.
pub token: Address,
/// The maker's payment recipient.
pub recipient: Address,
/// Price denominator and budget, in the order venue's base units.
pub supply: Amount,
/// Price numerator, in `venue` base units.
pub receive: Amount,
/// The smallest fill, in the order venue's base units.
pub min_fill: Amount,
}
/// A quote of a [`QuoteSet`] with what it can still fill.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct OfferedQuote {
/// The venue the taker pays on.
pub venue: VenueId,
/// That venue's chain.
pub chain_id: u64,
/// The token paid.
pub token: Address,
/// The maker's payment recipient.
pub recipient: Address,
/// Price denominator and budget, in the order venue's base units.
pub supply: Amount,
/// Price numerator, in `venue` base units.
pub receive: Amount,
/// The smallest fill, in the order venue's base units.
pub min_fill: Amount,
/// What it can fill now.
pub available: Amount,
/// What it offers in this sequence.
pub offered: Amount,
}
/// An order's signed quotes for one sequence.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QuoteSet {
/// The sequence.
pub sequence: u64,
/// The signed on-chain settlement deadline.
pub expires_at: DateTime<Utc>,
/// The quotes, in signed order.
pub quotes: Vec<OfferedQuote>,
/// The quote signer's signature (an opaque ERC-1271 signature on some older sets).
pub signature: Bytes,
/// When it was stored.
pub created_at: DateTime<Utc>,
/// The last admission time.
pub valid_until: DateTime<Utc>,
/// The sequence's admission budget; not signed on chain.
pub quote_size: Amount,
/// The identity generation it was signed under.
pub identity_generation: Revision,
/// Whether it admits takes now: within validity, lease and identity.
pub active: bool,
}
/// A maker's prices and stock on one venue.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QuoteLine {
/// The venue.
pub venue: VenueId,
/// What the maker pays to receive one unit on `venue`; `None` receives nothing there.
#[serde(deserialize_with = "super::required")]
pub buy: Option<Price>,
/// What the maker asks to deliver one unit on `venue`; `None` delivers nothing there.
#[serde(deserialize_with = "super::required")]
pub sell: Option<Price>,
/// What the identity's pool on `venue` offers to deliver.
pub stock: Amount,
/// The smallest fill of the pool's quotes; `None` is one token.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub min_fill: Option<Amount>,
}
/// A quote identity's published lines.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QuoteLines {
/// The identity.
pub quote_identity_id: QuoteIdentityId,
/// Advances at each publication.
pub revision: Revision,
/// One line per venue.
pub lines: Vec<QuoteLine>,
}
/// One pool's quote set to sign for a lines publication.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QuoteLineDraft {
/// The pool.
pub order_id: OrderId,
/// The pool's venue.
pub venue: VenueId,
/// The draft, named by its signature.
pub draft_id: Uuid,
/// The sequence it signs.
pub sequence: u64,
/// The last admission time, Unix seconds.
pub valid_until: u64,
/// The signed settlement deadline, Unix seconds.
pub expires_at: u64,
/// The line's stock; not signed on chain.
pub quote_size: Amount,
/// The quotes to sign.
pub quotes: Vec<Quote>,
/// The quote set's typed data.
pub to_sign: Vec<ToSign>,
}
/// A prepared lines publication: the normalized lines and the drafts to sign.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QuoteLinesPreparation {
/// The preparation.
pub id: Uuid,
/// The identity.
pub quote_identity_id: QuoteIdentityId,
/// The lines' revision it replaces.
pub expected_revision: Revision,
/// The last admission time, Unix seconds.
pub valid_until: u64,
/// The lines, normalized and sorted by venue.
pub lines: Vec<QuoteLine>,
/// One draft per pool to quote.
pub drafts: Vec<QuoteLineDraft>,
/// The pools whose quotes the publication pulls.
pub cancels: Vec<OrderId>,
}
/// A quote identity's lease: its quotes admit takes only while it runs.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Lease {
/// The identity.
pub identity_id: QuoteIdentityId,
/// The identity's generation.
pub generation: Revision,
/// When the lease ends unless renewed.
pub expires_at: DateTime<Utc>,
}
/// The answer to pulling every quote of an identity.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IdentityCancellation {
/// The identity.
pub identity_id: QuoteIdentityId,
/// The identity's new generation.
pub generation: Revision,
/// How many orders' quotes were pulled.
pub orders: u64,
}