Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating #7

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0647251
On-chainVoting
FurkanSezal Oct 24, 2022
eb9e262
uptaded erc20
FurkanSezal Oct 26, 2022
9c4aed1
Add tests
FurkanSezal Oct 28, 2022
64bd7d7
add tests v1.1
FurkanSezal Oct 28, 2022
c6f35b2
add test v1.1
FurkanSezal Oct 28, 2022
7b0be87
Add tests v1.2
FurkanSezal Oct 28, 2022
15038d9
Add submit
FurkanSezal Oct 31, 2022
6220217
Funding contract
FurkanSezal Nov 4, 2022
db68871
Funding Contract
FurkanSezal Nov 4, 2022
a7a4d7f
Fixed submit_and_propose and testing
FurkanSezal Nov 5, 2022
ea4432c
add more test
FurkanSezal Nov 6, 2022
a658f31
Add more testing before chainlink keepers
FurkanSezal Nov 6, 2022
74473f4
fix test
FurkanSezal Nov 7, 2022
15bd11e
Add chainlink automation without testing.
FurkanSezal Nov 8, 2022
b38e711
Add chainlink automation without testing V2.
FurkanSezal Nov 8, 2022
9aa568a
Add chainlink automation without testing V3.
FurkanSezal Nov 8, 2022
0a4c984
Add chainlink automation without testing V3.
FurkanSezal Nov 8, 2022
eb6206b
Add chainlink automation without testing V4.
FurkanSezal Nov 8, 2022
5ee5a40
Add chainlink automation Fix big bug. Add tests V1
FurkanSezal Nov 10, 2022
b400b6d
Add chainlink automation Fix big bug. Add tests V2
FurkanSezal Nov 10, 2022
1e4c63e
Add chainlink automation Fix big bug. Add tests V3
FurkanSezal Nov 10, 2022
b2981e4
Add chainlink automation Fix big bug. Add tests V4
FurkanSezal Nov 10, 2022
35bdfab
Fix bugs update code v1.
FurkanSezal Nov 13, 2022
82cfbdb
Fix bugs update code v2
FurkanSezal Nov 13, 2022
54c2dcb
deployed mumbai testnet
FurkanSezal Nov 17, 2022
505a2f9
deployed mumbai testnet v2
FurkanSezal Nov 17, 2022
fd54f69
deployed mumbai testnet v2
FurkanSezal Nov 18, 2022
327bbd8
deployed mumbai testnet v3
FurkanSezal Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
On-chainVoting
FurkanSezal committed Oct 24, 2022
commit 0647251d9b919713c27b959f31a4048c25142736
8 changes: 4 additions & 4 deletions deploy/02-deploy-timelock.js
Original file line number Diff line number Diff line change
@@ -7,20 +7,20 @@ module.exports = async ({ getNamedAccounts, deployments }) => {
const { deployer } = await getNamedAccounts();

args = [MIN_DELAY, [], []];
const timelock = await deploy("TimeLock", {
const timeLock = await deploy("TimeLock", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
});
log(`timelock deployed at ${timelock.address}`);
log(`timelock deployed at ${timeLock.address}`);

if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(timelock.address, args);
await verify(timeLock.address, args);
}
};

module.exports.tags = ["all", "governanceToken"];
module.exports.tags = ["all", "timeLock"];
35 changes: 13 additions & 22 deletions deploy/04-setup-governance-contract.js
Original file line number Diff line number Diff line change
@@ -4,37 +4,28 @@ const {
VOTING_PERIOD,
VOTING_DELAY,
QUORUM_PERCENTAGE,
ADDRESS_ZERO,
} = require("../helper-config");
const { verify } = require("../utils/verify");

module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const governanceToken = await ethers.getContract("GovernanceToken", deployer);
const governor = await ethers.getContract("GovernerContract", deployer);
const timelock = await ethers.getContract("TimeLock", deployer);

console.log("Setting up roles...");
args = [
governanceToken.address,
timelock.address,
VOTING_DELAY,
VOTING_PERIOD,
QUORUM_PERCENTAGE,
];
const governorContract = await deploy("GovernerContract", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
});
log(`governorContract deployed at ${governorContract.address}`);

if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(governorContract.address, args);
}
const proposerRole = await timelock.PROPOSER_ROLE();
const executorRole = await timelock.EXECUTOR_ROLE();
const adminRole = await timelock.TIMELOCK_ADMIN_ROLE();

const proposerTx = await timelock.grantRole(proposerRole, governor.address);
await proposerTx.wait(1);
const executorTx = await timelock.grantRole(executorRole, ADDRESS_ZERO);
await executorTx.wait(1);
const revokeTx = await timelock.revokeRole(adminRole, deployer);
await revokeTx.wait(1);
};

module.exports.tags = ["all", "governorContract"];
module.exports.tags = ["all", "setupGovernanceContract"];
32 changes: 32 additions & 0 deletions deploy/05-deploy-box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { getNamedAccounts, deployments, network, ethers } = require("hardhat");
const { developmentChains } = require("../helper-config");
const { verify } = require("../utils/verify");

module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();

args = [];
log("deploying box contract...");
const box = await deploy("Box", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
});
log(`Box deployed at ${box.address}`);

if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(box.address, args);
}
const timeLock = await ethers.getContract("TimeLock");
const boxContract = await ethers.getContractAt("Box", box.address);
const transferOwnerTx = await boxContract.transferOwnership(timeLock.address);
await transferOwnerTx.wait(1);
log("Ownership transfered!");
};

module.exports.tags = ["all", "box"];
1 change: 1 addition & 0 deletions deployments/localhost/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
31337
185 changes: 185 additions & 0 deletions deployments/localhost/Box.json

Large diffs are not rendered by default.

922 changes: 922 additions & 0 deletions deployments/localhost/GovernanceToken.json

Large diffs are not rendered by default.

1,779 changes: 1,779 additions & 0 deletions deployments/localhost/GovernerContract.json

Large diffs are not rendered by default.

1,173 changes: 1,173 additions & 0 deletions deployments/localhost/TimeLock.json

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions deployments/localhost/solcInputs/0a567a41a96dc2d81abbf99faae0732b.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions helper-config.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@ const MIN_DELAY = 3600;
const VOTING_PERIOD = 5;
const VOTING_DELAY = 1;
const QUORUM_PERCENTAGE = 4;
const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
const NEW_VALUE = 77;
const FUNC = "store";
const PROPOSAL_DESCRIPTION = "Propasol #1: Store 77 in the Box!";
const proposalsFile = "./proposals.json";

module.exports = {
developmentChains,
@@ -24,4 +29,9 @@ module.exports = {
VOTING_PERIOD,
VOTING_DELAY,
QUORUM_PERCENTAGE,
ADDRESS_ZERO,
NEW_VALUE,
FUNC,
PROPOSAL_DESCRIPTION,
proposalsFile,
};
1 change: 1 addition & 0 deletions proposals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"31337":["47521742407248176895329046821676979254978125686746004564697692958941862657168"]}
46 changes: 46 additions & 0 deletions scripts/propose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { ethers, network } = require("hardhat");
const {
FUNC,
NEW_VALUE,
PROPOSAL_DESCRIPTION,
developmentChains,
VOTING_DELAY,
proposalsFile,
} = require("../helper-config");
const { moveBlocks } = require("../utils/move-blocks");
const fs = require("fs");

async function propose(args, functionToCall, proposalDescription) {
const governor = await ethers.getContract("GovernerContract");
const box = await ethers.getContract("Box");

const encodedFunctionCall = box.interface.encodeFunctionData(
functionToCall,
args
);
console.log(`Proposing ${functionToCall} on ${box.address} with ${args}`);
console.log(`Proposal description: \n ${proposalDescription}`);

const proposalTx = await governor.propose(
[box.address],
[0],
[encodedFunctionCall],
proposalDescription
);
const proposeReceipt = await proposalTx.wait(1);

if (developmentChains.includes(network.name)) {
await moveBlocks(VOTING_DELAY + 1);
}
const proposalId = proposeReceipt.events[0].args.proposalId;
let proposals = JSON.parse(fs.readFileSync(proposalsFile), "utf8");
proposals[network.config.chainId.toString()].push(proposalId.toString());
fs.writeFileSync(proposalsFile, JSON.stringify(proposals));
}

propose([NEW_VALUE], FUNC, PROPOSAL_DESCRIPTION)
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
57 changes: 57 additions & 0 deletions scripts/queue-and-execute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { ethers, network } = require("hardhat");
const {
FUNC,
NEW_VALUE,
PROPOSAL_DESCRIPTION,
developmentChains,
VOTING_DELAY,
proposalsFile,
MIN_DELAY,
} = require("../helper-config");
const { moveBlocks } = require("../utils/move-blocks");
const { moveTime } = require("../utils/move-time");
const fs = require("fs");

async function queue_and_execute(functionToCall, proposalDescription) {
const args = [NEW_VALUE];

const box = await ethers.getContract("Box");

const encodedFunctionCall = box.interface.encodeFunctionData(FUNC, args);
const descriptionHash = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(PROPOSAL_DESCRIPTION)
);

const governor = await ethers.getContract("GovernerContract");
console.log("Queueing...");
const queueTx = await governor.queue(
[box.address],
[0],
[encodedFunctionCall],
descriptionHash
);
await queueTx.wait(1);

if (developmentChains.includes(network.name)) {
await moveTime(MIN_DELAY + 1);
await moveBlocks(1);
}

console.log("Executing...");
const executeTx = await governor.execute(
[box.address],
[0],
[encodedFunctionCall],
descriptionHash
);
await executeTx.wait(1);
const boxNewValue = await box.retrieve();
console.log(`New Box Value: ${boxNewValue.toString()}`);
}

queue_and_execute([NEW_VALUE], FUNC, PROPOSAL_DESCRIPTION)
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
37 changes: 37 additions & 0 deletions scripts/vote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { ethers, network } = require("hardhat");
const {
proposalsFile,
developmentChains,
VOTING_PERIOD,
} = require("../helper-config");
const { moveBlocks } = require("../utils/move-blocks");
const fs = require("fs");

const index = 0;

async function vote(proposalIndex) {
const proposals = JSON.parse(fs.readFileSync(proposalsFile, "utf8"));
const proposalId = proposals[network.config.chainId][proposalIndex];
// 0 = aganist, 1 = for, 2= abstain
const voteWay = 1;
const governor = await ethers.getContract("GovernerContract");
const reason = "Just I want!";
const voteTxResponse = await governor.castVoteWithReason(
proposalId,
voteWay,
reason
);
await voteTxResponse.wait(1);

if (developmentChains.includes(network.name)) {
await moveBlocks(VOTING_PERIOD + 1);
}
console.log("Voted! Ready to gooo!");
}

vote(index)
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
20 changes: 20 additions & 0 deletions utils/move-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { network } = require("hardhat");

function sleep(timeMs) {
return new Promise((resolve) => setTimeout(resolve, timeMs));
}
async function moveBlocks(amount, sleepAmount = 0) {
console.log("Moving blocks...");
for (let index = 0; index < amount; index++) {
await network.provider.request({
method: "evm_mine",
params: [],
});
if (sleepAmount) {
console.log(`Sleeping for ${sleepAmount}`);
await sleep(sleepAmount);
// you can say await because sleep returns a promise
}
}
}
module.exports = { moveBlocks, sleep };
8 changes: 8 additions & 0 deletions utils/move-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { network } = require("hardhat");

async function moveTime(amount) {
console.log("Moving time...");
await network.provider.send("evm_increaseTime", [amount]);
console.log(`Moved forward ${amount} seconds..`);
}
module.exports = { moveTime };