hylo-core 2.2.2

Core protocol data types, math, and utilities.
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
//! Oracle-derived collateral rebalancing price curves.
//!
//! Computes the price at which collateral trades against USDC based on
//! the protocol's current collateral ratio (CR) and oracle price range.
//!
//! Two independent curves:
//! * **Sell side** (low CR, 1.0–1.35): protocol sells collateral for USDC
//! * **Buy side** (high CR, 1.65–2.0+): protocol buys collateral with USDC

use anchor_lang::prelude::{
  borsh, AnchorDeserialize, AnchorSerialize, InitSpace,
};
use fix::prelude::*;
use serde::{Deserialize, Serialize};

use crate::error::CoreError;
use crate::fees::interp::{FixInterp, Point};
use crate::pyth::OraclePrice;
use crate::rebalance::mode::RebalanceMode;

const MIN_DEVIATION_PCT: UFix64<N9> = UFix64::constant(1);
pub const SELL_FLOOR_MAX_PCT: UFix64<N9> = UFix64::constant(5_000_000);
pub const SELL_CEIL_MAX_PCT: UFix64<N9> = UFix64::constant(5_000_000);
pub const BUY_FLOOR_MAX_PCT: UFix64<N9> = UFix64::constant(5_000_000);
pub const BUY_CEIL_MAX_PCT: UFix64<N9> = UFix64::constant(2_000_000);

/// Floor/ceil deviation percentages for rebalance price curve construction.
#[derive(
  Copy,
  Clone,
  Debug,
  PartialEq,
  InitSpace,
  AnchorSerialize,
  AnchorDeserialize,
  Serialize,
  Deserialize,
)]
pub struct RebalanceCurveConfig {
  pub floor_pct: UFixValue64,
  pub ceil_pct: UFixValue64,
}

impl RebalanceCurveConfig {
  #[must_use]
  pub fn new(
    floor_pct: UFixValue64,
    ceil_pct: UFixValue64,
  ) -> RebalanceCurveConfig {
    RebalanceCurveConfig {
      floor_pct,
      ceil_pct,
    }
  }

  /// Converts floor percentage discount to `UFix64`.
  ///
  /// # Errors
  /// * Conversion fails
  pub fn floor_pct(&self) -> Result<UFix64<N9>, CoreError> {
    Ok(self.floor_pct.try_into()?)
  }

  /// Converts ceil percentage premium to `UFix64`.
  ///
  /// # Errors
  /// * Conversion fails
  pub fn ceil_pct(&self) -> Result<UFix64<N9>, CoreError> {
    Ok(self.ceil_pct.try_into()?)
  }

  /// Validates a sell-side curve against its deviation caps.
  ///
  /// # Errors
  /// * Incorrect precision or out-of-range deviation
  pub fn validate_sell(self) -> Result<Self, CoreError> {
    let ok = |pct, max| (MIN_DEVIATION_PCT..=max).contains(&pct);
    (ok(self.floor_pct()?, SELL_FLOOR_MAX_PCT)
      && ok(self.ceil_pct()?, SELL_CEIL_MAX_PCT))
    .then_some(self)
    .ok_or(CoreError::RebalanceCurveConfigValidation)
  }

  /// Validates a buy-side curve against its deviation caps.
  ///
  /// # Errors
  /// * Incorrect precision or out-of-range deviation
  pub fn validate_buy(self) -> Result<Self, CoreError> {
    let ok = |pct, max| (MIN_DEVIATION_PCT..=max).contains(&pct);
    (ok(self.floor_pct()?, BUY_FLOOR_MAX_PCT)
      && ok(self.ceil_pct()?, BUY_CEIL_MAX_PCT))
    .then_some(self)
    .ok_or(CoreError::RebalanceCurveConfigValidation)
  }
}

/// Complement of a percentage: `1 − pct`.
///
/// # Errors
/// * Arithmetic underflow
fn complement(pct: UFix64<N9>) -> Result<UFix64<N9>, CoreError> {
  UFix64::<N9>::one()
    .checked_sub(&pct)
    .ok_or(CoreError::RebalancePercentArithmetic)
}

/// Markup of a percentage: `1 + pct`.
///
/// # Errors
/// * Arithmetic overflow
fn markup(pct: UFix64<N9>) -> Result<UFix64<N9>, CoreError> {
  UFix64::<N9>::one()
    .checked_add(&pct)
    .ok_or(CoreError::RebalancePercentArithmetic)
}

/// Convert unsigned CR to signed for curve lookup.
///
/// # Errors
/// * Conversion overflow
fn narrow(cr: UFix64<N9>) -> Result<IFix64<N9>, CoreError> {
  cr.narrow::<i64>()
    .ok_or(CoreError::RebalancePriceConversion)
}

/// Interpolated rebalance price controller.
/// Implementors define boundary behavior via
/// [`RebalancePriceController::price_inner`].
pub trait RebalancePriceController {
  /// Reference to the underlying interpolator.
  fn curve(&self) -> &FixInterp<2, N9>;

  /// Whether the given CR falls within the active domain.
  fn is_active(&self, ucr: UFix64<N9>) -> bool;

  /// Compute price for CR from underlying curve with boundary handling.
  ///
  /// # Errors
  /// * Domain or arithmetic errors.
  fn price_inner(&self, cr: IFix64<N9>) -> Result<IFix64<N9>, CoreError>;

  /// Slope of the price curve at the given CR.
  /// Zero on the flat region outside the active domain.
  ///
  /// # Errors
  /// * CR conversion, domain, or arithmetic
  fn price_slope(&self, ucr: UFix64<N9>) -> Result<IFix64<N9>, CoreError>;

  /// Collateral price at the given CR.
  ///
  /// # Errors
  /// * CR conversion, domain, or arithmetic
  fn price(&self, ucr: UFix64<N9>) -> Result<UFix64<N9>, CoreError> {
    let cr = narrow(ucr)?;
    self
      .price_inner(cr)?
      .narrow()
      .ok_or(CoreError::RebalancePriceConversion)
  }

  /// CR that produces the given price — inverse of [`price`](Self::price).
  ///
  /// Assumes `price` lies within the curve's `[floor, ceil]` range.
  ///
  /// ```txt
  /// cr = x_0 + (price - y_0) * (x_1 - x_0) / (y_1 - y_0)
  /// ```
  ///
  /// # Errors
  /// * Conversion or arithmetic
  fn cr_at_price(&self, price: UFix64<N9>) -> Result<UFix64<N9>, CoreError> {
    self
      .curve()
      .inverse_interpolate(narrow(price)?)?
      .narrow()
      .ok_or(CoreError::RebalancePriceConversion)
  }

  /// Validate curve invariants after construction.
  ///
  /// # Errors
  /// * Invariant violation (e.g. non-positive prices, floor >= ceil).
  fn validate(self) -> Result<Self, CoreError>
  where
    Self: Sized;
}

/// Sell side rebalance pricing curve.
/// Active when CR is low (below 1.35).
#[derive(Debug, Clone)]
pub struct SellPriceCurve {
  curve: FixInterp<2, N9>,
}

impl SellPriceCurve {
  /// Construct sell side price curve.
  ///
  /// # Errors
  /// * Arithmetic underflow/overflow
  /// * Conversion overflow
  pub fn new(
    OraclePrice { spot, .. }: OraclePrice,
    config: &RebalanceCurveConfig,
  ) -> Result<SellPriceCurve, CoreError> {
    let floor_mult = config.floor_pct().and_then(complement)?;
    let ceil_mult = config.ceil_pct().and_then(markup)?;
    let (floor, ceil) = spot
      .mul_div_floor(floor_mult, UFix64::one())
      .zip(spot.mul_div_ceil(ceil_mult, UFix64::one()))
      .ok_or(CoreError::RebalancePriceConstruction)?;
    let sell_zone_1 = RebalanceMode::SellZone1.active_range();
    let curve = FixInterp::from_points([
      Point {
        x: narrow(sell_zone_1.start()?)?,
        y: narrow(floor)?,
      },
      Point {
        x: narrow(sell_zone_1.end()?)?,
        y: narrow(ceil)?,
      },
    ])?;
    SellPriceCurve { curve }.validate()
  }
}

impl RebalancePriceController for SellPriceCurve {
  fn curve(&self) -> &FixInterp<2, N9> {
    &self.curve
  }

  fn is_active(&self, ucr: UFix64<N9>) -> bool {
    (RebalanceMode::SellZone2..RebalanceMode::Neutral)
      .contains(&RebalanceMode::from_cr(ucr))
  }

  fn price_inner(&self, cr: IFix64<N9>) -> Result<IFix64<N9>, CoreError> {
    let interp = self.curve();
    if cr < interp.x_min() {
      Ok(interp.y_min())
    } else if cr > interp.x_max() {
      Err(CoreError::RebalanceOutOfDomain)
    } else {
      interp.interpolate(cr)
    }
  }

  fn price_slope(&self, ucr: UFix64<N9>) -> Result<IFix64<N9>, CoreError> {
    let cr = narrow(ucr)?;
    let interp = self.curve();
    if cr < interp.x_min() {
      Ok(IFix64::zero())
    } else if cr > interp.x_max() {
      Err(CoreError::RebalanceOutOfDomain)
    } else {
      interp.derivative(cr)
    }
  }

  fn validate(self) -> Result<SellPriceCurve, CoreError> {
    let interp = self.curve();
    (interp.y_min() > IFix64::zero() && interp.y_min() < interp.y_max())
      .then_some(self)
      .ok_or(CoreError::RebalancePriceConstruction)
  }
}

/// Buy-side rebalance pricing curve.
/// Active when CR is high (above 1.65).
#[derive(Debug, Clone)]
pub struct BuyPriceCurve {
  curve: FixInterp<2, N9>,
}

impl BuyPriceCurve {
  /// Construct buy side price curve.
  ///
  /// # Errors
  /// * Arithmetic underflow/overflow
  /// * Precision conversion
  pub fn new(
    OraclePrice { spot, .. }: OraclePrice,
    config: &RebalanceCurveConfig,
  ) -> Result<BuyPriceCurve, CoreError> {
    let floor_mult = config.floor_pct().and_then(complement)?;
    let ceil_mult = config.ceil_pct().and_then(markup)?;
    let (floor, ceil) = spot
      .mul_div_floor(floor_mult, UFix64::one())
      .zip(spot.mul_div_ceil(ceil_mult, UFix64::one()))
      .ok_or(CoreError::RebalancePriceConstruction)?;
    let buy_zone_1 = RebalanceMode::BuyZone1.active_range();
    let curve = FixInterp::from_points([
      Point {
        x: narrow(buy_zone_1.start()?)?,
        y: narrow(floor)?,
      },
      Point {
        x: narrow(buy_zone_1.end()?)?,
        y: narrow(ceil)?,
      },
    ])?;
    BuyPriceCurve { curve }.validate()
  }
}

impl RebalancePriceController for BuyPriceCurve {
  fn curve(&self) -> &FixInterp<2, N9> {
    &self.curve
  }

  fn is_active(&self, ucr: UFix64<N9>) -> bool {
    RebalanceMode::from_cr(ucr) > RebalanceMode::Neutral
  }

  fn price_inner(&self, cr: IFix64<N9>) -> Result<IFix64<N9>, CoreError> {
    let interp = self.curve();
    if cr < interp.x_min() {
      Err(CoreError::RebalanceOutOfDomain)
    } else if cr > interp.x_max() {
      Ok(interp.y_max())
    } else {
      interp.interpolate(cr)
    }
  }

  fn price_slope(&self, ucr: UFix64<N9>) -> Result<IFix64<N9>, CoreError> {
    let cr = narrow(ucr)?;
    let interp = self.curve();
    if cr < interp.x_min() {
      Err(CoreError::RebalanceOutOfDomain)
    } else if cr > interp.x_max() {
      Ok(IFix64::zero())
    } else {
      interp.derivative(cr)
    }
  }

  fn validate(self) -> Result<BuyPriceCurve, CoreError> {
    let interp = self.curve();
    (interp.y_min() > IFix64::zero() && interp.y_min() < interp.y_max())
      .then_some(self)
      .ok_or(CoreError::RebalancePriceConstruction)
  }
}

#[cfg(test)]
mod tests {
  use more_asserts::*;
  use proptest::prelude::*;

  use super::*;
  use crate::error::CoreError;
  use crate::pyth::OraclePrice;

  const ORACLE: OraclePrice = OraclePrice {
    spot: UFix64::constant(146_401_109_370),
    conf: UFix64::constant(94_635_820),
  };

  const SELL_CONFIG: RebalanceCurveConfig = RebalanceCurveConfig {
    floor_pct: UFixValue64 {
      bits: 10_000_000,
      exp: -9,
    },
    ceil_pct: UFixValue64 {
      bits: 5_000_000,
      exp: -9,
    },
  };

  const BUY_CONFIG: RebalanceCurveConfig = RebalanceCurveConfig {
    floor_pct: UFixValue64 {
      bits: 5_000_000,
      exp: -9,
    },
    ceil_pct: UFixValue64 {
      bits: 10_000_000,
      exp: -9,
    },
  };

  const UCR_1_00: UFix64<N9> = UFix64::constant(1_000_000_000);
  const UCR_1_15: UFix64<N9> = UFix64::constant(1_150_000_000);
  const UCR_1_20: UFix64<N9> = UFix64::constant(1_200_000_000);
  const UCR_1_275: UFix64<N9> = UFix64::constant(1_275_000_000);
  const UCR_1_35: UFix64<N9> = UFix64::constant(1_350_000_000);
  const UCR_1_40: UFix64<N9> = UFix64::constant(1_400_000_000);
  const UCR_1_60: UFix64<N9> = UFix64::constant(1_600_000_000);
  const UCR_1_65: UFix64<N9> = UFix64::constant(1_650_000_000);
  const UCR_1_70: UFix64<N9> = UFix64::constant(1_700_000_000);
  const UCR_1_75: UFix64<N9> = UFix64::constant(1_750_000_000);
  const UCR_1_80: UFix64<N9> = UFix64::constant(1_800_000_000);
  const UCR_2_50: UFix64<N9> = UFix64::constant(2_500_000_000);

  #[test]
  fn sell_constructs() -> Result<(), CoreError> {
    SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    Ok(())
  }

  #[test]
  fn buy_constructs() -> Result<(), CoreError> {
    BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    Ok(())
  }

  #[test]
  fn sell_flat_below_domain() -> Result<(), CoreError> {
    let curve = SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    assert_eq!(curve.price(UCR_1_00)?, curve.price(UCR_1_15)?);
    Ok(())
  }

  #[test]
  fn sell_inactive_above_domain() -> Result<(), CoreError> {
    let curve = SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    assert_eq!(
      curve.price(UCR_1_40).err(),
      Some(CoreError::RebalanceOutOfDomain)
    );
    Ok(())
  }

  #[test]
  fn sell_endpoints() -> Result<(), CoreError> {
    let curve = SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    let at_floor = curve.price(UCR_1_20)?;
    let at_ceil = curve.price(UCR_1_35)?;
    assert_lt!(at_floor, at_ceil);
    assert_eq!(at_floor, curve.price(UCR_1_00)?);
    Ok(())
  }

  #[test]
  fn buy_inactive_below_domain() -> Result<(), CoreError> {
    let curve = BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    assert_eq!(
      curve.price(UCR_1_60).err(),
      Some(CoreError::RebalanceOutOfDomain)
    );
    Ok(())
  }

  #[test]
  fn buy_flat_above_domain() -> Result<(), CoreError> {
    let curve = BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    assert_eq!(curve.price(UCR_1_80)?, curve.price(UCR_2_50)?);
    Ok(())
  }

  #[test]
  fn buy_endpoints() -> Result<(), CoreError> {
    let curve = BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    let at_floor = curve.price(UCR_1_65)?;
    let at_ceil = curve.price(UCR_1_75)?;
    assert_lt!(at_floor, at_ceil);
    assert_eq!(at_ceil, curve.price(UCR_2_50)?);
    Ok(())
  }

  #[test]
  fn sell_endpoint_values() -> Result<(), CoreError> {
    let curve = SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    assert_eq!(curve.price(UCR_1_20)?, UFix64::constant(144_937_098_276));
    assert_eq!(curve.price(UCR_1_35)?, UFix64::constant(147_133_114_917));
    Ok(())
  }

  #[test]
  fn buy_endpoint_values() -> Result<(), CoreError> {
    let curve = BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    assert_eq!(curve.price(UCR_1_65)?, UFix64::constant(145_669_103_823));
    assert_eq!(curve.price(UCR_1_75)?, UFix64::constant(147_865_120_464));
    Ok(())
  }

  #[test]
  fn sell_midpoint_value() -> Result<(), CoreError> {
    let curve = SellPriceCurve::new(ORACLE, &SELL_CONFIG)?;
    assert_eq!(curve.price(UCR_1_275)?, UFix64::constant(146_035_106_597));
    Ok(())
  }

  #[test]
  fn buy_midpoint_value() -> Result<(), CoreError> {
    let curve = BuyPriceCurve::new(ORACLE, &BUY_CONFIG)?;
    assert_eq!(curve.price(UCR_1_70)?, UFix64::constant(146_767_112_144));
    Ok(())
  }

  fn config(floor: u64, ceil: u64) -> RebalanceCurveConfig {
    RebalanceCurveConfig {
      floor_pct: UFixValue64 {
        bits: floor,
        exp: -9,
      },
      ceil_pct: UFixValue64 {
        bits: ceil,
        exp: -9,
      },
    }
  }

  #[test]
  fn validate_accepts_in_range() -> Result<(), CoreError> {
    let sell = config(3_000_000, 3_000_000);
    let buy = config(3_000_000, 1_000_000);
    assert_eq!(sell.validate_sell()?, sell);
    assert_eq!(buy.validate_buy()?, buy);
    Ok(())
  }

  #[test]
  fn validate_enforces_side_caps() {
    let err = Some(CoreError::RebalanceCurveConfigValidation);
    assert_eq!(config(6_000_000, 1_000_000).validate_sell().err(), err);
    assert_eq!(config(1_000_000, 3_000_000).validate_buy().err(), err);
  }

  #[test]
  fn validate_rejects_above_max_deviation() {
    let err = Some(CoreError::RebalanceCurveConfigValidation);
    assert_eq!(config(1_000_000, 20_000_001).validate_sell().err(), err);
    assert_eq!(config(20_000_001, 1_000_000).validate_buy().err(), err);
  }

  #[test]
  fn validate_rejects_zero_band() {
    let err = Some(CoreError::RebalanceCurveConfigValidation);
    assert_eq!(config(0, 0).validate_sell().err(), err);
    assert_eq!(config(0, 0).validate_buy().err(), err);
  }

  #[test]
  fn floor_pct_above_one_underflows() {
    let config = RebalanceCurveConfig {
      floor_pct: UFixValue64 {
        bits: 1_010_000_000,
        exp: -9,
      },
      ceil_pct: SELL_CONFIG.ceil_pct,
    };
    assert_eq!(
      SellPriceCurve::new(ORACLE, &config).err(),
      Some(CoreError::RebalancePercentArithmetic)
    );
  }

  fn sell_cr() -> BoxedStrategy<UFix64<N9>> {
    (1_000_000_000u64..1_350_000_000)
      .prop_map(UFix64::new)
      .boxed()
  }

  fn buy_cr() -> BoxedStrategy<UFix64<N9>> {
    (1_650_000_000u64..4_000_000_000)
      .prop_map(UFix64::new)
      .boxed()
  }

  fn oracle_spot() -> BoxedStrategy<UFix64<N9>> {
    (10_000_000_000u64..1_000_000_000_000)
      .prop_map(UFix64::new)
      .boxed()
  }

  fn oracle_ci() -> BoxedStrategy<UFix64<N9>> {
    (10_000u64..500_000_000).prop_map(UFix64::new).boxed()
  }

  fn spot_band(
    spot: UFix64<N9>,
    config: &RebalanceCurveConfig,
  ) -> Result<(UFix64<N9>, UFix64<N9>), CoreError> {
    let floor = spot
      .mul_div_floor(complement(config.floor_pct()?)?, UFix64::one())
      .ok_or(CoreError::RebalancePriceConstruction)?;
    let ceil = spot
      .mul_div_ceil(markup(config.ceil_pct()?)?, UFix64::one())
      .ok_or(CoreError::RebalancePriceConstruction)?;
    Ok((floor, ceil))
  }

  proptest! {
    #[test]
    fn sell_price_in_spot_band(
      cr in sell_cr(),
      spot in oracle_spot(),
      conf in oracle_ci(),
    ) {
      let oracle = OraclePrice { spot, conf };
      if let Ok(curve) = SellPriceCurve::new(oracle, &SELL_CONFIG) {
        let (floor, ceil) = spot_band(spot, &SELL_CONFIG)
          .map_err(|e| TestCaseError::fail(format!("{e}")))?;
        let price = curve
          .price(cr)
          .map_err(|e| TestCaseError::fail(format!("{e}")))?;
        prop_assert_eq!(curve.price(UCR_1_20)?, floor);
        prop_assert_eq!(curve.price(UCR_1_35)?, ceil);
        prop_assert!(price >= floor && price <= ceil);
      }
    }

    #[test]
    fn buy_price_in_spot_band(
      cr in buy_cr(),
      spot in oracle_spot(),
      conf in oracle_ci(),
    ) {
      let oracle = OraclePrice { spot, conf };
      if let Ok(curve) = BuyPriceCurve::new(oracle, &BUY_CONFIG) {
        let (floor, ceil) = spot_band(spot, &BUY_CONFIG)
          .map_err(|e| TestCaseError::fail(format!("{e}")))?;
        let price = curve
          .price(cr)
          .map_err(|e| TestCaseError::fail(format!("{e}")))?;
        prop_assert_eq!(curve.price(UCR_1_65)?, floor);
        prop_assert_eq!(curve.price(UCR_1_75)?, ceil);
        prop_assert!(price >= floor && price <= ceil);
      }
    }
  }
}