Skip to content

Commit

Permalink
f: added skip logic to setup contract and fixed most tests, 2 still f…
Browse files Browse the repository at this point in the history
…ailing
  • Loading branch information
jordaniza committed Jun 11, 2024
1 parent e82b9d3 commit d3d51b8
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 116 deletions.
7 changes: 3 additions & 4 deletions packages/contracts/plugin-settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import buildMetadata from './src/build-metadata.json';
import releaseMetadata from './src/release-metadata.json';
import {GovernanceERC20} from './test/test-utils/typechain-versions';
import {VersionTag} from '@aragon/osx-commons-sdk';
import {ethers} from 'hardhat';

export const PLUGIN_CONTRACT_NAME = 'TokenVoting'; // This must match the filename `packages/contracts/src/MyPlugin.sol` and the contract name `MyPlugin` within.
Expand All @@ -11,9 +10,9 @@ export const PLUGIN_REPO_ENS_SUBDOMAIN_NAME = 'token-voting'; // This will resul
export const GOVERNANCE_ERC20_CONTRACT_NAME = 'GovernanceERC20';
export const GOVERNANCE_WRAPPED_ERC20_CONTRACT_NAME = 'GovernanceWrappedERC20';

export const VERSION: VersionTag = {
release: 1, // Increment this number ONLY if breaking/incompatible changes were made. Updates between releases are NOT possible.
build: 3, // Increment this number if non-breaking/compatible changes were made. Updates to newer builds are possible.
export const VERSION = {
release: 2, // Increment this number ONLY if breaking/incompatible changes were made. Updates between releases are NOT possible.
build: 0, // Increment this number if non-breaking/compatible changes were made. Updates to newer builds are possible.
};

// The metadata associated with the plugin version you are currently working on.
Expand Down
81 changes: 41 additions & 40 deletions packages/contracts/src/TokenVotingSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {ITokenVoting} from "./ITokenVoting.sol";

import {ProxyLib} from "@aragon/osx-commons-contracts/src/utils/deployment/ProxyLib.sol";

import "hardhat/console.sol";

Check warning on line 25 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / checks

global import of path hardhat/console.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 25 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

global import of path hardhat/console.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 25 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

global import of path hardhat/console.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

/// @title TokenVotingSetup
/// @author Aragon X - 2022-2023
/// @notice The setup contract of the `TokenVoting` plugin.
Expand Down Expand Up @@ -96,19 +98,23 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
ITokenVoting.VotingSettings memory votingSettings,
TokenSettings memory tokenSettings,
// only used for GovernanceERC20(token is not passed)
GovernanceERC20.MintSettings memory mintSettings
GovernanceERC20.MintSettings memory mintSettings,
bool bypassTokenValidation
) = abi.decode(
_data,
(ITokenVoting.VotingSettings, TokenSettings, GovernanceERC20.MintSettings)
(ITokenVoting.VotingSettings, TokenSettings, GovernanceERC20.MintSettings, bool)
);

address token = tokenSettings.addr;
bool tokenAddressNotZero = token != address(0);
bool deployedAragonToken = false;

// Prepare helpers.
address[] memory helpers = new address[](1);

if (tokenAddressNotZero) {
if (bypassTokenValidation) {

Check warning on line 115 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / checks

Code contains empty blocks

Check warning on line 115 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Code contains empty blocks

Check warning on line 115 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Code contains empty blocks
// do noting, essentially GOTO setting helpers
} else if (tokenAddressNotZero) {
if (!token.isContract()) {
revert TokenNotContract(token);
}
Expand All @@ -117,18 +123,7 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
revert TokenNotERC20(token);
}

// [0] = IERC20Upgradeable, [1] = IVotesUpgradeable, [2] = IGovernanceWrappedERC20
bool[] memory supportedIds = _getTokenInterfaceIds(token);

if (
// If token supports none of them
// it's simply ERC20 which gets checked by _isERC20
// Currently, not a satisfiable check.
(!supportedIds[0] && !supportedIds[1] && !supportedIds[2]) ||
// If token supports IERC20, but neither
// IVotes nor IGovernanceWrappedERC20, it needs wrapping.
(supportedIds[0] && !supportedIds[1] && !supportedIds[2])
) {
if (missingInterface(token)) {
token = governanceWrappedERC20Base.clone();
// User already has a token. We need to wrap it in
// GovernanceWrappedERC20 in order to make the token
Expand All @@ -138,6 +133,7 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
tokenSettings.name,
tokenSettings.symbol
);
deployedAragonToken = true;
}
} else {
// Clone a `GovernanceERC20`.
Expand All @@ -148,6 +144,7 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
tokenSettings.symbol,
mintSettings
);
deployedAragonToken = true;
}

helpers[0] = token;
Expand Down Expand Up @@ -185,15 +182,15 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
permissionId: EXECUTE_PERMISSION_ID
});

if (!tokenAddressNotZero) {
bytes32 tokenMintPermission = GovernanceERC20(token).MINT_PERMISSION_ID();

// If the token was our Governance ERC20, grant mint permission to the DAO.
// if we didn't deploy an aragon token, we can't guarantee mint permission will exist on the token.
if (deployedAragonToken) {
permissions[2] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: token,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: tokenMintPermission
permissionId: GovernanceERC20(token).MINT_PERMISSION_ID()
});
}

Expand All @@ -202,33 +199,17 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
}

/// @inheritdoc IPluginSetup
/// @dev Revoke the upgrade plugin permission to the DAO for all builds prior the current one (3).
/// @dev This is a new release, so there is nothing to update to.
function prepareUpdate(
address _dao,
uint16 _fromBuild,
SetupPayload calldata _payload
address,
uint16,
SetupPayload calldata
)
external
view
override
returns (bytes memory initData, PreparedSetupData memory preparedSetupData)
{
(initData);
if (_fromBuild < 3) {
PermissionLib.MultiTargetPermission[]
memory permissions = new PermissionLib.MultiTargetPermission[](1);

permissions[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _payload.plugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: tokenVotingBase.UPGRADE_PLUGIN_PERMISSION_ID()
});

preparedSetupData.permissions = permissions;
}
}
{}

Check warning on line 212 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / checks

Code contains empty blocks

Check warning on line 212 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Code contains empty blocks

Check warning on line 212 in packages/contracts/src/TokenVotingSetup.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Code contains empty blocks

/// @inheritdoc IPluginSetup
function prepareUninstallation(
Expand Down Expand Up @@ -281,4 +262,24 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
);
return success && data.length == 0x20;
}

/// @notice Uses ERC-165 checks to see if a passed token appears to support
/// the required interfaces for governance.
/// @dev As an unsatisfactory check, this can be skipped.
/// @param token The address of the governance token passed to 'prepareInstallation'.
function missingInterface(address token) public view returns (bool) {
// [0] = IERC20Upgradeable, [1] = IVotesUpgradeable, [2] = IGovernanceWrappedERC20
bool[] memory supportedIds = _getTokenInterfaceIds(token);

// If token supports none of them
// it's simply ERC20 which gets checked by _isERC20
// Currently, not a satisfiable check.
bool isVanillaERC20 = (!supportedIds[0] && !supportedIds[1] && !supportedIds[2]);

// If token supports IERC20, but neither
// IVotes nor IGovernanceWrappedERC20, it needs wrapping.
bool missingGovernance = (supportedIds[0] && !supportedIds[1] && !supportedIds[2]);

return isVanillaERC20 || missingGovernance;
}
}
8 changes: 7 additions & 1 deletion packages/contracts/src/build-metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ui": {},
"change": "v1.3\n - Removed an unneccessary permission that allowed the Dao to upgrade the plugin, because this is supposed to happens as part of the update itself. The unnecessary permission, which was granted on installation of previous versions, will be automatically removed with the update to this version.\n - Allowed the DAO to still mint new tokens after uninstallation by not revoking the associated permission.",
"change": "v2.0 - Allow for split voting, partial voting and encode proposal data in proposal IDs",
"pluginSetup": {
"prepareInstallation": {
"description": "The information required for the installation.",
Expand Down Expand Up @@ -88,6 +88,12 @@
"name": "mintSettings",
"type": "tuple",
"description": "The token mint settings struct containing the `receivers` and `amounts`."
},
{
"internalType": "bool",
"name": "skipTokenValidation",
"type": "bool",
"description": "If passing a token address, do not run validation checks including for wrapping."
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/release-metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "TokenVoting",
"description": "",
"description": "A plugin that allows Token Holders to create and vote on proposals",
"images": {}
}
Loading

0 comments on commit d3d51b8

Please sign in to comment.