From a36eb3ca6291f40462d365302c1d8bf56c84efa2 Mon Sep 17 00:00:00 2001 From: Atatakai Date: Fri, 6 Dec 2024 11:44:47 +0400 Subject: [PATCH 1/2] feat: add isEligibleForRewards logic, some fixes around loading states --- frontend/context/RewardProvider.tsx | 4 ++-- frontend/context/ServicesProvider.tsx | 19 ++++++++------- frontend/service/agents/Memeooor.ts | 33 +++++++++++---------------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/frontend/context/RewardProvider.tsx b/frontend/context/RewardProvider.tsx index a1077da08..8052d7282 100644 --- a/frontend/context/RewardProvider.tsx +++ b/frontend/context/RewardProvider.tsx @@ -127,7 +127,7 @@ export const RewardProvider = ({ children }: PropsWithChildren) => { const { data: stakingRewardsDetails, refetch: refetchStakingRewardsDetails, - isFetched: isStakingRewardsDetailsFetched, + isLoading: isStakingRewardsDetailsLoading, } = useStakingRewardsDetails(); const { data: availableRewardsForEpoch, @@ -177,7 +177,7 @@ export const RewardProvider = ({ children }: PropsWithChildren) => { isEligibleForRewards, optimisticRewardsEarnedForEpoch, updateRewards, - isStakingRewardsDetailsFetched, + isStakingRewardsDetailsFetched: !isStakingRewardsDetailsLoading, }} > {children} diff --git a/frontend/context/ServicesProvider.tsx b/frontend/context/ServicesProvider.tsx index e7d9ab0fe..4723ed5cf 100644 --- a/frontend/context/ServicesProvider.tsx +++ b/frontend/context/ServicesProvider.tsx @@ -91,8 +91,7 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { const { data: services, isError, - isFetched: isServicesFetched, - isLoading, + isLoading: isServicesLoading, isFetching, refetch, } = useQuery({ @@ -104,7 +103,7 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { const { data: selectedServiceStatus, - isFetched: isSelectedServiceStatusFetched, + isLoading: isSelectedServiceStatusLoading, refetch: refetchSelectedServiceStatus, } = useQuery({ queryKey: REACT_QUERY_KEYS.SERVICE_DEPLOYMENT_STATUS_KEY( @@ -161,7 +160,7 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { }, [selectedAgentType]); const serviceWallets: Optional = useMemo(() => { - if (!isServicesFetched) return; + if (isServicesLoading) return; if (isEmpty(services)) return []; return services?.reduce( @@ -208,14 +207,14 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { }, [], ); - }, [isServicesFetched, services]); + }, [isServicesLoading, services]); /** * Select the first service by default */ useEffect(() => { if (!selectedAgentConfig) return; - if (!isServicesFetched) return; + if (isSelectedServiceStatusLoading) return; if (!services) return; if (isEmpty(services)) return; @@ -227,7 +226,7 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { setSelectedServiceConfigId(currentService.service_config_id); }, [ - isServicesFetched, + isSelectedServiceStatusLoading, selectedServiceConfigId, services, selectedAgentConfig, @@ -239,8 +238,8 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { services, serviceWallets, isError, - isFetched: isServicesFetched, - isLoading, + isFetched: !isServicesLoading, + isLoading: isServicesLoading, isFetching, refetch, paused, @@ -250,7 +249,7 @@ export const ServicesProvider = ({ children }: PropsWithChildren) => { selectedService: selectedServiceWithStatus, selectedServiceStatusOverride, refetchSelectedServiceStatus, - isSelectedServiceStatusFetched, + isSelectedServiceStatusFetched: !isSelectedServiceStatusLoading, selectedAgentConfig, selectedAgentType, updateAgentType, diff --git a/frontend/service/agents/Memeooor.ts b/frontend/service/agents/Memeooor.ts index 0bad22d35..81f842679 100644 --- a/frontend/service/agents/Memeooor.ts +++ b/frontend/service/agents/Memeooor.ts @@ -40,31 +40,27 @@ export abstract class MemeooorBaseService extends StakedAgentService { const provider = PROVIDERS[chainId].multicallProvider; - // TODO: discuss how to calculate the activity - // const mechContract = - // MECHS[chainId][stakingProgramConfig.mechType!].contract; - const contractCalls = [ - // mechContract.getRequestsCount(agentMultisigAddress), stakingTokenProxyContract.getServiceInfo(serviceId), stakingTokenProxyContract.livenessPeriod(), - activityChecker.livenessRatio(), stakingTokenProxyContract.rewardsPerSecond(), stakingTokenProxyContract.calculateStakingReward(serviceId), stakingTokenProxyContract.minStakingDeposit(), stakingTokenProxyContract.tsCheckpoint(), + activityChecker.livenessRatio(), + activityChecker.getMultisigNonces(), ]; const multicallResponse = await provider.all(contractCalls); const [ - // mechRequestCount, serviceInfo, livenessPeriod, - livenessRatio, rewardsPerSecond, accruedStakingReward, minStakingDeposit, tsCheckpoint, + livenessRatio, + currentMultisigNonces, ] = multicallResponse; /** @@ -83,19 +79,16 @@ export abstract class MemeooorBaseService extends StakedAgentService { uint256 inactivity;} */ + const lastMultisigNonces = serviceInfo[2]; const nowInSeconds = Math.floor(Date.now() / 1000); - // const requiredMechRequests = - // (Math.ceil(Math.max(livenessPeriod, nowInSeconds - tsCheckpoint)) * - // livenessRatio) / - // 1e18 + - // MECH_REQUESTS_SAFETY_MARGIN; - - // const mechRequestCountOnLastCheckpoint = serviceInfo[2][1]; - // const eligibleRequests = - // mechRequestCount - mechRequestCountOnLastCheckpoint; - - // const isEligibleForRewards = eligibleRequests >= requiredMechRequests; + const [isEligibleForRewards] = await provider.all([ + activityChecker.isRatioPass( + currentMultisigNonces, + lastMultisigNonces, + Math.ceil(nowInSeconds - tsCheckpoint), + ), + ]); const availableRewardsForEpoch = Math.max( rewardsPerSecond * livenessPeriod, // expected rewards for the epoch @@ -112,7 +105,7 @@ export abstract class MemeooorBaseService extends StakedAgentService { livenessPeriod, livenessRatio, rewardsPerSecond, - isEligibleForRewards: false, + isEligibleForRewards, availableRewardsForEpoch, accruedServiceStakingRewards: parseFloat( ethers.utils.formatEther(`${accruedStakingReward}`), From ff71c47e2f3c5ceecb3b60111c2d8c6515ad3c07 Mon Sep 17 00:00:00 2001 From: Atatakai Date: Fri, 6 Dec 2024 11:55:00 +0400 Subject: [PATCH 2/2] chore: remove comment --- frontend/config/stakingPrograms/base.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/config/stakingPrograms/base.ts b/frontend/config/stakingPrograms/base.ts index e96277090..5bdf7c7a9 100644 --- a/frontend/config/stakingPrograms/base.ts +++ b/frontend/config/stakingPrograms/base.ts @@ -24,8 +24,6 @@ export const BASE_STAKING_PROGRAMS: StakingProgramMap = { stakingRequirements: { [TokenSymbol.OLAS]: 100, }, - // TODO: find out how the activity is tracked and provide mech if through it - // mech: MECHS[EvmChainId.Base][??].contract, activityChecker: ACTIVITY_CHECKERS[EvmChainId.Base][ ActivityCheckerType.MemeActivityChecker