1#[cfg(not(feature = "std"))]
2use alloc::vec::Vec;
3#[cfg(feature = "scale")]
4use codec::{Decode, Encode};
5#[cfg(feature = "scale")]
6use scale_info::TypeInfo;
7
8pub trait Currency: Ord + Clone {}
10impl<T: Ord + Clone> Currency for T {}
11
12pub trait Amount: Copy + TryInto<u128> + TryFrom<u128> {}
14impl<T: Copy + TryInto<u128> + TryFrom<u128>> Amount for T {}
15
16pub trait Provider: Ord + Clone {}
18impl<T: Ord + Clone> Provider for T {}
19
20#[derive(Clone, Eq, PartialEq, Debug, Ord, PartialOrd)]
22#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
23pub struct Pair<C: Currency> {
24 pub source: C,
25 pub target: C,
26}
27
28#[derive(Clone, Eq, PartialEq, Debug, Ord, PartialOrd)]
30#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
31pub struct ProviderPair<C: Currency, P: Provider> {
32 pub pair: Pair<C>,
33 pub provider: P,
34}
35
36#[derive(Clone, Eq, PartialEq, Debug)]
38#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
39pub struct PricePath<C: Currency, A: Amount, P: Provider> {
40 pub total_cost: A,
41 pub steps: Vec<PathStep<C, A, P>>,
42}
43
44#[derive(Clone, Eq, PartialEq, Debug)]
46#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
47pub struct PathStep<C: Currency, A: Amount, P: Provider> {
48 pub pair: Pair<C>,
49 pub provider: P,
50 pub cost: A,
51}
52
53#[derive(Debug)]
54pub enum CalculatorError {
55 NegativeCyclesError,
56 ConversionError,
57}