From 72d7f193f0f59ec5dc63aaa9336f80180a8730a8 Mon Sep 17 00:00:00 2001 From: tiltom Date: Tue, 6 Feb 2024 15:42:56 +0100 Subject: [PATCH] SOV-3727: Adjust staking rewards claim (#2592) * Adjust staking rewards claim * Fix invalid restart time * Potential claim fix * force rebuild * Start time fix --- .../hooks/useGetLiquidSovClaimAmount.ts | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/app/pages/RewardPage/hooks/useGetLiquidSovClaimAmount.ts b/src/app/pages/RewardPage/hooks/useGetLiquidSovClaimAmount.ts index a446c54bf..a935df095 100644 --- a/src/app/pages/RewardPage/hooks/useGetLiquidSovClaimAmount.ts +++ b/src/app/pages/RewardPage/hooks/useGetLiquidSovClaimAmount.ts @@ -21,23 +21,32 @@ export const useGetLiquidSovClaimAmount = () => { } const now = Math.ceil(Date.now() / 1000); - const lockDate = await contractReader - .call('staking', 'timestampToLockDate', [now]) + + const startTime = await contractReader + .call('stakingRewards', 'startTime', []) + .then(Number); + + const maxDuration = await contractReader + .call('stakingRewards', 'maxDuration', []) .then(Number); + const result = await contractReader.call<{ + lastWithdrawalInterval: string; + amount: string; + }>('stakingRewards', 'getStakerCurrentReward', [false, 0], address); + let checks = 30; - let amount = 0; + let intervalAmount = 0; let lastWithdrawalInterval = 0; - let restartTime = 0; + let restartTime = startTime; - // If lastWithdrawalInterval > 0 and amount = 0 - // call getStakerCurrentReward(True, lastWithdrawalInterval) - // Stop when: a) Both lastWithdrawalInterval > 0 and amount > 0 OR b) lastWithdrawalInterval(returned) > currentTimeStamp + // Call getStakerCurrentReward(True, restartTime) until either + // a) lastWithdrawalInterval > 0 and amount > 0 OR b) restartTime >= now // as additional brake, run at maximum 30 checks while ( !( - (lastWithdrawalInterval > 0 && amount > 0) || - lastWithdrawalInterval === lockDate || + (lastWithdrawalInterval > 0 && intervalAmount > 0) || + restartTime >= now || checks < 0 ) ) { @@ -49,7 +58,7 @@ export const useGetLiquidSovClaimAmount = () => { }>( 'stakingRewards', 'getStakerCurrentReward', - [false, lastWithdrawalInterval], + [true, restartTime], address, ) .then(response => ({ @@ -61,8 +70,12 @@ export const useGetLiquidSovClaimAmount = () => { restartTime = lastWithdrawalInterval; } + if (result.amount === 0) { + restartTime += Number(maxDuration); + } + lastWithdrawalInterval = result.lastWithdrawalInterval; - amount = result.amount; + intervalAmount = result.amount; checks--; } catch (e) { console.error(e); @@ -72,7 +85,7 @@ export const useGetLiquidSovClaimAmount = () => { return { lastWithdrawalInterval: restartTime, - amount: bignumber(amount).toString(), + amount: bignumber(result.amount).toString(), }; }, [address]);