Skip to content

Week 3 weekend project - Lesson 12 - Tokenized Votes

Notifications You must be signed in to change notification settings

EC-EVM/tokenized-ballot

Repository files navigation

Tokenized Votes

ERC20Votes properties
Snapshots
Creating snapshots when supply changes
Using snapshots
Self delegation
Contract overall operation

Getting Started

Running the Test Script First

-There's a contract MyToken.sol and you can run "npx hardhat compile"
-There's a script TestMyToken.ts and you can "npx hardhat run ./scripts/TestMyToken.ts"

How to initialize a new project

-copy all files/folders from voting-contract except artifacts, cache, node_modules
-create new tokenized-ballot and paste here
-make sure you have the .env file (.gitignore it)
create a scripts folder under the root tokenized-ballot folder & then create a TestMyToken.ts file under scripts directory
-don't forget to npm i @openzeppelin/contracts

==============================================

TODO

Running a script

The easiest way is to run the CheckVoter.ts script below to check if the address has a voting right/weight, the address has already voted, etc:

npx ts-node --files ./scripts/CheckVoter.ts [contractAddress] [address1] 

Sample contract: https://sepolia.etherscan.io/address/0x329590c91563584091f6f4d8909728eb1050efec

Screenshot 2024-08-17 at 5 40 34 PM

You can also run the PrintResults.ts script below to check the result of votes:

npx ts-node --files ./scripts/PrintResults.ts 0x329590c91563584091f6f4d8909728eb1050efec 3 

To deploy a new contract you can run the DeployWithViem.ts script below:

npx ts-node --files ./scripts/DeployWithViem.ts 
npx ts-node --files ./scripts/DeployWithViem.ts ramen pizza burger 

Deploy Token

npx ts-node --files ./scripts/DeployMyToken.ts

Grant Minter Role

npx ts-node --files ./scripts/GrantMinterRole.ts CONTRACT MINTER_ADDRESS

Mint Tokens

npx ts-node --files ./scripts/MintTokens.ts CONTRACT TO_ADDRESS AMOUNT

Transfer Tokens

npx ts-node --files ./scripts/TransferTokens.ts CONTRACT_ADDRESS TO_ADDRESS AMOUNT

Delegate Votes

npx ts-node --files ./scripts/DelegateVotes.ts CONTRACT_ADDRESS DELEGATE_ADDRESS

View Token Status

npx ts-node --files ./scripts/ViewTokenStatus.ts CONTRACT_ADDRESS ACCOUNT_ADDRESS

Deploy Ballot

*Target block determines voting power/delegation

npx ts-node --files ./scripts/DeployTokenizedBallot.ts TOKEN_CONTRACT TARGET_BLOCK_NUMBER PROPOSAL_NAMES

Cast Vote

*Proposal_Index follows values: 0,1,2… *Use Ballot Contract Address

npx ts-node --files ./scripts/CastVote.ts CONTRACT_ADDRESS PROPOSAL_INDEX AMOUNT

View Voting Status

npx ts-node --files ./scripts/ViewVotingStatus.ts CONTRACT_ADDRESS ACCOUNT_ADDRESS

View Results

npx ts-node --files ./scripts/ViewProposalStatus.ts CONTRACT_ADDRESS

Installation

-copy all files/folders from project2 except artifacts, cache, node_modules
-create new project3 and paste here
-make sure you have the .env file (.gitignore it)
create a scripts folder under the root project4 folder & then create a DeployWithHardhat.ts file under scripts directory

Prerequisites

nvm use --lts   
node -v
v20.14.0

Group 2

Unique id Discord username
RAAzLF @GRAVER 👾
2SyBp0 @wackozacco
10exgX @δαλλασκατ
r5YSqY @imchrismayfield
HhHAQw @swooz
Pok9XD @Timster
T5zGzt @Carl Youngblood

Report

Please check into CONTRACT INTERACTION REPORT

Hardhat

npm init
npm install --save-dev hardhat
npx hardhat init

-> Create a typescript project

npx hardhat compile
npx hardhat test
npx hardhat clean


cretae a .mocharc.json with contents:
{
  "require": "hardhat/register",
  "timeout": 40000,
  "_": ["test*/**/*.ts"]
}


rm ./contracts/*
rm ./ignition/*
rm ./test/*
npx hardhat clean
npm i viem
npm install --save-dev @nomicfoundation/hardhat-chai-matchers

References

Screenshot 2024-08-18 at 3 32 13 PM

About

Week 3 weekend project - Lesson 12 - Tokenized Votes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published