Skip to content

Commit

Permalink
Dynamic epoch duration
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Dec 20, 2024
1 parent d69b502 commit 3432571
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 0 additions & 4 deletions frontend/app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,3 @@ export const REDEMPTION_RISK: Record<Exclude<RiskLevel, "high">, number> = {
medium: 3.5 / 100,
low: 5 / 100,
};

// in seconds
export const GOVERNANCE_EPOCH_DURATION = 604800;
export const GOVERNANCE_EPOCH_VOTING_CUTOFF = 518400;
28 changes: 20 additions & 8 deletions frontend/app/src/liquity-governance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Address, Initiative } from "@/src/types";
import type { Config as WagmiConfig } from "wagmi";

import { GOVERNANCE_EPOCH_DURATION, GOVERNANCE_EPOCH_VOTING_CUTOFF } from "@/src/constants";
import { getProtocolContract } from "@/src/contracts";
import { KNOWN_INITIATIVES_URL } from "@/src/env";
import { useGovernanceInitiatives } from "@/src/subgraph-hooks";
Expand All @@ -23,30 +22,43 @@ export function useGovernanceState() {
}, {
...Governance,
functionName: "secondsWithinEpoch",
}, {
...Governance,
functionName: "EPOCH_DURATION",
}, {
...Governance,
functionName: "EPOCH_VOTING_CUTOFF",
}],
query: {
select: ([
epochStart,
epochStart_,
totalVotesAndState,
secondsWithinEpoch,
GOVERNANCE_EPOCH_DURATION,
GOVERNANCE_EPOCH_VOTING_CUTOFF,
]) => {
const period: "cutoff" | "voting" = (secondsWithinEpoch.result ?? 0n) > GOVERNANCE_EPOCH_VOTING_CUTOFF
const epochStart = epochStart_.result ?? 0n;
const epochDuration = GOVERNANCE_EPOCH_DURATION.result ?? 0n;
const epochVotingCutoff = GOVERNANCE_EPOCH_VOTING_CUTOFF.result ?? 0n;

const period: "cutoff" | "voting" = (secondsWithinEpoch.result ?? 0n) > epochVotingCutoff
? "cutoff"
: "voting";

const seconds = Number(secondsWithinEpoch.result ?? 0n);
const daysLeft = (Number(GOVERNANCE_EPOCH_DURATION) - seconds) / (24 * 60 * 60);
const daysLeft = (Number(epochDuration) - seconds) / (24 * 60 * 60);
const daysLeftRounded = Math.ceil(daysLeft);

return {
countedVoteLQTY: totalVotesAndState.result?.[1].countedVoteLQTY,
countedVoteOffset: totalVotesAndState.result?.[1].countedVoteOffset,
epochStart: epochStart.result,
secondsWithinEpoch: secondsWithinEpoch.result,
totalVotes: totalVotesAndState.result?.[0],
period,
daysLeft,
daysLeftRounded,
epochEnd: epochStart + epochDuration,
epochStart,
period,
secondsWithinEpoch: secondsWithinEpoch.result,
totalVotes: totalVotesAndState.result?.[0],
};
},
},
Expand Down

0 comments on commit 3432571

Please sign in to comment.