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
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[cfg(feature = "scale")]
use codec::{Decode, Encode};
#[cfg(feature = "scale")]
use scale_info::TypeInfo;
pub trait Currency: Ord + Clone + AsRef<[u8]> {}
impl<T: Ord + Clone + AsRef<[u8]>> Currency for T {}
pub trait Amount: Clone + Copy + TryInto<u128> + TryFrom<u128> {}
impl<T: Clone + Copy + TryInto<u128> + TryFrom<u128>> Amount for T {}
pub trait Provider: Ord + Clone {}
impl<T: Ord + Clone> Provider for T {}
#[derive(Clone, Eq, PartialEq, Debug, Ord, PartialOrd)]
#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
pub struct Pair<C: Currency> {
pub source: C,
pub target: C,
}
#[derive(Clone, Eq, PartialEq, Debug, Ord, PartialOrd)]
#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
pub struct ProviderPair<C: Currency, P: Provider> {
pub pair: Pair<C>,
pub provider: P,
}
#[derive(Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
pub struct PricePath<C: Currency, A: Amount, P: Provider> {
pub total_cost: A,
pub steps: Vec<PathStep<C, A, P>>,
}
#[derive(Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "scale", derive(Encode, Decode, TypeInfo))]
pub struct PathStep<C: Currency, A: Amount, P: Provider> {
pub pair: Pair<C>,
pub provider: P,
pub cost: A,
}
#[derive(Debug)]
pub enum CalculatorError {
NegativeCyclesError,
ConversionError,
}