Skip to content

Commit

Permalink
Enable testnet for monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruch committed Jun 14, 2024
1 parent ebe60e1 commit cd91e9c
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions packages/rewards-calculator/src/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import express from "express";
import { mainnet } from "viem/chains";
import { createPublicClient, http } from "viem";
import { epochStats } from "./reward";
import { config } from "./config";
import { config, l1Client } from "./config";
import { getBlockNumber } from "./chain";

const app = express();
const port = process.env.PORT ?? 3000;
Expand All @@ -17,14 +16,10 @@ function isInteger(value: string): boolean {
}

const duration = async (_fromBlock: bigint, _toBlock: bigint) => {
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const fromBlock = await publicClient.getBlock({
const fromBlock = await l1Client.getBlock({
blockNumber: _fromBlock,
});
const toBlock = await publicClient.getBlock({
const toBlock = await l1Client.getBlock({
blockNumber: _toBlock,
});
return Number(toBlock.timestamp - fromBlock.timestamp);
Expand Down Expand Up @@ -111,12 +106,8 @@ app.get("/rewards/:fromBlock/:toBlock", async (req, res) => {
});

app.get("/rewards/:lastNBlocks", async (req, res) => {
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const lastBlock = await publicClient.getBlockNumber();
const fromBlock = lastBlock - BigInt(req.params.lastNBlocks);
const lastBlock = await getBlockNumber();
const fromBlock = lastBlock - Number(req.params.lastNBlocks);
await rewards(fromBlock.toString(), lastBlock.toString(), res);
});

Expand Down

2 comments on commit cd91e9c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.