tycho-simulation 0.528.0

Provides tools for interacting with protocol states, calculating spot prices, and quoting token swaps.
Documentation
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
use std::{
    collections::{HashMap, HashSet},
    sync::Arc,
};

use tracing::debug;
use tycho_common::Bytes;

use crate::{
    book::{
        all_pairs::{BookCollector, ComponentLayout, MarketMaker, QuoteRule, VenueBook},
        component::maker_component_id,
        tvl, Book, BookFeedConfig, BookSnapshot, Books, ReceivedAt,
    },
    rfq::protocols::hashflow::{
        client::{HashflowClient, HashflowLevelsClient},
        models::{HashflowMarketMakerLevels, HashflowPrices},
        state::{HashflowAllPairsState, HashflowState},
        PROTOCOL_TYPE,
    },
    snapshot_feed::{errors::FeedError, http::HttpSource},
};

/// Fetches one complete Hashflow book per poll: the prices of every market maker, built into
/// books by its [`HashflowBookAssembler`].
#[derive(Clone, Debug)]
pub struct HashflowBookSource {
    pub(super) prices: HashflowPricesSource,
    pub(super) assembler: HashflowBookAssembler,
}

impl HttpSource for HashflowBookSource {
    type Snapshot = BookSnapshot<ReceivedAt>;

    /// Both requests (market makers, then their levels) count as one poll.
    async fn fetch(&self) -> Result<BookSnapshot<ReceivedAt>, FeedError> {
        let prices = self.prices.fetch().await?;
        Ok(BookSnapshot::received_now(self.assembler.collect(prices)))
    }
}

/// Reads the market makers and their price levels through a [`HashflowLevelsClient`].
#[derive(Clone, Debug)]
pub(super) struct HashflowPricesSource {
    client: HashflowLevelsClient,
}

impl HashflowPricesSource {
    pub(super) fn new(client: HashflowLevelsClient) -> Self {
        Self { client }
    }
}

impl HttpSource for HashflowPricesSource {
    type Snapshot = HashflowPrices;

    /// Fetches the market makers, then their price levels, in one poll.
    async fn fetch(&self) -> Result<HashflowPrices, FeedError> {
        let market_makers = self
            .client
            .fetch_market_makers()
            .await?;
        let levels_by_maker = self
            .client
            .fetch_price_levels(&market_makers)
            .await?;
        debug!(market_makers = levels_by_maker.len(), "fetched price levels");
        Ok(HashflowPrices { levels_by_maker })
    }
}

/// Turns [`HashflowPrices`] into the books [`HashflowFeed`](super::feed::HashflowFeed) would
/// publish for the same poll: every market maker's levels between the configured tokens whose
/// normalized TVL clears the threshold, one simulate-ready book per maker and pair, whose states
/// request firm quotes through the assembler's client. Created by
/// [`HashflowBookAssemblerBuilder`](super::feed::HashflowBookAssemblerBuilder), which also makes
/// the one a [`HashflowFeed`](super::feed::HashflowFeed) uses.
#[derive(Clone, Debug)]
pub struct HashflowBookAssembler {
    /// The protocol system stamped on the components: the venue's own, or its fallback-router
    /// one for a feed built with `with_fallback_router()`.
    pub(super) protocol_system: &'static str,
    pub(super) book_config: BookFeedConfig,
    /// USD-priced tokens the book's TVL is normalized into before the threshold applies.
    pub(super) usd_quote_tokens: Arc<HashSet<Bytes>>,
    /// Requests binding quotes; shared with every state built here.
    pub(super) client: Arc<HashflowClient>,
    /// Whether the venue's pairs are published as one component or one each.
    pub(super) component_layout: ComponentLayout<QuoteRule>,
}

impl HashflowBookAssembler {
    /// Returns the books for `prices`, keyed by component id.
    pub fn books(&self, prices: HashflowPrices) -> HashMap<String, Book> {
        self.collect(prices).into_map()
    }

    pub(super) fn collect(&self, prices: HashflowPrices) -> Books {
        let levels_by_maker = prices.levels_by_maker;
        let mut collector = BookCollector::new(
            self.protocol_system,
            PROTOCOL_TYPE,
            self.book_config.chain,
            self.component_layout,
        );
        for (maker_name, maker_levels) in levels_by_maker.iter() {
            for maker_level in maker_levels {
                let base_bytes = &maker_level.pair.base_token;
                let quote_bytes = &maker_level.pair.quote_token;
                let Some((base_token, quote_token)) = self
                    .book_config
                    .pair_tokens(base_bytes, quote_bytes)
                else {
                    continue;
                };

                // Hashflow's levels price one direction, so the reverse pair is a different book.
                let component_id =
                    maker_component_id(self.protocol_system, base_bytes, quote_bytes, maker_name);
                let tvl = maker_level.levels.notional();
                let Some(normalized_tvl) = self.normalized_tvl(tvl, quote_bytes, &levels_by_maker)
                else {
                    debug!(
                        %component_id,
                        market_maker = %maker_name,
                        "skipping pair, no levels price its quote token in a USD quote token"
                    );
                    continue;
                };

                if !self
                    .book_config
                    .clears_min_tvl(normalized_tvl, &component_id)
                {
                    continue;
                }

                // `levels_by_maker` stays borrowed for the TVL normalization lookups above.
                let state = HashflowState::new(
                    base_token.clone(),
                    quote_token.clone(),
                    maker_level.clone(),
                    maker_name.clone(),
                    Arc::clone(&self.client),
                );
                collector.push(
                    component_id,
                    VenueBook { signer: MarketMaker(maker_name.clone()), updated_at: None, state },
                );
            }
        }
        collector.finish::<HashflowAllPairsState>()
    }

    /// The TVL in USD quote-token units, converted through every pair the response priced —
    /// each market maker's level set is one such pair.
    fn normalized_tvl(
        &self,
        raw_tvl: f64,
        quote_token: &Bytes,
        levels_by_maker: &HashMap<String, Vec<HashflowMarketMakerLevels>>,
    ) -> Option<f64> {
        tvl::tvl_in_usd(
            raw_tvl,
            quote_token,
            &self.usd_quote_tokens,
            levels_by_maker
                .values()
                .flatten()
                .map(|maker_level| {
                    (
                        &maker_level.pair.base_token,
                        &maker_level.pair.quote_token,
                        &maker_level.levels,
                    )
                }),
        )
    }
}

#[cfg(test)]
mod tests {
    use std::{
        collections::{HashMap, HashSet},
        str::FromStr,
    };

    use rstest::rstest;
    use tycho_common::{simulation::errors::SimulationError, Bytes};

    use super::*;
    use crate::{
        book::{
            all_pairs::{ComponentLayout, QuoteRule},
            assert_same_books,
            component::{maker_component_id, PairState},
            decode_swap_directions,
            levels::{Levels, PriceLevel},
        },
        rfq::protocols::hashflow::{
            state::HashflowState,
            test_support::{
                assembler_for, levels_client, prices_source, two_maker_server, weth_usdc_levels,
                UNPRICED, USDC, WETH,
            },
            FALLBACK_PROTOCOL_SYSTEM, PROTOCOL_SYSTEM,
        },
        snapshot_feed::http::test_support::spawn_http_server,
    };

    /// A source whose endpoints live under `endpoint`, serving `tokens` (18 decimals each) above
    /// `min_tvl_usd`, with USDC and USDT as the USD quote tokens.
    fn source_for(endpoint: &str, tokens: &[&Bytes], min_tvl_usd: f64) -> HashflowBookSource {
        HashflowBookSource {
            prices: prices_source(endpoint),
            assembler: assembler_for(endpoint, tokens, min_tvl_usd),
        }
    }

    #[rstest]
    #[case::per_pair(
        ComponentLayout::PerPair,
        // "fallback:rfq:hashflow" in ASCII, then WETH, USDC and the maker's name.
        "0x66616c6c6261636b3a7266713a68617368666c6f77\
           c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\
           a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\
           6d6d31"
    )]
    #[case::all_pairs(
        ComponentLayout::AllPairs(QuoteRule::OncePerMaker),
        // The venue-wide component is the protocol system and nothing else.
        "0x66616c6c6261636b3a7266713a68617368666c6f77"
    )]
    #[tokio::test]
    async fn a_fallback_source_labels_its_components_for_the_fallback_router(
        #[case] component_layout: ComponentLayout<QuoteRule>,
        #[case] expected_id: &str,
    ) {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let market_makers = r#"{"marketMakers":["mm1"]}"#.to_string();
        let price_levels = format!(
            r#"{{"status":"success","levels":{{
                "mm1":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"3000"}}]}}]
            }}}}"#
        );
        let server = spawn_http_server(move |request| {
            if request
                .target
                .starts_with("/taker/v3/market-makers")
            {
                Some(("200 OK", market_makers.clone()))
            } else {
                Some(("200 OK", price_levels.clone()))
            }
        })
        .await;
        let mut source = source_for(&server.url(), &[&weth, &usdc], 0.0);
        source.assembler.protocol_system = FALLBACK_PROTOCOL_SYSTEM;
        source.assembler.component_layout = component_layout;

        let books = source.fetch().await.unwrap().books;

        let book = books.values().next().expect("one book");
        assert_eq!(book.component.protocol_system, "fallback:rfq:hashflow");
        assert_eq!(book.component.id.to_string(), expected_id);
    }

    /// Every market maker's level set becomes its own directed book once its TVL, normalized
    /// into a USD quote token, clears the floor; the response carries no timestamps.
    #[tokio::test]
    async fn fetch_books_builds_one_directed_book_per_pair() {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let wbtc = Bytes::from_str("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599").unwrap();
        let market_makers = r#"{"marketMakers":["mm1","mm2"]}"#.to_string();
        // mm1: WETH/USDC worth 3000 USD; WBTC/USDC worth 100 USD (below the 1000 USD floor).
        // mm2: WBTC/WETH worth 10 WETH, priced through mm1's WETH/USDC level at 3000.
        let price_levels = format!(
            r#"{{"status":"success","levels":{{
                "mm1":[
                    {{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"3000"}}]}},
                    {{"pair":{{"baseToken":"{wbtc}","quoteToken":"{USDC}"}},"levels":[{{"q":"0.1","p":"1000"}}]}}
                ],
                "mm2":[
                    {{"pair":{{"baseToken":"{wbtc}","quoteToken":"{WETH}"}},"levels":[{{"q":"1","p":"10"}}]}}
                ]
            }}}}"#
        );
        let server = spawn_http_server(move |request| {
            if request
                .target
                .starts_with("/taker/v3/market-makers")
            {
                Some(("200 OK", market_makers.clone()))
            } else {
                Some(("200 OK", price_levels.clone()))
            }
        })
        .await;
        let source = source_for(&server.url(), &[&weth, &usdc, &wbtc], 1000.0);

        let books = source.fetch().await.unwrap().books;

        let weth_usdc = maker_component_id(PROTOCOL_SYSTEM, &weth, &usdc, "mm1");
        let wbtc_weth = maker_component_id(PROTOCOL_SYSTEM, &wbtc, &weth, "mm2");
        let wbtc_usdc = maker_component_id(PROTOCOL_SYSTEM, &wbtc, &usdc, "mm1");
        let key = |id: &Bytes| id.to_string();
        assert_eq!(
            books
                .keys()
                .cloned()
                .collect::<HashSet<_>>(),
            HashSet::from([key(&weth_usdc), key(&wbtc_weth)]),
            "below-floor {wbtc_usdc} must be absent"
        );
        let book = &books[&key(&wbtc_weth)];
        assert_eq!(book.updated_at, None);
        assert_eq!(book.component.id, wbtc_weth);
        let state = book
            .state
            .as_any()
            .downcast_ref::<HashflowState>()
            .expect("a Hashflow state");
        assert_eq!(state.base_token().address, wbtc);
        assert_eq!(state.quote_token().address, weth);
        assert_eq!(
            decode_swap_directions(&book.component.static_attributes["swap_directions"]).unwrap(),
            vec![(wbtc.clone(), weth.clone())],
            "a maker's levels sell the base token only, which the component has to say"
        );
    }

    /// Two makers quoting the same pair are two books, each with its own maker and ladder.
    #[tokio::test]
    async fn fetch_books_keeps_every_market_maker_of_a_pair() {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let market_makers = r#"{"marketMakers":["mm1","mm2"]}"#.to_string();
        let price_levels = format!(
            r#"{{"status":"success","levels":{{
                "mm1":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"3000"}}]}}],
                "mm2":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"2","p":"2990"}}]}}]
            }}}}"#
        );
        let server = spawn_http_server(move |request| {
            if request
                .target
                .starts_with("/taker/v3/market-makers")
            {
                Some(("200 OK", market_makers.clone()))
            } else {
                Some(("200 OK", price_levels.clone()))
            }
        })
        .await;
        let source = source_for(&server.url(), &[&weth, &usdc], 1.0);

        let books = source.fetch().await.unwrap().books;

        let makers_and_ladders: HashMap<_, _> = books
            .values()
            .map(|book| {
                let state = book
                    .state
                    .as_any()
                    .downcast_ref::<HashflowState>()
                    .expect("a Hashflow state");
                assert_eq!(
                    book.component.id,
                    maker_component_id(PROTOCOL_SYSTEM, &weth, &usdc, &state.market_maker)
                );
                (state.market_maker.clone(), state.levels.levels.clone())
            })
            .collect();
        assert_eq!(
            makers_and_ladders,
            HashMap::from([
                (
                    "mm1".to_string(),
                    Levels::new(vec![PriceLevel { quantity: 1.0, price: 3000.0 }]).unwrap()
                ),
                (
                    "mm2".to_string(),
                    Levels::new(vec![PriceLevel { quantity: 2.0, price: 2990.0 }]).unwrap()
                ),
            ])
        );
    }

    /// Hashflow signals failure inside an HTTP 200: a non-success status is a connection error
    /// carrying the API's message, a success without levels a parsing error.
    #[rstest]
    #[case::status_fail_with_message(
        r#"{"status":"fail","error":{"code":429,"message":"rate limited"}}"#,
        FeedError::Connection("rate limited (code 429)".to_string())
    )]
    #[case::success_without_levels(r#"{"status":"success"}"#, FeedError::Parsing(String::new()))]
    #[tokio::test]
    async fn price_levels_status_fail_and_missing_levels_are_errors(
        #[case] body: &'static str,
        #[case] expected: FeedError,
    ) {
        let server = spawn_http_server(move |_| Some(("200 OK", body.to_string()))).await;
        let error = levels_client(&server.url())
            .fetch_price_levels(&["mm1".to_string()])
            .await
            .unwrap_err();

        match (&error, &expected) {
            (FeedError::Connection(msg), FeedError::Connection(text)) => {
                assert!(msg.contains(text), "{msg}")
            }
            (FeedError::Parsing(_), FeedError::Parsing(_)) => {}
            _ => panic!("expected {expected:?}, got {error:?}"),
        }
    }

    /// Published as one component, every market maker's levels stay their own book, the swap
    /// goes to the better one, and the component advertises the rule it is quoted under.
    #[rstest]
    #[case::once_per_maker(QuoteRule::OncePerMaker, "once_per_maker")]
    #[case::once_per_venue(QuoteRule::OncePerVenue, "once_per_venue")]
    #[tokio::test]
    async fn fetch_publishes_every_maker_under_one_component(
        #[case] rule: QuoteRule,
        #[case] attribute: &str,
    ) {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let market_makers = r#"{"marketMakers":["mm1","mm2"]}"#.to_string();
        // Both makers quote one WETH of WETH/USDC depth, mm1 a dollar better.
        let price_levels = format!(
            r#"{{"status":"success","levels":{{
                "mm1":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"3000"}}]}}],
                "mm2":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"2999"}}]}}]
            }}}}"#
        );
        let server = spawn_http_server(move |request| {
            if request
                .target
                .starts_with("/taker/v3/market-makers")
            {
                Some(("200 OK", market_makers.clone()))
            } else {
                Some(("200 OK", price_levels.clone()))
            }
        })
        .await;
        let mut source = source_for(&server.url(), &[&weth, &usdc], 1000.0);
        source.assembler.component_layout = ComponentLayout::AllPairs(rule);

        let books = source.fetch().await.unwrap().books;

        assert_eq!(books.len(), 1, "one component: {:?}", books.keys());
        let book = books.values().next().unwrap();
        // The venue's protocol system in ASCII, which is the whole id.
        assert_eq!(book.component.id.to_string(), "0x7266713a68617368666c6f77");
        assert_eq!(
            decode_swap_directions(&book.component.static_attributes["swap_directions"]).unwrap(),
            vec![(weth.clone(), usdc.clone())],
            "Hashflow's levels price one direction"
        );
        assert_eq!(
            book.component.static_attributes["quote_rule"],
            Bytes::from(attribute.as_bytes())
        );

        let tokens = &source.assembler.book_config.tokens;
        // Hashflow's first level is the minimum tradable size, so the swap is one whole WETH.
        let swap = |state: &dyn tycho_common::simulation::protocol_sim::ProtocolSim| {
            state.get_amount_out(
                num_bigint::BigUint::from(10u64).pow(18),
                &tokens[&weth],
                &tokens[&usdc],
            )
        };
        let first = swap(book.state.as_ref()).unwrap();
        assert_eq!(
            first.amount,
            num_bigint::BigUint::from(3000u64) * num_bigint::BigUint::from(10u64).pow(18),
            "the better maker quotes first"
        );
    }

    /// A maker declines an amount below its first level, so the venue's floor under one
    /// component is the smallest of its makers' — and what it refuses below, it names.
    #[tokio::test]
    async fn the_venue_floor_is_the_smallest_makers_minimum() {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let market_makers = r#"{"marketMakers":["deep_mm","small_mm"]}"#.to_string();
        // deep_mm takes two WETH at a time, small_mm takes one.
        let price_levels = format!(
            r#"{{"status":"success","levels":{{
                "deep_mm":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"2","p":"3000"}}]}}],
                "small_mm":[{{"pair":{{"baseToken":"{WETH}","quoteToken":"{USDC}"}},"levels":[{{"q":"1","p":"2999"}}]}}]
            }}}}"#
        );
        let server = spawn_http_server(move |request| {
            if request
                .target
                .starts_with("/taker/v3/market-makers")
            {
                Some(("200 OK", market_makers.clone()))
            } else {
                Some(("200 OK", price_levels.clone()))
            }
        })
        .await;
        let mut source = source_for(&server.url(), &[&weth, &usdc], 1000.0);
        source.assembler.component_layout = ComponentLayout::AllPairs(QuoteRule::OncePerMaker);

        let books = source.fetch().await.unwrap().books;
        let state = &books.values().next().unwrap().state;
        let tokens = &source.assembler.book_config.tokens;
        let swap = |whole_weth: u64| {
            state.get_amount_out(
                num_bigint::BigUint::from(whole_weth) * num_bigint::BigUint::from(10u64).pow(17),
                &tokens[&weth],
                &tokens[&usdc],
            )
        };

        // Half a WETH is under every maker's floor, one WETH is over small_mm's.
        match swap(5) {
            Err(SimulationError::RecoverableError(message)) => assert_eq!(
                message,
                "Amount below minimum. Input amount: 500000000000000000, min amount: \
                 1000000000000000000 (both in base units)"
            ),
            other => panic!("expected the venue's floor, got {other:?}"),
        }
        assert!(swap(10).is_ok(), "one WETH is small_mm's minimum");
    }

    /// Books rebuilt from serialized prices match the source's published books for the same
    /// poll.
    #[tokio::test]
    async fn prices_round_trip_builds_the_published_books() {
        let weth = Bytes::from_str(WETH).unwrap();
        let usdc = Bytes::from_str(USDC).unwrap();
        let server = two_maker_server().await;
        let source = source_for(&server.url(), &[&weth, &usdc], 1.0);
        let published = source.fetch().await.unwrap().books;
        let prices = source.prices.fetch().await.unwrap();

        let sent = serde_json::to_string(&prices).unwrap();
        let received: HashflowPrices = serde_json::from_str(&sent).unwrap();

        assert_eq!(received, prices);
        assert_same_books(&source.assembler.books(received), &published);
        assert_eq!(published.len(), 1, "only mm1's pair is between the served tokens");
    }

    /// The response carries one market maker's WETH/USDC level at 3000.
    #[rstest]
    #[case::usd_quote_token_is_taken_as_is(USDC, 1000.0, Some(1000.0))]
    #[case::other_quote_token_is_converted_through_its_usd_level(WETH, 2.0, Some(6000.0))]
    #[case::quote_token_without_usd_level_has_no_tvl(UNPRICED, 1000.0, None)]
    fn normalized_tvl_converts_into_usd_quote_tokens(
        #[case] quote_token: &str,
        #[case] raw_tvl: f64,
        #[case] expected: Option<f64>,
    ) {
        let assembler = assembler_for("https://hashflow.example", &[], 1.0);
        let levels = HashMap::from([("test_mm".to_string(), vec![weth_usdc_levels()])]);

        let result =
            assembler.normalized_tvl(raw_tvl, &Bytes::from_str(quote_token).unwrap(), &levels);

        assert_eq!(result, expected);
    }
}