feat(univ4): Pass user_data as hook_data in execution
Because we don't know the size of hook data, it needs to be at the end of the protocol data. But we also don't know the size of the intermediary swaps. To solve this, we are now ple encoding the intermediary swaps and only then appending the hook data Took 2 hours 50 minutes Took 40 seconds
This commit is contained in:
committed by
Diana Carvalho
parent
a0581773cd
commit
93678d9d19
@@ -121,16 +121,25 @@ impl StrategyEncoder for SingleSwapStrategyEncoder {
|
||||
transfer_type: transfer,
|
||||
};
|
||||
|
||||
let mut grouped_protocol_data: Vec<u8> = vec![];
|
||||
let mut grouped_protocol_data: Vec<Vec<u8>> = vec![];
|
||||
let mut initial_protocol_data: Vec<u8> = vec![];
|
||||
for swap in grouped_swap.swaps.iter() {
|
||||
let protocol_data = swap_encoder.encode_swap(swap, &encoding_context)?;
|
||||
grouped_protocol_data.extend(protocol_data);
|
||||
if encoding_context.group_token_in == swap.token_in {
|
||||
initial_protocol_data = protocol_data;
|
||||
} else {
|
||||
grouped_protocol_data.push(protocol_data);
|
||||
}
|
||||
}
|
||||
|
||||
if !grouped_protocol_data.is_empty() {
|
||||
initial_protocol_data.extend(ple_encode(grouped_protocol_data));
|
||||
}
|
||||
|
||||
let swap_data = self.encode_swap_header(
|
||||
Bytes::from_str(swap_encoder.executor_address())
|
||||
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?,
|
||||
grouped_protocol_data,
|
||||
initial_protocol_data,
|
||||
);
|
||||
Ok(EncodedSolution {
|
||||
function_signature: self.function_signature.clone(),
|
||||
@@ -269,17 +278,26 @@ impl StrategyEncoder for SequentialSwapStrategyEncoder {
|
||||
transfer_type: transfer,
|
||||
};
|
||||
|
||||
let mut grouped_protocol_data: Vec<u8> = vec![];
|
||||
let mut grouped_protocol_data: Vec<Vec<u8>> = vec![];
|
||||
let mut initial_protocol_data: Vec<u8> = vec![];
|
||||
for swap in grouped_swap.swaps.iter() {
|
||||
let protocol_data = swap_encoder.encode_swap(swap, &encoding_context)?;
|
||||
grouped_protocol_data.extend(protocol_data);
|
||||
if encoding_context.group_token_in == swap.token_in {
|
||||
initial_protocol_data = protocol_data;
|
||||
} else {
|
||||
grouped_protocol_data.push(protocol_data);
|
||||
}
|
||||
}
|
||||
|
||||
if !grouped_protocol_data.is_empty() {
|
||||
initial_protocol_data.extend(ple_encode(grouped_protocol_data));
|
||||
}
|
||||
|
||||
let swap_data = self.encode_swap_header(
|
||||
Bytes::from_str(swap_encoder.executor_address()).map_err(|_| {
|
||||
EncodingError::FatalError("Invalid executor address".to_string())
|
||||
})?,
|
||||
grouped_protocol_data,
|
||||
initial_protocol_data,
|
||||
);
|
||||
swaps.push(swap_data);
|
||||
}
|
||||
@@ -458,10 +476,19 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
transfer_type: transfer,
|
||||
};
|
||||
|
||||
let mut grouped_protocol_data: Vec<u8> = vec![];
|
||||
let mut grouped_protocol_data: Vec<Vec<u8>> = vec![];
|
||||
let mut initial_protocol_data: Vec<u8> = vec![];
|
||||
for swap in grouped_swap.swaps.iter() {
|
||||
let protocol_data = swap_encoder.encode_swap(swap, &encoding_context)?;
|
||||
grouped_protocol_data.extend(protocol_data);
|
||||
if encoding_context.group_token_in == swap.token_in {
|
||||
initial_protocol_data = protocol_data;
|
||||
} else {
|
||||
grouped_protocol_data.push(protocol_data);
|
||||
}
|
||||
}
|
||||
|
||||
if !grouped_protocol_data.is_empty() {
|
||||
initial_protocol_data.extend(ple_encode(grouped_protocol_data));
|
||||
}
|
||||
|
||||
let swap_data = self.encode_swap_header(
|
||||
@@ -471,7 +498,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
Bytes::from_str(swap_encoder.executor_address()).map_err(|_| {
|
||||
EncodingError::FatalError("Invalid executor address".to_string())
|
||||
})?,
|
||||
grouped_protocol_data,
|
||||
initial_protocol_data,
|
||||
);
|
||||
swaps.push(swap_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user