docs: (WIP) In-code docs for encoders
- TODO double check all this, look for missing docs
This commit is contained in:
@@ -12,6 +12,7 @@ use tokio::runtime::Runtime;
|
||||
|
||||
use crate::encoding::{errors::EncodingError, evm::utils::encode_input};
|
||||
|
||||
/// A manager for checking if an approval is needed for interacting with a certain spender.
|
||||
pub struct ProtocolApprovalsManager {
|
||||
client: Arc<RootProvider<BoxTransport>>,
|
||||
runtime: Runtime,
|
||||
@@ -23,6 +24,9 @@ impl ProtocolApprovalsManager {
|
||||
let client = runtime.block_on(get_client())?;
|
||||
Ok(Self { client, runtime })
|
||||
}
|
||||
|
||||
/// Checks the current allowance for the given token, owner, and spender, and returns True
|
||||
/// if the current allowance is zero.
|
||||
pub fn approval_needed(
|
||||
&self,
|
||||
token: Address,
|
||||
|
||||
@@ -12,6 +12,12 @@ use crate::encoding::{
|
||||
strategy_encoder::{StrategyEncoder, StrategyEncoderRegistry},
|
||||
};
|
||||
|
||||
|
||||
/// Contains all supported strategies to encode a solution.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `strategies` - A hashmap containing the name of the strategy as a key and the strategy
|
||||
/// encoder as a value.
|
||||
pub struct EVMStrategyEncoderRegistry {
|
||||
strategies: HashMap<String, Box<dyn StrategyEncoder>>,
|
||||
}
|
||||
|
||||
@@ -54,6 +54,13 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the encoder for a swap strategy which supports single, sequential and split swaps.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
||||
/// * `permit2`: Permit2, the object containing necessary information for managing permit2 operations
|
||||
/// * `selector`: String, the selector for the swap function in the router contract
|
||||
pub struct SplitSwapStrategyEncoder {
|
||||
swap_encoder_registry: SwapEncoderRegistry,
|
||||
permit2: Permit2,
|
||||
@@ -213,7 +220,11 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
}
|
||||
|
||||
/// This strategy encoder is used for solutions that are sent directly to the pool.
|
||||
/// Only 1 solution with 1 swap is supported.
|
||||
/// Only one solution with one swap is supported.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
||||
pub struct ExecutorStrategyEncoder {
|
||||
swap_encoder_registry: SwapEncoderRegistry,
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ use crate::encoding::{
|
||||
swap_encoder::SwapEncoder,
|
||||
};
|
||||
|
||||
|
||||
/// Encodes a swap on a Uniswap V2 pool through the given executor address.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `executor_address` - The address of the executor contract that will perform the swap.
|
||||
/// * `executor_selector` - The selector of the swap function in the executor contract.
|
||||
#[derive(Clone)]
|
||||
pub struct UniswapV2SwapEncoder {
|
||||
executor_address: String,
|
||||
@@ -66,6 +72,11 @@ impl SwapEncoder for UniswapV2SwapEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Encodes a swap on a Uniswap V3 pool through the given executor address.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `executor_address` - The address of the executor contract that will perform the swap.
|
||||
/// * `executor_selector` - The selector of the swap function in the executor contract.
|
||||
#[derive(Clone)]
|
||||
pub struct UniswapV3SwapEncoder {
|
||||
executor_address: String,
|
||||
@@ -140,6 +151,11 @@ impl SwapEncoder for UniswapV3SwapEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Encodes a swap on a Balancer pool through the given executor address.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `executor_address` - The address of the executor contract that will perform the swap.
|
||||
/// * `executor_selector` - The selector of the swap function in the executor contract.
|
||||
#[derive(Clone)]
|
||||
pub struct BalancerV2SwapEncoder {
|
||||
executor_address: String,
|
||||
|
||||
@@ -11,8 +11,15 @@ use crate::encoding::{
|
||||
tycho_encoder::TychoEncoder,
|
||||
};
|
||||
|
||||
/// Represents an encoder for a swap through the given router address using any strategy supported
|
||||
/// by the strategy registry.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `strategy_registry`: S, the strategy registry to use to select the best strategy to encode a
|
||||
/// solution, based on its supported strategies and the solution attributes.
|
||||
/// * `router_address`: Bytes, the address of the router to use to execute the swaps.
|
||||
pub struct EVMTychoEncoder<S: StrategyEncoderRegistry> {
|
||||
strategy_selector: S,
|
||||
strategy_registry: S,
|
||||
router_address: Bytes,
|
||||
}
|
||||
|
||||
@@ -20,7 +27,7 @@ impl<S: StrategyEncoderRegistry> EVMTychoEncoder<S> {
|
||||
pub fn new(strategy_selector: S, router_address: String) -> Result<Self, EncodingError> {
|
||||
let router_address = Bytes::from_str(&router_address)
|
||||
.map_err(|_| EncodingError::FatalError("Invalid router address".to_string()))?;
|
||||
Ok(EVMTychoEncoder { strategy_selector, router_address })
|
||||
Ok(EVMTychoEncoder { strategy_registry: strategy_selector, router_address })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +89,7 @@ impl<S: StrategyEncoderRegistry> TychoEncoder<S> for EVMTychoEncoder<S> {
|
||||
.unwrap_or(self.router_address.clone());
|
||||
|
||||
let strategy = self
|
||||
.strategy_selector
|
||||
.strategy_registry
|
||||
.get_encoder(solution)?;
|
||||
let (contract_interaction, target_address) =
|
||||
strategy.encode_strategy(solution.clone(), router_address)?;
|
||||
|
||||
Reference in New Issue
Block a user