Skip to content

Commit

Permalink
SOV-3727: Adjust staking rewards claim (#2592)
Browse files Browse the repository at this point in the history
* Adjust staking rewards claim

* Fix invalid restart time

* Potential claim fix

* force rebuild

* Start time fix
  • Loading branch information
tiltom authored Feb 6, 2024
1 parent d0cadea commit 72d7f19
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/app/pages/RewardPage/hooks/useGetLiquidSovClaimAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
) {
Expand All @@ -49,7 +58,7 @@ export const useGetLiquidSovClaimAmount = () => {
}>(
'stakingRewards',
'getStakerCurrentReward',
[false, lastWithdrawalInterval],
[true, restartTime],
address,
)
.then(response => ({
Expand All @@ -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);
Expand All @@ -72,7 +85,7 @@ export const useGetLiquidSovClaimAmount = () => {

return {
lastWithdrawalInterval: restartTime,
amount: bignumber(amount).toString(),
amount: bignumber(result.amount).toString(),
};
}, [address]);

Expand Down

0 comments on commit 72d7f19

Please sign in to comment.