Skip to content

Commit

Permalink
Merge pull request #611 from valory-xyz/mohan/flickering-debug
Browse files Browse the repository at this point in the history
fix: flickering debug for agents.fun
  • Loading branch information
mohandast52 authored Dec 18, 2024
2 parents dc3e708 + 0c4281c commit 18f5b2b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const useEpochEndTime = () => {
return { data, isLoading };
};

/**
* Staking rewards for the current epoch
*/
export const StakingRewardsThisEpoch = () => {
const { data: epochEndTimeInMs } = useEpochEndTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const DisplayRewards = () => {
const reward = getFormattedReward(availableRewardsForEpochEth);

const earnedTag = useMemo(() => {
if (isStakingRewardsDetailsLoading && !isStakingRewardsDetailsError)
if (isStakingRewardsDetailsLoading && !isStakingRewardsDetailsError) {
return <Skeleton.Input size="small" />;
}
if (isEligibleForRewards) {
return <Tag color="success">Earned</Tag>;
}
Expand Down
21 changes: 11 additions & 10 deletions frontend/context/RewardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,24 @@ const useStakingRewardsDetails = () => {
token!,
),
queryFn: async () => {
if (!multisig || !token || !selectedStakingProgramId) return null;
const response =
await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({
agentMultisigAddress: multisig,
serviceId: token,
stakingProgramId: selectedStakingProgramId,
chainId: currentChainId,
});
try {
const response =
await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({
agentMultisigAddress: multisig!,
serviceId: token!,
stakingProgramId: selectedStakingProgramId!,
chainId: currentChainId,
});

if (!response) return null;
if (!response) return null;

try {
const parsed = StakingRewardsInfoSchema.parse(response);
return parsed;
} catch (e) {
console.error('Error parsing staking rewards info', e);
}

return null;
},
enabled:
!!isOnline &&
Expand Down
20 changes: 12 additions & 8 deletions frontend/service/agents/Memeooor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export abstract class MemeooorBaseService extends StakedAgentService {
stakingTokenProxyContract.minStakingDeposit(),
stakingTokenProxyContract.tsCheckpoint(),
activityChecker.livenessRatio(),
activityChecker.getMultisigNonces(),
activityChecker.getMultisigNonces(agentMultisigAddress),
];
const multicallResponse = await provider.all(contractCalls);

Expand Down Expand Up @@ -82,13 +82,17 @@ export abstract class MemeooorBaseService extends StakedAgentService {
const lastMultisigNonces = serviceInfo[2];
const nowInSeconds = Math.floor(Date.now() / 1000);

const [isEligibleForRewards] = await provider.all([
activityChecker.isRatioPass(
currentMultisigNonces,
lastMultisigNonces,
Math.ceil(nowInSeconds - tsCheckpoint),
),
]);
const isServiceStaked = serviceInfo[2].length > 0;

const [isEligibleForRewards] = isServiceStaked
? await provider.all([
activityChecker.isRatioPass(
currentMultisigNonces,
lastMultisigNonces,
Math.ceil(nowInSeconds - tsCheckpoint),
),
])
: [false];

const availableRewardsForEpoch = Math.max(
rewardsPerSecond * livenessPeriod, // expected rewards for the epoch
Expand Down

0 comments on commit 18f5b2b

Please sign in to comment.