Skip to content

Commit 872cd53

Browse files
committed
More helper functions for setting and viewing scopes/limits
1 parent bb3fef7 commit 872cd53

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/ProposalTypesConfigurator.sol

+35-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
2323
mapping(uint8 proposalTypeId => bool) internal _proposalTypesExists;
2424
mapping(uint8 proposalTypeId => Scope[]) public scopes;
2525
mapping(uint8 proposalTypeId => mapping(bytes32 typeHash => bool)) public scopeExists;
26-
mapping(bytes32 typeHash => bytes32 limits) public limits;
2726

2827
/*//////////////////////////////////////////////////////////////
2928
MODIFIERS
@@ -137,4 +136,39 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {
137136

138137
emit ProposalTypeSet(proposalTypeId, quorum, approvalThreshold, name, txTypeHashes);
139138
}
139+
140+
/**
141+
* @notice Adds an additional scope for a given proposal type.
142+
* @param proposalTypeId Id of the proposal type
143+
* @param scope An object that contains the scope for a transaction type hash
144+
*/
145+
function updateScopeForProposalType(uint8 proposalTypeId, Scope calldata scope) external override onlyAdmin {
146+
_updateScopeForProposalType(proposalTypeId, scope);
147+
}
148+
149+
function _updateScopeForProposalType(uint8 proposalTypeId, Scope calldata scope) internal {
150+
if (_proposalTypesExists[proposalTypeId]) revert InvalidProposalType();
151+
scopes[proposalTypeId].push(scope);
152+
153+
require(scopeExists[proposalTypeId][scope.txTypeHash]); // Do not allow multiple scopes for a single transaction type
154+
scopeExists[proposalTypeId][scope.txTypeHash] = true;
155+
}
156+
157+
/**
158+
* @notice Retrives the encoded limit of a transaction type signature for a given proposal type.
159+
* @param proposalTypeId Id of the proposal type
160+
* @param txTypeHash A type signature of a function that has a limit specified in a scope
161+
*/
162+
function getLimit(uint8 proposalTypeId, bytes32 txTypeHash) public view returns (bytes32) {
163+
if (_proposalTypesExists[proposalTypeId]) revert InvalidProposalType();
164+
165+
require(scopeExists[proposalTypeId][txTypeHash]);
166+
Scope[] memory validScopes = scopes[proposalTypeId];
167+
168+
for (uint8 i = 0; i < validScopes.length; i++) {
169+
if (validScopes[i].txTypeHash == txTypeHash) {
170+
return validScopes[i].encodedLimits;
171+
}
172+
}
173+
}
140174
}

src/interfaces/IProposalTypesConfigurator.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ interface IProposalTypesConfigurator {
7070
bytes[] memory parameters,
7171
Comparators[] memory comparators
7272
) external;
73-
// function updateScopeForProposalType(uint proposalTypeId, Scope scope) external;
74-
// function getLimit(uint8 proposalTypeId, bytes32 typeHash) public view;
75-
// function setLimit(uint8 proposalTypeId, bytes32 typeHash, bytes32 scope) external;
73+
74+
function updateScopeForProposalType(uint8 proposalTypeId, Scope calldata scope) external;
75+
function getLimit(uint8 proposalTypeId, bytes32 txTypeHash) external returns (bytes32);
7676
}

0 commit comments

Comments
 (0)