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

send full ruleset #240

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 9 additions & 15 deletions src/JBDeadline.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {JBApprovalStatus} from "./enums/JBApprovalStatus.sol";
import {IJBRulesetApprovalHook} from "./interfaces/IJBRulesetApprovalHook.sol";
import {JBRuleset} from "./structs/JBRuleset.sol";

/// @notice `JBDeadline` is a ruleset approval hook which rejects rulesets if they are not queued at least `duration`
/// seconds before the current ruleset ends. In other words, rulesets must be queued before the deadline to take effect.
Expand Down Expand Up @@ -34,31 +35,24 @@ contract JBDeadline is IJBRulesetApprovalHook {
//*********************************************************************//

/// @notice The approval status of a given ruleset.
/// @param rulesetId The ID of the ruleset to check the status of.
/// @param start The start timestamp of the ruleset to check the status of.
/// @param projectId The ID of the project that the ruleset belongs to.
/// @param ruleset The ruleset to check the status of.
/// @return The ruleset's approval status.
function approvalStatusOf(
uint256,
uint256 rulesetId,
uint256 start
)
public
view
override
returns (JBApprovalStatus)
{
function approvalStatusOf(uint256, JBRuleset memory ruleset) public view override returns (JBApprovalStatus) {
// The ruleset ID is the timestamp at which the ruleset was queued.
// If the provided `rulesetId` timestamp is after the start timestamp, the ruleset has `Failed`.
if (rulesetId > start) return JBApprovalStatus.Failed;
if (ruleset.id > ruleset.start) return JBApprovalStatus.Failed;

unchecked {
// If there aren't enough seconds between the time the ruleset was queued and the time it starts, it has
// `Failed`.
// Otherwise, if there is still time before the deadline, the ruleset's status is `ApprovalExpected`.
// If we've already passed the deadline, the ruleset is `Approved`.
return (start - rulesetId < DURATION)
return (ruleset.start - ruleset.id < DURATION)
? JBApprovalStatus.Failed
: (block.timestamp + DURATION < start) ? JBApprovalStatus.ApprovalExpected : JBApprovalStatus.Approved;
: (block.timestamp + DURATION < ruleset.start)
? JBApprovalStatus.ApprovalExpected
: JBApprovalStatus.Approved;
}
}

Expand Down
62 changes: 25 additions & 37 deletions src/JBRulesets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ contract JBRulesets is JBControlled, IJBRulesets {
// Resolve the struct for the latest ruleset.
JBRuleset memory ruleset = _getStructFor(projectId, rulesetId);

return _approvalStatusOf({
projectId: projectId,
rulesetId: ruleset.id,
start: ruleset.start,
approvalHookRulesetId: ruleset.basedOnId
});
return _approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});
}

/// @notice The ruleset that is currently active for the specified project.
Expand All @@ -187,7 +182,8 @@ contract JBRulesets is JBControlled, IJBRulesets {
ruleset = _getStructFor(projectId, rulesetId);

// Get a reference to the approval status.
JBApprovalStatus approvalStatus = _approvalStatusOf(projectId, ruleset);
JBApprovalStatus approvalStatus =
_approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});

// Check to see if this ruleset's approval hook is approved if it exists.
// If so, return it.
Expand All @@ -212,7 +208,8 @@ contract JBRulesets is JBControlled, IJBRulesets {
ruleset = _getStructFor(projectId, rulesetId);

// Get a reference to the approval status.
JBApprovalStatus approvalStatus = _approvalStatusOf(projectId, ruleset);
JBApprovalStatus approvalStatus =
_approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});

// While the ruleset has a approval hook that isn't approved or if it hasn't yet started, get a reference to
// the ruleset that the latest is based on, which has the latest approved configuration.
Expand All @@ -221,8 +218,12 @@ contract JBRulesets is JBControlled, IJBRulesets {
|| block.timestamp < ruleset.start
) {
rulesetId = ruleset.basedOnId;
ruleset = _getStructFor(projectId, rulesetId);
approvalStatus = _approvalStatusOf(projectId, ruleset);
ruleset = _getStructFor({projectId: projectId, rulesetId: rulesetId});
approvalStatus = _approvalStatusOf({
projectId: projectId,
ruleset: ruleset,
approvalHookRulesetId: ruleset.basedOnId
});
}
}

Expand Down Expand Up @@ -269,12 +270,8 @@ contract JBRulesets is JBControlled, IJBRulesets {
ruleset = _getStructFor(projectId, rulesetId);

// Resolve the approval status.
approvalStatus = _approvalStatusOf({
projectId: projectId,
rulesetId: ruleset.id,
start: ruleset.start,
approvalHookRulesetId: ruleset.basedOnId
});
approvalStatus =
_approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});
}

/// @notice The ruleset that's up next for a project.
Expand All @@ -298,7 +295,8 @@ contract JBRulesets is JBControlled, IJBRulesets {
ruleset = _getStructFor(projectId, upcomingApprovableRulesetId);

// Get a reference to the approval status.
approvalStatus = _approvalStatusOf(projectId, ruleset);
approvalStatus =
_approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});

// If the approval hook is empty, expects approval, or has approved the ruleset, return it.
if (
Expand Down Expand Up @@ -326,7 +324,8 @@ contract JBRulesets is JBControlled, IJBRulesets {
if (ruleset.duration == 0) return _getStructFor(0, 0);

// Get a reference to the approval status.
approvalStatus = _approvalStatusOf(projectId, ruleset);
approvalStatus =
_approvalStatusOf({projectId: projectId, ruleset: ruleset, approvalHookRulesetId: ruleset.basedOnId});

// Check to see if this ruleset's approval hook hasn't failed.
// If so, return a ruleset based on it.
Expand Down Expand Up @@ -503,29 +502,14 @@ contract JBRulesets is JBControlled, IJBRulesets {
// -------------------------- internal views ------------------------- //
//*********************************************************************//

/// @notice The approval status of a given project and ruleset struct according to the relevant approval hook.
/// @param projectId The ID of the project that the ruleset belongs to.
/// @param ruleset The ruleset to get an approval flag for.
/// @return The approval status of the project's ruleset.
function _approvalStatusOf(uint256 projectId, JBRuleset memory ruleset) internal view returns (JBApprovalStatus) {
return _approvalStatusOf({
projectId: projectId,
rulesetId: ruleset.id,
start: ruleset.start,
approvalHookRulesetId: ruleset.basedOnId
});
}

/// @notice The approval status of a given ruleset (ID) for a given project (ID).
/// @param projectId The ID of the project the ruleset belongs to.
/// @param rulesetId The ID of the ruleset to get the approval status of.
/// @param start The start time of the ruleset to get the approval status of.
/// @param ruleset The ruleset to get the approval status of.
/// @param approvalHookRulesetId The ID of the ruleset with the approval hook that should be checked against.
/// @return The approval status of the project.
function _approvalStatusOf(
uint256 projectId,
uint256 rulesetId,
uint256 start,
JBRuleset memory ruleset,
uint256 approvalHookRulesetId
)
internal
Expand All @@ -546,7 +530,7 @@ contract JBRulesets is JBControlled, IJBRulesets {

// Return the approval hook's approval status.
// slither-disable-next-line calls-loop
return approvalHookRuleset.approvalHook.approvalStatusOf(projectId, rulesetId, start);
return approvalHookRuleset.approvalHook.approvalStatusOf({projectId: projectId, ruleset: ruleset});
}

/// @notice The ID of the ruleset which has started and hasn't expired yet, whether or not it has been approved, for
Expand Down Expand Up @@ -947,7 +931,11 @@ contract JBRulesets is JBControlled, IJBRulesets {
JBRuleset memory baseRuleset = _getStructFor(projectId, latestId);

// Get a reference to the approval status.
JBApprovalStatus approvalStatus = _approvalStatusOf(projectId, baseRuleset);
JBApprovalStatus approvalStatus = _approvalStatusOf({
projectId: projectId,
ruleset: baseRuleset,
approvalHookRulesetId: baseRuleset.basedOnId
});

// If the base ruleset has started but wasn't approved if a approval hook exists
// OR it hasn't started but is currently approved
Expand Down
10 changes: 2 additions & 8 deletions src/interfaces/IJBRulesetApprovalHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {JBApprovalStatus} from "./../enums/JBApprovalStatus.sol";
import {JBRuleset} from "./../structs/JBRuleset.sol";

/// @notice `IJBRulesetApprovalHook`s are used to determine whether the next ruleset in the ruleset queue is approved or
/// rejected.
Expand All @@ -12,12 +13,5 @@ import {JBApprovalStatus} from "./../enums/JBApprovalStatus.sol";
interface IJBRulesetApprovalHook is IERC165 {
function DURATION() external view returns (uint256);

function approvalStatusOf(
uint256 projectId,
uint256 rulesetId,
uint256 start
)
external
view
returns (JBApprovalStatus);
function approvalStatusOf(uint256 projectId, JBRuleset memory ruleset) external view returns (JBApprovalStatus);
}
13 changes: 12 additions & 1 deletion test/TestRulesetQueueing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,19 @@ contract TestRulesetQueuing_Local is TestBaseWorkflow {
_duration = bound(_duration, 1, block.timestamp);

JBDeadline deadline = new JBDeadline(_duration);
JBRuleset memory ruleset = JBRuleset({
cycleNumber: 1,
id: _rulesetId,
basedOnId: 0,
start: _start,
duration: 0,
weight: 0,
weightCutPercent: 0,
approvalHook: IJBRulesetApprovalHook(address(0)),
metadata: 0
});

JBApprovalStatus _currentStatus = deadline.approvalStatusOf(1, _rulesetId, _start); // 1 is the `projectId`,
JBApprovalStatus _currentStatus = deadline.approvalStatusOf(1, _ruleset); // 1 is the `projectId`,
// unused

// Ruleset ID (timestamp) is after deadline -> approval hook failed.
Expand Down
Loading