feat: Add protocol_specific_addresses.json file

This way we can define protocol and chain specific addresses in this file and use them in the Encoders

--- don't change below this line ---
ENG-4306 Took 1 hour 4 minutes
This commit is contained in:
Diana Carvalho
2025-04-08 09:29:38 +01:00
parent 913d677ffb
commit 739fb46d20
6 changed files with 370 additions and 215 deletions

View File

@@ -1,3 +1,5 @@
use std::collections::HashMap;
use crate::encoding::{
errors::EncodingError,
evm::swap_encoder::swap_encoders::{
@@ -13,42 +15,67 @@ pub struct SwapEncoderBuilder {
protocol_system: String,
executor_address: String,
chain: Chain,
config: Option<HashMap<String, String>>,
}
impl SwapEncoderBuilder {
pub fn new(protocol_system: &str, executor_address: &str, chain: Chain) -> Self {
pub fn new(
protocol_system: &str,
executor_address: &str,
chain: Chain,
config: Option<HashMap<String, String>>,
) -> Self {
SwapEncoderBuilder {
protocol_system: protocol_system.to_string(),
executor_address: executor_address.to_string(),
chain,
config,
}
}
pub fn build(self) -> Result<Box<dyn SwapEncoder>, EncodingError> {
match self.protocol_system.as_str() {
"uniswap_v2" => {
Ok(Box::new(UniswapV2SwapEncoder::new(self.executor_address, self.chain)?))
"uniswap_v2" => Ok(Box::new(UniswapV2SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"sushiswap_v2" => Ok(Box::new(UniswapV2SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"pancakeswap_v2" => Ok(Box::new(UniswapV2SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"vm:balancer_v2" => Ok(Box::new(BalancerV2SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"uniswap_v3" => Ok(Box::new(UniswapV3SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"pancakeswap_v3" => Ok(Box::new(UniswapV3SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"uniswap_v4" => Ok(Box::new(UniswapV4SwapEncoder::new(
self.executor_address,
self.chain,
self.config,
)?)),
"ekubo_v2" => {
Ok(Box::new(EkuboSwapEncoder::new(self.executor_address, self.chain, self.config)?))
}
"sushiswap_v2" => {
Ok(Box::new(UniswapV2SwapEncoder::new(self.executor_address, self.chain)?))
"vm:curve" => {
Ok(Box::new(CurveSwapEncoder::new(self.executor_address, self.chain, self.config)?))
}
"pancakeswap_v2" => {
Ok(Box::new(UniswapV2SwapEncoder::new(self.executor_address, self.chain)?))
}
"vm:balancer_v2" => {
Ok(Box::new(BalancerV2SwapEncoder::new(self.executor_address, self.chain)?))
}
"uniswap_v3" => {
Ok(Box::new(UniswapV3SwapEncoder::new(self.executor_address, self.chain)?))
}
"pancakeswap_v3" => {
Ok(Box::new(UniswapV3SwapEncoder::new(self.executor_address, self.chain)?))
}
"uniswap_v4" => {
Ok(Box::new(UniswapV4SwapEncoder::new(self.executor_address, self.chain)?))
}
"ekubo_v2" => Ok(Box::new(EkuboSwapEncoder::new(self.executor_address, self.chain)?)),
"vm:curve" => Ok(Box::new(CurveSwapEncoder::new(self.executor_address, self.chain)?)),
_ => Err(EncodingError::FatalError(format!(
"Unknown protocol system: {}",
self.protocol_system