-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tasks: Add script to checkpoint all delegators
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
Showing
4 changed files
with
29,625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
Oops, something went wrong.