diff --git a/src/endpoints/defi/rewards.rs b/src/endpoints/defi/rewards.rs index 95e80a7..c11fadc 100644 --- a/src/endpoints/defi/rewards.rs +++ b/src/endpoints/defi/rewards.rs @@ -40,7 +40,7 @@ pub async fn get_defi_rewards( .build(); let (zklend_rewards, nostra_rewards, nimbora_rewards, ekubo_rewards, vesu_rewards) = tokio::join!( - fetch_zklend_rewards(&client, &addr), + fetch_zklend_rewards(&client, &addr, &state), fetch_nostra_rewards(&client, &addr, &state), fetch_nimbora_rewards(&client, &addr, &state), fetch_ekubo_rewards(&client, &addr, &state), @@ -83,7 +83,9 @@ pub async fn get_defi_rewards( async fn fetch_zklend_rewards( client: &ClientWithMiddleware, addr: &str, + state: &AppState, ) -> Result, Error> { + let logger = &state.logger; let zklend_url = format!("https://app.zklend.com/api/reward/all/{}", addr); let response = client .get(&zklend_url) @@ -112,7 +114,7 @@ async fn fetch_zklend_rewards( Ok(rewards) } Err(err) => { - eprintln!("Failed to deserialize zkLend response: {:?}", err); + logger.warning(format!("Failed to deserialize zkLend response: {:?}", err)); Err(Error::Reqwest(err)) } } @@ -123,6 +125,7 @@ async fn fetch_nostra_rewards( addr: &str, state: &AppState, ) -> Result, Error> { + let logger = &state.logger; let url = "https://us-east-2.aws.data.mongodb-api.com/app/data-yqlpb/endpoint/data/v1/action/find"; @@ -155,7 +158,10 @@ async fn fetch_nostra_rewards( let reward_periods = match periods_resp.json::().await { Ok(result) => result, Err(err) => { - eprintln!("Failed to deserialize Nostra periods response: {:?}", err); + logger.warning(format!( + "Failed to deserialize Nostra periods response: {:?}", + err + )); NostraPeriodsResponse { documents: vec![] } } }; @@ -163,7 +169,10 @@ async fn fetch_nostra_rewards( let rewards = match rewards_resp.json::().await { Ok(result) => result, Err(err) => { - eprintln!("Failed to deserialize Nostra rewards response: {:?}", err); + logger.warning(format!( + "Failed to deserialize Nostra rewards response: {:?}", + err + )); return Err(Error::Reqwest(err)); } }; @@ -225,6 +234,7 @@ async fn fetch_nimbora_rewards( addr: &str, state: &AppState, ) -> Result, Error> { + let logger = &state.logger; let config = &state.conf; let nimbora_url = format!( "https://strk-dist-backend.nimbora.io/get_calldata?address={}", @@ -267,7 +277,7 @@ async fn fetch_nimbora_rewards( Ok(vec![reward]) } Err(err) => { - eprintln!("Failed to deserialize nimbora response: {:?}", err); + logger.warning(format!("Failed to deserialize nimbora response: {:?}", err)); Err(Error::Reqwest(err)) } } @@ -278,6 +288,7 @@ async fn fetch_ekubo_rewards( addr: &str, state: &AppState, ) -> Result, Error> { + let logger = &state.logger; let strk_token = state.conf.tokens.strk.clone(); let ekubo_url = format!( "https://mainnet-api.ekubo.org/airdrops/{}?token={}", @@ -290,7 +301,10 @@ async fn fetch_ekubo_rewards( let rewards = match response.json::>().await { Ok(result) => result, Err(err) => { - eprintln!("Failed to deserialize Ekubo rewards response: {:?}", err); + logger.warning(format!( + "Failed to deserialize Ekubo rewards response: {:?}", + err + )); return Err(Error::Reqwest(err)); } }; @@ -362,6 +376,7 @@ async fn fetch_vesu_rewards( addr: &str, state: &AppState, ) -> Result, Error> { + let logger = &state.logger; let vesu_url = format!("https://api.vesu.xyz/users/{}/strk-rewards", addr); let response = client.get(&vesu_url).headers(get_headers()).send().await?; @@ -403,7 +418,7 @@ async fn fetch_vesu_rewards( Ok(vec![reward]) } Err(err) => { - eprintln!("Failed to deserialize vesu response: {:?}", err); + logger.warning(format!("Failed to deserialize vesu response: {:?}", err)); Err(Error::Reqwest(err)) } } diff --git a/src/endpoints/discover/defi/get_alt_protocol_stats.rs b/src/endpoints/discover/defi/get_alt_protocol_stats.rs index 24793a3..3a93b45 100644 --- a/src/endpoints/discover/defi/get_alt_protocol_stats.rs +++ b/src/endpoints/discover/defi/get_alt_protocol_stats.rs @@ -27,6 +27,7 @@ fn get_nimbora_strategy_map() -> HashMap { #[route(get, "/discover/defi/get_alt_protocol_stats")] pub async fn handler(State(state): State>) -> impl IntoResponse { + let logger = &state.logger; let endpoint = &state.conf.discover.alt_protocols_api_endpoint; let client = reqwest::Client::new(); let request_builder = client.get(endpoint); @@ -85,7 +86,7 @@ pub async fn handler(State(state): State>) -> impl IntoResponse { } } } else { - println!("Failed to fetch or parse Nimbora data"); + logger.info("Failed to fetch or parse Nimbora data".to_string()); } return (StatusCode::OK, Json(new_map)).into_response(); diff --git a/src/utils.rs b/src/utils.rs index 43714c2..0f22b8f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -904,15 +904,16 @@ pub async fn check_if_unclaimed( calldata: Vec, source: RewardSource, ) -> bool { + let logger = &state.logger; match read_contract(state, contract, selector, calldata).await { Ok(result) => result.get(0) == Some(&FieldElement::ZERO), Err(err) => { - eprintln!( + logger.severe(format!( "Error checking {:?} claim status: {:?} in {}", source, err, to_hex(contract) - ); + )); false } }