From cf49c6d2789fd08c06f7fafc59a6ed8e83fffdbe Mon Sep 17 00:00:00 2001 From: iamoskvin Date: Fri, 22 Mar 2024 13:44:31 +0300 Subject: [PATCH 1/3] fix incorrect json from api --- src/pages/Rewards/index.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pages/Rewards/index.tsx b/src/pages/Rewards/index.tsx index 57eb3cdb..d10c2954 100644 --- a/src/pages/Rewards/index.tsx +++ b/src/pages/Rewards/index.tsx @@ -458,14 +458,20 @@ export default function Rewards() { }), fetchPolicy: 'cache-first' }) - const rewardsResp = await fetch(STARKNET_REWARDS_API_URL).then(res => res.json()) + const rewardsResp = await fetch(STARKNET_REWARDS_API_URL) + const rewardsRespStr = await rewardsResp.text() + const rewardsRespStrClean = rewardsRespStr.replace(/\bNaN\b/g, "null") + const rewardsRespJson = JSON.parse(rewardsRespStrClean) const priceResp = await fetch(STRK_PRICE_API_URL).then(res => res.json()) const strkPrice = parseFloat(priceResp.price) - const jediRewards = rewardsResp.Jediswap_v1 + const jediRewards = rewardsRespJson.Jediswap_v1 const rewardsPositions: any = [] for (const pair of pairs) { const rewardsData = jediRewards[pair.rewardName].pop() + if (!rewardsData) { + continue + } const recentDate = rewardsData.date const pairDayData = pairsResp.data.pairDayDatas.find( dayData => dayData.pairId === pair.poolAddress && dayData.date === recentDate + 'T00:00:00' @@ -628,7 +634,7 @@ export default function Rewards() { pair.token1.symbol === 'ETH' ? pair.token1 : allTokens[validateAndParseAddress(pair.token1.tokenAddress)] return ( - +
From 16613bfa07497aa98ba7367fc02f1e50bea2b539 Mon Sep 17 00:00:00 2001 From: iamoskvin Date: Fri, 22 Mar 2024 13:44:37 +0300 Subject: [PATCH 2/3] new pairs --- src/pages/Rewards/RewardPairs.ts | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/pages/Rewards/RewardPairs.ts b/src/pages/Rewards/RewardPairs.ts index 6cd18d42..662a0b9b 100644 --- a/src/pages/Rewards/RewardPairs.ts +++ b/src/pages/Rewards/RewardPairs.ts @@ -46,6 +46,42 @@ const pairs = [ tokenAddress: '0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8', symbol: 'USDC' } + }, + { + rewardName: 'USDC/DAI', + poolAddress: '0x7582a77c9128e063c6f7d5a57acae969417f925904540edfac388bacaeb1fa6', + token0: { + tokenAddress: '0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8', + symbol: 'USDC' + }, + token1: { + tokenAddress: '0x5574eb6b8789a91466f902c380d978e472db68170ff82a5b650b95a58ddf4ad', + symbol: 'DAI' + } + }, + { + rewardName: 'WSTETH/ETH', + poolAddress: '0x70cda8400d7b1ee9e21f7194d320b9ad9c7a2b27e0d15a5a9967b9fefe10c76', + token0: { + tokenAddress: '0x42b8f0484674ca266ac5d08e4ac6a3fe65bd3129795def2dca5c34ecc5f96d2', + symbol: 'wstETH' + }, + token1: { + tokenAddress: '0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7', + symbol: 'ETH' + } + }, + { + rewardName: 'WBTC/ETH', + poolAddress: '0x260e98362e0949fefff8b4de85367c035e44f734c9f8069b6ce2075ae86b45c', + token0: { + tokenAddress: '0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac', + symbol: 'WBTC' + }, + token1: { + tokenAddress: '0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7', + symbol: 'ETH' + } } ] From 60950e6c6d2e76c55fcbb4244a496f44b2fb5b9e Mon Sep 17 00:00:00 2001 From: iamoskvin Date: Fri, 22 Mar 2024 14:03:03 +0300 Subject: [PATCH 3/3] remove STRK price request --- src/pages/Rewards/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/Rewards/index.tsx b/src/pages/Rewards/index.tsx index d10c2954..5aacb4b6 100644 --- a/src/pages/Rewards/index.tsx +++ b/src/pages/Rewards/index.tsx @@ -462,9 +462,7 @@ export default function Rewards() { const rewardsRespStr = await rewardsResp.text() const rewardsRespStrClean = rewardsRespStr.replace(/\bNaN\b/g, "null") const rewardsRespJson = JSON.parse(rewardsRespStrClean) - const priceResp = await fetch(STRK_PRICE_API_URL).then(res => res.json()) - const strkPrice = parseFloat(priceResp.price) const jediRewards = rewardsRespJson.Jediswap_v1 const rewardsPositions: any = [] for (const pair of pairs) { @@ -477,7 +475,7 @@ export default function Rewards() { dayData => dayData.pairId === pair.poolAddress && dayData.date === recentDate + 'T00:00:00' ) const aprFee = ((pairDayData.dailyVolumeUSD * 0.003) / pairDayData.reserveUSD) * 365 * 100 - const aprStarknet = (rewardsData.allocation / pairDayData.reserveUSD) * 365 * 100 * strkPrice + const aprStarknet = rewardsData.apr * 100 rewardsPositions.push({ ...pair, reserveUSD: pairDayData.reserveUSD,