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
//! BaiBai on Base: a maker-published curve per base token, quoted against one quote
//! token and filled from one shared custodian.
//!
//! The feed reads each pair from the chain over JSON-RPC every poll, through the CurveBook's own
//! getters, and prices swaps locally with the contract's arithmetic. The implementations behind
//! the three proxies are not source-verified; the arithmetic was checked wei for wei against the
//! deployed `CurveBook.quote` and `Entrypoint.quoteFor` (see `testdata/`), and an upgrade that
//! changes it needs this module updated. The Entrypoint was last upgraded at Base block
//! 53,492,231; the recording at 53,545,000 postdates it.
//!
//! Only spreads of zero and depths of 0 or 100% have been seen live, so the spread and partial
//! depth paths of the arithmetic follow the contract's observed rounding but have not been
//! compared with it.
//!
//! # Priority surcharge
//!
//! The entrypoint withholds part of the gross output from a swap whose priority fee (gas price
//! less basefee) exceeds 2e6 wei (0.002 gwei): one hundredth of a basis point per 1e4 wei above
//! that, rounded down, capped at 50 bps (reached at 0.052 gwei), and the withheld amount rounded
//! up. Measured at Base block 53,545,000, after the Entrypoint upgrade at 53,492,231; before it,
//! the rule was a flat 10 bps above a priority fee of 8e6 wei. The books do not price it, since
//! the priority fee is the sending client's choice and a quote does not carry one: a route
//! through BaiBai sent with a tip above 0.002 gwei receives up to 50 bps less than quoted, and
//! reverts when its slippage tolerance is tighter than that.
//!
//! # What this integration depends on
//!
//! The arithmetic, the expiry rules, the fee and the gas model were measured against one
//! implementation behind each proxy, pinned in `BASE_DEPLOYMENT`:
//!
//! | Proxy | Implementation | Since Base block | Upgrades since deployment |
//! |------------|----------------|------------------|---------------------------|
//! | Entrypoint | `0xCc61…F3B0` | 53,492,231 | 5 |
//! | CurveBook | `0x3E6A…9f1d` | 52,963,996 | 4 |
//! | Custodian | `0x997b…3076` | 50,895,903 | none |
//!
//! Counted from every `Upgraded` event of the three proxies, deployed at blocks 50,895,895 to
//! 50,895,911, up to block 56,419,398.
//!
//! A Safe (`0xB1F4E4d67E330CC505e526488bAe0388e616A907`) owns all three and can upgrade any of
//! them. None is source-verified, so every upgrade is treated as one that may change the
//! arithmetic: each poll reads the three EIP-1967 implementation slots, and one that differs from
//! its pin ends the feed. Accepting a new implementation means re-recording a fixture with
//! `testdata/record_fixture.py` and comparing its quotes wei for wei, re-measuring the gas
//! constants in `state.rs` on a fork, and re-running tycho-execution's `Baibai.t.sol`, which pins
//! the priority surcharge and the expiry rules, then updating the pin.
//!
//! The pins do not catch the owner changing parameters in storage. The TTL and the taker fee are
//! read every poll, so a change to them reaches the books. The priority surcharge's threshold
//! (view `0xc256865c`) and cap (`prioritySurchargeBps()`) are not read; a change to them would
//! leave the section above stale, though the books do not price the surcharge either way.
//!
//! Reference: <https://docs.baibai.cx/takers/quoting-and-swapping>
use ;
use Chain;
pub use ;
pub use BaibaiState;
/// Protocol system stamped on every component this integration emits; tycho-execution keys
/// BaiBai's encoder on it.
pub const PROTOCOL_SYSTEM: &str = "baibai";
/// Component type stamped on every pair this integration emits.
pub const PROTOCOL_TYPE: &str = "baibai_pair";
/// Static attributes naming the pair's base and quote token, which the encoder reads to choose
/// the base and the direction.
pub const BASE_ATTRIBUTE: &str = "base";
pub const QUOTE_ATTRIBUTE: &str = "quote";
/// The three proxies of one BaiBai deployment, the implementation each was verified against, the
/// chain they are on and the quote token every pair trades against.
pub
/// The Base deployment, quoted in USDC.
pub const BASE_DEPLOYMENT: Deployment = Deployment ;
/// The bases listed on the Base deployment: WETH and cbBTC. The CurveBook cannot enumerate its
/// pairs, so a base listed later is served only once it is passed to
/// [`BaibaiFeedBuilder::bases`]; the feed never discovers one. The book emits
/// `PairListed(address indexed base, address indexed quote)` with a base's first curve, from
/// block 51,696,183 on, where an upgrade emitted WETH's after the fact. Up to block 53,831,402
/// the only other one is cbBTC's, at 52,869,661, so a later `PairListed` log names a base to add
/// here.
pub const BASE_LISTED_BASES: = ;
/// Tycho's default router on Base, the taker the books are priced for unless
/// [`BaibaiFeedBuilder::taker`] sets another. The books carry the fee the entrypoint charges this
/// router; a router BaiBai has not whitelisted pays the venue default of 50 millionths.
pub const BASE_ROUTER: Address = address!;