Learn how to interact with lending protocols using the Ember SDK.
use ember_sdk::{LendTokensParams};
async fn lend_tokens(client: &EmberClient) -> Result<(), EmberError> {
let lend_params = LendTokensParams {
from_address: "0xYourAddress...".to_string(),
protocol: "AAVE_V3".to_string(),
token: "0xTokenAddress...".to_string(),
amount: "1000".to_string(),
interest_rate_mode: "VARIABLE".to_string(),
enable_collateral: true,
max_fee: "5".to_string(),
};
let lending_plan = client.lend_tokens(lend_params).await?;
println!("Lending plan created: {:?}", lending_plan);
Ok(())
}
use ember_sdk::{BorrowTokensParams};
async fn borrow_tokens(client: &EmberClient) -> Result<(), EmberError> {
let borrow_params = BorrowTokensParams {
from_address: "0xYourAddress...".to_string(),
protocol: "AAVE_V3".to_string(),
borrow_token: "0xTokenToBorrow...".to_string(),
borrow_amount: "500".to_string(),
interest_rate_mode: "VARIABLE".to_string(),
max_fee: "5".to_string(),
};
let borrowing_plan = client.borrow_tokens(borrow_params).await?;
println!("Borrowing plan created: {:?}", borrowing_plan);
Ok(())
}
async fn get_positions(client: &EmberClient) -> Result<(), EmberError> {
let positions_params = GetLendingPositionsParams {
address: "0xYourAddress...".to_string(),
protocols: Some(vec!["AAVE_V3".to_string()]),
chain_ids: Some(vec![1]),
active: Some(true),
};
let positions = client.get_lending_positions(positions_params).await?;
for position in positions.positions {
println!("Position: {:?}", position);
}
Ok(())
}
use ember_sdk::{EmberWebSocket, StreamPositionsParams};
async fn monitor_health_factor(ws: &EmberWebSocket) -> Result<(), EmberError> {
let stream_params = StreamPositionsParams {
address: "0xYourAddress...".to_string(),
position_types: vec!["LENDING".to_string()],
};
let mut position_stream = ws.stream_positions(stream_params).await?;
ws.on_position_update(|update| {
if let Some(health_factor) = update.details.health_factor {
if health_factor < "1.1" {
println!("Warning: Low health factor!");
}
}
}).await;
Ok(())
}