From 359bb806f7026f3186d677e7fba8216d46709e9b Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Wed, 19 Feb 2025 17:02:32 +0000 Subject: [PATCH] docs: Add docstrings to EVMEncoderBuilder --- don't change below this line --- ENG-4246 Took 41 minutes --- src/encoding/evm/encoder_builder.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/encoding/evm/encoder_builder.rs b/src/encoding/evm/encoder_builder.rs index 332d253..efb6e73 100644 --- a/src/encoding/evm/encoder_builder.rs +++ b/src/encoding/evm/encoder_builder.rs @@ -10,6 +10,9 @@ use crate::encoding::{ strategy_encoder::StrategyEncoder, }; +/// Builder pattern for constructing an `EVMTychoEncoder` with customizable options. +/// +/// This struct allows setting a chain and strategy encoder before building the final encoder. pub struct EVMEncoderBuilder { strategy: Option>, chain: Option, @@ -29,10 +32,18 @@ impl EVMEncoderBuilder { self.chain = Some(chain); self } + + /// Sets the `strategy_encoder` manually. + /// + /// **Note**: This method should not be used in combination with `tycho_router` or + /// `direct_execution`. pub fn strategy_encoder(mut self, strategy: Box) -> Self { self.strategy = Some(strategy); self } + + /// Shortcut method to initialize a `SplitSwapStrategyEncoder` with a given `swapper_pk`. + /// **Note**: Should not be used at the same time as `strategy_encoder`. pub fn tycho_router( self, swapper_pk: String, @@ -45,10 +56,13 @@ impl EVMEncoderBuilder { Ok(EVMEncoderBuilder { chain: Some(chain), strategy: Some(strategy) }) } else { Err(EncodingError::FatalError( - "Please set the chain before setting the strategy".to_string(), + "Please set the chain before setting the tycho router".to_string(), )) } } + + /// Shortcut method to initialize an `ExecutorStrategyEncoder`. + /// **Note**: Should not be used at the same time as `strategy_encoder`. pub fn direct_execution( self, executors_file_path: Option, @@ -64,6 +78,8 @@ impl EVMEncoderBuilder { } } + /// Builds the `EVMTychoEncoder` instance using the configured chain and strategy. + /// Returns an error if either the chain or strategy has not been set. pub fn build(self) -> Result { if let (Some(chain), Some(strategy)) = (self.chain, self.strategy) { EVMTychoEncoder::new(chain, strategy)