-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsolution.rs
More file actions
90 lines (88 loc) · 3.78 KB
/
solution.rs
File metadata and controls
90 lines (88 loc) · 3.78 KB
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
use {
crate::domain::{eth, solution},
dto::solution::*,
};
/// Creates a new solution DTO from its domain object.
pub fn from_domain(solutions: &[solution::Solution]) -> dto::solution::SolverResponse {
dto::solution::SolverResponse::Solutions {
solutions: solutions
.iter()
.map(|solution| Solution {
id: solution.id.0,
prices: solution
.prices
.0
.iter()
.map(|(token, price)| (token.0, *price))
.collect(),
trades: solution
.trades
.iter()
.map(|trade| match trade {
solution::Trade::Fulfillment(trade) => Trade::Fulfillment(Fulfillment {
order: OrderUid(trade.order().uid.0),
executed_amount: trade.executed().amount,
fee: trade.surplus_fee().map(|fee| fee.amount),
}),
})
.collect(),
pre_interactions: interaction_data_from_domain(&solution.pre_interactions),
post_interactions: interaction_data_from_domain(&solution.post_interactions),
interactions: solution
.interactions
.iter()
.map(|interaction| match interaction {
solution::Interaction::Custom(interaction) => {
Interaction::Custom(CustomInteraction {
target: interaction.target,
value: interaction.value.0,
calldata: interaction.calldata.clone(),
internalize: interaction.internalize,
allowances: interaction
.allowances
.iter()
.map(|allowance| Allowance {
token: allowance.asset.token.0,
amount: allowance.asset.amount,
spender: allowance.spender,
})
.collect(),
inputs: interaction
.inputs
.iter()
.map(|i| Asset {
token: i.token.0,
amount: i.amount,
})
.collect(),
outputs: interaction
.outputs
.iter()
.map(|o| Asset {
token: o.token.0,
amount: o.amount,
})
.collect(),
})
}
})
.collect(),
gas: solution
.gas
.map(|gas| u64::try_from(gas.0).expect("value overflows u64::MAX")),
flashloans: None,
wrappers: Default::default(),
})
.collect(),
}
}
fn interaction_data_from_domain(interaction_data: &[eth::Interaction]) -> Vec<Call> {
interaction_data
.iter()
.map(|interaction| Call {
target: interaction.target,
value: interaction.value.0,
calldata: interaction.calldata.clone(),
})
.collect()
}