This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
LlamaAbsoluteQuorum.sol
57 lines (47 loc) · 2.42 KB
/
LlamaAbsoluteQuorum.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {ILlamaStrategy} from "src/interfaces/ILlamaStrategy.sol";
import {LlamaAbsoluteStrategyBase} from "src/strategies/absolute/LlamaAbsoluteStrategyBase.sol";
import {ActionInfo} from "src/lib/Structs.sol";
import {LlamaPolicy} from "src/LlamaPolicy.sol";
/// @title Llama Absolute Quorum Strategy
/// @author Llama (devsdosomething@llama.xyz)
/// @notice This is a Llama strategy which has the following properties:
/// - Approval/disapproval thresholds are specified as absolute numbers.
/// - Action creators are allowed to cast approvals or disapprovals on their own actions within this strategy.
/// - Role quantity is used to determine the approval and disapproval weight of a policyholder's cast.
contract LlamaAbsoluteQuorum is LlamaAbsoluteStrategyBase {
// -------- At Action Creation --------
/// @inheritdoc ILlamaStrategy
function validateActionCreation(ActionInfo calldata /* actionInfo */ ) external view override {
LlamaPolicy llamaPolicy = policy; // Reduce SLOADs.
uint256 checkpointTime = block.timestamp - 1;
uint256 approvalPolicySupply = llamaPolicy.getPastRoleSupplyAsQuantitySum(approvalRole, checkpointTime);
if (approvalPolicySupply == 0) revert RoleHasZeroSupply(approvalRole);
uint256 disapprovalPolicySupply = llamaPolicy.getPastRoleSupplyAsQuantitySum(disapprovalRole, checkpointTime);
if (disapprovalPolicySupply == 0) revert RoleHasZeroSupply(disapprovalRole);
if (minApprovals > approvalPolicySupply) revert InsufficientApprovalQuantity();
if (minDisapprovals != type(uint96).max && minDisapprovals > disapprovalPolicySupply) {
revert InsufficientDisapprovalQuantity();
}
}
// -------- When Casting Approval --------
/// @inheritdoc ILlamaStrategy
function checkIfApprovalEnabled(ActionInfo calldata, /* actionInfo */ address, /* policyholder */ uint8 role)
external
view
override
{
if (role != approvalRole && !forceApprovalRole[role]) revert InvalidRole(approvalRole);
}
// -------- When Casting Disapproval --------
/// @inheritdoc ILlamaStrategy
function checkIfDisapprovalEnabled(ActionInfo calldata, /* actionInfo */ address, /* policyholder */ uint8 role)
external
view
override
{
if (minDisapprovals == type(uint96).max) revert DisapprovalDisabled();
if (role != disapprovalRole && !forceDisapprovalRole[role]) revert InvalidRole(disapprovalRole);
}
}