Skip to content

Commit

Permalink
Merge pull request #280 from EveripediaNetwork/fix-treasury-value
Browse files Browse the repository at this point in the history
Fix Treasury Value
  • Loading branch information
SidharthK2 authored Oct 17, 2024
2 parents 6251d79 + a23c27c commit 2d9770d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/dashboard/TreasuryGraphTable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { useCallback, useState, useEffect, useRef } from 'react'
import { TOKEN_KEYS, TOKENS, PIE_CHART_COLORS } from '@/data/treasury-data'
import { TreasuryTokenType } from '@/types/TreasuryTokenType'
import { formatValue } from '@/utils/LockOverviewUtils'
Expand All @@ -18,7 +19,6 @@ import {
Th,
Tbody,
} from '@chakra-ui/react'
import React, { useCallback, useState, useEffect, useRef } from 'react'
import PageHeader from './PageHeader'
import { ChartDataType, OnPieEnter } from '@/types/chartType'
import Chart from '../elements/PieChart/Chart'
Expand Down Expand Up @@ -107,7 +107,7 @@ export const TreasuryGraphTable = ({
formatPieData(treasuryValuePlusYield, totalAccountValue)
setTokenData(treasuryValuePlusYield)
setTokenDataToShow(treasuryValuePlusYield)
}, [])
}, [rate, userTotalIQLocked, totalHiiqSupply, fraxAprData, fraxEthSummary])

useEffect(() => {
if (!isTokenFetched.current) {
Expand Down
22 changes: 20 additions & 2 deletions src/data/treasury-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,30 @@ export const TOKENS: TokensType = {
address: '0xe035e27a8ed6842b478933820f90093d205f7098',
image: '/svgs/fxb.svg',
},
'stkcvxFxs Fraxtal': {
'0x8c279f6bfa31c47f29e5d05a68796f2a6c216892': {
id: 'stkcvxFxs Fraxtal',
name: 'cvxFxs Fraxtal',
name: 'cvxFxs FXTL',
address: '0x8c279f6bfa31c47f29e5d05a68796f2a6c216892',
image: '/svgs/stkcvx.svg',
},
'0x1872621050cc3c267c1982c6d199b7d6a4d0e87a': {
id: 'FXB20551231',
name: 'FXB20551231 FXTL',
address: '0x1872621050cc3c267c1982c6d199b7d6a4d0e87a',
image: '/svgs/FXB.svg',
},
'0x22c4649ea0937e86ab64366ddfb39d6769874b17': {
id: 'FXB20251231',
name: 'FXB20251231 FXTL',
address: '0x22c4649ea0937e86ab64366ddfb39d6769874b17',
image: '/svgs/FXB.svg',
},
'0xed634f2dd6632d0eb017d44639ae77798a315c0f': {
id: 'FXB20291231',
name: 'FXB20291231 FXTL',
address: '0xed634f2dd6632d0eb017d44639ae77798a315c0f',
image: '/svgs/FXB.svg',
},
}

export const tokenIds = Object.values(TOKENS).map((tok) => tok.id)
Expand Down
89 changes: 59 additions & 30 deletions src/utils/treasury-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { fraxLendQueryObject } from '@/services/treasury/queries'
import { store } from '@/store/store'
import {
getProtocolDetails,
getTokenInfo,
getWalletTokens,
} from '@/services/treasury/restApi'

Expand All @@ -37,6 +36,13 @@ const SUPPORTED_LP_TOKENS_ADDRESSES = [
const FRAXTAL_TOKENS = [
'0xfc00000000000000000000000000000000000008',
'0x8c279f6bfa31c47f29e5d05a68796f2a6c216892',
'0x124189d975bd59f85a0be1845b556d9249096522',
'0x1872621050cc3c267c1982c6d199b7d6a4d0e87a',
'0x22c4649ea0937e86ab64366ddfb39d6769874b17',
'0x331b9182088e2a7d6d3fe4742aba1fb231aecc56',
'0xab4b7c5c9a7c8ebb97877085a6c3550ad4ed3f97',
'0xed634f2dd6632d0eb017d44639ae77798a315c0f',
'0xfc00000000000000000000000000000000000002',
]

const PROTOCOLS = ['fraxlend', 'convex', 'frax', 'eigenlayer']
Expand Down Expand Up @@ -83,21 +89,23 @@ const getTreasuryPayload = (protocol: string) => {
}

export const getTreasuryDetails = async () => {
const [{ data: tokens }, { data: fraxtalTokens }] = await Promise.all([
const [
{ data: tokens },
{ data: fraxtalTokens },
{ data: fraxConvexDetails },
] = await Promise.all([
store.dispatch(getWalletTokens.initiate(config.treasuryAddress as string)),
store.dispatch(
getWalletTokens.initiate(config.fraxtalTreasuryAddress as string),
),
store.dispatch(
getProtocolDetails.initiate({
protocolId: 'frax_convex',
id: '0x5493f3dbe06accd1f51568213de839498a2a3b83',
}),
),
])

const { data: tokenInfo } = await store.dispatch(
getTokenInfo.initiate({
chain: 'frax',
ids: '0xefb4b26fc242478c9008274f9e81db89fa6adab9',
}),
)
const cvxFXSPrice = tokenInfo[0]?.price || 0

const { data: protocolDetails } = await store.dispatch(
getProtocolDetails.initiate({
protocolId: 'apestake',
Expand All @@ -122,11 +130,10 @@ export const getTreasuryDetails = async () => {
value += contractProtocoldetails?.amount
}

const dollarValue =
token.symbol === 'stkcvxFxs' ? cvxFXSPrice * value : token.price * value
const dollarValue = token.price * value
const tokenDetails = {
id: FRAXTAL_TOKENS.includes(token.id)
? `${token.symbol} Fraxtal`
? `${token.symbol} FXTL`
: token.symbol,
contractAddress: token.id,
token: value,
Expand All @@ -138,23 +145,45 @@ export const getTreasuryDetails = async () => {
},
)

const additionalTreasuryData: TreasuryTokenType[] = []
const allLpTokens = walletDetails.map(({ data }) => data)
allLpTokens.flat().forEach((lp) => {
if (SUPPORTED_LP_TOKENS_ADDRESSES.includes(lp.pool.id)) {
additionalTreasuryData.push({
id: lp.pool.adapter_id,
contractAddress: lp.pool.controller,
raw_dollar: Number(lp.stats.asset_usd_value),
token: lp.detail.supply_token_list.map(
(supply: { amount: number; symbol: string }) => ({
amount: supply.amount,
symbol: supply.symbol,
}),
),
})
}
})
const processTreasuryData = (data: any[], supportedAddresses: string[]) => {
return data.flatMap((item) => {
if (supportedAddresses.includes(item.pool.id)) {
return [
{
id:
item.pool?.chain === 'frax'
? item.pool.id
: item.pool.adapter_id || item.pool.id,
contractAddress:
item.pool?.chain === 'frax'
? item.pool.id
: item.pool.controller || item.pool.id,
raw_dollar: Number(item.stats.asset_usd_value),
token: item.detail.supply_token_list.map(
(supply: { amount: number; symbol: string }) => ({
amount: supply.amount,
symbol: supply.symbol,
}),
),
},
]
}
return []
})
}

const additionalTreasuryData: TreasuryTokenType[] = [
...processTreasuryData(
walletDetails.flatMap(({ data }) => data),
SUPPORTED_LP_TOKENS_ADDRESSES,
),
...processTreasuryData(
fraxConvexDetails || [],
fraxConvexDetails
? fraxConvexDetails.map((item: any) => item.pool.id)
: [],
),
]

const allTreasureDetails = [...treasuryDetails, ...additionalTreasuryData]

Expand Down

0 comments on commit 2d9770d

Please sign in to comment.