Skip to content

Commit 734cd71

Browse files
authoredJan 13, 2025··
Merge pull request #229 from Bananapus/jango/ruleset-weight-special
ruleset weight special case of 1
2 parents 589ee2b + a46507a commit 734cd71

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed
 

‎src/JBRulesets.sol

+5-6
Original file line numberDiff line numberDiff line change
@@ -1025,20 +1025,19 @@ contract JBRulesets is JBControlled, IJBRulesets {
10251025
mustStartAtOrAfter: mustStartAtOrAfter
10261026
});
10271027

1028-
// A weight of 1 is treated as a weight of 0.
1029-
// This is to allow a weight of 0 (default) to represent inheriting the cut weight of the previous
1028+
// A weight of 1 is a special case that represents inheriting the cut weight of the previous
10301029
// ruleset.
1031-
weight = weight > 0
1032-
? (weight == 1 ? 0 : weight)
1033-
: deriveWeightFrom({
1030+
weight = weight == 1
1031+
? deriveWeightFrom({
10341032
projectId: projectId,
10351033
baseRulesetStart: baseRuleset.start,
10361034
baseRulesetDuration: baseRuleset.duration,
10371035
baseRulesetWeight: baseRuleset.weight,
10381036
baseRulesetWeightCutPercent: baseRuleset.weightCutPercent,
10391037
baseRulesetCacheId: baseRuleset.id,
10401038
start: start
1041-
});
1039+
})
1040+
: weight;
10421041

10431042
// Derive the correct ruleset cycle number.
10441043
uint256 rulesetCycleNumber = deriveCycleNumberFrom({

‎test/TestRulesetQueueing.sol

+103
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,109 @@ contract TestRulesetQueuing_Local is TestBaseWorkflow {
205205
assertEq(_newRuleset.basedOnId, _currentRulesetId);
206206
}
207207

208+
function testReconfigureProjectWithWeightOfZero() public {
209+
// Package a ruleset configuration.
210+
JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
211+
_rulesetConfig[0].mustStartAtOrAfter = 0;
212+
_rulesetConfig[0].duration = _RULESET_DURATION;
213+
_rulesetConfig[0].weightCutPercent = 0;
214+
_rulesetConfig[0].approvalHook = _deadline;
215+
_rulesetConfig[0].metadata = _metadata;
216+
_rulesetConfig[0].splitGroups = _splitGroup;
217+
_rulesetConfig[0].fundAccessLimitGroups = _fundAccessLimitGroup;
218+
219+
// Deploy a project.
220+
uint256 projectId = launchProjectForTest();
221+
222+
// Keep a reference to the current ruleset.
223+
JBRuleset memory _ruleset = jbRulesets().currentOf(projectId);
224+
225+
// Make sure the ruleset has a cycle number of 1.
226+
assertEq(_ruleset.cycleNumber, 1);
227+
// Make sure the ruleset's weight matches.
228+
assertEq(_ruleset.weight, _weight);
229+
230+
// Keep a reference to the ruleset's ID.
231+
uint256 _currentRulesetId = _ruleset.id;
232+
233+
// Increment the weight to create a difference.
234+
_rulesetConfig[0].weight = 0;
235+
236+
// Add a ruleset.
237+
vm.prank(multisig());
238+
_controller.queueRulesetsOf(projectId, _rulesetConfig, "");
239+
240+
// Make sure the current ruleset hasn't changed.
241+
_ruleset = jbRulesets().currentOf(projectId);
242+
assertEq(_ruleset.cycleNumber, 1);
243+
assertEq(_ruleset.id, _currentRulesetId);
244+
assertEq(_ruleset.weight, _weight);
245+
246+
// Go to the start of the next ruleset.
247+
vm.warp(_ruleset.start + _ruleset.duration);
248+
249+
// Get the current ruleset.
250+
JBRuleset memory _newRuleset = jbRulesets().currentOf(projectId);
251+
252+
// It should be the second cycle.
253+
assertEq(_newRuleset.cycleNumber, 2);
254+
assertEq(_newRuleset.weight, 0);
255+
assertEq(_newRuleset.basedOnId, _currentRulesetId);
256+
}
257+
258+
function testReconfigureProjectWithWeightOfOne() public {
259+
// Package a ruleset configuration.
260+
JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
261+
_rulesetConfig[0].mustStartAtOrAfter = 0;
262+
_rulesetConfig[0].duration = _RULESET_DURATION;
263+
_rulesetConfig[0].weightCutPercent = 0;
264+
_rulesetConfig[0].approvalHook = _deadline;
265+
_rulesetConfig[0].metadata = _metadata;
266+
_rulesetConfig[0].splitGroups = _splitGroup;
267+
_rulesetConfig[0].fundAccessLimitGroups = _fundAccessLimitGroup;
268+
269+
// Deploy a project.
270+
uint256 projectId = launchProjectForTest();
271+
272+
// Keep a reference to the current ruleset.
273+
JBRuleset memory _ruleset = jbRulesets().currentOf(projectId);
274+
275+
// Make sure the ruleset has a cycle number of 1.
276+
assertEq(_ruleset.cycleNumber, 1);
277+
// Make sure the ruleset's weight matches.
278+
assertEq(_ruleset.weight, _weight);
279+
280+
// Keep a reference to the ruleset's ID.
281+
uint256 _currentRulesetId = _ruleset.id;
282+
283+
// Increment the weight to create a difference.
284+
_rulesetConfig[0].weight = 1;
285+
_rulesetConfig[0].weightCutPercent = 1_000_000_000 / 2;
286+
_rulesetConfig[0].duration = 1 days;
287+
288+
// Add a ruleset.
289+
vm.prank(multisig());
290+
_controller.queueRulesetsOf(projectId, _rulesetConfig, "");
291+
292+
// Make sure the current ruleset hasn't changed.
293+
_ruleset = jbRulesets().currentOf(projectId);
294+
assertEq(_ruleset.cycleNumber, 1);
295+
assertEq(_ruleset.id, _currentRulesetId);
296+
assertEq(_ruleset.weight, _weight);
297+
assertEq(_ruleset.weightCutPercent, 0);
298+
299+
// Go to the start of the next ruleset.
300+
vm.warp(_ruleset.start + _ruleset.duration + 1 days);
301+
302+
// Get the current ruleset.
303+
JBRuleset memory _newRuleset = jbRulesets().currentOf(projectId);
304+
305+
// It should be the second cycle.
306+
assertEq(_newRuleset.cycleNumber, 3);
307+
assertEq(_newRuleset.weight, _weight / 2);
308+
assertEq(_newRuleset.basedOnId, _currentRulesetId);
309+
}
310+
208311
function testMultipleQueuedOnCycledOver() public {
209312
// Keep references to two different weights.
210313
uint112 _weightFirstQueued = uint112(1234 * 10 ** 18);

0 commit comments

Comments
 (0)
Please sign in to comment.