Skip to content

Commit

Permalink
Merge pull request #286 from lfglabs-dev/fix/removing-already-claimed…
Browse files Browse the repository at this point in the history
…-amount-for-nimbora

fix: removing already claimed amount for nimbora
  • Loading branch information
Th0rgal authored Oct 16, 2024
2 parents c466919 + 8b5b1f9 commit a4ceaba
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/endpoints/defi/rewards.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
config::Config,
models::{
AppState, CommonReward, ContractCall, DefiReward, EkuboRewards, NimboraRewards,
NostraPeriodsResponse, NostraResponse, RewardSource, ZkLendReward,
},
utils::{check_if_claimed, to_hex_trimmed, to_hex},
utils::{check_if_claimed, read_contract, to_hex, to_hex_trimmed},
};
use axum::{
extract::{Query, State},
Expand All @@ -21,7 +20,7 @@ use reqwest_tracing::TracingMiddleware;
use serde::{Deserialize, Serialize};
use serde_json::json;
use starknet::{core::types::FieldElement, macros::selector};
use std::{sync::Arc, vec};
use std::{str::FromStr, sync::Arc, vec};

#[derive(Debug, Serialize, Deserialize)]
pub struct RewardQuery {
Expand All @@ -45,7 +44,7 @@ pub async fn get_defi_rewards(
let (zklend_rewards, nostra_rewards, nimbora_rewards, ekubo_rewards) = tokio::join!(
fetch_zklend_rewards(&client, &addr),
fetch_nostra_rewards(&client, &addr, &state),
fetch_nimbora_rewards(&client, &addr, &state.conf),
fetch_nimbora_rewards(&client, &addr, &state),
fetch_ekubo_rewards(&client, &addr, &state),
);

Expand Down Expand Up @@ -186,7 +185,7 @@ async fn fetch_nostra_rewards(
distributor,
selector!("amount_already_claimed"),
vec![addr_field],
RewardSource::Nostra
RewardSource::Nostra,
)
.await
{
Expand Down Expand Up @@ -216,13 +215,13 @@ async fn fetch_nostra_rewards(
async fn fetch_nimbora_rewards(
client: &ClientWithMiddleware,
addr: &str,
config: &Config,
state: &AppState,
) -> Result<Vec<CommonReward>, Error> {
let config = &state.conf;
let nimbora_url = format!(
"https://strk-dist-backend.nimbora.io/get_calldata?address={}",
addr
);

let response = client
.get(&nimbora_url)
.headers(get_headers())
Expand All @@ -233,8 +232,20 @@ async fn fetch_nimbora_rewards(

match response.json::<NimboraRewards>().await {
Ok(result) => {
let amount = result.amount;
let claimed_amount = read_contract(
state,
config.rewards.nimbora.contract,
selector!("amount_already_claimed"),
vec![FieldElement::from_str(addr).unwrap()],
)
.await
.unwrap()[0];
if claimed_amount == amount {
return Ok(vec![]);
}
let reward = CommonReward {
amount: result.amount,
amount: amount - claimed_amount,
proof: result.proof,
reward_id: None,
token_symbol: strk_symbol.clone(),
Expand Down Expand Up @@ -284,7 +295,7 @@ async fn fetch_ekubo_rewards(
reward.contract_address,
selector!("is_claimed"),
vec![FieldElement::from(reward.claim.id)],
RewardSource::Ekubo
RewardSource::Ekubo,
)
.await
{
Expand Down

0 comments on commit a4ceaba

Please sign in to comment.