Skip to content
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 apps/staking/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const loadPublisherData = async (
);
const apyHistory = publisher.apyHistory.map(({ epoch, apy }) => ({
date: epochToDate(epoch + 1n),
apy: Number(apy),
apy,
}));

return {
Expand Down
3 changes: 3 additions & 0 deletions governance/pyth_staking_sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const ONE_WEEK_IN_SECONDS = 7n * ONE_DAY_IN_SECONDS;

export const EPOCH_DURATION = ONE_WEEK_IN_SECONDS;

export const FRACTION_PRECISION = 1_000_000;
export const FRACTION_PRECISION_N = 1_000_000n;

export const POSITION_BUFFER_SIZE = 200;
export const POSITIONS_ACCOUNT_HEADER_SIZE = DISCRIMINATOR_SIZE + 32;

Expand Down
2 changes: 1 addition & 1 deletion governance/pyth_staking_sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type PublisherData = {
stakeAccount: PublicKey | null;
totalDelegation: bigint;
selfDelegation: bigint;
apyHistory: { epoch: bigint; apy: bigint; selfApy: bigint }[];
apyHistory: { epoch: bigint; apy: number; selfApy: number }[];
}[];

export enum PositionState {
Expand Down
8 changes: 7 additions & 1 deletion governance/pyth_staking_sdk/src/utils/apy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { FRACTION_PRECISION } from "../constants";

export const convertEpochYieldToApy = (epochYield: bigint) => {
return (Number(epochYield) * 52 * 100) / FRACTION_PRECISION;
};

export const calculateApy = (
options: {
selfStake: bigint;
Expand All @@ -8,7 +14,7 @@ export const calculateApy = (
const { selfStake, poolCapacity, yieldRate, isSelf } = options;
const eligibleSelfStake = selfStake > poolCapacity ? poolCapacity : selfStake;

const apyPercentage = (Number(yieldRate) * 52 * 100) / 1_000_000;
const apyPercentage = convertEpochYieldToApy(yieldRate);

if (isSelf) {
if (selfStake === 0n) {
Expand Down
12 changes: 8 additions & 4 deletions governance/pyth_staking_sdk/src/utils/pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PublicKey } from "@solana/web3.js";

import { convertEpochYieldToApy } from "./apy";
import { FRACTION_PRECISION_N } from "../constants";
import type { PoolDataAccount, PublisherData } from "../types";

export const extractPublisherData = (
Expand All @@ -22,12 +24,14 @@ export const extractPublisherData = (
.filter((event) => event.epoch > 0n)
.map((event) => ({
epoch: event.epoch,
apy:
apy: convertEpochYieldToApy(
(event.y * (event.eventData[index]?.otherRewardRatio ?? 0n)) /
1_000_000n,
selfApy:
FRACTION_PRECISION_N,
),
selfApy: convertEpochYieldToApy(
(event.y * (event.eventData[index]?.selfRewardRatio ?? 0n)) /
1_000_000n,
FRACTION_PRECISION_N,
),
}))
.sort((a, b) => Number(a.epoch) - Number(b.epoch)),
}));
Expand Down
Loading