Skip to content
Open
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
18 changes: 12 additions & 6 deletions src/containers/ChainOverview/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ export const Stats = memo(function Stats(props: IStatsProps) {
<span className="font-jetbrains ml-auto">{formattedNum(props.dexs.total24h, true)}</span>
</summary>
<div className="mb-3 flex flex-col">
{props.dexs.total7d != null ? (
{props.dexs.total7d != null && (
<p className="justify-stat flex flex-wrap gap-4 border-b border-dashed border-(--cards-border) py-1 last:border-none">
<span className="text-(--text-label)">Volume (7d)</span>
<span className="font-jetbrains ml-auto">{formattedNum(props.dexs.total7d, true)}</span>
</p>
) : null}
)}
{props.dexs.change_7dover7d != null && (
<p className="justify-stat flex flex-wrap gap-4 border-b border-dashed border-(--cards-border) py-1 last:border-none">
<span className="text-(--text-label)">Weekly Change</span>
Expand All @@ -362,12 +362,12 @@ export const Stats = memo(function Stats(props: IStatsProps) {
</span>
</p>
)}
{props.dexs.dexsDominance != null ? (
{props.dexs.dexsDominance != null && (
<p className="justify-stat flex flex-wrap gap-4 border-b border-dashed border-(--cards-border) py-1 last:border-none">
<span className="text-(--text-label)">DEX vs CEX dominance</span>
<span className="font-jetbrains ml-auto">{props.dexs.dexsDominance}%</span>
</p>
) : null}
)}
</div>
</details>
) : null}
Expand Down Expand Up @@ -395,7 +395,7 @@ export const Stats = memo(function Stats(props: IStatsProps) {
<span className="font-jetbrains ml-auto">{formattedNum(props.perps.total7d, true)}</span>
</p>
) : null}
{props.perps.change_7dover7d != null ? (
{props.perps.change_7dover7d != null && (
<p className="justify-stat flex flex-wrap gap-4 border-b border-dashed border-(--cards-border) py-1 last:border-none">
<span className="text-(--text-label)">Weekly Change</span>
<span
Expand All @@ -406,7 +406,13 @@ export const Stats = memo(function Stats(props: IStatsProps) {
{`${props.perps.change_7dover7d >= 0 ? '+' : ''}${props.perps.change_7dover7d}%`}
</span>
</p>
) : null}
)}
{props.perps.dexsDominance != null && (
<p className="justify-stat flex flex-wrap gap-4 border-b border-dashed border-(--cards-border) py-1 last:border-none">
<span className="text-(--text-label)">DEX vs CEX dominance</span>
<span className="font-jetbrains ml-auto">{props.perps.dexsDominance}%</span>
</p>
)}
</div>
</details>
) : null}
Expand Down
12 changes: 9 additions & 3 deletions src/containers/ChainOverview/queries.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function getChainOverviewData({ chain }: { chain: string }): Promis
IAdapterSummary | null,
IAdapterSummary | null,
IAdapterOverview | null,
number | null,
{ spotVolume: number | null; derivativeVolume: number | null } | null,
Array<[number, number]> | null,
Array<[number, number]> | null,
Array<[number, { tvl: number; borrowed?: number; staking?: number; doublecounted?: number }]> | null,
Expand Down Expand Up @@ -562,13 +562,19 @@ export async function getChainOverviewData({ chain }: { chain: string }): Promis
total7d: dexs?.total7d ?? null,
change_7dover7d: dexs?.change_7dover7d ?? null,
dexsDominance:
cexVolume && dexs?.total24h ? +((dexs.total24h / (cexVolume + dexs.total24h)) * 100).toFixed(2) : null,
cexVolume && dexs?.total24h
? +((dexs.total24h / (cexVolume.spotVolume + dexs.total24h)) * 100).toFixed(2)
: null,
chart: dexs ? dexs.totalDataChart.slice(-14).map((x) => [x[0] * 1000, x[1]]) : null
},
perps: {
total24h: perps?.total24h ?? null,
total7d: perps?.total7d ?? null,
change_7dover7d: perps?.change_7dover7d ?? null
change_7dover7d: perps?.change_7dover7d ?? null,
dexsDominance:
cexVolume && perps?.total24h
? +((perps.total24h / (cexVolume.derivativeVolume + perps.total24h)) * 100).toFixed(2)
: null
},
users: { activeUsers, newUsers, transactions: transactions ? +transactions : null },
inflows: inflowsData,
Expand Down
7 changes: 6 additions & 1 deletion src/containers/ChainOverview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ export interface IChainOverviewData {
dexsDominance: number | null
chart: Array<[number, number]> | null
}
perps: { total24h: number | null; total7d: number | null; change_7dover7d: number | null }
perps: {
total24h: number | null
total7d: number | null
change_7dover7d: number | null
dexsDominance: number | null
}
users: { activeUsers: number | null; newUsers: number | null; transactions: number | null }
inflows: { netInflows: number | null } | null
treasury: { tvl: number | null; tokenBreakdowns: Record<string, number> | null } | null
Expand Down
27 changes: 23 additions & 4 deletions src/containers/DimensionAdapters/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,42 @@ export async function getAdapterProtocolSummary({
}

export async function getCexVolume() {
const [cexs, btcPriceRes] = await Promise.all([
const [cexs, cexDerivatives, btcPriceRes] = await Promise.all([
fetchJson(
`https://api.llama.fi/cachedExternalResponse?url=${encodeURIComponent(
'https://api.coingecko.com/api/v3/exchanges?per_page=250'
)}`
),
fetchJson(`https://pro-api.coingecko.com/api/v3/derivatives/exchanges?per_page=250`, {
headers: {
'x-cg-pro-api-key': process.env.CG_KEY
}
}),
fetchJson(
`https://api.llama.fi/cachedExternalResponse?url=${encodeURIComponent(
'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd'
)}`
)
])
const btcPrice = btcPriceRes?.bitcoin?.usd
if (!btcPrice || !cexs || typeof cexs.filter !== 'function') return undefined
if (
!btcPrice ||
!cexs ||
typeof cexs.filter !== 'function' ||
!cexDerivatives ||
typeof cexDerivatives.filter !== 'function'
)
return undefined

// cexs might not be a list TypeError: cexs.filter is not a function
const volume = cexs.filter((c) => c.trust_score >= 9).reduce((sum, c) => sum + c.trade_volume_24h_btc, 0) * btcPrice
return volume
const spotVolume =
cexs.filter((c) => c.trust_score >= 9).reduce((sum, c) => sum + c.trade_volume_24h_btc, 0) * btcPrice
const derivativeVolume =
cexDerivatives
.filter((c) => c.number_of_perpetual_pairs >= 10)
.reduce((sum, c) => sum + Number(c.trade_volume_24h_btc), 0) * btcPrice

return { spotVolume, derivativeVolume }
}

async function getEmissionsData() {
Expand Down