From 7a0d1c671a77e106e24e2e0061fd5c10b8eaaf94 Mon Sep 17 00:00:00 2001 From: Michaelkingsdev Date: Sun, 24 Nov 2024 13:56:05 +0100 Subject: [PATCH 1/2] Reinforce the WatchTower implementation --- src/endpoints/defi/rewards.rs | 29 ++++++++++++++----- .../discover/defi/get_alt_protocol_stats.rs | 3 +- src/utils.rs | 5 ++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/endpoints/defi/rewards.rs b/src/endpoints/defi/rewards.rs index d147f96..1b0090f 100644 --- a/src/endpoints/defi/rewards.rs +++ b/src/endpoints/defi/rewards.rs @@ -42,7 +42,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), @@ -85,7 +85,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) @@ -114,7 +116,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)) } } @@ -125,6 +127,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"; @@ -157,7 +160,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![] } } }; @@ -165,7 +171,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)); } }; @@ -227,6 +236,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={}", @@ -269,7 +279,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)) } } @@ -280,6 +290,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={}", @@ -292,7 +303,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)); } }; @@ -364,6 +378,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?; @@ -405,7 +420,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 2c297a1..67c1c7b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -932,15 +932,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.info(format!( "Error checking {:?} claim status: {:?} in {}", source, err, to_hex(contract) - ); + )); false } } From 1a0028623d7676ff25eeb8007101ad7f3e2a7d26 Mon Sep 17 00:00:00 2001 From: Michaelkingsdev Date: Mon, 25 Nov 2024 17:00:08 +0100 Subject: [PATCH 2/2] change logger.info to logger.severe in utils.rs --- src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 67c1c7b..ee64362 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -936,7 +936,7 @@ pub async fn check_if_unclaimed( match read_contract(state, contract, selector, calldata).await { Ok(result) => result.get(0) == Some(&FieldElement::ZERO), Err(err) => { - logger.info(format!( + logger.severe(format!( "Error checking {:?} claim status: {:?} in {}", source, err,