diff --git a/src/exchange_rate.rs b/src/exchange_rate.rs index c9140789..767cbb42 100644 --- a/src/exchange_rate.rs +++ b/src/exchange_rate.rs @@ -20,45 +20,30 @@ sol!( type Provider = alloy::providers::RootProvider>; pub async fn grt_per_usd(provider: Url) -> anyhow::Result>> { - // https://data.chain.link/ethereum/mainnet/crypto-eth/grt-eth - let chainlink_eth_per_grt: Address = "0x17d054ecac33d91f7340645341efb5de9009f1c1" - .parse() - .unwrap(); - // https://data.chain.link/ethereum/mainnet/crypto-usd/eth-usd - let chainlink_usd_per_eth: Address = "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419" + // https://data.chain.link/feeds/arbitrum/mainnet/grt-usd + let chainlink_grt_per_usd: Address = "0x0F38D86FceF4955B705F35c9e41d1A16e0637c73" .parse() .unwrap(); let provider = Arc::new(ProviderBuilder::new().on_http(provider)); - let eth_per_grt = ChainlinkPriceFeed::new(chainlink_eth_per_grt, provider.clone()); - let usd_per_eth = ChainlinkPriceFeed::new(chainlink_usd_per_eth, provider); + let grt_per_usd = ChainlinkPriceFeed::new(chainlink_grt_per_usd, provider); let (tx, mut rx) = watch::channel(NotNan::new(0.0).unwrap()); tokio::spawn(async move { let mut interval = interval(Duration::from_secs(60)); - interval.set_missed_tick_behavior(MissedTickBehavior::Skip); + interval.set_missed_tick_behavior(MissedTickBehavior::Delay); loop { interval.tick().await; - let eth_per_grt = match fetch_price(ð_per_grt).await { - Ok(eth_per_grt) => eth_per_grt, - Err(eth_per_grt_err) => { - tracing::error!(%eth_per_grt_err); - return; - } - }; - let usd_per_eth = match fetch_price(&usd_per_eth).await { - Ok(usd_per_eth) => usd_per_eth, - Err(usd_per_eth_err) => { - tracing::error!(%usd_per_eth_err); - return; + let grt_per_usd = match fetch_price(&grt_per_usd).await { + Ok(grt_per_usd) => grt_per_usd, + Err(grt_per_usd_err) => { + tracing::error!(%grt_per_usd_err); + continue; } }; - let grt_per_usd = NotNan::new((eth_per_grt * usd_per_eth).recip()).unwrap(); tracing::info!(%grt_per_usd); - if let Err(grt_per_usd_send_err) = tx.send(grt_per_usd) { - tracing::error!(%grt_per_usd_send_err); - } + tx.send(grt_per_usd).unwrap(); } }); diff --git a/src/receipts.rs b/src/receipts.rs index 4278e003..873605e0 100644 --- a/src/receipts.rs +++ b/src/receipts.rs @@ -1,7 +1,6 @@ use std::{collections::HashMap, sync::Arc, time::SystemTime}; -use alloy::primitives::U256; -use alloy::{dyn_abi::Eip712Domain, signers::local::PrivateKeySigner}; +use alloy::{dyn_abi::Eip712Domain, primitives::U256, signers::local::PrivateKeySigner}; use parking_lot::{Mutex, RwLock}; use rand::RngCore; pub use receipts::QueryStatus as ReceiptStatus;