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

Only use active positions for metrics #107

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/app/stats/components/HntInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { fetchHntGovernanceStats } from "../utils/fetchGovernanceMetrics"
import { fetchMint } from "../utils/fetchMint"
import { getNextHalvening } from "../utils/getNextHalvening"
import {
getRemainingEmissions,
MAX_DAILY_NET_EMISSIONS,
getRemainingEmissions,
} from "../utils/remainingEmissions"
import { Countdown } from "./Countdown"

Expand Down
20 changes: 16 additions & 4 deletions src/app/stats/utils/positionsMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,21 @@ const getSum = (nums: BN[]) => {
}

export const getPositionMetrics = async (positions: PositionWithMeta[]) => {
const vehnt = positions.map(({ veHnt }) => veHnt)
const hnt = positions.map((position) => position.amountDepositedNative)
const lockups = await getPositionLockups(positions)
const now = await fetchUnixTimestap()
const nowBN = new BN(now)

const activePositions = positions.filter((position) => {
const expiredCliff =
Object.keys(position.lockup.kind as LockupKind)[0] === "cliff" &&
position.lockup.endTs.lt(nowBN)

// constant positions and non expired cliffs are still active
return !expiredCliff
})

const vehnt = activePositions.map(({ veHnt }) => veHnt)
const hnt = activePositions.map((position) => position.amountDepositedNative)
const lockups = await getPositionLockups(activePositions)
const positonMetrics: PositionMetrics = {
stats: {
avgVehnt: getMean(vehnt),
Expand All @@ -82,7 +94,7 @@ export const getPositionMetrics = async (positions: PositionWithMeta[]) => {
medianLockup: getMedian(lockups),
},
total: {
count: new BN(positions.length) as BN,
count: new BN(activePositions.length) as BN,
hnt: getSum(hnt),
vehnt: getSum(vehnt),
},
Expand Down