feat: Add estimated_amount_in to Swap. Add SwapBuilder
Use SwapBuilder everywhere inside crate Integration tests will be done later --- don't change below this line --- ENG-4696 Took 1 hour 56 minutes Took 4 minutes
This commit is contained in:
@@ -89,6 +89,9 @@ pub struct Swap<'a> {
|
||||
/// Optional protocol state used to perform the swap.
|
||||
#[serde(skip)]
|
||||
pub protocol_state: Option<&'a dyn ProtocolSim>,
|
||||
/// Optional estimated amount in for this Swap. This is necessary for RFQ protocols. This value
|
||||
/// is used to request the quote
|
||||
pub estimated_amount_in: Option<BigUint>,
|
||||
}
|
||||
|
||||
impl<'a> Swap<'a> {
|
||||
@@ -99,8 +102,17 @@ impl<'a> Swap<'a> {
|
||||
split: f64,
|
||||
user_data: Option<Bytes>,
|
||||
protocol_state: Option<&'a dyn ProtocolSim>,
|
||||
estimated_amount_in: Option<BigUint>,
|
||||
) -> Self {
|
||||
Self { component: component.into(), token_in, token_out, split, user_data, protocol_state }
|
||||
Self {
|
||||
component: component.into(),
|
||||
token_in,
|
||||
token_out,
|
||||
split,
|
||||
user_data,
|
||||
protocol_state,
|
||||
estimated_amount_in,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +127,66 @@ impl<'a> PartialEq for Swap<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwapBuilder<'a> {
|
||||
component: ProtocolComponent,
|
||||
token_in: Bytes,
|
||||
token_out: Bytes,
|
||||
split: f64,
|
||||
user_data: Option<Bytes>,
|
||||
protocol_state: Option<&'a dyn ProtocolSim>,
|
||||
estimated_amount_in: Option<BigUint>,
|
||||
}
|
||||
|
||||
impl<'a> SwapBuilder<'a> {
|
||||
pub fn new<T: Into<ProtocolComponent>>(
|
||||
component: T,
|
||||
token_in: Bytes,
|
||||
token_out: Bytes,
|
||||
) -> Self {
|
||||
Self {
|
||||
component: component.into(),
|
||||
token_in,
|
||||
token_out,
|
||||
split: 0.0,
|
||||
user_data: None,
|
||||
protocol_state: None,
|
||||
estimated_amount_in: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn split(mut self, split: f64) -> Self {
|
||||
self.split = split;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_data(mut self, user_data: Bytes) -> Self {
|
||||
self.user_data = Some(user_data);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn protocol_state(mut self, protocol_state: &'a dyn ProtocolSim) -> Self {
|
||||
self.protocol_state = Some(protocol_state);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn estimated_amount_in(mut self, estimated_amount_in: BigUint) -> Self {
|
||||
self.estimated_amount_in = Some(estimated_amount_in);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Swap<'a> {
|
||||
Swap {
|
||||
component: self.component,
|
||||
token_in: self.token_in,
|
||||
token_out: self.token_out,
|
||||
split: self.split,
|
||||
user_data: self.user_data,
|
||||
protocol_state: self.protocol_state,
|
||||
estimated_amount_in: self.estimated_amount_in,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a transaction to be executed.
|
||||
///
|
||||
/// # Fields
|
||||
@@ -262,6 +334,7 @@ mod tests {
|
||||
0.5,
|
||||
user_data.clone(),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
assert_eq!(swap.token_in, Bytes::from("0x12"));
|
||||
assert_eq!(swap.token_out, Bytes::from("0x34"));
|
||||
|
||||
Reference in New Issue
Block a user