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": {
|
"executors": {
|
||||||
"uniswap_v2": "0x5C2F5a71f67c01775180ADc06909288B4C329308",
|
"ethereum": {
|
||||||
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
"uniswap_v2": "0x5C2F5a71f67c01775180ADc06909288B4C329308",
|
||||||
|
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use tycho_core::dto::Chain;
|
||||||
|
|
||||||
use crate::encoding::swap_encoder::registry::{Config, SwapEncoderRegistry};
|
use crate::encoding::swap_encoder::registry::{Config, SwapEncoderRegistry};
|
||||||
|
|
||||||
@@ -11,6 +12,6 @@ mod swap_struct_encoder;
|
|||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SWAP_ENCODER_REGISTRY: RwLock<SwapEncoderRegistry> = {
|
pub static ref SWAP_ENCODER_REGISTRY: RwLock<SwapEncoderRegistry> = {
|
||||||
let config = Config::from_file("config.json").expect("Failed to load configuration file");
|
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 std::{collections::HashMap, fs};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use tycho_core::dto::Chain;
|
||||||
|
|
||||||
use crate::encoding::swap_encoder::{
|
use crate::encoding::swap_encoder::{
|
||||||
builder::SwapEncoderBuilder, swap_struct_encoder::SwapEncoder,
|
builder::SwapEncoderBuilder, swap_struct_encoder::SwapEncoder,
|
||||||
@@ -11,15 +12,18 @@ pub struct SwapEncoderRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SwapEncoderRegistry {
|
impl SwapEncoderRegistry {
|
||||||
pub fn new(config: Config) -> Self {
|
pub fn new(config: Config, blockchain: Chain) -> Self {
|
||||||
let mut encoders = HashMap::new();
|
let mut encoders = HashMap::new();
|
||||||
|
let executors = config
|
||||||
for (protocol, executor_address) in config.executors {
|
.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 builder = SwapEncoderBuilder::new(&protocol, &executor_address);
|
||||||
let encoder = builder.build().unwrap_or_else(|_| {
|
let encoder = builder.build().unwrap_or_else(|_| {
|
||||||
panic!("Failed to build swap encoder for protocol: {}", protocol)
|
panic!("Failed to build swap encoder for protocol: {}", protocol)
|
||||||
});
|
});
|
||||||
encoders.insert(protocol, encoder);
|
encoders.insert(protocol.to_string(), encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { encoders }
|
Self { encoders }
|
||||||
@@ -33,7 +37,8 @@ impl SwapEncoderRegistry {
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
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 {
|
impl Config {
|
||||||
|
|||||||
Reference in New Issue
Block a user