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

Fix ProposalCreated event dates #369

Merged
merged 128 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
dd7a0dc
feat: protect the DAO executor against reentrancy
heueristik Apr 17, 2023
ad2fd40
fix: remove console.log
heueristik Apr 17, 2023
616b8bf
fix: prevent storage corruption
heueristik Apr 17, 2023
e45854c
feat: refactored reentrancy guard into a modifier
heueristik Apr 18, 2023
2ac2262
feat: added tests and preliminary versioning
heueristik Apr 18, 2023
9fb0473
chore: cleaning
heueristik Apr 19, 2023
a025523
fix: remove empty comment
heueristik Apr 19, 2023
3fcc083
fix: refactor findEventTopicLog function
heueristik Apr 19, 2023
02711cc
fix: moved implementation slot and renamed file
heueristik Apr 19, 2023
360079c
fix: remove redundant includes
heueristik Apr 19, 2023
1b14d42
prepare package
Rekard0 Apr 25, 2023
9d73698
remember the branch
Rekard0 Apr 25, 2023
fe9fe0f
only artifact src
Rekard0 Apr 25, 2023
c8f10de
correct the paths
Rekard0 Apr 25, 2023
c878bf4
correct root path
Rekard0 Apr 25, 2023
f319e0c
update hashes
Rekard0 Apr 25, 2023
3575258
add logs
Rekard0 Apr 25, 2023
1c6b6f8
only copy typechain
Rekard0 Apr 25, 2023
9f961cc
generate typechain
Rekard0 Apr 25, 2023
e8d6590
setup rollup
Rekard0 Apr 25, 2023
930b436
update npm packages
Rekard0 Apr 25, 2023
049ecc6
Merge branch 'develop' into feature/OS-358-nonreentrant-executor
heueristik Apr 25, 2023
5db940f
update rollup index
Rekard0 Apr 26, 2023
4dc131e
add esm cjs
Rekard0 Apr 26, 2023
6005f06
add readme
Rekard0 Apr 26, 2023
748b382
remove gitIgnore
Rekard0 Apr 26, 2023
f78ad2c
Merge branch 'f/OS-380_npm_package_versions' into feature/OS-358-nonr…
heueristik Apr 27, 2023
f9858c7
update typechain
Rekard0 Apr 27, 2023
1653ca1
update typescript
Rekard0 Apr 27, 2023
03ad311
convert script to typescript
Rekard0 Apr 27, 2023
5dd35fe
change commit hash json
Rekard0 Apr 27, 2023
252b165
rename types to typechain
Rekard0 Apr 28, 2023
ab50a5e
add test
Rekard0 Apr 28, 2023
0ad3a4f
add json to rollup and export types
Rekard0 Apr 28, 2023
b9230a7
update usage test
Rekard0 Apr 28, 2023
30c9593
generate index.ts dynamically
Rekard0 Apr 28, 2023
50e094c
update readme
Rekard0 Apr 28, 2023
744f4f7
add empty line
Rekard0 Apr 28, 2023
1832124
Merge remote-tracking branch 'origin/f/OS-380_npm_package_versions' i…
heueristik Apr 28, 2023
ece3a1f
update commit hashes
heueristik Apr 28, 2023
62f5bdb
fix index.ts
Rekard0 Apr 28, 2023
559d154
chore: update test
heueristik Apr 28, 2023
d2e5456
Merge remote-tracking branch 'origin/f/OS-380_npm_package_versions' i…
heueristik Apr 28, 2023
cd35fe0
fix: removed redundant imports
heueristik Apr 28, 2023
57f755c
chore: remove legacy version files of DAO
heueristik Apr 28, 2023
8fb39df
fix: adapt contracts-version tests
heueristik Apr 28, 2023
c409409
fix: remove version in title as contracts will get a constant
heueristik Apr 28, 2023
403436c
fix: compile legacy contracts for regression testing
heueristik Apr 28, 2023
1043deb
Revert "fix: compile legacy contracts for regression testing "
heueristik Apr 28, 2023
757bc4c
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 2, 2023
1b224a2
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 2, 2023
c900797
revert versioning changes
heueristik May 2, 2023
9629728
adapt tests
heueristik May 2, 2023
6261b85
test with creating symbolic link
Rekard0 May 2, 2023
b2df3f0
correct path
Rekard0 May 2, 2023
57ecd70
feat: added tests for proposal start and end date handling
heueristik May 3, 2023
ca52351
fix: corrected wrong validation order
heueristik May 3, 2023
abfa6af
Revert "chore: remove legacy version files of DAO"
heueristik Apr 28, 2023
3e25be2
add legacy versions
heueristik May 5, 2023
aaff5bd
fix: renaming of the versions
heueristik May 5, 2023
1ce07f3
chore: remove old CI task
heueristik May 5, 2023
96d35af
chore: maintained changelog
heueristik May 5, 2023
857a9db
fix: version numbers
heueristik May 5, 2023
9d129f4
fix: imports
heueristik May 5, 2023
b9d3dc3
WIP
heueristik May 5, 2023
f437dbc
doc: clarified the origin of the implementation slot
heueristik May 8, 2023
168b55b
fix: versioning
heueristik May 8, 2023
dbe2134
fix: move files
heueristik May 8, 2023
5e209e3
Apply suggestions from code review
heueristik May 8, 2023
6cbc32e
chore: formatting
heueristik May 8, 2023
1b86fd0
chore: remove NatSpec version number from osx files
heueristik May 8, 2023
9b6a514
feat: added more tests
heueristik May 8, 2023
ebc96ac
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 8, 2023
f997500
Merge remote-tracking branch 'origin/develop' into feature/OS-409-pro…
heueristik May 8, 2023
c9c04f8
Applied review suggestion
heueristik May 10, 2023
706de67
feat: added test checking that execution is still possible after the …
heueristik May 10, 2023
9c80df2
Improved comments
heueristik May 10, 2023
0cabf6b
feat: initialize _rentrancyStatus
heueristik May 10, 2023
9599e38
doc: clarify comments
heueristik May 10, 2023
0dee336
fix: change version number
heueristik May 10, 2023
4e9e628
fix: use upgradeToAndCall and correct versions
heueristik May 10, 2023
6c814d2
feat: added initializeUpgradeFrom function and tests
heueristik May 10, 2023
f8ca50c
feat: improved function and added more tests
heueristik May 10, 2023
4ea9840
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 11, 2023
f8876fd
WIP
heueristik May 11, 2023
4c2573e
fix: tests
heueristik May 11, 2023
ad8fc66
fix: finalize tests
heueristik May 11, 2023
ca9a176
fix typechain and add a script
Rekard0 May 11, 2023
f689e6c
fix: typo
heueristik May 11, 2023
9303b42
feat: improve initializeUpgradeFrom
heueristik May 12, 2023
cf3b2c1
feat: added _initData parameter
heueristik May 12, 2023
9cd9e65
feat: added test
heueristik May 12, 2023
452c958
fix: wrong version number
heueristik May 12, 2023
c865dcb
WIP
Rekard0 May 12, 2023
758bceb
fix remaining tests
Rekard0 May 12, 2023
fec63aa
fix subgraph
Rekard0 May 12, 2023
559a756
add ref depth
Rekard0 May 12, 2023
df4a9e3
fix: replacing getContractFactory and getContractAt by typechain fact…
heueristik May 12, 2023
c1088ef
fix: test timings
heueristik May 12, 2023
728cb80
Merge branch 'fix/fix-typechain-and-contracts-tests' into feature/OS-…
heueristik May 12, 2023
099018a
fix: re-introduced yarn postinstall
heueristik May 12, 2023
1a15563
fix: remove redundant includes
heueristik May 12, 2023
ba71d52
fix: adapt upgrade tests
heueristik May 12, 2023
51c831c
feat: optimize if statements
heueristik May 12, 2023
1ab55d6
fix: tests
heueristik May 12, 2023
58a9250
feat: rename initializeUpgradeFrom to initializeFrom
heueristik May 12, 2023
b71193f
fix: correct test description
heueristik May 15, 2023
054bca1
fix: removed duplicate file
heueristik May 15, 2023
4372af1
Merge remote-tracking branch 'origin/develop' into feature/OS-409-pro…
heueristik May 15, 2023
8566eec
fix: typo
heueristik May 15, 2023
0604694
fix: delete legacy files
heueristik May 15, 2023
8b51d4b
revert: metadata changes as they will happen in #375
heueristik May 15, 2023
263bc1b
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 16, 2023
0e1128a
fix: merge conflicts
heueristik May 16, 2023
3c64f8e
fix: re-order changelog entries
heueristik May 16, 2023
d08e1ee
fix: remove wrong/redundant import originating from merge
heueristik May 16, 2023
cc571dc
feat: improve upgrade version checks
heueristik May 16, 2023
649732b
fix: remove redundant ROOT_PERMISSION grant call
heueristik May 16, 2023
c275b62
feat: added more checks to the upgrade tests
heueristik May 16, 2023
a97a9ba
feat: more explicit variable naming
heueristik May 16, 2023
a84625b
Merge remote-tracking branch 'origin/develop' into feature/OS-409-pro…
heueristik May 16, 2023
7c3e22c
fix: reworked initializeFrom logic
heueristik May 16, 2023
717d30e
Merge branch 'develop' into feature/OS-409-proposal-created-event-dates
heueristik May 17, 2023
ea3be72
Merge branch 'feature/OS-358-nonreentrant-executor' into feature/OS-4…
heueristik May 17, 2023
3eeb2fe
Merge branch 'develop' into feature/OS-409-proposal-created-event-dates
heueristik May 17, 2023
8317c61
feat: improved changelog entry
heueristik May 17, 2023
ffc5800
feat: improved comment
heueristik May 17, 2023
5dd7b55
chore: remove deploy scripts to be handled in a separate task
heueristik May 19, 2023
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
1 change: 1 addition & 0 deletions packages/contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed logic bug in the `TokenVoting` and `AddresslistVoting` implementations that caused the `createProposal` function to emit the unvalidated `_startDate` and `_endDate` input arguments (that both can be zero) in the `ProposalCreated` event instead of the validated ones.
- Changed the `createProposal` functions in `Multisig` to allow creating proposals when the `_msgSender()` is listed in the current block.
- Changed the `createProposal` functions in `AddresslistVoting` to allow creating proposals when the `_msgSender()` is listed in the current block.
- Changed the `createProposal` functions in `TokenVoting` to allow creating proposals when the `_msgSender()` owns more tokens at least `minProposerVotingPower()` tokens in the current block.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {PluginRepo__factory} from '../../../typechain';
import {getContractAddress, uploadToIPFS} from '../../helpers';

import tokenVotingReleaseMetadata from '../../../src/plugins/governance/majority-voting/token/release-metadata.json';
import tokenVotingBuildMetadata from '../../../src/plugins/governance/majority-voting/token/build-metadata.json';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpdate TokenVoting Plugin');
const {deployments, ethers, network} = hre;
const {deploy} = deployments;
const [deployer] = await ethers.getSigners();

const deployResult = await deploy('TokenVotingSetup', {
heueristik marked this conversation as resolved.
Show resolved Hide resolved
from: deployer.address,
args: [],
log: true,
});

const tokenVotingReleaseCIDPath = await uploadToIPFS(
JSON.stringify(tokenVotingReleaseMetadata),
network.name
);
const tokenVotingBuildCIDPath = await uploadToIPFS(
JSON.stringify(tokenVotingBuildMetadata),
network.name
);

const tokenVotingRepoAddress = await getContractAddress(
'token-voting-repo',
hre
);
const tokenVotingRepo = PluginRepo__factory.connect(
tokenVotingRepoAddress,
ethers.provider
);
if (
await tokenVotingRepo.callStatic.isGranted(
tokenVotingRepoAddress,
deployer.address,
await tokenVotingRepo.MAINTAINER_PERMISSION_ID(),
'0x00'
)
) {
console.log(`Deployer has permission to install new TokenVoting version`);
const tx = await tokenVotingRepo
.connect(deployer)
.createVersion(
1,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingReleaseCIDPath}`)
);
console.log(`Creating new TokenVoting build version with ${tx.hash}`);
await tx.wait();
return;
}

const tx = await tokenVotingRepo
.connect(deployer)
.populateTransaction.createVersion(
1,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingReleaseCIDPath}`)
);

if (!tx.to || !tx.data) {
throw new Error(
`Failed to populate TokenVoting Repo createVersion transaction`
);
}

console.log(
`Deployer has no permission to create a new version. Adding managingDAO action`
);
hre.managingDAOActions.push({
to: tx.to,
data: tx.data,
value: 0,
description: `Creates a new build for release 1 in the TokenVotingRepo (${tokenVotingRepoAddress}) with TokenVotingSetup (${deployResult.address})`,
});
};
export default func;
func.tags = ['TokenVotingPlugin'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nConcluding TokenVoting Plugin Update');

hre.aragonToVerifyContracts.push(
await hre.deployments.get('TokenVotingSetup')
heueristik marked this conversation as resolved.
Show resolved Hide resolved
);
};
export default func;
func.tags = ['TokenVotingPlugin', 'Verify'];
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ contract AddresslistVoting is IMembership, Addresslist, MajorityVotingBase {
snapshotBlock = block.number.toUint64() - 1; // The snapshot block must be mined already to protect the transaction against backrunning transactions causing census changes.
}

(_startDate, _endDate) = _validateProposalDates(_startDate, _endDate);

proposalId = _createProposal({
_creator: _msgSender(),
_metadata: _metadata,
Expand All @@ -110,10 +112,8 @@ contract AddresslistVoting is IMembership, Addresslist, MajorityVotingBase {
// Store proposal related information
Proposal storage proposal_ = proposals[proposalId];

(proposal_.parameters.startDate, proposal_.parameters.endDate) = _validateProposalDates({
_start: _startDate,
_end: _endDate
});
proposal_.parameters.startDate = _startDate;
proposal_.parameters.endDate = _endDate;
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ contract TokenVoting is IMembership, MajorityVotingBase {
revert NoVotingPower();
}

(_startDate, _endDate) = _validateProposalDates(_startDate, _endDate);

proposalId = _createProposal({
_creator: _msgSender(),
_metadata: _metadata,
Expand All @@ -117,10 +119,8 @@ contract TokenVoting is IMembership, MajorityVotingBase {
// Store proposal related information
Proposal storage proposal_ = proposals[proposalId];

(proposal_.parameters.startDate, proposal_.parameters.endDate) = _validateProposalDates(
_startDate,
_endDate
);
proposal_.parameters.startDate = _startDate;
proposal_.parameters.endDate = _endDate;
proposal_.parameters.snapshotBlock = snapshotBlock.toUint64();
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
Expand Down Expand Up @@ -148,7 +148,7 @@ contract TokenVoting is IMembership, MajorityVotingBase {

/// @inheritdoc IMembership
function isMember(address _account) external view returns (bool) {
// A member must own or least one token or have at least one token delegated to her/him.
// A member must own at least one token or have at least one token delegated to her/him.
return
votingToken.getVotes(_account) > 0 ||
IERC20Upgradeable(address(votingToken)).balanceOf(_account) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,52 @@ describe('AddresslistVoting', function () {
.withArgs(earliestEndDate, tooEarlyEndDate);
});

it('sets the startDate to now and endDate to startDate + minDuration, if 0 is provided as an input', async () => {
await voting.initialize(dao.address, votingSettings, [
signers[0].address,
]);

// Create a proposal with zero as an input for `_startDate` and `_endDate`
const startDate = 0; // now
const endDate = 0; // startDate + minDuration

const creationTx = await voting.createProposal(
dummyMetadata,
[],
0,
startDate,
endDate,
VoteOption.None,
false
);

const currentTime = (
await ethers.provider.getBlock((await creationTx.wait()).blockNumber)
).timestamp;

const expectedStartDate = currentTime;
const expectedEndDate = expectedStartDate + votingSettings.minDuration;

// Check the state
const proposal = await voting.getProposal(id);
expect(proposal.parameters.startDate).to.eq(expectedStartDate);
expect(proposal.parameters.endDate).to.eq(expectedEndDate);

// Check the event
const event = await findEvent<ProposalCreatedEvent>(
creationTx,
'ProposalCreated'
);

expect(event.args.proposalId).to.equal(id);
expect(event.args.creator).to.equal(signers[0].address);
expect(event.args.startDate).to.equal(expectedStartDate);
expect(event.args.endDate).to.equal(expectedEndDate);
expect(event.args.metadata).to.equal(dummyMetadata);
expect(event.args.actions).to.deep.equal([]);
expect(event.args.allowFailureMap).to.equal(0);
});

it('ceils the `minVotingPower` value if it has a remainder', async () => {
votingSettings.minParticipation = pctToRatio(30).add(1); // 30.0001 %

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,54 @@ describe('TokenVoting', function () {
.withArgs(earliestEndDate, tooEarlyEndDate);
});

it('sets the startDate to now and endDate to startDate + minDuration, if 0 is provided as an input', async () => {
await voting.initialize(
dao.address,
votingSettings,
governanceErc20Mock.address
);

// Create a proposal with zero as an input for `_startDate` and `_endDate`
const startDate = 0; // now
const endDate = 0; // startDate + minDuration

const creationTx = await voting.createProposal(
dummyMetadata,
[],
0,
startDate,
endDate,
VoteOption.None,
false
);

const currentTime = (
await ethers.provider.getBlock((await creationTx.wait()).blockNumber)
).timestamp;

const expectedStartDate = currentTime;
const expectedEndDate = expectedStartDate + votingSettings.minDuration;

// Check the state
const proposal = await voting.getProposal(id);
expect(proposal.parameters.startDate).to.eq(expectedStartDate);
expect(proposal.parameters.endDate).to.eq(expectedEndDate);

// Check the event
const event = await findEvent<ProposalCreatedEvent>(
creationTx,
'ProposalCreated'
);

expect(event.args.proposalId).to.equal(id);
expect(event.args.creator).to.equal(signers[0].address);
expect(event.args.startDate).to.equal(expectedStartDate);
expect(event.args.endDate).to.equal(expectedEndDate);
expect(event.args.metadata).to.equal(dummyMetadata);
expect(event.args.actions).to.deep.equal([]);
expect(event.args.allowFailureMap).to.equal(0);
});

it('ceils the `minVotingPower` value if it has a remainder', async () => {
votingSettings.minParticipation = pctToRatio(30).add(1); // 30.0001 %

Expand Down