feat: Add chain in config.json for the executor addresses
--- don't change below this line --- ENG-4075 <#DTT#>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"executors": {
|
||||
"uniswap_v2": "0x5C2F5a71f67c01775180ADc06909288B4C329308",
|
||||
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
||||
"ethereum": {
|
||||
"uniswap_v2": "0x5C2F5a71f67c01775180ADc06909288B4C329308",
|
||||
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::sync::RwLock;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use tycho_core::dto::Chain;
|
||||
|
||||
use crate::encoding::swap_encoder::registry::{Config, SwapEncoderRegistry};
|
||||
|
||||
@@ -11,6 +12,6 @@ mod swap_struct_encoder;
|
||||
lazy_static! {
|
||||
pub static ref SWAP_ENCODER_REGISTRY: RwLock<SwapEncoderRegistry> = {
|
||||
let config = Config::from_file("config.json").expect("Failed to load configuration file");
|
||||
RwLock::new(SwapEncoderRegistry::new(config))
|
||||
RwLock::new(SwapEncoderRegistry::new(config, Chain::Ethereum))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{collections::HashMap, fs};
|
||||
|
||||
use serde::Deserialize;
|
||||
use tycho_core::dto::Chain;
|
||||
|
||||
use crate::encoding::swap_encoder::{
|
||||
builder::SwapEncoderBuilder, swap_struct_encoder::SwapEncoder,
|
||||
@@ -11,15 +12,18 @@ pub struct SwapEncoderRegistry {
|
||||
}
|
||||
|
||||
impl SwapEncoderRegistry {
|
||||
pub fn new(config: Config) -> Self {
|
||||
pub fn new(config: Config, blockchain: Chain) -> Self {
|
||||
let mut encoders = HashMap::new();
|
||||
|
||||
for (protocol, executor_address) in config.executors {
|
||||
let executors = config
|
||||
.executors
|
||||
.get(&blockchain)
|
||||
.unwrap_or_else(|| panic!("No executors found for blockchain: {}", blockchain));
|
||||
for (protocol, executor_address) in executors {
|
||||
let builder = SwapEncoderBuilder::new(&protocol, &executor_address);
|
||||
let encoder = builder.build().unwrap_or_else(|_| {
|
||||
panic!("Failed to build swap encoder for protocol: {}", protocol)
|
||||
});
|
||||
encoders.insert(protocol, encoder);
|
||||
encoders.insert(protocol.to_string(), encoder);
|
||||
}
|
||||
|
||||
Self { encoders }
|
||||
@@ -33,7 +37,8 @@ impl SwapEncoderRegistry {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
pub executors: HashMap<String, String>, // Protocol -> Executor address mapping
|
||||
pub executors: HashMap<Chain, HashMap<String, String>>, /* Blockchain -> {Protocol ->
|
||||
* Executor address} mapping */
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
||||
Reference in New Issue
Block a user