跳到主要内容

_initFor

Contract: JBFundingCycleStore

Initializes a funding cycle with the specified properties.

Definition

function _initFor(
uint256 _projectId,
JBFundingCycle memory _baseFundingCycle,
uint256 _configuration,
uint256 _mustStartAtOrAfter,
uint256 _weight
) private { ... }
  • Arguments:
    • _projectId is the ID of the project to which the funding cycle being initialized belongs.
    • _baseFundingCycle is the funding cycle to base the initialized one on.
    • _configuration is the configuration of the funding cycle being initialized.
    • _mustStartAtOrAfter is the time before which the initialized funding cycle cannot start.
    • _weight is the weight to give the newly initialized funding cycle.
  • The function is private to this contract.
  • The function doesn't return anything.

Body

  1. If no base funding cycle was provided, create a first funding cycle for the project by storing its intrinsic properties. Otherwise, create a new funding cycle by deriving values from the specified base cycle, interpreting a weight of 0 to inherit from the discounted weight of the base funding cycle and a weight of 1 as a weight of 0.

    // If there is no base, initialize a first cycle.
    if (_baseFundingCycle.number == 0) {
    // The first number is 1.
    uint256 _number = 1;

    // Set fresh intrinsic properties.
    _packAndStoreIntrinsicPropertiesOf(
    _configuration,
    _projectId,
    _number,
    _weight,
    _baseFundingCycle.configuration,
    _mustStartAtOrAfter
    );
    } else {
    // Derive the correct next start time from the base.
    uint256 _start = _deriveStartFrom(_baseFundingCycle, _mustStartAtOrAfter);

    // A weight of 1 is treated as a weight of 0.
    // This is to allow a weight of 0 (default) to represent inheriting the discounted weight of the previous funding cycle.
    _weight = _weight > 0
    ? (_weight == 1 ? 0 : _weight)
    : _deriveWeightFrom(_baseFundingCycle, _start);

    // Derive the correct number.
    uint256 _number = _deriveNumberFrom(_baseFundingCycle, _start);

    // Update the intrinsic properties.
    _packAndStoreIntrinsicPropertiesOf(
    _configuration,
    _projectId,
    _number,
    _weight,
    _baseFundingCycle.configuration,
    _start
    );
    }

    Internal references:

  2. Store the initialized configuration as the latest of the project.

    // Set the project's latest funding cycle configuration.
    latestConfigurationOf[_projectId] = _configuration;

    Internal references:

  3. Emit an Init event with the relevant parameters.

    emit Init(_configuration, _projectId, _baseFundingCycle.configuration);

    Event references: