Skip to content

Commit

Permalink
feat(operate): add available rewards display in staking contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Nov 7, 2024
1 parent 8f6d182 commit d4cfb71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions apps/operate/components/Contracts/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { StakingContract } from 'types';
import { Abi, Address, formatEther } from 'viem';
import { Abi, Address, formatEther, formatUnits } from 'viem';
import { useReadContracts } from 'wagmi';

import { useNominees, useNomineesMetadata } from 'libs/common-contract-functions/src';
Expand Down Expand Up @@ -203,11 +203,13 @@ export const useStakingContractsList = () => {
return nominees.map((item, index) => {
const maxSlots = Number(maxNumServicesList[index]);
const servicesLength = ((serviceIdsList[index] as string[]) || []).length;
const availableRewards = availableRewardsList[index] as bigint;
const availableSlots = availableRewards > 0 && maxSlots > 0 ? maxSlots - servicesLength : 0;
const availableRewardsInWei = availableRewardsList[index] as bigint;
const availableSlots =
availableRewardsInWei > 0 && maxSlots > 0 ? maxSlots - servicesLength : 0;
const rewardsPerSecond = rewardsPerSecondList[index] as bigint;
const minStakingDeposit = minStakingDepositList[index] as bigint;
const numAgentInstances = numAgentInstancesList[index] as bigint;
const availableRewards = Number(formatUnits(availableRewardsInWei, 18)).toFixed(2);

const apy = getApy(rewardsPerSecond, minStakingDeposit, numAgentInstances);
const stakeRequired = getStakeRequired(minStakingDeposit, numAgentInstances);
Expand All @@ -226,6 +228,7 @@ export const useStakingContractsList = () => {
minOperatingBalance: details?.minOperatingBalance,
minOperatingBalanceToken: details?.minOperatingBalanceToken || null,
minOperatingBalanceHint: details?.minOperatingBalanceHint || null,
availableRewards,
};
}) as StakingContract[];
}
Expand Down
9 changes: 8 additions & 1 deletion apps/operate/components/Contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const columns: ColumnsType<StakingContract> = [
render: (apy) => <Tag color="purple" className="m-0">{`${apy}%`}</Tag>,
className: 'text-end',
},
{
title: () => 'Available Rewards (OLAS)',
dataIndex: 'availableRewards',
key: 'availableRewards',
render: (availableRewards) => <Text>{availableRewards}</Text>,
className: 'text-end',
},
{
title: 'Stake required, OLAS',
dataIndex: 'stakeRequired',
Expand Down Expand Up @@ -77,7 +84,7 @@ const columns: ColumnsType<StakingContract> = [
);
},
className: 'text-end',
width: 200,
width: 180,
},
{
title: () => (
Expand Down
1 change: 1 addition & 0 deletions apps/operate/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type StakingContract = {
minOperatingBalance: number | null;
minOperatingBalanceToken: string | null;
minOperatingBalanceHint?: string;
availableRewards: string;
};

0 comments on commit d4cfb71

Please sign in to comment.