mpl_gavel/
utils.rs

1use crate::types::{Configuration, Mode, Tick};
2
3pub struct AggregatedConfiguration {
4    // Auction mode.
5    pub mode: Mode,
6    /// Maximum number of bids.
7    pub capacity: u32,
8    /// Starting bid value.
9    pub start_value: u64,
10    /// Minimum bid value.
11    pub minimum_value: u64,
12    /// Amount by which the price must increament over the lowest.
13    pub tick_value: u64,
14    /// Indicates the tick increment type.
15    pub tick: Tick,
16    /// Date to start the auction.
17    pub start_date: i64,
18    /// Date to end the auction.
19    pub end_date: i64,
20    /// Indicates the amount to extend the end date when a bid is
21    /// placed near the end.
22    pub grace_period: i64,
23    /// Refund fee percentage for unsuccessful bids.
24    pub refund_fee: u16,
25}
26
27impl From<Configuration> for AggregatedConfiguration {
28    fn from(configuration: Configuration) -> Self {
29        match configuration {
30            Configuration::UniformPriceV1 {
31                capacity,
32                start_date,
33                end_date,
34                grace_period,
35                minimum_value,
36                tick_value,
37                tick,
38                refund_fee,
39            } => Self {
40                mode: Mode::UniformPrice,
41                capacity,
42                start_date,
43                end_date,
44                grace_period,
45                // start value is the same as the minumum value
46                start_value: minimum_value,
47                minimum_value,
48                tick_value,
49                tick,
50                refund_fee,
51            },
52            Configuration::EnglishV1 {
53                start_date,
54                end_date,
55                start_value,
56                tick_value,
57                tick,
58                grace_period,
59                refund_fee,
60            } => Self {
61                mode: Mode::English,
62                capacity: 1,
63                start_date,
64                end_date,
65                grace_period,
66                start_value,
67                // minimum value is the start value
68                minimum_value: start_value,
69                tick_value,
70                tick,
71                refund_fee,
72            },
73            Configuration::DutchV1 {
74                capacity,
75                start_date,
76                end_date,
77                start_value,
78                minimum_value,
79                refund_fee,
80            } => Self {
81                mode: Mode::Dutch,
82                capacity,
83                start_date,
84                end_date,
85                grace_period: 0,
86                start_value,
87                minimum_value,
88                tick_value: 0,
89                tick: Tick::Absolute,
90                refund_fee,
91            },
92            Configuration::DutlishV1 {
93                start_date,
94                end_date,
95                grace_period,
96                start_value,
97                minimum_value,
98                tick_value,
99                tick,
100                refund_fee,
101                ..
102            } => Self {
103                mode: Mode::Dutlish,
104                capacity: 1,
105                start_date,
106                end_date,
107                grace_period,
108                start_value,
109                minimum_value,
110                tick_value,
111                tick,
112                refund_fee,
113            },
114        }
115    }
116}