I hope you're doing great. I have been tinkering with ERC20Votes
and creating a DAO for my Vendor
contract. The issue I'm facing is that whenever I try to delegate my GovernanceToken
contract to the deployer and check the numCheckpoints
function it shows Checkpoint: 0
.
If I'm correct, upon successful delegation to the deployer or any address the checkpoint should be at 1.
Here are my VendorGovernanceToken.sol
contract and my deploy-governance-token.js
script.
- VendorGovernanceToken.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
contract VendorGovernanceToken is ERC20, ERC20Permit, ERC20Votes {
constructor() ERC20("GovernanceToken", "GNT") ERC20Permit("GovernanceToken") {}
// The following functions are overrides required by Solidity.
function _update(address from, address to, uint256 value) internal override(ERC20, ERC20Votes) {
super._update(from, to, value);
}
function nonces(address owner) public view override(ERC20Permit, Nonces) returns (uint256) {
return super.nonces(owner);
}
}
- deploy-governance-token.js
const { network, ethers } = require("hardhat");
const { verify } = require("../utils/verification");
const {networkConfig, developmentChains} = require("../helper-hardhat-config");
module.exports = async function({getNamedAccounts, deployments}) {
const {deploy, log} = deployments;
const {deployer} = await getNamedAccounts();
log("------------------------------------------------------------");
log("Deploying Governance Token...");
const governanceToken = await deploy("VendorGovernanceToken", {
from: deployer,
log: true,
args: [],
waitConfirmations: 1
});
log(`Governance Token deployed at ${governanceToken.address}`);
if(!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying contract please wait...");
await verify(governanceToken, []);
}
log(`Delegating to ${deployer}`);
const vendorGovernanceTokenContract = await ethers.getContractAt("VendorGovernanceToken", governanceToken.address);
const tx = await vendorGovernanceTokenContract.delegate(deployer);
await tx.wait(1);
console.log(`Checkpoints: ${ await vendorGovernanceTokenContract.numCheckpoints(deployer)}`);
log("Successfully Delegated");
log("------------------------------------------------------------");
}
module.exports.tags = ["all", "GTN", "Governance"];
- Terminal Output
------------------------------------------------------------
Deploying Governance Token...
deploying "VendorGovernanceToken" (tx: 0x7e787d1f4ba66d80c124b4b9dd8e9f59d2a18254b2ace53adff58deb76ff7eae)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 3238170 gas
Governance Token deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3
Delegating to 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Checkpoints: 0
Successfully Delegated
------------------------------------------------------------
Any help will be appreciated.