Skip to content

Commit

Permalink
(operate) fix: apy calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Atatakai authored and Atatakai committed Aug 23, 2024
1 parent 0987cb8 commit 4d03999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions apps/operate/components/Contracts/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const AVAILABLE_ON: Record<Address, StakingContract['availableOn']> = {
'0x0000000000000000000000005344b7dd311e5d3dddd46a4f71481bd7b05aaa3e': 'quickstart',
};

const getApy = (rewardsPerSecond: bigint, minStakingDeposit: bigint) => {
const getApy = (
rewardsPerSecond: bigint,
minStakingDeposit: bigint,
maxNumAgentInstances: bigint,
) => {
const rewardsPerYear = rewardsPerSecond * BigInt(ONE_YEAR);
const apy = (rewardsPerYear * BigInt(100)) / minStakingDeposit;
return (Number(apy) / 100).toFixed(2);
return Number(apy) / (1 + Number(maxNumAgentInstances));
};

const getStakeRequired = (minStakingDeposit: bigint, numAgentInstances: bigint) => {
Expand Down Expand Up @@ -103,7 +107,7 @@ export const useStakingContractsList = () => {
const minStakingDeposit = minStakingDepositList[index] as bigint;
const numAgentInstances = numAgentInstancesList[index] as bigint;

const apy = getApy(rewardsPerSecond, minStakingDeposit);
const apy = getApy(rewardsPerSecond, minStakingDeposit, numAgentInstances);
const stakeRequired = getStakeRequired(minStakingDeposit, numAgentInstances);

return {
Expand Down
2 changes: 1 addition & 1 deletion apps/operate/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type StakingContract = {
metadata: Metadata;
availableSlots: number;
maxSlots: number;
apy: string;
apy: number;
stakeRequired: string;
availableOn: 'pearl' | 'quickstart' | null;
};

0 comments on commit 4d03999

Please sign in to comment.