• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gnosis / dex-services / 4463 / 3
31%
master: 31%

Build:
DEFAULT BRANCH: master
Ran 31 Jul 2020 10:09AM UTC
Files 86
Run time 28s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

31 Jul 2020 09:51AM UTC coverage: 28.264% (-0.002%) from 28.266%
OPEN_SOLVER_VERSION=v0.0.11 PRIVATE_SOLVER_VERSION=v0.8.2

push

travis-pro

web-flow
Allow average price source to be used with references (#1215)

The struct AveragePriceSource forces ownership semantics onto the user.
We extract the average computation out of the struct so that it can be
used with references.
This is going to be useful for the price estimator where it won't be possible for AveragePriceSource to own the pricegraph based price source but we nonetheless want to calculate the average by reusing the existing code.

### Test Plan
No logic change, existing tests still work.

---

I also tried to make a more advanced version that makes the average price source generic over whether it owns the price source or has references. 

```rust
struct AveragePriceSource_<T0, T1: ?Sized, T2> {
    t: T0,
    _t1: PhantomData<T1>,
    _t2: PhantomData<T2>,
}

impl<'a, T0, T1, T2> AveragePriceSource_<T0, T1, T2>
where
    T0: AsRef<T1>,
    T1: 'a + ?Sized,
    &'a T1: IntoIterator<Item = T2>,
    T2: AsRef<dyn PriceSource + 'a>,
{
    fn new(t: T0) -> Self {
        Self {
            t,
            _t1: PhantomData,
            _t2: PhantomData,
        }
    }

    async fn get_prices(&'a self, tokens: &[TokenId]) -> Result<HashMap<TokenId, NonZeroU128>> {
        // For brevity we return the result of the first price source but in the real code we would average.
        let t1: &'a T1 = self.t.as_ref();
        let mut iter = t1.into_iter();
        let first = iter.next().unwrap();
        let source: &dyn PriceSource = first.as_ref();
        source.get_prices(tokens).await
    }
}

#[test]
fn compiles() {
    type BoxDyn = Box<dyn PriceSource>;

    let owned: Vec<BoxDyn> = Vec::new();
    let _ = AveragePriceSource_::<_, [BoxDyn], _>::new(owned).get_prices(&[]);

    let slice: &[BoxDyn] = &[];
    let _ = AveragePriceSource_::<_, [BoxDyn], _>::new(slice).get_prices(&[]);

    let slice_of_references: &[&BoxDyn] = &[];
    let _ = AveragePriceSource_::<_, [&BoxDyn], _>::new(s... (continued)

11357 of 45842 branches covered (24.77%)

Branch coverage included in aggregate %.

2970 of 4848 relevant lines covered (61.26%)

12601.83 hits per line

Source Files on job 4463.3 (OPEN_SOLVER_VERSION=v0.0.11 PRIVATE_SOLVER_VERSION=v0.8.2)
  • Tree
  • List 0
  • Changed 26
  • Source Changed 1
  • Coverage Changed 26
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Build 943
  • Travis Job 4463.3
  • 9e1afb20 on github
  • Prev Job for OPEN_SOLVER_VERSION=v0.0.11 PRIVATE_SOLVER_VERSION=v0.8.2 on master (#4459.3)
  • Next Job for OPEN_SOLVER_VERSION=v0.0.11 PRIVATE_SOLVER_VERSION=v0.8.2 on master (#4465.3)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc