tycho-simulation 0.527.1

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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
use std::{any::Any, borrow::Cow, collections::HashMap, sync::Arc};

use async_trait::async_trait;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};
use tycho_common::{
    dto::ProtocolStateDelta,
    models::{protocol::GetAmountOutParams, token::Token},
    simulation::{
        errors::{SimulationError, TransitionError},
        indicatively_priced::{IndicativelyPriced, SignedQuote},
        protocol_sim::{Balances, GetAmountOutResult, ProtocolSim},
    },
    Bytes,
};

use crate::{
    book::{
        all_pairs::{all_pairs_state, PricesAfterFill, RefusesQuote, SignedByVenue},
        component::PairState,
        levels::Levels,
        sim::{self, SwapDirection},
    },
    rfq::protocols::bebop::{client::BebopClient, models::BebopBook},
};

/// Rough gas estimate for one Bebop settlement.
const BEBOP_SWAP_GAS: u64 = 70_000;

/// What Bebop's quote endpoint refuses below, measured against the live API on Ethereum and
/// Base in both directions: a trade worth less than one US dollar on the side being sold, the
/// same figure for every pair. The venue says so in the refusal — `MinSize: Request quotes over
/// $1.` — and publishes no per-token minimum, so this constant and a price are the whole rule.
const MIN_TRADE_USD: f64 = 1.0;

#[derive(Clone, derive_more::Debug, Serialize, Deserialize)]
pub struct BebopState {
    pub(super) base_token: Token,
    pub(super) quote_token: Token,
    #[debug(skip)]
    pub(super) book: BebopBook,
    /// What one quote token is worth in US dollars, from the pair that prices it in a USD quote
    /// token at the moment this book was published. It is what turns the venue's dollar floor
    /// into an amount of a token.
    pub(super) usd_per_quote_token: f64,
    #[serde(skip)]
    #[debug(skip)]
    client: Option<Arc<BebopClient>>,
}

impl BebopState {
    /// A book this venue prices, with the client its binding quotes go to.
    pub(super) fn new(
        base_token: Token,
        quote_token: Token,
        book: BebopBook,
        usd_per_quote_token: f64,
        client: Arc<BebopClient>,
    ) -> Self {
        BebopState { base_token, quote_token, book, usd_per_quote_token, client: Some(client) }
    }

    /// The ladder a swap in `direction` consumes, in the units of the token sold: the bids as
    /// published for selling base, the asks re-expressed per quote unit for selling quote.
    fn ladder(&self, direction: SwapDirection) -> Cow<'_, Levels> {
        match direction {
            SwapDirection::BaseToQuote => Cow::Borrowed(&self.book.bids),
            SwapDirection::QuoteToBase => Cow::Owned(self.book.asks.invert()),
        }
    }
}

impl PairState for BebopState {
    fn base_token(&self) -> &Token {
        &self.base_token
    }

    fn quote_token(&self) -> &Token {
        &self.quote_token
    }

    fn directions(&self) -> Vec<(Bytes, Bytes)> {
        sim::directions(
            &self.base_token,
            &self.quote_token,
            !self.book.bids.is_empty(),
            !self.book.asks.is_empty(),
        )
    }
}

impl PricesAfterFill for BebopState {
    fn marginal_price(
        &self,
        token_in: &Bytes,
        token_out: &Bytes,
        filled: &BigUint,
    ) -> Result<f64, SimulationError> {
        let direction =
            SwapDirection::require(&self.base_token, &self.quote_token, token_in, token_out)?;
        let (sell_decimals, _) = direction.decimals(&self.base_token, &self.quote_token);
        sim::marginal_price(&self.ladder(direction), filled, sell_decimals)
    }
}

#[typetag::serde]
impl ProtocolSim for BebopState {
    fn fee(&self) -> f64 {
        0.0
    }

    fn spot_price(&self, base: &Token, quote: &Token) -> Result<f64, SimulationError> {
        let direction = SwapDirection::require(
            &self.base_token,
            &self.quote_token,
            &base.address,
            &quote.address,
        )?;
        // Since this method does not care about sell direction, we average the price of the best
        // bid and ask
        let best_bid = self
            .book
            .bids
            .first()
            .map(|level| level.price);
        let best_ask = self
            .book
            .asks
            .first()
            .map(|level| level.price);
        // If just one is available, only consider that one
        let average_price = match (best_bid, best_ask) {
            (Some(best_bid), Some(best_ask)) => (best_bid + best_ask) / 2.0,
            (Some(best_bid), None) => best_bid,
            (None, Some(best_ask)) => best_ask,
            (None, None) => {
                return Err(SimulationError::RecoverableError("No liquidity available".to_string()))
            }
        };
        match direction {
            SwapDirection::BaseToQuote => Ok(average_price),
            SwapDirection::QuoteToBase => Ok(1.0 / average_price),
        }
    }

    fn get_amount_out(
        &self,
        amount_in: BigUint,
        token_in: &Token,
        token_out: &Token,
    ) -> Result<GetAmountOutResult, SimulationError> {
        // Bebop refuses a zero amount with `101 InvalidApiRequest: Sell amounts must be
        // higher than 0.`, before the dollar floor below has anything to say.
        sim::require_positive_amount(&amount_in)?;

        let direction = SwapDirection::require(
            &self.base_token,
            &self.quote_token,
            &token_in.address,
            &token_out.address,
        )?;
        let ladder = self.ladder(direction);
        let amount_in = sim::to_human(&amount_in, token_in.decimals);
        let fill = ladder.fill(amount_in);
        // The trade's worth is read on the quote side, which the swap already expresses: the
        // amount sold when the quote token is sold, and what the ladder pays otherwise. The
        // floor speaks for a book that took something: a side with no levels takes none of any
        // amount and so is worth nothing, which the fill below reports as the absence of
        // liquidity it is, the same answer at every size.
        let quote_amount = match direction {
            SwapDirection::QuoteToBase => amount_in,
            SwapDirection::BaseToQuote => fill.amount_out,
        };
        let worth_usd = quote_amount * self.usd_per_quote_token;
        if fill.remaining_in < amount_in && worth_usd < MIN_TRADE_USD {
            return Err(SimulationError::RecoverableError(format!(
                "Trade is worth {worth_usd} USD, below the {MIN_TRADE_USD} USD Bebop quotes"
            )));
        }
        // The state doesn't change after a swap.
        sim::fill_result(fill, amount_in, token_out.decimals, BEBOP_SWAP_GAS, self)
    }

    fn get_limits(
        &self,
        sell_token: Bytes,
        buy_token: Bytes,
    ) -> Result<(BigUint, BigUint), SimulationError> {
        let direction =
            SwapDirection::require(&self.base_token, &self.quote_token, &sell_token, &buy_token)?;
        let ladder = self.ladder(direction);
        // Nothing on this side is no swap at any size, so there is no limit to report.
        if ladder.is_empty() {
            return Err(SimulationError::RecoverableError("No liquidity".into()));
        }
        let (sell_decimals, buy_decimals) = direction.decimals(&self.base_token, &self.quote_token);
        sim::limits(&ladder, sell_decimals, buy_decimals)
    }

    fn delta_transition(
        &mut self,
        _delta: ProtocolStateDelta,
        _tokens: &HashMap<Bytes, Token>,
        _balances: &Balances,
    ) -> Result<(), TransitionError> {
        Err(TransitionError::DecodeError("Not implemented".into()))
    }

    fn clone_box(&self) -> Box<dyn ProtocolSim> {
        Box::new(self.clone())
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    fn as_any_mut(&mut self) -> &mut dyn Any {
        self
    }

    fn eq(&self, other: &dyn ProtocolSim) -> bool {
        if let Some(other_state) = other
            .as_any()
            .downcast_ref::<BebopState>()
        {
            self.base_token == other_state.base_token &&
                self.quote_token == other_state.quote_token &&
                self.book == other_state.book
        } else {
            false
        }
    }

    fn as_indicatively_priced(&self) -> Result<&dyn IndicativelyPriced, SimulationError> {
        Ok(self)
    }
}

#[async_trait]
impl IndicativelyPriced for BebopState {
    async fn request_signed_quote(
        &self,
        params: GetAmountOutParams,
    ) -> Result<SignedQuote, SimulationError> {
        Ok(sim::quoting_client(self.client.as_ref(), "Bebop")?
            .request_binding_quote(&params)
            .await?)
    }
}

all_pairs_state! {
    /// Bebop's books on one chain behind one component.
    ///
    /// Bebop signs its quotes itself and names no market maker, so all of its books share one
    /// turn: a route takes one quote from the venue, and the swap that takes it spends every
    /// book behind the component.
    BebopAllPairsState(BebopState, SignedByVenue);
}

impl RefusesQuote for BebopAllPairsState {}

#[cfg(test)]
mod tests {
    use std::str::FromStr;

    use rstest::rstest;
    use tokio::time::Duration;
    use tycho_common::models::Chain;

    use super::*;
    use crate::rfq::protocols::bebop::{
        client::QuoteOrigin,
        models::{BebopPriceData, BebopSupportedChain},
    };

    fn wbtc() -> Token {
        Token::new(
            &hex::decode("2260fac5e5542a773aa44fbcfedf7c193bc2c599")
                .unwrap()
                .into(),
            "WBTC",
            8,
            0,
            &[Some(10_000)],
            Chain::Ethereum,
            100,
        )
    }

    fn usdc() -> Token {
        Token::new(
            &hex::decode("a0b86991c6218a76c1d19d4a2e9eb0ce3606eb48")
                .unwrap()
                .into(),
            "USDC",
            6,
            0,
            &[Some(10_000)],
            Chain::Ethereum,
            100,
        )
    }

    fn weth() -> Token {
        Token::new(
            &Bytes::from_str("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").unwrap(),
            "WETH",
            18,
            0,
            &[],
            Default::default(),
            100,
        )
    }

    fn empty_client() -> Arc<BebopClient> {
        Arc::new(BebopClient::new(
            BebopSupportedChain::Ethereum,
            String::new(),
            Duration::from_secs(30),
            QuoteOrigin::default(),
        ))
    }

    /// Bebop will not sign a trade worth less than a dollar, so simulating one advertises a
    /// quote that cannot be had. This book quotes WBTC in USDC — a dollar is one USDC going in,
    /// and 1539 satoshi coming out at the 65 000 USDC best bid.
    #[rstest]
    #[case::half_a_dollar_of_usdc("500000", true, false)]
    #[case::two_dollars_of_usdc("2000000", true, true)]
    #[case::sixty_five_cents_of_wbtc("1000", false, false)]
    #[case::six_dollars_of_wbtc("10000", false, true)]
    fn a_trade_worth_less_than_a_dollar_is_refused(
        #[case] amount_in: &str,
        #[case] sell_quote: bool,
        #[case] quotable: bool,
    ) {
        let state = create_test_bebop_state();
        let (token_in, token_out) = if sell_quote { (usdc(), wbtc()) } else { (wbtc(), usdc()) };

        let result =
            state.get_amount_out(BigUint::from_str(amount_in).unwrap(), &token_in, &token_out);

        assert_eq!(result.is_ok(), quotable, "{result:?}");
        if !quotable {
            let error = result.unwrap_err().to_string();
            assert!(error.contains("below the 1 USD Bebop quotes"), "{error}");
        }
    }

    /// Nobody bidding is the absence of liquidity, not a trade too small to quote: the amount
    /// is irrelevant, so both a trade well over the dollar floor and one under it get the same
    /// answer.
    #[rstest]
    #[case::six_dollars_of_wbtc("10000")]
    #[case::sixty_five_cents_of_wbtc("1000")]
    fn selling_into_a_side_with_no_bids_reports_no_liquidity(#[case] amount_in: &str) {
        let mut state = create_test_bebop_state();
        state.book.bids = Levels::default();

        let error = state
            .get_amount_out(BigUint::from_str(amount_in).unwrap(), &wbtc(), &usdc())
            .unwrap_err();

        assert!(
            matches!(&error, SimulationError::InvalidInput(message, None)
                if message.contains("no liquidity on this side")),
            "{error:?}"
        );
    }

    /// A state read back from a recording carries no client: the venue's credentials are not
    /// part of what is serialized, so a replayed book still prices but has nothing to ask for a
    /// firm quote through.
    #[tokio::test]
    async fn a_replayed_state_prices_but_cannot_quote() {
        let state = create_test_bebop_state();
        let replayed: BebopState =
            serde_json::from_str(&serde_json::to_string(&state).unwrap()).unwrap();

        let priced = replayed.get_amount_out(BigUint::from(10_000u64), &wbtc(), &usdc());
        let quoted = replayed
            .request_signed_quote(GetAmountOutParams {
                amount_in: BigUint::from(10_000u64),
                token_in: wbtc().address,
                token_out: usdc().address,
                sender: Bytes::zero(20),
                receiver: Bytes::zero(20),
                origin: None,
            })
            .await;

        assert!(priced.is_ok(), "{priced:?}");
        assert!(
            matches!(&quoted, Err(SimulationError::FatalError(message))
                if message.contains("carries no client")),
            "{quoted:?}"
        );
    }

    fn create_test_bebop_state() -> BebopState {
        let price_data = BebopPriceData {
            base: hex::decode("2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599").unwrap(), // WBTC
            quote: hex::decode("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48").unwrap(), // USDC
            last_update_ts: 1703097600,
            bids: vec![65000.0f32, 1.5f32, 64950.0f32, 2.0f32, 64900.0f32, 0.5f32],
            asks: vec![65100.0f32, 1.0f32, 65150.0f32, 2.5f32, 65200.0f32, 1.5f32],
        };
        BebopState {
            base_token: wbtc(),
            quote_token: usdc(),
            book: BebopBook::try_from(price_data).unwrap(),
            // The pair's quote token is USDC.
            usd_per_quote_token: 1.0,
            client: Some(empty_client()),
        }
    }

    /// After some input went in, the next unit is priced at the level where the fill stopped, on
    /// the side of the book a swap in that direction fills.
    #[rstest]
    #[case::selling_base_in_the_first_level(true, 100_000_000, Some(65000.0))]
    #[case::selling_base_on_the_first_boundary(true, 150_000_000, Some(64950.0))]
    #[case::selling_base_past_the_depth(true, 400_000_000, None)]
    #[case::selling_quote_before_any_fill(false, 0, Some(1.0 / 65100.0))]
    fn the_price_after_a_fill_is_the_level_where_it_stopped(
        #[case] sell_base: bool,
        #[case] filled: u64,
        #[case] expected: Option<f64>,
    ) {
        let state = create_test_bebop_state();
        let (token_in, token_out) = if sell_base { (wbtc(), usdc()) } else { (usdc(), wbtc()) };

        let price =
            state.marginal_price(&token_in.address, &token_out.address, &BigUint::from(filled));

        match (price, expected) {
            (Ok(price), Some(expected)) => assert_eq!(price, expected),
            (Err(SimulationError::RecoverableError(message)), None) => {
                assert_eq!(message, "No liquidity")
            }
            (price, _) => panic!("expected {expected:?}, got {price:?}"),
        }
    }

    #[test]
    fn spot_price_matching_base_and_quote() {
        let state = create_test_bebop_state();

        // Test WBTC/USDC (base/quote) - should use average of best bid and ask
        let price = state
            .spot_price(&wbtc(), &usdc())
            .unwrap();
        assert_eq!(price, 65050.0);
    }

    #[test]
    fn spot_price_inverted_base_and_quote() {
        let state = create_test_bebop_state();

        // Test USDC/WBTC (quote/base) - should use average of best bid and ask, then invert
        let price = state
            .spot_price(&usdc(), &wbtc())
            .unwrap();
        let expected = 0.00001537279;
        assert!((price - expected).abs() < 1e-10);
    }

    #[test]
    fn spot_price_empty_asks() {
        let mut state = create_test_bebop_state();
        state.book.asks = Levels::default();

        // Test WBTC/USDC with no asks - should use only best bid
        let price = state
            .spot_price(&wbtc(), &usdc())
            .unwrap();
        assert_eq!(price, 65000.0);
    }

    #[test]
    fn spot_price_empty_bids() {
        let mut state = create_test_bebop_state();
        state.book.bids = Levels::default();
        // Test WBTC/USDC with no bids - should use only best ask
        let price = state
            .spot_price(&wbtc(), &usdc())
            .unwrap();
        assert_eq!(price, 65100.0);
    }

    #[test]
    fn spot_price_no_liquidity() {
        let mut state = create_test_bebop_state();
        state.book.bids = Levels::default();
        state.book.asks = Levels::default();
        // Test with no liquidity at all - should return error
        let result = state.spot_price(&wbtc(), &usdc());
        assert!(result.is_err());
    }

    #[test]
    fn get_limits_sell_base_for_quote() {
        let state = create_test_bebop_state();

        // Test selling WBTC for USDC (should use bids)
        let (wbtc_limit, usdc_limit) = state
            .get_limits(wbtc().address, usdc().address)
            .unwrap();

        // Use bids: vec![(65000.0, 1.5), (64950.0, 2.0), (64900.0, 0.5)]

        // Total WBTC available: 1.5 + 2.0 + 0.5 = 4.0 WBTC
        let expected_wbtc_limit = BigUint::from(4u64) * BigUint::from(10u64).pow(8u32);

        // Total USDC value: (65000*1.5) + (64950*2.0) + (64900*0.5) = 97500 + 129900 + 32450 =
        // 259850
        let expected_usdc_limit = BigUint::from(259850u64) * BigUint::from(10u64).pow(6u32);

        assert_eq!(wbtc_limit, expected_wbtc_limit);
        assert_eq!(usdc_limit, expected_usdc_limit);
    }

    #[test]
    fn get_limits_buy_base_with_quote() {
        let state = create_test_bebop_state();

        // Test buying WBTC with USDC (should use asks)
        let (usdc_limit, wbtc_limit) = state
            .get_limits(usdc().address, wbtc().address)
            .unwrap();

        // Use asks: vec![(65100.0, 1.0), (65150.0, 2.5), (65200.0, 1.5)]

        // Total USDC needed: (65100*1.0) + (65150*2.5) + (65200*1.5) = 65100 + 162875 + 97800 =
        // 325775
        let expected_usdc_limit = BigUint::from(325775u64) * BigUint::from(10u64).pow(6u32);

        // Total WBTC available: 1.0 + 2.5 + 1.5 = 5.0 WBTC
        let expected_wbtc_limit = BigUint::from(5u64) * BigUint::from(10u64).pow(8u32);

        assert_eq!(usdc_limit, expected_usdc_limit);
        assert_eq!(wbtc_limit, expected_wbtc_limit);
    }

    /// Bebop's book prices both directions, so what it cannot answer is a token that is not in
    /// the pair — whichever of the three questions it is asked.
    #[test]
    fn rejects_tokens_outside_the_pair() {
        let state = create_test_bebop_state();
        let amount = BigUint::from_str("1000000000000000000").unwrap();
        let results = [
            state
                .spot_price(&weth(), &usdc())
                .map(|_| ()),
            state
                .get_amount_out(amount.clone(), &weth(), &usdc())
                .map(|_| ()),
            state
                .get_amount_out(amount, &wbtc(), &weth())
                .map(|_| ()),
            state
                .get_limits(weth().address, usdc().address)
                .map(|_| ()),
        ];

        for result in results {
            assert!(
                matches!(&result, Err(SimulationError::InvalidInput(msg, None)) if msg.contains("Invalid token addresses")),
                "{result:?}"
            );
        }
    }

    /// A side the venue is not quoting has no depth to report and no swap to price.
    #[test]
    fn a_side_with_no_levels_has_nothing_to_offer() {
        let mut state = create_test_bebop_state();
        state.book.asks = Levels::default();

        assert!(matches!(
            state.get_amount_out(BigUint::from(2_000_000u64), &usdc(), &wbtc()),
            Err(SimulationError::InvalidInput(_, None))
        ));
        assert!(matches!(
            state.get_limits(usdc().address, wbtc().address),
            Err(SimulationError::RecoverableError(_))
        ));
    }

    #[test]
    fn get_amount_out_walks_the_ladder_on_both_sides() {
        // WETH/USDC
        let price_data = BebopPriceData {
            base: hex::decode("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").unwrap(), // WETH
            quote: hex::decode("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48").unwrap(), // USDC
            last_update_ts: 1234567890,
            bids: vec![3000.0f32, 2.0f32, 2900.0f32, 2.5f32],
            asks: vec![3100.0f32, 1.5f32, 3000.0f32, 3.0f32],
        };

        let weth = weth();
        let usdc = usdc();
        let state = BebopState {
            base_token: weth.clone(),
            quote_token: usdc.clone(),
            book: BebopBook::try_from(price_data).unwrap(),
            // The pair's quote token is USDC.
            usd_per_quote_token: 1.0,
            client: Some(empty_client()),
        };

        // swap 3 WETH -> USDC
        let amount_out_result = state
            .get_amount_out(BigUint::from_str("3_000000000000000000").unwrap(), &weth, &usdc)
            .unwrap();

        // 6000 from level 1 + 2900 from level 2 = 8900 USDC
        assert_eq!(amount_out_result.amount, BigUint::from_str("8900_000_000").unwrap());

        // swap 7000 USDC -> WETH
        let amount_out_result = state
            .get_amount_out(BigUint::from_str("7000_000_000").unwrap(), &usdc, &weth)
            .unwrap();

        // 1.5 from level 1 + 0.78333 from level 2 = 2.283333 WETH
        assert_eq!(amount_out_result.amount, BigUint::from_str("2_283333333333333248").unwrap());
    }

    /// The venue refuses a swap of nothing, so simulating one must not report a fill.
    #[test]
    fn rejects_a_zero_amount() {
        let state = create_test_bebop_state();

        let result = state.get_amount_out(BigUint::ZERO, &wbtc(), &usdc());

        assert!(matches!(result, Err(SimulationError::InvalidInput(_, None))), "{result:?}");
    }
}