Skip to content

Commit

Permalink
removed unused import
Browse files Browse the repository at this point in the history
  • Loading branch information
frankudoags committed Apr 16, 2023
1 parent 04485fa commit 61f3c46
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/get_reserves.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use ethers::{
contract::abigen,
core::{
types::Address,
utils::parse_ether,
},

core::types::Address,
providers::{Http, Provider},
};
use eyre::Result;
Expand Down Expand Up @@ -40,18 +36,26 @@ pub async fn get_reserves(pool: Address) -> Result<()> {
// instantiate the pair contract bindings
let pair = IUniswapV2Pair::new(pool, Arc::clone(&client));
let (reserve0, reserve1, _timestamp) = pair.get_reserves().call().await?;



// get the reserves
// get the token addresses
let token0 = pair.token_0().call().await?;
let token1 = pair.token_1().call().await?;
// get the token names from the token addresses
let token0_name = IERC20::new(token0, Arc::clone(&client)).name().call().await?;
let token1_name = IERC20::new(token1, Arc::clone(&client)).name().call().await?;
let token0_name = IERC20::new(token0, Arc::clone(&client))
.name()
.call()
.await?;
let token1_name = IERC20::new(token1, Arc::clone(&client))
.name()
.call()
.await?;

// print the reserves with the token names
println!("Reserves for {} and {}: {} and {}", token0_name, token1_name, reserve0, reserve1);
println!(
"Reserves for {} and {}: {} and {}",
token0_name, token1_name, reserve0, reserve1
);
// calculate the mid price, no idea if this is correct, copied from ethers-rs examples: ethers-rs/examples/queries/examples/uniswapv2_pair.rs
let mid_price = f64::powi(10.0, 18 - 6) * reserve1 as f64 / reserve0 as f64;
println!("Price of {} in {}: {}", token0_name, token1_name, mid_price);
Expand Down

0 comments on commit 61f3c46

Please sign in to comment.