use crate::swap::approve::{RouterAddress};
use crate::client::OneInchClient;
use crate::consts::{BASIC_URL, SWAP_API_VERSION};
use std::error::Error;
impl OneInchClient {
pub async fn get_router_address(
&self,
) -> Result<RouterAddress, Box<dyn Error>> {
let url = format!(
"{}/swap/{}/{}/approve/spender",
BASIC_URL, SWAP_API_VERSION, self.network_id
);
let request_result = self
.http_client
.get(url)
.header("Authorization", &self.token)
.send()
.await;
let response = request_result
.map_err(|e| Box::new(e) as Box<dyn Error>)?
.error_for_status()
.map_err(|e| Box::new(e) as Box<dyn Error>)?;
let address: RouterAddress = response
.json()
.await
.map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(address)
}
}