docs: Document validation functions

This commit is contained in:
TAMARA LIPOWSKI
2025-02-05 16:44:28 -05:00
parent 021a179076
commit 2b43ecdf29
2 changed files with 23 additions and 0 deletions

View File

@@ -90,6 +90,14 @@ impl SplitSwapStrategyEncoder {
Ok(Self { permit2: Permit2::new(signer_pk, chain)?, selector, swap_encoder_registry })
}
/// Raises an error if the split percentages are invalid.
///
/// Split percentages are considered valid of all the following conditions are met:
/// * Each split amount is < 1 (100%)
/// * There is exactly one 0% split for each token, and it's the last swap specified, signifying
/// to the router to send the remainder of the token to the designated protocol
/// * The sum of all non-remainder splits for each token is < 1 (100%)
/// * There are no negative split amounts
fn validate_split_percentages(&self, swaps: &[Swap]) -> Result<(), EncodingError> {
let mut swaps_by_token: HashMap<Bytes, Vec<&Swap>> = HashMap::new();
for swap in swaps {
@@ -160,6 +168,12 @@ impl SplitSwapStrategyEncoder {
Ok(())
}
/// Raises an error if swaps do not represent a valid path from the given token to the checked
/// token.
///
/// A path is considered valid of all the following conditions are met:
/// * The checked token is reachable from the given token through the swap path
/// * There are tokens which are unconnected from the main path
fn validate_swap_path(
&self,
swaps: &[Swap],