Skip to content

Commit

Permalink
tasks: Add script to checkpoint all delegators
Browse files Browse the repository at this point in the history
This is just to register the contract + task I ran to
checkpoint all delegators on the deployed Delta contracts.

Not intended to merge, just have it registered somewhere
in the repository.
  • Loading branch information
victorges committed Oct 17, 2023
1 parent 6f05e03 commit 0afbfc2
Show file tree
Hide file tree
Showing 4 changed files with 29,625 additions and 0 deletions.
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

0 comments on commit 0afbfc2

Please sign in to comment.