0

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.

  1. 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);
    }
}

  1. 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"];
  1. 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.

1 Answer 1

0

The contract won't increase the checkpoint if you have 0 tokens. You can test it by minting some tokens to the deployer in the constructor:

    constructor() ERC20("GovernanceToken", "GNT") ERC20Permit("GovernanceToken") {
        _mint(msg.sender, 1000);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.