Skip to content
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

tasks: Add script to checkpoint all delegators #635

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 17 additions & 0 deletions contracts/bonding/Checkpointer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

interface IBondingManager {
function checkpointBondingState(address _account) external;
}

/// @custom:security-contact [email protected]
contract Checkpointer {
IBondingManager public constant BONDING_MANAGER = IBondingManager(0x35Bcf3c30594191d53231E4FF333E8A770453e40); // mainnet

function checkpointMany(address[] calldata addresses) public {
for (uint256 i = 0; i < addresses.length; i++) {
BONDING_MANAGER.checkpointBondingState(addresses[i]);
}
}
}
75 changes: 75 additions & 0 deletions tasks/checkpoint-all-delegators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {task} from "hardhat/config"
import {delegators} from "./delegators"
import {BondingVotes, Checkpointer} from "../typechain"
import {Address} from "hardhat-deploy/types"
import {readFileSync, writeFileSync} from "fs"

task(
"checkpoint-all-delegators",
"Verifies all contracts in the deployments folder"
)
.addOptionalParam(
"skipListFile",
"Skip-list files of already processed delegators",
"./tasks/delegators-skip.json"
)
.setAction(async (taskArgs, hre) => {
const {skipListFile} = taskArgs
const Checkpointer: Checkpointer = await hre.ethers.getContractAt(
"Checkpointer",
"0xFb260b0957DDe757b6AEc16b62Abf6842C1Ff8fB"
)
const BondingVotes: BondingVotes = await hre.ethers.getContractAt(
"BondingVotes",
"0x0B9C254837E72Ebe9Fe04960C43B69782E68169A"
)

const allDelegators = delegators.reduce<Address[]>((acc, q) => {
return acc.concat(q.data.delegators.map(d => d.id))
}, [])

const skip: string[] = JSON.parse(readFileSync(skipListFile, "utf8"))
const addToSkipList = (...delegators: Address[]) => {
skip.push(...delegators)
writeFileSync(skipListFile, JSON.stringify(skip, null, 2))
}

let batch = [] as Address[]
const checkpointBatch = async () => {
console.log(`Checkpointing ${batch.length} delegators`)

await Checkpointer.checkpointMany(batch, {
gasPrice: 100000000
}).then(tx => {
console.log(`tx: ${tx.hash}`)
return tx.wait()
})

addToSkipList(...batch)
batch = []
}

for (const delegator of allDelegators) {
if (skip.includes(delegator)) {
continue
}

const hasCheckpoint = await BondingVotes.hasCheckpoint(delegator)
if (hasCheckpoint) {
console.log(`Skipping checkpointed ${delegator}`)
addToSkipList(delegator)
continue
}

batch.push(delegator)
if (batch.length % 10 === 0) {
console.log(`Batch size: ${batch.length}`)
}
if (batch.length === 100) {
await checkpointBatch()
}
}
if (batch.length > 0) {
await checkpointBatch()
}
})
1 change: 1 addition & 0 deletions tasks/delegators-skip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading
Loading