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

@@ -2,7 +2,10 @@ use std::{collections::HashMap, fs};
use crate::encoding::{
errors::EncodingError,
evm::{constants::DEFAULT_EXECUTORS_JSON, swap_encoder::builder::SwapEncoderBuilder},
evm::{
constants::{DEFAULT_EXECUTORS_JSON, PROTOCOL_SPECIFIC_CONFIG},
swap_encoder::builder::SwapEncoderBuilder,
},
models::Chain,
swap_encoder::SwapEncoder,
};
@@ -33,12 +36,27 @@ impl SwapEncoderRegistry {
DEFAULT_EXECUTORS_JSON.to_string()
};
let config: HashMap<String, HashMap<String, String>> = serde_json::from_str(&config_str)?;
let mut encoders = HashMap::new();
let executors = config
.get(&chain.name)
.ok_or(EncodingError::FatalError("No executors found for chain".to_string()))?;
let protocol_specific_config: HashMap<String, HashMap<String, HashMap<String, String>>> =
serde_json::from_str(PROTOCOL_SPECIFIC_CONFIG)?;
let protocol_specific_config = protocol_specific_config
.get(&chain.name)
.ok_or(EncodingError::FatalError(
"No protocol specific config found for chain".to_string(),
))?;
let mut encoders = HashMap::new();
for (protocol, executor_address) in executors {
let builder = SwapEncoderBuilder::new(protocol, executor_address, chain.clone());
let builder = SwapEncoderBuilder::new(
protocol,
executor_address,
chain.clone(),
protocol_specific_config
.get(protocol)
.cloned(),
);
let encoder = builder.build()?;
encoders.insert(protocol.to_string(), encoder);
}