Skip to content

Commit

Permalink
chore: Refactor Autonolas.ts to improve code readability and remove c…
Browse files Browse the repository at this point in the history
…onsole.log statements
  • Loading branch information
truemiller committed Jun 19, 2024
1 parent 200e321 commit 4d1a4c4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions frontend/service/Autonolas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ const getAgentStakingRewardsInfo = async ({
uint256 inactivity;}
*/

const nowInSeconds = Math.round(Date.now() / 1000);

const requiredMechRequests =
(Math.ceil(
Math.max(
livenessPeriod,
Math.round(Date.now() / 1000) - lastTsCheckpoint,
),
) *
(Math.ceil(Math.max(livenessPeriod, nowInSeconds - lastTsCheckpoint)) *
livenessRatio) /
1e18 +
REQUIRED_MECH_REQUESTS_SAFETY_MARGIN;
Expand Down Expand Up @@ -140,16 +137,22 @@ const getAgentStakingRewardsInfo = async ({
const getAvailableRewardsForEpoch = async (): Promise<number | undefined> => {
const contractCalls = [
serviceStakingTokenMechUsageContract.rewardsPerSecond(),
serviceStakingTokenMechUsageContract.livenessPeriod(),
serviceStakingTokenMechUsageContract.epochLength(),
serviceStakingTokenMechUsageContract.tsCheckpoint(), // last checkpoint timestamp
];

await gnosisMulticallProvider.init();

const multicallResponse = await gnosisMulticallProvider.all(contractCalls);

const [rewardsPerSecond, livenessPeriod] = multicallResponse;
const [rewardsPerSecond, epochLength, tsCheckpoint] = multicallResponse;

const nowInSeconds = Math.round(Date.now() / 1000);

return rewardsPerSecond * livenessPeriod;
return Math.max(
rewardsPerSecond * epochLength,
rewardsPerSecond * (nowInSeconds - tsCheckpoint),
);
};

const getServiceRegistryInfo = async (
Expand Down

0 comments on commit 4d1a4c4

Please sign in to comment.