Skip to main content

_configure

Configures a funding cycle and stores information pertinent to the configuration.

Definition​

function _configure(
uint256 _projectId,
JBFundingCycleData calldata _data,
JBFundingCycleMetadata calldata _metadata,
uint256 _mustStartAtOrAfter,
JBGroupedSplits[] memory _groupedSplits,
JBFundAccessConstraints[] memory _fundAccessConstraints
) internal returns (uint256) { ... }
  • Arguments:
    • _projectId is the ID of the project whose funding cycles are being reconfigured.
    • _data is a JBFundingCycleData data structure that defines the funding cycle. These properties will remain fixed for the duration of the funding cycle.
    • _metadata is a JBFundingCycleMetadata data structure specifying the controller specific params that a funding cycle can have. These properties will remain fixed for the duration of the funding cycle.
    • _mustStartAtOrAfter is the time before which the configured funding cycle cannot start.
    • _groupedSplits is an array of JBGroupedSplits data structures containing splits to set for any number of groups. The core protocol makes use of groups defined in JBSplitsGroups.
    • _fundAccessConstraints is an array of JBFundAccessConstraints data structures containing amounts that a project can use from its treasury for each payment terminal. Amounts are fixed point numbers using the same number of decimals as the accompanying terminal. The distributionLimit applies for each funding cycle, and the overflowAllowance applies for the entirety of the configuration. The _distributionLimit and _overflowAllowance parameters must fit in a uint232.
  • The resulting function is internal to this contract and its inheriters.
  • The function returns the funding cycle configuration that was successfully updated.

Body​

  1. Make sure the reserved rate is a valid number out of the max value.

    // Make sure the provided reserved rate is valid.
    if (_metadata.reservedRate > JBConstants.MAX_RESERVED_RATE) revert INVALID_RESERVED_RATE();

    Library references:

  2. Make sure the redemption rate is a valid number out of the max value.

    // Make sure the provided redemption rate is valid.
    if (_metadata.redemptionRate > JBConstants.MAX_REDEMPTION_RATE)
    revert INVALID_REDEMPTION_RATE();

    Library references:

  3. Make sure the ballot redemption rate is less than the max value.

    // Make sure the provided ballot redemption rate is valid.
    if (_metadata.ballotRedemptionRate > JBConstants.MAX_REDEMPTION_RATE)
    revert INVALID_BALLOT_REDEMPTION_RATE();

    Library references:

  4. Configure the project's funding cycles. Pack the metadata into a uint256.

    // Configure the funding cycle's properties.
    JBFundingCycle memory _fundingCycle = fundingCycleStore.configureFor(
    _projectId,
    _data,
    JBFundingCycleMetadataResolver.packFundingCycleMetadata(_metadata),
    _mustStartAtOrAfter
    );

    External references:

    Library references:

  5. Set splits.

    // Set splits for the group.
    splitsStore.set(_projectId, _fundingCycle.configuration, _groupedSplits);

    External references:

  6. For each fund access constraint struct in the array passed in, store the values of the distribution limit and overflow allowance packed with their respective currencies. Make sure the values are contained within their bit limit so that they can be packed together in one uint256. Emit a SetFundAccessConstraints event with the relevant parameters.

    // Set distribution limits if there are any.
    for (uint256 _i; _i < _fundAccessConstraints.length) {
    JBFundAccessConstraints memory _constraints = _fundAccessConstraints[_i];

    // If distribution limit value is larger than 232 bits, revert.
    if (_constraints.distributionLimit > type(uint232).max) revert INVALID_DISTRIBUTION_LIMIT();

    // If distribution limit currency value is larger than 24 bits, revert.
    if (_constraints.distributionLimitCurrency > type(uint24).max)
    revert INVALID_DISTRIBUTION_LIMIT_CURRENCY();

    // If overflow allowance value is larger than 232 bits, revert.
    if (_constraints.overflowAllowance > type(uint232).max) revert INVALID_OVERFLOW_ALLOWANCE();

    // If overflow allowance currency value is larger than 24 cbits, revert.
    if (_constraints.overflowAllowanceCurrency > type(uint24).max)
    revert INVALID_OVERFLOW_ALLOWANCE_CURRENCY();

    // Set the distribution limit if there is one.
    if (_constraints.distributionLimit > 0)
    _packedDistributionLimitDataOf[_projectId][_fundingCycle.configuration][
    _constraints.terminal
    ] = _constraints.distributionLimit | (_constraints.distributionLimitCurrency << 232);

    // Set the overflow allowance if there is one.
    if (_constraints.overflowAllowance > 0)
    _packedOverflowAllowanceDataOf[_projectId][_fundingCycle.configuration][
    _constraints.terminal
    ] = _constraints.overflowAllowance | (_constraints.overflowAllowanceCurrency << 232);

    emit SetFundAccessConstraints(
    _fundingCycle.configuration,
    _fundingCycle.number,
    _projectId,
    _constraints,
    msg.sender
    );

    unchecked {
    ++_i;
    }
    }

    Internal references:

    Event references:

  7. Return the funding cycle's configuration.

    return _fundingCycle.configuration;