JBRulesets
Inherits: JBControlled, IJBRulesets
Manages rulesets and queuing.
Rulesets dictate how a project behaves for a period of time. To learn more about their functionality, see the
JBRuleset
data structure.
Throughout this contract, rulesetId
is an identifier for each ruleset. The rulesetId
is the unix timestamp
when the ruleset was initialized.
approvable
means a ruleset which may or may not be approved.
State Variables
_WEIGHT_CUT_MULTIPLE_CACHE_LOOKUP_THRESHOLD
The number of weight cut percent multiples before a cached value is sought.
uint256 internal constant _WEIGHT_CUT_MULTIPLE_CACHE_LOOKUP_THRESHOLD = 1000;
_MAX_WEIGHT_CUT_MULTIPLE_CACHE_THRESHOLD
The maximum number of weight cut percent multiples that can be cached at a time.
uint256 internal constant _MAX_WEIGHT_CUT_MULTIPLE_CACHE_THRESHOLD = 50_000;
latestRulesetIdOf
The ID of the ruleset with the latest start time for a specific project, whether the ruleset has been approved or not.
If a project has multiple rulesets queued, the latestRulesetIdOf
will be the last one. This is the
"changeable" cycle.
mapping(uint256 projectId => uint256) public override latestRulesetIdOf;
_metadataOf
The metadata for each ruleset, packed into one storage slot.
mapping(uint256 projectId => mapping(uint256 rulesetId => uint256)) internal _metadataOf;
_packedIntrinsicPropertiesOf
The mechanism-added properties to manage and schedule each ruleset, packed into one storage slot.
mapping(uint256 projectId => mapping(uint256 rulesetId => uint256)) internal _packedIntrinsicPropertiesOf;
_packedUserPropertiesOf
The user-defined properties of each ruleset, packed into one storage slot.
mapping(uint256 projectId => mapping(uint256 rulesetId => uint256)) internal _packedUserPropertiesOf;
_weightCacheOf
Cached weight values to derive rulesets from.
mapping(uint256 projectId => mapping(uint256 rulesetId => JBRulesetWeightCache)) internal _weightCacheOf;
Functions
constructor
constructor(IJBDirectory directory) JBControlled(directory);
Parameters
Name | Type | Description |
---|---|---|
directory | IJBDirectory | A contract storing directories of terminals and controllers for each project. |
allOf
Get an array of a project's rulesets up to a maximum array size, sorted from latest to earliest.
function allOf(
uint256 projectId,
uint256 startingId,
uint256 size
)
external
view
override
returns (JBRuleset[] memory rulesets);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the rulesets of. |
startingId | uint256 | The ID of the ruleset to begin with. This will be the latest ruleset in the result. If 0 is passed, the project's latest ruleset will be used. |
size | uint256 | The maximum number of rulesets to return. |
Returns
Name | Type | Description |
---|---|---|
rulesets | JBRuleset[] | The rulesets as an array of JBRuleset structs. |
currentApprovalStatusForLatestRulesetOf
The current approval status of a given project's latest ruleset.
function currentApprovalStatusForLatestRulesetOf(uint256 projectId) external view override returns (JBApprovalStatus);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to check the approval status of. |
Returns
Name | Type | Description |
---|---|---|
<none> | JBApprovalStatus | The project's current approval status. |
currentOf
The ruleset that is currently active for the specified project.
If a current ruleset of the project is not found, returns an empty ruleset with all properties set to 0.
function currentOf(uint256 projectId) external view override returns (JBRuleset memory ruleset);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the current ruleset of. |
Returns
Name | Type | Description |
---|---|---|
ruleset | JBRuleset | The project's current ruleset. |
getRulesetOf
Get the ruleset struct for a given rulesetId
and projectId
.
function getRulesetOf(uint256 projectId, uint256 rulesetId) external view override returns (JBRuleset memory ruleset);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to which the ruleset belongs. |
rulesetId | uint256 | The ID of the ruleset to get the struct of. |
Returns
Name | Type | Description |
---|---|---|
ruleset | JBRuleset | The ruleset struct. |
latestQueuedOf
The latest ruleset queued for a project. Returns the ruleset's struct and its current approval status.
Returns struct and status for the ruleset initialized furthest in the future (at the end of the ruleset queue).
function latestQueuedOf(uint256 projectId)
external
view
override
returns (JBRuleset memory ruleset, JBApprovalStatus approvalStatus);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the latest queued ruleset of. |
Returns
Name | Type | Description |
---|---|---|
ruleset | JBRuleset | The project's latest queued ruleset's struct. |
approvalStatus | JBApprovalStatus | The approval hook's status for the ruleset. |
upcomingOf
The ruleset that's up next for a project.
If an upcoming ruleset is not found for the project, returns an empty ruleset with all properties set to 0.
function upcomingOf(uint256 projectId) external view override returns (JBRuleset memory ruleset);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the upcoming ruleset of. |
Returns
Name | Type | Description |
---|---|---|
ruleset | JBRuleset | The struct for the project's upcoming ruleset. |
deriveCycleNumberFrom
The cycle number of the next ruleset given the specified ruleset.
Each time a ruleset starts, whether it was queued or cycled over, the cycle number is incremented by 1.
function deriveCycleNumberFrom(
uint256 baseRulesetCycleNumber,
uint256 baseRulesetStart,
uint256 baseRulesetDuration,
uint256 start
)
public
pure
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
baseRulesetCycleNumber | uint256 | The cycle number of the base ruleset. |
baseRulesetStart | uint256 | The start time of the base ruleset. |
baseRulesetDuration | uint256 | The duration of the base ruleset. |
start | uint256 | The start time of the ruleset to derive a cycle number for. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The ruleset's cycle number. |
deriveStartFrom
The date that is the nearest multiple of the base ruleset's duration from the start of the next cycle.
function deriveStartFrom(
uint256 baseRulesetStart,
uint256 baseRulesetDuration,
uint256 mustStartAtOrAfter
)
public
pure
returns (uint256 start);
Parameters
Name | Type | Description |
---|---|---|
baseRulesetStart | uint256 | The start time of the base ruleset. |
baseRulesetDuration | uint256 | The duration of the base ruleset. |
mustStartAtOrAfter | uint256 | The earliest time the next ruleset can start. The ruleset cannot start before this timestamp. |
Returns
Name | Type | Description |
---|---|---|
start | uint256 | The next start time. |
deriveWeightFrom
The accumulated weight change since the specified ruleset.
function deriveWeightFrom(
uint256 projectId,
uint256 baseRulesetStart,
uint256 baseRulesetDuration,
uint256 baseRulesetWeight,
uint256 baseRulesetWeightCutPercent,
uint256 baseRulesetCacheId,
uint256 start
)
public
view
returns (uint256 weight);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to which the ruleset weights apply. |
baseRulesetStart | uint256 | The start time of the base ruleset. |
baseRulesetDuration | uint256 | The duration of the base ruleset. |
baseRulesetWeight | uint256 | The weight of the base ruleset. |
baseRulesetWeightCutPercent | uint256 | The weight cut percent of the base ruleset. |
baseRulesetCacheId | uint256 | The ID of the ruleset to base the calculation on (the previous ruleset). |
start | uint256 | The start time of the ruleset to derive a weight for. |
Returns
Name | Type | Description |
---|---|---|
weight | uint256 | The derived weight, as a fixed point number with 18 decimals. |
_approvalStatusOf
The approval status of a given project and ruleset struct according to the relevant approval hook.
function _approvalStatusOf(uint256 projectId, JBRuleset memory ruleset) internal view returns (JBApprovalStatus);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project that the ruleset belongs to. |
ruleset | JBRuleset | The ruleset to get an approval flag for. |
Returns
Name | Type | Description |
---|---|---|
<none> | JBApprovalStatus | The approval status of the project's ruleset. |
_approvalStatusOf
The approval status of a given ruleset (ID) for a given project (ID).
function _approvalStatusOf(
uint256 projectId,
uint256 rulesetId,
uint256 start,
uint256 approvalHookRulesetId
)
internal
view
returns (JBApprovalStatus);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project the ruleset belongs to. |
rulesetId | uint256 | The ID of the ruleset to get the approval status of. |
start | uint256 | The start time of the ruleset to get the approval status of. |
approvalHookRulesetId | uint256 | The ID of the ruleset with the approval hook that should be checked against. |
Returns
Name | Type | Description |
---|---|---|
<none> | JBApprovalStatus | The approval status of the project. |
_currentlyApprovableRulesetIdOf
The ID of the ruleset which has started and hasn't expired yet, whether or not it has been approved, for a given project. If approved, this is the active ruleset.
A value of 0 is returned if no ruleset was found.
Assumes the project has a latest ruleset.
function _currentlyApprovableRulesetIdOf(uint256 projectId) internal view returns (uint256);