Skip to content

Ensure a validator's successful hardfork

tak edited this page Jun 22, 2023 · 2 revisions

Overview

This code displays the slashing status of each validator. It is used to check whether a validator has correctly upgraded their node during a hardfork.

Getting Started

// init project
yarn init

// install dependencies
yarn add [email protected]

// create tsconfig.json
tsc --init

// compile ts to js
tsc printSlashedValidators.ts

// run js
node printSlashedValidators.js

Script

import { ethers } from 'ethers'

const stakemanager = new ethers.Contract(
  '0x0000000000000000000000000000000000001001',
  [
    {
      inputs: [
        {
          internalType: 'uint256',
          name: 'cursor',
          type: 'uint256',
        },
        {
          internalType: 'uint256',
          name: 'howMany',
          type: 'uint256',
        },
      ],
      name: 'getValidatorOwners',
      outputs: [
        {
          internalType: 'address[]',
          name: 'owners',
          type: 'address[]',
        },
        {
          internalType: 'uint256',
          name: 'newCursor',
          type: 'uint256',
        },
      ],
      stateMutability: 'view',
      type: 'function',
    },
    {
      inputs: [
        {
          internalType: 'address',
          name: 'validator',
          type: 'address',
        },
        {
          internalType: 'uint256',
          name: 'epoch',
          type: 'uint256',
        },
      ],
      name: 'getBlockAndSlashes',
      outputs: [
        {
          internalType: 'uint256',
          name: 'blocks',
          type: 'uint256',
        },
        {
          internalType: 'uint256',
          name: 'slashes',
          type: 'uint256',
        },
      ],
      stateMutability: 'view',
      type: 'function',
    },
  ],
  new ethers.providers.JsonRpcProvider('https://rpc.mainnet.oasys.games'),
)

const names: { [address: string]: string } = {
  '0x15f41edfe3556b853d79f96edbae4b68c0217673': 'Oasys',
  '0x025e6bec8c34dbb38120840610004e8968790b7e': 'Astar',
  '0x324d14607bb6853fb0e15a02c80d59045714520f': 'Bandai Namco',
  '0xd47620f7904686e1b61bc2b16ad4ef333623c3a4': 'Bitflyer',
  '0x272d6bd040c2b8454f4f6f43115758fbe318ee2c': 'BOBG',
  '0x6e28e5af24da4cb7bd669332244271edce95f747': 'Com2Us U.S.',
  '0x5f6831bda9d0483054eb50a48966d65d2b156c7b': 'Crypto Games',
  '0x80e358cbb533f6c8d07d2dc5604a55aa925a95df': 'double jump',
  '0x5646b6e8a0856766f0ace6d008f6919ad42df82c': 'GREE',
  '0x3d821c7399ea97da12e55727a378b4f5eb0289f8': 'gumi',
  '0xfcb42091acbef803e333a1b5c7079a43b0cfde59': 'Jump Crypto',
  '0x86652fe437425ac63211c55b6b067b3181bbcb17': 'MCH',
  '0x9b64be0ec5a334968b37bbd687eadbc757da6875': 'Mythical',
  '0x5ed4f15045acfdd0392a7a0706503ae1aa2b82dc': 'Neowiz',
  '0x4e5e774d3837bd9302b83cad94a112575411f07b': 'Netmarble',
  '0x362ee93c00d8bffc1e0284116d7cc9513cde959f': 'NHN PlayArt',
  '0xec21628fd017bbb0c751cb14bcbc6b81eb437241': 'SEGA',
  '0xaf76f079631ca0f3c090a98a2987b8d232c26447': 'Square Enix',
  '0xb441a6a51bf69366d903c072d3b5594ca02ff1e0': 'Thirdverse',
  '0xf5100e233e0a5af82e9c6f3dedf6ca2e45099ef8': 'Ubisoft',
  '0xa505014a84e8bdc4a620470a53ead872b0c1ca5b': 'Wemade',
  '0x3c8075380217eb85d4109226406cacda4c3bdb75': 'YGG',
  '0x18050b80d427b373c96ab24b78996310c0733c13': 'Nexon',
  '0xaaf5a641256131484d00acc565d84683025f2444': 'Softbank',
  '0x4e5963c92bfe4de6f319b0859b2efcf95267e3ae': 'KDDI',
}
const pad = 4 + 42 + Object.values(names).sort((a, b) => b.length - a.length)[0].length

async function main() {
  let owners: string[]
  ;({ owners } = await stakemanager.functions.getValidatorOwners(0, 100))

  const epoch = 0 // is current epoch
  for (let address of owners.map((x: string) => x.toLowerCase())) {
    const { slashes } = await stakemanager.functions.getBlockAndSlashes(address, epoch)
    const label = `${address} (${names[address] || 'unknown'})`
    console.log(`${label.padEnd(pad)}: ${slashes.toNumber()}`)
  }
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })
Clone this wiki locally