Skip to main content

_mockFundingCycleBasedOn

Contract: JBFundingCycleStore

A view of the funding cycle that would be created based on the provided one if the project doesn't make a reconfiguration.

Returns an empty funding cycle if there can't be a mock funding cycle based on the provided one.

Assumes a funding cycle with a duration of 0 will never be asked to be the base of a mock.

Definition

function _mockFundingCycleBasedOn(JBFundingCycle memory _baseFundingCycle, bool _allowMidCycle)
private
view
returns (JBFundingCycle memory) { ... }
  • Arguments:
    • _baseFundingCycle is the JBFundingCycle that the resulting funding cycle should follow.
    • _allowMidCycle is a flag indicating if the mocked funding cycle is allowed to already be mid cycle.
  • The view function is private to this contract.
  • The view function does not alter state on the blockchain.
  • The function returns a mock JBFundingCycle of what the next funding cycle will be.

Body

  1. Save a reference to time at or after which the mock must have started. There are a few possibilities.

    1. If the call to the function does not allow mid cycle, the start date must be now or in the future. This is also the case if the base funding cycle doesn't have a duration because the next funding cycle can start immediately.
    2. If neither of these cases apply, moving back one full duration period of the base funding cycle will find the most recent possible start time for the mock cycle to start.
    // Get the distance of the current time to the start of the next possible funding cycle.
    // If the returned mock cycle must not yet have started, the start time of the mock must be in the future.
    uint256 _mustStartAtOrAfter = !_allowMidCycle
    ? block.timestamp + 1
    : block.timestamp - _baseFundingCycle.duration + 1;
  2. Find the correct start time for the mock funding cycle.

    // Derive what the start time should be.
    uint256 _start = _deriveStartFrom(_baseFundingCycle, _mustStartAtOrAfter);

    Internal references:

  3. Find the correct number for the mock funding cycle.

    // Derive what the number should be.
    uint256 _number = _deriveNumberFrom(_baseFundingCycle, _start);

    Internal references:

  4. Return a JBFundingCycle with the aggregated configuration.

    return
    JBFundingCycle(
    _number,
    _baseFundingCycle.configuration,
    _baseFundingCycle.basedOn,
    _start,
    _baseFundingCycle.duration,
    _deriveWeightFrom(_baseFundingCycle, _start),
    _baseFundingCycle.discountRate,
    _baseFundingCycle.ballot,
    _baseFundingCycle.metadata
    );

    Internal references: