10000 add Feature with withdrawal amount in validator list by PatrickSky131 · Pull Request #13 · DillLabs/dillscan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add Feature with withdrawal amount in validator list #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ yarn-error.log*
.sentryclirc

logs

*.code-workspace
142 changes: 60 additions & 82 deletions apps/web/src/pages/validators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Validators: NextPage = function () {
<Card key={validator.index}>
<CardContent>
<Grid container spacing={3}>
<Grid item xs={2}>
<Grid item xs={1}>
<Typography
variant="h6"
style={{
Expand All @@ -53,7 +53,7 @@ const Validators: NextPage = function () {
fontWeight: "bold",
}}
>
Public Key
Index
</Typography>
<div
style={{
Expand All @@ -64,17 +64,12 @@ const Validators: NextPage = function () {
>
<Link href={buildValidatorRoute(validator.index)}>
<Typography style={{ lineHeight: "40px" }}>
{validator.validator.pubkey.substring(0, 12)}...
{validator.index}
</Typography>
</Link>
<CopyToClipboard text={validator.validator.pubkey}>
<IconButton style={{ color: "#6541EF" }}>
<FileCopyIcon fontSize="small" />
</IconButton>
</CopyToClipboard>
</div>
</Grid>
<Grid item xs={1}>
<Grid item xs={2}>
<Typography
variant="h6"
style={{
Expand All @@ -85,7 +80,7 @@ const Validators: NextPage = function () {
fontWeight: "bold",
}}
>
Index
Public Key
</Typography>
<div
style={{
Expand All @@ -96,12 +91,17 @@ const Validators: NextPage = function () {
>
<Link href={buildValidatorRoute(validator.index)}>
<Typography style={{ lineHeight: "40px" }}>
{validator.index}
{validator.validator.pubkey.substring(0, 12)}...
</Typography>
</Link>
<CopyToClipboard text={validator.validator.pubkey}>
<IconButton style={{ color: "#6541EF" }}>
<FileCopyIcon fontSize="small" />
</IconButton>
</CopyToClipboard>
</div>
</Grid>
<Grid item xs={3}>
<Grid item xs={2.5}>
<Typography
variant="h6"
style={{
Expand All @@ -122,7 +122,31 @@ const Validators: NextPage = function () {
}}
>
{parseFloat(convertWei(validator.balance)).toFixed(4)} DILL
({convertWei(validator.validator.effective_balance)} DILL)
</Typography>
</Grid>
<Grid item xs={2}>
<Typography
variant="h6"
style={{
lineHeight: "60px",
display: "flex",
justifyContent: "center",
color: "#143226",
fontWeight: "bold",
}}
>
Withdrawal
</Typography>
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
{validator.withdrawal_amount === "----"
? "----"
: (parseFloat(convertWei(validator.withdrawal_amount))).toFixed(4) + " DILL"}
</Typography>
</Grid>
<Grid item xs={1.5}>
Expand Down Expand Up @@ -225,49 +249,14 @@ const Validators: NextPage = function () {
</Typography>
)}
</Grid>
<Grid item xs={1.5}>
<Typography
variant="h6"
style={{
lineHeight: "60px",
display: "flex",
justifyContent: "center",
color: "#143226",
fontWeight: "bold",
}}
>
W/able
</Typography>
{validator.validator.exit_epoch === "18446744073709551615" ? (
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
----
</Typography>
) : (
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
Epoch {validator.validator.withdrawable_epoch}
</Typography>
)}
</Grid>
</Grid>
</CardContent>
</Card>
) : (
<Card key={validator.index}>
<CardContent>
<Grid container spacing={3}>
<Grid item xs={2}>
<Grid item xs={1}>
<div
style={{
display: "flex",
Expand All @@ -277,17 +266,12 @@ const Validators: NextPage = function () {
>
<Link href={buildValidatorRoute(validator.index)}>
<Typography style={{ lineHeight: "40px" }}>
{validator.validator.pubkey.substring(0, 12)}...
{validator.index}
</Typography>
</Link>
<CopyToClipboard text={validator.validator.pubkey}>
<IconButton style={{ color: "#6541EF" }}>
<FileCopyIcon fontSize="small" />
</IconButton>
</CopyToClipboard>
</div>
</Grid>
<Grid item xs={1}>
<Grid item xs={2}>
<div
style={{
display: "flex",
Expand All @@ -297,12 +281,17 @@ const Validators: NextPage = function () {
>
<Link href={buildValidatorRoute(validator.index)}>
<Typography style={{ lineHeight: "40px" }}>
{validator.index}
{validator.validator.pubkey.substring(0, 12)}...
</Typography>
</Link>
<CopyToClipboard text={validator.validator.pubkey}>
<IconButton style={{ color: "#6541EF" }}>
<FileCopyIcon fontSize="small" />
</IconButton>
</CopyToClipboard>
</div>
</Grid>
<Grid item xs={3}>
<Grid item xs={2.5}>
<Typography
style={{
display: "flex",
Expand All @@ -311,7 +300,19 @@ const Validators: NextPage = function () {
}}
>
{parseFloat(convertWei(validator.balance)).toFixed(4)} DILL
({convertWei(validator.validator.effective_balance)} DILL)
</Typography>
</Grid>
<Grid item xs={2}>
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
{validator.withdrawal_amount === "----"
? "----"
: (parseFloat(convertWei(validator.withdrawal_amount))).toFixed(4) + " DILL"}
</Typography>
</Grid>
<Grid item xs={1.5}>
Expand Down Expand Up @@ -378,29 +379,6 @@ const Validators: NextPage = function () {
</Typography>
)}
</Grid>
<Grid item xs={1.5}>
{validator.validator.exit_epoch === "18446744073709551615" ? (
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
----
</Typography>
) : (
<Typography
style={{
display: "flex",
justifyContent: "center",
lineHeight: "40px",
}}
>
Epoch {validator.validator.withdrawable_epoch}
</Typography>
)}
</Grid>
</Grid>
</CardContent>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion kill.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

ps aux | grep -i scan | grep -v grep | awk '{print $2}' | xargs kill -9
ps aux | grep -i scan | grep -v grep | grep -v indexer | grep -v rewards | awk '{print $2}' | xargs kill -9

ps aux | grep -i next-router-wo | grep -v grep | awk '{print $2}' | xargs kill -9
4 changes: 3 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
"@blobscan/zod": "workspace:^0.1.0",
"@trpc/server": "^10.43.2",
"jsonwebtoken": "^9.0.0",
"pg": "^8.13.1",
"superjson": "1.9.1",
"trpc-openapi": "^1.2.0"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.2"
"@types/jsonwebtoken": "^9.0.2",
"@types/pg": "^8.11.11"
},
"eslintConfig": {
"root": true,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
export const env = createEnv({
envOptions: {
server: {
DATABASE_URL: z.string(),
CHAIN_ID: z.coerce.number().positive().default(1),
SECRET_KEY: z.string(),
NODE_ENV: nodeEnvSchema.optional(),
Expand Down
56 changes: 55 additions & 1 deletion packages/api/src/routers/stats/getAllValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import { logger } from "@blobscan/logger"
import { env } from "../../env"
import { BASE_PATH } from "./common";
import { publicProcedure } from "../../procedures";
import { Pool } from "pg";
//cd packages/api
//pnpm add --save-dev @types/pg

const DATABASE_INFO = env.DATABASE_URL;

const parsedUrl = new URL(DATABASE_INFO);

const dbConfig = {
user: parsedUrl.username,
password: parsedUrl.password,
host: parsedUrl.hostname,
port: parseInt(parsedUrl.port),
database: parsedUrl.pathname.slice(1),
};

const pool = new Pool(dbConfig);

export const inputSchema = z.void();

Expand All @@ -22,6 +39,7 @@ export const outputSchema = z.object({
exit_epoch: z.string(),
withdrawable_epoch: z.string(),
}),
withdrawal_amount: z.string(),
}))
});

Expand All @@ -39,6 +57,41 @@ async function getAllValidatorQuery() {
}
}

async function getWithdrawalAmounts(indices: string[]) {
try {
const result = await pool.query(
"SELECT validator_idx, withdrawal_amount FROM validator_withdrawal WHERE validator_idx = ANY($1)",
[indices]
);

return new Map(result.rows.map(row => [row.validator_idx, row.withdrawal_amount]));
} catch (error) {
logger.error("Error fetching withdrawal amounts:", error);
return new Map();
}
}

async function enrichValidators(data: any[]) {
const batchSize = 1000;
let enrichedData: any[] = [];

for (let i = 0; i < data.length; i += batchSize) {
const batch = data.slice(i, i + batchSize);
const validatorIndices = batch.map(v => v.index);

const withdrawalAmounts = await getWithdrawalAmounts(validatorIndices);

const batchResult = batch.map(validator => ({
...validator,
withdrawal_amount: withdrawalAmounts.get(validator.index) || "----"
}));

enrichedData = enrichedData.concat(batchResult);
}

return enrichedData;
}

export const getAllValidators = publicProcedure
.meta({
openapi: {
Expand All @@ -52,5 +105,6 @@ export const getAllValidators = publicProcedure
.output(outputSchema)
.query(async () => {
const data = await getAllValidatorQuery();
return { data:data };
const enrichedData = await enrichValidators(data);
return { data: enrichedData };
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE "validator_income" (
"sync_committee_penalty" BIGINT NOT NULL,
"finality_delay_penalty" BIGINT NOT NULL,
"tx_fee_reward_wei" BIGINT NOT NULL,
"withdrawal_amount" BIGINT NOT NULL,
"inserted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "validator_withdrawal" (
"id" BIGSERIAL NOT NULL,
"validator_idx" BIGINT,
"epoch_idx_gathered" BIGINT,
"withdrawal_amount" BIGINT NOT NULL,
"inserted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "validator_withdrawal_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "uni_validator_withdrawal_validator_idx_key" ON "validator_withdrawal"("validator_idx");
Loading
Loading
0