Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new columns #1668

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/api/categories/protocols/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<number>; choices: Array<string>; id: string }>
stats: {
Expand Down
27 changes: 27 additions & 0 deletions src/components/Table/Defi/Protocols/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,33 @@ export const airdropsColumns: ColumnDef<IProtocolRow>[] = [
}
},
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))
]

Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
20 changes: 16 additions & 4 deletions src/pages/airdrops.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 === '-') &&
Expand All @@ -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[]) => {
Expand Down