pub struct Client { /* private fields */ }Expand description
Client for interacting with the Enso Finance API
Implementations§
Source§impl Client
impl Client
Sourcepub fn with_api_key(api_key: impl Into<String>) -> Result<Self>
pub fn with_api_key(api_key: impl Into<String>) -> Result<Self>
Create a new client with an API key
Sourcepub fn with_config(config: Config) -> Result<Self>
pub fn with_config(config: Config) -> Result<Self>
Create a new client with custom configuration
Sourcepub fn base(&self) -> &BaseClient
pub fn base(&self) -> &BaseClient
Get the underlying base client
Sourcepub async fn get_route(&self, request: &RouteRequest) -> Result<RouteResponse>
pub async fn get_route(&self, request: &RouteRequest) -> Result<RouteResponse>
Get optimal route for token swap
Returns the best route for swapping tokens with transaction data.
§Arguments
request- Route request parameters
§Example
use enso_api::{Client, Chain, RouteRequest};
#[tokio::main]
async fn main() -> Result<(), enso_api::Error> {
let client = Client::with_api_key("your-key")?;
let request = RouteRequest::new(
1, // Ethereum
"0xYourAddress",
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"1000000000000000000",
100,
);
let route = client.get_route(&request).await?;
println!("Output: {}", route.amount_out);
Ok(())
}Sourcepub async fn bundle(&self, request: &BundleRequest) -> Result<BundleResponse>
pub async fn bundle(&self, request: &BundleRequest) -> Result<BundleResponse>
Bundle multiple DeFi actions into one transaction
Allows combining multiple actions (swap, deposit, stake) into a single transaction.
§Arguments
request- Bundle request with actions
§Example
use enso_api::{Client, BundleRequest, BundleAction};
#[tokio::main]
async fn main() -> Result<(), enso_api::Error> {
let client = Client::with_api_key("your-key")?;
let actions = vec![
BundleAction::swap("0xTokenA", "0xTokenB", "1000000"),
];
let request = BundleRequest::new(1, "0xYourAddress", actions);
let bundle = client.bundle(&request).await?;
println!("Send to: {}", bundle.tx.to);
Ok(())
}Sourcepub async fn get_token_price(
&self,
chain_id: u64,
token: &str,
) -> Result<TokenPrice>
pub async fn get_token_price( &self, chain_id: u64, token: &str, ) -> Result<TokenPrice>
Sourcepub async fn get_balances(
&self,
chain_id: u64,
address: &str,
) -> Result<Vec<TokenBalance>>
pub async fn get_balances( &self, chain_id: u64, address: &str, ) -> Result<Vec<TokenBalance>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more