fix: in hashflow's encode_swap, fail early if router address is not present

This commit is contained in:
adrian
2025-08-20 10:07:16 +02:00
committed by Adrian Benavides
parent 2b9f9a99f2
commit c506f2c048

View File

@@ -888,27 +888,28 @@ impl SwapEncoder for HashflowSwapEncoder {
encoding_context: &EncodingContext, encoding_context: &EncodingContext,
) -> Result<Vec<u8>, EncodingError> { ) -> Result<Vec<u8>, EncodingError> {
// Native tokens doesn't need approval, only ERC20 tokens do // Native tokens doesn't need approval, only ERC20 tokens do
let approval_needed: bool; let sender = encoding_context
if let Some(router_address) = &encoding_context.router_address { .router_address
let tycho_router_address = bytes_to_address(router_address)?; .clone()
let hashflow_router_address = Address::from_str(&self.hashflow_router_address) .ok_or(EncodingError::FatalError(
.map_err(|_| { "The router address is needed to perform a Hashflow swap".to_string(),
))?;
let tycho_router_address = bytes_to_address(&sender)?;
let hashflow_router_address =
Address::from_str(&self.hashflow_router_address).map_err(|_| {
EncodingError::FatalError("Invalid hashflow router address address".to_string()) EncodingError::FatalError("Invalid hashflow router address address".to_string())
})?; })?;
// Native ETH doesn't need approval, only ERC20 tokens do // Native ETH doesn't need approval, only ERC20 tokens do
if swap.token_in == self.native_token_address { let approval_needed = if swap.token_in == self.native_token_address {
approval_needed = false; false
} else { } else {
approval_needed = ProtocolApprovalsManager::new()?.approval_needed( ProtocolApprovalsManager::new()?.approval_needed(
bytes_to_address(&swap.token_in)?, bytes_to_address(&swap.token_in)?,
tycho_router_address, tycho_router_address,
hashflow_router_address, hashflow_router_address,
)?; )?
} };
} else {
approval_needed = true;
}
// Get quote // Get quote
let protocol_state = swap let protocol_state = swap