// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)pragmasolidity ^0.8.0;import"./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
Contract Source Code
File 2 of 44: IERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/interfaceIERC165{
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 3 of 44: IERC721.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/interfaceIERC721isIERC165{
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner, addressindexed approved, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/eventApprovalForAll(addressindexed owner, addressindexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/functionbalanceOf(address owner) externalviewreturns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functionownerOf(uint256 tokenId) externalviewreturns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/functionapprove(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functiongetApproved(uint256 tokenId) externalviewreturns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/functionsetApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/functionisApprovedForAll(address owner, address operator) externalviewreturns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId,
bytescalldata data
) external;
}
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'@openzeppelin/contracts/utils/introspection/ERC165.sol';
import'@paulrberg/contracts/math/PRBMath.sol';
import'./abstract/JBOperatable.sol';
import'./interfaces/IJBController.sol';
import'./interfaces/IJBMigratable.sol';
import'./interfaces/IJBOperatorStore.sol';
import'./interfaces/IJBPaymentTerminal.sol';
import'./interfaces/IJBProjects.sol';
import'./libraries/JBConstants.sol';
import'./libraries/JBFundingCycleMetadataResolver.sol';
import'./libraries/JBOperations.sol';
import'./libraries/JBSplitsGroups.sol';
/**
@notice
Stitches together funding cycles and community tokens, making sure all activity is accounted for and correct.
@dev
Adheres to -
IJBController: General interface for the generic controller methods in this contract that interacts with funding cycles and tokens according to the protocol's rules.
IJBMigratable: Allows migrating to this contract, with a hook called to prepare for the migration.
@dev
Inherits from -
JBOperatable: Several functions in this contract can only be accessed by a project owner, or an address that has been preconfifigured to be an operator of the project.
ERC165: Introspection on interface adherance.
*/contractJBControllerisIJBController, IJBMigratable, JBOperatable, ERC165{
// A library that parses the packed funding cycle metadata into a more friendly format.usingJBFundingCycleMetadataResolverforJBFundingCycle;
//*********************************************************************//// --------------------------- custom errors ------------------------- ////*********************************************************************//errorBURN_PAUSED_AND_SENDER_NOT_VALID_TERMINAL_DELEGATE();
errorCANT_MIGRATE_TO_CURRENT_CONTROLLER();
errorCHANGE_TOKEN_NOT_ALLOWED();
errorFUNDING_CYCLE_ALREADY_LAUNCHED();
errorINVALID_BALLOT_REDEMPTION_RATE();
errorINVALID_DISTRIBUTION_LIMIT();
errorINVALID_DISTRIBUTION_LIMIT_CURRENCY();
errorINVALID_OVERFLOW_ALLOWANCE();
errorINVALID_OVERFLOW_ALLOWANCE_CURRENCY();
errorINVALID_REDEMPTION_RATE();
errorINVALID_RESERVED_RATE();
errorMIGRATION_NOT_ALLOWED();
errorMINT_NOT_ALLOWED_AND_NOT_TERMINAL_DELEGATE();
errorNO_BURNABLE_TOKENS();
errorNOT_CURRENT_CONTROLLER();
errorZERO_TOKENS_TO_MINT();
//*********************************************************************//// --------------------- internal stored properties ------------------ ////*********************************************************************///**
@notice
The difference between the processed token tracker of a project and the project's token's total supply is the amount of tokens that still need to have reserves minted against them.
_projectId The ID of the project to get the tracker of.
*/mapping(uint256=>int256) internal _processedTokenTrackerOf;
/**
@notice
Data regarding the distribution limit of a project during a configuration.
@dev
bits 0-231: The amount of token that a project can distribute per funding cycle.
@dev
bits 232-255: The currency of amount that a project can distribute.
_projectId The ID of the project to get the packed distribution limit data of.
_configuration The configuration during which the packed distribution limit data applies.
_terminal The terminal from which distributions are being limited.
_token The token for which distributions are being limited.
*/mapping(uint256=>mapping(uint256=>mapping(IJBPaymentTerminal =>mapping(address=>uint256))))
internal _packedDistributionLimitDataOf;
/**
@notice
Data regarding the overflow allowance of a project during a configuration.
@dev
bits 0-231: The amount of overflow that a project is allowed to tap into on-demand throughout the configuration.
@dev
bits 232-255: The currency of the amount of overflow that a project is allowed to tap.
_projectId The ID of the project to get the packed overflow allowance data of.
_configuration The configuration during which the packed overflow allowance data applies.
_terminal The terminal managing the overflow.
_token The token for which overflow is being allowed.
*/mapping(uint256=>mapping(uint256=>mapping(IJBPaymentTerminal =>mapping(address=>uint256))))
internal _packedOverflowAllowanceDataOf;
//*********************************************************************//// --------------- public immutable stored properties ---------------- ////*********************************************************************///**
@notice
Mints ERC-721's that represent project ownership.
*/
IJBProjects publicimmutableoverride projects;
/**
@notice
The contract storing all funding cycle configurations.
*/
IJBFundingCycleStore publicimmutableoverride fundingCycleStore;
/**
@notice
The contract that manages token minting and burning.
*/
IJBTokenStore publicimmutableoverride tokenStore;
/**
@notice
The contract that stores splits for each project.
*/
IJBSplitsStore publicimmutableoverride splitsStore;
/**
@notice
The directory of terminals and controllers for projects.
*/
IJBDirectory publicimmutableoverride directory;
//*********************************************************************//// ------------------------- external views -------------------------- ////*********************************************************************///**
@notice
The amount of token that a project can distribute per funding cycle, and the currency it's in terms of.
@dev
The number of decimals in the returned fixed point amount is the same as that of the specified terminal.
@param _projectId The ID of the project to get the distribution limit of.
@param _configuration The configuration during which the distribution limit applies.
@param _terminal The terminal from which distributions are being limited.
@param _token The token for which the distribution limit applies.
@return The distribution limit, as a fixed point number with the same number of decimals as the provided terminal.
@return The currency of the distribution limit.
*/functiondistributionLimitOf(uint256 _projectId,
uint256 _configuration,
IJBPaymentTerminal _terminal,
address _token
) externalviewoverridereturns (uint256, uint256) {
// Get a reference to the packed data.uint256 _data = _packedDistributionLimitDataOf[_projectId][_configuration][_terminal][_token];
// The limit is in bits 0-231. The currency is in bits 232-255.return (uint256(uint232(_data)), _data >>232);
}
/**
@notice
The amount of overflow that a project is allowed to tap into on-demand throughout a configuration, and the currency it's in terms of.
@dev
The number of decimals in the returned fixed point amount is the same as that of the specified terminal.
@param _projectId The ID of the project to get the overflow allowance of.
@param _configuration The configuration of the during which the allowance applies.
@param _terminal The terminal managing the overflow.
@param _token The token for which the overflow allowance applies.
@return The overflow allowance, as a fixed point number with the same number of decimals as the provided terminal.
@return The currency of the overflow allowance.
*/functionoverflowAllowanceOf(uint256 _projectId,
uint256 _configuration,
IJBPaymentTerminal _terminal,
address _token
) externalviewoverridereturns (uint256, uint256) {
// Get a reference to the packed data.uint256 _data = _packedOverflowAllowanceDataOf[_projectId][_configuration][_terminal][_token];
// The allowance is in bits 0-231. The currency is in bits 232-255.return (uint256(uint232(_data)), _data >>232);
}
/**
@notice
Gets the amount of reserved tokens that a project has available to distribute.
@param _projectId The ID of the project to get a reserved token balance of.
@param _reservedRate The reserved rate to use when making the calculation.
@return The current amount of reserved tokens.
*/functionreservedTokenBalanceOf(uint256 _projectId, uint256 _reservedRate)
externalviewoverridereturns (uint256)
{
return
_reservedTokenAmountFrom(
_processedTokenTrackerOf[_projectId],
_reservedRate,
tokenStore.totalSupplyOf(_projectId)
);
}
/**
@notice
Gets the current total amount of outstanding tokens for a project, given a reserved rate.
@param _projectId The ID of the project to get total outstanding tokens of.
@param _reservedRate The reserved rate to use when making the calculation.
@return The current total amount of outstanding tokens for the project.
*/functiontotalOutstandingTokensOf(uint256 _projectId, uint256 _reservedRate)
externalviewoverridereturns (uint256)
{
// Get the total number of tokens in circulation.uint256 _totalSupply = tokenStore.totalSupplyOf(_projectId);
// Get the number of reserved tokens the project has.uint256 _reservedTokenAmount = _reservedTokenAmountFrom(
_processedTokenTrackerOf[_projectId],
_reservedRate,
_totalSupply
);
// Add the reserved tokens to the total supply.return _totalSupply + _reservedTokenAmount;
}
/**
@notice
A project's funding cycle for the specified configuration along with its metadata.
@param _projectId The ID of the project to which the funding cycle belongs.
@return fundingCycle The funding cycle.
@return metadata The funding cycle's metadata.
*/functiongetFundingCycleOf(uint256 _projectId, uint256 _configuration)
externalviewoverridereturns (JBFundingCycle memory fundingCycle, JBFundingCycleMetadata memory metadata)
{
fundingCycle = fundingCycleStore.get(_projectId, _configuration);
metadata = fundingCycle.expandMetadata();
}
/**
@notice
A project's latest configured funding cycle along with its metadata and the ballot state of the configuration.
@param _projectId The ID of the project to which the funding cycle belongs.
@return fundingCycle The latest configured funding cycle.
@return metadata The latest configured funding cycle's metadata.
@return ballotState The state of the configuration.
*/functionlatestConfiguredFundingCycleOf(uint256 _projectId)
externalviewoverridereturns (
JBFundingCycle memory fundingCycle,
JBFundingCycleMetadata memory metadata,
JBBallotState ballotState
)
{
(fundingCycle, ballotState) = fundingCycleStore.latestConfiguredOf(_projectId);
metadata = fundingCycle.expandMetadata();
}
/**
@notice
A project's current funding cycle along with its metadata.
@param _projectId The ID of the project to which the funding cycle belongs.
@return fundingCycle The current funding cycle.
@return metadata The current funding cycle's metadata.
*/functioncurrentFundingCycleOf(uint256 _projectId)
externalviewoverridereturns (JBFundingCycle memory fundingCycle, JBFundingCycleMetadata memory metadata)
{
fundingCycle = fundingCycleStore.currentOf(_projectId);
metadata = fundingCycle.expandMetadata();
}
/**
@notice
A project's queued funding cycle along with its metadata.
@param _projectId The ID of the project to which the funding cycle belongs.
@return fundingCycle The queued funding cycle.
@return metadata The queued funding cycle's metadata.
*/functionqueuedFundingCycleOf(uint256 _projectId)
externalviewoverridereturns (JBFundingCycle memory fundingCycle, JBFundingCycleMetadata memory metadata)
{
fundingCycle = fundingCycleStore.queuedOf(_projectId);
metadata = fundingCycle.expandMetadata();
}
//*********************************************************************//// -------------------------- public views --------------------------- ////*********************************************************************///**
@notice
Indicates if this contract adheres to the specified interface.
@dev
See {IERC165-supportsInterface}.
@param _interfaceId The ID of the interface to check for adherance to.
*/functionsupportsInterface(bytes4 _interfaceId)
publicviewvirtualoverride(ERC165, IERC165)
returns (bool)
{
return
_interfaceId ==type(IJBController).interfaceId||
_interfaceId ==type(IJBMigratable).interfaceId||
_interfaceId ==type(IJBOperatable).interfaceId||super.supportsInterface(_interfaceId);
}
//*********************************************************************//// ---------------------------- constructor -------------------------- ////*********************************************************************///**
@param _operatorStore A contract storing operator assignments.
@param _projects A contract which mints ERC-721's that represent project ownership and transfers.
@param _directory A contract storing directories of terminals and controllers for each project.
@param _fundingCycleStore A contract storing all funding cycle configurations.
@param _tokenStore A contract that manages token minting and burning.
@param _splitsStore A contract that stores splits for each project.
*/constructor(
IJBOperatorStore _operatorStore,
IJBProjects _projects,
IJBDirectory _directory,
IJBFundingCycleStore _fundingCycleStore,
IJBTokenStore _tokenStore,
IJBSplitsStore _splitsStore
) JBOperatable(_operatorStore) {
projects = _projects;
directory = _directory;
fundingCycleStore = _fundingCycleStore;
tokenStore = _tokenStore;
splitsStore = _splitsStore;
}
//*********************************************************************//// --------------------- external transactions ----------------------- ////*********************************************************************///**
@notice
Creates a project. This will mint an ERC-721 into the specified owner's account, configure a first funding cycle, and set up any splits.
@dev
Each operation within this transaction can be done in sequence separately.
@dev
Anyone can deploy a project on an owner's behalf.
@param _owner The address to set as the owner of the project. The project ERC-721 will be owned by this address.
@param _projectMetadata Metadata to associate with the project within a particular domain. This can be updated any time by the owner of the project.
@param _data Data that defines the project's first funding cycle. These properties will remain fixed for the duration of the funding cycle.
@param _metadata Metadata specifying the controller specific params that a funding cycle can have. These properties will remain fixed for the duration of the funding cycle.
@param _mustStartAtOrAfter The time before which the configured funding cycle cannot start.
@param _groupedSplits An array of splits to set for any number of groups.
@param _fundAccessConstraints An array 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` and `_overflowAllowance` parameters must fit in a `uint232`.
@param _terminals Payment terminals to add for the project.
@param _memo A memo to pass along to the emitted event.
@return projectId The ID of the project.
*/functionlaunchProjectFor(address _owner,
JBProjectMetadata calldata _projectMetadata,
JBFundingCycleData calldata _data,
JBFundingCycleMetadata calldata _metadata,
uint256 _mustStartAtOrAfter,
JBGroupedSplits[] calldata _groupedSplits,
JBFundAccessConstraints[] calldata _fundAccessConstraints,
IJBPaymentTerminal[] memory _terminals,
stringmemory _memo
) externalvirtualoverridereturns (uint256 projectId) {
// Mint the project into the wallet of the message sender.
projectId = projects.createFor(_owner, _projectMetadata);
// Set this contract as the project's controller in the directory.
directory.setControllerOf(projectId, address(this));
// Configure the first funding cycle.uint256 _configuration = _configure(
projectId,
_data,
_metadata,
_mustStartAtOrAfter,
_groupedSplits,
_fundAccessConstraints
);
// Add the provided terminals to the list of terminals.if (_terminals.length>0) directory.setTerminalsOf(projectId, _terminals);
emit LaunchProject(_configuration, projectId, _memo, msg.sender);
}
/**
@notice
Creates a funding cycle for an already existing project ERC-721.
@dev
Each operation within this transaction can be done in sequence separately.
@dev
Only a project owner or operator can launch its funding cycles.
@param _projectId The ID of the project to launch funding cycles for.
@param _data Data that defines the project's first funding cycle. These properties will remain fixed for the duration of the funding cycle.
@param _metadata Metadata specifying the controller specific params that a funding cycle can have. These properties will remain fixed for the duration of the funding cycle.
@param _mustStartAtOrAfter The time before which the configured funding cycle cannot start.
@param _groupedSplits An array of splits to set for any number of groups.
@param _fundAccessConstraints An array 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` and `_overflowAllowance` parameters must fit in a `uint232`.
@param _terminals Payment terminals to add for the project.
@param _memo A memo to pass along to the emitted event.
@return configuration The configuration of the funding cycle that was successfully created.
*/functionlaunchFundingCyclesFor(uint256 _projectId,
JBFundingCycleData calldata _data,
JBFundingCycleMetadata calldata _metadata,
uint256 _mustStartAtOrAfter,
JBGroupedSplits[] calldata _groupedSplits,
JBFundAccessConstraints[] memory _fundAccessConstraints,
IJBPaymentTerminal[] memory _terminals,
stringmemory _memo
)
externalvirtualoverriderequirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.RECONFIGURE)
returns (uint256 configuration)
{
// If there is a previous configuration, reconfigureFundingCyclesOf should be called insteadif (fundingCycleStore.latestConfigurationOf(_projectId) >0)
revert FUNDING_CYCLE_ALREADY_LAUNCHED();
// Set this contract as the project's controller in the directory.
directory.setControllerOf(_projectId, address(this));
// Configure the first funding cycle.
configuration = _configure(
_projectId,
_data,
_metadata,
_mustStartAtOrAfter,
_groupedSplits,
_fundAccessConstraints
);
// Add the provided terminals to the list of terminals.if (_terminals.length>0) directory.setTerminalsOf(_projectId, _terminals);
emit LaunchFundingCycles(configuration, _projectId, _memo, msg.sender);
}
/**
@notice
Proposes a configuration of a subsequent funding cycle that will take effect once the current one expires if it is approved by the current funding cycle's ballot.
@dev
Only a project's owner or a designated operator can configure its funding cycles.
@param _projectId The ID of the project whose funding cycles are being reconfigured.
@param _data Data that defines the funding cycle. These properties will remain fixed for the duration of the funding cycle.
@param _metadata Metadata specifying the controller specific params that a funding cycle can have. These properties will remain fixed for the duration of the funding cycle.
@param _mustStartAtOrAfter The time before which the configured funding cycle cannot start.
@param _groupedSplits An array of splits to set for any number of groups.
@param _fundAccessConstraints An array 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` and `_overflowAllowance` parameters must fit in a `uint232`.
@param _memo A memo to pass along to the emitted event.
@return configuration The configuration of the funding cycle that was successfully reconfigured.
*/functionreconfigureFundingCyclesOf(uint256 _projectId,
JBFundingCycleData calldata _data,
JBFundingCycleMetadata calldata _metadata,
uint256 _mustStartAtOrAfter,
JBGroupedSplits[] calldata _groupedSplits,
JBFundAccessConstraints[] calldata _fundAccessConstraints,
stringcalldata _memo
)
externalvirtualoverriderequirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.RECONFIGURE)
returns (uint256 configuration)
{
// Configure the next funding cycle.
configuration = _configure(
_projectId,
_data,
_metadata,
_mustStartAtOrAfter,
_groupedSplits,
_fundAccessConstraints
);
emit ReconfigureFundingCycles(configuration, _projectId, _memo, msg.sender);
}
/**
@notice
Issues an owner's ERC20 JBTokens that'll be used when claiming tokens.
@dev
Deploys a project's ERC20 JBToken contract.
@dev
Only a project's owner or operator can issue its token.
@param _projectId The ID of the project being issued tokens.
@param _name The ERC20's name.
@param _symbol The ERC20's symbol.
*/functionissueTokenFor(uint256 _projectId,
stringcalldata _name,
stringcalldata _symbol
)
externalvirtualoverriderequirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.ISSUE)
returns (IJBToken token)
{
// Issue the token in the store.return tokenStore.issueFor(_projectId, _name, _symbol);
}
/**
@notice
Swap the current project's token that is minted and burned for another, and transfer ownership of the current token to another address if needed.
@dev
Only a project's owner or operator can change its token.
@param _projectId The ID of the project to which the changed token belongs.
@param _token The new token.
@param _newOwner An address to transfer the current token's ownership to. This is optional, but it cannot be done later.
*/functionchangeTokenOf(uint256 _projectId,
IJBToken _token,
address _newOwner
)
externalvirtualoverriderequirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.CHANGE_TOKEN)
{
// Get a reference to the project's current funding cycle.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// The current funding cycle must not be paused.if (!_fundingCycle.changeTokenAllowed()) revert CHANGE_TOKEN_NOT_ALLOWED();
// Change the token in the store.
tokenStore.changeFor(_projectId, _token, _newOwner);
}
/**
@notice
Mint new token supply into an account, and optionally reserve a supply to be distributed according to the project's current funding cycle configuration.
@dev
Only a project's owner, a designated operator, one of its terminals, or the current data source can mint its tokens.
@param _projectId The ID of the project to which the tokens being minted belong.
@param _tokenCount The amount of tokens to mint in total, counting however many should be reserved.
@param _beneficiary The account that the tokens are being minted for.
@param _memo A memo to pass along to the emitted event.
@param _preferClaimedTokens A flag indicating whether a project's attached token contract should be minted if they have been issued.
@param _useReservedRate Whether to use the current funding cycle's reserved rate in the mint calculation.
@return beneficiaryTokenCount The amount of tokens minted for the beneficiary.
*/functionmintTokensOf(uint256 _projectId,
uint256 _tokenCount,
address _beneficiary,
stringcalldata _memo,
bool _preferClaimedTokens,
bool _useReservedRate
) externalvirtualoverridereturns (uint256 beneficiaryTokenCount) {
// There should be tokens to mint.if (_tokenCount ==0) revert ZERO_TOKENS_TO_MINT();
// Define variables that will be needed outside scoped section below.// Keep a reference to the reserved rate to useuint256 _reservedRate;
// Scoped section prevents stack too deep. `_fundingCycle` only used within scope.
{
// Get a reference to the project's current funding cycle.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// Minting limited to: project owner, authorized callers, project terminal and current funding cycle data source
_requirePermissionAllowingOverride(
projects.ownerOf(_projectId),
_projectId,
JBOperations.MINT,
directory.isTerminalOf(_projectId, IJBPaymentTerminal(msg.sender)) ||msg.sender==address(_fundingCycle.dataSource())
);
// If the message sender is not a terminal or a datasource, the current funding cycle must allow minting.if (
!_fundingCycle.mintingAllowed() &&!directory.isTerminalOf(_projectId, IJBPaymentTerminal(msg.sender)) &&msg.sender!=address(_fundingCycle.dataSource())
) revert MINT_NOT_ALLOWED_AND_NOT_TERMINAL_DELEGATE();
// Determine the reserved rate to use.
_reservedRate = _useReservedRate ? _fundingCycle.reservedRate() : 0;
}
if (_reservedRate == JBConstants.MAX_RESERVED_RATE)
// Subtract the total weighted amount from the tracker so the full reserved token amount can be printed later.
_processedTokenTrackerOf[_projectId] =
_processedTokenTrackerOf[_projectId] -int256(_tokenCount);
else {
// The unreserved token count that will be minted for the beneficiary.
beneficiaryTokenCount = PRBMath.mulDiv(
_tokenCount,
JBConstants.MAX_RESERVED_RATE - _reservedRate,
JBConstants.MAX_RESERVED_RATE
);
if (_reservedRate ==0)
// If there's no reserved rate, increment the tracker with the newly minted tokens.
_processedTokenTrackerOf[_projectId] =
_processedTokenTrackerOf[_projectId] +int256(beneficiaryTokenCount);
// Mint the tokens.
tokenStore.mintFor(_beneficiary, _projectId, beneficiaryTokenCount, _preferClaimedTokens);
}
emit MintTokens(
_beneficiary,
_projectId,
_tokenCount,
beneficiaryTokenCount,
_memo,
_reservedRate,
msg.sender
);
}
/**
@notice
Burns a token holder's supply.
@dev
Only a token's holder, a designated operator, or a project's terminal can burn it.
@param _holder The account that is having its tokens burned.
@param _projectId The ID of the project to which the tokens being burned belong.
@param _tokenCount The number of tokens to burn.
@param _memo A memo to pass along to the emitted event.
@param _preferClaimedTokens A flag indicating whether a project's attached token contract should be burned first if they have been issued.
*/functionburnTokensOf(address _holder,
uint256 _projectId,
uint256 _tokenCount,
stringcalldata _memo,
bool _preferClaimedTokens
)
externalvirtualoverriderequirePermissionAllowingOverride(
_holder,
_projectId,
JBOperations.BURN,
directory.isTerminalOf(_projectId, IJBPaymentTerminal(msg.sender))
)
{
// There should be tokens to burnif (_tokenCount ==0) revert NO_BURNABLE_TOKENS();
// Get a reference to the project's current funding cycle.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// If the message sender is not a terminal, the current funding cycle must not be paused.if (
_fundingCycle.burnPaused() &&!directory.isTerminalOf(_projectId, IJBPaymentTerminal(msg.sender))
) revert BURN_PAUSED_AND_SENDER_NOT_VALID_TERMINAL_DELEGATE();
// Update the token tracker so that reserved tokens will still be correctly mintable.
_processedTokenTrackerOf[_projectId] =
_processedTokenTrackerOf[_projectId] -int256(_tokenCount);
// Burn the tokens.
tokenStore.burnFrom(_holder, _projectId, _tokenCount, _preferClaimedTokens);
emit BurnTokens(_holder, _projectId, _tokenCount, _memo, msg.sender);
}
/**
@notice
Distributes all outstanding reserved tokens for a project.
@param _projectId The ID of the project to which the reserved tokens belong.
@param _memo A memo to pass along to the emitted event.
@return The amount of minted reserved tokens.
*/functiondistributeReservedTokensOf(uint256 _projectId, stringcalldata _memo)
externalvirtualoverridereturns (uint256)
{
return _distributeReservedTokensOf(_projectId, _memo);
}
/**
@notice
Allows other controllers to signal to this one that a migration is expected for the specified project.
@dev
This controller should not yet be the project's controller.
@param _projectId The ID of the project that will be migrated to this controller.
@param _from The controller being migrated from.
*/functionprepForMigrationOf(uint256 _projectId, address _from) externalvirtualoverride{
// This controller must not be the project's current controller.if (directory.controllerOf(_projectId) ==address(this))
revert CANT_MIGRATE_TO_CURRENT_CONTROLLER();
// Set the tracker as the total supply.
_processedTokenTrackerOf[_projectId] =int256(tokenStore.totalSupplyOf(_projectId));
emit PrepMigration(_projectId, _from, msg.sender);
}
/**
@notice
Allows a project to migrate from this controller to another.
@dev
Only a project's owner or a designated operator can migrate it.
@param _projectId The ID of the project that will be migrated from this controller.
@param _to The controller to which the project is migrating.
*/functionmigrate(uint256 _projectId, IJBMigratable _to)
externalvirtualoverriderequirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.MIGRATE_CONTROLLER)
{
// This controller must be the project's current controller.if (directory.controllerOf(_projectId) !=address(this)) revert NOT_CURRENT_CONTROLLER();
// Get a reference to the project's current funding cycle.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// Migration must be allowed.if (!_fundingCycle.controllerMigrationAllowed()) revert MIGRATION_NOT_ALLOWED();
// All reserved tokens must be minted before migrating.if (uint256(_processedTokenTrackerOf[_projectId]) != tokenStore.totalSupplyOf(_projectId))
_distributeReservedTokensOf(_projectId, '');
// Make sure the new controller is prepped for the migration.
_to.prepForMigrationOf(_projectId, address(this));
// Set the new controller.
directory.setControllerOf(_projectId, address(_to));
emit Migrate(_projectId, _to, msg.sender);
}
//*********************************************************************//// ------------------------ internal functions ----------------------- ////*********************************************************************///**
@notice
Distributes all outstanding reserved tokens for a project.
@param _projectId The ID of the project to which the reserved tokens belong.
@param _memo A memo to pass along to the emitted event.
@return tokenCount The amount of minted reserved tokens.
*/function_distributeReservedTokensOf(uint256 _projectId, stringmemory _memo)
internalreturns (uint256 tokenCount)
{
// Get the current funding cycle to read the reserved rate from.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// Get a reference to new total supply of tokens before minting reserved tokens.uint256 _totalTokens = tokenStore.totalSupplyOf(_projectId);
// Get a reference to the number of tokens that need to be minted.
tokenCount = _reservedTokenAmountFrom(
_processedTokenTrackerOf[_projectId],
_fundingCycle.reservedRate(),
_totalTokens
);
// Set the tracker to be the new total supply.
_processedTokenTrackerOf[_projectId] =int256(_totalTokens + tokenCount);
// Get a reference to the project owner.address _owner = projects.ownerOf(_projectId);
// Distribute tokens to splits and get a reference to the leftover amount to mint after all splits have gotten their share.uint256 _leftoverTokenCount = tokenCount ==0
? 0
: _distributeToReservedTokenSplitsOf(
_projectId,
_fundingCycle.configuration,
JBSplitsGroups.RESERVED_TOKENS,
tokenCount
);
// Mint any leftover tokens to the project owner.if (_leftoverTokenCount >0) tokenStore.mintFor(_owner, _projectId, _leftoverTokenCount, false);
emit DistributeReservedTokens(
_fundingCycle.configuration,
_fundingCycle.number,
_projectId,
_owner,
tokenCount,
_leftoverTokenCount,
_memo,
msg.sender
);
}
/**
@notice
Distribute tokens to the splits according to the specified funding cycle configuration.
@param _projectId The ID of the project for which reserved token splits are being distributed.
@param _domain The domain of the splits to distribute the reserved tokens between.
@param _group The group of the splits to distribute the reserved tokens between.
@param _amount The total amount of tokens to mint.
@return leftoverAmount If the splits percents dont add up to 100%, the leftover amount is returned.
*/function_distributeToReservedTokenSplitsOf(uint256 _projectId,
uint256 _domain,
uint256 _group,
uint256 _amount
) internalreturns (uint256 leftoverAmount) {
// Set the leftover amount to the initial amount.
leftoverAmount = _amount;
// Get a reference to the project's reserved token splits.
JBSplit[] memory _splits = splitsStore.splitsOf(_projectId, _domain, _group);
//Transfer between all splits.for (uint256 _i =0; _i < _splits.length; _i++) {
// Get a reference to the split being iterated on.
JBSplit memory _split = _splits[_i];
// The amount to send towards the split.uint256 _tokenCount = PRBMath.mulDiv(
_amount,
_split.percent,
JBConstants.SPLITS_TOTAL_PERCENT
);
// Mints tokens for the split if needed.if (_tokenCount >0) {
tokenStore.mintFor(
// If an allocator is set in the splits, set it as the beneficiary.// Otherwise if a projectId is set in the split, set the project's owner as the beneficiary.// If the split has a beneficiary send to the split's beneficiary. Otherwise send to the msg.sender.
_split.allocator != IJBSplitAllocator(address(0))
? address(_split.allocator)
: _split.projectId !=0
? projects.ownerOf(_split.projectId)
: _split.beneficiary !=address(0)
? _split.beneficiary
: msg.sender,
_projectId,
_tokenCount,
_split.preferClaimed
);
// If there's an allocator set, trigger its `allocate` function.if (_split.allocator != IJBSplitAllocator(address(0)))
_split.allocator.allocate(
JBSplitAllocationData(
address(tokenStore.tokenOf(_projectId)),
_tokenCount,
18,
_projectId,
_group,
_split
)
);
// Subtract from the amount to be sent to the beneficiary.
leftoverAmount = leftoverAmount - _tokenCount;
}
emit DistributeToReservedTokenSplit(
_projectId,
_domain,
_group,
_split,
_tokenCount,
msg.sender
);
}
}
/**
@notice
Configures a funding cycle and stores information pertinent to the configuration.
@param _projectId The ID of the project whose funding cycles are being reconfigured.
@param _data Data that defines the funding cycle. These properties will remain fixed for the duration of the funding cycle.
@param _metadata Metadata specifying the controller specific params that a funding cycle can have. These properties will remain fixed for the duration of the funding cycle.
@param _mustStartAtOrAfter The time before which the configured funding cycle cannot start.
@param _groupedSplits An array of splits to set for any number of groups.
@param _fundAccessConstraints An array 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.
@return configuration The configuration of the funding cycle that was successfully reconfigured.
*/function_configure(uint256 _projectId,
JBFundingCycleData calldata _data,
JBFundingCycleMetadata calldata _metadata,
uint256 _mustStartAtOrAfter,
JBGroupedSplits[] memory _groupedSplits,
JBFundAccessConstraints[] memory _fundAccessConstraints
) internalreturns (uint256) {
// Make sure the provided reserved rate is valid.if (_metadata.reservedRate > JBConstants.MAX_RESERVED_RATE) revert INVALID_RESERVED_RATE();
// Make sure the provided redemption rate is valid.if (_metadata.redemptionRate > JBConstants.MAX_REDEMPTION_RATE)
revert INVALID_REDEMPTION_RATE();
// Make sure the provided ballot redemption rate is valid.if (_metadata.ballotRedemptionRate > JBConstants.MAX_REDEMPTION_RATE)
revert INVALID_BALLOT_REDEMPTION_RATE();
// Configure the funding cycle's properties.
JBFundingCycle memory _fundingCycle = fundingCycleStore.configureFor(
_projectId,
_data,
JBFundingCycleMetadataResolver.packFundingCycleMetadata(_metadata),
_mustStartAtOrAfter
);
// Set splits for the group.
splitsStore.set(_projectId, _fundingCycle.configuration, _groupedSplits);
// Set distribution limits if there are any.for (uint256 _i; _i < _fundAccessConstraints.length; _i++) {
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 bits, 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.token] =
_constraints.distributionLimit |
(_constraints.distributionLimitCurrency <<232);
// Set the overflow allowance if there is one.if (_constraints.overflowAllowance >0)
_packedOverflowAllowanceDataOf[_projectId][_fundingCycle.configuration][
_constraints.terminal
][_constraints.token] =
_constraints.overflowAllowance |
(_constraints.overflowAllowanceCurrency <<232);
emit SetFundAccessConstraints(
_fundingCycle.configuration,
_fundingCycle.number,
_projectId,
_constraints,
msg.sender
);
}
return _fundingCycle.configuration;
}
/**
@notice
Gets the amount of reserved tokens currently tracked for a project given a reserved rate.
@param _processedTokenTracker The tracker to make the calculation with.
@param _reservedRate The reserved rate to use to make the calculation.
@param _totalEligibleTokens The total amount to make the calculation with.
@return amount reserved token amount.
*/function_reservedTokenAmountFrom(int256 _processedTokenTracker,
uint256 _reservedRate,
uint256 _totalEligibleTokens
) internalpurereturns (uint256) {
// Get a reference to the amount of tokens that are unprocessed.uint256 _unprocessedTokenBalanceOf = _processedTokenTracker >=0
? _totalEligibleTokens -uint256(_processedTokenTracker)
: _totalEligibleTokens +uint256(-_processedTokenTracker);
// If there are no unprocessed tokens, return.if (_unprocessedTokenBalanceOf ==0) return0;
// If all tokens are reserved, return the full unprocessed amount.if (_reservedRate == JBConstants.MAX_RESERVED_RATE) return _unprocessedTokenBalanceOf;
return
PRBMath.mulDiv(
_unprocessedTokenBalanceOf,
JBConstants.MAX_RESERVED_RATE,
JBConstants.MAX_RESERVED_RATE - _reservedRate
) - _unprocessedTokenBalanceOf;
}
}
Contract Source Code
File 24 of 44: JBDidPayData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./JBTokenAmount.sol';
/**
@member payer The address from which the payment originated.
@member projectId The ID of the project for which the payment was made.
@member currentFundingCycleConfiguration The configuration of the funding cycle during which the payment is being made.
@member amount The amount of the payment. Includes the token being paid, the value, the number of decimals included, and the currency of the amount.
@member projectTokenCount The number of project tokens minted for the beneficiary.
@member beneficiary The address to which the tokens were minted.
@member preferClaimedTokens A flag indicating whether the request prefered to mint project tokens into the beneficiaries wallet rather than leaving them unclaimed. This is only possible if the project has an attached token contract.
@member memo The memo that is being emitted alongside the payment.
@member metadata Extra data to send to the delegate.
*/structJBDidPayData {
address payer;
uint256 projectId;
uint256 currentFundingCycleConfiguration;
JBTokenAmount amount;
uint256 projectTokenCount;
address beneficiary;
bool preferClaimedTokens;
string memo;
bytes metadata;
}
Contract Source Code
File 25 of 44: JBDidRedeemData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./JBTokenAmount.sol';
/**
@member holder The holder of the tokens being redeemed.
@member projectId The ID of the project with which the redeemed tokens are associated.
@member currentFundingCycleConfiguration The configuration of the funding cycle during which the redemption is being made.
@member projectTokenCount The number of project tokens being redeemed.
@member reclaimedAmount The amount reclaimed from the treasury. Includes the token being reclaimed, the value, the number of decimals included, and the currency of the amount.
@member beneficiary The address to which the reclaimed amount will be sent.
@member memo The memo that is being emitted alongside the redemption.
@member metadata Extra data to send to the delegate.
*/structJBDidRedeemData {
address holder;
uint256 projectId;
uint256 currentFundingCycleConfiguration;
uint256 projectTokenCount;
JBTokenAmount reclaimedAmount;
addresspayable beneficiary;
string memo;
bytes metadata;
}
Contract Source Code
File 26 of 44: JBFundAccessConstraints.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBPaymentTerminal.sol';
/**
@member terminal The terminal within which the distribution limit and the overflow allowance applies.
@member token The token for which the fund access constraints apply.
@member distributionLimit The amount of the distribution limit, as a fixed point number with the same number of decimals as the terminal within which the limit applies.
@member distributionLimitCurrency The currency of the distribution limit.
@member overflowAllowance The amount of the allowance, as a fixed point number with the same number of decimals as the terminal within which the allowance applies.
@member overflowAllowanceCurrency The currency of the overflow allowance.
*/structJBFundAccessConstraints {
IJBPaymentTerminal terminal;
address token;
uint256 distributionLimit;
uint256 distributionLimitCurrency;
uint256 overflowAllowance;
uint256 overflowAllowanceCurrency;
}
Contract Source Code
File 27 of 44: JBFundingCycle.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBFundingCycleBallot.sol';
/**
@member number The funding cycle number for the cycle's project. Each funding cycle has a number that is an increment of the cycle that directly preceded it. Each project's first funding cycle has a number of 1.
@member configuration The timestamp when the parameters for this funding cycle were configured. This value will stay the same for subsequent funding cycles that roll over from an originally configured cycle.
@member basedOn The `configuration` of the funding cycle that was active when this cycle was created.
@member start The timestamp marking the moment from which the funding cycle is considered active. It is a unix timestamp measured in seconds.
@member duration The number of seconds the funding cycle lasts for, after which a new funding cycle will start. A duration of 0 means that the funding cycle will stay active until the project owner explicitly issues a reconfiguration, at which point a new funding cycle will immediately start with the updated properties. If the duration is greater than 0, a project owner cannot make changes to a funding cycle's parameters while it is active – any proposed changes will apply to the subsequent cycle. If no changes are proposed, a funding cycle rolls over to another one with the same properties but new `start` timestamp and a discounted `weight`.
@member weight A fixed point number with 18 decimals that contracts can use to base arbitrary calculations on. For example, payment terminals can use this to determine how many tokens should be minted when a payment is received.
@member discountRate A percent by how much the `weight` of the subsequent funding cycle should be reduced, if the project owner hasn't configured the subsequent funding cycle with an explicit `weight`. If it's 0, each funding cycle will have equal weight. If the number is 90%, the next funding cycle will have a 10% smaller weight. This weight is out of `JBConstants.MAX_DISCOUNT_RATE`.
@member ballot An address of a contract that says whether a proposed reconfiguration should be accepted or rejected. It can be used to create rules around how a project owner can change funding cycle parameters over time.
@member metadata Extra data that can be associated with a funding cycle.
*/structJBFundingCycle {
uint256 number;
uint256 configuration;
uint256 basedOn;
uint256 start;
uint256 duration;
uint256 weight;
uint256 discountRate;
IJBFundingCycleBallot ballot;
uint256 metadata;
}
Contract Source Code
File 28 of 44: JBFundingCycleData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBFundingCycleBallot.sol';
/**
@member duration The number of seconds the funding cycle lasts for, after which a new funding cycle will start. A duration of 0 means that the funding cycle will stay active until the project owner explicitly issues a reconfiguration, at which point a new funding cycle will immediately start with the updated properties. If the duration is greater than 0, a project owner cannot make changes to a funding cycle's parameters while it is active – any proposed changes will apply to the subsequent cycle. If no changes are proposed, a funding cycle rolls over to another one with the same properties but new `start` timestamp and a discounted `weight`.
@member weight A fixed point number with 18 decimals that contracts can use to base arbitrary calculations on. For example, payment terminals can use this to determine how many tokens should be minted when a payment is received.
@member discountRate A percent by how much the `weight` of the subsequent funding cycle should be reduced, if the project owner hasn't configured the subsequent funding cycle with an explicit `weight`. If it's 0, each funding cycle will have equal weight. If the number is 90%, the next funding cycle will have a 10% smaller weight. This weight is out of `JBConstants.MAX_DISCOUNT_RATE`.
@member ballot An address of a contract that says whether a proposed reconfiguration should be accepted or rejected. It can be used to create rules around how a project owner can change funding cycle parameters over time.
*/structJBFundingCycleData {
uint256 duration;
uint256 weight;
uint256 discountRate;
IJBFundingCycleBallot ballot;
}
Contract Source Code
File 29 of 44: JBFundingCycleMetadata.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./JBGlobalFundingCycleMetadata.sol';
import'./../interfaces/IJBFundingCycleDataSource.sol';
/**
@member global Data used globally in non-migratable ecosystem contracts.
@member reservedRate The reserved rate of the funding cycle. This number is a percentage calculated out of `JBConstants.MAX_RESERVED_RATE`.
@member redemptionRate The redemption rate of the funding cycle. This number is a percentage calculated out of `JBConstants.MAX_REDEMPTION_RATE`.
@member ballotRedemptionRate The redemption rate to use during an active ballot of the funding cycle. This number is a percentage calculated out of `JBConstants.MAX_REDEMPTION_RATE`.
@member pausePay A flag indicating if the pay functionality should be paused during the funding cycle.
@member pauseDistributions A flag indicating if the distribute functionality should be paused during the funding cycle.
@member pauseRedeem A flag indicating if the redeem functionality should be paused during the funding cycle.
@member pauseBurn A flag indicating if the burn functionality should be paused during the funding cycle.
@member allowMinting A flag indicating if the mint functionality should be allowed during the funding cycle.
@member allowChangeToken A flag indicating if changing tokens should be allowed during this funding cycle.
@member allowTerminalMigration A flag indicating if migrating terminals should be allowed during this funding cycle.
@member allowControllerMigration A flag indicating if migrating controllers should be allowed during this funding cycle.
@member holdFees A flag indicating if fees should be held during this funding cycle.
@member useTotalOverflowForRedemptions A flag indicating if redemptions should use the project's balance held in all terminals instead of the project's local terminal balance from which the redemption is being fulfilled.
@member useDataSourceForPay A flag indicating if the data source should be used for pay transactions during this funding cycle.
@member useDataSourceForRedeem A flag indicating if the data source should be used for redeem transactions during this funding cycle.
@member dataSource The data source to use during this funding cycle.
*/structJBFundingCycleMetadata {
JBGlobalFundingCycleMetadata global;
uint256 reservedRate;
uint256 redemptionRate;
uint256 ballotRedemptionRate;
bool pausePay;
bool pauseDistributions;
bool pauseRedeem;
bool pauseBurn;
bool allowMinting;
bool allowChangeToken;
bool allowTerminalMigration;
bool allowControllerMigration;
bool holdFees;
bool useTotalOverflowForRedemptions;
bool useDataSourceForPay;
bool useDataSourceForRedeem;
address dataSource;
}
Contract Source Code
File 30 of 44: JBFundingCycleMetadataResolver.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBFundingCycleDataSource.sol';
import'./../structs/JBFundingCycleMetadata.sol';
import'./../structs/JBGlobalFundingCycleMetadata.sol';
import'./JBConstants.sol';
import'./JBGlobalFundingCycleMetadataResolver.sol';
libraryJBFundingCycleMetadataResolver{
functionglobal(JBFundingCycle memory _fundingCycle)
internalpurereturns (JBGlobalFundingCycleMetadata memory metadata)
{
return JBGlobalFundingCycleMetadataResolver.expandMetadata(uint8(_fundingCycle.metadata >>8));
}
functionreservedRate(JBFundingCycle memory _fundingCycle) internalpurereturns (uint256) {
returnuint256(uint16(_fundingCycle.metadata >>24));
}
functionredemptionRate(JBFundingCycle memory _fundingCycle) internalpurereturns (uint256) {
// Redemption rate is a number 0-10000. It's inverse was stored so the most common case of 100% results in no storage needs.return JBConstants.MAX_REDEMPTION_RATE -uint256(uint16(_fundingCycle.metadata >>40));
}
functionballotRedemptionRate(JBFundingCycle memory _fundingCycle)
internalpurereturns (uint256)
{
// Redemption rate is a number 0-10000. It's inverse was stored so the most common case of 100% results in no storage needs.return JBConstants.MAX_REDEMPTION_RATE -uint256(uint16(_fundingCycle.metadata >>56));
}
functionpayPaused(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>72) &1) ==1;
}
functiondistributionsPaused(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>73) &1) ==1;
}
functionredeemPaused(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>74) &1) ==1;
}
functionburnPaused(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>75) &1) ==1;
}
functionmintingAllowed(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>76) &1) ==1;
}
functionchangeTokenAllowed(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>77) &1) ==1;
}
functionterminalMigrationAllowed(JBFundingCycle memory _fundingCycle)
internalpurereturns (bool)
{
return ((_fundingCycle.metadata >>78) &1) ==1;
}
functioncontrollerMigrationAllowed(JBFundingCycle memory _fundingCycle)
internalpurereturns (bool)
{
return ((_fundingCycle.metadata >>79) &1) ==1;
}
functionshouldHoldFees(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return ((_fundingCycle.metadata >>80) &1) ==1;
}
functionuseTotalOverflowForRedemptions(JBFundingCycle memory _fundingCycle)
internalpurereturns (bool)
{
return ((_fundingCycle.metadata >>81) &1) ==1;
}
functionuseDataSourceForPay(JBFundingCycle memory _fundingCycle) internalpurereturns (bool) {
return (_fundingCycle.metadata >>82) &1==1;
}
functionuseDataSourceForRedeem(JBFundingCycle memory _fundingCycle)
internalpurereturns (bool)
{
return (_fundingCycle.metadata >>83) &1==1;
}
functiondataSource(JBFundingCycle memory _fundingCycle) internalpurereturns (address) {
returnaddress(uint160(_fundingCycle.metadata >>84));
}
/**
@notice
Pack the funding cycle metadata.
@param _metadata The metadata to validate and pack.
@return packed The packed uint256 of all metadata params. The first 8 bits specify the version.
*/functionpackFundingCycleMetadata(JBFundingCycleMetadata memory _metadata)
internalpurereturns (uint256 packed)
{
// version 1 in the bits 0-7 (8 bits).
packed =1;
// global metadta in bits 8-23 (16 bits).
packed |=
JBGlobalFundingCycleMetadataResolver.packFundingCycleGlobalMetadata(_metadata.global) <<8;
// reserved rate in bits 24-39 (16 bits).
packed |= _metadata.reservedRate <<24;
// redemption rate in bits 40-55 (16 bits).// redemption rate is a number 0-10000. Store the reverse so the most common case of 100% results in no storage needs.
packed |= (JBConstants.MAX_REDEMPTION_RATE - _metadata.redemptionRate) <<40;
// ballot redemption rate rate in bits 56-71 (16 bits).// ballot redemption rate is a number 0-10000. Store the reverse so the most common case of 100% results in no storage needs.
packed |= (JBConstants.MAX_REDEMPTION_RATE - _metadata.ballotRedemptionRate) <<56;
// pause pay in bit 72.if (_metadata.pausePay) packed |=1<<72;
// pause tap in bit 73.if (_metadata.pauseDistributions) packed |=1<<73;
// pause redeem in bit 74.if (_metadata.pauseRedeem) packed |=1<<74;
// pause burn in bit 75.if (_metadata.pauseBurn) packed |=1<<75;
// allow minting in bit 76.if (_metadata.allowMinting) packed |=1<<76;
// allow change token in bit 77.if (_metadata.allowChangeToken) packed |=1<<77;
// allow terminal migration in bit 78.if (_metadata.allowTerminalMigration) packed |=1<<78;
// allow controller migration in bit 79.if (_metadata.allowControllerMigration) packed |=1<<79;
// hold fees in bit 80.if (_metadata.holdFees) packed |=1<<80;
// useTotalOverflowForRedemptions in bit 81.if (_metadata.useTotalOverflowForRedemptions) packed |=1<<81;
// use pay data source in bit 82.if (_metadata.useDataSourceForPay) packed |=1<<82;
// use redeem data source in bit 83.if (_metadata.useDataSourceForRedeem) packed |=1<<83;
// data source address in bits 84-243.
packed |=uint256(uint160(address(_metadata.dataSource))) <<84;
}
/**
@notice
Expand the funding cycle metadata.
@param _fundingCycle The funding cycle having its metadata expanded.
@return metadata The metadata object.
*/functionexpandMetadata(JBFundingCycle memory _fundingCycle)
internalpurereturns (JBFundingCycleMetadata memory metadata)
{
return
JBFundingCycleMetadata(
global(_fundingCycle),
reservedRate(_fundingCycle),
redemptionRate(_fundingCycle),
ballotRedemptionRate(_fundingCycle),
payPaused(_fundingCycle),
distributionsPaused(_fundingCycle),
redeemPaused(_fundingCycle),
burnPaused(_fundingCycle),
mintingAllowed(_fundingCycle),
changeTokenAllowed(_fundingCycle),
terminalMigrationAllowed(_fundingCycle),
controllerMigrationAllowed(_fundingCycle),
shouldHoldFees(_fundingCycle),
useTotalOverflowForRedemptions(_fundingCycle),
useDataSourceForPay(_fundingCycle),
useDataSourceForRedeem(_fundingCycle),
dataSource(_fundingCycle)
);
}
}
Contract Source Code
File 31 of 44: JBGlobalFundingCycleMetadata.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBFundingCycleDataSource.sol';
/**
@member allowSetTerminals A flag indicating if setting terminals should be allowed during this funding cycle.
@member allowSetController A flag indicating if setting a new controller should be allowed during this funding cycle.
*/structJBGlobalFundingCycleMetadata {
bool allowSetTerminals;
bool allowSetController;
}
Contract Source Code
File 32 of 44: JBGlobalFundingCycleMetadataResolver.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBFundingCycleDataSource.sol';
import'./../structs/JBFundingCycleMetadata.sol';
import'./JBConstants.sol';
libraryJBGlobalFundingCycleMetadataResolver{
functionsetTerminalsAllowed(uint8 _data) internalpurereturns (bool) {
return (_data &1) ==1;
}
functionsetControllerAllowed(uint8 _data) internalpurereturns (bool) {
return ((_data >>1) &1) ==1;
}
/**
@notice
Pack the global funding cycle metadata.
@param _metadata The metadata to validate and pack.
@return packed The packed uint256 of all global metadata params. The first 8 bits specify the version.
*/functionpackFundingCycleGlobalMetadata(JBGlobalFundingCycleMetadata memory _metadata)
internalpurereturns (uint256 packed)
{
// allow set terminals in bit 0.if (_metadata.allowSetTerminals) packed |=1;
// allow set controller in bit 1.if (_metadata.allowSetController) packed |=1<<1;
}
/**
@notice
Expand the global funding cycle metadata.
@param _packedMetadata The packed metadata to expand.
@return metadata The global metadata object.
*/functionexpandMetadata(uint8 _packedMetadata)
internalpurereturns (JBGlobalFundingCycleMetadata memory metadata)
{
return
JBGlobalFundingCycleMetadata(
setTerminalsAllowed(_packedMetadata),
setControllerAllowed(_packedMetadata)
);
}
}
Contract Source Code
File 33 of 44: JBGroupedSplits.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./JBSplit.sol';
/**
@member group The group indentifier.
@member splits The splits to associate with the group.
*/structJBGroupedSplits {
uint256 group;
JBSplit[] splits;
}
Contract Source Code
File 34 of 44: JBOperatable.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBOperatable.sol';
/**
@notice
Modifiers to allow access to functions based on the message sender's operator status.
@dev
Adheres to -
IJBOperatable: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
*/abstractcontractJBOperatableisIJBOperatable{
//*********************************************************************//// --------------------------- custom errors -------------------------- ////*********************************************************************//errorUNAUTHORIZED();
//*********************************************************************//// ---------------------------- modifiers ---------------------------- ////*********************************************************************///**
@notice
Only allows the speficied account or an operator of the account to proceed.
@param _account The account to check for.
@param _domain The domain namespace to look for an operator within.
@param _permissionIndex The index of the permission to check for.
*/modifierrequirePermission(address _account,
uint256 _domain,
uint256 _permissionIndex
) {
_requirePermission(_account, _domain, _permissionIndex);
_;
}
/**
@notice
Only allows the speficied account, an operator of the account to proceed, or a truthy override flag.
@param _account The account to check for.
@param _domain The domain namespace to look for an operator within.
@param _permissionIndex The index of the permission to check for.
@param _override A condition to force allowance for.
*/modifierrequirePermissionAllowingOverride(address _account,
uint256 _domain,
uint256 _permissionIndex,
bool _override
) {
_requirePermissionAllowingOverride(_account, _domain, _permissionIndex, _override);
_;
}
//*********************************************************************//// ---------------- public immutable stored properties --------------- ////*********************************************************************///**
@notice
A contract storing operator assignments.
*/
IJBOperatorStore publicimmutableoverride operatorStore;
//*********************************************************************//// -------------------------- constructor ---------------------------- ////*********************************************************************///**
@param _operatorStore A contract storing operator assignments.
*/constructor(IJBOperatorStore _operatorStore) {
operatorStore = _operatorStore;
}
//*********************************************************************//// -------------------------- internal views ------------------------- ////*********************************************************************///**
@notice
Require the message sender is either the account or has the specified permission.
@param _account The account to allow.
@param _domain The domain namespace within which the permission index will be checked.
@param _permissionIndex The permission index that an operator must have within the specified domain to be allowed.
*/function_requirePermission(address _account,
uint256 _domain,
uint256 _permissionIndex
) internalview{
if (
msg.sender!= _account &&!operatorStore.hasPermission(msg.sender, _account, _domain, _permissionIndex) &&!operatorStore.hasPermission(msg.sender, _account, 0, _permissionIndex)
) revert UNAUTHORIZED();
}
/**
@notice
Require the message sender is either the account, has the specified permission, or the override condition is true.
@param _account The account to allow.
@param _domain The domain namespace within which the permission index will be checked.
@param _domain The permission index that an operator must have within the specified domain to be allowed.
@param _override The override condition to allow.
*/function_requirePermissionAllowingOverride(address _account,
uint256 _domain,
uint256 _permissionIndex,
bool _override
) internalview{
if (
!_override &&msg.sender!= _account &&!operatorStore.hasPermission(msg.sender, _account, _domain, _permissionIndex) &&!operatorStore.hasPermission(msg.sender, _account, 0, _permissionIndex)
) revert UNAUTHORIZED();
}
}
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;/**
@member operator The address of the operator.
@member domain The domain within which the operator is being given permissions. A domain of 0 is a wildcard domain, which gives an operator access to all domains.
@member permissionIndexes The indexes of the permissions the operator is being given.
*/structJBOperatorData {
address operator;
uint256 domain;
uint256[] permissionIndexes;
}
Contract Source Code
File 37 of 44: JBPayParamsData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBPaymentTerminal.sol';
import'./JBTokenAmount.sol';
/**
@member terminal The terminal that is facilitating the payment.
@member payer The address from which the payment originated.
@member amount The amount of the payment. Includes the token being paid, the value, the number of decimals included, and the currency of the amount.
@member projectId The ID of the project being paid.
@member currentFundingCycleConfiguration The configuration of the funding cycle during which the payment is being made.
@member beneficiary The specified address that should be the beneficiary of anything that results from the payment.
@member weight The weight of the funding cycle during which the payment is being made.
@member reservedRate The reserved rate of the funding cycle during which the payment is being made.
@member memo The memo that was sent alongside the payment.
@member metadata Extra data provided by the payer.
*/structJBPayParamsData {
IJBPaymentTerminal terminal;
address payer;
JBTokenAmount amount;
uint256 projectId;
uint256 currentFundingCycleConfiguration;
address beneficiary;
uint256 weight;
uint256 reservedRate;
string memo;
bytes metadata;
}
Contract Source Code
File 38 of 44: JBProjectMetadata.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;/**
@member content The metadata content.
@member domain The domain within which the metadata applies.
*/structJBProjectMetadata {
string content;
uint256 domain;
}
Contract Source Code
File 39 of 44: JBRedeemParamsData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBPaymentTerminal.sol';
import'./JBTokenAmount.sol';
/**
@member terminal The terminal that is facilitating the redemption.
@member holder The holder of the tokens being redeemed.
@member projectId The ID of the project whos tokens are being redeemed.
@member currentFundingCycleConfiguration The configuration of the funding cycle during which the redemption is being made.
@member tokenCount The proposed number of tokens being redeemed, as a fixed point number with 18 decimals.
@member totalSupply The total supply of tokens used in the calculation, as a fixed point number with 18 decimals.
@member overflow The amount of overflow used in the reclaim amount calculation.
@member reclaimAmount The amount that should be reclaimed by the redeemer using the protocol's standard bonding curve redemption formula. Includes the token being reclaimed, the reclaim value, the number of decimals included, and the currency of the reclaim amount.
@member useTotalOverflow If overflow across all of a project's terminals is being used when making redemptions.
@member redemptionRate The redemption rate of the funding cycle during which the redemption is being made.
@member ballotRedemptionRate The ballot redemption rate of the funding cycle during which the redemption is being made.
@member memo The proposed memo that is being emitted alongside the redemption.
@member metadata Extra data provided by the redeemer.
*/structJBRedeemParamsData {
IJBPaymentTerminal terminal;
address holder;
uint256 projectId;
uint256 currentFundingCycleConfiguration;
uint256 tokenCount;
uint256 totalSupply;
uint256 overflow;
JBTokenAmount reclaimAmount;
bool useTotalOverflow;
uint256 redemptionRate;
uint256 ballotRedemptionRate;
string memo;
bytes metadata;
}
Contract Source Code
File 40 of 44: JBSplit.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./../interfaces/IJBSplitAllocator.sol';
/**
@member preferClaimed A flag that only has effect if a projectId is also specified, and the project has a token contract attached. If so, this flag indicates if the tokens that result from making a payment to the project should be delivered claimed into the beneficiary's wallet, or unclaimed to save gas.
@member preferAddToBalance A flag indicating if a distribution to a project should prefer triggering it's addToBalance function instead of its pay function.
@member percent The percent of the whole group that this split occupies. This number is out of `JBConstants.SPLITS_TOTAL_PERCENT`.
@member projectId The ID of a project. If an allocator is not set but a projectId is set, funds will be sent to the protocol treasury belonging to the project who's ID is specified. Resulting tokens will be routed to the beneficiary with the claimed token preference respected.
@member beneficiary An address. The role the of the beneficary depends on whether or not projectId is specified, and whether or not an allocator is specified. If allocator is set, the beneficiary will be forwarded to the allocator for it to use. If allocator is not set but projectId is set, the beneficiary is the address to which the project's tokens will be sent that result from a payment to it. If neither allocator or projectId are set, the beneficiary is where the funds from the split will be sent.
@member lockedUntil Specifies if the split should be unchangeable until the specified time, with the exception of extending the locked period.
@member allocator If an allocator is specified, funds will be sent to the allocator contract along with all properties of this split.
*/structJBSplit {
bool preferClaimed;
bool preferAddToBalance;
uint256 percent;
uint256 projectId;
addresspayable beneficiary;
uint256 lockedUntil;
IJBSplitAllocator allocator;
}
Contract Source Code
File 41 of 44: JBSplitAllocationData.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;import'./JBSplit.sol';
/**
@member token The token being sent to the split allocator.
@member amount The amount being sent to the split allocator, as a fixed point number.
@member decimals The number of decimals in the amount.
@member projectId The project to which the split belongs.
@member group The group to which the split belongs.
@member split The split that caused the allocation.
*/structJBSplitAllocationData {
address token;
uint256 amount;
uint256 decimals;
uint256 projectId;
uint256 group;
JBSplit split;
}
// SPDX-License-Identifier: MITpragmasolidity 0.8.6;/*
@member token The token the payment was made in.
@member value The amount of tokens that was paid, as a fixed point number.
@member decimals The number of decimals included in the value fixed point number.
@member currency The expected currency of the value.
**/structJBTokenAmount {
address token;
uint256 value;
uint256 decimals;
uint256 currency;
}