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

txCosts using layer2Data #14616

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
28 changes: 17 additions & 11 deletions src/lib/api/fetchGrowThePie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { GrowThePieData } from "../types"
import type { GrowThePieData } from "@/lib/types"

import { layer2Data } from "@/data/networks/networks"

type DataItem = {
metric_key: string
Expand Down Expand Up @@ -44,18 +46,22 @@ export const fetchGrowThePie = async (): Promise<GrowThePieData> => {
let totalTxCount = 0
let weightedSum = 0

mostRecentData.forEach((item) => {
if (item.metric_key !== TXCOSTS_MEDIAN_USD) return

const txCountItem = mostRecentData.find(
(txItem) =>
txItem.metric_key === TXCOUNT && txItem.origin_key === item.origin_key
mostRecentData
.filter((item) =>
layer2Data.some((l2) => l2.growthepieID === item.origin_key)
)
if (!txCountItem) return
.forEach((item) => {
if (item.metric_key !== TXCOSTS_MEDIAN_USD) return

const txCountItem = mostRecentData.find(
(txItem) =>
txItem.metric_key === TXCOUNT && txItem.origin_key === item.origin_key
)
if (!txCountItem) return

totalTxCount += txCountItem.value
weightedSum += item.value * txCountItem.value
})
totalTxCount += txCountItem.value
weightedSum += item.value * txCountItem.value
})

// The weighted average of txcosts_median_usd, by txcount on each network (origin_key)
const weightedAverage = totalTxCount ? weightedSum / totalTxCount : 0
Expand Down
Loading