mirror of
https://github.com/status-im/community-dapp.git
synced 2025-02-23 03:28:21 +00:00
feat(VotingContract): make voting length configurable
This commit is contained in:
parent
910c0a41d6
commit
f7579494bd
@ -13,9 +13,6 @@ contract VotingContract {
|
|||||||
using ECDSA for bytes32;
|
using ECDSA for bytes32;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
|
||||||
uint256 private constant VOTING_LENGTH = 1000;
|
|
||||||
uint256 private constant TIME_BETWEEN_VOTING = 3600;
|
|
||||||
|
|
||||||
enum VoteType {
|
enum VoteType {
|
||||||
REMOVE,
|
REMOVE,
|
||||||
ADD
|
ADD
|
||||||
@ -57,6 +54,9 @@ contract VotingContract {
|
|||||||
Directory public directory;
|
Directory public directory;
|
||||||
IERC20 public token;
|
IERC20 public token;
|
||||||
|
|
||||||
|
uint256 public votingLength;
|
||||||
|
uint256 public timeBetweenVoting;
|
||||||
|
|
||||||
VotingRoom[] public votingRooms;
|
VotingRoom[] public votingRooms;
|
||||||
mapping(bytes => uint256) public activeRoomIDByCommunityID;
|
mapping(bytes => uint256) public activeRoomIDByCommunityID;
|
||||||
mapping(bytes => uint256[]) private roomIDsByCommunityID;
|
mapping(bytes => uint256[]) private roomIDsByCommunityID;
|
||||||
@ -100,9 +100,11 @@ contract VotingContract {
|
|||||||
return digest.recover(vote.r, vote.vs) == vote.voter;
|
return digest.recover(vote.r, vote.vs) == vote.voter;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(IERC20 _address) {
|
constructor(IERC20 _address, uint256 _votingLength, uint256 _timeBetweenVoting) {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
token = _address;
|
token = _address;
|
||||||
|
votingLength = _votingLength;
|
||||||
|
timeBetweenVoting = _timeBetweenVoting;
|
||||||
DOMAIN_SEPARATOR = hash(
|
DOMAIN_SEPARATOR = hash(
|
||||||
EIP712Domain({
|
EIP712Domain({
|
||||||
name: 'Voting Contract',
|
name: 'Voting Contract',
|
||||||
@ -180,7 +182,7 @@ contract VotingContract {
|
|||||||
if (historyLength > 0) {
|
if (historyLength > 0) {
|
||||||
uint256 roomId = roomIDsByCommunityID[publicKey][historyLength - 1];
|
uint256 roomId = roomIDsByCommunityID[publicKey][historyLength - 1];
|
||||||
require(
|
require(
|
||||||
block.timestamp.sub(_getVotingRoom(roomId).endAt) > TIME_BETWEEN_VOTING,
|
block.timestamp.sub(_getVotingRoom(roomId).endAt) > timeBetweenVoting,
|
||||||
'Community was in a vote recently'
|
'Community was in a vote recently'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -196,7 +198,7 @@ contract VotingContract {
|
|||||||
votingRooms.push(
|
votingRooms.push(
|
||||||
VotingRoom({
|
VotingRoom({
|
||||||
startBlock: block.number,
|
startBlock: block.number,
|
||||||
endAt: block.timestamp.add(VOTING_LENGTH),
|
endAt: block.timestamp.add(votingLength),
|
||||||
voteType: voteType,
|
voteType: voteType,
|
||||||
finalized: false,
|
finalized: false,
|
||||||
community: publicKey,
|
community: publicKey,
|
||||||
|
@ -9,9 +9,9 @@ const hre = require("hardhat");
|
|||||||
import { ERC20Mock, MultiCall } from '../abi';
|
import { ERC20Mock, MultiCall } from '../abi';
|
||||||
import { BigNumber } from 'ethers';
|
import { BigNumber } from 'ethers';
|
||||||
|
|
||||||
async function deployVotingContract(tokenAddress: string) {
|
async function deployVotingContract(tokenAddress: string, votingLength, timeBetweenVoting) {
|
||||||
const contractFactory = await hre.ethers.getContractFactory('VotingContract');
|
const contractFactory = await hre.ethers.getContractFactory('VotingContract');
|
||||||
const contract = await contractFactory.deploy(tokenAddress);
|
const contract = await contractFactory.deploy(tokenAddress, votingLength, timeBetweenVoting);
|
||||||
await contract.deployed();
|
await contract.deployed();
|
||||||
|
|
||||||
console.log(`Voting contract deployed with address: ${contract.address}`);
|
console.log(`Voting contract deployed with address: ${contract.address}`);
|
||||||
@ -67,6 +67,8 @@ async function obtainTokenAddress(deployer, chainId): Promise<string> {
|
|||||||
async function main() {
|
async function main() {
|
||||||
const [deployer] = await hre.ethers.getSigners();
|
const [deployer] = await hre.ethers.getSigners();
|
||||||
const network = await hre.ethers.provider.getNetwork();
|
const network = await hre.ethers.provider.getNetwork();
|
||||||
|
const votingLengthInSeconds = isTestNetwork(network.chainId) ? 2 * 60 : 30 * 24 * 3600 // 2 minutes or 30 days
|
||||||
|
const timeBetweenVotingInSeconds = isTestNetwork(network.chainId) ? 60 : 7 * 24 * 3600 // 1 minute or 7 days
|
||||||
|
|
||||||
console.log(`Deploying contracts on the network: ${network.name}(${network.chainId}), with the account: ${deployer.address}`);
|
console.log(`Deploying contracts on the network: ${network.name}(${network.chainId}), with the account: ${deployer.address}`);
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tokenAddress = await obtainTokenAddress(deployer, network.chainId);
|
const tokenAddress = await obtainTokenAddress(deployer, network.chainId);
|
||||||
const votingContract = await deployVotingContract(tokenAddress);
|
const votingContract = await deployVotingContract(tokenAddress, votingLengthInSeconds, timeBetweenVotingInSeconds);
|
||||||
const directoryContract = await deployDirectoryContract(votingContract.address);
|
const directoryContract = await deployDirectoryContract(votingContract.address);
|
||||||
await votingContract.setDirectory(directoryContract.address)
|
await votingContract.setDirectory(directoryContract.address)
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ async function fixture() {
|
|||||||
await erc20Contract.transfer(thirdSigner.address, 10000)
|
await erc20Contract.transfer(thirdSigner.address, 10000)
|
||||||
|
|
||||||
const votingContractFactory = await ethers.getContractFactory('VotingContract')
|
const votingContractFactory = await ethers.getContractFactory('VotingContract')
|
||||||
const votingContract = await votingContractFactory.deploy(erc20Contract.address)
|
const votingContract = await votingContractFactory.deploy(erc20Contract.address, 1000, 3600)
|
||||||
|
|
||||||
const directoryContractFactory = await ethers.getContractFactory('Directory')
|
const directoryContractFactory = await ethers.getContractFactory('Directory')
|
||||||
const directoryContract = await directoryContractFactory.deploy(votingContract.address)
|
const directoryContract = await directoryContractFactory.deploy(votingContract.address)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user