library JBFundingCycleMetadataResolver {
function global(JBFundingCycle memory _fundingCycle)
internal
pure
returns (JBGlobalFundingCycleMetadata memory)
{
return JBGlobalFundingCycleMetadataResolver.expandMetadata(uint8(_fundingCycle.metadata >> 8));
}
function reservedRate(JBFundingCycle memory _fundingCycle) internal pure returns (uint256) {
return uint256(uint16(_fundingCycle.metadata >> 24));
}
function redemptionRate(JBFundingCycle memory _fundingCycle) internal pure returns (uint256) {
return JBConstants.MAX_REDEMPTION_RATE - uint256(uint16(_fundingCycle.metadata >> 40));
}
function ballotRedemptionRate(JBFundingCycle memory _fundingCycle)
internal
pure
returns (uint256)
{
return JBConstants.MAX_REDEMPTION_RATE - uint256(uint16(_fundingCycle.metadata >> 56));
}
function payPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 72) & 1) == 1;
}
function distributionsPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 73) & 1) == 1;
}
function redeemPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 74) & 1) == 1;
}
function burnPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 75) & 1) == 1;
}
function mintingAllowed(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 76) & 1) == 1;
}
function terminalMigrationAllowed(JBFundingCycle memory _fundingCycle)
internal
pure
returns (bool)
{
return ((_fundingCycle.metadata >> 77) & 1) == 1;
}
function controllerMigrationAllowed(JBFundingCycle memory _fundingCycle)
internal
pure
returns (bool)
{
return ((_fundingCycle.metadata >> 78) & 1) == 1;
}
function shouldHoldFees(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return ((_fundingCycle.metadata >> 79) & 1) == 1;
}
function preferClaimedTokenOverride(JBFundingCycle memory _fundingCycle)
internal
pure
returns (bool)
{
return ((_fundingCycle.metadata >> 80) & 1) == 1;
}
function useTotalOverflowForRedemptions(JBFundingCycle memory _fundingCycle)
internal
pure
returns (bool)
{
return ((_fundingCycle.metadata >> 81) & 1) == 1;
}
function useDataSourceForPay(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
return (_fundingCycle.metadata >> 82) & 1 == 1;
}
function useDataSourceForRedeem(JBFundingCycle memory _fundingCycle)
internal
pure
returns (bool)
{
return (_fundingCycle.metadata >> 83) & 1 == 1;
}
function dataSource(JBFundingCycle memory _fundingCycle) internal pure returns (address) {
return address(uint160(_fundingCycle.metadata >> 84));
}
function metadata(JBFundingCycle memory _fundingCycle) internal pure returns (uint256) {
return uint256(uint8(_fundingCycle.metadata >> 244));
}
function packFundingCycleMetadata(JBFundingCycleMetadata memory _metadata)
internal
pure
returns (uint256 packed)
{
packed = 1;
packed |=
JBGlobalFundingCycleMetadataResolver.packFundingCycleGlobalMetadata(_metadata.global) <<
8;
packed |= _metadata.reservedRate << 24;
packed |= (JBConstants.MAX_REDEMPTION_RATE - _metadata.redemptionRate) << 40;
packed |= (JBConstants.MAX_REDEMPTION_RATE - _metadata.ballotRedemptionRate) << 56;
if (_metadata.pausePay) packed |= 1 << 72;
if (_metadata.pauseDistributions) packed |= 1 << 73;
if (_metadata.pauseRedeem) packed |= 1 << 74;
if (_metadata.pauseBurn) packed |= 1 << 75;
if (_metadata.allowMinting) packed |= 1 << 76;
if (_metadata.allowTerminalMigration) packed |= 1 << 77;
if (_metadata.allowControllerMigration) packed |= 1 << 78;
if (_metadata.holdFees) packed |= 1 << 79;
if (_metadata.preferClaimedTokenOverride) packed |= 1 << 80;
if (_metadata.useTotalOverflowForRedemptions) packed |= 1 << 81;
if (_metadata.useDataSourceForPay) packed |= 1 << 82;
if (_metadata.useDataSourceForRedeem) packed |= 1 << 83;
packed |= uint256(uint160(address(_metadata.dataSource))) << 84;
packed |= _metadata.metadata << 244;
}
function expandMetadata(JBFundingCycle memory _fundingCycle)
internal
pure
returns (JBFundingCycleMetadata memory)
{
return
JBFundingCycleMetadata(
global(_fundingCycle),
reservedRate(_fundingCycle),
redemptionRate(_fundingCycle),
ballotRedemptionRate(_fundingCycle),
payPaused(_fundingCycle),
distributionsPaused(_fundingCycle),
redeemPaused(_fundingCycle),
burnPaused(_fundingCycle),
mintingAllowed(_fundingCycle),
terminalMigrationAllowed(_fundingCycle),
controllerMigrationAllowed(_fundingCycle),
shouldHoldFees(_fundingCycle),
preferClaimedTokenOverride(_fundingCycle),
useTotalOverflowForRedemptions(_fundingCycle),
useDataSourceForPay(_fundingCycle),
useDataSourceForRedeem(_fundingCycle),
dataSource(_fundingCycle),
metadata(_fundingCycle)
);
}
}