Skip to content

Commit

Permalink
notes
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Jan 15, 2025
1 parent 6fdbcfc commit e64a875
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-upgradeable-v4
Submodule openzeppelin-contracts-upgradeable-v4 added at f6c4c9
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-v4
Submodule openzeppelin-contracts-v4 added at d00ace
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-v5
Submodule openzeppelin-contracts-v5 added at dbb610
7 changes: 6 additions & 1 deletion src/AgoraGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract AgoraGovernor is
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
string memory description // 0|this is the string
) public virtual override returns (uint256) {
uint256 beforeProposalId = hooks.beforePropose(targets, values, calldatas, description);

Expand Down Expand Up @@ -295,7 +295,12 @@ contract AgoraGovernor is
override(Governor, GovernorCountingSimple)
returns (bool)
{

(uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) = proposalVotes(proposalId);

// uint256 defaultQuorum = this.quorum()
// uint256 x = afterQuorum(against, for, abstain, defaultQuorum);
// return x == 0 ? defaultQuorum :
return quorum(proposalSnapshot(proposalId)) <= againstVotes + forVotes + abstainVotes;
}

Expand Down
1 change: 0 additions & 1 deletion src/interfaces/IProposalTypesConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface IProposalTypesConfigurator {
error NotAdminOrTimelock();
error NotAdmin();
error AlreadyInit();
error InvalidGovernor();
error Invalid4ByteSelector();
error InvalidParamNotEqual();
error InvalidParamRange();
Expand Down
44 changes: 19 additions & 25 deletions src/modules/ProposalTypesConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {IProposalTypesConfigurator} from "src/interfaces/IProposalTypesConfigura
import {AgoraGovernor} from "src/AgoraGovernor.sol";
import {IHooks} from "src/interfaces/IHooks.sol";
import {Hooks} from "src/libraries/Hooks.sol";
import {BaseHook} from "src/BaseHook.sol";

contract ProposalTypesConfigurator is IProposalTypesConfigurator {
contract ProposalTypesConfigurator is IProposalTypesConfigurator, BaseHook {
using Hooks for IHooks;
/*//////////////////////////////////////////////////////////////
EVENTS
Expand All @@ -19,8 +20,6 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
IMMUTABLE STORAGE
//////////////////////////////////////////////////////////////*/

AgoraGovernor public governor;

/// @notice Max value of `quorum` and `approvalThreshold` in `ProposalType`
uint16 public constant PERCENT_DIVISOR = 10_000;

Expand All @@ -29,6 +28,7 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
//////////////////////////////////////////////////////////////*/

mapping(uint8 proposalTypeId => ProposalType) internal _proposalTypes;

mapping(uint8 proposalTypeId => mapping(bytes24 key => Scope[])) internal _assignedScopes;
mapping(bytes24 key => bool) internal _scopeExists;

Expand All @@ -41,21 +41,7 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
_;
}

/*//////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice Initialize the contract with the governor and proposal types.
* @param _governor Address of the governor contract.
* @param _proposalTypesInit Array of ProposalType structs to initialize the contract with.
*/
function initialize(address payable _governor, ProposalType[] calldata _proposalTypesInit) public {
if (address(governor) != address(0)) revert AlreadyInit();
if (_governor == address(0)) revert InvalidGovernor();

governor = AgoraGovernor(_governor);

constructor(address payable _governor) BaseHook(_governor) {
for (uint8 i = 0; i < _proposalTypesInit.length; i++) {
_setProposalType(
i,
Expand All @@ -68,18 +54,24 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
}
}

function getHookPermissions() public pure returns (Hooks.Permissions memory) {
/*//////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/

function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
beforeQuorumCalculation: true,
afterQuorumCalculation: false,
beforeVote: true,
afterVote: true,
beforeQuorumCalculation: false,
afterQuorumCalculation: true,
beforeVote: false,
afterVote: false,
beforePropose: true,
afterPropose: false,
afterPropose: true, // set voting threshold
beforeCancel: false,
afterCancel: false,
beforeQueue: false,
afterQueue: false,
beforeExecute: false,
afterExecute: false
});
Expand All @@ -90,12 +82,14 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
//////////////////////////////////////////////////////////////*/

/// @notice The hook called before quorum calculation is performed
function beforeQuorumCalculation(address sender, uint256 timepoint) external view returns (bytes4, uint256) {
function beforeQuorumCalculation(address sender, uint256 timepoint) external override view returns (bytes4, uint256) {
uint256 _beforeQuorum =
(governor.token().getPastTotalSupply(timepoint) * _proposalTypes[0].quorum) / governor.quorumDenominator();
return (IHooks.beforeQuorumCalculation.selector, _beforeQuorum);
}

// remove timepoint (either call the governor or some other hook), just use proposalId

/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
Expand Down

0 comments on commit e64a875

Please sign in to comment.