use anchor_client::Cluster;
use anchor_lang::prelude::Pubkey;
use jup_lend_sdk::oracle;
use std::{str::FromStr, time::Instant};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let rpc_url =
        dotenv::var("RPC_URL").unwrap_or("https://api.mainnet-beta.solana.com".to_string());
    let cluster = Cluster::from_str(rpc_url.as_str())?;

    let start = Instant::now();
    let price = oracle::simulations::get_oracle_price_liquidate(
        Pubkey::from_str_const("546HPrQvDrXJtyPk2jbd4J1Gtw4hCgQj9xLCjRxe6t7S"),
        cluster.clone(),
    )
    .await?;
    let oracle_duration = start.elapsed();

    println!("Simulated Oracle price: {}", price.price);
    println!("Simulated oracle price took: {:?}", oracle_duration);

    let start = Instant::now();
    let price = oracle::read::get_oracle_price_liquidate(
        Pubkey::from_str_const("546HPrQvDrXJtyPk2jbd4J1Gtw4hCgQj9xLCjRxe6t7S"),
        cluster.clone(),
    )
    .await?;
    let read_duration = start.elapsed();

    println!("Read Oracle price: {}", price.price);
    println!("Read oracle price took: {:?}", read_duration);

    Ok(())
}
