diff --git a/src/api/categories/protocols/index.ts b/src/api/categories/protocols/index.ts index ab87a3819..eb4db8186 100644 --- a/src/api/categories/protocols/index.ts +++ b/src/api/categories/protocols/index.ts @@ -19,7 +19,8 @@ import { CHART_API, ETF_OVERVIEW_API, ETF_HISTORY_API, - CHAINS_API_V2 + CHAINS_API_V2, + TOTAL_PROTOCOL_USERS_API } from '~/constants' import { BasicPropsToKeep, formatProtocolsData } from './utils' import { @@ -948,6 +949,20 @@ export async function getAirdropDirectoryData() { })) } +export async function getTotalProtocolUsersData() { + const protocolUsers_ = await fetchWithErrorLogging(TOTAL_PROTOCOL_USERS_API).then((r) => r.json()) + + const protcolUsers = {} + for (const p of protocolUsers_) { + protcolUsers[p.protocolid] = { + totalTxs: +p.total_txs, + totalUsers: +p.total_users, + txsOverUsers: +p.txs_over_users + } + } + return protcolUsers +} + export function formatGovernanceData(data: { proposals: Array<{ scores: Array; choices: Array; id: string }> stats: { diff --git a/src/components/Table/Defi/Protocols/columns.tsx b/src/components/Table/Defi/Protocols/columns.tsx index c2c937fed..d6223de91 100644 --- a/src/components/Table/Defi/Protocols/columns.tsx +++ b/src/components/Table/Defi/Protocols/columns.tsx @@ -548,6 +548,33 @@ export const airdropsColumns: ColumnDef[] = [ } }, listedAtColumn, + { + header: 'Total Tx', + accessorKey: 'totalTxs', + cell: ({ getValue }) => <>{getValue() ? `${toK(getValue())}` : ''}, + size: 120, + meta: { + align: 'end' as const + } + }, + { + header: 'Total Users', + accessorKey: 'totalUsers', + cell: ({ getValue }) => <>{getValue() ? `${toK(getValue())}` : ''}, + size: 120, + meta: { + align: 'end' as const + } + }, + { + header: 'Tx over Users', + accessorKey: 'txsOverUsers', + cell: ({ getValue }) => <>{getValue() ? `${toK(getValue())}` : ''}, + size: 120, + meta: { + align: 'end' as const + } + }, ...protocolsColumns.slice(3, -1).filter((c: any) => !['volume_7d', 'fees_7d', 'revenue_7d'].includes(c.accessorKey)) ] diff --git a/src/constants/index.ts b/src/constants/index.ts index 701fb6c4b..8a9701bf6 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -135,3 +135,5 @@ export const DEV_METRICS_API = 'https://defillama-datasets.llama.fi/dev-metrics/ export const MCAPS_API = 'https://coins.llama.fi/mcaps' export const CACHE_SERVER = 'https://fe-cache.llama.fi' + +export const TOTAL_PROTOCOL_USERS_API = 'https://api.llama.fi/totalProtocolUsers' diff --git a/src/pages/airdrops.tsx b/src/pages/airdrops.tsx index 490344c79..e3bd52c65 100644 --- a/src/pages/airdrops.tsx +++ b/src/pages/airdrops.tsx @@ -1,6 +1,10 @@ import { RecentProtocols } from '~/components/RecentProtocols' import { maxAgeForNext } from '~/api' -import { getAirdropDirectoryData, getSimpleProtocolsPageData } from '~/api/categories/protocols' +import { + getAirdropDirectoryData, + getSimpleProtocolsPageData, + getTotalProtocolUsersData +} from '~/api/categories/protocols' import { basicPropertiesToKeep } from '~/api/categories/protocols/utils' import { FORK_API, RAISES_API } from '~/constants' import { fetchOverCache, withPerformanceLogging } from '~/utils/perf' @@ -114,11 +118,12 @@ const exclude = [ ] export const getStaticProps = withPerformanceLogging('airdrops', async () => { - const [protocolsRaw, { forks }, { raises }, claimableAirdrops] = await Promise.all([ + const [protocolsRaw, { forks }, { raises }, claimableAirdrops, totalProtocolUsers] = await Promise.all([ getSimpleProtocolsPageData([...basicPropertiesToKeep, 'extraTvl', 'listedAt', 'chainTvls', 'defillamaId']), fetchOverCache(FORK_API).then((r) => r.json()), fetchOverCache(RAISES_API).then((r) => r.json()), - getAirdropDirectoryData() + getAirdropDirectoryData(), + getTotalProtocolUsersData() ]) const parents = protocolsRaw.parentProtocols.reduce((acc, p) => { @@ -127,7 +132,7 @@ export const getStaticProps = withPerformanceLogging('airdrops', async () => { } return acc }, {}) - const protocols = protocolsRaw.protocols + let protocols = protocolsRaw.protocols .filter( (token) => (token.symbol === null || token.symbol === '-') && @@ -150,6 +155,13 @@ export const getStaticProps = withPerformanceLogging('airdrops', async () => { })) .sort((a, b) => a.listedAt - b.listedAt) + protocols = protocols.map((p) => ({ + ...p, + totalTxs: totalProtocolUsers[p.defillamaId]?.totalTxs ?? null, + totalUsers: totalProtocolUsers[p.defillamaId]?.totalUsers ?? null, + txsOverUsers: totalProtocolUsers[p.defillamaId]?.txsOverUsers ?? null + })) + const forkedList: { [name: string]: boolean } = {} Object.values(forks).map((list: string[]) => {